akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x,y;
    x=a/b;
    if(x>d)x=d;
    if(x==0){cout<<"NA"<<endl;continue;}
    a-=b*x;
    //cout<<x<<" "<<a<<endl;
    while(1){
      y=a/c;
      if(x+y>=n)break;
      x--;
      a+=b;
      if(!x)break;
    }
    if(!x)cout<<"NA"<<endl;
    else cout<<x<<" "<<y<<endl;
  }


}

Measured memory_bytes: 1160
from collections import namedtuple

Music = namedtuple('Music', 'title time')

N = int(input())

music = []

for _ in range(N):
  s, t = input().split()
  music.append(Music(s, int(t)))
  
X = input()

index = [m.title for m in music].index(X)

print(sum([m.time for m in music][index + 1:]))
    

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



int main() {
	string s;
	cin >> s;
	int n = s.size(), i;
	string t;
	for (i = 0; i < n; i++) {
		if (s[i] != 'A') {
			t.push_back(s[i]);
		}
	}
	if (t != "KIHBR") {
		cout << "NO" << endl;
		return 0;
	}
	i = 0;
	char c = '?';
	int cnt = 0;
	while (i < n) {
		if (c == '?' || c=='H' || c=='B' || c=='R') {
			if (cnt > 1) {
				cout << "NO" << endl;
				return 0;
			}
		}
		else {
			if (cnt > 0) {
				cout << "NO" << endl;
				return 0;
			}
		}
		if (s[i] == 'A') {
			cnt++;
		}
		else {
			c = s[i];
			cnt = 0;
		}
		i++;
	}
	if (cnt > 1) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
     int N, K, num;

     scanf("%d %d", &N, &K);

     if( (N-1) % (K-1) == 0) num = (N-1)/(K-1);
     else                             num = (N-1)/(K-1)+1;

    printf("%d\n", num);

/*
     for(int i=0;i<N;i++){
         scanf("%d", &A);
         if( A == 1){
             num = i;
             break;
         }
    }
*/    

}
   

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
	vector<int> h,w;
	int temph,tempw;
	do{
		cin>>temph>>tempw;
		h.push_back(temph);
		w.push_back(tempw);
	}while (temph!=0 || tempw!=0);
	for (vector<int>::size_type i=0;i<h.size()-1;i++){
		for (int j=0;j<h[i];j++){
			for (int k=0;k<w[i];k++){
				if (j==0 || j==h[i]-1 || k==0 || k==w[i]-1){
					cout<<"#";
				}
				else{
					cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>

int main(void){
  char a[1][1];
  scanf("%c",&a[0][0]);
  int ans = a[0][0] - 'a';
  if( a[0][0] - 'a' > -1){
    printf("a\n");
  }

  else{
    printf("A\n");
  }

  return 0;
}

Measured memory_bytes: 1584
#include<iostream>
#define MAXN 100002
using namespace std;
int n,k,a[MAXN],b[MAXN],c[MAXN];
main()
{
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		a[i] = a[i] + max(b[i-1],c[i-1]);
		b[i] = b[i] + max(a[i-1],c[i-1]);
		c[i] = c[i] + max(a[i-1],b[i-1]);
	}
	int m = max(a[n],b[n]);
	cout<<max(m,c[n]);
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>

#define M 1000000

int heapsize = 1;
int H[M];

void maxHeapify(int i){
  int lk,rk,lar,temp;

  lk = i*2;
  rk = i*2 + 1;

  if((lk <= heapsize) && (H[lk] > H[i])) lar = lk;
  else lar = i;
  if((rk <= heapsize) && (H[rk] > H[lar])) lar = rk;

  if(lar != i){
    temp = H[i];
    H[i] = H[lar];
    H[lar] = temp;
    maxHeapify(lar);
  }
}

void increase(int i,int k){
  int temp;
  
  if(k < H[i]) return;

  H[i] = k;
  while(i > 1 && H[i/2] < H[i]){
    temp = H[i];
    H[i] = H[i/2];
    H[i/2] = temp;
    i = i/2;
  }
}

void insert(int k){
  heapsize = heapsize + 1;
  H[heapsize] = -1000000;
  increase(heapsize,k);
}

int extract(void){
  int max;
  
  if(heapsize < 1) return -1000000;

  max = H[1];

  H[1] = H[heapsize];
  heapsize--;
  maxHeapify(1);

  return max;
}

int main(){
  char word[9];
  int key;

  while(1){

    scanf("%s",word);
    
    if(strcmp(word,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    
    else if(strcmp(word,"extract") == 0){
      printf("%d\n",extract());
    }

    else if(strcmp(word,"end") == 0) break;
    
  }
  
  return 0;
}



Measured memory_bytes: 5704
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(!n) return 0;
    vector<vector<pair<int,int> > >e(n);
    // to,d
    vector<tuple<int,int,int,int> > edge(m);
    // cost,u,v,d
    REP(i,m){
      int u,v,d,c;
      cin >> u >> v >> d >> c;
      --u,--v;
      e[u].push_back(make_pair(v,d));
      e[v].push_back(make_pair(u,d));
      edge[i]=make_tuple(c,u,v,d);
    }
    SORT(edge);
    map<int,int> cost;
    priority_queue<pair<int,int> > dijk;
    //negcos,pos
    dijk.push(make_pair(0,0));
    while(!dijk.empty()){
      int ncos,pos;
      tie(ncos,pos)=dijk.top();
      dijk.pop();
      if(cost.count(pos)) continue;
      cost[pos]=-ncos;
      for(auto x:e[pos]) dijk.push(make_pair(ncos-x.second,x.first));
    }
    vector<bool> reach(n,false);
    reach[0]=true;
    int answer=0;
    REP(i,edge.size()){
      int c,u,v,d;
      tie(c,u,v,d)=edge[i];
      if(cost[u]>cost[v]) swap(u,v);
      //cost[u]<cost[v]
      if(reach[v]) continue;
      if(d==cost[v]-cost[u]){
	reach[v]=true;
	answer+=c;
      }
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 4448
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	int n;
	int a[5005];
	while (cin >> n, n)
	{
		memset(a, 5005, 0);
		REP(i, n) cin >> a[i];
		int s[5005];
		s[0] = 0;
		FOR(i, 1, n+1) s[i] = s[i - 1] + a[i-1];
		int ans = -INF;
		REP(i, n)
		{
			for (int j = i + 1; j < n+1; j++)
			{
				ans = max(ans, (s[j] - s[i]));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;

int ceii(int a, int b)
{
	return (a + b - 1) / b;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	int h, w, n;
	cin >> h >> w >> n;
	cout << ceii(n, max(h, w)) << '\n';
	
	
	return 0;
}






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

int main() {
  char c;
  cin >> c;
  char vow[5]={'a','e','i','o','u'};
  for ( int i=0; i<5; i++ ) {
    if ( c==vow[i] ) {
      cout << "vowel";
      return 0;
    }
  }
  cout << "consonant";
  return 0;
}
  

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

V<int> ans;
int n, x, y, cnt;
int main() {
    cin >> n >> x >> y;

    ans.resize(n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j) continue;
            int a = abs(x - i) + abs(j - y) + 1;
            int b = abs(y - i) + abs(j - x) + 1;
            int d = min({abs(j - i), a, b});
            ans[d]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << ans[i] / 2 << endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int K[100001];
int to[200001], ne[200001], he[100001], num[200001];
vector<int> S1[100001], S2[100001];
int dame[100001];

int dfs(int v, int prev) {
	if (dame[v]) {
		ll ret = 1;
		if (prev >= 2) {
			int k = K[v] - num[prev];
			ret = (ll)S1[v][k - 1] * S2[v][k] % M;
		}
		else ret = S1[v][K[v]];
		if (dame[v] >= 2 && dame[v] != prev) {
			ll tmp = dfs(to[dame[v]], dame[v] ^ 1);
			int k = K[v] - num[dame[v]];
			for (int i = k; i <= K[v]; i++) {
				S1[v][i] = S1[v][i] * tmp % M;
			}
			for (int i = k - 1; i >= 0; i--) {
				S2[v][i] = S2[v][i] * tmp % M;
			}
			ret *= tmp;
			dame[v] = -1;
		}
		return (ret + 1) % M;
	}
	dame[v] = prev;
	ll ret = 1;
	int k = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int tmp = 1;
		if (i != prev) {
			tmp = dfs(to[i], i ^ 1);
			ret = ret * tmp % M;
		}
		S2[v][k++] = tmp;
		S1[v][k] = ret;
	}
	for (int i = k - 2; i >= 0; i--) {
		S2[v][i] = ((ll)S2[v][i] * S2[v][i + 1]) % M;
	}
	return ret + 1;
}

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


	cin >> N >> M;

	int k = 2;
	rep1(i, N - 1) {
		int x, y;
		cin >> x >> y;

		num[k] = K[x];
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		num[k] = K[y];
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
		K[x]++;
		K[y]++;
	}
	rep1(i, N) {
		S1[i].resize(K[i] + 1);
		S2[i].resize(K[i] + 1);
		S1[i][0] = 1;
		S2[i][K[i]] = 1;
	}

	rep1(j, N) {
		ll kotae = (dfs(j, -1) - 1 + M) % M;
		co(kotae);
	}


	Would you please return 0;
}

Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  int ans = 0;
  for(int i = 0; i < 4; i++){
  	if(S.at(i) == '+'){
    	ans++;
    }else if(S.at(i) == '-'){
    	ans--;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
using namespace std;
 
lli gcd(lli a, lli b) { return (b == 0 ? a : gcd(b, a % b)); }
 
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
 
 
 
const int N = 1e6 + 30;
const lli mod = 998244353;

lli n, a, b;
int main()
{
	fastio;
	cin >> n >> a >> b;
	lli pat = min(n - a, b - 1LL);
	if((b - a) % 2LL == 0LL)
	{
		pat =  min(min(n - a, b - 1LL), (b - a)/2LL);
	}
	lli sm1 = a + (b - a - 1LL)/2LL;
	lli sm2 = n - b + 1LL + (n - (a + n - b + 1LL))/2LL;
	cout << min(min(sm1, sm2), pat);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int R; cin >> R;
	if (R < 1200) cout << "ABC" << endl;
	else if (R >= 2800) cout << "AGC" << endl;
	else cout << "ARC" << endl;
}

Measured memory_bytes: 256
$S=<STDIN>;chomp $S;

$L=length($S);

if($L % 2==0) {
	$r=$L/2;
	$i=int($L/2);$j=1;
	$c=substr($S,$i,1);
	while ( $r<$L && substr($S, $i-$j,1) eq $c && substr($S,$i+$j-1,1) eq $c ) {
		$j+=1;
		$r+=1;
	}
} else {
	$r=($L+1)/2;
	$i=int($L/2);$j=1;
	$c=substr($S,$i,1);
	while ( $r<$L && substr($S, $i-$j,1) eq $c && substr($S,$i+$j,1) eq $c ) {
		$j+=1;
		$r+=1;
	}
}
print $r;


Measured memory_bytes: 512
import sys
import os
M, D = map(int,input().split())

ans = 0
for m in range(1,M+1):
    for d in range(12,D+1):
        d1 = d%10
        d10 = (d - d1)//10
        if d1 >= 2 and d10 >= 2 and d1*d10 == m:
            ans += 1
print(ans)


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

int main()
{
    int r, g, b;
    string answer = "NO";
    cin >> r >> g >> b;
    if ((g * 10 + b) % 4 == 0) {
        answer = "YES";
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  vl cnt(200000,0);
  vl x(n),y(n);
  rep(i,n){
    x[i]=a[i]+i;
    if(x[i]<200000){
      cnt[x[i]]++;
    }
    y[i]=a[i]-i;
    if(y[i]<0){
      ans +=cnt[-y[i]];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9532
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

ll AN(ll A, ll N){
  if (N == 0){
    return 1;
  }else{
    if (N % 2 == 0){
      return AN((A*A)%nmax, N/2) % nmax;
    }else{
      return AN((A*A)%nmax, N/2) * A % nmax;
    }
  }
}


int main(){
  int N, M; cin >> N >> M;
  vector <int> S(N), T(M);
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];

  ll DP[N + 1][M + 1], sum[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++){
    for (int j = 0; j < M + 1; j++){
      DP[i][j] = 0; sum[i][j] = 0;
    }
  }

  DP[0][0] = 0;
  
  for (int i = 1; i < N + 1; i++){
    for (int j = 1; j < M + 1; j++){
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      sum[i][j] %= nmax;
      if (S[i - 1] == T[j - 1]){
        DP[i][j] = sum[i - 1][j - 1] + 1;
        DP[i][j] %= nmax;
      }
      sum[i][j] += DP[i][j];
      while (sum[i][j] < 0){
        sum[i][j] += nmax;
      }
      
      sum[i][j] %= nmax;
    }
  }
  
  ll ans = (sum[N][M] + 1) * AN(2, nmax - 1) % nmax;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 62848
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

using namespace std;

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

void solution()
{
    int n;
    cin >> n;
    vector<int> as(n);
    cin >> as;
    int total_xor = accumulate(begin(as), end(as), 0, [](int x, int y){ return x^y; });
    for(int a : as){
        cout << (a ^ total_xor) << ' ';
    }
    cout << '\n';
}

/*
a1 =      x2 @ x3 @ x4
a2 = x1 @      x3 @ x4
a3 = x1 @ x2      @ x4
a4 = x1 @ x2 @ x3
*/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <typename T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const vector<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
void ce(void){cerr << '\n';}
template <typename T>
void ce(const T n){cerr << n << '\n';}
template <typename T>
void cesp(const T n){cerr << n << ' ';}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cesp(i); ce();}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	ll x, k, d;
	cin >> x >> k >> d;

	ll t = x / d;

	if (abs(t) > k) {
		co(min(abs(x - d * k), abs(x + d * k)));
		return 0;
	}

	ll ans = LINF;
	rep(i, 100) {
		if ((k & 1) != ((t - 50 + i) & 1)) continue;
		chmin(ans, abs(x - d * (t - 50 + i)));
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
#define MAX 100000
using namespace std;


int main(){
  string s;

  cin >> s;

  int len = s.size(); 
  
  string ans;
  for(int i = 0; i < len; i++){
    if(i % 2 == 0){
      ans += s[i];
    }
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
h,w = map(int,input().split())
maps = []
for i in range(h):
  maps.append(list(input()))

l_list = [[0 for i in range(w)] for i in range(h)]
r_list = [[0 for i in range(w)] for i in range(h)]
u_list = [[0 for i in range(w)] for i in range(h)]
d_list = [[0 for i in range(w)] for i in range(h)]

for i in range(h):
  for j in range(w):
    if maps[i][j] == "#":
      l_list[i][j] = 0
    elif j == 0:
      l_list[i][j] = 1
    else:
      l_list[i][j] = l_list[i][j-1] + 1
      
for i in range(h):
  for j in range(w-1,-1,-1):
    if maps[i][j] == "#":
      r_list[i][j] = 0
    elif j == w-1:
      r_list[i][j] = 1
    else:
      r_list[i][j] = r_list[i][j+1] + 1
      
for i in range(h):
  for j in range(w):
    if maps[i][j] == "#":
      u_list[i][j] = 0
    elif i == 0:
      u_list[i][j] = 1
    else:
      u_list[i][j] = u_list[i-1][j] + 1  
      
for i in range(h-1,-1,-1):
  for j in range(w):
    if maps[i][j] == "#":
      d_list[i][j] = 0
    elif i == h-1:
      d_list[i][j] = 1
    else:
      d_list[i][j] = d_list[i+1][j] + 1  

result = []
for i in range(h):
  for j in range(w):
    result.append(l_list[i][j] + u_list[i][j] + d_list[i][j] + r_list[i][j] - 3)
  
print(max(result))

          

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

using namespace std;
vector<string>vs;
int h,w,k;
int chk(int msk){
    vector<int>vcnt(__builtin_popcount(msk)+1);
    int ret=0;
    for(int i=0;i<w;i++){
        int iv=0;
        int icnt=0;
        for(int j=0;j<h;j++){
            if(j>0&&((1<<(j-1))&msk)){
                vcnt[iv]+=icnt;
                if(vcnt[iv]>k){
                    vcnt=vector<int>(__builtin_popcount(msk)+1,0);
                    i--;
                    ret++;
                    break;
                }
                icnt=0;
                iv++;
            }
            if(vs[j][i]=='1'){
                icnt++;
                if(icnt>k)
                    return 1e6;
            }
            if(j==h-1){
                vcnt[iv]+=icnt;
                if(vcnt[iv]>k){
                    vcnt=vector<int>(__builtin_popcount(msk)+1,0);
                    i--;
                    ret++;
                    break;
                }
            }
        }
    }

    return ret;
}
int main()
{///{}
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>h>>w>>k;
    vs.resize(h);
    for(int i=0;i<h;i++)
        cin>>vs[i];
    int mn=INT_MAX;
    for(int msk=0;msk<(1<<h);msk++){
        int ret=__builtin_popcount(msk)+chk(msk);
        mn=min(mn,ret);
    }
    cout<<mn<<'\n';
    return 0;
}

/**
4 10 4
1110010010
1000101110
0011101001
1101000111


3 5 4
11100
10001
00111
*/


Measured memory_bytes: 3612
#include <string>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm> 
#include <bits/stdc++.h>

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
using namespace std;
typedef unsigned long long int ull;

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


ull lcm(ull a, ull b)  
{  
	return (a*b)/gcd(a, b);  
}   
 


int main()
{
	ull A,B,C,D,a=0,b=0,l=0,sol=0;
	cin>>A>>B>>C>>D;
	l=lcm(C,D);
	a=(B/C)-((A-1)/C);
	b=(B/D)-((A-1)/D);
	l=(B/l)-((A-1)/l);
	sol=(B-A+1)-(a+b-l);
	cout<<sol;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<ll, ll> mp;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}
	ll ans = 0;
	for (auto c : mp) {
		if (c.second >= c.first) {
			ans += (c.second - c.first);
		}
		else ans += c.second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6272
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

z = {}
ans = 0

for i in range(n):
    s = "".join(sorted(input()))
    try:
        z[s] += 1
    except:
        z[s] = 1

for i in z:
    ans += z[i]*(z[i]-1)//2

print(ans)

Measured memory_bytes: 22132
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=1;
    cin>>n;
    char arr_ch[n];
    for(int i =0;i<n;i++){
      cin>>arr_ch[i];
        if(arr_ch[i] != arr_ch[i-1] && i != 0){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 384
n,k=map(int,input().split())
s,p,r=map(int,input().split())
a=list(input())
count={}
count["s"]=s
count["p"]=p
count["r"]=r
ans=0

for i in range(k):
    for j in range(i,n,k):
        if j-k>=0 and a[j-k]!=a[j]:
            ans+=count[a[j]]
        if j-k>=0 and a[j-k]==a[j]:
            a[j]="q"
        elif j-k<0:
            ans+=count[a[j]]
        
print(ans)

Measured memory_bytes: 78040
import sys


line = sys.stdin.readline()
N, K = line.split(" ")
N = int(N)
K = int(K)
if N%2 == 0:
	if K <= (N/2):
		print("YES")
	else:
		print("NO")	
else:
	if K <= (N/2 + 1):
		print("YES")
	else:
		print("NO")

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

int main()
{
  int n;
  bool unique = true;
  cin >> n;
  long A[n];
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  sort(A, A + n);
  for (int i = 0; i < n - 1; i++){
    if(A[i] == A[i + 1]) {
      unique = false;
      break;
    }
  }
  cout << (unique ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, k; cin >> n >> k;
	long long dp[123456] = { 0 }, test[123456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> a; test[h] = a;
	}
	for (int h = 1; h < 123456; h++) {
		dp[h] = 1234567891234;
	}
	for (int h = 1; h < n; h++) {
		for (int i = 1; i <= k; i++) {
			if (h - i >= 0) {
				dp[h] = min(dp[h], dp[h - i] + abs(test[h - i] - test[h]));
			}
		}
	}
	cout << dp[n - 1] << endl;
	cin >> n;
}


Measured memory_bytes: 2176
#include<cstdio>
using namespace std;
char s[5];
int a[150];
int main() {
	scanf("%s",s+1);
	for(int i=1;i<=3;i++) a[(int)s[i]]++;
	if(a['A']&&a['A']<3) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,curr,temp;
    string a;
    cin >> a;
    bool can = 1;
    for(i=0;i<3;i++)
    {
        if(a[i] == a[i+1])
            can = 0;
    }
    if(can)
        cout << "Good";
    else
        cout << "Bad";
    return 0;
}


Measured memory_bytes: 256
h,w,x = map(int, input().split())
c = [input() for _ in range(h)]
ans = 0
for i in range(2**(h+w)):
    tnp = 0
    bad = []
    for j in range(h+w):
        if ((i>>j)&1):
            bad.append(j)
    for j in range(h):
        for k in range(w):
            if (c[j][k]=="#"):
                if (j in bad or k+h in bad):
                    continue
                else:
                    tnp += 1
    if (tnp == x):
        ans += 1
print(ans)

Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long answer = 0;
		for(int a = 1;a <=k;a++) {
			for(int b = 1;b <=k;b++) {
				int tmp = getMaxKoyakusu(a,b);
				for(int c = 1;c <=k;c++) {
					answer+= getMaxKoyakusu(tmp,c);
				}
			}
		}
		System.out.println(answer);
	}

	private static int getMaxKoyakusu(int a, int b) {
		int base = a;
		if(base > b) {
			base =b;
		}

		for(int i =base;i >=1;i--) {
			if(a % i !=0) {
				continue;
			}
			if(b % i !=0) {
				continue;
			}
			return i;
		}

		return 1;

	}
}

Measured memory_bytes: 36444
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 55;
int n;
int a[N][2];
map<pii, int> mapchik;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 2; j++)
			scanf("%d", &a[i][j]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			int x = a[i][0] - a[j][0], y = a[i][1] - a[j][1];
			mapchik[mp(x, y)]++;
		}
	int ans = 0;
	for (auto t : mapchik)
		ans = max(ans, t.second);
	printf("%d\n", n - ans);

	return 0;
}


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

int main() {
    int N,q;cin>>N>>q;
    vector<int > v[N];
    while(q--){
        int a;cin>>a;
        if(a==0){
            int t,x;cin>>t>>x;
            v[t].push_back(x);
        }
        else if(a==1){
            int t;cin>>t;
            for(auto i=v[t].begin();i<v[t].end();++i){
                if((i+1)==v[t].end()){
                    cout<<*i;
                    break;
                }
                cout << *i << ' ';
            }
            cout<<endl;
        }
        else if(a==2){
            int t;cin>>t;
            v[t].clear();
        }
    }
    return 0;
}



Measured memory_bytes: 5924
#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	if(n<105){
		puts("0");
		return 0;
	}
	if(n<135){
		puts("1");
		return 0;
	}
	if(n<165){
		puts("2");
		return 0;
	}
	if(n<189){
		puts("3");
		return 0;
	}
	if(n<195){
		puts("4");
		return 0;
	}
	puts("5");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int h[N];
  int cnt = 0;
  for(int i=0;i<N;i++){
    cin >> h[i];
    if(h[i] >= K){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;

}


Measured memory_bytes: 640
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = ni()
print(n**2 - a)

Measured memory_bytes: 3060
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

a,b=li()
s=""
t=""
for i in range(0,b):
    s=s+str(a)
for i in range(0,a):
    t=t+str(b)
s=int(s)
t=int(t)

print(max(s,t))

Measured memory_bytes: 3440
N, M = map(int, input().split())

g = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)

for e1 in g[1]:
    for e2 in g[e1]:
        if e2 == N:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')

Measured memory_bytes: 28976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    ll a, b;
    cin >> a >> b;

    cout << bitset<32>(a & b) << endl;
    cout << bitset<32>(a | b) << endl;
    cout << bitset<32>(a ^ b) << endl;
    return 0;
}


Measured memory_bytes: 3144
# include <stdio.h>
#include <math.h>

int main(){
    int mat[3][3];
    int n;

    for(int i=0; i<3; ++i){
        for(int j=0; j< 3; ++j)
            scanf("%d", &mat[i][j]);
    }
    scanf("%d", &n);
    int sortidos=0;

    for(int h = 0; h <n; ++h){
        int bixin;
        scanf("%d", &bixin);
        for(int i=0; i< 3; ++i){
            for(int j=0; j<3; ++j){
                if(bixin== mat[i][j])
                    mat[i][j]=-1;

            }
        }
    }

    int vdd = 0;

    //linha
    for(int i=0; i<3; ++i){
    int linha = 0;
        for(int j=0; j<3; ++j){
            if (mat[i][j]==-1)
                linha += 1;
        }
        if (linha == 3){
            vdd = 1;
        //   printf("###\n");
        }
    }
    // COLUNA
    for(int j=0; j <3; ++j){
        int coluna =0;
        for(int i =0; i<3; ++i){
            if(mat[i][j]==-1)
                coluna+=1;
        }
        if(coluna == 3){
            vdd=1;
            //printf("###\n");
        }
    }


    if (mat[0][0]==-1 && mat[1][1]==-1 && mat[2][2]== -1){
        vdd = 1;
        //printf("--###\n");
    }
    if (mat[0][2] == -1 && mat[1][1] == -1 && mat[2][0] == -1){
        vdd = 1;
        //printf("---------###\n");
    }


    if(vdd==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    string s;
    cin>>s;
    int cnt1=0, cnt0=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='0')   cnt0++;
        else            cnt1++;
    }
    cout<<2*min(cnt0,cnt1)<<endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
string w;
vector<int> alp(26, 0);
int main() {
    cin >> w;
    int slen = w.length();
    for(int i = 0; i < slen; ++i) {
        alp.at(w.at(i) - 97)++;
    }

    for(int i = 0; i < 26; ++i) {
        if(alp.at(i) % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		ALDS1_3_A();
	}

	public static void ALDS1_3_A() {
		Scanner sc = new Scanner(System.in);
		Deque<String> stack = new ArrayDeque<String>();
		while(sc.hasNext()) {
			String str = sc.next();
			if(str.equals("+")) {
				int a = Integer.parseInt(stack.removeFirst());
				int b = Integer.parseInt(stack.removeFirst());
				String c = Integer.toString(a + b);
				stack.addFirst(c);
			} else if(str.equals("-")) {
				int a = Integer.parseInt(stack.removeFirst());
				int b = Integer.parseInt(stack.removeFirst());
				String c = Integer.toString(b - a);
				stack.addFirst(c);
			} else if(str.equals("*")) {
				int a = Integer.parseInt(stack.removeFirst());
				int b = Integer.parseInt(stack.removeFirst());
				String c = Integer.toString(a * b);
				stack.addFirst(c);
			} else {
				stack.addFirst(str);
			}
		}
		
		System.out.println(stack.removeFirst());
	}
	
}


Measured memory_bytes: 26332
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;

namespace CPLib
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = s[0];
            int m = s[1];
            var sb = new StringBuilder();
            for (int i = 0; i < Max(n,m); i++)
            {
                sb.Append(Min(n,m));
            }
            WriteLine(sb.ToString());
        }
    }
}


Measured memory_bytes: 11348
l=list(map(int,input().split()))
n=int(input())
a=[l[0]]
b=[2*l[0],l[1]]
c=[4*l[0],2*l[1],l[2]]
d=[8*l[0],4*l[1],2*l[2],l[3]]
ans=0
x=n//2
y=n%2
print(x*min(d)+y*min(c))


Measured memory_bytes: 38384
#B
x1,y1,x2,y2=map(int,input().split())
X1=[x1,y1]
d=[x2-x1,y2-y1]
dT=[-d[1],d[0]]
P3,P4=X1+dT,X1+dT+d
x3=x1+dT[0]+d[0]
y3=y1+dT[1]+d[1]
x4=x1+dT[0]
y4=y1+dT[1]
print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int x[105];

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n,k;
  cin >> n >> k;
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      a--;
      x[a]++;
    }
  }
  int ans = 0;
  rep(i,n){
    if(x[i] == 0 ) ans ++ ;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
vector <long long> v;
void rec(long long len, long long num){
	if(len >= 11) return;
	v.push_back(num);
	if(num % 10 > 0){
		int last = num % 10;
		rec(len + 1, num * 10 + (last - 1));
	}
	if(num % 10 < 9){
		int last = num % 10;
		rec(len + 1, num * 10 + (last + 1));
	}
	int last = num % 10;
	rec(len + 1, num * 10 + last);
}
int main(){
	for(long long i = 1; i <= 9; i++){
		rec(0, i);
	}
	long long k;
	cin >> k;
	sort(v.begin(), v.end());
	cout << v[k - 1] << endl;
}

Measured memory_bytes: 10476
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int K; cin >> K;
	cout << A[--K] << ln;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void){
	int x = 1;
	int i = 0;
	while(x != 0){
		scanf("%d", &x);
		i++;
		if(x != 0) printf("Case %d: %d\n", i, x);
	}
	return 0;
}

Measured memory_bytes: 600
/*input
4 5
1 2
2 5
#.###
####.
#..##
#..##
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
string arr[maxn];
int dist[maxn][maxn];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool in[maxn][maxn];
int n,m;
bool isin(int x,int y){
    if(x<0 or x>=n or y<0 or y>=m) return false;
    return true;
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    
    cin>>n>>m;
    int sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    --sx;
    --sy;--ex;--ey;
    REP(i,n) cin>>arr[i];
    REP(i,n) REP(j,m) dist[i][j]=INF;
    dist[sx][sy]=0;
    deque<pii> q;
    q.pb({sx,sy});
    while(!q.empty()){
        pii z=q.front();
        q.pop_front();
        in[z.f][z.s]=0;
        REP(i,5){
            REP(j,5){
                int x=z.f+i-2,y=z.s+j-2;
                if(isin(x,y) and arr[x][y]!='#' and dist[x][y]>dist[z.f][z.s]+1){
                    dist[x][y]=dist[z.f][z.s]+1;
                    if(!in[x][y]) q.pb({x,y}),in[x][y]=1;
                }
            }
        }
        REP(k,4){
            int a=z.f+dx[k],b=z.s+dy[k];
            if(isin(a,b) and arr[a][b]!='#' and dist[a][b]>dist[z.f][z.s]){
                dist[a][b]=dist[z.f][z.s];
                if(!in[a][b]) q.push_front({a,b}),in[a][b]=1;
            }
        }
    }
    if(dist[ex][ey]!=INF) cout<<dist[ex][ey];
    else cout<<-1;
}


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

int main() {
	int n;

	cin >> n ;

	vector<string> blue(n);
	
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		blue[i]=s;
	}

	int m;

	cin >> m;

	vector<string> red(m);

	for (int i = 0; i < m; i++) {
		string s;
		cin >> s;
		red[i] = s;
	}

	int ans = 0;

	for (string s : blue) {
		int tmp = 0;
		for (string str : blue) {
			if (s == str) {
				tmp++;
			}
		}
		for (string str : red) {
			if (s == str) {
				tmp--;
			}
		}
		ans = max(ans, tmp);
	}

	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll N;
  cin >> N;

  vi a(N - 1), b(N - 1);
  for (ll i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i];
    a[i] -= 1;
    b[i] -= 1;
  }

  vector<unordered_set<ll>> G(N);
  for (ll i = 0; i < N - 1; i++) {
    G[a[i]].insert(b[i]);
    G[b[i]].insert(a[i]);
  }

  vi v(N);
  queue<ll> q1, q2;
  q1.push(0);
  q2.push(N - 1);
  v[0] = 1;
  v[N - 1] = 2;

  while (true) {
    if (q1.size() + q2.size() == 0) {
      break;
    }

    for (ll i = q1.size(); i > 0; i--) {
      ll fr = q1.front();
      q1.pop();
      for (ll to: G[fr]) {
        if (v[to] == 0) {
          v[to] = 1;
          q1.push(to);
        }
      }
    }

    for (ll i = q2.size(); i > 0; i--) {
      ll fr = q2.front();
      q2.pop();
      for (ll to: G[fr]) {
        if (v[to] == 0) {
          v[to] = 2;
          q2.push(to);
        }
      }

    }
  }

  ll cnt1 = 0, cnt2 = 0;
  for (ll i: v) {
    if (i == 1) cnt1 += 1;
    else if (i == 2) cnt2 += 1;
  }

  if (cnt1 > cnt2) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
}

Measured memory_bytes: 19072
#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;
int main(void)
{
    int count=0;
    int length;
    int i,j=0;
    string S;
    cin>>S;
    length=S.size();
    i=0;
    j=length-1;
    while(i<j)
    {
        if(S[i]!=S[j])
        {
            count++;
        }
        i++;
        j--;
    }
    
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int main() {
  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  vector<int> Speaker[M];
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int L;
      cin >> L;
      L--;
      Speaker[L].push_back(i);
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 1; j < (int)Speaker[i].size(); j++) {
      uf.unite(Speaker[i][j-1],Speaker[i][j]);
    }
  }
  if (uf.size(0) == N) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 7740
#include <stdio.h>

int main()
{
  int i, j, k, x, y;
  scanf("%d%d", &x, &y);
  while(x != 0 && y != 0) {
    for(i = 0; i < x; ++i) {
      if (0 == (i % 2)) {
        for(k = 0; k < y; ) {
          printf("#");
          k++;
          if(k < y) {
            printf(".");
            k++;
          }
        }
        printf("\n");
      }
      if (1 == (i % 2)) {
        for (k = 0; k < y; ) {
          printf(".");
          k++;
          if(k < y) {
            printf("#");
            k++;
          }
        }
        printf("\n");
      }
    }
    printf("\n");
    scanf("%d%d", &x, &y);
  }
  return 0;
}

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

int k[101];
char s[101];
int main() {
	vector<char>v;
	for (char c = 'a'; c <= 'z'; c++)v.push_back(c);
	for (char c = 'A'; c <= 'Z'; c++)v.push_back(c);
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%d", &k[i]);
		scanf("%s", s);
		int len = strlen(s);
		rep(i, len) {
			s[i] = v[(find(v.begin(), v.end(), s[i]) - v.begin() + 52 - k[i%n]) % 52];
		}
		puts(s);
	}
}

Measured memory_bytes: 3160
#include<stdio.h>
int main(void){
char s[3];
int i,r=0,l=0,j=0;
scanf("%s",s);
for(i=0;i<3;i++){
if(s[i]=='a')
r++;
else if(s[i]=='b')
l++;
else if(s[i]=='c')
j++;
}
if(r==1&&l==1&&j==1)
puts("Yes");
else
puts("No");

return 0;
}

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

int main() {
    ll n,k,p=1000000007;
    cin >> n >> k;
    vector<ll> a(n);for(int i=0;i<n;i++) cin >> a[i];  
    ll ans=0,ta=0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(a[i]>a[j]) ta++;
        }
    }
    ans += k*ta; ans %= p;

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    vector<ll> b(n);
    for(int i = 1; i < n; i++) {
        if(a[i]==a[i-1]) b[i]=b[i-1];
        else b[i]=i;
    }

    ll x=k*(k-1)/2; x%=p;
    for(int i = 0; i < n; i++) {
        ll y=b[i];
        y *= x;
        y %= p;
        ans += y;
        ans %= p;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
H, N = map(int, input().split())
magic = []
for _ in range(N):
    A, B = map(int, input().split())
    magic.append((A,B))

dp = [10**10] * (H+1)
dp[0] = 0
for i in range(1,H+1):
    for m in magic:
        if m[0] > i:
            dp[i] = min(dp[i], m[1])
        else:
            dp[i] = min(dp[i], dp[i-m[0]]+m[1])

print(dp[H])

Measured memory_bytes: 40688
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort()
 
D = [0 for _ in range(M-1)]
for m in range(1, M):
    D[m-1] = X[m] - X[m-1]
D.sort()

print(sum(D[0:max(M-N, 0)]))

Measured memory_bytes: 13832
from sys import stdin


def main():
    lines = stdin.readlines()
    A = [int(i) for i in lines[1].split()]
    B = [int(i) for i in lines[2].split()]
    pre = A[0]
    ans = 0
    for a, b in zip(A[1:], B):
        tmp1 = pre if pre < b else b
        b -= tmp1
        tmp2 = a if a < b else b
        ans += tmp1 + tmp2
        pre = a - tmp2
    print(ans)
    return


main()


Measured memory_bytes: 20192
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j,cnt,cnt1;
	char s[101],x[101][21];
	scanf("%s%d",s,&n);
	for(i=0;i<n;i++){
		scanf("%s",x[i]);
		for(j=1;j<=10;j++) x[i][9+j]=x[i][j-1];
	}
	cnt=0; cnt1=0;
	for(i=0;i<n;i++){
		for(j=0;j<20;j++){
			if(s[cnt]==x[i][j]) cnt++;
			if(strlen(s)==cnt){
				cnt1++; cnt=0; break;
			}
		}
	}
	printf("%d\n",cnt1);
	return 0;
}

Measured memory_bytes: 1740