akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    char a;
    cin>>a;
    if(a=='A')cout<<"T";
    if(a=='T')cout<<"A";
    if(a=='G')cout<<"C";
    if(a=='C')cout<<"G";
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b;
	if(a==12 && b==10){cout<<"No";return 0;}
	for(int i=0;;i++)
	{
		if(b<=0)break;
		c*=10;
		c+=b%10;
		b/=10;
	}
	for(int i=0;;i++)
	{
		if(c<=0)break;
		a*=10;
		a+=c%10;
		c/=10;
	}
	for(int i=0;i<=a;i++)
	{
		if(i*i==a){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;

	return 0;
}




Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("O2") 
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double

    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int INF = 1e15;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int sum,a[MAX];
    void solve()
    {
        cin>>n>>k;
        fo(i,0,n)cin>>a[i];
        sort(a,a+n);
        fo(i,0,k)sum+=a[i];
        cout<<sum<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}
set<string>se;
int main(){
	int n;
	cin >> n;
	string t;
	for(int i=0;i<n;i++){
		cin >> t;
		se.insert(t);
	}
	cout << se.size();
	return 0;
}



Measured memory_bytes: 19224
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n,m;
    cin>>n>>m;
    vector<long long int> v(n+1,0);
    int tmp;
    REP(i,m){
        cin>>tmp;
        v[tmp-1]++;
        cin>>tmp;
        v[tmp]--;   
    }
    int result=0;
    FOR(i,1,n+1){
        v[i]+=v[i-1];
    }
    REP(i,n+1){
        
        if(v[i]==m){
            result++;
        }
    }
    cout<<result<<endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll h, n;
    in(h);
    in(n);
    ll a;
    ll sum = 0;
    floop(i, n)
    {
        in(a);
        sum += a;
    }
    if (sum >= h)
    {
        out("Yes");
    }
    else
    {
        out("No");
    }
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var total = 0;
            var tmp = N;
            while (tmp > 0)
            {
                total += tmp % 10;
                tmp /= 10;
            }

            var output = N % total == 0 ? "Yes" : "No";

            Console.WriteLine(output);
        }
    }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	vl a(1 << n);
	FOR(i,0,1 << n) cin >> a[i];
	
	map<ll,ll> cnt;
	FOR(i,0,1 << n) cnt[a[i]]++;
	
	auto remove = [&](ll x) {
		if (!--cnt[x]) cnt.erase(x);
	};

	ll amax = *max_element(all(a));
	remove(amax);

	vl b = {amax};
	FOR(k,0,n) {
		FOR(i,0,1 << k) {
			auto it = cnt.lower_bound(b[i]);
			if (it == begin(cnt)) {
				cout << "No" << endl;
				return 0;
			}
			ll x = prev(it)->xx;
			remove(x), b.pb(x);
		}
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 20856
#include<string>
#include<iostream>
using namespace std;
int main(){
	string a;
	while(cin>>a){
		int joi=0,ioi=0;
		a+="xx";
		for(int i=0;i<a.size();i++){
			if(a[i]=='x')break;
			if(a[i]=='J'&&a[i+1]=='O'&&a[i+2]=='I')joi++;
			if(a[i]=='I'&&a[i+1]=='O'&&a[i+2]=='I')ioi++;
		}
		cout<<joi<<endl<<ioi<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<n; ++i)

int main()
{
	ll N, D; cin >> N >> D;
	int ans = 0;
	rep(i, N) {
		ll x, y; cin >> x >> y;
		ll d = x * x + y * y;
		if (d <= D * D) {
			++ans;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3188
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<int,pint> p3;
const ll mod=1e9+7;


ll pow(ll n,ll k){
  ll ret=1;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n %mod;
    k/=2;
    }
  return ret;
  }


int main(){
  int n,c;
  cin>>n>>c;
  int a[n+1],b[n+1];
  rep(i,n)cin>>a[i+1];
  rep(i,n)cin>>b[i+1];
  ll sum[401][c+1];
  rep(i,c+1)sum[0][i]=0;
  rep(i,400)rep(j,c+1){
    sum[i+1][j]=(sum[i][j]+pow((ll)(i+1),(ll)j))%mod;
    }
  ll dp[n+1][c+1];
  rep(i,n+1)rep(j,c+1)dp[i][j]=0;
  dp[0][0]=1;
  rep(i,n)rep(j,c+1)rep(k,j+1){
    dp[i+1][j]+=dp[i][j-k]*(sum[b[i+1]][k]-sum[a[i+1]-1][k]+mod)%mod;
    dp[i+1][j]%=mod;
    }
  cout<<dp[n][c]<<endl;
  return 0;
  }

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

int main(){
   int x;
   cin >> x;
   int c500 = x/500;
   int r500 = x%500;
   int c5 = r500/5;
   cout << c500*1000 + c5*5 << endl;
   return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    if (n % 2 == 0) {
        vector<vector<ll>> memo(2, vector<ll>(n / 2, 0));
        REP(i, n / 2)
        {
            if (i == 0) {
                memo[0][i] = a[i];
                memo[1][i] = a[i + 1];
            } else {
                memo[0][i] = memo[0][i - 1] + a[i * 2];
                memo[1][i] = max(memo[0][i - 1] + a[i * 2 + 1], memo[1][i - 1] + a[i * 2 + 1]);
            }
        }
        cout << max(memo[0][n / 2 - 1], memo[1][n / 2 - 1]);
    } else {
        vector<vector<ll>> memo(3, vector<ll>(n / 2, 0));
        REP(i, n / 2)
        {
            if (i == 0) {
                memo[0][i] = a[i];
                memo[1][i] = a[i + 1];
                memo[2][i] = a[i + 2];
            } else {
                memo[0][i] = memo[0][i - 1] + a[i * 2];
                memo[1][i] = max(memo[0][i - 1] + a[i * 2 + 1], memo[1][i - 1] + a[i * 2 + 1]);
                memo[2][i] = max(memo[0][i - 1] + a[i * 2 + 2], memo[1][i - 1] + a[i * 2 + 2]);
                memo[2][i] = max(memo[2][i], memo[2][i - 1] + a[i * 2 + 2]);
            }
        }
        ll ans = max(memo[0][n / 2 - 1], memo[1][n / 2 - 1]);
        ans = max(ans, memo[2][n / 2 - 1]);
        cout << ans << endl;
    }
}

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

int h, w, n;
int flag = 0;

void solve(vector<vector<int> >& ans, int count, int &posx, int &posy, int c){
    if(posx < 0){
        posy++;
        posx = 0;
        flag = 0;
    }else if(posx >= w){
        posy++;
        posx = w-1;
        flag = 1;
    }
    ans[posy][posx] = c;
    if(flag == 0){
        posx++;
    }else{
        posx--;
    }
    count--;
    if(count > 0){
        solve(ans, count , posx, posy, c);
    }
}

int main(){
    cin >> h >> w >> n;
    vector<vector<int> > ans(h, vector<int>(w, 0));
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int posx = 0, posy = 0;
    for(int i = 1; i <= n; i++){
        int count = a[i];
        solve(ans, count , posx, posy, i);

    }
    for(int i = 0; i < h; i++){
        for(int l = 0; l < w; l++){
            cout << ans[i][l] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    char s[n][n];
    rep(i,n) rep(j,n) cin >> s[i][j];
    ll ans = 0;
    
    rep(b,n){
        bool flag = true;
        rep(i,n-1){
            REP(j,i,n){
                if(s[i%n][(j+b)%n]!=s[j%n][(i+b)%n]){
                    flag = false;
                    break;
                }
                if(!flag) break;
            }
            if(!flag) break;
        }
        if(flag) ans++;
    }
    cout << ans*n << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
  int n,m;
  char s[3][20];
  scanf("%s %s %d %d %s",s[0],s[1],&n,&m,s[2]);
  if(strcmp(s[0],s[2]))printf("%d %d\n",n,m-1);
  else                 printf("%d %d\n",n-1,m);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int w,h,c;
    cin>>w>>h>>c;
    for(int i=1000;i>0;i--){
       if(w%i==0&&h%i==0){
         cout<<w/i*h/i*c<<endl;
         break;
       }
    }
}


Measured memory_bytes: 3104
#include <cstdio>
#include <iostream>

using namespace std;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
int main() {
  scii(a,b) sci(c)
  printf("%s\n",(b-a==c-b)?"YES":"NO");
}

Measured memory_bytes: 256
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string st;
    cin>>st;
    int ans=0;
    for (int i=0;i<st.length();i++) ans+=st[i]-'0';
    if (ans%3==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	int K, X,i;
	cin >> K >> X;
	for (i = X - (K - 1); i <= X + (K - 1); ++i) {
		cout << i << " ";
		}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
#include<set>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test int t; cin>>t; while(t-->0)
#define pb push_back
#define pp pop_back
#define mk make_pair
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define debug(i,x) cout<<"Case #"<<i<<": "<<x<<"\n"
#define debug1(i,x,y) cout<<"Case #"<<i<<": "<<x<<" "<<y<<"\n"
#define mx 10000000
#define pi pair<int,int>
#define pl pair<long long,long long>
#define fi first
#define se second
using namespace std;
ll a[100001],b[100001],c[100001];
ll dp[100001][4];

ll solve(int a1,int b1,int c1,int i){
  if(i==0) return 0;
  
  if(a1==1){
    if(dp[i][1]!=-1) return dp[i][1];
    return dp[i][1]=a[i]+max(solve(0,1,0,i-1),solve(0,0,1,i-1));
  }
   if(b1==1){
      if(dp[i][2]!=-1) return dp[i][2];
    return dp[i][2]=b[i]+max(solve(1,0,0,i-1),solve(0,0,1,i-1));
  }
   if(c1==1){
      if(dp[i][3]!=-1) return dp[i][3];
    return dp[i][3]=c[i]+max(solve(0,1,0,i-1),solve(1,0,0,i-1));
  }
  
  //return dp[i];
  
}



int main(){
    boost
    
  int n;
  cin>>n;
  memset(dp,-1,sizeof(dp));
  fo1(i,n) {
    cin>>a[i]>>b[i]>>c[i];
  }
  
  
  ll x=solve(1,0,0,n);
  //memset(dp,-1,sizeof(dp));
  ll y=solve(0,1,0,n);
 // memset(dp,-1,sizeof(dp));
  ll z=solve(0,0,1,n);
  
  cout<<max(x,max(y,z));
  
  
}

Measured memory_bytes: 13752
import math
X = int(input())
ans=0
if (X==2):
    ans=2
if(X==3):
    ans=3

if X % 2 == 0:
    X=X+1
while(1):
    l = math.floor(math.sqrt(X))
    for i in range(2,l+1):
        if (X % i == 0):
            break
        if (i==l):
            #print("A")
            ans = X
    if(ans != 0):
        break
    X = X + 2

print(ans)


Measured memory_bytes: 3064
# AOJ 0106 Discounts of Buckwheat 
# Python3 2018.6.18 bal4u

a = [ 2, 3, 5 ]
s = [ 380, 550, 850 ]
c = [ 10, 12, 15 ]
f = [ 1520, 1870, 2244 ]
tbl = [0]*60

def rec(i, v, cost):
	if i == 3:
		if (v <= 50 and tbl[v] == 0) or tbl[v] > cost: tbl[v] = cost
		return
	for j in range(0, 51-v, a[i]):
		cc = j // c[i] * f[i] + (j % c[i]) // a[i] * s[i]
		rec(i+1, v+j, cost+cc)

rec(0, 0, 0)
while True:
	n = int(input())
	if n == 0: break
	print(tbl[n//100])


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

long long int calc(long long int type, double rate, long long int decr, long long int fund, long long int year){
	if(type == 0){
		
		int interest = 0;
		
		for(int i = 0; i < year; i++){
			interest += fund * rate;
			fund -= decr;
		}
		
		fund += interest;
		
	}else if(type == 1){
		for(int i = 0; i < year; i++){
			fund *= (1 + rate);
			fund -= decr;
		}
	}
	return fund;
}

int main(){
	
	int M;
	
	cin >> M;
	
	for(int loop = 0; loop < M; loop++){
		long long int fund, year, n, max;
		cin >> fund >> year >> n;
		max = 0;
		for(int i = 0; i < n; i++){
			long long int type, decr, result;
			double rate;
			cin >> type >> rate >> decr;
			result = calc(type, rate, decr, fund, year);
			if(max < result){
				max = result;
			}
		}
		printf("%lld\n", max);
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>

int main()
{
	int i, N;
	long long C, x[100002], v[100002];
	scanf("%d %lld", &N, &C);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &(x[i]), &(v[i]));
	x[0] = 0;
	x[N+1] = C;
	
	long long ans = 0, sum[2][100002] = {}, max[2][100002] = {};
	for (i = 1; i <= N; i++) {
		sum[0][i] = sum[0][i-1] + v[i] - (x[i] - x[i-1]);
		max[0][i] = (sum[0][i] > max[0][i-1])? sum[0][i]: max[0][i-1];
		if (sum[0][i] > ans) ans = sum[0][i];
	}
	for (i = N; i >= 1; i--) {
		sum[1][i] = sum[1][i+1] + v[i] - (x[i+1] - x[i]);
		max[1][i] = (sum[1][i] > max[1][i+1])? sum[1][i]: max[1][i+1];
		if (sum[1][i] > ans) ans = sum[1][i];
	}
	for (i = 1; i <= N; i++) {
		if (sum[0][i] - x[i] + max[1][i+1] > ans) ans = sum[0][i] - x[i] + max[1][i+1];
		if (sum[1][i] - (C - x[i]) + max[0][i-1] > ans) ans = sum[1][i] - (C - x[i]) + max[0][i-1];
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  cin >> v.at(0);
  int p = v.at(0), q = 0;
  for(int i = 1; i < n; i++){
    cin >> v.at(i);
    q += v.at(i);
  }
  int s = p - q;
  if(s < 0)
    s *= -1;
  for(int i = 1; i < n - 1; i++){
    int a = 0, b = 0;
    for(int j = 0; j <= i; j++)
      a += v.at(j);
    for(int j = i + 1; j < n; j++)
      b += v.at(j);
    int r = a - b;
    if(r < 0)
      r *= -1;
    s = min(s, r);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	long int n,x,length;
	long int a[2];
	cin>>n>>x;
	a[0]=n-x;
	a[1]=x;
	length=x;
	while(a[0]!=a[1]){
		if(a[0]>a[1]){
		length=length+((a[0]-1)/a[1])*a[1];
		a[0]=(a[0]-1)%a[1]+1;
		}
		if(a[0]<a[1]){
		a[1]=(a[1]-1)%a[0]+1;
		}
	}
	cout<<length*3;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    ll la;
    ll lb;
    ll ra;
    ll rb;
    ll q;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.q) == (riRight.q)){
            return riLeft.q < riRight.q;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.q) < (riRight.q);
    }
};


//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}


int n;
//int dat[2*10000000];
//int dat2[2*10000000];
int dat[2*100];
int dat2[2*100];

void init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;i++){
        dat[i]=0;
        dat2[i]=0;
    }
}

void initset(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=dat[k*2+1]+dat[k*2+2];
    }
}

//[a,b)の間を[l,r]区間で比較しアップデート
//引数のindexに注意
//nは固定。initで計算すみ
//update2(L[i],R[i]+1,0,0,n,D[i]);
void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index
    if(r<=a || b<=l)return;
    if(a<=l && r<=b){
        dat[k]+=dat2[k];
        if(r-l>1){
            dat2[k*2+1]+=dat2[k]/2;
            dat2[k*2+1]+=dat2[k]/2;
        }
        dat2[k]=v*(r-l);
        return;
    }else{
        update2(a,b,k*2+1,l,(l+r)/2,v);
        update2(a,b,k*2+2,(l+r)/2,r,v);
        return;
    }
}

int query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return 0;
    if(a<=l && r<=b){
        dat[k]+=dat2[k];
        if(r-l>1){
            dat2[k*2+1]+=dat2[k]/2;
            dat2[k*2+1]+=dat2[k]/2;
        }
        dat2[k]=0;
        return dat[k];
    }
    else{
        int vl=query(a,b,k*2+1,l,(l+r)/2);
        int vr=query(a,b,k*2+2,(l+r)/2,r);
        return vl+vr;
    }
}


int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs( "1_06.txt" );//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    if(n<1000){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }

    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000
 
typedef struct node_tbl
{
    int key;
    int parent;
    int left;
    int right;
} node;
 
const int nil = -1;
node t[MAX_N + 1];
int root;
int ix;
 
void
insert(int k)
{
    int y = nil;
    int x = root;
    int z = ix++;
 
    t[z].key = k;
    t[z].left = nil;
    t[z].right = nil;
 
    while (x != nil)
    {
        y = x;
        if (t[z].key < t[x].key)
            x = t[x].left;
        else
            x = t[x].right;
    }
 
    t[z].parent = y;
    if (y == nil)
        root = z;
    else
    {
        if (t[z].key < t[y].key)
            t[y].left = z;
        else
            t[y].right = z;
    }
}
 
void
inorder(int u)
{
    if (u == nil)
        return;
 
    inorder(t[u].left);
    printf(" %d", t[u].key);
    inorder(t[u].right);
}
 
void
preorder(int u)
{
    if (u == nil)
        return;
 
    printf(" %d", t[u].key);
    preorder(t[u].left);
    preorder(t[u].right);
}
 
int
main(int argc, char** argv)
{
    char command[8];
    int n;
    int x;
    int i;
 
    root = nil;
    ix = 0;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%s", command);
        switch (command[0])
        {
        case 'i':
            scanf("%d", &x);
            insert(x);
            break;
 
        case 'p':
        default:
            inorder(root);
            printf("\n");
 
            preorder(root);
            printf("\n");
            break;
        }
    }
 
    return 0;
}


Measured memory_bytes: 9548
// 2_abc138_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<double> a(n);
    double ans = 0;
    rep(i, n){
        cin >> a[i];
        ans += 1 / a[i];
    }
    cout << setprecision(15) << 1 / ans << endl;
    return 0;
}


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

using namespace std;

const int INF = 1 << 30;

int N, M, all;
int mat[15][15];
int dp[1 << 15][15];
int LatteMalta[1 << 15];

int rec(int bit, int last)
{
  if(~dp[bit][last]) return (dp[bit][last]);
  if(last == N - 1 && bit == 0) return (0);
  int ret = -INF;
  for(int i = bit; i > 0; i = (i - 1) & bit) {
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) {
        if(mat[last][j] == 0) continue;
        auto p = rec(i ^ bit, j);
        if(p == -INF) continue;
        ret = max(ret, p + mat[last][j] + LatteMalta[i]);
      }
    }
  }
  return (dp[bit][last] = ret);
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    mat[a][b] = mat[b][a] = c;
    all += c;
  }
  int ret = -INF;
  int mask = (1 << N) - 1;
  for(int i = 0; i < (1 << N); i++) {
    for(int j = 0; j < N; j++) {
      for(int k = j + 1; k < N; k++) {
        if((i >> j) & 1 && (i >> k) & 1) {
          LatteMalta[i] += mat[j][k];
        }
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < (1 << N); i++) {
    if(i & 1) {
      if(i & (1 << (N - 1))) continue;
      ret = max(ret, rec(mask ^ i, 0) + LatteMalta[i]);
    }
  }
  cout << all - ret << endl;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(void) {
	int N = 0;
	int a_A[1000];

	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a_A[i]);

	int v = 0, j = 0;
	for (int i = 1; i <= N; i++) {
		for (int k = 0; k < N; k++) {
			printf("%d", a_A[k]);
			if (k != N - 1) { printf(" "); }
			else { printf("\n"); }
		}
		if (i >= N) break;
		v = a_A[i];
		j = i - 1;
		while (j >= 0 && a_A[j] > v) {
			a_A[j + 1] = a_A[j];
			j--;
		}
		a_A[j + 1] = v;
	}
	return 0;
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  string s; cin >> s;
  int res = 0;
  for(int i = 0; i + 3 <= n; i++){
    if(s.substr(i, 3) == "ABC")res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit('i8[:](i8[:],i8[:,:])')
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 145036
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }




// ***************************************


int main(){

    string S;
    cin >> S;

    if (S[1] == 'R'){
        cout << "ABC" << endl;
    } else{
        cout << "ARC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

int isprime(long long int n){
	if (n == 1) return 0;
    if (n == 2) return 1;
    for (int i=2;i < sqrt(n)+1;i++){
        if (n % i == 0) return 0;
    }
    return 1;
}

int main(){
	int x; cin >> x;
	for (int i = x; ; i++){
		if (isprime(i)){
			cout << i << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)break;
            int[][] count = new int[n+1][n+1];
            for (int i=0;i<n+1;i++) {
                for (int j=0;j<n +1; j++) {
                    if (i != n && j != n) {
                        int a = sc.nextInt();
                        count[i][j]=a;count[i][n]+=a; count[n][j]+=a;
                    } else if (i==n&& j!= n)  count[n][n]+=count[n][j];
                    System.out.print(String.format("%5d", count[i][j]));
                }
                System.out.println();
            }
        }
 
    }
}

Measured memory_bytes: 21944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
  int key;
  int left;
  int right;
  int parent;
}node;
int main() {
  int i,j,n;
  node *H;
  scanf("%d",&n);
  H = malloc((n+1)*sizeof(node));
  for(i=1;i<=n;i++)
    {
      scanf("%d",&H[i].key);
    }

  for(i=1;i<=n;i++)
    {
      if(i==1)
	{
	  H[i].parent = -1;
	  H[i].left = H[2*i].key;
	  H[i].right = H[2*i+1].key;
	  continue;
	}
      if(2*i > n)
	{
	  H[i].parent = H[i/2].key;
	  H[i].right = -1;
	  H[i].left = -1;
	  continue;
	}
      else if(2*i+1 > n)
	{
	  H[i].parent = H[i/2].key;
	  H[i].right = -1;
	  H[i].left = H[2*i].key;
	  continue;
	}
      H[i].parent = H[i/2].key;
      H[i].left = H[2*i].key;
      H[i].right = H[2*i+1].key;
    }

   for(i=1;i<=n;i++)
    {
      if(i==1)
	{
	  printf("node %d: key = %d, left key = %d, right key = %d, \n",i,H[i].key,H[i].left,H[i].right);
	  continue;
	}
      if(2*i > n)
	{
	  printf("node %d: key = %d, parent key = %d, \n",i,H[i].key,H[i].parent);
	  continue;
	}
      else if(2*i+1 > n)
	{
	  printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,H[i].key,H[i].parent,H[i].left);
	  continue;
	}
      printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,H[i].key,H[i].parent,H[i].left,H[i].right);
    }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

const int MAX_N = 11;
int v[MAX_N][MAX_N];

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

int isOn(int x, int y){
    int sum = v[y][x];
    rep(i,5){
        int nx = x+dx[i], ny = y+dy[i];
        if(nx < 0 || nx >= 10 || ny < 0 || ny >= 10) continue;
        sum += answer[ny][nx];
    }
    return sum%2;
}

bool check(int state){
	memset(answer, 0, sizeof(answer));
    rep(i, 10){
        answer[0][9-i] = (state>>i)&1;
    }
    FOR(i, 1, 10){
        rep(j, 10){
           if(isOn(j, i-1)) answer[i][j] = 1;
        }
    }

    rep(i, 10){
        if(isOn(i, 9)) return false;
    }

    return true;
}

int main(){
	int dataset;
	cin >> dataset;
	while(dataset--){
		rep(i, 10) rep(j, 10) cin >> v[i][j];
        for(int state = 0; state < (1<<10); state++){
            if(check(state)) break;
        }

        rep(i, 10){
            rep(j, 10) cout << (j?" ":"") << answer[i][j];
            cout << endl;
        }
	}

    return 0;
}

Measured memory_bytes: 1160
n,a,b = map(int,input().split())
mod = 10 ** 9 + 7

def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    else:
        a = b = 1
        for i in range(r):
            a = a * (n - i) % mod
            b = b * (r - i) % mod
        return (a * pow(b,mod-2,mod)) % mod

ans = pow(2,n,mod) - 1 - nCr(n,a) - nCr(n,b)
print(ans%mod)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int n, k, tmp[100];
	int down[100], up[100];

	scanf("%d", &n);

	for(int i=0; i<n; i++){
		down[i] = up[i] = 0;
		scanf("%d",&k);
		scanf("%d",&tmp[0]);
		for(int j=1; j<k; j++){
			scanf("%d",&tmp[j]);
			if(tmp[j] < tmp[j-1] && down[i] < (tmp[j-1]-tmp[j]))
				down[i] = (tmp[j-1]-tmp[j]);
			else if(tmp[j] > tmp[j-1] && up[i] < (tmp[j]-tmp[j-1]))
				up[i] = (tmp[j]-tmp[j-1]);
		}
	}

	for(int i=0; i<n; i++)
		printf("%d %d\n",up[i], down[i]);

	return 0;
}

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

typedef signed long long ll;

int H,N;
int A[10101],B[101010];
ll dp[20100];

void solve() {
	int i,j,k,l,r,x,y; 
	
	cin>>H>>N;
	
	for(i=0; i<20001; ++i) 
	   dp[i]=1LL<<60;
	
	dp[0]=0;
	
	for(i=0; i<N; ++i) {
		cin>>x>>y;
		for(j=0; j<H; ++j) 
		   dp[j+x] = min(dp[j+x],dp[j]+y);
	}
	
	ll mi=1LL<<60;
	
	for(i=H;i<=20000;i++) 
	   mi=min(mi,dp[i]);
	
	cout<<mi<<endl;	
}

int main(){
	int i;
	
	ios::sync_with_stdio(false), cin.tie(0);
	
	solve(); 
    
	return 0;
}


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

typedef long long int ll; 

int main(void)
{
	ll n;
	cin >> n;

	ll ac=0,wa=0,tle=0,re=0;

	char s[10];
	for(ll i=0;i<n;i++)
	{
		cin >> s;
		if(strcmp(s,"AC") == 0)
			ac++;
		else if(strcmp(s,"WA") == 0)
			wa++;
		else if(strcmp(s,"TLE") == 0)
			tle++;
		else if(strcmp(s,"RE") == 0)
			re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int i,j,f=0;
	string s,t;
	cin>>s;
	int l=s.length();
	while(1){
		j=0;
		if(s[j]=='A'&&s[j+1]=='K'){
			j+=2;
		}else if(s[j]=='K'){
			j+=1;
		}else{
			f=1;
			break;
		}
		if(s[j]=='I'&&s[j+1]=='H')j+=2;
		else{
			f=1;
			break;
		}
		if(s[j]=='A'&&s[j+1]=='B'){
			j+=2;
		}else if(s[j]=='B'){
			j+=1;
		}else{
			f=1;
			break;
		}
		if(s[j]=='A'&&s[j+1]=='R'){
			j+=2;
		}else if(s[j]=='R'){
			j+=1;
		}else{
			f=1;
			break;
		}
		if(j>=l){
			break;
		}else if(j==l-1){
			if(s[j]!='A')f=1;
			break;
		}else{
			f=1;
		}
		break;
	}
	if(f==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define nmax 100005
using namespace std;
    int dp[nmax],p[nmax];
int modul (int x)
{
    if (x<0)
    {
        return -x;
    }
    return x;
}
int cost (int k,int i)
{
    return dp[k]+modul(p[k]-p[i]);
}
int main()
{
int i,j,n,k;

cin>>n;
for (i=1;i<=n;i++)
    cin>>p[i];
    dp[2]=modul(p[1]-p[2]);
for (i=3;i<=n;i++)
{
    dp[i] = min(cost(i - 1, i), cost(i - 2, i));
}
cout<<dp[n];
    }


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	scanf("%d", &n);
	PRINTD(n % 2 ? n*2 : n);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> a(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    int res = 0;
    for (int maskr = 0; maskr < (1 << h); maskr++) {
        for (int maskc = 0; maskc < (1 <<w); maskc++) {
            int black = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (((maskr >> i) & 1) && ((maskc >> j)&1) && a[i][j] == '#') {
                        black++;
                    }
                }
            }
            if (black == k) res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] d = new int[k];
		boolean[] have = new boolean[n];
		for(int i = 0;i<n;i++) {
			have[i] = false;
		}
		
		for(int i =0;i<k;i++) {
			d[i] = sc.nextInt();
			for(int j=0;j<d[i];j++) {
				have[sc.nextInt()-1]=true;
			}
		}
		
		int counter =0;
		for(int i =0;i<n;i++) {
			if(!have[i])counter++;
		}

		System.out.println(counter);

	}

	static long divn(int target, int times) {//10_9+7のあまり累乗版
		int sqtimes = (int)Math.sqrt(times);
		long ans = 1;
		for(int i =0;i<sqtimes;i++) {
			ans = (ans * target)%(1000000000+7);
		}
		long holder = ans;
		ans = 1;
		for(int i =0;i<sqtimes;i++) {
			ans = (ans*holder)%(1000000000+7);
		}
		for(int i=0;i<times - sqtimes*sqtimes;i++) {
			ans = (ans * target)%(1000000000+7);
		}
		return ans;
	}

	static long div(long a) {//10_9+7のあまり
		if(a<0)a+=1000000000+7;
		return a%(1000000000+7);
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


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

int main() {
    ll n, x, t;
    cin >> n >> x >> t;
    if (n<x) {
        cout << t;
        return 0;
    }
    if (n%x!=0) cout << (n/x+1)*t;
    else cout << n/x*t;
    return 0;
}

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

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

    int N;
    string S1, S2;
    cin >> N >> S1 >> S2;

    ll mod = pow(10, 9) + 7;

    vector<ll> x;

    for(int i = 0; i < N; i++) {
        if(S1[i] == S2[i])
            x.push_back(1LL);
        else {
            x.push_back(2LL);
            i++;
        }
    }

    vector<ll> a;

    a.push_back(x[0] * 3LL);

    for(int i = 0; i < x.size() - 1; i++) {
        if(x[i] == 1) {
            a.push_back(2LL);
        } else {
            if(x[i + 1] == 1) {
                a.push_back(1LL);
            } else {
                a.push_back(3LL);
            }
        }
    }

    ll ans = 1LL;

    for(int i = 0; i < a.size(); i++) {
        ans *= a[i] % mod;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n = 0;
    int temp;
    
    while((temp = getchar()) != '\n'){
        n += temp - '0';
    }

    if((n % 9) == 0)
        printf("Yes");
    else
        printf("No");
    
    return 0;
}

Measured memory_bytes: 1992
n = gets.to_i
k = gets.to_i

ans = nil
[0,1].repeated_permutation(n).to_a.each do |sample|
  res = 1
  sample.each do |op|
    if op == 0
      res = res *2
    else
      res = res + k
    end
  end
  ans = res if ans == nil
  ans = res if ans > res
end

puts ans

Measured memory_bytes: 1916
import sys
sys.setrecursionlimit(1000000)

N,K = list(map(int,input().split()))
edges = [[] for _ in range(N+1)]

MOD = 1000000007

for _ in range(N-1):
    (e1, e2) = tuple(map(int, input().split()))
    edges[e1].append(e2)
    edges[e2].append(e1)

children = [[] for _ in range(N+1)]
seen = set()
stack = []

stack.append(1)
seen.add(1)

while stack:
    node = stack[-1]
    stack.pop()
    for edge in edges[node]:
        if edge not in seen:
            seen.add(edge)
            children[node].append(edge)
            stack.append(edge)

def solve(node, siblings, depth):
    num_children = len(children[node])

    has_grandparent = depth >= 2
    has_parent = depth >= 1

    ans = max(0, K-(siblings)-int(has_parent)-int(has_grandparent))
    child_siblings = 0
    for child in children[node]:
        ans *=  solve(child, child_siblings, depth+1)
        ans %= MOD
        child_siblings += 1
    return ans


print(solve(1, 0, 0) % MOD)



Measured memory_bytes: 108008
n,m=$stdin.gets.split(/\s+/).collect{|e| e.to_i}
sita=1
m.times do |i|
  l,r=$stdin.gets.split(/\s+/).collect{|e| e.to_i}
  sita=l if l>sita
  n=r if r<n
end
if n<sita then
  puts "0"
else
  puts "#{n-(sita-1)}"
end

Measured memory_bytes: 2428