akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define FIO "agc58F"
using namespace std;

const int N=2e3+5,K=1e4+5,S=1e6+5,C=26;

#define bs bitset<S> 

int n,k,len[N],st[N];
bitset<K> f[N];
char s[N][K];

bs tr[C<<2],pos[C];

#define lk k<<1
#define rk k<<1|1
#define mid (l+r>>1)

inline void mdy(int pos,int val,int k=1,int l=0,int r=C-1){
  tr[k][val]=1;
  if(l==r)return;
  if(pos<=mid)mdy(pos,val,lk,l,mid);
  else mdy(pos,val,rk,mid+1,r);
}

bs state;

inline int qry(int k=1,int l=0,int r=C-1){
  if(l==r)return l;
  if((state&tr[lk]).none())return qry(rk,mid+1,r);
  return qry(lk,l,mid);
}

int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++)scanf("%s",s[i]+1),len[i]=strlen(s[i]+1);
  f[n+1][0]=1;
  for(int i=n;i;i--)for(int j=k;~j;j--)f[i][j]=f[i+1][j]|(j>=len[i]?f[i+1][j-len[i]]:0);
  for(int t=0,i=1;i<=n;i++){
    st[i]=t+1;
    for(int j=1;j<=len[i];j++){
      t++;
      mdy(s[i][j]-'a',t);
      pos[s[i][j]-'a'][t]=1;
    }
  }

  state[1]=1;
  st[n+1]=k+1;

  for(int i=1;i<=k;i++){
    for(int j=1;j<n;j++)if(state[st[j]])state[st[j+1]]=1;
    for(int j=1;j<=n;j++)if(k-i+1<len[j]||!f[j+1][k-i+1-len[j]])state[st[j]]=0;
    int x=qry();
    putchar(x+'a');
    (state&=pos[x])<<=1;
  }

  return 0;
}


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

ll N, K, R, S, P;
string T;

array<vector<ll>, 3> memo = { vector<ll>(100000 * 3, -1), vector<ll>(100000 * 3, -1), vector<ll>(100000 * 3, -1) };
const map<char, size_t> hand2i = { { 'r', 0 }, { 's', 1 }, { 'p', 2 } };

ll dfs(char hand, int index, int a)
{
    if (index * K >= N) {
        return 0;
    }

    auto hand_index = index * K + a;
    auto& memo_r = memo[hand2i.at(hand)][hand_index];
    if (memo_r != -1) {
        return memo_r;
    }

    auto enemy_hand = T[hand_index];
    ll score = 0;
    if (hand == 'r') {
        if (enemy_hand == 's') {
            score += R;
        }
        score += max(dfs('s', index + 1, a), dfs('p', index + 1, a));
    }
    if (hand == 's') {
        if (enemy_hand == 'p') {
            score += S;
        }
        score += max(dfs('r', index + 1, a), dfs('p', index + 1, a));
    }
    if (hand == 'p') {
        if (enemy_hand == 'r') {
            score += P;
        }
        score += max(dfs('r', index + 1, a), dfs('s', index + 1, a));
    }

    memo_r = score;
    return score;
}

void main_()
{
    cin >> N >> K >> R >> S >> P;
    cin >> T;

    ll ans = 0;
    for (ll i = 0; i < K; ++i) {
        ans += max({
            dfs('r', 0, i),
            dfs('s', 0, i),
            dfs('p', 0, i),
        });
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 12112
import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.Stream;

// internous_atcoder_001 at 2018/02/15

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

	private void solveA080() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (N * A < B) {
			System.out.println(N * A);
		} else {
			System.out.println(B);
		}
	}

	private void solveA044() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		if (N <= K) {
			System.out.println(N * X);
		} else {
			System.out.println((K * X) + (N - K) * Y);
		}
	}

	private void solveB044() {
		Scanner sc = new Scanner(System.in);
		char w[] = sc.nextLine().toCharArray();
		ArrayList<Character> used = new ArrayList<>();
		for (char c : w) {
			if (!used.contains(c)) {
				if (!cnt(w, c)) {
					System.out.println("No");
					return;
				} else {
					used.add(c);
				}
			}
		}
		System.out.println("Yes");
	}
	private boolean cnt(char[] w, char t) {
		int count = 0;
		for (char c : w) {
			if (c == t) {
				count++;
			}
		}
		if (count % 2 == 1) {
			return false;
		}
		return true;
	}

	private void solveB081() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		int A[] = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int B[] = new int[N];
		int cnt = 0;
		while (true) {
			for (int i = 0; i < N; i++) {
				if (A[i] % 2 == 1) {
					System.out.println(cnt);
					return;
				} else {
					B[i] = A[i] / 2;
				}
			}
			cnt++;
			A = B;
		}
	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveF() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

}

Measured memory_bytes: 29776
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static ArrayList[] connect;
  public static int[] nextStep;
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int M = scan.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    connect = new ArrayList[N];
    nextStep = new int[N];
    for(int i=0; i<N; i++) {
      connect[i] = new ArrayList<Integer>();
      nextStep[i] = -1;
    }
    for(int i=0; i<M; i++) {
      A[i] = scan.nextInt();
      B[i] = scan.nextInt();
      connect[A[i]-1].add(B[i]-1);
      connect[B[i]-1].add(A[i]-1);
    }
    scan.close();

    nextStep[0] = 0;
    ArrayList<Integer> nextTargets = new ArrayList<Integer>();
    nextTargets.add(0);

    while(nextTargets.size() != 0) {
      ArrayList<Integer> tempTargets = new ArrayList<Integer>();
      for(int i=0; i<nextTargets.size(); i++) {
        for(int j=0; j<connect[nextTargets.get(i)].size(); j++) {
          int nextTarget = (int)connect[nextTargets.get(i)].get(j);
          if(nextStep[nextTarget] == -1) {
            nextStep[nextTarget] = nextTargets.get(i);
            tempTargets.add(nextTarget);
          }
        }
      }
      nextTargets = tempTargets;
    }

    System.out.println("Yes");
    for(int i=1; i<N; i++) {
      System.out.println(nextStep[i] + 1);
    }
  }
}

Measured memory_bytes: 72156
def test():

	while True:

		deck = list(input())
		
		if deck[0] == '-':
			break
		
		m = int(input())

		for i in range(m):

			h = int(input())
			deck = deck[h:len(deck)] + deck[0:h]

		print(''.join(deck))

if __name__ == "__main__":
	test()


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL x,y,z;
    cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<endl;
    return 0;
}

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

int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            int k = S - i - j;
            if (k >= 0 && k <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









const int N=2e5+10;
ll n,p,x,s,res,a[N];




void solve()
{
	cin>>n;
	p=1;
	x=0;
	s=0;
	res=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		x^=a[i];
		s+=a[i];
		for(;;)
		{
			if(s==x)break;
			s-=a[p];
			x^=a[p];
			p++;
		}
		res+=i-p+1;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,a,b;
  cin >> x>>a >>b;
  int c = b-a;
  if(b-a<=0){
    cout << "delicious";
  }
  else if(b-a <=x){
    cout << "safe";
  }
  else {
    cout << "dangerous";
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    ArrayList<Integer> n = new ArrayList<Integer>();

    while(scanner.hasNextInt()){
      int x = scanner.nextInt();
      if(x == 0){
        break;
      }
      n.add(x);
    }
    for (int i = 0; i < n.size(); i++){
      System.out.println("Case " + (i + 1) + ": " + n.get(i));
    }
  }
}

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

using namespace std;

int h, w;
int n;
bool ita[6100][6100];
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };

struct Box {
	int bx, by, ex, ey;
};

vector<Box> in;

void Press(vector<Box> &v) {
	vector<int> pressx, pressy;
	pressx.push_back(0), pressx.push_back(w - 1);
	pressy.push_back(0), pressy.push_back(h - 1);
	for (int i = 0; i < n; i++) {
		pressx.push_back(v[i].bx);
		pressx.push_back(v[i].ex);
		pressy.push_back(v[i].by);
		pressy.push_back(v[i].ey);
		if(v[i].bx - 1 >= 0)pressx.push_back(v[i].bx-1);
		if (v[i].ex - 1 >= 0)pressx.push_back(v[i].ex-1);
		if (v[i].by - 1 >= 0)pressy.push_back(v[i].by-1);
		if (v[i].ey - 1 >= 0)pressy.push_back(v[i].ey-1);
		if (v[i].bx + 1 < w)pressx.push_back(v[i].bx+1);
		if (v[i].ex + 1 < w)pressx.push_back(v[i].ex+1);
		if (v[i].by + 1 < h)pressy.push_back(v[i].by+1);
		if (v[i].ey + 1 < h)pressy.push_back(v[i].ey+1);
	}
	sort(pressx.begin(), pressx.end());
	sort(pressy.begin(), pressy.end());
	pressx.erase(unique(pressx.begin(), pressx.end()), pressx.end());
	pressy.erase(unique(pressy.begin(), pressy.end()), pressy.end());

	for (int i = 0; i < n; i++) {
		v[i].bx = lower_bound(pressx.begin(), pressx.end(), v[i].bx) - pressx.begin();
		v[i].by = lower_bound(pressy.begin(), pressy.end(), v[i].by) - pressy.begin();
		v[i].ex = lower_bound(pressx.begin(), pressx.end(), v[i].ex) - pressx.begin();
		v[i].ey = lower_bound(pressy.begin(), pressy.end(), v[i].ey) - pressy.begin();
	}

	h = pressy.size(), w = pressx.size();
}

void dfs(int x, int y) {
	ita[y][x] = true;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= w - 1 || ny >= h - 1)continue;
			if (ita[ny][nx] == false) {
			dfs(nx, ny);
		}
	}
}

int main() {
	while (cin >> w >> h, w*h) {
		cin >> n;
		in.clear();
		in.resize(n);
		for (int i = 0; i < 6100; i++)for (int j = 0; j < 6100; j++)ita[i][j] = false;
		for (int i = 0; i < n; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			in[i].bx = a, in[i].by = b, in[i].ex = c, in[i].ey = d;
		}
		Press(in);

		for (int i = 0; i < n; i++) {
			for (int x = in[i].bx; x < in[i].ex; x++) {
				for (int y = in[i].by; y < in[i].ey; y++) {
					ita[y][x] = true;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < h - 1; i++) {
			for (int j = 0; j < w - 1; j++) {
				if (!ita[i][j]) {
					dfs(j, i);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 60776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    string s;
    cin >> s;
    int a=0; int b=0; int c=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='a'){
            a++;
        }
        if(s[i]=='b'){
            b++;
        }
        if(s[i]=='c'){
            c++;
        }
    }
    if(a==1 && b==1 && c==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
 int i,j;
 char c[3][4];

 for(i=0;i<3;i++){
    scanf("%s",c[i]);
 }
 for(i=0;i<3;i++){
   for(j=i;j<=i;j++)
     printf("%c", c[i][j]);
  }
 printf("\n");
 return 0;
} 


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

int main(){
	int n, m;
	int p[1000];
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		for(int i = 0;i < n;i++){
			cin >> p[i];
		}
		int ans = 0;
		sort(p, p + n, greater<int>());
		for(int i = 0;i < n;i++){
			if(i % m == m - 1) continue;
			ans += p[i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
"""
ABC049 A - 居合を終え、青い絵を覆う
https://atcoder.jp/contests/abc049/tasks/abc049_a
"""

c = input()
boin = ['a', 'e', 'i', 'o', 'u']
if c in boin:
    print('vowel')
else:
    print('consonant')


Measured memory_bytes: 8984
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

signed main() {
	int n;
	cin >> n;
	int x[105];
	rep(i, n) cin >> x[i];
	int ans = INF;
	rep(i, 101) {
		int cnt = 0;
		rep(j, n) {
			cnt += (x[j] - i) * (x[j] - i);
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int main(){
  int n,l,r;
  while(cin >> n >> l >> r,n){
    int count=0;
    int a[51];
    a[0] = 0;
    rep(i,n) cin >> a[i];
    for(int x=l; x<=r; x++){
      bool flag=false;
      rep(i,n){
        if(x%a[i] == 0){
          flag = true;
          if(i%2 != 0) {
            count++;
          }
          break;
        }
      }
      if(flag == false && n%2 == 0) count++;
    }
    cout << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
import java.io.*;
import java.util.*;

class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Double> ans = new ArrayList<Double>();
		
		double max = Double.MIN_VALUE;
		double min = Double.MAX_VALUE;
		
		while (true) {
			
			String s = br.readLine();
			if (s == null) break;
			ans.add(Double.parseDouble(s));
			
		}
		
		for (int i = 0; i < ans.size(); i++) {
			max = Math.max(ans.get(i), max);
			min = Math.min(ans.get(i), min);
		}
		
		System.out.println(max - min);
	}
	
}

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

vector<vector<int>> G;
vector<int> used;
vector<int> found;
vector<int> done;

int dfs(int v, int t){
    if(used[v]){
        return done[v];
    }
    else{
        used[v] = 1;
        found[v] = t;
    }
    for(long long i=0; i<G[v].size(); i++){
        int nv = G[v][i];
        if(used[nv]) continue;
        else{
            t = dfs(nv, ++t);
        }
    }
    return done[v] = ++t;
}

int main(){
    int N; cin>>N;
    G.resize(N);
    used.resize(N, 0);
    found.resize(N, 0);
    done.resize(N, 0);
    found[0] = 1;
    for(long long i=0; i<N; i++){
        int u, k; cin >> u >>k;
        u--;
        G[u].resize(k);
        for(long long j=0; j<k; j++){
            int v; cin >> v;
            v--;
            G[u][j] = v;
        }
    }
    int t = 1;
    for(long long i=0; i<N; i++){
        if(used[i]) continue;
        t = dfs(i, t) + 1;
    }
    for(long long i=0; i<N; i++){
        cout << i+1 << " " << found[i] << " " << done[i] << endl;
    }
    return 0;
}


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

const int nax = 1e5;
vector<pair<int,int>> node[nax];
vector<int> child[nax];
int weight[nax*2], par[nax];
int col[nax];

void dfs(int p, int c) {
  if (col[p]) return;
  col[p] = c;
  for (int i : child[p])
    dfs(i, 3-c);
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    node[a].emplace_back(b, i);
    node[b].emplace_back(a, i);
    weight[i] = 1e9;
  }
  for (int i = 0; i < n; i++) {
    par[i] = -1;
    for (auto pa : node[i]) {
      int j = pa.first, ei = pa.second;
      if (d[j] <= d[i]) {
	weight[ei] = d[i];
	par[i] = j;
	if (d[j] == d[i]) {
	  par[j] = i;
	}
      }
    }
    if (par[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++)
    child[par[i]].push_back(i);
  for (int i = 0; i < n; i++) {
    if (par[par[i]] == i) {
      dfs(i, 1);
    }
  }
  for (int i = 0; i < n; i++)
    cout << (col[i] == 2 ? "B" : "W");
  cout << '\n';
  for (int i = 0; i < m; i++)
    cout << weight[i] << '\n';
}


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

int main() {
	int H, W, i, k;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}
		for (k = 1; k <= H; k++) {
			if (k == 1 || k == H) {

				for (i = 1; i <= W; i++) {
					if (i != W) {
						cout << "#";
					} else {
						cout << "#" << endl;
					}
				}
			} else {
				for (i = 1; i <= W; i++) {
					if (i == 1) {
						cout << "#";
					} else if (i != W) {
						cout << ".";
					} else {
						cout << "#" << endl;
					}
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

int main() {
  int r,g,b,n;
  cin >> r >> g >> b >> n;

  int rmax = n / r;
  // cout << rmax << endl;
  ll ans = 0;
  for (int i = 0; i <= rmax; ++i) {
    int rem = n - i * r;
    int gmax = (rem / g) + 1;
    for (int j = 0; j <= gmax; ++j) {
      int remain = rem - j * g;
      if (remain >= 0 and remain % b == 0) ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# div2019-2C - Successive Subtraction
def main():
    n = int(input())
    lst = sorted(list(map(int, input().rstrip().split())))
    s = lst[0]
    l = lst[-1]
    log = []
    for i in lst[1:-1]:
        if i > 0:
            log += [(s, i)]
            s -= i
        else:
            log += [(l, i)]
            l -= i
    log += [(l, s)]
    print(l - s)
    for i, j in log:
        print(i, j)


if __name__ == "__main__":
    main()

Measured memory_bytes: 20120
n, k, q = list(map(lambda x: int(x), input().split()))
kachinuke_point = [q - k + 1] * n

for i in range(q):
    kachinuke_point[int(input())-1] -= 1
    
for p in kachinuke_point:
    if p > 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 50904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    int M,D;cin>>M>>D;
    int cnt=0;
    for(int i=1;i<=M;i++){
        for(int j=10;j<=D;j++){
            int a=j/10,b=j%10;
            if(a>=2&&b>=2&&a*b==i) cnt++;
        }
    }
    
    cout<<cnt<<endl;
}



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

int main()
{
    ios::sync_with_stdio(false);
    int n;
    string S;
    cin>>n;
    cin>>S;
    for(char c: S)
        cout<<(char)((c+n-'A')%26+'A');

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            string s = cin.next();
            Console.WriteLine(s.Replace(",", " "));
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//static const int NIL = -1;
//static const int MOD = 1000000007;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
//#define int ll

signed main(){
    bool dpw[3145]={},dps[3145]={};
    dpw[0] = dps[0] = 1;
    int a,b,c,d,e,f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    a*=100,b*=100;
    double p = double(e)/double(100+e);

    for(int i=0;i<3145;i++){
        if(dpw[i]){
            if(i+a<=f) dpw[i+a] = 1;
            if(i+b<=f) dpw[i+b] = 1;
        }
        if(dps[i]){
            if(i+c<=f) dps[i+c] = 1;
            if(i+d<=f) dps[i+d] = 1;
        }
    }

    double ans=0;
    int s=a,t=0;
    for(int i=0;i<=f;i++){
        if(dpw[i]){
            for(int j=0;i+j<=f;j++){
                if(dps[j]){
                    //printf("%d %d\n",i,j);
                    double tmp = double(j)/double(i+j);
                    if(tmp>ans&&p>=tmp){
                        s = i+j;
                        t = j;
                        ans = tmp;
                    }
                }
            }
        }
    }

    printf("%d %d\n",s,t);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  if((A+B) % 2 == 0){
    printf("%d\n", (A+B)/2);
  }else{
    printf("%s\n","IMPOSSIBLE");
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===


const int INF = int(1e9 + 7);


int main() {
	ll L, R;
	cin >> L >> R;
	if (R - L >= 2019) {
		cout << 0 << endl;
	}
	else {
		ll ans = 2e9;
		for (ll i = L; i < R; ++i) {
			for (ll j = i + 1; j <= R; ++j) {
				ll tmp = i * j % 2019;
				ans = min(ans, tmp);
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int k, q;
	vector<int> d;
	
	cin>>k>>q;
	
	d.resize(k);	


	for(int i = 0; i < k; i++){
		cin>>d[i];
	}
	
	for(int i = 0; i < q; i++){
		int n, x, m, ans = 0, sum = 0;
		
		cin>>n>>x>>m;
		
		sum = x;
		
		for(int i = 0; i < k; i++){
			if(d[i] % m == 0) {
				ans += (n - 1 - i + k - 1) / k;
			}
			sum += (d[i] % m) * ((n - 1 - i + k - 1) / k);
			// cout<<"i = "<<i<<" "<<(n - 1 - i + k - 1) / k<<endl;
		}
		
		
		ans += sum / m - x / m;
		
		// cout<<"ans = "<<ans<<endl;
		
		ans = n - 1 - ans;
		
		// cout<<"sum = "<<sum<<" "<<ans<<endl;
		
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMultipleOf2AndN solver = new AMultipleOf2AndN();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMultipleOf2AndN {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println(n % 2 == 0 ? n : n * 2);
        }

    }
}



Measured memory_bytes: 22100
#include<cstdio>
#include<iostream>
using namespace std;
#define mod 998244353
const int maxn=3010;
long long f[maxn][maxn];
int main(){
    //freopen("a.in","r",stdin);
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    f[a][b]=1;
    for(long long i=a;i<=c;i++){
        for(long long j=b;j<=d;j++){
            if(i==a&&j==b)continue;
            f[i][j]=((f[i-1][j]*j%mod+f[i][j-1]*i%mod)%mod-(i-1)*(j-1)*f[i-1][j-1]%mod+mod)%mod;
        }
    }
    cout<<f[c][d]<<endl;
    return 0;
}

Measured memory_bytes: 73704
n = int(input())
h = [int(v) for v in input().split()]
c = [0] * n

c[0] = 0
c[1] = abs(h[0]-h[1])

for i in range(1,n-1):
  cost1 = c[i-1] + abs(h[i-1] - h[i+1])
  cost2 = c[i] + abs(h[i]-h[i+1])
  c[i+1] = min(cost1,cost2)

print(c[-1])

Measured memory_bytes: 13980
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    print('A' if str.isupper(S) else 'a')


if __name__ == '__main__':
    main()


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

double kitai(int a){
    double sum;
    sum=(1+a)/2.0;
    return sum;
}


int main (){
    int n,k;
    double ma=0.0;
    int i;
    cin >> n >> k;
    vector <double> a(n+1);
    a.at(0)=0;
    rep(i,n){
        int p;
        cin >> p;
        a.at(i+1)=a.at(i)+kitai(p);
    }
    
    for(i=k;i<n+1;i++){
        double m=0.0;
        m=a.at(i)-a.at(i-k);
        if(m>ma) ma=m;
    }
    printf("%0.12lf",ma);
    
    return 0;
}


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

int main(void){
  string s;
  cin >> s;
  for(int i = 0; i < (int)s.length(); i++){
    if(i%2 == 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) continue;
    if(i%2 == 1 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) continue;
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
signed main(){
	cin >> n;
	int ans = 0, re = 0;
	for (int i = 0; i < n; i++) {
		int k = read();
		if (re <= k) {
			ans++;
			re = k;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

string S,T;
int main (){
    cin >> S >> T;
    if( S.length() != T.length()) {
        cout << "No" << endl;
        return 0;
    }
    S += S;
    int cnt = 0;
    for(int i=0; i<S.length(); i++){
        for(int j=0; j<T.length(); j++){
            if( S[i] == T[j + cnt]) {
                cnt++;
                if( cnt == T.length()) {
                     cout << "Yes" << endl;
                     return 0;
                }
                break;
            }
            cnt = 0;
            break;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????

		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		StringBuilder sb = new StringBuilder();

		String[] starr = br.readLine().split(" ");

		int[] lab = new int[starr.length];
		for (int i = 0; i < starr.length; i++) {
			lab[i] = Integer.parseInt(starr[i]);
		}

		DiceII d = new DiceII(lab);

		int q =Integer.parseInt( br.readLine() );

		for (int i = 0; i < q; i++) {
			String temp[] = br.readLine().split(" ");
			int lab0 =Integer.parseInt( temp[0] );
			int lab1 =Integer.parseInt( temp[1] );

			for (int j = 0; j < 3; j++) {
				if (d.lab[0] == lab0) break;
				d.koroS();
			}
			labelif:
			if (d.lab[0] != lab0) {
					d.koroE();
					if (d.lab[0] == lab0) break labelif;
					d.koroE();
					d.koroE();
			}
			while (d.lab[1] != lab1) {
				d.kaitentokei();
			}
			sb.append(d.lab[2] + "\n");
		}

		System.out.print(sb);
	}
}

class DiceII {
	int[] lab = new int[6];

	DiceII(int[] lab) {
		for (int i = 0; i < lab.length; i++) {
			this.lab[i] = lab[i];
		}
	}

	void koroS() {
		int temp = this.lab[0];
		lab[0] = lab[4];
		lab[4] = lab[5];
		lab[5] = lab[1];
		lab[1] = temp;
	}

	void koroN() {
		int temp = this.lab[0];
		lab[0] = lab[1];
		lab[1] = lab[5];
		lab[5] = lab[4];
		lab[4] = temp;
	}

	void koroW() {
		int temp = this.lab[0];
		lab[0] = lab[2];
		lab[2] = lab[5];
		lab[5] = lab[3];
		lab[3] = temp;
	}

	void koroE() {
		int temp = this.lab[0];
		lab[0] = lab[3];
		lab[3] = lab[5];
		lab[5] = lab[2];
		lab[2] = temp;
	}
	void kaitentokei() {
		int temp = this.lab[1];
		lab[1] = lab[2];
		lab[2] = lab[4];
		lab[4] = lab[3];
		lab[3] = temp;
	}
}

Measured memory_bytes: 24228
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  string a,b,c;

  cin>>a>>b>>c;

  if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;

}




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

int n, a, b;
int ans = 0;

int sumofdigits(int n) {
    int s = 0;
    while (n > 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int main() {
    cin >> n >> a >> b;
    for (int i = 0; i <= n; i++) {
        int sum = sumofdigits(i);
        if (sum >= a && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
b = []
c = []
for i in range(q):
    x, y = map(int, input().split())
    b.append(x)
    c.append(y)

d = collections.defaultdict(int)
for i in range(n):
    d[a[i]] += 1

s = sum(a)

for i in range(q):
    s -= b[i] * d[b[i]]
    s += c[i] * d[b[i]]
    d[c[i]] += d[b[i]]
    d[b[i]] = 0
    print(s)

Measured memory_bytes: 103664
S = input()
a, b = int(S[:2]), int(S[2:])
if (1 <= a <= 12):
    if (1 <= b <= 12):
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if (1 <= b <= 12):
        print('YYMM')
    else:
        print('NA')

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

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;


int main(){
  string s1, s2; cin >> s1 >> s2;

  int ans = 0;
  for (int i = 0; i < 3; i++){
    if (s1[i] == s2[i]) ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 1e5 + 10;

int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    ll x, y ,z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << ' ' << y << ' ' << z;
    return 0;
}
/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/
//! N.N


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x; cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}
/********  Main() Ends Here *************/


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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[n];
  int min = 2100000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < min) min = a[i];
  }
  bool flg;
  int tmp;
  while(true) {
    flg = false;
    for (int i = 0; i < n; i++) {
      tmp = ((a[i] - 1) % min) + 1;
      if (tmp != a[i]) {
        flg = true;
        a[i] = tmp;
      }
    }
    if (!flg) break;
    for (int i = 0; i < n; i++) {
      if (a[i] < min) min = a[i];
    }
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    ll N;
    cin >> N;

    ll m = sqrt(N);

    ll ans;
    for (ll i=m; i>=1; i--) {
        if (N%i == 0) {
            ll a = N / i;
            ans = a + i - 2;
            break;
        }
    }
    print(ans);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> vec(N, vector<int>(10));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < 10;j++) {
            cin >> vec.at(i).at(j);
        }
    }
    vector<vector<int>> P(N, vector<int>(11));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < 11;j++) {
            cin >> P.at(i).at(j);
        }
    }
    ll ret = -INF;
    for(int bit = 1;bit < (1 << 10);bit++) {
        vector<int> cnt(10);
        for(int i = 0;i < 10;i++) {
            if(bit & (1 << i)) {
                cnt.at(i) = 1;
            }
            else {
                cnt.at(i) = 0;
            }
        }
        ll count = 0;
        for(int i = 0;i < N;i++) {
            int cnt2 = 0;
            for(int j = 0;j < 10;j++) {
                if(vec.at(i).at(j) == 1 && cnt.at(j) == 1) {
                    cnt2++;
                }
            }
            count += P.at(i).at(cnt2);
        }
        ret = max(ret, count);
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;

int main(){

	long N; cin >> N;
	long C[1000], S[1000], F[1000];
	long res[1000] = {};

	for (int i = 1; i <= N; i++) cin >> C[i] >> S[i] >> F[i];

	for (int i = 1; i <= N; i++){
		for (int j = i; j <= N - 1; j++){
			if (res[i] < S[j]) res[i] = S[j];
			if ((res[i] - S[j]) % F[j] != 0){
				res[i] += F[j] - (res[i] - S[j]) % F[j];
            }
            res[i] += C[j];
		}
		cout << res[i] << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vi d(n);
    map<int,int>c;
    rep(i,n){
        cin>>d[i];
        c[d[i]]++;
    }
    int m;cin>>m;
    vi t(m);
    map<int,int>s;
    rep(i,m){
        cin>>t[i];
        s[t[i]]++;
    }
    sort(all(t));
    t.erase(unique(all(t)),t.end());
    int x=t.size();
    bool a=true;
    rep(i,x){
        if(c[t[i]]<s[t[i]])a=false;
    }
    if(a)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

int main(){
    int N,M;
    cin>>N>>M;
    int v,u;
    vector<int> edge[300000];
    rep(i,M){
        cin>>u>>v;
        v--;u--;
        edge[3*u].push_back(3*v+1);
        edge[3*u+1].push_back(3*v+2);
        edge[3*u+2].push_back(3*v);
    }
    int S,T;
    cin>>S>>T;
    S--;T--;
    S*=3;T*=3;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,S));
    bool done[300000];
    rep(i,3*N) done[i] = false;
    while(1){
        if(q.empty()) break;
        pair<int,int> p = q.top();
        q.pop();
        if(done[p.second]) continue;
        if(p.second == T){
            cout<<p.first/3<<endl;
            return 0;
        }
        done[p.second] = true;
        rep(i,edge[p.second].size()){
            if(done[edge[p.second][i]]) continue;
            q.push(make_pair(p.first+1,edge[p.second][i]));
        }
    }
    cout<<-1<<endl;
    return 0;
}

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

typedef long long LL;  
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const int M = 1000000007;

int main()
{
ios_base::sync_with_stdio(0); 
cout.precision(15);
cout.setf(ios::fixed);

//I can do it..from tommorrow I will switch on my ultra power mode...

string s;

cin >> s;
int i;
int n = s.size();

stack <char> st;

for(i=0;i<n;i++)
	{
	if(st.empty())
		st.push(s[i]);
	else if(st.top()!='S')
		st.push(s[i]);
	else if(s[i]!='T')	
		st.push(s[i]);
	else
		st.pop();
	
	//cout << st.top() << endl;
	}	
		
cout << st.size() << endl;	

}

Measured memory_bytes: 720
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split(" ");
 
  var a = parseInt(input[0],10);
  var b = parseInt(input[1],10);
  
  if(a > b){
      var tmp = a;
      a = b;
      b = tmp;
  }
  var ans;
  if(a < b-1){
      ans = b + (b-1);
  }else{
      ans = b + a;
  }
  
  console.log('%d\n',ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372