akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	int ans = 0;
	cin >> s1 >> s2;
	for (int i = 0; i < 3; i++) ans += s1[i] == s2[i];
	cout << ans << endl;
	return 0;
}

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=105, mod=1e9+7;
inline void add(int &x,int y) {x=(x+y>=mod) ? (x+y-mod) : (x+y);}

int n,a[N];
int f[N/2][N][N];

int main() {
	n=rd();
	for(int i=1;i<=2*n-1;i++) a[i]=rd();
	sort(a+1,a+2*n);
	
	int p=lower_bound(a+1,a+2*n,a[n])-a;
	f[n][1][0]=1;
	
	for(int i=n-1;i>=1;i--) {
		int al=(a[i]!=a[i+1]), ar=(a[2*n-i]!=a[2*n-i-1]);
		
		for(int l=0;l<=2*n-1;++l)
			for(int r=0;r+l<=2*n-1;++r) if(f[i+1][l][r]) {
				int &t=f[i+1][l][r];	
				for(int dl=1;dl<=l+al;++dl) 
					add(f[i][l+al-dl+1][r+ar+(dl>1)],t);
				for(int dr=1;dr<=r+ar;++dr) 
					add(f[i][l+al+1][r+ar-dr],t);
			}
	}
	
	int ans=0;
	for(int l=0;l<=2*n-1;++l)
		for(int r=0;r+l<=2*n-1;++r)
			add(ans,f[1][l][r]);
	cout<<ans<<'\n';
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL N,A,B;

int main(){
	scanf("%lld%lld%lld" , &N , &A , &B);
	if(A>B){
		printf("0\n");
	} else if(N==(LL)1){
		printf("%d\n" , A == B ? 1 : 0);
	} else {
		printf("%lld\n" , B*(N-1)+A-(A*(N-1)+B)+1);
	}
	return 0;
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main(){

  string s;
  cin >> s;
  cout << s.substr(0, s.size() - 8) << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int a,b;
  if(M%2==1){
    a=1;
    b=M;
    while(a<b){
        printf("%d %d\n",a++,b--);
        //++a; --b;
    }
    a=M+1;
    b=M*2+1;
    while(a<b){
        printf("%d %d\n",a++,b--);
        //++a; --b;
    }
  }else{
    a=1;
    b=M+1;
    while(a<b){
        printf("%d %d\n",a,b);
        ++a; --b;
    }
    a=M+2;
    b=M*2+1;
    while(a<b){
        printf("%d %d\n",a,b);
        ++a; --b;
    }
  }
}


Measured memory_bytes: 3748
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] X = new int[M];
		int[] Y = new int[M];
		int[] Z = new int[M];
		for (int i=0;i<M;i++) {
			X[i]=sc.nextInt();
			Y[i]=sc.nextInt();
			Z[i]=sc.nextInt();
		}
		UnionFind uni = new UnionFind(N);
		for (int i=0;i<M;i++) {
			uni.connect(X[i]-1,Y[i]-1);
		}
		int ans=0;
		for (int i=0;i<N;i++) {
			if (uni.Parent.get(i)<0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

class UnionFind {
	List<Integer> Parent;
	UnionFind(int N) {
		Parent = new ArrayList<Integer>();
		Integer[] values = new Integer[N];
		Arrays.fill(values, -1);
		Parent.addAll(Arrays.asList(values));
	}
	int root(int A) {
		if (Parent.get(A) < 0)
			return A;
		int root = root(Parent.get(A));
		Parent.set(A, root);
		return root;
	}
	int size(int A) {
		return -Parent.get(root(A));
	}

	boolean connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}

		if (size(A) < size(B)) {
			int temp = A;
			A = B;
			B = temp;
		}

		Parent.set(A, Parent.get(A) + Parent.get(B));
		Parent.set(B, A);

		return true;
	}
}

Measured memory_bytes: 91956
#include<stdio.h>
int main(void){
    double l,b,r;
    scanf("%lf",&r);
    b=3.141592653589*r*r*1.0;
    l=3.141592653589*2*r*1.0;
    printf("%.6lf %.6lf\n",b,l);
return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

struct tree{
    vector<tree> left;
    vector<tree> right;
};

// <exp> := ( <exp> , <exp> ) | ""
tree parse(int& index, const string& str){
    tree ret;
    if(str[index]=='(') index++;
    if(str[index]!=',') {
        //<exp>
        ret.left.push_back(parse(index,str));
    }
    if(str[index]==',')index++;
    if(str[index]!=')') {
        //<exp>
        ret.right.push_back(parse(index,str));
    }
    if(str[index]==')')index++;
    return ret;
}

string intersection_tree(tree a, tree b){
    string res=",";

    if(!a.left.empty() && !b.left.empty()){
        res="("+intersection_tree(a.left[0],b.left[0]) +res;
    }else{
        res="("+res;
    }

    if(!a.right.empty() && !b.right.empty()){
        res=res+intersection_tree(a.right[0],b.right[0]) +")";
    }else{
        res=res+")";
    }
    return res;
}

string union_tree(tree a, tree b){
    string res=",";
    tree tmp1,tmp2;
    if(!a.left.empty() || !b.left.empty()){
        if(a.left.size()!=0){
            tmp1=a.left[0];
        }else{
            tmp1.left.clear();
            tmp1.right.clear();
        }
        if(b.left.size()!=0){
            tmp2=b.left[0];
        }else{
            tmp2.left.clear();
            tmp2.right.clear();
        }
        res="("+union_tree(tmp1,tmp2) +res;
    }else{
        res="("+res;
    }

    if(!a.right.empty() || !b.right.empty()){
        if(a.right.size()!=0){
            tmp1=a.right[0];
        }else{
            tmp1.left.clear();
            tmp1.right.clear();
        }
        if(b.right.size()!=0){
            tmp2=b.right[0];
        }else{
            tmp2.left.clear();
            tmp2.right.clear();
        }
        res=res+union_tree(tmp1, tmp2) +")";
    }else{
        res=res+")";
    }
    return res;
}

int main(){
    int index=0;
    char mode;
    string a,b;
    while(cin>>mode>>a>>b){
        tree tmp1,tmp2;
        //cout<<a<<endl;
        //cout<<b<<endl;
        index=0;
        tmp1=parse(index,a);
        index=0;
        tmp2=parse(index,b);
        if(mode=='i')
            cout<<intersection_tree(tmp1,tmp2)<<endl;
        else
            cout<<union_tree(tmp1,tmp2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define LL long long
#define db double

using namespace std;


typedef pair<int, int> pii;
#define X first
#define Y second
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool fg = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            fg = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (fg) {
        x = -x;
    }
}

const int MAXN = 100100;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;

LL h, k, w, more, res = 1;

LL f[(1 << 8)][11][101];
LL pos[(1 << 8)], cnt;

void init() {
	for(int i = 0; i < (1 << w - 1); i++) {
		if(! (i & (i << 1))) pos[++cnt] = i; 
	}
}

signed main() {
	read(h), read(w), read(k);
	init();
	f[0][1][0] = 1;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= cnt; j++) {
			int s = pos[j];
			for(int p = 1; p <= cnt; p++) {
				int s2 = pos[p];
				for(int l = 1; l <= w; l++) {
					if((1 << (l - 1)) & s2) {
						f[s2][l + 1][i] = (f[s2][l + 1][i] + f[s][l][i - 1]) % mod;
						continue;
					}
					if((1 << (l - 2)) & s2) {
						f[s2][l - 1][i] = (f[s2][l - 1][i] + f[s][l][i - 1]) % mod;
						continue;
					}
					f[s2][l][i] = (f[s2][l][i] + f[s][l][i - 1]) % mod;
				}
			}
		}
	}
	LL ans = 0;
	for(int i = 0; i < (1 << w - 1); i++) {
		ans += f[i][k][h];
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> have(n, false);
  for(int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for(int j = 0; j < d; j++) {
      int a;
      cin >> a;
      a--;
      have[a] = true;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if (!have[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int N;
	cin >> N;
	vector<ll> A(N), B(N), C(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) cin >> C[i];

	sort(all(A)); sort(all(B)); sort(all(C));
	vector<ll> b(N);
	int i;
	i = 0;
	rep(k,N) {
		if(k) b[k] = b[k-1];
		else b[k] = 0;
		while (i < N && A[i] < B[k]) i++;
		b[k] += i;
	}
	ll res = 0;
	i = 0;
	rep(k,N) {
		while(i < N && B[i] < C[k]) i++;
		if(i) res += b[i-1];
	}
	cout << res << endl;
	return 0;
}


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

int main(){
    int n,r=0,a;cin>>n;a=n;
    while(n!=0){
        r+=n%10;
        n/=10;
    }
    if(a%r==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  vector<int> b(101, 0);
  int pop = -1000;
  bool flag = false;
  vector<int> v;
  cin >> N;
  REP(i, N) {
    cin >> b[i];
    if((b[i] == (i + 1)) && (pop < i)) {
      pop = i;
    }
  }

  if(pop < 0) flag = true;
  else v.pb(b[pop]);
  while(v.size() < N) {
    if(flag) break;
    b.erase(b.begin() + pop);
    pop = -1000;
    REP(i, N) {
      if((b[i] == (i + 1)) && (pop < i)) {
        pop = i;
      }
    }
    if(pop < 0) flag = true;
    else v.pb(b[pop]);
  }

  if(flag) {
    cout << -1 << endl;
  }
  else {
    REP(i, N) {
      cout << v.back() << endl;
      v.pop_back();
    }
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		n = 1000 - n;
		int ans(0);
		ans += (n / 500);
		n %= 500;
		ans += (n / 100);
		n %= 100;
		ans += (n / 50);
		n %= 50;
		ans += (n / 10);
		n %= 10;
		ans += (n / 5);
		n %= 5;
		ans += n;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

count = 0

for i in range(1, N+1):
  for j in range(1, min(i,N-i-1)+1):
    if S[i-j] != S[i] and S[i+j] != S[i] and S[i+j] != S[i-j]:
      count+=1
      
print((r * g * b) - count)      
    

Measured memory_bytes: 9200
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  char fromswap;
  char toswap; 
  if (S[0] == 'R') {
    fromswap = 'L';
    toswap = 'R';
  }
  else {
    fromswap = 'R';
    toswap = 'L';
  }
  ll swapcount = 0;
  ll swapl = 0, swapr = 0;
  rep (i, S.size()) {
    if (swapcount == K) break;
    if (S[i] == fromswap && swapl == 0) {
      swapl = i;
    }
    if (S[i] != fromswap && swapl != 0) {
      swapr = i;
      for (int j = swapl; j < swapr; ++j) {
        S[j] = toswap;
      }
      swapl = 0;
      swapr = 0;
      swapcount++;
    }
    if (i == S.size() - 1 && swapl != 0) {
      swapr = i + 1;
      for (int j = swapl; j < swapr; ++j) {
        S[j] = toswap;
      }
      swapl = 0;
      swapr = 0;
      swapcount++;
      break;
    }
  }
  ll happyness = 0;
  rep (i, S.size()) {
    if (S[i] == 'R' && i != S.size() - 1) {
      if (S[i+1] == 'R') happyness++;
    }
    else if (S[i] == 'L' && i != 0) {
      if (S[i-1] == 'L') happyness++;
    }
  }
  cout << happyness << endl;
  return 0;
}



Measured memory_bytes: 512
/*=======================
Author    : Shounak Dey
Filename  : 1180a.cpp
=======================	*/
 
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
 
#define PB push_back
#define MK make_pair 
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);
 
 
#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
 
 
#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
 
vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}
 
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}
 
int main()
{
	fast_io;
	char a,b;
	cin >> a >> b >> b;
	if(a=='D')
	    b = (b=='H')?'D':'H';
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;

int main(){
  int no, i;
  stack<int> sum;
  while(cin >> no, no) {
      for( i = 1;no > 8; i*=10){
	sum.push(no % 8);
	no /= 8;

      }
      sum.push(no);
      while(sum.size()) {
	no = sum.top();
	if(no == 4) no++;
	else if(no  >= 5) no+=2;
	cout << no;
	sum.pop();
      }
      cout << endl;
  }
  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<long long> L(N);
    for (int i = 0; i < N; ++i) {
        cin >> L[i];
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            for (int k = j + 1; k < N; ++k) {
                if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
                    if (L[i] + L[j] + L[k] > max(max(L[i], L[j]), L[k]) * 2) {
                        ++ans;
                    }
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
// 2019/03/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int n, m;
	cin >> n;

	while(true){
		char c;
		cin >> c;

		switch(c){
		case '+':
			cin >> m;
			n += m;
			break;
		case '-':
			cin >> m;
			n -= m;
			break;
		case '*':
			cin >> m;
			n *= m;
			break;
		case '/':
			cin >> m;
			n /= m;
			break;
		case '=':
			cout << n << endl;
			return 0;
		default:
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 3072
import java.io.*
import java.util.*

fun solve(N: Int) {
    val ans = (3..9).map{ create753(it) }.flatten().distinct()
    .filter{ it.toInt() <= N }
    .filter{
        "3" in it && "5" in it && "7" in it
    }.size
    println(ans)
}

fun create753(digit: Int): List<String>{
    var lis = listOf("3", "5", "7")
    repeat(digit - 1){
        lis = lis.flatMap{ listOf(it+"3", it+"5", it+"7") }
    }
    return lis
}

fun powerOfTen(x: Int): Int {
    var n = x
    var count = 0
    while (n > 0) {
        n /= 10
        count++
    }
    return count
}

tailrec fun Int.pow(n: Int): Int = if (n <= 1) this else this * this.pow(n - 1)

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}


Measured memory_bytes: 41480
#include <iostream>
using namespace std;
typedef long long ll;
int ng[100010];
ll dp[100010] = {};
ll inf = 1e9+7;
int N,M;
int main(){
    cin >> N >> M;
    int a;
    for(int i=1;i<=M;i++){
        cin >> a;
        ng[a] = 1;
    }
    dp[0] = 1;
    for(int i=1;i<=N;i++){
        if(ng[i]) continue;
        (dp[i] += dp[i-1])%=inf;
        if(i>=2) (dp[i] += dp[i-2])%=inf;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1408
moji=input()
cycle=int(input())
flont_or_back=0
flont=""
back=""
for i in range(cycle):
    line=input()
    if line[0]=="1":
        flont_or_back+=1
    else:
        fi=line[2]
        ci=line[4]
        if flont_or_back%2==0:
            if fi=="1":
                flont=ci+flont
            else:
                back+=ci
        else:
            if fi=="1":
                back+=ci
            else:
                flont=ci+flont
moji=flont+moji+back
if flont_or_back%2==0:
    print(moji)
else:
    print(moji[::-1])

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

/*
  Idea : imagine a segment from [0..N] is uncovered
  A ball x with frequency[x] can cover a range from [x-f[x]..x]
  let's call [x-f[x]..x] is a segment
  minimum changes is the number of uncovered interval

  when we change ball[i] to y, then :
  - segment [ball[i]-f[ball[i]]..ball[i]] change to
    segment [ball[i]-f[ball[i]]+1..ball[i]]
  - segment [y-f[y]..y] change to
    segment [y-f[y]-1..y]

  maintain the number of uncovered range each query
*/

int cnt[200005], ball[200005];
int covered[200005];
int uncovered = 0;


int main(){
  ios_base :: sync_with_stdio(false);

  int n, q;
  cin >> n >> q;
  for(int i=1; i<=n; i++){
    cin >> ball[i];
    cnt[ball[i]]++;
  }

  for(int i=1; i<=n; i++){
    for(int j=i; j>i-cnt[i] && j>0; j--)
      covered[j]++;
  }

  for(int i=1; i<=n; i++) uncovered += (covered[i] == 0);

  while(q--){
    int idx, num;
    cin >> idx >> num;
    int b = ball[idx];

    if(b-cnt[b]+1 > 0){
      covered[b-cnt[b]+1]--;
      if(covered[b-cnt[b]+1] == 0) uncovered++;
    }
    cnt[b]--;

    if(num-cnt[num] > 0){
      covered[num-cnt[num]]++;
      if(covered[num-cnt[num]] == 1) uncovered--;
    }
    cnt[num]++;
    ball[idx] = num;
    cout << uncovered << endl;
  }

  return 0;
}

Measured memory_bytes: 5956
#include <bits/stdc++.h>
using namespace std;
int n,m,dp[103][103],dir[2][2]={{0,1},{1,0}};
char c[103][103];
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) cin>>c[i][j];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) dp[i][j]=1e9;
	if (c[1][1]=='#') dp[1][1]=1;
	else dp[1][1]=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			for (int k=0;k<2;k++){
				int u=i+dir[k][0],v=j+dir[k][1]; 
				if (u>n && v>m) continue;
				if (c[u][v]==c[i][j] || c[u][v]=='.') dp[u][v]=min(dp[u][v],dp[i][j]);
				else dp[u][v]=min(dp[u][v],dp[i][j]+1);
			}
	cout<<dp[n][m];
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a , b;
	char op;
	
	while(scanf("%d %c %d" , &a , &op , &b))
	{
		if(op == '?')
		{
			break;
		}
		switch(op)
		{
			case '+':
				printf("%d\n" , a + b);
				break;
			case '-':
				printf("%d\n" , a - b);
				break;
			case '*':
				printf("%d\n" , a * b);
				break;
			case '/':
				printf("%d\n" , a / b);
				break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 2716
#include<cstdio>
#include<cctype>
#include<set>
using namespace std;
int n;
set<char> s;
char ch[2333];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",ch);
		s.insert(ch[0]);
	}
	if(s.size()==3)puts("Three");
	else puts("Four");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;

int d[100], n, k, dp[100][6];
// 0:aa, 1:bb, 2:cc, 3:a, 4:b, 5:c

int main() {
  int a, b;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) d[i] = 0;
  for (int i = 0; i < k; i++) scanf("%d%d", &a, &b), d[a-1] = b;
  dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = dp[0][5] = 0;
  if (d[0] == 0) dp[0][3] = dp[0][4] = dp[0][5] = 1;
  if (d[0] == 1) dp[0][3] = 1;
  if (d[0] == 2) dp[0][4] = 1;
  if (d[0] == 3) dp[0][5] = 1;
  for (int i = 1; i < n; i++) {
    dp[i][0] = dp[i-1][3];
    dp[i][1] = dp[i-1][4];
    dp[i][2] = dp[i-1][5];
    dp[i][3] = dp[i-1][1] + dp[i-1][2] + dp[i-1][4] + dp[i-1][5];
    dp[i][4] = dp[i-1][0] + dp[i-1][2] + dp[i-1][3] + dp[i-1][5];
    dp[i][5] = dp[i-1][0] + dp[i-1][1] + dp[i-1][3] + dp[i-1][4];
    for (int j = 0; j < 6; j++) dp[i][j] = dp[i][j] % 10000;
    if (d[i] == 0) continue;
    if (d[i] == 1) dp[i][1] = dp[i][2] = dp[i][4] = dp[i][5] = 0;
    if (d[i] == 2) dp[i][0] = dp[i][2] = dp[i][3] = dp[i][5] = 0;
    if (d[i] == 3) dp[i][0] = dp[i][1] = dp[i][3] = dp[i][4] = 0;
  }
  int ans = 0;
  for (int j = 0; j < 6; j++) ans += dp[n-1][j];
  printf("%d\n", ans % 10000);
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m, k;
  cin >> n >> m >> k;
  
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i * (m - j) + (n - i) * j == k) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  ll res = x % 11;
  ans += 2 * (x / 11);
  if (res == 0) {
    cout << ans;
  } else if (res - 6 > 0) {
    cout << ans + 2;
  } else {
    cout << ans + 1;
  }
  return 0;
}

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

#define rep(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define ff first
#define ss second
#define fill(x,v) memset(x, v, sizeof(x))


typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

vi arr;

int main(){
  ll a,b;
  cin >> a >> b;
  ll suma = a+b;
  if(suma%2) cout << "IMPOSSIBLE" << endl;
  else{
  ll rpta = suma/2;
  cout << rpta << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W>=x+r&&H>=y+r&&0<=x-r&&0<=y-r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  if (s=="ABC")
    cout << "ARC" << endl;
  if (s=="ARC")
    cout << "ABC" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 * 2;

int main() {
	int n, k;
	cin >> n >> k;
	int num = 1;
	rep(i, n){
		num += min(num, k);
	}
	cout << num << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll gcd(ll a, ll b) {
	if(b == 0) return a;
	else return gcd(b, a % b);
}

ll N, M;
string S, T;
map<ll, char> D;

void solve() {
	cin >> N >> M;
	cin >> S >> T;
	ll L = N * M / gcd(N, M);
	rep(i, 0, N) {
		D[L / N * i] = S[i];
	}
	rep(i, 0, M) {
		if(D.count(L / M * i) && D[L / M * i] != T[i]) {
			cout << "-1\n";
			return ;
		}
	}
	cout << L << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

typedef long long ll;

const int N = 1e9;

ll s;

int main()
{
	std::cin >> s; int c = (s + N - 1) / N;
	std::cout << "0 0 " << N << " 1 " << 1ll * N * c - s << " " << c << std::endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	cout << N - K + 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;
int kai(int);

int main(){
    int N;
    scanf("%d",&N);
    vector<int> P;
    vector<int> Q;
    for(int i=0;i<N;i++){
        int a;
        scanf("%d",&a);
        P.push_back(a);
    }
    for(int i=0;i<N;i++){
        int a;
        scanf("%d",&a);
        Q.push_back(a);
    }
    vector<int> per;
    for(int i=1;i<=N;i++){
        per.push_back(i);
    }
    int A;
    int B;
    for(int i=0;i<kai(N);i++){
        
        if(equal(begin(P),end(P),begin(per),end(per))){
            A=i;
        }
        if(equal(begin(Q),end(Q),begin(per),end(per))){
            B=i;
        }
        next_permutation(per.begin(),per.end());
    }
    cout<<abs(A-B)<<"\n";

}

int kai(int N){
    int sum=1;
    for(int i=1;i<=N;i++){
        sum = sum*i;
    }
    return sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b,x;
    cin>>a>>b>>x;
    if(a==x){
        cout<<"YES"<<endl;
    }else if(a<x&&a+b>x){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 250//ヒープの最大サイズ
#define NIL 0//初期化用

/*構造体（木）*/
typedef struct {
  int key;
  int p_key;
  int r_key;
  int l_key;
}Node;

Node Tree[MAX];

/*プロトタイプ宣言*/
void makeTree(int );

/*グローバル変数*/
int heap_size = 0;


main() {

  int i;//counter

  scanf("%d", &heap_size);
  /**/
  //木を初期化する
  for(i = 1; i <= heap_size; i++) {
    Tree[i].key = NIL;
    Tree[i].p_key = NIL;
    Tree[i].r_key = NIL;
    Tree[i].l_key = NIL;
  }

  //keyをそれぞれ入力していく
  for(i = 1; i <= heap_size; i++) {
    scanf("%d", /**/&Tree[i].key); 
  }

  //makeTree関数で木を作成する
  for(i = 1; i <= heap_size; i++) {
    makeTree(i);
  }



  //結果出力
  for(i = 1; i <= heap_size; i++) {

    printf("node %d: key = %d, ", i, Tree[i].key);

    //Treeの要素の親がいればそれを表示
    if(Tree[i].p_key != NIL) {
      printf("parent key = %d, ", Tree[i].p_key);
    }

    //Treeの要素の左がいればそれを表示
    if(Tree[i].l_key != NIL) {
      printf("left key = %d, ", Tree[i].l_key);
    }

    //Treeの要素の右がいればそれを表示
    if(Tree[i].r_key != NIL) {
      printf("right key = %d, ", Tree[i].r_key);
    }

    printf("\n");

  }
return 0;
}



/*
*    makeTree関数...ヒープソートによって木を作成する。
*/
void makeTree(int u) {

  //二つ目以降は親がいる
  //今回は完全２分木なので[u/2]をして、二つの子に親をつける
  if(u != 1) {
    Tree[u].p_key = Tree[u/2].key;
  }

  //2倍したuでもheap_sizeを超さない＝左の子供は確実に存在する
  if(2*u <= heap_size) {
    Tree[u].l_key = Tree[2*u].key;
  }

  //2倍＋１したuでもheap_sizeを超さない＝右の子供は確実に存在する
  if(2*u+1 <= heap_size) {
    Tree[u].r_key = Tree[2*u+1].key;
  }

}

Measured memory_bytes: 604
#include<iostream>
using namespace std;

int main(){
    int N;
    int a = 0;
    string S[110];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    for(int i = 0; i < N; i++){
        if(S[i]=="Y"){
            a = 1;
        }
    }
    if(a==0){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		
		int tmp, k;
		
		for(int i = 1; i < N; i++) {
			for(int j = 0; j < N - 1; j++) {
				System.out.print(A[j] + " ");
			}
			System.out.println(A[N - 1]);
			
			tmp = A[i];
			k = i - 1;
			
			while(k >= 0 && A[k] > tmp) {
				A[k + 1] = A[k];
				k--;
			}
			
			A[k + 1] = tmp;
		}
		
		for(int i = 0; i < N - 1; i++) {
			System.out.print(A[i] + " ");
		}
		System.out.println(A[N - 1]);
	}
}

Measured memory_bytes: 31912
import sys
from collections import Counter
N = int(input())
A = [int(_) for _ in input().split()]

S = [0] * (N + 1)
for n in range(N):
    S[n + 1] = S[n] + A[n]

ans = 0
for value in Counter(S).values():
    if value >= 2:
        ans += value * (value - 1) // 2
print(ans)

Measured memory_bytes: 41496
#include <iostream>
#include <cmath>
using namespace std;
const long long MOD = 1000000007;
/*
// N^P modM の計算
typedef long long int ll;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/
long long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long long C(long long N,long long K)
{
	long long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

int main()
{
    long long n,a,b;
    cin >> n >> a >> b;
    
    long long int total = power(2, n) - 1;
    //cout << total << endl;
    /*
    // 前処理
    COMinit();
    // 計算例
    long long nCa = COM(n, a);
    long long nCb = COM(n, b);
    */
    long long nCa = C(n, a);
    long long nCb = C(n, b);
    //cout << nCa << "," << nCb << endl;
    total -= (nCa + nCb);
    
    /*
    if(total <= 0) total += MOD;
    cout << total << endl;
    */
    cout<<(total%MOD+MOD)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int D = sc.nextInt();
		int N = sc.nextInt();

		int x = (int) Math.pow(100, D);

		if(N==100)  N++;
		out.println(x*N);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

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; }

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

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

    int c0 = 0;
    int c1 = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0') {
            c0++;
        }
    }
    c1 = s.length() - c0;

    cout << min(c0, c1) * 2 << endl;
    return 0;
}


Measured memory_bytes: 3760
r = 0
l = 0
while True:
    try:
        a, b, c = map(int, input().split(','))
        if a == b:
            l += 1
        else:
            if a**2 + b**2 == c**2:
                r += 1
    except:
        print(r)
        print(l)
        break

Measured memory_bytes: 7556
import java.util.Scanner;

public class Main {

	static char[] s;
	static int idx;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		while(N--!=0){
			String str = cin.next();
			idx=0;
			s = new char[101];
			for(int i = 0; i < str.length(); i++){
				s[i]=str.charAt(i);
			}
			System.out.println(expression());
		}
	}
	static int expression(){
		int res = term();
		while(s[idx]=='+'||s[idx]=='-'){
			if(s[idx]=='+'){
				idx++;
				res += term();
			}
			else{
				idx++;
				res -= term();
			}
		}
		return res;
	}
	static int term(){
		int res = fact();
		while(s[idx]=='*' || s[idx]=='/'){
			if(s[idx]=='*'){
				idx++;
				res *= fact();
			}
			else{
				idx++;
				res /= fact();
			}
		}
		return res;
	}
	static int fact(){
		int res;
		if(s[idx]=='('){
			idx++;
			res = expression();
			idx++;
		}
		else{
			//res = s[idx++]-'0';
			res = value();
		}
		return res;
	}
	static int value(){
		int a[]=new int[100];
		int count=0, sum=0;
		while(true){
			if(s[idx]>='0'&& s[idx]<='9'){
				a[count++]=s[idx++]-'0';
			}
			else{
				break;
			}
		}
		for(int i = 0; i < count;i++){
			sum += (int) (a[i]*Math.pow(10, count-i-1));
		}
		return sum;
	}
}

Measured memory_bytes: 11000
n, m = map(int, input().split())
a = []
for i in range(n):
    a.append(list(input()))
b = []
for i in range(m):
    b.append(list(input()))
wa = len(a[0])
wb = len(b[0])
# print(wa)
# print(wb)
ans = 'No'
#print(a)
#print(b)
for i in range(n-m+1):
    for j in range(wa-wb+1):
        flg = True
        for k in range(m):
            for l in range(wb):
                #print(i,j,k,l)

                if a[i+k][j+l] != b[k][l]:
                    flg = False
        if flg == True:
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
vvi dp,vis,visa;vector<string>s;int X1,Y1,X2,Y2,K,ans=inf;int h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
void bfs(int i,int j){
  queue<pair<pii,int>>q;
  q.push({{i,j},0});
  while(q.empty()==0){
    auto z=q.front();q.pop();
    if(z.F==mp(X2,Y2)){ans=min(ans,z.S);break;}
    vis[z.F.F][z.F.S]=1;
    visa[z.F.F][z.F.S]=1;
    rep(k,0,3)
      rep(I,1,K){
        int x=z.F.F+I*dx[k],y=z.F.S+I*dy[k];
        if(x<h and x>=0 and y<w and y>=0 and s[x][y]=='.'){
          if(vis[x][y]==0)q.push({{x,y},z.S+1}),vis[x][y]=1;
        }
        if(x<h and x>=0 and y<w and y>=0 and s[x][y]=='@')break;
        if(x<h and x>=0 and y<w and y>=0 and visa[x][y]==1)break;
        if(x>=h or x<0 or y<0 or y>=w)break;
      }
  }
}
void solve(){
  cin>>h>>w>>K;
  s=vector<string>(h);
  dp=vis=visa=vvi(h,vi(w,0));
  cin>>X1>>Y1>>X2>>Y2;
  rep(i,0,h-1)cin>>s[i];
  X1--,Y1--,X2--,Y2--;
  bfs(X1,Y1);
  if(ans==inf)cout<<-1;else
  cout<<ans;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

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

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int syurui, G;
  cin >> syurui >> G;
  int zyoko = G;
  vector<int> g(syurui);
  
  for(int i = 0; i < syurui; i++) {
    int buf;
    cin >> buf;
    g.at(i) = buf;
    zyoko -= buf;
  }
  sort(g.begin(), g.end());
  
  int a = zyoko / g.at(0);
  int res = a + syurui;
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int x;cin>>x;
    ll ans=0;
    ans+=1000*(x/500);
    x%=500;
    ans+=5*(x/5);
    cout<<ans<<endl;
}




Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split()) 
    union_find = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        union_find.union(A, B)

    answer = 0
    for i in range(N):
        answer = max(answer, union_find.size(i))

    print(answer)


Measured memory_bytes: 14516
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

AB = sorted(AB, key = lambda x:x[1])
time = 0
for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 55264
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

ll N;
string s[222];
vector<ll> g[222];

ll solve(ll S) {
  ll i, j;
  ll d[222]={};
  ll used[222]={};
  queue<ll> q;
  q.push(S);
  used[S]=1;
  
  while(q.size()) {
    ll u=q.front(); q.pop();
    
    for(i=0; i<g[u].size(); i++) {
      ll v=g[u][i];
      
      if(used[v]) continue;
      
      used[v]=1;
      d[v]=d[u]+1;
      q.push(v);
    }
    
  }
  
  for(i=0; i<N; i++) {
    for(j=i+1; j<N; j++) {
      if(d[i]==d[j] && s[i][j]=='1') return -2;
    }
  }
  
  ll max=0;
  for(i=0; i<N; i++) chmax(max, d[i]);
  return max;
}

int main(void) {
  ll i, j;
  cin >> N;
  
  for(i=0; i<N; i++) {
    cin >> s[i];
  }
  
  for(i=0; i<N; i++) {
    for(j=i+1; j<N; j++) {
      if(s[i][j]=='1') {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  
  ll ans=-2;
  for(i=0; i<N; i++) chmax(ans, solve(i));
  
  pt(ans+1);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    map<int, int> m;
    int mi = INT_MAX, ma = INT_MIN;
    int ans = INT_MIN;
    
    rep(i, N) {
        int a;
        cin >> a;
        mi = min(mi, a);
        ma = max(ma, a);
        m[a]++;
    }
    
    int ms = m.size();
    
    if (ms == 1) {
        for (auto x : m) {
            ans = x.second;
        }
    }
    else {
        reps(x, mi, ma) {
            int v[3];
            v[0] = m[x - 1];
            v[1] = m[x];
            v[2] = m[x + 1];
            ans = max(ans, v[0] + v[1] + v[2]);
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	vector<ll>v;
	f(n-1){
		ll add;
		cin >> add;
		v.pb(add);
	}
	ll ans = 0;
	f1(n-2){
		ans += min(v[i],v[i-1]);
	}
	ans += v[0];
	ans += v.back();
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll max_self(ll &a , ll b)
{   return a = max(a , b);    }

int main()
{
   ll n , max_weight;
   cin>>n>>max_weight;
   vector<ll> dp( max_weight+1 );
   for(int i=0 ; i<n ; i++)
   {
        ll weight , val;
        cin>>weight>>val;

        for(int j = max_weight - weight ; j>=0 ; --j)
            max_self(dp[j + weight] , dp[j] + val);

        //for(auto j:dp)            cout<<j<<" ";        cout<<endl<<endl;
   }
   ll ans = 0;
   for(auto i:dp)
    ans = max(ans , i);
    cout<<ans;
}


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

void Main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    for (int i = 0; i < n; i++)
    {
        if(s[i] != t[i])
        {
            cout << "No" << endl;
            return; 
        }
    }
    
    cout << "Yes" << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3568
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int n;
ll h[100010];
ll dp[100010];

ll rec(int i){
    if(dp[i] < INF) return dp[i];
    if(i == 0) return 0;
    ll res = INF;
    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); 
    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); 

    return dp[i] = res;
}

int main(){
    cin >> n;
    rep(i, n) cin >> h[i];

    fill(dp, dp + 100010, INF);

    cout << rec(n-1) << ln;
}
    

Measured memory_bytes: 4992