akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <math.h>

int main(void) {
        int debt = 100000;
        int n, i;
        double tmp;
        scanf("%d", &n);
        tmp=(double)debt;
        for(i=1;i<=n;i++) {
                tmp*=1.05;
                tmp/=1000;
                tmp=ceil(tmp);
                tmp*=1000;
        }

        printf("%d\n", (int)tmp);
        return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main {
	private static int h[];
	private static int dp[];

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
        h = new int[n];
        dp = new int[n];

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

		// 40 10 20 70 80 10 20 70 80 60
		dp[0] = 0;
		for (int i=1; i < n; i++) {
			for (int j=1;j <k+1;j++){
				if (i>=j) {
					int wk =bbbb(i,j);
                    if (j==1){
                    	dp[i]=wk;
                    } else {
						dp[i]=Math.min(dp[i],wk);
                    }
				}
			}
		}
		System.out.println(dp[n-1]);
	}
	private static int bbbb(int i, int j) {
		int b = Math.abs(h[i] - h[i-j]); //     i-2 j-1
		return dp[i-j] + b;
    }
}




Measured memory_bytes: 62464
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int, C: int, K: int):
    ret = 0
    ret += min(A, K)
    K = max(K - A, 0)
    if K > 0:
        K = max(K - B, 0)
        if K > 0:
            ret -= K
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


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

int cnt;

void Merge(vector<int>& v, int left, int mid, int right)
{
    int n1 = mid - left, n2 = right - mid;
    vector<int> L(n1 + 1),R(n2 + 1);
    for(int i = 0; i < n1; ++i) L[i] = v[left + i];
    for(int i = 0; i < n2; ++i) R[i] = v[mid + i];
    L[n1] = R[n2] = 1 << 30;
    int i = 0, j = 0;
    for(int k = left; k < right; ++k){
        cnt++;
        if(L[i] <= R[j]){
            v[k] = L[i];
            ++i;
        } else {
            v[k] = R[j];
            ++j;
        }
    }
}

void MergeSort(vector<int>& v, int left, int right)
{
    if(left + 1 < right){
        int mid = (left + right) / 2;
        MergeSort(v,left,mid);
        MergeSort(v,mid,right);
        Merge(v,left,mid,right);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) cin >> v[i];
    
    MergeSort(v,0,n);
    
    for(int i = 0; i < n; ++i){
        if(i != 0) cout << ' ';
        cout << v[i];
    }
    cout << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 5076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    string S;
    cin >> S;
    stack<int> s;
    ll count = 0;
    for (int i = 0; i < S.size(); ++i) {
        int tmp = S[i]-'0';
        if(s.empty()){
            s.push(tmp);
        }else{
            if(s.top() != tmp){
                s.pop();
                count++;
            }else{
                s.push(tmp);
            }
        }
    }
    cout << count*2 << endl;
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <array>

#define ARC(i,a,b) for(Int i=(a);i<(b);++i)
#define ARCH(i,a,b) for(Int i=(a)-1;i>=(b);--i)
#define RC(i,n) ARC(i,0,n)
#define RCH(i,n) ARCH(i,n,0)
#define SRC(i,s) for(Int i=0;(s)[i];++i)
#define ATH(a,b) ((a)>(b)?(a):(b))
#define OTH(a,b) ((a)<(b)?(a):(b))
#define ANTH(a,b) {if((a)<(b))(a)=(b);}
#define ONTH(a,b) {if((a)>(b))(a)=(b);}
#define ACH printf
#define ECH scanf
#define AC putchar
#define EC getchar
#define _ AC('\n');

using ull = unsigned long long;
using Int = long long;

int main() {
	Int n, a[11000], b[11000], c[11000];
	ECH("%lld", &n);
	RC(i, n) ECH("%lld", a + i);
	RC(i, n) ECH("%lld", b + i);
	RC(i, n) c[i] = b[i] - a[i];
	Int sum = 0;
	RC(i, n) sum += c[i];
	Int p2 = 0, m1 = 0;
	RC(i, n) {
		if(c[i] > 0) {
			p2 += (c[i] + 1) / 2;
			m1 += c[i] % 2;
		}
		else {
			m1 -= c[i];
		}
		//ACH("%d %d\n", p2, m1);
	}
	if(sum >= m1 && (sum - p2) * 2 == sum - m1) printf("Yes\n");
	else printf("No\n");
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int H, W;
    cin >> H >> W;
    vector<string> C(H);
    CINVEC(C);

    REP(i, H) {
        cout << C[i] << endl;
        cout << C[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N;

long long x[200005];
long long y[200005];

int main(){
	long long p_x_p_y = - 2000000005;
	long long p_x_p_y_idx = -1;
	long long p_x_m_y = - 2000000005;
	long long p_x_m_y_idx = -1;
	long long m_x_p_y = - 2000000005;
	long long m_x_p_y_idx = -1;
	long long m_x_m_y = - 2000000005;
	long long m_x_m_y_idx = -1;


	cin >> N;

	rep(i, N) {
		cin >> x[i] >> y[i];
	}

	rep(i, N) {
		if(p_x_p_y < x[i] + y[i]) {
			p_x_p_y = x[i] + y[i];
			p_x_p_y_idx = i;
		}

		if(p_x_m_y < x[i] - y[i]) {
			p_x_m_y = x[i] - y[i];
			p_x_m_y_idx = i;
		}

		if(m_x_p_y < -1 * x[i] + y[i]) {
			m_x_p_y = -1 * x[i] + y[i];
			m_x_p_y_idx = i;
		}

		if(m_x_m_y < -1 * x[i] - y[i]) {
			m_x_m_y = -1 * x[i] - y[i];
			m_x_m_y_idx = i;
		}
	}


	vector<long long> vec;
	vec.push_back(p_x_p_y_idx);
	vec.push_back(p_x_m_y_idx);
	vec.push_back(m_x_p_y_idx);
	vec.push_back(m_x_m_y_idx);

	long long ans = 0;
	for(long long i = 0; i < vec.size(); i++) {
		for(long long j = i + 1; j < vec.size(); j++) {
			ans = max(ans, abs(x[vec[i]] - x[vec[j]]) + abs(y[vec[i]] - y[vec[j]]));
		}
	}

	cout << ans << endl;



}



Measured memory_bytes: 6720
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INA(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : -(a))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 2006;

int n, m;
int a[MAXN], b[MAXN];
ll dp[MAXN][MAXN];
ll endd[MAXN][MAXN];
int lasta[100005];
int lastb[100005];

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n >> m;
	INA(a, n);
	INA(b, m);
	
}


void preprocess() {
	
	FOR(i, 0, n)
		dp[i][0] = endd[i][0] = 1;
	FOR(i, 0, m)
		dp[0][i] = endd[0][i] = 1;
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	ll more;
	
	FOR(i, 1, n) {
		more = 0;
		FOR(j, 1, m) {
			if (a[i] == b[j])
				dp[i][j] = dp[i-1][j-1] + more + dp[i-1][j];
			else
				dp[i][j] = dp[i-1][j] + more;
			
			if (a[i] == b[j])
				more += dp[i-1][j-1];
			
			dp[i][j] %= MOD;
			more %= MOD;
			
//			cout << "dp " << i << " " << j << ": " << dp[i][j] << "\n";
		}
		
	}
	cout << dp[n][m] << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 62208
n=int(input())
s=list(input())
cost=s[1:].count("E")
min_cost=cost
#print(cost)
for i in range(n-1):
    if s[i]=="W":
        cost+=1
    if s[i+1]=="E":
        cost-=1
    if min_cost>cost:
        min_cost=cost
    #print(cost)
print(min_cost)


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


int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  if( k%2 == 1 ){
    cout << b-a << endl;
  }else{
    cout << a-b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=int64([[u>'#'for u in t[:w]]for t in s])
a,b,c,d=eval('zeros((h,w),"i"),'*4)
for i in r(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Measured memory_bytes: 137564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		if(S > W) {
			System.out.println("safe");
		}else {
			System.out.println("unsafe");
		}
		

	}

}


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

int main() {
  int N;
  cin >> N;
  
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A, A+N);
  
  int ptr = 0;
  int ans = 0;
  while(ptr < N) {
    
    int n = A[ptr];
    int number = 0;
    while(n == A[ptr]) {
      number++;
      ptr++;
    }
    if (number % 2) 
      ans++;
  }
  cout << ans << endl;



}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N);
    double ave=0;
    rep(i,N){
        cin >> a[i];
        ave+=a[i];
    }
    ave/=N;
    int ans=0;
    double diff=INF;
    rep(i,N) if (chmin(diff,abs(ave-a[i]))) ans=i;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] strAi = Console.ReadLine().Split(' ');
            string[] strBi = Console.ReadLine().Split(' ');
            string[] strCi = Console.ReadLine().Split(' ');
            int[] Ai = new int[N];
            int[] Bi = new int[N];
            int[] Ci = new int[N-1];
            int count=0;  

            for(int i=0;i<N;i++)
            {
                Ai[i] = int.Parse(strAi[i]);
                Bi[i] = int.Parse(strBi[i]);
               
            }

            for(int i=0;i<N-1;i++)
            {
                Ci[i] = int.Parse(strCi[i]);
            }

            for(int i=0;i<N;i++)
            {

                count += Bi[Ai[i]-1];

            }

            for(int i=0; i<N-1;i++)
            {
                if (Ai[i] + 1 == Ai[i + 1])
                {
                    count += Ci[Ai[i]-1];
                }
            }
            
            Console.WriteLine(count);
            Console.ReadLine();
           
        }
    }

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    //解説AC   
  int main(){
      string s;
      cin>>s;
      s+='f';
      vector<char> x;
      rep(i,s.size()-1){
          if(s[i]=='f')break;
        if(s[i]=='B'&&s[i+1]=='C'){x.push_back('D');
        i++;
        }
        else x.push_back(s[i]);
      }
      lint ans=0;
      lint counta=0;
      rep(i,x.size()){
          if(x[i]=='A')counta++;
          else if(x[i]=='D')ans+=counta;
          else counta=0;
      }
      cout<<ans<<endl;
  }
  
     


Measured memory_bytes: 772
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> up(n,0),down(n,0);
    vector<vector<int>> a(2,vector<int>(n,0));
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];
            if(j>0){
                if(i==0)up[j]=a[i][j]+up[j-1];
                else down[j]=a[i][j]+down[j-1];
            }else{
                if(i==0)up[j]=a[i][j];
                else down[j]=a[i][j];
            }
        }
    }

    int maxval=up[0]+down[n-1]; 
    for(int i=1;i<n;i++){
        maxval=max(maxval, up[i]+down[n-1]-down[i-1]);
    }

    cout << maxval << endl;

    return 0;
}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> digits(n, -1);
	bool works = true;
	for (int i = 0; i < m; ++i) {
		int s, c;
		cin >> s >> c;
		if (digits[s-1] != -1 && digits[s-1] != c) works = false;
		else if (s == 1 && c == 0 && n > 1) works = false;
		else digits[s-1] = c;
	}
	// for (int u : digits) cout << u;
	// cerr << '\n';
	if (!works) {
		cout << "-1\n";
		exit(0);
	}
	if (digits[0] == -1 && digits.size() > 1) digits[0] = 1;
	for (int i = 0; i < n; ++i) 
		if (digits[i] == -1) digits[i] = 0;
	for (int u : digits) cout << u;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	cin >> N;

	vector< vector< pair<int, int> > > A(N);

	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		for(int j = 0; j < a; j++) {
			int x, y;
			cin >> x >> y;
			A[i].push_back(make_pair(x, y));
		}
	}
	//cout << endl;

	int ans = 0;

	for(int bit = 0; bit < (1 << N); bit++) {
		vector<int> S(N);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(bit & (1 << i)) {
				S[i] = 1;
				count++;
			}
		}

		bool checker = true;
		for(int i = 0; i < N; i++) {
			if(S[i] == 1) {
				for(int j = 0; j < A[i].size(); j++) {
					if(S[A[i][j].first - 1] != A[i][j].second) {
						checker = false;
						break;
					}
				}
				if(!checker) {
					break;
				}
			}
		}
		if(checker) {/*
			for(int i = 0; i < N; i++) {
				cout << S[i];
			}*/
			//cout << endl;
			if(count > ans) {
				ans = count;
			}
		}
	}

	cout << ans << endl;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dp[2][1<<20];
int bit[501],bit2[28][501],cnt[501];
int main(){
    int n,m;
    string s;
    while(cin>>n>>m,n){
        if(m<=18){
            memset(bit,0,sizeof(bit));
            rep(i,n){
                cin>>s;
                rep(j,m)if(s[j]=='1') bit[i]|=1<<j;
            }
            memset(dp,-1,sizeof(dp));
            dp[0][0]=0;
            rep(i,n){
                rep(j,1<<m) dp[1][j]=dp[0][j];
                rep(j,1<<m)if(dp[0][j]!=-1){
                    dp[1][j^bit[i]]=max(dp[1][j^bit[i]],dp[0][j]+1);
                }
                swap(dp[0],dp[1]);
            }
            cout<<dp[0][0]<<endl;
        }
        else{
            memset(bit2,0,sizeof(bit2));
            rep(i,n){
                cin>>s;
                rep(j,m)if(s[j]=='1') bit2[i][j]=1;
            }
            int mx=0;
            rep(i,1<<n){
                int c=__builtin_popcount(i);
                if(mx>=c) continue;
                memset(cnt,0,sizeof(cnt));
                rep(j,n)if((i>>j)&1)rep(k,m) cnt[k]^=bit2[j][k];
                int sum=0;
                rep(j,m) sum+=cnt[j];
                if(sum==0) mx=max(mx,c);
            }
            cout<<mx<<endl;
        }
    }
    return 0;
}


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

int f(int n, int m) {
	if(n==1) return 0;
	return (f(n-1,m)+m)%n;
}

int main() {
	while(true) {
		int n, k, m;
		cin >> n >> k >> m;
		if(!n && !k && !m) break; 
		cout << (f(n-1, k)+m)%n+1 << endl;

	}
}

Measured memory_bytes: 3288
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail+1 > LEN) tail = 1;
  tail++;
}

P dequeue(){
  P x = Q[head];

  if(head+1 > LEN) head = 1;
  head++;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  
  
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  head = 1;
  tail = n+1;
  
  while(1){
    u = dequeue();
    
    if(u.t <= q){
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
    }
    else if(u.t > q){
      elaps += q;
      u.t -= q;
      enqueue(u);
    }
    
    if(head == tail) break;
  }
  
  return 0;
}

Measured memory_bytes: 10756
s = input()


a = int(s[:2])
b = int(s[2:])

if(a <= 12 and a != 0 and b <= 12 and b != 0): print("AMBIGUOUS")
elif(a <= 12 and a != 0 and (b > 12or b == 0)): print("MMYY")
elif((a > 12 or a == 0) and b <= 12 and b != 0): print("YYMM")
else: print("NA")

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func scan(sl []int) []int{
	for i := 0; i <len(sl); i++ {
		fmt.Scan(&sl[i])
	}
	return sl
}

func main() {
	var N int
	fmt.Scan(&N)
	
	a := make([]int, N)
	b := make([]int, N)
	c := make([]int, N)

	scan(a)
	scan(b)
	scan(c)
	
	stf := 0
	
	for i := 0; i < N; i++ {
		stf += b[a[i]-1]
      
		if i > 0 && a[i - 1] == a[i] - 1 {
          stf += c[a[i - 1] - 1]
		} 
	}
	
	fmt.Println(stf)
}


Measured memory_bytes: 512
using namespace std;
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> dl;
typedef vector<ii> vii;
typedef vector<dl> vdll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define in insert
#define bs binary_search
#define INF LLONG_MAX
#define rc(s) return cout << s,0
#define int ll
const ll mod=1e9+7;
const int N=100005;
#define int ll
/*----------------------------*/ 
int arr[N];
/*----------------------------*/
int32_t main() {
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int mn=INF;
    int sum=0;
    int neg=0;
    for(int i=1;i<=n;i++){cin>>arr[i];mn=min(mn,abs(arr[i]));sum+=abs(arr[i]);if(arr[i]<0)neg++;}
    if(neg%2)sum-=2*abs(mn);
	rc(sum);
   	//THIS IS IS THE END
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        
        cin = new Scanner();
        long n = cin.inputInt();
        long[] aArray = cin.arrayLong((int)n);
        long ans = aArray[0];
        for(long a = 0; a < n-1; a++)
        {
            ans=GCD(ans, aArray[a + 1]);
        }
        WriteLine(ans);

    }
    static long GCD(long a,long b)
    {
        long m = a % b;
        if (m == 0)
        {
            return b;
        }
        else
        {
            return GCD(b, m);
        }
        
    }
}





class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string input()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return input();
        i = 0;
        return s[i++];
    }

    public int inputInt()
    {
        return int.Parse(input());
    }
    public int[] arrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputInt() + add;
        }
        return Array;
    }

    public long inputLong()
    {
        return long.Parse(input());
    }

    public long[] arrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputLong() + add;
        }
        return Array;
    }

    public double inputDouble()
    {
        return double.Parse(input());
    }


    public double[] arrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 22752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  vector<int> W(N);
  for(int i = 0; i < Q; ++i){
    cin >> A[i];
    W[A[i]-1]++;
  }
  for(int i = 0; i < N; ++i){
    if(W[i] > Q - K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }


  
}


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

using namespace std;
int a[1010][1010] , Dp[1000100];
bool vis[1000100] , recStack[1000100];
vector < int > v[1000100];

bool check_if_Cycle(int x){

    vis[x] = true;
    recStack[x] = true;
    bool Res = false;
    for(auto j : v[x]){
        if(recStack[j])  return true;
        if(!vis[j])
            Res|=check_if_Cycle(j);
    }
    recStack[x] = false;
    return Res;
}

int Rec(int x){

    if(Dp[x] != -1)  return Dp[x];

    int Res = 0;

    for(auto j : v[x])
        Res = max(Res , 1 + Rec(j));

    return Dp[x] = Res;
}

map < pair < int , int > , int > mp;
int Hash = 1;

int main()
{
    memset(Dp , -1 , sizeof(Dp));
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=i + 1;j<=n;j++){
            mp[{j , i}] = Hash;
            mp[{i , j}] = Hash++;
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n - 1; j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=2; j<=n - 1; j++)
        {
            v[mp[{i , a[i][j - 1]}]].push_back(mp[{i , a[i][j]}]);
        }
    }
    for(int i=1;i<=Hash;i++){
        if(!vis[i] && check_if_Cycle(i))  return cout << "-1" , 0;
    }
    int Ans = 0;
    for(int i=1;i<=Hash;i++)  Ans = max(Ans , Rec(i));
    cout << Ans + 1;
    return 0;
}


Measured memory_bytes: 111616
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int minPrice = b;
        int patternA = n * a;
        if (patternA < b) {
            minPrice = patternA;
        }

        System.out.println(minPrice);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

vector<ll> pickdiv(ll n){
    vector<ll> res;
    for(ll i=1; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i);
        ll q = n/i;
        if(q != i){
            res.emplace_back(q);
        }
    }
    return res;
}

vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>> res;
    for(ll i=2; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)res.emplace_back(n,1);
    return res;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<vector<ll>> v(N);
    //map<ll,ll> mp,mp2;
    vector<ll> mp(1000010);
    rep(i,N){
        cin >> A[i];
        v[i] = pickdiv(A[i]);
        mp[A[i]]++;
        /*for(auto& e:v[i]){
            ll a = e.first;
            mp2[a]++;
        }*/
    }
    /*if(mp[1] > 0){
        cout << 0 << endl;
        return 0;
    }*/
    //vector<ll> B;
    ll ans = 0;
    rep(i,N){
        ll flag = false;
        if(mp[A[i]] > 1) continue;
        for(auto& e:v[i]){
            if(mp[e] > 0 && e != A[i]){
                flag = true;
                break;
            }
        }
        if(flag) continue;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 120236
import itertools
n, q = map(int, input().split())
s = input()

ac = [0] * n
for i in range(n-1):
    if s[i] == "A":
        if s[i+1] == "C":
            ac[i+1] = 1
i = itertools.accumulate(ac)
ac = list(i)

for j in range(q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(ac[r] - ac[l])

Measured memory_bytes: 52512
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e5) + 17;

int n, k;
int a[MAXN], s[MAXN];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        cin >> a[i + 1];

    return true;
}

void solve() {
    forn (i, n)
        s[i + 1] = (s[i] + a[i + 1]) % k;

    map<int, int> mp;
    ll ans = 0;
    mp[0] = 1;

    forn (i, n) {
        ans += mp[s[i + 1]];
        ++mp[s[i + 1]];
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 3968
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
  
struct Node{
    int key;
    struct Node *prev;
    struct Node *next;
};
typedef struct Node Node;
Node *nil;
void init(void){
    nil = (Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
Node* listSearch(int key){
    Node *cur=nil->next;
    while (cur!=nil&&cur->key!=key) {
        cur = cur->next;
    }
    return cur;
}
void deleteNode(Node *t){
    if (t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
void deleteFirst(void){
    deleteNode(nil->next);
}
void deleteLast(void){
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}
void printList(void){
    Node *cur=nil->next;
    while (cur!=nil) {
        printf("%d",cur->key);
        if (cur->next!=nil) {
            printf(" ");
        }
        cur = cur->next;
    }
    printf("\n");
}
int main(){
    int n, i, x;
    char a[20];
    init();
    scanf("%d",&n);
    for (i=0;i<n;i++) {
        scanf("%s",a);
        if (a[0]=='i') {
            scanf("%d",&x);
            insert(x);
        } else if (a[0]=='d') {
            if (strlen(a)>6) {
                if (a[6]=='F') {
                    deleteFirst();
                } else if (a[6]=='L') {
                    deleteLast();
                }
            } else {
                scanf("%d",&x);
                deleteKey(x);
            }
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 33024
from bisect import bisect_right
from random import randint


def calculate_score(c, L):
    global D, last, S
    rst = 0
    _last = L
    for d in range(1, D + 1):
        down = C[c] * (d - _last[d])
        up = S[d][c] if _last[d] == d else 0
        rst += up - down
    return rst


Z = 26
D = int(input())
C = list(map(int, input().split()))
S = [tuple([0] * Z)] + [tuple(map(int, input().split())) for _ in range(D)]

last = [-1] * Z
ans = 0
T = [0]
for d in range(D):
    maxScore = -float('inf')
    cand = 0
    for i in range(26):
        tmp = last[i]
        last[i] = d
        up = S[d][i]
        down = sum(C[j] * (d - last[j]) for j in range(Z))
        score = up - down
        if maxScore < score:
            cand = i
            maxScore = score
        last[i] = tmp
    last[cand] = d
    T.append(cand)


last = [[0] * (D + 1) for _ in range(Z)]
V = [0] * Z
for d in range(1, D + 1):
    t = T[d]
    for p in range(Z):
        last[p][d] = last[p][d - 1]
    last[t][d] = d
for p in range(Z):
    V[p] = calculate_score(p, last[p])

score = sum(V)
# print('Initial Score: ', score)

max_iter = 10 ** 4
for _ in range(max_iter):
    d = randint(1, D)
    q = randint(0, Z - 1)

    p = T[d]
    if p == q:
        continue

    e = bisect_right(last[p], d)
    _lastP = [0] * (D + 1)
    for j in range(d):
        _lastP[j] = last[p][j]
    for j in range(d, e):
        _lastP[j] = _lastP[j - 1]
    for j in range(e, D + 1):
        _lastP[j] = last[p][j]

    old = last[q][d]
    e = bisect_right(last[q], old)
    _lastQ = [0] * (D + 1)
    for j in range(d):
        _lastQ[j] = last[q][j]
    for j in range(d, e):
        _lastQ[j] = d
    for j in range(e, D + 1):
        _lastQ[j] = last[q][j]

    Vp = calculate_score(p, _lastP)
    Vq = calculate_score(q, _lastQ)
    if V[p] + V[q] < Vp + Vq:
        score -= V[p] + V[q]
        score += Vp + Vq
        V[p] = Vp
        V[q] = Vq
        T[d] = q
        last[p] = _lastP
        last[q] = _lastQ

for i in range(1, D + 1):
    print(T[i] + 1)
# print(score)


Measured memory_bytes: 84480
#include<iostream>
#include<string>

int main() {
	std::string s;
	std::string t;
	char ms[30] = {};
	char mt[30] = {};
	bool flug = true;
	std::cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (ms[s[i] - 'a']!=t[i]) {
			if (ms[s[i] - 'a'] != 0) {
				flug = false;
				break;
			}
			else {
				ms[s[i] - 'a'] = t[i];
			}
		}
		if (mt[t[i] - 'a'] != s[i]) {
			if (mt[t[i] - 'a'] != 0) {
				flug = false;
				break;
			}
			else {
				mt[t[i] - 'a'] = s[i];
			}
		}
	}
	if (flug)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}


Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}



void solve(vector<int> a){
    int n=a.size()-2;
    int len=0;
    rep(i,n+1){
        len+=abs(a[i+1]-a[i]);
    }
    
    REP(i,1,n+1){
        int diff=abs(a[i+1]-a[i-1]) - ( abs(a[i]-a[i-1])+abs(a[i+1]-a[i]) );
        cout<<len+diff<<endl;
    }
    return;
}


int main(void){
    int n,m;
    ll ans=0;
    ll x,y,z;
    cin>>n>>m;
    vvll t(8,vector<ll>(n));
    vi sn={-1,1};
    rep(q,n){
        cin>>x>>y>>z;
        int l=0;
        for(int i:sn){
            for(int j:sn){
                for(int k:sn){
                    t[l][q]=x*i+y*j+z*k;
                    //cout<<n<<i<<j<<k<<l<<t.at(0).size()<<endl;
                    l++;
                }
            }   
        }
    }
    rep(l,8){
        ll tmp=0;
        sort(all(t[l]),greater<ll>());
        rep(i,m)tmp+=t[l][i];
        if (ans<tmp)ans=tmp;
    }
    
    cout<<ans<<endl;
    //solve(t);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvp g;
vi a,b,c,vis,res;

void dfs(int v,int t){
	vis[v]=t;
	for(auto p:g[v]){
		int u=p.first,id=p.second;
		if(vis[u]!=t&&a[u]<=a[v]){
			res[id]=a[v];
			if(!vis[u]) dfs(u,t);
			b[v]=b[u]^1;
			break;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	g=vvp(n);
	a=vis=b=vi(n);
	c=res=vi(m);
	for(auto &i:a) cin>>i;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	bool B=0;
	for(int i=0;i<n;i++){
		bool flag=1;
		for(auto p:g[i]){
			int v=p.first;
			if(a[v]<=a[i]) flag=0;
		}
		B|=flag;
	}
	if(B){
		cout<<-1<<endl;
		return 0;
	}
	int id=1;
	for(int i=0;i<n;i++) if(!vis[i]) dfs(i,id++);
	for(int i=0;i<n;i++) cout<<(b[i]?'B':'W');
	cout<<endl;
	for(int i=0;i<m;i++){
		if(!res[i]) cout<<1000000000<<endl;
		else cout<<res[i]<<endl;
	}
}

Measured memory_bytes: 13840
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
 
def main():
    x = inp()
    for a in range(-10**3,10**3):
        for b in range(-10**3,a):
            if a**5-b**5 == x:
                print(a,b)
                return
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
	class Program
	{
		static void Main()
		{
			var NM = Console.ReadLine().Split().Select(int.Parse);
			int N = NM.First(), M = NM.Last();
			var ans = new int[N];
			for (int i = 0; i < M; i++)
			{
				var ab = Console.ReadLine().Split().Select(int.Parse);
				foreach (var item in ab)
				{
					ans[item - 1]++;
				}
			}
			foreach(var item in ans)
			{
				Console.WriteLine(item);
			}
#if DEBUG
			Console.ReadKey();
#endif
		}
	}
}


Measured memory_bytes: 11348
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=1e5+5;


int n;
int a[maxn][3],dp[maxn][3];

int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
	FOR(i,1,n){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}
	printf("%d\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
	return 0;
}


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

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat
int main (){
    ll int x;
    cin >> x;
    ll int ans;
    ll int ans5;

    ans = (x/500) * 1000;
    ans5 = (x - (x/500)*500)/5 * 5;
    ans = ans + ans5;
    cout << ans;
}

Measured memory_bytes: 256
X, K, D = [int(n) for n in input().split(" ")]

#X = 10
#K = 1
#D = 2


startN = (D * K - X) // (2 * D)

N1 = startN + 1
N2 = startN
N3 = startN - 1

if N1 < 0:
    N1 = 0
if N2 < 0:
    N2 = 0
if N3 < 0:
    N3 = 0
if N1 > K:
    N1 = K
if N2 > K:
    N2 = K
if N3 > K:
    N3 = K

def getScore(n):
    score = X + n * D - D * (K - n)
    if score < 0:
        score = score * -1
    return score

score1 = getScore(N1)
score2 = getScore(N2)
score3 = getScore(N3)

minScore = score1
if minScore > score2:
    minScore = score2
if minScore > score3:
    minScore = score3

print(minScore)

Measured memory_bytes: 9228
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int n = 100;

char aa[105][105];

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	for(int i = 1; i <= n / 2; i++)
		for(int j = 1; j <= n; j++)
		{
			aa[i][j] = '.';
		}
	for(int i = n / 2 + 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
		{
			aa[i][j] = '#';
		}
	a--;
	b--;
	while(a > 0)
	{
		for(int i = n / 2 + 2; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				if(i % 2 == 1 && j % 2 == 1) {
					aa[i][j] = '.';
					a--;
				}
				if(a <= 0) break;
			}
			if(a <= 0) break;
		}
	}
	while(b > 0)
	{
		for(int i = 1; i <= n / 2; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				if(i % 2 == 1 && j % 2 == 1) {
					aa[i][j] = '#';
					b--;
				}
				if(b <= 0) break;
			}
			if(b <= 0) break;
		}
	}
	printf("100 100\n");
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			printf("%c", aa[i][j]);
		}
		printf("\n");
	}
}

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

using namespace std;

int main(){
    int N, W;
    cin >> N >> W;
    int v1[100000];
    int v2[100000];
    int v3[100000];
    int v4[100000];
    long sum1[100001];
    long sum2[100001];
    long sum3[100001];
    long sum4[100001];
    int n1 = 1, n2 = 0, n3 = 0, n4 = 0;
    int w1, v;
    cin >> w1 >> v;
    v1[0] = v;
    for(int i = 1; i < N; i++){
        int w;
        cin >> w >> v;
        if(w-w1 == 0){
            v1[n1] = v;
            n1++;
        }
        if(w-w1 == 1){
            v2[n2] = v;
            n2++;
        }
        if(w-w1 == 2){
            v3[n3] = v;
            n3++;
        }
        if(w-w1 == 3){
            v4[n4] = v;
            n4++;
        }
    }
    sort(v1, v1+n1, greater<int>());
    sort(v2, v2+n2, greater<int>());
    sort(v3, v3+n3, greater<int>());
    sort(v4, v4+n4, greater<int>());
    sum1[0] = 0;
    sum2[0] = 0;
    sum3[0] = 0;
    sum4[0] = 0;
    for(int i = 1; i <= n1; i++) sum1[i] = sum1[i-1]+v1[i-1];
    for(int i = 1; i <= n2; i++) sum2[i] = sum2[i-1]+v2[i-1];
    for(int i = 1; i <= n3; i++) sum3[i] = sum3[i-1]+v3[i-1];
    for(int i = 1; i <= n4; i++) sum4[i] = sum4[i-1]+v4[i-1];
    
    long ans = 0;
    for(int i = 0; i <= n1; i++){
        for(int j = 0; j <= n2; j++){
            for(int k = 0; k <= n3; k++){
                for(int l = 0; l <= n4; l++){
                    if( w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l <= W){
                        ans = max(ans, sum1[i]+sum2[j]+sum3[k]+sum4[l]);
                        //cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << ans << endl;
                    }
                }
            }
        }
    }
    //cout << n1 << ' ' << n2 << ' ' << n3 << ' ' << n4 << endl;
    cout << ans << endl;
}

Measured memory_bytes: 4352