akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

/**
 * C - Snack
 * 高橋君はパーティを企画しています。
 * パーティーでは参加者に 1 人 1 個以上のお菓子を配る予定です。
 * 高橋君は参加者の人数が A 人か B 人のどちらかになるだろうという予想を立てました。
 * どちらの場合でも均等に配りきることができるようなお菓子の個数の最小値を求めてください。
 * ただし、 1 個のお菓子を分割して複数人で分けることはできないものとします。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println( lcm( a, b ) );

        sc.close();
    }

    /*
     *  最小公倍数lcm
     */
    static long lcm ( int a, int b ) {
        int temp;
        long c = a;
        c *= b;
        while( ( temp = a % b ) != 0 ) {
            a = b;
            b = temp;
        }
        return c / b ;
    }
}

Measured memory_bytes: 35868
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // strcmp()

#define MAX_L 100
const char NUL = '\0';

int
main(int argc, char** argv)
{
	char s[MAX_L];
	char t[MAX_L];
	int u, v;
	int n;
	int c;
	int i;

	scanf("%d\n", &n);
	u = 0, v = 0;
	for (i = 0; i < n; ++i)
	{
		scanf("%s %s\n", s, t);
		c = strcmp(s, t);
		if (c < 0)
			v += 3;
		else if (c > 0)
			u += 3;
		else
		{
			u++;
			v++;
		}
	}

	printf("%d %d\n", u, v);
	return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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


using Int = long long;
Int cnt[2];
int sign[2];
Int v[2];
int n;
Int a;

void solve() {
    REP(i, 2) cnt[i] = 0;
    REP(i, 2) v[i] = 0;
    sign[0] = 1;
    sign[1] = -1;
    cin >> n;
    REP(i, n) {
        cin >> a;
        REP(j, 2){
            v[j] += a;
            if (sign[j] == 1 && v[j] < 1){
                cnt[j] += -v[j] + 1;
                v[j] = 1;
            }
            if (sign[j] == -1 && v[j] > -1) {
                cnt[j] += v[j] + 1;
                v[j] = -1;
            }
            sign[j] *= -1;
        }
    }
    cout << (cnt[0] < cnt[1] ? cnt[0] : cnt[1]) << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

int MAIN() {
    solve();
    
    return 0;
}


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

int func(int n){
  if(n%2==0) return n/2;
  else return 3*n+1;
}

int main() {
  int x1,y1,x2,y2; 
  cin>>x1>>y1>>x2>>y2;
  int dx = x2-x1;
  int dy = y2-y1;
  int x3 = x2-dy;
  int x4 = x2-dy-dx;
  int y3 = y2+dx;
  int y4 = y1+dx;
  cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
}

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<ll> queA;
  priority_queue<ll> queB;
  priority_queue<ll, std::vector<ll>, std::greater<ll>> ans;
  priority_queue<ll> queC;
  ll _ans = 0;
  rep(i, a) {
    ll tmp;
    cin >> tmp;
    queA.push(tmp);
  }
  rep(i, b) {
    ll tmp;
    cin >> tmp;
    queB.push(tmp);
  }
  rep(i, c) {
    ll tmp;
    cin >> tmp;
    queC.push(tmp);
  }
  rep(i, x) {
    ll tmp = queA.top();
    queA.pop();
    ans.push(tmp);
  }
  rep(i, y) {
    ll tmp = queB.top();
    queB.pop();
    ans.push(tmp);
  }
  rep(i, c) {
    ll tmp = queC.top();
    ll min = ans.top();
    if (min > tmp) break;
    ans.pop();
    queC.pop();
    ans.push(tmp);
  }
  while (ans.size() != 0) {
    _ans += ans.top();
    ans.pop();
  }
  cout << _ans << endl;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b;
    cin>>a>>b;
    if(((a+b)%3==0) || (a%3==0) || (b%3==0))
        cout<<"Possible"<<endl;
    else
        cout<<"Impossible"<<endl;

    return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m, q;
int mx = 0;
vector<int> a(50), b(50), c(50), d(50);

int dfs(int u[], int v, int num);

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

	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	int t[10] = {};
	cout << dfs(t, 0, 1) << endl;

	return 0;
}

int dfs(int u[], int v, int num)
{
	if (v >= n) {
		int t = 0;
		for (int i = 0; i < q; i++) {
			if (u[b[i]] - u[a[i]] == c[i]) {
				t += d[i];
			}
		}
		return t;
	}
	
	for (int i = num; i <= m; i++) {
		u[v] = i;

		mx = max(mx, dfs(u, v + 1, i));
	}
	
	return mx;
}

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

int main() {
  int n;
  std::cin >> n;

  if (n % 2 == 0) {
    std::cout << n * (n - 1) / 2 - n / 2 << std::endl;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (j != n + 1 - i) {
          std::cout << i << " " << j << std::endl;
        }
      }
    }
  } else {
    std::cout << n * (n - 1) / 2 - (n - 1) / 2 << std::endl;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (j != n - i) {
          std::cout << i << " " << j << std::endl;
        }
      }
    }
  }
  return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int solve(int num, int A, int B){
    int ret = num;
    int acc = 0;
    while(num > 0){
        acc += num % 10;
        num /= 10;
    }
    //cout << ret << ": " << acc << endl;
    if(A <= acc && acc <= B) return ret;
    else return 0;
}

int main(void){
    ll X, Y; cin >> X >> Y;
    vector<ll> ans;
    ans.push_back(X);
    while(true){
        if(ans.back()*2 > Y) break;
        ans.push_back(ans.back()*2);
    }
    cout << ans.size() << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  map<ll, bool> m;
  m[a] = true;
  m[b] = true;

  for (ll i = 1; i <= 3; ++i) {
    if (m.find(i) == m.end()) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using std::cin;
using std::cout;

int L, limit, pw, point, E;
struct node { int x, y, l; };
std::vector < node > v;

inline void insert(int x, int y, int z) { v.push_back((node) {x, y, z}), ++E; }

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> L;
    for (limit = 1; limit <= L; limit <<= 1, ++point);
	for (int i = 1; i < point; ++i) insert(i, i + 1, 0), insert(i, i + 1, 1 << i - 1);
	for (int i = 1; i < point; ++i) if (L & (1 << i - 1)) L ^= (1 << i - 1), insert(i, point, L);
	cout << point << ' ' << E << '\n';
	for (int i = 0; i < E; ++i) cout << v[i].x << ' ' << v[i].y << ' ' << v[i].l << '\n';
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin>>s;
    int n = s.size();
    vi cnt(2,0);

    REP(i,n){
        cnt[s[i]-'0']++;
    }

    int ans = min(cnt[0],cnt[1])*2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
const int s = 2e5+10;
int arr[s];
long long pre[s];
int main()
{
	int n;
	long long sum,mn;
	while(~scanf("%d",&n)){
		mn=0xffffffffffffffl;
		sum=0;
		for(int i=0;i<n;++i){
			scanf("%d",&arr[i]);
			sum+=arr[i];
		}
		pre[0]=arr[0];
		for(int i=1;i<n;++i){
			pre[i]=pre[i-1]+arr[i];
		}
		for(int i=0;i<n-1;++i){
			mn=min(mn,abs(sum-2*pre[i]));
		}
		printf("%lld\n",mn);
	}
	return 0;
}


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

int main(void){
    int n = 0, m = 0;
    int t[101];
    int p = 0, x = 0;
    int sum = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d\n", &t[i]);
        sum += t[i];
    }

    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        scanf("%d%d", &p, &x);

        printf("%d\n", sum - (t[p - 1] - x) );
    }
    return 0;

} 


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
#include<math.h>
using namespace std;
int val[505] = {};

int MyPow(int a, int b)
{
	int t = 1;
	while (b--)t *= a;
	return t;
}

bool Get(int n)
{
	for (int i = 2; i < 10; i++)
	{
		int k = pow(n*1.0,1.0/i);
		k = MyPow(k,i);
		if (k == n)
			return true;
	}
	return false;
}
int main()
{
	int n;
	cin >> n;
	if (n == 1000) {
		cout << 1000;
		return 0;
	}
	n++;
	while (!Get(--n));
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int m, f, r;
	
	while(1){
		scanf("%d %d %d", &m, &f, &r);
		
		if(m==-1 && f==-1 && r==-1)
		break;
		
		if(m==-1 || f==-1)
		printf("F\n");
		
		else if(m+f>=80)
		printf("A\n");
		
		else if(m+f>=65 && m+f<80)
		printf("B\n");
		
		else if(m+f>=50 && m+f<65)
		printf("C\n");
		
		else if(m+f>=30 && m+f<50){
			if(r<50)
			printf("D\n");
			
			else
			printf("C\n");
		}
		
		else if(m+f<30)
		printf("F\n");
	}
	return 0;
}

Measured memory_bytes: 584
//*
#include <bits/stdc++.h>
//*/
/*
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
//*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
    const long long INF = LLONG_MAX / 10;
#else
    const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int H, W;
char a;
map<char, int> cnt;

int four = 0, two = 0, one = 0;

signed main()
{
    cin >> H >> W;
    REP(i,H) REP(j,W) {
        cin >> a;
        cnt[a]++;
        if (cnt[a] >= 4) {
            four++;
            cnt[a] = 0;
        }
    }

    for (auto p : cnt) {
        if (p.second == 3) {
            two++; one++;
        } else if (p.second == 2) {
            two++;
        } else if (p.second == 1) {
            one++;
        }
    }

    int needFour = 0, needTwo = 0, needOne = 0;
    if (H % 2 == 0 && W % 2 == 0) {
        needFour = (H / 2) * (W / 2);
        if (four < needFour) {
            cout << "No" << endl;
            return 0;
        } else {
            cout << "Yes" << endl;
            return 0;
        }
    } else if (H % 2 == 1 && W % 2 == 1) {
        needFour = (H / 2) * (W / 2);
        if (four < needFour) {
            cout << "No" << endl;
            return 0;
        } else {
            four -= needFour;
            two += 2 * four;
        }
        needTwo = H / 2 + W / 2;
        if (two < needTwo) {
            cout << "No" << endl;
            return 0;
        } else {
            two -= needTwo;
            one += 2 * two;
        }
        needOne = 1;
        if (one < needOne) {
            cout << "No" << endl;
            return 0;
        } else {
            cout << "Yes" << endl;
            return 0;
        }
    } else {
        needFour = (H / 2) * (W / 2);
        if (four < needFour) {
            cout << "No" << endl;
            return 0;
        } else {
            four -= needFour;
            two += 2 * four;
        }
        if (H % 2 == 1) {
            needTwo = W / 2;
        } else if (W % 2 == 1) {
            needTwo = H / 2;
        }
        //needTwo = H / 2 + W / 2;
        if (two < needTwo) {
            cout << "No" << endl;
            return 0;
        } else {
            two -= needTwo;
            one += 2 * two;
        }
        if (one == 0) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  int64_t K;
  cin>>N>>K;
  map<int,int64_t>M;
  for(int i=0;i<N;i++){
  int a;
    int64_t b;
    cin>>a>>b;
   if(M.count(a))
     M.at(a)+=b;
    else
      M[a]=b;
  }int ans;
  int64_t sum=0;
  for(auto p:M){
  auto k=p.first;
    auto v=p.second;
    sum+=v;
    if(K<=sum){
    ans=k; break;
    }
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    string s;
    cin >> s; // s = "ABA"
    set <char> v;
    for (ll i=0;i<3;i++){
        v.insert(s[i]);
    }


    if(v.size() == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

using namespace std;

int main()
{
	array<int,1000>v={0};
	long long a,b,ans=0,min=10000;
	cin >> a >> b;
	for (long long i = 0 ; i < a ; i++)
	{
		cin >> v[i];
	}

	for (long long i = 0 ; i < a ; i++)
	{
		b-=v[i];
		if (v[i]<min)
		{
			min=v[i];
		}
		ans++;
	}

	cout << ans+(b/min);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  if(N < M){
    swap(N,M);
    swap(S,T);
  }
  int a = N;
  int b = M;
  int r = a % b;
  while(r > 0){
    a = b;
    b = r;
    r = a % b;
  }
  int gcd = b;
  int64_t gcm = N*M/gcd;
  bool exist = true;
  int x = N /gcd;
  int y = M /gcd;
  
  for(int i=0; i<gcd; i++){
    if(S.at(0+i*x) != T.at(0+i*y)){
      exist = false;
    }
  }
  
  if(exist){
    cout << gcm << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[101010];
ll X;

template<class C> vector<C> gf2_rank(vector<C>& V) { /* input */
	int i,j;
	int N=V.size();
	FOR(i,N) {
		int x=max_element(V.begin()+i,V.end())-V.begin();
		if(V[x]==0) break;
		swap(V[i],V[x]);
		C msb=1;
		while(msb<<1 <= V[i]) msb<<=1;
		FOR(j,N) if(j!=i) if(V[j]&msb) V[j]^=V[i];
	}
	while(V.size() && V.back()==0) V.pop_back();
	return V;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<ll> V;
	FOR(i,N) {
		cin>>A[i];
		X^=A[i];
	}
	FOR(i,N) {
		A[i]&=~X;
		V.push_back(A[i]);
	}
	auto W=gf2_rank(V);
	ll ret=0;
	FORR(v,V) ret=max(ret,ret^v);
	cout<<ret*2+X<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2296
n = int(input())

def prime_factor(n):
    factor = []
    for i in range(2, int(n ** 0.5) + 1):
        while (n % i == 0):
            factor.append(i)
            n //= i
    if n != 1:
        factor.append(n)
    return list(set(factor))

factor = prime_factor(n)

cnt = 0
for p in factor:
    if n % p == 0:
        e = 1
        while n % pow(p, e) == 0:
            cnt += 1
            n //= pow(p, e)
            e += 1

print(cnt)

Measured memory_bytes: 63380
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n,a,b=pM(split(readline()))
  print((b-a)%2==0 ? "Alice" : "Borys")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 169480
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int div = n / 1000;
        int rem = n % 1000;
        if (rem == 0)
            cout << 0 << "\n";
        else
        {
            cout << 1000 - rem << "\n";
        }
    }
}

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

void chmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  int N;
  cin >> N;
  
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  int ans = 10000000;
  
  for (int i = 0; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {    
      sum += (A[j] - i) * (A[j] - i);
    }
    chmin(ans, sum);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
q=[(1+pp)/2 for pp in p]
ans=0
c=[0]
for qq in q:
      c.append(c[-1]+qq)
ans=0

for qq in range(k,1+n):
  ans=max(ans,c[qq]-c[qq-k])

print(ans)

Measured memory_bytes: 78984
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<map>
#include<queue>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
const int inf = 1 << 30;
const int maxn = 1e5;
typedef long long LL;
int main(){
	int n;
	cin >> n;
	bool ans = true;
	int x = 0,y = 0;
	while(n--){
		int t,a,b;
		cin >> t >> a >> b;
		if(a-x+b-y>t) ans = false;
		else if((a-x+b-y<=t)&&(a+b-x-y)%2!=t%2) ans = false;
	}
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main() {
	string s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int r[4] = {}, p=0, o = 0;
		r[0] = 1;
		while (o != 3) {
			cin >> s;
			if (s[1] == 'I') {
				if (r[3])
					p++;
				for (int j = 3; j >= 1; j--)
					r[j] = r[j - 1];
			}
			else if (s[1] == 'U')
				o++;
			else if (s[1] == 'O') {
				p++;
				for (int j = 1; j <= 3; j++) {
					if (r[j]) {
						p++;
						r[j] = 0;
					}
				}
			}
		}
		cout << p << endl;
	}
	return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
#include <set>
using namespace std;
const int N = 70002;
map<string, int> vmap;
char name[N][22], str[22];
int val[N], n, m, sz, bsz;
typedef pair<int, int> PII;

set<PII> vset, mset;
set<PII>:: iterator it, rit;
bool suc;
int main(){
//	freopen ("in.txt", "r", stdin);
//	freopen ("out.txt", "w", stdout);
	cin >> n; int v;
	for (int i = 0; i < n; i++) {
		scanf ("%s %d", str, &v);
		vmap[str] = i;
		strcpy(name[i], str);
		val[i] = v;
		mset.insert(make_pair(v, i));
	}
	cin >> m; sz = n;
	for (int i = 0; i < sz/5; i++) {
		it = mset.end(); it--;
		vset.insert(*it);
		mset.erase(*it);
	}
	for (int i = 0; i < m; i++){
//		cout << vset.size() << ' ' << mset.size() << endl;
		scanf ("%s", str);
//		puts(str); cout << sz << endl;
		if (str[0] == '+'){
			scanf ("%s %d", str, &v);
			strcpy(name[n], str);
			val[n] = v;
			sz++;
			mset.insert(make_pair(v, n));
			it = mset.end(); it--;
			if (sz % 5 == 0){
				vset.insert(*it);
				if ((*it).second == n) printf ("%s is working hard now.\n", name[n]), suc = 1;
				else {
					printf ("%s is not working now.\n", name[n]);
					printf ("%s is working hard now.\n", name[(*it).second]);
					suc = 1;
				}
				mset.erase(it);
			}
			else {
				if (vset.size() && *it > *vset.begin()){
					PII nv = *vset.begin();
					vset.erase(nv);
					vset.insert(*it);
					if ((*it).second == n) {
						printf ("%s is working hard now.\n", name[n]);
						printf ("%s is not working now.\n", name[nv.second]);
						suc = 1;
					}
					else {
						printf ("%s is not working now.\n", name[n]);
						suc = 1;
						if ((*it).second > nv.second){
							printf ("%s is working hard now.\n", name[(*it).second]);
							printf ("%s is not working now.\n", name[nv.second]);
						} else {
							printf ("%s is not working now.\n", name[nv.second]);
							printf ("%s is working hard now.\n", name[(*it).second]);
						}
					}
					mset.erase(it);
					mset.insert(nv);
				}
				else {
					printf ("%s is not working now.\n", name[n]);
					suc = 1;
				}
			}

			vmap[str] = n++;
		} 
		else {
			scanf ("%s", str);
			int u = vmap[str];
//			cout << str << ' ' << u << ' ' << name[u] << endl;
			PII nv = make_pair(val[u], u);
			vmap.erase(str);
			sz--;
			if (sz % 5 != 4){
				it = mset.lower_bound(nv);
				if (it != mset.end() && *it == nv){
					mset.erase(it);
				} else {
//					cout << name[nv.second] << ' ' << nv.first << endl;
					vset.erase(nv);
					it = mset.end(); it--;
					printf ("%s is working hard now.\n", name[(*it).second]);
					suc = 1;
					vset.insert(*it);
					mset.erase(it);
				}
			} else {
				it = vset.lower_bound(nv);
				if (it != vset.end() && *it == nv){
//					cout << str << ' ' << name[(*it).second] << ' ' << (*it).first << endl;
					vset.erase(it);
				} else {
					mset.erase(nv);
					it = vset.begin();
					printf ("%s is not working now.\n", name[(*it).second]);
					suc = 1;
					mset.insert(*it);
					vset.erase(it);
				}
			}
		}
//		cout << i << ' ' << vset.size() << ' ' << sz << endl;
	}
//	if (!suc) puts("(blank)");
}


Measured memory_bytes: 12604
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 

bool ng(int a, int b, int c){
    return (a == 1 && b == 2 && c == 3);
}

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

int N; cin >> N;
vector<vector<VVI>> cnt(N+1, vector<VVI>(4, VVI(4, VI(4, 0))));
cnt[0][0][0][0] = 1; // TAGC = 0123

rep(i, 0, N) rep(a, 0, 4) rep(b, 0, 4) rep(c, 0, 4) rep(d, 0, 4) {
    if (ng(b, c, d)|| ng(c, b, d) || ng(b, d, c)) continue;
    if (ng(a, c, d) || ng(a, b, d)) continue;

    (cnt[i+1][b][c][d] += cnt[i][a][b][c]) %= MOD;
}

i64 ans = 0;
rep(a, 0, 4) rep(b, 0, 4) rep(c, 0, 4)
    (ans += cnt[N][a][b][c]) %= MOD;
cout << ans << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 384
n, k = map(int,input().split())
s = input()
i = 0
while len(s) > i + 1:
    if s[i] == s[i + 1]:
        s = s[:i] + s[i + 1:]
    else:
        i += 1

ans = len(s)

for i in range(k):
    if ans > 2:
        ans -= 2
    elif ans == 1:
        break
    elif ans == 2:
        ans = 1

ans = n - ans

print(ans)

Measured memory_bytes: 3416
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cmath>
using namespace std;
#define fio ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int N,M;
int main() {
	scanf("%d %d", &N, &M);
	ll ans = N * M - (M + N - 1);

	printf("%d", ans);

}



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

int main(){
  long long A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  
  int d = abs(A-B);
  if(V <= W){
  	cout << "NO" << endl;
    return 0;
  }
  int s = V-W;
  if(d <= (long long)s*T) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 3616
X = gets.to_i

case X
when 400..599
  p 8
when 600..799
  p 7
when 800..999
  p 6
when 1000..1199
  p 5
when 1200..1399
  p 4
when 1400..1599
  p 3
when 1600..1799
  p 2
when 1800..1999
  p 1
end


Measured memory_bytes: 14420
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib>
#include <typeinfo>

using namespace std;

#define FOR(i,n) for(i=0;i<n;++i)
#define INF 1e9

int i,j;

int main(void){
    
    int n,m;
    cin>>n>>m;
    
    int a[n],b[n],c[m],d[m];
    int ans[n];
    FOR(i,n){
        cin>>a[i]>>b[i];
        ans[i]=INF;
    }
    FOR(i,m)cin>>c[i]>>d[i];
    
    int now,point[i];
    FOR(i,n){
        FOR(j,m){
            now = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(ans[i]>now){
                ans[i]=now;
                point[i]=j+1;
            }
        }
    }
    FOR(i,n)cout<<point[i]<<endl;
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  int x[100];
  bool flag = true;
  cin >> N;
  for(int i=0; i < N;i++){
  cin >> x[i];
  }
  for(int i =0; i < N; i++){
    if(x[i] % 2 == 0 && x[i] % 3 != 0 && x[i] % 5 != 0)
      flag = false;
       }
  if(flag == true)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
 
 
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())
ans = 0
if N <= K:
    for n in range(1, N+1):
        ans += (1/N) * (1/2)**math.ceil(math.log2(K/n))
elif N > K:
    for n in range(1, K+1):
        ans += (1/N) * (1/2)**math.ceil(math.log2(K/n))
    ans += (1/N) * (N - (K+1) + 1)
print(ans)

Measured memory_bytes: 3188
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;


int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	for(int i=0;i<N;i++)cin >> S[i];
	int a=INF,b=INF,c=INF,d=INF,e=INF,f=INF,g=INF,h=INF,i=INF,j=INF,k=INF,l=INF,m=INF,n=INF,o=INF,p=INF,q=INF,r=INF,s=INF,t=INF,u=INF,v=INF,w=INF,x=INF,y=INF,z=INF;
	for(int I=0;I<N;I++){
		int tmpa=0,tmpb=0,tmpc=0,tmpd=0,tmpe=0,tmpf=0,tmpg=0,tmph=0,tmpi=0,tmpj=0,tmpk=0,tmpl=0,tmpm=0,tmpn=0,tmpo=0,tmpp=0,tmpq=0,tmpr=0,tmps=0,tmpt=0,tmpu=0,tmpv=0,tmpw=0,tmpx=0,tmpy=0,tmpz=0;
		for(int J=0;J<S[I].length();J++){
			if(S[I][J]=='a')tmpa++;
			 if(S[I][J]=='b')tmpb++;
			 if(S[I][J]=='c')tmpc++;
			 if(S[I][J]=='d')tmpd++;
			 if(S[I][J]=='e')tmpe++;
			 if(S[I][J]=='f')tmpf++;
			 if(S[I][J]=='g')tmpg++;
			 if(S[I][J]=='h')tmph++;
			 if(S[I][J]=='i')tmpi++;
			 if(S[I][J]=='j')tmpj++;
			 if(S[I][J]=='k')tmpk++;
			 if(S[I][J]=='l')tmpl++;
			 if(S[I][J]=='m')tmpm++;
			 if(S[I][J]=='n')tmpn++;
			 if(S[I][J]=='o')tmpo++;
			 if(S[I][J]=='p')tmpp++;
			 if(S[I][J]=='q')tmpq++;
			 if(S[I][J]=='r')tmpr++;
			 if(S[I][J]=='s')tmps++;
			 if(S[I][J]=='t')tmpt++;
			 if(S[I][J]=='u')tmpu++;
			 if(S[I][J]=='v')tmpv++;
			 if(S[I][J]=='w')tmpw++;
			 if(S[I][J]=='x')tmpx++;
			 if(S[I][J]=='y')tmpy++;
			 if(S[I][J]=='z')tmpz++;
			

	}
	a=min(a,tmpa);b=min(b,tmpb);c=min(c,tmpc);d=min(d,tmpd);e=min(e,tmpe);f=min(f,tmpf);g=min(g,tmpg);h=min(h,tmph);i=min(i,tmpi);j=min(j,tmpj);k=min(k,tmpk);l=min(l,tmpl);m=min(m,tmpm);n=min(n,tmpn);o=min(o,tmpo);p=min(p,tmpp);q=min(q,tmpq);r=min(r,tmpr);s=min(s,tmps);t=min(t,tmpt);u=min(u,tmpu);v=min(v,tmpv);w=min(w,tmpw);x=min(x,tmpx);y=min(y,tmpy);z=min(z,tmpz);
	
	}
	
	string ans=string(a,'a')+ string(b,'b')+ string(c,'c')+ string(d,'d')+ string(e,'e')+ string(f,'f')+ string(g,'g')+ string(h,'h')+ string(i,'i')+ string(j,'j')+ string(k,'k')+ string(l,'l')+ string(m,'m')+ string(n,'n')+ string(o,'o')+ string(p,'p')+ string(q,'q')+ string(r,'r')+ string(s,'s')+ string(t,'t')+ string(u,'u')+ string(v,'v')+ string(w,'w')+ string(x,'x')+ string(y,'y')+ string(z,'z');
	cout <<ans<<endl;
	}


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

int main(){
  ll n,m,i;
  cin >> n >> m;
  vector<ll> a(n),b(n),p(n,0);
  for(i=0;i<n;i++){
    cin >> a.at(i);
    a.at(i) /= 2;
    b.at(i)=a.at(i);
    while(b.at(i)%2==0){
      b.at(i) /= 2;
      p.at(i)++;
    }
    if(p.at(i)!=p.at(0)){
      cout << 0 << endl;
      return 0;
    }
  }
  
  ll lcm=a.at(0);
  for(i=1;i<n;i++){
    lcm=lcm*a.at(i)/__gcd(lcm,a.at(i));
    if(lcm>m){
      cout << 0 << endl;
      return 0;
    }
  }
  
  cout << (m+lcm)/(2*lcm) << endl;
}

Measured memory_bytes: 5544
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }

    sort(all(a));

    vi dp(t, -1);
    dp[0] = 0;
    int ans = 0;
    rep(i, n) {
        for(int j = t-1; j >= 0; --j) {
            if(dp[j] != -1) {
                if(j+a[i].first < t) {
                    dp[j+a[i].first] = max(dp[j+a[i].first], dp[j]+a[i].second);
                } else {
                    ans = max(ans, dp[j]+a[i].second);
                }
            }
        } 
    }

    rep(i, t) {
        ans = max(ans, dp[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k <= a) {
    cout << k << endl;
  }else if(k <= a+b) {
    cout << a << endl;
  }else {
    cout << a - (k-a-b) << endl;
  }
  return 0;
}


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

vector<vector<int>> field;
vector<int> r_list;
vector<int> perm;
map<int, bool> used;

const int INF = 100000000;
int result = INF;

void dfs(int i, int n)
{
    if (i == n)
    {
        int tmp = 0;
        for (int j = 0; j < n - 1; j++)
        {
            tmp += field[perm[j]][perm[j + 1]];
        }
        result = min(result, tmp);
        return;
    }

    for (int j : r_list)
    {
        if (!used[j])
        {
            perm.push_back(j);
            used[j] = true;
            dfs(i + 1, n);
            perm.pop_back();
            used[j] = false;
        }
    }

    return;
}

int main()
{
    int N, M, R;
    cin >> N >> M >> R;
    field = vector<vector<int>>(N + 1, vector<int>(N + 1, INF));

    for (int i = 0; i < R; i++)
    {
        int r;
        cin >> r;
        r_list.push_back(r);
        used[r] = false;
    }

    for (int i = 0; i < M; i++)
    {
        int A, B, C;
        cin >> A >> B >> C;
        field[A][B] = field[B][A] = C;
    }

    for (int i = 1; i <= N; i++)
    {
        field[i][i] = 0;
    }

    for (int k = 1; k <= N; k++)
    {
        for (int j = 1; j <= N; j++)
        {

            for (int i = 1; i <= N; i++)
            {
                field[i][j] = min(field[i][j], field[i][k] + field[k][j]);
            }
        }
    }

    // This may be not necesarry.
    sort(r_list.begin(), r_list.end());

    // permutation
    for (int i : r_list)
    {
        perm.push_back(i);
        used[i] = true;
        dfs(1, r_list.size());
        perm.pop_back();
        used[i] = false;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_7_A {
    class Node {
        public int Parent { get; set; }
        public int Depth { get; set; }
        public List<int> Children { get; set; }

        public Node() {
            Parent = -1;
            Children = new List<int>();
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Dictionary<int, Node> nodes = Enumerable.Range(0, n)
                .ToDictionary(i => i, i => new Node());

            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                int nodeId = int.Parse(input[0]);
                int childrenVolume = int.Parse(input[1]);
                if (childrenVolume == 0)
                    continue;
                for (int j = 0; j < childrenVolume; j++) {
                    int childId = int.Parse(input[j + 2]);
                    nodes[nodeId].Children.Add(childId);
                    nodes[childId].Parent = nodeId;
                }
            }

            int root = GetParent(nodes);
            CheckDepth(nodes, root);
            Print(nodes);
        }

        static int GetParent(Dictionary<int,Node> nodes) {
            for (int i = 0; i < nodes.Count; i++)
                if (nodes[i].Parent == -1)
                    return i;
            return -1;
        }

        static void CheckDepth(Dictionary<int, Node> nodes,int root) {
            Stack<int> stk = new Stack<int>(nodes[root].Children);

            while (stk.Count > 0) {
                int cur = stk.Pop();
                nodes[cur].Depth = nodes[nodes[cur].Parent].Depth + 1;
                if (nodes[cur].Children.Count != 0) {
                    foreach (var child in nodes[cur].Children) {
                        stk.Push(child);
                    }
                }
            }
        }

        static void Print(Dictionary<int, Node> nodes) {
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < nodes.Count; i++) {
                sb.Append("node " + i);
                sb.Append(": parent = " + nodes[i].Parent);
                sb.Append(", depth = " + nodes[i].Depth);
                sb.Append(", " + GetType(nodes, i));
                sb.Append(", [");
                for(int j = 0; j < nodes[i].Children.Count; j++) {
                    if (j > 0)
                        sb.Append(", ");
                    sb.Append(nodes[i].Children[j]);
                }
                sb.AppendLine("]");
            }
            Console.Write(sb);
        }

        static string GetType(Dictionary<int,Node>nodes,int index) {
            if (nodes[index].Parent == -1)
                return "root";
            if (nodes[index].Children.Count == 0)
                return "leaf";
            return "internal node";
        }
    }
}

Measured memory_bytes: 61412
#![allow(non_snake_case)]

use std::io;

fn main() {
    let sin = io::stdin();
    loop {
        let mut buf = String::new();
        sin.read_line(&mut buf).ok();
        let mut ws = buf.split_whitespace();
        let m: i32 = ws.next().unwrap().parse().unwrap();
        let f: i32 = ws.next().unwrap().parse().unwrap();
        let r: i32 = ws.next().unwrap().parse().unwrap();

        if m == -1 && f == -1 && r == -1 {
            break;
        } else {
            let grade = if m == -1 || f == -1 {
                "F"
            } else {
                let s = m+f;
                match s {
                    80...100 => "A",
                    65...84  => "B",
                    50...64  => "C",
                    30...49  => { if r >= 50 {"C"} else {"D"} },
                    _  => "F",
                }
            };
            println!("{}", grade);
        }
    }
}



Measured memory_bytes: 5024
from collections import defaultdict


def main():
    N, x = map(int, input().split())
    c = list(map(int, input().split()))
    pre = sum(c)

    c = [min(i, x) for i in c]
    ans = pre - sum(c)

    for i in range(len(c) - 1):
        if c[i] + c[i + 1] > x:
            n = (c[i] + c[i + 1]) - x
            c[i + 1] -= n
            ans += n

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14516
#include <iostream>
#include <queue>
#include <string>

using namespace std;
#define NINF -999999
typedef pair<int, int> P;
int field[21][21];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

void solve()
{
	int W, H;
	while(cin >> W >> H)
	{
		if(!W && !H)
		{
			break;
		}
		string tile[21];
		for(int i = 0; i < H; ++i)
		{
			cin >> tile[i];
		}
		queue<P> Que;
		for(int i = 0; i < H; ++i)
		{
			for(int j = 0; j < W; ++j)
			{
				if(tile[i][j] == '@')
				{
					P p;
					p.first = i;
					p.second = j;
					Que.push(p);
					field[i][j] = 0;
				}
				else
				{
					field[i][j] = NINF;
				}
			}
		}
		int count = 1;
		queue<P> NextQue;
		while(!Que.empty())
		{
			for(int i = 0; i < 4; ++i)
			{
				P p;
				p.first = Que.front().first + dy[i];
				p.second = Que.front().second + dx[i];
				
				if(p.first < 0 || p.first >= H || p.second < 0 || p.second >= W)
				{
					continue;
				}
				else if((tile[p.first][p.second] != '#') && (field[p.first][p.second] == NINF))
				{
					field[p.first][p.second] = field[Que.front().first][Que.front().second] + 1;
					NextQue.push(p);
					count++;
				}
			}
			Que.pop();
			if(Que.empty())
			{
				while(!NextQue.empty())
				{
					Que.push(NextQue.front());
					NextQue.pop();
				}
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

using namespace std;

int main(){
  int a, b; cin >> a >> b;
  if (a+b>=10) cout << "error" << endl;
  else cout << a+b << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

int main() {

    string s,t; cin >> s >> t;

    int n, m;
    n = s.length();
    m = t.length();

    int dp[n+1][m+1];
    // dp[i][j] : sのi文字目、tのj文字目のLCSの長さ
    rep(i, n+1) rep(j, m+1) dp[i][j] = 0;

    // dpテーブルの構築
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string ans = "";
    int x = n;
    int y = m;
    while(x > 0 && y > 0){
        if(dp[x][y] == dp[x-1][y]) x--;
        else if(dp[x][y] == dp[x][y-1]) y--;
        else {
            // t, sを1文字づつ減らしていく
            // どちらかが減ってもLCSの桁が変わらない場合はその文字は不要な文字なので削除
            // 両方ともLCSが-1になってしまうときが、共通文字の箇所なので、この文字をansに突っ込む
            // これをt,s両方ともの全ての文字に対して行う
            x--; y--;
            ans.push_back(s[x]);
        }
    }

    // 逆順に入っているので、リバースする
    reverse(ans.begin(), ans.end());

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 35456
#include<iostream>
#include<set>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int X, N; std::cin >> X >> N;
  std::set<int> s;
  for(int i = 0; i < N; ++i) {
    int p; std::cin >> p;
    s.insert(p);
  }
  if(s.count(X) == 0) fin(X);
  for(int i = 1;; ++i) {
    if(s.count(X-i) == 0) fin(X-i);
    if(s.count(X+i) == 0) fin(X+i);
  }
  return 0;
}


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

using namespace std;

uint64_t pow3(uint64_t n)
{
  return n * n * n;
}

int main()
{
  uint64_t N, K;
  cin >> N >> K;
  
  uint64_t P = N / K;
  
  uint64_t S = pow3(P);
  if (K % 2 == 0) {
    uint64_t Q = (N + (K / 2)) / K;
    S += pow3(Q);
  }
  
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if (s=="ani") cout<<"square1001\n";
    else cout<<"e869120\n";
    return 0;
}



Measured memory_bytes: 3088
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v: Vec<i32> = read_vec();
    (v[0], v[1])
}

fn main() {
    let (N, Q) = read_int_tuple();
    let N = N as usize;
    let S: Vec<char> = read_line().chars().collect();
    let mut count = vec![0; N];
    for i in 1..N {
        count[i] = count[i-1] + (S[i-1] == 'A' && S[i] == 'C') as i64;
    }
    for _ in 0..Q as usize {
        let (l, r) = read_int_tuple();
        println!("{}", count[r as usize -1] - count[l as usize -1]);
    }
}


Measured memory_bytes: 4988
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		B(sc);
	}
	
	public static void A(Scanner sc) {
		int N = sc.nextInt();
		int A = sc.nextInt();
		if(N%500 <=A) out.println("Yes");
		else out.println("No");
	}
	
	public static void B(Scanner sc) {
		int N = sc.nextInt();
		int ret = 0;
		Integer[] a = new Integer[N];
		for(int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a,Collections.reverseOrder());
		for(int i=0;i<N;i++) {
			if(i%2==0) ret+=a[i];
			else ret-=a[i];
		}
		out.println(ret);
	}
}

Measured memory_bytes: 22868
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt64(scanner)
	aa := make([]int, 0)
	for x := n - 1; x >= 0; x = x/26 - 1 {
		aa = append(aa, int(x%26))
	}
	for i := len(aa) - 1; i >= 0; i-- {
		fmt.Fprint(writer, fmt.Sprintf("%c", 'a'+aa[i]))
	}
	fmt.Fprintln(writer, "")
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int W = 0;
    int H = 0;
    int x = 0;
    int y = 0;
    int r = 0;
    cin>>W>>H>>x>>y>>r;

    if ((W - x) >= r && (H - y) >= r &&
            (x - r )>= 0 && (y - r )>= 0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const long long int MODU = 1e9+7;
const int N = 1e5+10;


void solve() {
	
}

int main() {
	long long int ans = 0, n, k;
	cin >> n >> k;
	long long int temp = 0, sum = 0;
	for(long long int i = k; i <= n+1; i++) {
		temp = ((i)*(2*n-i+1))/2;
		sum += (temp - ((i)*(i-1))/2 + 1);
		sum = sum % MODU;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<cstdio>
using namespace std;

int main(){
  int x,a,b;
  scanf("%d%d%d",&x,&a,&b);
  int ans=b-a;
  if(ans<=0){
    cout<<"delicious"<<endl;
  }
  else if(ans<=x){
    cout<<"safe"<<endl;
  }
  else{
    cout<<"dangerous"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n,m,i,j,t[100],p,x,time;

	cin >> n;
	for (i = 0; i < n; i++) cin >> t[i];
	cin >> m;
	for (i = 0; i < m; i++) {
		time = 0;
		cin >> p >> x;
		for (j = 0; j < n; j++) {
			if (j == p - 1)time += x;
			else time += t[j];
		}
		cout << time << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    # N = int(input())
    # vA = [int(input()) for _ in [0,]*N]
    # h,m,H,M,K = linput()
    S = input().rstrip()

    res = S.replace("?", "D")
    print(res)
    # print(("No","Yes")[res%2])
    # print(*vR, sep="\n")

main()


Measured memory_bytes: 9468