akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef int64_t lint;

int main() {
	string s, t;
	cin >> s >> t;

	int a=s.size(), b=t.size(), c=0, x, y, z;
	vector<vector<int>> dp(a+1, vector<int>(b+1));
	rep(i, a) {
		rep(j, b) {
			if (s.at(i) == t.at(j)) dp[i+1][j+1] = dp[i][j] + 1;
			chmax(dp[i+1][j+1], dp[i+1][j]);
			chmax(dp[i+1][j+1], dp[i][j+1]);
		}
	}

	string u = "";
	while(a>0 && b>0) {
		if (dp[a][b] == dp[a-1][b]) a--;
		else if (dp[a][b] == dp[a][b-1]) b--;
		else if (dp[a][b] == dp[a-1][b-1]+1) {
			u = s.at(a-1) + u;
			a--, b--;
		}
	}
	cout << u << '\n';
}


Measured memory_bytes: 38912
import java.util.Scanner

object Main {
  def main(args: Array[String]) = {
    val s = new Scanner(System.in)
    val n = s.nextInt
    val m = s.nextInt
    val nums = (0 until n).map(i => s.nextInt).toArray
    val sum = nums.sum
    val lowerLimit = (sum.asInstanceOf[Float] / (4 * m)).ceil
    val canPick = nums.filter(_ >= lowerLimit).size >= m
    print(if (canPick) "Yes\n" else "No\n")
  }
}

Measured memory_bytes: 25520
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);
		int[] n = new int[4];

		for ( int i = 0 ; i < 4 ; i++) {
			n[i] = sc1.nextInt();
		}

		Arrays.sort(n);

		if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9	) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}

		sc1.close();

	}

}

Measured memory_bytes: 21844
S = list(raw_input())
T = list(raw_input())

ans = []
flag = False
for i in range(len(S)-len(T)+1)[::-1]:
    if flag == False:
        counter = 0
        sample = [c for c in S]
        for j in T:
            if sample[i+counter] != '?':
                if sample[i+counter] != j:
                    break
            else:
                sample[i+counter] = j
            counter += 1
            if counter == len(T):
                for k in range(len(sample)):
                    if sample[k] == '?':
                        sample[k] = 'a'
                sample = ''.join(sample)
                ans = sample
                flag = True

if flag:
    print ans
else:
    print 'UNRESTORABLE'

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  if (a + b < c + d)
    std::cout << "Right" << std::endl;
  else if (a + b > c + d)
    std::cout << "Left" << std::endl;
  else
    std::cout << "Balanced" << std::endl;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    V vec(n);
    ll sum = 0;
    rep(i, n){
        cin >> vec[i];
    } 
    if(n<=k){
        cout << 0 << endl;
        return 0;
    }
    sort(all(vec), greater<ll>());
    rep3(i,k,n){
        sum += vec[i];
    }
    cout << sum  << endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i=0; i<m; i++) {
        cin >> b[i];
    }
    int cnt = 0;
    for(int i=0; i<n; i++) {
        int sum = c;
        for(int j=0; j<m; j++) {
            int a; 
            cin >> a;
            sum += a * b[j]; 
        }
        if(sum > 0) {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 3666666
#define inf 999999999999
map<pair<int,int>,int> mp;
vector<pair<int,int> >v[N];
struct str{
	int now,w;
	bool operator < (const str &t) const {
		return w>t.w;
	}
};
int n,m,cnt;
int vis[N],dis[N];
void dij(int st){
	for(int i=0;i<=cnt+10;i++) dis[i]=inf,vis[i]=0;
	dis[st]=0;
	priority_queue<str> q;
	q.push((str){st,0});
	while(!q.empty()){
        struct str t=q.top();
        q.pop();
        if(vis[t.now]) continue;
        vis[t.now]=1;
        for(int i=0;i<v[t.now].size();i++){
            if(dis[v[t.now][i].first]>dis[t.now]+v[t.now][i].second){
                dis[v[t.now][i].first]=dis[t.now]+v[t.now][i].second;
                q.push((str){v[t.now][i].first,dis[v[t.now][i].first]});
            }
        }
    }
} 
signed main(){
	
	scanf("%lld%lld",&n,&m);
	cnt=n+1;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		int t1=0,t2=0;
		if(!mp[make_pair(a,c)])
			 mp[make_pair(a,c)]=cnt++;
		
		if(!mp[make_pair(b,c)])
			mp[make_pair(b,c)]=cnt++;
		
		t1=mp[make_pair(a,c)]; 
		t2=mp[make_pair(b,c)];
		v[t1].push_back(make_pair(t2,0));
		v[t2].push_back(make_pair(t1,0));
		v[a].push_back(make_pair(t1,1));
		v[t1].push_back(make_pair(a,1));
		v[b].push_back(make_pair(t2,1));
		v[t2].push_back(make_pair(b,1));
	}
	dij(1);
	if(dis[n]==inf) cout<<"-1";
	else cout<<dis[n]/2;
	return 0;
}

Measured memory_bytes: 155248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
typedef long long ll;

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
vector<string> grid;
int h, w;

void dfs(int y, int x, vector<vector<bool>> &visited){
  visited[y][x] = true;
  vector<bool> cond(2,false);
  for (int i = 0; i < 2; i++){
    int ny = y + dy[i], nx = x + dx[i];
    if(ny < 0 || h <= ny || nx < 0 || w <= nx || grid[ny][nx] == '.'){
      continue;
    }else {
      cond[i] = true;
    }
  } 
  if(cond[0] ^ cond[1]){
    if(cond[0] == 1){
      dfs(y + dy[0], x + dx[0], visited);
    }else{
      dfs(y + dy[1], x + dx[1], visited);
    }
  }else {
    return;
  }
}

int main() {
  cin >> h >> w;
  grid.resize(h);
  vector<vector<bool>> visited(h, vector<bool>(w, false));
  rep(i, h) cin >> grid[i];
  dfs(0, 0, visited);
  rep(i,h){
    rep(j,w){
      if(grid[i][j] == '#' && !visited[i][j]){
        cout << "Impossible" << endl;
        return 0;
      }
    }
  }
  cout << "Possible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)

int main() {
	string N;
	cin>>N;
	int i = N[0] - '0';
	int k = 0;
	for(int j = 1; j<=N.size()-1;j++){
		int n = N[j] -'0';
		if(n!=9) break;
		else k++;
	}
	if(k==N.size()-1 && N.size() != 1) cout<<i +(N.size()-1)*9<<endl;
	else if(N.size()-1) cout<<i - 1 +(N.size()-1)*9<<endl;
	else cout<<i<<endl;


	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int a;
    int count=0;
    for(int i=0;i<N;i++){
        cin >> a;
        if(a%2) count++;
    }
    if(count%2) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

vi V(5);
int mn=INF;
int n;
int ans;
signed main(){

    in(V);

    rep(i,5) {
        if(V[i]%10==0) continue;
        if(mn>V[i]%10){
            mn=V[i]%10;
            n=i;
        }
    }

    rep(i,5){
        if(n!=i){
            int res=V[i]%10!=0?10-(V[i]%10):0;
            ans+=V[i]+res;
        }else{
            ans+=V[i];
        }
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>

using namespace std;

const int MX = 1000;

char ans[MX][MX];

void solve2(int x, int y, int p) {
	if (x == 0) {
		for (int i = 0; i < y; i++) ans[p][i] = 'b';
	}
	else if (y == 0) {
		for (int i = 0; i < x; i++) ans[p][i] = 'a';
	}
	else if (x >= y) {
		int g = (x + y - 1) / y;
		int f = x % y;
		if (f == 0) f = y;
		
		solve2(f, y - f, p + 1);
		
		for (int i = 0, j = 0; i < y; i++) {
			for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
			
			if (ans[p + 1][i] == 'a') ans[p][j++] = 'a';
			ans[p][j++] = 'b';
		}
	}
	else {
		int g = (x + y - 1) / x;
		int f = y % x;
		if (f == 0) f = x;
		
		solve2(x - f, f, p + 1);
		
		for (int i = 0, j = 0; i < x; i++) {
			ans[p][j++] = 'a';
			for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'b';
			
			if (ans[p + 1][i] == 'b') ans[p][j++] = 'b';
		}
	}
}

void solve(int x, int y, int z, int p = 0) {
	if (x == 0) {
		solve2(y, z, p);
		for (int i = 0; i < y + z; i++) ans[p][i]++;
	}
	else if (y == 0) {
		solve2(x, z, p);
		for (int i = 0; i < x + z; i++)
			if (ans[p][i] == 'b')
				ans[p][i] = 'c';
	}
	else if (z == 0) {
		solve2(x, y, p);
	}
	else if (x >= y + z) {
		int g = (x + y + z - 1) / (y + z);
		int f = x % (y + z);
		if (f == 0) f = y + z;
		
		if (z >= f) {
			solve(f, y, z - f, p + 1);
			
			for (int i = 0, j = 0; i < y + z; i++) {
				for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
				
				if (ans[p + 1][i] == 'a') {
					ans[p][j++] = 'a';
					ans[p][j++] = 'c';
				}
				else {
					ans[p][j++] = ans[p + 1][i];
				}
			}
		}
		else {
			solve(f - z, z, y + z - f, p + 1);
			
			for (int i = 0, j = 0; i < y + z; i++) {
				for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
				
				if (ans[p + 1][i] == 'c') {
					ans[p][j++] = 'b';
				}
				else {
					ans[p][j++] = 'a';
					ans[p][j++] = ans[p + 1][i] + 1;
				}
			}
		}
	}
	else {
		static string S[MX];
		for (int i = 0; i < x; i++) S[i] = "a";
		for (int i = 0; i < z; i++) S[i % x] += "c";
		for (int i = 0; i < y; i++) S[z % x + i % (x - z % x)] += "b";
		
		set<string> strs;
		for (int i = 0; i < x; i++) strs.insert(S[i]);
		
		string SS[3];
		int cnt[3] = {0, 0, 0}, iter = 0;
		for (auto& s : strs) {
			SS[iter] = s;
			cnt[iter] = 0;
			for (int i = 0; i < x; i++) if (S[i] == s) cnt[iter]++;
			iter++;
		}
		
		solve(cnt[0], cnt[1], cnt[2], p + 1);
		
		for (int i = 0, j = 0; i < x; i++)
			for (char c : SS[ans[p + 1][i] - 'a'])
				ans[p][j++] = c;
	}
}

int main() {
	int x, y, z;
	ignore = scanf("%d %d %d", &x, &y, &z);
	solve(x, y, z);
	ans[0][x + y + z] = 0;
	printf("%s\n", ans[0]);
	
	return 0;
}


Measured memory_bytes: 256
s  = str(input())
t = ""
u = ""
q = int(input())
count_inv = 0
for i in range(q):
  inlis = list(map(str,input().split())) + [0,0]
  if inlis[0] ==  "1":
    count_inv += 1
    count_inv %= 2
  if inlis[0] == "2":
    if inlis[1]  == "1":
      if count_inv == 0:
        u += str(inlis[2])
      else:
        t += str(inlis[2])
      # print(1)
    if inlis[1] == "2":
      if count_inv == 0:
        t += str(inlis[2])
      else:
        u += str(inlis[2])
      # print(2)
  # print(s)
if count_inv == 0:
  u = u[::-1]
  ans = u+s+t
else:
  t = t[::-1]
  s = s[::-1]
  ans = t+s+u
print(ans)
     



Measured memory_bytes: 4444
n,x=map(int, input().split())
l_list=list(map(int, input().split()))
d_list=[]
d=0
count=0
for i in range(n+1):
  if i==0:
    d_list.append(d)
  else:
    d_list.append(d_list[i-1]+l_list[i-1])
  if d_list[i] <= x:
    count+=1
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    string s;
    bool findA = false;
    int Aindex, Zindex;

    cin >> s;

    rep(i,s.size()){
        if(!findA && s[i] == 'A') {
            Aindex = i;
            findA = true;
        }

        if(s[i] == 'Z'){
            Zindex = i;
        }
    }
    
    cout << Zindex - Aindex + 1 << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	const int mod = 1e9 + 7;
	const int N = 2e5;
	vi fac(N + 1);
	fac[0] = 1;
	for (int i = 1; i < N + 1; i++) {
		fac[i] = (ll)i * fac[i - 1] % mod;
	}
	auto power = [&](int a, int b) {
		int ret = 1;
		while (b) {
			if (b & 1) {
				ret = (ll)ret * a % mod;
			}
			b >>= 1;
			a = (ll)a * a % mod;
		}
		return ret;
	};
	vi fac_rev(N + 1);
	for (int i = 0; i < N + 1; i++) {
		fac_rev[i] = power(fac[i], mod - 2);
	}
	auto cnk = [&](int n, int k) {
		if (n < k) return 0LL;
		return (ll)fac[n] * fac_rev[k] % mod * fac_rev[n - k] % mod;
	};
	int h, w;
	int n;
	cin >> h >> w >> n;
	vector<pii> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(all(a));
	vector<vi> dp(n, vi(2, 0));
	for (int i = 0; i < n; i++) {
		dp[i][1] = cnk(a[i].first + a[i].second - 2, a[i].first - 1);
		for (int j = 0; j < i; j++) {
			for (int p = 0; p < 2; p++) {
				if (a[j].second <= a[i].second) {
					int N = a[i].first - a[j].first + 1;
					int M = a[i].second - a[j].second + 1;
					dp[i][p ^ 1] = (dp[i][p ^ 1] + (ll)dp[j][p] * cnk(N + M - 2, N - 1)) % mod;
				}
			}
		}
	}
	int ans = cnk(h + w - 2, h - 1);
	for (int i = 0; i < n; i++) {
		int N = h - a[i].first + 1;
		int M = w - a[i].second + 1;
		int C = cnk(N + M - 2, N - 1);
		ans = (ans + (ll)dp[i][0] * C) % mod;
		ans = (ans - (ll)dp[i][1] * C) % mod;
	}
	cout << (ans + mod) % mod;
}


Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String d = Integer.toString(N);
        int length = d.length();
        long answer = 0;
        if (length % 2 == 0) {
            long base = 1;
            for (int i = 1; i < length; i += 2) {
                answer += 9 * base;
                base *= 100;
            }
        } else {
            long base = 1;
            for (int i = 1; i < length - 1; i += 2) {
                answer += 9 * base;
                base *= 100;
            }
            answer += N - (long) Math.pow(10, length-1) + 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.List.Split (splitOneOf)

main :: IO ()
main = do
  getLine >>= putStrLn . unwords . solve

solve :: String -> [String]
solve = filter (\s -> length s >= 3 && length s <= 6) . splitOneOf " ,."

Measured memory_bytes: 3604
import itertools
a = [int(i) for i in  input().split()]

def cost(a):
    return abs(a[0]-a[1])+abs(a[1]-a[2])

ans = sum(a)
for i in itertools.permutations(a):
    c = cost(i)
    if c < ans:
        ans = c

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, c;
  string S;
  cin >> N >> S;
  c = 0;
  if(N % 2 != 0) cout << "No" << endl;
  else {
    for(int i = 0; i < N / 2; i++) {
      if(S.at(i) != S.at(i + N / 2)) c++;
    }
    if(c == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
x,k,d = list(map(int,input().split()))

x=abs(x)

if x == d:
    if k%2==0:
        print(x)
    else:
        print(0)
elif x < d:
    if k%2==0:
        print(x)
    else:
        print(d-x)
else:
    if x//d < k:
        new_x=x%d
        new_k=k-x//d
        if new_k%2==0:
            print(new_x)
        else:
            print(d-new_x)
    else:
        print(x-k*d)

Measured memory_bytes: 9140
s=input()
l=len(s)
c=s.count('W')
ans='W'*c+'B'*(l-c)
w=0
b=0
for i in range(l):
    if i<=c-1 and s[i]!='W':
        w+=i
    if i>=c and s[i]!='B':
        b+=i
print(b-w)

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;

signed main() {
  int N, K;
  cin>>N>>K;
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    double tmp = 1.0/N;
    int now = i;
    while (now < K) {
      now *= 2;
      tmp /= 2;
    }
    ans += tmp;
  }
  cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {
  int num = 0;
  int x, y;
  cin >> x >> y;
  if (x == 1 && y == 1) { num += 400000; }
  if (x == 1) { num += 300000; }
  if (x == 2) { num += 200000; }
  if (x == 3) { num += 100000; }
  if (y == 1) { num += 300000; }
  if (y == 2) { num += 200000; }
  if (y == 3) { num += 100000; }
  cout << num << endl;
}

Measured memory_bytes: 256
def havec(x_list, y):
    x_list[y-1] = 1
    
def printc(x_list, s):
    for i in range(13):
        if x_list[i] == 0:
            print("%s %d" %(s, i+1))

n = input()
Sp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Ha = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Cl = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Di = [0,0,0,0,0,0,0,0,0,0,0,0,0]

for i in range(n):
    incard = raw_input()
    a, b = incard.split(" ")
    b = int(b)
    
    if a == "S":
        havec(Sp, b)
    elif a == "H":
        havec(Ha, b)
    elif a == "C":
        havec(Cl, b)
    else:
        havec(Di, b)

printc(Sp, "S")
printc(Ha, "H")
printc(Cl, "C")
printc(Di, "D")

Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
int main(){
  char N[3];
  cin >> N;
  if (N[0] == N[1] && N[1] == N[2]){
    cout << "Yes" << endl;
  }
  else if (N[1] == N[2] && N[2] == N[3]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
void solve()
{
	ll h,w;
	rl2(h,w);
	ll i=0,ct=0,ct2=0;


	ct=(h+1)/2;
	// if(h%2==1)
	// 	ct++;



	ct2=(w+1)/2;
	ll ans,ans2;
	if(h==1|w==1)
	{
		cout<<1<<endl;
		return;
	}
	if(w%2==0)
	{
		ans=(w/2)*h;	

		//cout<<ans<<endl;
	}
	else
	{
		ans=((w/2)*h)+ct;
		//cout<<ans<<endl;
	}
	if(h%2==0)
	{
		ans2=(h/2)*w;
	}
	else
	{
		ans2=((h/2)*w)+ct2;
	}
	ans=max(ans,ans2);
	cout<<ans<<endl;
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int x=0;
	for(int i=0;i<s.length();i++)
	{
		x=(x+(s[i]-'0'))%9;
	}
	if(x==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3700
l = list(map(int,input().split()))
count = 0
while True:
    if l[0] == l[1] == l[2]:
        if l[1]%2 == 0:
            print(-1)
            exit()
    for i in range(3):
        if l[i]%2 == 1:
            print(count)
            exit()
    count += 1
    l[0],l[1],l[2] = (l[1]+l[2])//2,(l[0]+l[2])//2,(l[1]+l[0])//2
             
            


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{

    class Program
    {
        static void Main(string[] args)
        {
            string left;
            string right;
            while (true)
            {
                string str = Console.ReadLine();
                if (str == "-")
                {
                    break;
                }
                int m = int.Parse(Console.ReadLine());

                for (int i = 0; i < m; i++)
                {
                    int h = int.Parse(Console.ReadLine());
                    left = str.Substring(0, h);
                    right = str.Substring(h);
                    str = right + left;
                }
                Console.WriteLine(str);
            }
        }
    }
}

Measured memory_bytes: 8936
#pragma region template 1.2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    ll N;
    cin >> N;
    vi h(N);
    REP(i, N)
    {
        cin >> h[i];
    }

    vi dp(N + 1);
    dp[1] = abs(h[1] - h[0]);
    for (ll i = 2; i < N; ++i)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    ll ans = dp[N - 1];

    OUT(ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
 ll n,i;
  cin >> n;
  string ch;
  cin >> ch;
  i=0;
  ll sum=0;
  while(i<n-2)
  {
      if(ch[i]=='A'&&ch[i+1]=='B' && ch[i+2]=='C')
        {sum++;i=i+2;}
      i++;


  }
cout << sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
 
using namespace std;
 
#define INF 1 << 29
#define LL long long int
 
LL const MOD = 1000000007;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n,x;
    cin >> n >> x;
 
    vector<int> result(2*n-1,-1);
 
    if(x == 1 || x == 2*n - 1){
        cout << "No" << endl;
    }else{
        int j = (2*n-1)/2;
        result[j] = x;
        result[j+1] = 1;
        result[j-1] = 2*n-1;
        j = 0;
        for(int i = 2; i < 2*n-1; i++){
            if(i == x){
                continue;
            }
            while(result[j] != -1){
                j++;
            }
            result[j] = i;
            j++;
        }
 
        cout << "Yes" << endl;
 
        for(int i = 0; i < 2*n-1; i++){
            cout << result[i] << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    println(max(0, a - b * 2))
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
a = [int(input()) for _ in range(N)]
a = [s-1 for s in a]
index = a[0]
count = 1
flag = False
while(count <= N):
  if index == 1:
    flag = True
    break
  else:
    count += 1
    index = a[index]

if (flag):
  print(count)
else:
  print(-1)
  

Measured memory_bytes: 17036
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,n;
  cin >> n >> m;
  string s[105];
  int i,j,k;
  for(i=0;i<m;i++){
    cin >> s[i];
  }
  int d[10005]={};
    
  for(i=0;i<n;i++){
    d[i+1]=d[i];
    for(j=0;j<m;j++){ 
      if(s[j][i]=='W') d[i+1]++;
    }
  }
    
  int mi=1000005;
  int l=0;
  for(i=0;i<=n;i++){
    if(i*m+d[n]-2*d[i]<mi){
      l=i;
      mi=i*m+d[n]-2*d[i];
    }
  }
    
  cout << l << " " << l+1 << endl;
  return 0;
}

Measured memory_bytes: 4624
#include<iostream>
using namespace std;
int main()
{
	int a, b, ans;
	cin >> a >> b;
	ans = a + b;
	if(ans < a - b){
		ans = a - b;
	}
	if(ans < a*b){
		ans = a*b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>a(N+1);
	rep(i, N)cin >> a[i+1];
	a.push_back(0);
	vector<int>d;
	int dst = 0;
	rep(i, N + 1) {
		d.push_back(abs(a[i] - a[i + 1]));
		dst += abs(a[i] - a[i + 1]);
	}
	reps(i,1, N+1) {
		cout << dst - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
	}



	return 0;
}


Measured memory_bytes: 2552
# ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
    # compute a toble of factorials (1-idx)
    fact = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        fact[i] = x
    return fact

def get_inv(lim):
    # compute a toble of inverse factorials (1-idx)
    inv = [1] * (lim + 1)
    inv[lim] = pow(fact[lim], MOD - 2, MOD)
    x = inv[lim]
    for i in range(lim - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x
    return inv

def comb(n: int, r: int) -> int:
    # compute nCr (n! / r!(n - r)!)
    return fact[n] * inv[n - r] * inv[r]


def main():
    global MOD, fact, inv
    H, W, A, B = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    fact = get_fact(H + W)
    inv = get_inv(H + W)
    ans = 0
    x, y = H - A - 1, W + A - 2
    for i in range(B, W):
        ans += comb(x + i, i) * comb(y - i, A - 1)
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18804
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    return u;
  if(k<u->key)
    return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL)
    {
      y=x;
      if(z->key<x->key)
	x=x->left;
      else
	x=x->right;
    }
  z->parent=y;
  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;



}

void inorder(Node u){
  if(u!=NIL)
    {
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    }

}
void preorder(Node u){
   if(u!=NIL)
    {
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20436
#include <stdio.h>
#define N 4
int main(){
  int i,n;
  while (scanf("%d",&n)){
    if (n==0)
      break;
    int t,cnt=0;
    for (i=0;i<n/N;i++){
      scanf("%d",&t);
      cnt+=t;
    }
    printf("%d\n",cnt);
  }

  return 0;
}

Measured memory_bytes: 600
a= int (input())
lis=list(map(int,input().split()))
for i in range (1,a):
    lis[i]=lis[i]+lis[i-1]
k=lis[-1]/2
for i in range(a):
    if lis[i]>=k:
        l=lis.index(lis[i])
        break
u=abs(2*lis[l]-lis[-1])
v=abs(2*lis[l-1]-lis[-1])
print(min(u,v))



Measured memory_bytes: 26220
//Bouquet problem

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define sd second
#define ft first
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int p = 1e9 + 7;

// Fast Exponentiation

int fast_pow(int a, int n, int p)
{
    int res = 1;
    a %= p;
    if (a == 0)
        return 0;
    while (n > 0)
    {
        if (n & 1)
            res = (res * a) % p;
        n >>= 1;
        a = (a * a) % p;
    }
    return res;

}

// Modular Inverse

int modInverse(int a, int p)
{
    return fast_pow(a, p - 2, p);
}

// Fermat's Little Method ncr calculation

int ncrfermat(int n, int r, int p)
{
    if (r == 0)
        return 1;

    if (r > (n - r))
        r = n - r;

    int x = 1, y = 1;

    for (int i = 0; i < r; i++)
    {
        x = (x * (n - i)) % p;
        y = (y * (i + 1)) % p;
    }
    return (x * (modInverse(y, p) % p)) % p;
}

int32_t main()
{
    ios;
    int n, a, b;
    cin >> n >> a >> b;
    int sum = fast_pow(2, n, p) - 1;
    sum = (sum - (ncrfermat(n, a, p) + ncrfermat(n, b, p)) + p) % p;
    cout << (sum+p)%p << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N_ = 505;

int N;
int P[N_*N_];
int A[N_*N_];

priority_queue<int, vector<int>, greater<int> > pq;
bool used[N_*N_];

int get() {
	while(!pq.empty()) {
		int t = pq.top();
		if(!used[t]) {
			used[t] = true;
			return t;
		}
		pq.pop();
	}
	return N*N+1;
}

int C[N_];

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		int x; scanf("%d", &x);
		P[x] = i;
	}

	for(int x = 1; x <= N*N; x++)
		pq.push(x);

	for(int x = 1; x <= N*N; x++) if(P[x] > 0) {
		int i = P[x]; // (i, x)
		for(int k = 1; k < i; k++) A[get()] = i;
		used[x] = true;
		A[x] = i;
	}

	for(int x = 1; x <= N*N; x++) if(P[x] > 0) {
		int i = P[x]; // (i, x)
		for(int k = i+1; k <= N; k++) A[get()] = i;
	}

	for(int x = 1; x <= N*N; x++) {
		int v = A[x];
		if(v == 0) return 0 & puts("No");
		if(++C[v] == v) {
			if(P[x] != v) return 0 & puts("No");
		}
	}
	for(int i = 1; i <= N; i++) {
		if(C[i] != N) return 0 & puts("No");
	}

	puts("Yes");
	for(int x = 1; x <= N*N; x++)
		printf("%d%c", A[x], (x+1 <= N*N) ? ' ' : '\n');

	return 0;
}


Measured memory_bytes: 4212
x = int(input())

num = x // 100



dp = ["?"] * (x+1)
dp[0] = "1"

for i in range(1,x+1):
    if i <= 99:
        dp[i] = "0"
    elif i in (100,101,102,103,104,105):
        dp[i] = "1"
    else:
        if "1" in(dp[i-100],dp[i-101],dp[i-102],dp[i-103],dp[i-104],dp[i-105]):
            dp[i] = "1"
        else:
            dp[i] = "0"

            
print(dp[x])


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

#define REP(i, n) for(int i = 0; i< n; i++)

using namespace std;

int n, m, q;
vector<int> a, b, c, d;

long long score (vector<int> A)
{
    long long ans = 0;
    REP(i, q){
        if(A[b[i]] - A[a[i]] == c[i])
            ans += d[i];
    }
    return ans;
}

long long dfs(vector<int> &A){
    if(A.size() == n){
        return score(A);
    }
    int prev = (A.empty() ? 1 : A.back());
    long long res = 0;

    for (int i = prev; i <= m; i++){
        A.push_back(i);
        res = max(res, dfs(A));
        A.pop_back();
    }
    return res;
}

int main(void)
{
    cin >> n >> m >> q;
    a.resize(q);b.resize(q);
    c.resize(q);
    d.resize(q);
    REP(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3600
const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function nextLine(k::Int32)
    x,y,c=split(input())
    intSub(x)%2k+1,(intSub(y)+(c=="W")k)%2k+1
end
function main()
    n,k=intLine()
    g=Array{Int32,1}[[0for j in 1:2k]for i in 1:2k]
    for i in 1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    g=cumsum(map(cumsum,g))
    m=0
    for i in 1:2k
        for j in 1:2k
            a=0
            for x in -1:2
                for y in -1:2
                    if(x+y)%2!=0;continue;end
                    v,w=i+x*k,j+y*k
                    if v>0<w;a+=g[min(2k,v)][min(2k,w)];end
                    if v>k&&w>0;a-=g[min(2k,v-k)][min(2k,w)];end
                    if w>k&&v>0;a-=g[min(2k,v)][min(2k,w-k)];end
                    if v>k<w;a+=g[min(2k,v-k)][min(2k,w-k)];end
                end
            end
            m=max(m,a)
        end
    end
    println(m)
end
main()

Measured memory_bytes: 206532
s = int(input())
ls = [s]
a = 1

while 1 > 0:
    a += 1
    if s % 2 == 0:
        t = s //2
    else:
        t = 3 * s + 1
    if t in ls:
        print(a)
        break
    else:
        s = t
        ls.append(s)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if (abs(c-a)<=d)
		printf("Yes\n");
	else
		{
			if(abs(b-a)<=d && abs(c-b)<=d)
			printf("Yes\n");
			else
			printf("No\n");
		}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)cout << (b - a) / 2 << endl;
	else {
		int memo = min(b - 1 + a - 1, n - b + n - a);
		cout << (memo + 1) / 2 << endl;
	}
	ggr
}


Measured memory_bytes: 764
N = int(input())
Towns = [[i] + list(map(int, input().split())) for i in range(N)]


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


E = []
# xについてソート
Towns.sort(key=lambda t: t[1])
for i in range(1, N):
    t_prev, t_now = Towns[i - 1], Towns[i]
    E.append([t_prev[0], t_now[0], t_now[1] - t_prev[1]])
# yについてソート
Towns.sort(key=lambda t: t[2])
for i in range(1, N):
    t_prev, t_now = Towns[i - 1], Towns[i]
    E.append([t_prev[0], t_now[0], t_now[2] - t_prev[2]])

E.sort(reverse=True, key=lambda e: e[2])
UF = UnionFind(N)

MST_cost = 0
i = 0
# 辺のコストが小さいものから、閉路を作らないように、木を構成する
# 最小全域木の必要辺は(頂点数-1)本
while i != N - 1:
    x, y, cost = E.pop()
    # 同じ辺集合に属していないならば（閉路が生まれないならば）
    if not UF.same(x, y):
        MST_cost += cost
        UF.union(x, y)
        i += 1

print(MST_cost)


Measured memory_bytes: 56212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  cout << 2 * count(all(s), '+') - 4 <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i,j;
  scanf("%d",&n);
  int c[n],s[n],f[n];
  for(i=0;i<n-1;i++) scanf("%d %d %d",&c[i],&s[i],&f[i]);
  for(i=0;i<n-1;i++){
    int t=0;
    for(j=i;j<n-1;j++){
      if(t<s[j]) t = s[j];
      else if(t%f[j]==0);
      else t = t+f[j] -(t%f[j]);
      t += c[j];
    }
    printf("%d\n",t);
  }
  printf("0\n");
  return 0;
}

Measured memory_bytes: 128
s = input()
q = int(input())

query_list = []
for _ in range(q):
    query_list += [input()]


def query1(s):
    s = s[::-1]
    return s

def query2_1(letters,s):
    s = letters[4] + s
    return s

def query2_2(letters,s):
    s = s +  letters[4]
    return s

true_position = True
left = ""
right = ""

for i in range(q):
    if len(query_list[i])==1:
        true_position = not true_position
        # print(s)
    else:
        if query_list[i][2]=="1":
            if true_position:
                left = query_list[i][4] + left
            else:
                right = right + query_list[i][4]
        elif query_list[i][2]=="2":
            if true_position:
                right = right + query_list[i][4]
            else:
                left = query_list[i][4] + left

if true_position:
    ans = left + s + right
else:
    ans = right[::-1]+s[::-1]+left[::-1]

print(ans)

Measured memory_bytes: 17064
K = int(input())
total = 0

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(a,K):
    for c in range(b,K):
      if a==b and b==c:
        total += gdc(c+1, gdc(b+1, a+1))
      elif a==b or b==c or a==c:
        total += 3*gdc(c+1, gdc(b+1, a+1))
      else:
        total += 6*gdc(c+1, gdc(b+1, a+1))
print(total)

Measured memory_bytes: 9212
import numpy as np
import bisect
import sys
input = sys.stdin.readline

(A,B,Q) = map(int,input().split())
inf = 10**12
s = [0] * (A+2)
t = [0] * (B+2)
s[0] = -inf
t[0] = -inf
s[A+1] = inf
t[B+1] = inf

for i in range(A):
    s[i+1] = int(input())
for i in range(B):
    t[i+1] = int(input())

for _ in range(Q):
    x = int(input())
    p = bisect.bisect_left(s,x)
    q = bisect.bisect_left(t,x)
    spx = s[p] - x
    tqx = t[q] - x
    xtq1 = x - t[q-1]
    xsp1 = x - s[p-1]
    ans = min(max(spx, tqx),
              max(xsp1, xtq1),
                  spx*2 + xtq1,
                  spx + xtq1*2,
                  tqx*2 + xsp1,
                  t[q]-x + xsp1*2)
    print(ans)

Measured memory_bytes: 21128