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

int main(void) {
    int x,y,tem;
    while (1) {
        scanf("%d %d",&x,&y);
        if (x==0&&y==0)        {
            break;
        }else if(x>y){
            tem=x;
            x=y;
            y=tem;
            printf("%d %d\n",x,y);
        }else
        {  printf("%d %d\n",x,y);
        }
        
    }
  
    
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, A, B; cin >> N >> A >> B;
    int whole = 0, abroad = 0;
    string S; cin >> S;
    rep(i, N){
        if(S[i] == 'a'){
            if(whole < A+B){
                cout << "Yes" << endl;
                whole++;
            }
            else cout << "No" << endl;
        }
        else if(S[i] == 'b'){
            if(whole < A+B && abroad < B){
                cout << "Yes" << endl;
                whole++;
                abroad++;
            }
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  vector<int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  sort(vec.begin(), vec.end());
  cout << vec[2] - vec[0] << endl;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
int cost[15][15];

int main()
{
  int n, m;
  cin>>n>>m;
  rep(i, 0, 10)
    rep(j, 0, 10)
    {
      cin>>cost[i][j];
    }
  rep(k, 0, 10)
    rep(i, 0, 10)
      rep(j, 0, 10)
      {
        if(cost[i][j] > (cost[i][k] + cost[k][j]))
        {
          cost[i][j] = cost[i][k] + cost[k][j];
        }
      }
  ll ans = 0;
  rep(i, 0, n)
    rep(j, 0, m)
    {
      int a;
      cin>>a;
      if(a == -1) continue;
      ans += cost[a][1];
      //cout<<cost[a][1]<<endl;
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#define ll long long
#define re register
using namespace std;
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum*10)+ch-'0';ch=getchar();}
    return f*sum;
}
int r,D,X;
int main(){
	r=gi();D=gi();X=gi();
	for(int i=1;i<=10;i++)
	{
		X*=r;X-=D;
		printf("%d\n",X);
	}
	return 0;
}

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

const int MaxN(100003);
int A[MaxN];

int main()
{
	int n, ans = 0;
#ifdef zxp
	freopen("candy.in", "r", stdin);
	freopen("candy.out", "w", stdout);
#endif
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &A[i]);
	sort(A + 1, A + 1 + n, greater<int> ());
	for(int i = 1; i <= n; i++)
		if(i + 1 > A[i + 1])
		{
			for(int j = i + 1; A[j] == i; j++)
				ans ^= 1;
			ans |= (A[i] - i) & 1;
			break;
		}
	puts(ans ? "First" : "Second");
	return 0;
}


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

int main(){
	char s[11],t[11];
	int n;
	
	scanf("%s",s);
	scanf("%s",t);
	
	n = strlen(s);	//文字列の長さを調べる
	
	if(strncmp(s,t,n) == 0){
		//文字列sと文字列t、文字列sの長さの部分まで一致しているかどうか
		printf("Yes");
	}
	else printf("No");
	
	return 0;
}


Measured memory_bytes: 1776
n = int(input())
a = list(map(int,input().split()))
L = [0] * n
for i in range(n):
  count = 0
  while a[i] % 2 == 0:
    count += 1
    a[i] = a[i]//2
  L[i] = count
    
print(min(L))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>

#include <iostream>
#include <string>

using namespace std;

char alphas[26];

int main(int argc, char const *argv[])
{

	string S;
	cin >> S;

	for (int i = 0; i < S.length(); i++) {
		int pos = S[i] - 'a';
		if (alphas[pos]) {
			printf("no\n");
			return 0;
		}
		alphas[pos] = true;	
	}
	printf("yes\n");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
int main() {
	ios::sync_with_stdio(false);

	ll N; cin >> N;
	ll M; cin >> M;

	priority_queue<ll> s;

	FOR(i,0,N) {
		ll a;
		cin >> a;
		s.push(a);
	}

	FOR(i,0,M) {
		ll cur = s.top(); s.pop();
		s.push(cur / 2);
	}

	ll ges = 0;
	while(!s.empty()) {
		ll n = s.top(); s.pop();
		ges += n;
	}
	cout << ges << endl;

	return 0;
}


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

using namespace std;

int main(){
    string a,b;
    cin >> a;
    cin >> b;
    size_t result = a.length();
    if(a.compare(0, result, b, 0, result) == 0){
        if(b.length() == a.length() + 1){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int n,r;
    cin >> n >> r;
    cout << (n >= 10 ? r : r + 100*(10 - n)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>

using ll = long long;
using namespace std;
//#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int i = n; i >= 0; i--)

int main() {
	int h, n;
	int sum = 0;
	cin >> h >> n;
	vector<int> a;
	a.resize(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	};
	cout << ((h - sum <= 0) ? "Yes" : "No") << endl;
	return 0;
}

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

int main() {
   int n,k,ans=1;
   cin >> n >> k;
   rep(i, n) {
      if(ans*2 <= ans+k) {
         ans *= 2;
      }else {
         ans += k;
      }
   }
   cout << ans << endl;
   return 0;
}

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

int dignum(ll a){
  int cnt=0;
  while(a>0){
    a = a/10;
    cnt++;
  }
  return cnt;
}
int main(){
  ll N;
  ll cnt=0;
  cin >> N;
  ll ans=dignum(N);
  for(ll a=1; a*a<=N; a++){
    if(N%a!=0) continue;
    cnt = max(dignum(a), dignum(N/a));
  	ans = min(ans, cnt);
    //cout << ans << endl;
  }
     cout << ans << endl; 
 }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
s = "Q"+input()
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
deg = [0 for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
  deg[a] += 1
  deg[b] += 1
leaf = set()
for i in range(1,n+1):
  if deg[i] == 1:
    leaf.add(i)
if s.count("1") == 1:
  print(0)
  exit()
ans = 10**18
for root in range(1,n+1):
  degr = deg[:]
  degr[root] += 1
  if root in leaf:
    continue
  stack = list(leaf)
  dpn = [[] for i in range(n+1)]
  dpmn = [[] for i in range(n+1)]
  dpmx = [[] for i in range(n+1)]
  info = [[0,0,0] for i in range(n+1)]
  for i in leaf:
    if s[i] == "1":
      info[i][0] += 1
  vis = set(i for i in leaf)
  anstmp = 0
  while stack:
    x = stack.pop()
    if dpn[x]:
      if len(dpn[x]) == 1:
        num = dpn[x][0]
        info[x] = [num,dpmn[x][0]+num,dpmx[x][0]+num]
        if s[x] == "1":
          info[x][0] += 1
      else:
        info[x][0] = sum(dpn[x])
        info[x][2] = sum(dpmx[x])+info[x][0]
        mxv = -1
        mxind = -1
        for i in range(len(dpmn[x])):
          if mxv < dpmn[x][i]+dpn[x][i]:
            mxv = dpmn[x][i]+dpn[x][i]
            mxind = i
        cnst = mxv-info[x][2]+dpmx[x][mxind]+dpn[x][mxind]
        info[x][1] = max(0,cnst%2,cnst)
        if s[x] == "1":
          info[x][0] += 1
    for y in graph[x]:
      if y not in vis:
        dpn[y].append(info[x][0])
        dpmn[y].append(info[x][1])
        dpmx[y].append(info[x][2])
        degr[y] -= 1
        if degr[y] == 1:
          vis.add(y)
          stack.append(y)
  if info[root][1] == 0:
    ans = min(ans,info[root][2]//2)
if ans == 10**18:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 128772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    vl a(2), b(2);
    rep(i, 2) cin >> a[i];
    rep(i, 2) cin >> b[i];
    ll ans = -INF;
    rep(i, 2) rep(j, 2) chmax(ans, a[i] * b[j]);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	boolean[][] board;
	int[] fdx = new int[]{1, -1, 0, 0};
	int[] fdy = new int[]{0, 0, -1, 1};

	void dfs(int x, int y) {
		if(x < 0 || y < 0 || x >= 12 || y >= 12) return;
		if(!board[x][y]) return;
		if(board[x][y]) board[x][y] = false;
		for(int r = 0; r < fdx.length; r++) {
			dfs(x + fdx[r], y + fdy[r]);
		}
	}

	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			board = new boolean[12][12];
			for(int r = 0; r < 12; r++) {
				String input = stdIn.next();
				for(int c = 0; c < 12; c++) {
					if(input.charAt(c) == '1') board[r][c] = true;
				}
			}
			int count = 0;
			while(true) {
				boolean flag = false;
				for(int r = 0; r < 12; r++) {
					for(int c = 0; c < 12; c++) {
						if(board[r][c]) {
							flag = true;
							dfs(r, c);
							count++;
							break;
						}
						if(flag) break;
					}
				}
				if(!flag) break; //見つからなかったら既に探索が完了している。
			}
			System.out.println(count);
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}
}

Measured memory_bytes: 17160
from collections import defaultdict
from heapq import heappush, heappop

v, e = map(int, input().split())
E = defaultdict(list)
for _ in range(e):
    s, t, w = map(int, input().split())
    E[s].append((w, t))
    E[t].append((w, s))
d = [float("inf")] * v
used = [False] * v
d[0] = 0

# def prim
ans = 0
q = []
heappush(q, (0, 0))
while q:
    dist, now = heappop(q)
    if used[now]:
        continue
    used[now] = True
    ans += dist
    for w, nxt in E[now]:
        if not used[nxt]:
            heappush(q, (w, nxt))
print(ans)


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

int main() {
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n-1;i++){
        int x;cin>>x;
        a[x-1]++;
    }

    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }


    return 0;
}


Measured memory_bytes: 3988
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll mod=998244353;

int main(){
    ll n;
    cin >> n;
    vector<pll> s,t;
    rep(i,n){
        string a;
        cin >> a;
        ll m=a.length();
        ll le=0,ri=0;
        ll p=0;
        rep(j,m){
            if(a[j]=='(') le++;
            else ri++;
            p=min(p,le-ri);
            
        }
        if(le-ri>=0){
            s.push_back(make_pair(p,le-ri));
        }
        else{
            t.push_back(make_pair(p-(le-ri),ri-le));
        }
    }
    sort(s.rbegin(),s.rend());
    sort(t.rbegin(),t.rend());
    ll x=s.size();
    ll y=t.size();
    ll sum1=0,sum2=0;
    bool ok=true;
    rep(i,x){
        if(sum1+s[i].fi<0){
            ok=false;
            break;
        }
        sum1+=s[i].se;
    }
    rep(i,y){
        if(sum2+t[i].fi<0){
            ok=false;
            break;
        }
        sum2+=t[i].se;
    }
    if(ok && sum1==sum2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int A, B;
    cin >> A >> B;
    int cnt = 6;
    cout << cnt - A - B << '\n';
}

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


Measured memory_bytes: 256
using System.Linq;
using System;

public class P
{
    public int s { get; set; }
    public int t { get; set; }
}

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            ps[i] = new P { s = int.Parse(line[0]), t = int.Parse(line[1]) };
        }
        getAns(ps);
    }
    static void getAns (P[] ps)
    {
        var count = 0;
        var nt = -1;
        foreach (var x in ps.OrderBy(a =>a.t).ThenBy(a =>a.s))
            if (x.s > nt) { count++;  nt = x.t; }
        Console.WriteLine(count);
    }
}



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

namespace Atcoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            long L = Lcm(N, M);
            
            long lm = L / M;
            long ln = L / N;
            for (int i = 0; i < N / lm;i++){
                string S_char = S.Substring((int)lm * i, 1);
                string T_char = T.Substring((int)ln * i, 1);
                if(S_char!=T_char){
                    Console.WriteLine(-1);
                    return;
                }
            }
            Console.WriteLine(L);
        }
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
      
    }
}


Measured memory_bytes: 11488
#include <stdio.h>

int main(){
    long long int n,a,b,sum,ans,m;
    scanf("%lld%lld%lld",&n,&a,&b);
    sum=a+b;
    ans=a*(n/sum);
    m=n%sum;
    if(m>a) ans+=a;
    else ans+=m;
    printf("%lld",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int a, b, c;
	cin>>a>>b>>c;
	ll ans = 0;
	FOR(i, a, b + 1) {
		if(c % i == 0) ++ans;
	}
	cout<<ans<<endl;
}

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

#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    ll s,w; cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
        return 0;
    }
    else{
        cout<<"safe"<<endl;
    }
    
    return 0;
}

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

const int N=1e5+5;

ll x,y,h,w,n;
ll ans[15],node[N<<4],tot; 

int main(){ 
	scanf("%lld%lld%lld",&h,&w,&n);
	ll zero=(h-2)*(w-2);
	while(n--){
		scanf("%lld%lld",&x,&y);
		for(ll i=0;i<3;i++)
			for(ll j=0;j<3;j++)
				if(1<=x-i&&x-i<=h-2&&1<=y-j&&y-j<=w-2) node[tot++]=mod*(x-i)+(y-j);
	} 
	sort(node,node+tot);
	for(int i=0,cnt=1;i<tot;i++)
		if(node[i]==node[i+1]) cnt++;
		else ans[cnt]++,cnt=1,zero--; 
	printf("%lld\n",zero);
	for(int i=1;i<=9;i++) printf("%lld\n",ans[i]); 
	return 0; 
}


Measured memory_bytes: 8448
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if(a==1)a=14;
	if(b==1)b=14;
	if(a==b)cout<<"Draw\n";
	else if(a>b)cout<<"Alice\n";
	else cout<<"Bob";
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
using namespace std;
const int maxn = 1e5 + 100;
int n, k;
long long a[maxn][5], dp[maxn][5];
int main()
{
    cin>>n;
    for(int i = 1; i <= n; i++) for(int j = 0; j < 3; j++) cin>>a[i][j];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
            }
        }
    }
    long long ans = 0;
    for(int j = 0; j < 3; j++) ans = max(ans, dp[n][j]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long int    
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const ll MOD = 1e9 + 7, N = 1e5 + 3;

int main(){
    ll x;
    for(int i = 1; i <= 5; ++i){
        cin >> x;
        if(x == 0)
            cout << i;
    }
    return 0;
}

Measured memory_bytes: 3588
N = int(input())
S = str(input())

first_num_list  = []
second_num_list = []
third_num_list  = []

count = 0

for s_first in range(len(S)):
  second_num_list = []
  if S[s_first] not in first_num_list:
    first_num_list.append(S[s_first])
    for s_second in range(s_first+1,len(S)):
      third_num_list = []
      if S[s_second] not in second_num_list:
        second_num_list.append(S[s_second])
        for s_third in range(s_second+1,len(S)):
          if S[s_third] not in third_num_list:
            third_num_list.append(S[s_third])
            count += 1

print(count)


Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
int ans[300010];
int main() {
	int n, k;
	scanf("%d%d", &k, &n);
	if (k == 1) {
		for (int i = 1; i <= (n+1) / 2; i++) printf("1 ");
		puts("");
		return 0;
	}
	if (k % 2 == 0) {
		printf("%d ", k / 2);
		for (int i = 2; i <= n; i++) printf("%d ", k);
		puts("");
		return 0;
	}
	for (int i = 1; i <= n; i++) ans[i] = k / 2 + 1;
	int d = n / 2;
	for (; d > 0; d--) {
		if (ans[n] > 0) ans[n]--;
		else {
			int u;
			for (u = n; u >= 1 && ans[u] == 0; u--);
			if (--ans[u] != 0) {
				for (int j = u + 1; j <= n; j++) ans[j] = k;
			}
		}
	}
	for (int i = 1; i <= n && ans[i] != 0; i++) printf("%d ", ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3328
import itertools

A, B, C, D, E, F = map(int, input().split())

water, sugar = set(), set()
for a, b in itertools.product(range(F // (100 * A) + 1),
                              range(F // (100 * B) + 1)):
    tmp = 100 * A * a + 100 * B * b
    if 0 < tmp <= F:
        water.add(tmp)

for c, d in itertools.product(range(F // C + 1),
                              range(F // D + 1)):
    tmp = C * c + D * d
    if tmp <= F:
        sugar.add(tmp)

conc_max = 0
ans_w, ans_s = 100 * A, 0
for w, s in itertools.product(water, sugar):
    if w + s > F or w // 100 * E < s:
        continue
    conc = 100 * s / (w + s)
    if conc > conc_max:
        conc_max = conc
        ans_w, ans_s = w + s, s
print(ans_w, ans_s)


Measured memory_bytes: 3316
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  vector<ll> v;
  rep(i,0,5){
    ll a;
    cin>>a;
    v.pb(a);
  }
  rep(i,0,5){
    if(v[i]==0){
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	map<string, int> mp;
	for (int i = 0; i < N; i++) {
		string tmp;
		cin >> tmp;
		mp[tmp]++;
	}

	int freq = 0;
	vector<string> ans;
	for (const auto &e : mp) {
		if (chmax(freq, e.second)) ans.clear();
		if (freq == e.second) ans.emplace_back(e.first);
	}

	for (const auto &e : ans) cout << e << "\n";

	return 0;
}

Measured memory_bytes: 25584
#include <iostream>

using namespace std;

int main() {
  int a[100]; // constraint: n <= 100
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = n - 1; i >= 0; --i) {
    if (i < n - 1)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pi pair <ll,ll>
#define vi vector <ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define SQ(a) (a)*(a)
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>       //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll i,j,k,n,m,t,l=0,x,prev=0,max1=0,flag=0,cnt=0,y,min1,q;
    cin>>n>>k;
    set <ll> st;
    while(k--){
        cin>>m;
        for(i=0;i<m;i++){
            cin>>x;
            st.insert(x);
        }
    }
    cout<<n-st.size()<<endl;


    return 0;
}


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



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j) continue;
            int bit = 1;
            int cnt = 0;
            while(true){
                cnt++;
                if(((i&bit) ^ (j&bit)) == bit){
                    a[i][j] = cnt;
                    break;
                }
                bit = (1<<cnt);
                // cerr << cnt << " " << bit << " " << (i&bit) << " " << (j&bit) << endl;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
int smaller_on_left[2005], smaller_on_right[2005];
/***** MAIN *****/
signed main() {
  int n,k; cin >> n >> k;
  int nums[n];
  REP(i,n) {
    cin >> nums[i];
  }
  REP(i,n) {
    REP(j,n) {
      if(i==j) continue;
      if(nums[i] <= nums[j]) continue;
      if(i > j) ++smaller_on_left[i];
      else ++smaller_on_right[i];
    }
  }
  mint ans = 0;
  mint right_total = 0;
  mint left_total = 0;
  REP(i,n) {
    right_total += smaller_on_right[i];
    left_total += smaller_on_left[i];
  }
  if(k == 1) {
    cout << right_total << endl;
    return 0;
  }
  int left_multi = k>1
    ? k*(k-1)/2
    : 1;
  int right_multi = k*(k+1)/2;
  ans += left_total * left_multi;
  ans += right_total * right_multi;
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define all(x) x.begin() , x.end()

int const N = 2001;
int n, m , x, y , dp[3001][3001];
string a,b;

int go(int i,int j){
     if(i == n || j == m)return 0;
     int &ret = dp[i][j];
     if(ret + 1)return ret;
     if(a[i] == b[j])ret = max(ret,go(i+1,j+1)+1);
     return ret = max(ret,max(go(i+1,j),go(i,j+1)));
}

void build(int i,int j){
       if(i == n || j == m)return ;
       if(a[i] == b[j]){
         if(go(i+1,j+1)+1 == go(i,j)){
          cout << a[i];
           build(i+1,j+1);
           return ;
         }
         return ;
       }
      else {
          if(go(i+1,j) == go(i,j)){
             build(i+1,j);
             return;
          } else {
             build(i,j+1);
             return ;
          }
      }
}

int main()
{    
    cin >> a >> b ; 
    n = a.size(),m = b.size();
    memset(dp,-1,sizeof dp);
    int an = go(0,0);
    build(0,0);
} 

Measured memory_bytes: 35840
#include<iostream>
using namespace std;
int main(){
int student[30],i,j,num;
for(i=0;i<30;i++){
student[i]=i+1;
}
for(j=0;j<28;j++){
cin>>num;
student[num-1]=0;
}
for(i=0;i<30;i++){
if(student[i]!=0)cout<<student[i]<<endl;
}
return 0;
}

Measured memory_bytes: 1160
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))
lb = 0
ub = max(A)
while True:
    X = (ub+lb)/2
    count = 0
    for i in range(N):
        count += ceil(A[i]/X-1)
    if count > K:
        lb = X
    else:
        ub = X
    if ceil(ub) == ceil(lb):
        print(ceil(ub))
        exit()

Measured memory_bytes: 31052
n=int(input())
a=[*map(int,input().split())]
from math import *
l=a.copy()
r=a.copy()
for i in range(n-1):
  l[i+1]=gcd(l[i],l[i+1])
  r[-i-2]=gcd(r[-i-1],r[-i-2])
a=max(l[-2],r[1])
for i in range(1,n-1):
  a=max(a,gcd(l[i-1],r[i+1]))
print(a)

Measured memory_bytes: 20824
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;
int a[105];


int main() {
	int n;
	
	cin >> n;
	for (int i = 1; i < n + 1; i++) {
		int u = i;
		for (int j = 2; j < n + 1; j++) {
			while (u % j == 0) {
				u /= j;
				a[j]++;
			}
		}
	}
	int cou2 = 0;
	int cou4 = 0;
	for (int i = 0; i < n + 1; i++) {
		if (a[i]<4&&a[i] >= 2)cou2++;
		if (a[i] >= 4)cou4++;
	}
	int ans = cou2 * cou4 * (cou4 - 1) / 2 + cou4 * (cou4 - 1) * (cou4 - 2)/2 ;
	int cou14 = 0;
	cou4 = 0;
	for (int i = 0; i < n + 1; i++) {
		if (a[i] < 14 && a[i] >= 4)cou4++;
		if (a[i] >= 14)cou14++;
	}
	ans += cou14 * cou4+cou14*(cou14-1);
	int cou24 = 0;
	cou2 = 0;
	for (int i = 0; i < n + 1; i++) {
		if (a[i] < 24 && a[i] >= 2)cou2++;
		if (a[i] >= 24)cou24++;
	}
	ans += cou24 * cou2 + cou24 * (cou24 - 1);
	int cou = 0;
	for (int i = 0; i < n + 1; i++) {
		if (a[i] >=74)cou++;
	}
	ans += cou;
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    using namespace std;
    #define INF 10000000;
     
    
int fx(int x){
    int x2,sum;
	while(x>0){
		x2 = x%10;
		sum += x2;
        x /=10;
    }
    return sum;
}

int main(){
    int n,x;
    cin >> n;
    x = fx(n);
    if(n%x == 0)cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 int change(char);
int main(){
char c1,d1,s;
  scanf("%c%c%c",&c1,&s,&d1);
  
  int c =change(c1);
  int d = change(d1);
 
  if(c>d){
printf(">");
  }else if(c<d){
    printf("<");
  }else if(c = d){
    printf("=");
  }
  return 0;
}

int change(char i){
  if(i=='A'){
    return 65;
  }else if(i=='B'){
    return 66;
  }else if(i=='C'){
    return 67;
  }else if(i=='D'){
    return 68;
  }else if(i=='E'){
    return 69;
  }else if(i=='F'){
    return 70;
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n][3], b[n][3];
	for(int i =0 ;i <n; i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	b[0][0]=a[0][0];
	b[0][1]=a[0][1];
	b[0][2]=a[0][2];

	for(int i = 1;i<n; i++)
	{
		for(int j = 0;j<3; j++)
		{
			b[i][j] = max(b[i-1][(j+1)%3],b[i-1][(j+2)%3]);
			b[i][j] += a[i][j];
		}
	}
	cout<<*max_element(b[n-1],b[n-1]+3)<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	long N,L;
	vector<long> A;
	cin >> N;
	
	for (int i = 0; i < N; i++)
	{
		long t;
		cin >> t;
		A.push_back(t);
	}
	sort(A.begin(), A.end());

	L = A[N / 2] - A[N / 2 - 1];

	cout << L << endl;

}

Measured memory_bytes: 1400
using System;
using System.Linq;

namespace diverta2019_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var RGBN = (Console.ReadLine().Split(' ').Select(x => int.Parse(x))).ToList();
            var R = RGBN[0];
            var G = RGBN[1];
            var B = RGBN[2];
            var N = RGBN[3];
            var r = 0;

            for (int i = 0; i <= N; i += R)
            {
                for (int j = 0; j <= N; j += G)
                {
                    if (i + j > N) break;

                    //残りがBで割り切れる
                    if ((N - (i + j)) % B == 0) r++;
                }
            }

            Console.WriteLine(r);

        }
    }
}


Measured memory_bytes: 11220
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func nexChara() string {
	sc.Scan()
	return sc.Text()
}

type kv struct {
	Key   string
	Value int
}

type byValue []kv

func (a byValue) Len() int           { return len(a) }
func (a byValue) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byValue) Less(i, j int) bool { return a[i].Value > a[j].Value }
func (a byValue) Up(i, j int) bool   { return a[i].Value > a[j].Value }

func main() {
	var N int
	fmt.Scan(&N)

	m := make(map[string]int)
	for i := 0; i < N; i++ {
		chara := nexChara()
		m[chara]++
	}

	var tmpMax int
	for _, value := range m {
		if tmpMax <= value {

			tmpMax = value
		}
	}

	var ss []kv
	for k, v := range m {
		ss = append(ss, kv{k, v})
	}

	// sort.Slice(ss, func(i, j int) bool {
	// 	return ss[i].Value > ss[j].Value
	// })

	sort.Sort(byValue(ss))

	flat := []string{}
	var prev int
	for i, kv := range ss {
		if i == 0 {
			prev = kv.Value
		} else {
			if prev != kv.Value {
				break
			}
		}
		flat = append(flat, kv.Key)
	}

	sort.Strings(flat)

	for _, value := range flat {
		fmt.Println(value)
	}
}


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

int main()
{
	int a, b, n;
	while (cin >> a >> b >> n)
	{
		int ans = 0;
		a = 10 * (a % b);
		
		while (n--)
		{
			ans += a / b;
			a = 10 * (a % b);
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int main(){
	string iwi;
	int d = 0;

	cin >> iwi;
	if (!iwi.size()){
		printf("0\n");
		return 0;
	}
	for (int i = 0; i * 2 < iwi.size() ; i++){
		switch (iwi.at(i)){
		case 'i':
			if (iwi.at(iwi.size() - i - 1) != 'i'){
				d++;
			}
			break;
		case 'w':
			if (iwi.at(iwi.size() - i - 1) != 'w'){
				d++;
			}
			break;
		case '(':
			if (iwi.at(iwi.size() - i - 1) != ')'){
				d++;
			}
			break;
		case ')':
			if (iwi.at(iwi.size() - i - 1) != '('){
				d++;
			}
			break;
		}
	}
	printf("%d\n", d);
}

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

int main() {
    string S ;
    cin >> S ;
    
    int cnt=0;
    
    for( int i=0 ;i<3 ; i++){
        
        if( S == "RSR" ){
            cnt=1;
            break;
        }
        
        else if( S.at(i)=='R'){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	string s;
	cin >> s;
	int n = (int) s.size();
	set <string> st;
	for (int i = 0; i < n; i++) {
		int len = 0;
		for (int j = i; j < n; j++) {
			len++;
			st.insert(s.substr(i, len));
			if(len == 5)
				break;
		}
	}
	int k;
	cin >> k;
	for (auto g : st) {
		k--;
		if(k == 0) {
			cout << g;
			return 0;
		}
	}
}


Measured memory_bytes: 1664
#include<iostream>
int n,m,s[201],t[201],i,j,x,y;main(){for(;std::cin>>n>>m,n|m;x-999?printf("%d %d\n",x,y):puts("-1")){x=999;for(i=t[0]=0;i<n+m;t[i+1]=t[i]+s[i++])std::cin>>s[i];for(i=0;i<n;i++)for(j=0;j<m;j++)if(s[i]+s[n+j]<x+y&&!(t[n+m]-2*t[n]-2*s[n+j]+2*s[i])){x=s[i];y=s[n+j];}}}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, c, d[35][35], a[514][514];
vector<P> ans[3];
int cnt1, cnt2, cnt3;
vector<P> ta[3];
int mu = INF;

signed main() {
	cin >> n >> c;
	rep(i, c) {
		rep(j, c)cin >> d[i][j];
	}
	rep(i, n) {
		rep(j, n)cin >> a[i][j];
	}
	rep(i, c) {
		cnt1 = 0;
		cnt2 = 0;
		cnt3 = 0;
		rep(j, n) {
			rep(k, n){
				if ((j + k) % 3 == 0)cnt1 += d[a[j][k]-1][i];
				else if ((j + k) % 3 == 1)cnt2 += d[a[j][k]-1][i];
				else cnt3 += d[a[j][k]-1][i];
			}
		}
		ta[0].push_back({ cnt1,i });
		ta[1].push_back({ cnt2,i });
		ta[2].push_back({ cnt3,i });
	}
	rep(i, 3) {
		sort(all(ta[i]));
	}
	rep(i, 3) {
		rep(j, 3) {
			ans[i].push_back(ta[i][j]);
		}
	}
	rep(i, 3) {
		rep(j, 3) {
			rep(k, 3) {
				if (ans[0][i].second != ans[1][j].second&&ans[1][j].second != ans[2][k].second&&ans[0][i].second!=ans[2][k].second)mu = min(mu, ans[0][i].first + ans[1][j].first + ans[2][k].first);
			}
		}
	}
	cout << mu << endl;
}

Measured memory_bytes: 2304
L=list(map(int,input().split()))
count=0
L=sorted(L)
while(1):
	if L[1]!=L[2]:
		L[0]+=1
		L[1]+=1
		count+=1
	else:
		if L[0]==L[1]:
			print(count)
			exit()
		elif L[1]-L[0]>1:
			L[0]+=2
			count+=1
		elif L[1]-L[0]==1:
			print(count+2)
			exit()

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N=Integer.parseInt(sc.next());
        int A=Integer.parseInt(sc.next());
        int B=Integer.parseInt(sc.next());
        int ans=0;
        for (int i=1;i<=N;i++){
            int n=i;
            int sum=0;
            while (n>0){
                sum+=n%10;
                n/=10;
            }
            if (sum>=A && sum<=B)
                ans+=i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string s;
    cin >> s;
    if (s == "SUN") cout << 7 << endl;
    if (s == "MON") cout << 6 << endl;
    if (s == "TUE") cout << 5 << endl;
    if (s == "WED") cout << 4 << endl;
    if (s == "THU") cout << 3 << endl;
    if (s == "FRI") cout << 2 << endl;
    if (s == "SAT") cout << 1 << endl;
}


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 1e9
#define MOD 1000000007;//1e9+7

int main() {
    string S;
    cin >> S;
    int N = S.size();
    //dp[i][j]=上からi桁決めたときに13で割ってj余る数の総数をMODで割ったあまり
    vector<vector<long long>>dp(N + 1, vector<long long>(13, 0));
    dp[0][0] = 1;

    rep(i, N) {
        int d = (S[i] == '?') ? (-1) : (S[i] - '0');
        rep(k, 10) {
            if (d != -1 && d != k)continue;
            rep(j, 13) {
                int ni = i + 1, nj = (j * 10 + k) % 13;
                dp[ni][nj] += dp[i][j];
                dp[ni][nj] %= MOD;
            }
        }
    }
    cout << dp[N][5];

    return 0;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int n;
int h[16],w[16];
char t[16];
vector<P> G;
map<P,bool> used;
string str="RGB";

int d[(1<<16)];

int solve(){
  queue<int> Q;
  for(int i=0;i<(1<<16);i++)d[i]=-1;
  d[0]=0;
  Q.push(0);
  
  while(!Q.empty()){
    int S=Q.front();Q.pop();
    if(S==(1<<16)-1)return d[S];
    
    for(int i=0;i<(int)G.size();i++){
      int ay=G[i].first/5;
      int ax=G[i].first%5;
      int by=G[i].second/5;
      int bx=G[i].second%5;
      //cout<<ay<<' '<<ax<<' '<<by<<' '<<bx<<endl;
      for(int j=0;j<3;j++){
        char ch=str[j];
        int next=S;
        for(int y=ay;y<by;y++){
          for(int x=ax;x<bx;x++){
            int z=y*4+x;
            next|=(1<<z);
            if(t[z]!=ch)next-=(1<<z);
          }
        }
        if(d[next]==-1){
          d[next]=d[S]+1;
          Q.push(next);
        }
      }
    }
  }
  return -1;
}

void add(int h,int w){
  P p;
  for(int i=-h+1;i<4;i++){
    for(int j=-w+1;j<4;j++){
      int ay=max(i,0);
      int ax=max(j,0);
      int by=min(i+h,4);
      int bx=min(j+w,4);
      p.first=ay*5+ax;
      p.second=by*5+bx;
      if(used[p])continue;
      used[p]=true;
      G.push_back(p);
    }
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i]>>w[i];
    add(h[i],w[i]);
  }

  for(int i=0;i<16;i++)cin>>t[i];
  sort(G.begin(),G.end());
  cout<<solve()<<endl;
  return 0;
}

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

use std::io;

fn main() {
    let sin = io::stdin();
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let n: u32 = buf.trim().parse().unwrap();

    // 行がs,h,c,dの順で、列が1~13に対応。0は利用しない
    let mut trp: Vec<Vec<u32>> = vec![vec![0; 14]; 4];

    for _ in 0..n {
        let mut buf = String::new();
        sin.read_line(&mut buf).ok();
        let mut ws = buf.split_whitespace();
        let s: char = ws.next().unwrap().chars().nth(0).unwrap();
        let d: usize = ws.next().unwrap().parse().unwrap();

        match s {
            'S' => trp[0][d] += 1,
            'H' => trp[1][d] += 1,
            'C' => trp[2][d] += 1,
            'D' => trp[3][d] += 1,
            _ => panic!("irregular suit"),
        };
    }

    for s in 0..4 {
        let suit = match s {
            0 => 'S',
            1 => 'H',
            2 => 'C',
            3 => 'D',
            _ => panic!("irregular suit"),
        };

        for d in 1..14 {
            if trp[s][d] == 0 {
                println!("{} {}", suit, d);
            }
        }
    }
}



Measured memory_bytes: 5036
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 200005;

int n;
char a[N];
int x;
map <int, int> m;

int main() {
  scanf(" %s", a);
  n = strlen(a);
  m[0] = 0;
  for (int i = 0; i < n; i++) {
    x ^= (1 << (a[i] - 'a'));
    int here = i + 1;
    if (m.count(x)) {
      here = min(here, m[x] + 1);
    }
    for (int j = 0; j < 26; j++) {
      if (m.count(x ^ (1 << j))) {
        here = min(here, m[x ^ (1 << j)] + 1);
      }
    }
    if (m.count(x)) {
      m[x] = min(m[x], here);
    } else {
      m[x] = here;
    }
    if (i == n - 1) {
      printf("%d\n", here);
    }
  }
  return 0;
}


Measured memory_bytes: 9856