akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int n;
vector <string> res;

void f(string s, int mx){
  if(int(s.size()) == n){
    res.push_back(s);
    return;
  }
  for(int i = 0; i <= mx + 1; i++){
    s += char('a' + i);
    f(s, max(mx, i));
    s.pop_back();
  }
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  cin >> n;
  string x;
  x += 'a';
  f(x, 0);
  for(auto& y : res){
    cout << y << "\n";
  }
}

Measured memory_bytes: 9332
import heapq
import sys
input = sys.stdin.readline

def dijkstra(s):
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * n # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, u in e[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(hq, (tmp, u))
    return cost

n=10
H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(n)]
A = [list(map(int,input().split())) for _ in range(H)]

e = [[] for _ in range(n)]

for i in range(n):
    for j in range(n):
        e[i].append((c[i][j], j))
        
mp = float('inf')
mplist = [mp]*n
for i in range(n):
    dist = dijkstra(i)
    mplist[i] = dist[1]

chgmp =0
for ih in range(H):
    for iw in range(W):
        if A[ih][iw]!=-1:
            chgmp += mplist[A[ih][iw]]
print(chgmp)


Measured memory_bytes: 9660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const int z = 1000000007;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {
    cout << fixed << setprecision(20);
    llong a, bb;
    double b;
    cin >> a >> b;
    bb = (b+0.005) * 100;
    llong ans = (a * bb) / 100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3764
n = int(input())
mod = 10**9+7
  
dp = [[0]*4 for i in range(n)]
for i in range(4):
  dp[0][i] = 1
  dp[1][i] = 4
  dp[2][i] = 16
  
dp[2][1] -= 2
dp[2][2] -= 1
  
for i in range(3,n):
  for j in range(4):
    dp[i][j] = sum(dp[i-1])%mod
  dp[i][1] -= dp[i-2][0] #AGC
  dp[i][1] -= dp[i-2][2] #GAC
  dp[i][1] -= dp[i-3][0]*3 #AGTC,AGGC,ATGC
  dp[i][2] -= dp[i-2][0] #ACG
  dp[i][2] += dp[i-3][2] #GACG
  
print(sum(dp[n-1])%mod)

Measured memory_bytes: 3188
n=int(input())
a=list(map(int,input().split()))
q=int(input())
dic={}
for i in range(len(a)):
    if a[i] in dic:
        dic[a[i]]+=1
    else:
        dic.setdefault(a[i],1)
answer=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in dic:
        dic.setdefault(b,0)
    elif c not in dic:
        dic.setdefault(c,dic[b])
    else:
        dic[c]+=dic[b]
    answer=answer+dic[b]*c-dic[b]*b
    dic[b] = 0
    print(answer)

Measured memory_bytes: 23876
#include<cstdio>

int main(void){
    int n, m;
    int i, j, k;
    int a[100][100];
    int b[100];
    int c[100];

    scanf("%d %d", &n, &m);

    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            int factor;
            scanf("%d", &factor);
            a[i][j] = factor;
        }
    }

    for(i = 0; i < m; i++){
        int factor;
        scanf("%d", &factor);
        b[i] = factor;
    }

    for(i = 0; i < n; i++) c[i] = 0;

    //??????
    for(i = 0; i < n; i++){
        for(k = 0; k < m; k++){
            c[i] += a[i][k] * b[k];
        }
    }

    for(i = 0; i < n; i++){
        printf("%d\n", c[i]);
    }

    return 0;
}

Measured memory_bytes: 1068
import qualified Data.List as L

main :: IO ()
main = do
    n <- readLn
    print $ solve n

solve :: Int -> Int
solve n = length $ filter isValid ds0 ++ ds1
  where
    ds0 = filter (>1) $ divisors n
    ds1 = filter (>1) $ divisors (n - 1)
    isValid d = simulate n d == 1

    simulate x k = case quotRem x k of
        (q, 0) -> simulate q k
        (q, r) -> r

primeFactors :: (Integral i) => i -> [i]
primeFactors n | n < 2 = []
primeFactors n = go n [2..1000000]
  where
    go n pps@(p:ps)
        | n < p * p = [n]
        | r > 0     = go n ps
        | otherwise = p : go q pps
      where
        (q, r) = quotRem n p
    go n [] = [n]
{-# SPECIALIZE primeFactors :: Int -> [Int] #-}

divisors :: Int -> [Int]
divisors n = L.sort . map product . mapM (scanl (*) 1) . L.group $ primeFactors n


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

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

int main(){
  int n;
  cin >> n;
  map<string,int> kiroku;

  int maxCount = 0;
  rep(i,n){
    string moji;
    cin >> moji;
    if ( kiroku.find(moji)==kiroku.end()){
      kiroku[moji]=1;
    }else{
      kiroku[moji]++;
    }
    if(kiroku[moji]>maxCount)maxCount=kiroku[moji];
  }

  for (auto i=kiroku.begin(); i!=kiroku.end(); i++){
    if(i->second == maxCount){
      cout << i-> first << endl;
    }
  }

}

Measured memory_bytes: 25216
#include <iostream>
#include <utility>
#include <set>

using namespace std;

int main() {
	int n;
	cin >> n;
	int sum = ((n + 1) * n) / 2;
	set<pair<int,int>> path;
	if(n % 2 == 0) for(int i = 1;i <= n/2;i++) path.insert(make_pair(i,sum/(n/2)-i));
	else for(int i = 1;i <= n/2;i++) path.insert(make_pair(i,sum/((n/2)+1)-i));
	cout << ((n-1)*n/2)-path.size() << endl;
	for(int i = 1;i <= n;i++) for(int j = 1;j < i;j++) if(path.find(make_pair(j,i)) == path.end()) cout << j << " " << i << endl;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	int ans = 0;
	for(int i = 0; i < 4; i++)
	{
		if(s[i] == '+')
		{
			ans++;
		}
		else
		{
			ans--;
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

const int N = 310;

typedef pair<int, int> P;
typedef long long LL;

int G[2][N * 2][N * 2], n;

vector<P> dir;

void dfs(int x, int y, int t) {
    for (auto v : dir) {
        int tx = x + v.first, ty = y + v.second;
        if (tx > n * 2 || ty > n * 2 || tx < 1 || ty < 1 || G[t][tx][ty]) continue;
        G[t][tx][ty] = 3 - G[t][x][y], dfs(tx, ty, t);
    }
}

void Just_DOIT(int t, int d) {
    dir.clear();
    for (int i = 0; i < 2 * n; i++)
        for (int j = 0; j < 2 * n; j++)
            if ((LL)i * i + (LL)j * j == d) 
                for (int t = 0; t < 4; t++) 
                    dir.push_back(P(t & 1 ? i : -i, t & 2 ? j : -j));
    for (int i = 1; i <= n * 2; i++)
        for (int j = 1; j <= n * 2; j++) if (!G[t][i][j]) 
            G[t][i][j] = 1, dfs(i, j, t);
}

vector<P> fuck[4];

int main() {
    int d1, d2; scanf("%d%d%d", &n, &d1, &d2);
    Just_DOIT(0, d1), Just_DOIT(1, d2);
    for (int i = 1; i <= n * 2; i++)
        for (int j = 1; j <= n * 2; j++)
            fuck[G[0][i][j] + G[1][i][j] * 2 - 3].push_back(P(i, j));
    for (int i = 0; i < 4; i++) if (fuck[i].size() >= n * n) {
        for (int j = 0; j < n * n; j++) printf("%d %d\n", fuck[i][j].first - 1, fuck[i][j].second - 1);
        return 0;
    }
}//

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

int main() {
	string s;
	cin >> s;
	int L = s.size();
	vector<int> r(L, -1), l(L, -1), ans(L, 0);
	for (int i = 1; i < L; i++) {
		if (s[i] == 'L') {
			if (l[i - 1] == -1) {
				l[i] = i;
			}
			else {
				l[i] = l[i - 1];
			}
		}
	}
	for (int i = L - 1; i >= 0; i--) {
		if (s[i] == 'R') {
			if (r[i + 1] == -1) {
				r[i] = i;
			}
			else {
				r[i] = r[i + 1];
			}
		}
	}

	for (int i = 0; i < L; i++) {
		if (s[i] == 'L') {
			if (l[i] == i) {
				ans[i]++;
			}
			else {
				if ((i - l[i]) % 2 == 0) {
					ans[l[i]]++;
				}
				else {
					ans[l[i] - 1]++;
				}
			}
		}
	}
	for (int i = L - 1; i >= 0; i--) {
		if (s[i] == 'R') {
			if (r[i] == i) {
				ans[i]++;
			}
			else {
				if ((r[i] - i) % 2 == 0) {
					ans[r[i]]++;
				}
				else {
					ans[r[i] + 1]++;
				}
			}
		}
	}

	rep(i, L) cout << ans[i] << " ";
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.lang.StringBuilder;

public class Main {
  public static void main(String[] args ){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] a = new int[N];
    long amount = 0;
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }

    for(int i = 0; i < N; i++) {
      amount += a[i] - 1;
    }
    System.out.println(amount);

  }
}


Measured memory_bytes: 26472
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (a, b) = readInts()
    
    println(when {
        0 < a -> "Positive"
        0 <= b -> "Zero"
        else -> if ((Math.abs(a) + Math.abs(b)) % 2 == 0) "Negative" else "Positive"
    })
}

Measured memory_bytes: 36100
import java.util.*;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int array [] = new int [3];
    for(int i = 0; i<3; i++) {
    	array[i] = sc.nextInt();
    }
    Arrays.sort(array);
    System.out.println(array[2]*10+array[1]+array[0]);
  }
 
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 2e5 + 7;
int n, a[N], p[N];
ll k;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = -1;
  }
  int i = 1, cur = 0;
  while (p[i] == -1) {
    p[i] = cur;
    cur++;
    i = a[i];
  }
  if (k < cur) {
    for (int i = 1; i <= n; i++) {
      if (p[i] == k) {
        cout << i << "\n";
        return 0;
      }
    }
    cout << "why are you here?\n";
    return 0;
  }
  int go = p[i];
  k -= go;
  k %= (cur - go);
  for (int i = 1; i <= n; i++) {
    if (p[i] == k + go) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << "why are you here 2?\n";
  return 0;
}


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

using namespace std;
typedef long long ll;
ll sum(ll n,ll b)
{
	ll ans=0;
	while(n)
	{
		ans+=n%b;
		n/=b;
	}
	return ans;
}
int main()
{
	
	ll n,s;
	scanf("%lld%lld",&n,&s);
	if(n==s)
		printf("%lld\n",n+1);
	else
	{
		for(ll i=2;i<=sqrt(n)+1;i++)
		{
			ll b=i;
			if(sum(n,b)==s)
			{
				printf("%lld\n",b);
				return 0;
			}
		}
		if(n-s>1)
		{
			for(ll i=sqrt(n);i;i--)
			{
				ll b=(n-s)/i+1;
				if(sum(n,b)==s)
				{
					printf("%lld\n",b);
					return 0;
				}
			}
		}
		puts("-1");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
#define endl "\n"
#define MAX 1000000
int main(){
    lli n;
    cin>>n;
    lli ans = (n+2)*(n+1)*(n)/6;
    /*lli check = 0;
    for(int i = 1; i<=10; i++){
        check += i*(i+1)/2;
    }
    cout<<check<<endl;*/
   
    for(int i = 0; i<n-1; i++){
        lli a,b;
        cin>>a>>b;
        lli minm;
        minm = min(a,b);
        b = max(a,b);
        a = minm;
    
        ans -= (n-b+1)*(a);
    }
    cout<<ans<<endl;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    vector<int> tp[2];

    UnionFind(int n, int xsz){
        par.resize(n);
        sz.resize(n);
        tp[0].resize(n);
        tp[1].resize(n);
        int half = n/2;
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
            tp[i>=xsz][i]++;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        tp[0][y] += tp[0][x];
        tp[1][y] += tp[1][x];
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int N, X[100000], Y[100000];
    cin >> N;
    set<int> xst, yst;
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
        xst.insert(X[i]);
        yst.insert(Y[i]);
    }
    map<int, int> xmp, ymp;
    int xsz = 0, ysz = 0;
    for(int x : xst) xmp[x] = xsz++;
    for(int y : yst) ymp[y] = ysz++;

    UnionFind uf(xsz+ysz, xsz);
    for(int i=0; i<N; i++){
        int x = xmp[X[i]];
        int y = ymp[Y[i]];
        uf.unite(x, xsz + y);
    }

    int64_t sum = 0;
    for(int i=0; i<xsz+ysz; i++){
        if(uf.find(i) == i){
            sum += (int64_t) uf.tp[0][i] * uf.tp[1][i];
        }
    }

    int64_t ans = sum - N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B;
  C = A * B % 2;
    
  if (C == 0){
    cout << "Even" << endl;
  }
    else
     { cout << "Odd" << endl;
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {string here,ans;while (getline(cin,here)) for (int i=0;i<26;i++) {ans=here;for (int j=0;j<ans.size();j++) if (ans[j]>='a' && ans[j]<='z') ans[j]=(ans[j]-'a'+i)%26+'a';if (ans.find("that",0) != string::npos || ans.find("this",0) != string::npos || ans.find("the",0) != string::npos) {cout<<ans<<endl;break;}} return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl
int n, i, in; bool pos = true;
map < int, int > mp;
int main ()
{
   cin >> n;
   for(i = 1; i <= n; i++)
   {
     cin >> in;
     mp[in]++;
     if(mp[in] > 1) pos = false;
   }
   cout << ((pos) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
N = int(input())
S = input()

def z_algorithm_no_overlap(S_):
    N_ = len(S_)
    Z_ = [0] * N_
    L_ = R_ = 0
    for i in range(1, N_):
        if i > R_:
            L_ = R_ = i
            while R_ < N_ and S_[R_-L_] == S_[R_]:
                R_ += 1
            Z_[i] = R_ - L_
            R_ -= 1
        else:
            k = i - L_
            if Z_[k] < R_ - i + 1:
                Z_[i] = Z_[k]
            else:
                L_ = i
                while R_ < N_ and S_[R_-L_] == S_[R_]:
                    R_ += 1
                Z_[i] = R_ - L_
                R_ -= 1
    for i, z in enumerate(Z_):
        if z > i:
            Z_[i] = i
    return Z_
        
# print(max(max(z_algorithm_no_overlap(S[i:])) for i in range(N-1)))
ans = 0
for i in range(N-1):
    m = max(z_algorithm_no_overlap(S[i:]))
    ans = max(ans, m)
    if ans >= (N - i) // 2:
        break
print(ans)

Measured memory_bytes: 49116
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N + 1);
	for (auto &i : v)cin >> i;
	vector<long long int>w(N);
	for (auto &i : w)cin >> i;
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += min(v[i], w[i]);
		w[i] -= min(w[i], v[i]);
		int add = min(v[i + 1], w[i]);
		ans += add;
		v[i + 1] -= add;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>

// 入力
int K, S;

int main() {
  scanf("%d %d", &K, &S);

  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, M; std::cin >> N >> M;
  std::map<int, int> mp;
  std::set<int> indices;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    ++mp[a];
    indices.insert(a);
  }

  for (int m = 0; m < M; ++m) {
    int B, C; std::cin >> B >> C;
    mp[C] += B;
    indices.insert(C);
  }

  LL sum = 0;
  int count = 0;
  for (auto it = indices.rbegin(); it != indices.rend(); ++it) {
    LL index = *it;
    LL cnt = mp[index];
    if (count + cnt < N) {
      count += cnt;
      sum += index*cnt;
    } else {
      sum += index*(N - count);
      break;
    }
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 18944
num,alice,bob = gets.to_i,0,0
ary = gets.split(" ").map(&:to_i).sort {|a, b| b <=> a }
cnt = 0
ary.size.times do
    if cnt % 2 == 0
        alice += ary[cnt]
    else
        bob += ary[cnt]
    end
    cnt += 1
end
puts alice - bob

Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll int
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll a,b,c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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


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

	int a,b;

	cin >> a >> b;

	if(b%a==0)
	{
		cout << a+b << '\n';
	}
	else
	{
		cout << b-a << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

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

int main(){
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> alphabets(26);
    rep(i, n) alphabets[s[i] - 'a'].insert(i);
    rep(j, q){
        int type; cin >> type;
        if (type == 1){
            int i; cin >> i; i--;
            char c; cin >> c;
            alphabets[s[i] - 'a'].erase(i);
            s[i] = c;
            alphabets[c - 'a'].insert(i);
        }else{
            int l, r; cin >> l >> r; l--; r--;
            int cnt = 0;
            rep(i, 26){
                auto itr = alphabets[i].lower_bound(l);
                if (itr != alphabets[i].end() and *itr <= r) cnt++;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 24196
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int h,w,n,b;
    cin>>h>>w>>n;
    if(h>w)
        b=h;
    else
        b=w;
    if(n%b==0)
        cout<<(n/b)<<endl;
    else
        cout<<(n/b)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto mtpr = readInts();
		auto m = mtpr[0];
		auto t = mtpr[1];
		auto p = mtpr[2];
		auto r = mtpr[3];
		if((m|t|p|r) == 0) return;

		auto cp = new int[](t);
		auto pe = new int[](t);
		auto w = new int[][](t,p);
		for(int i; i < r; ++i) {
			auto mtpj = readInts();
			auto mi = mtpj[0];
			auto ti = mtpj[1]-1;
			auto pi = mtpj[2]-1;
			auto ji = mtpj[3];
			if(ji == 0) {
				++cp[ti];
				pe[ti] += mi + w[ti][pi] * 20;
			} else {
				++w[ti][pi];
			}
		}
		auto te = iota(1, t+1).array;
		bool win(Tuple!(int, int, int) a, Tuple!(int, int, int) b) {
			return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);
		}
		zip(cp, pe, te).sort!((a, b) => win(a,b) || (!win(a,b) && !win(b, a) && a[2] > b[2]));
		write(te[0]);
		for(int i = 1; i < t; ++i) {
			if(win(tuple(cp[i-1], pe[i-1], 0), tuple(cp[i], pe[i], 0))) {
				write(",");
			} else {
				write("=");
			}
			write(te[i]);
		}
		writeln();
	}
}

Measured memory_bytes: 3276
from collections import deque
N, M = map(int, input().split())
path = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    path[a-1].append(b)
    path[b-1].append(a)

table = [-1]*N
queue = deque([1])
table[0] = 0
count = 0
while queue:
    n = queue.popleft()
    for c in path[n-1]:
        if table[c-1] == -1:
            table[c-1] = n
            queue.append(c)
            count += 1
        
if count < N - 1:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(table[i])

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

int main(){
  int H,W;
  cin >> H >> W;
  for (int i=0;i<W+2;i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0;i<H;i++){
    cout << "#";
    vector<char> A(W);
    for(int j=0;j<W;j++){
      cin >> A.at(j);
      cout << A.at(j);
    }
    cout << "#" << endl;
  }
  for (int i=0;i<W+2;i++){
    cout << "#";
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, k;
vector<int> a, b;

bool f(int m){
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int target = m / b[i];
        if(a[i] > target) cnt += a[i] - target;
    }
    return cnt <= k;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    b.resize(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    int ok = 1e12, ng = -1;
    while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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


int main(void){
    string s;
    cin >> s;
    vector<int> a(26);
    for(int i = 0;i < s.size();i++){
        a[s[i] - 'a']++;
    }
    for(int i = 0;i < 26;i++){
        if(a[i] > 1){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
     
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    int sum = 0, mx = 0;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        mx = max(mx, a);
        sum += a;
    }
    sum -= mx;
    if( sum > mx ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, B) = Slice2<int>();
            WriteLine(Max(Max(A + B, A - B), A * B));
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27580
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> P;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    string S;
    cin >> S;
    set<char> T;
    for (int i = 0; i < S.size(); i++) {
        if (T.count(S.at(i))) {
            cout << "no" << endl;
            return 0;
        }
        T.insert(S.at(i));
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		long xi = sc.nextLong();
		long x;
		for(int i=0; i<10; i++){
			x=r*xi-d;
			System.out.println(x);
			xi = x;
		}
	}

}


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

long long gcd(long long number1, long long number2)
{
    //最大公約数
    long long m = number1;
    long long n = number2;

    if (number2 > number1)
    {
        m = number2;
        n = number1;
    }
    long long r = n % m;
    while (r != 0)
    {
        n = m;
        m = r;
        r = n % m;
    }

    return m;
}

template <typename T>
vector<T> Divisors(T n)
{
    vector<T> result;

    T boundary = sqrt(n);

    for (T i = 1; i <= boundary; i++)
    {
        if (n % i == 0)
        {
            result.push_back(i);
            if (i != (n / i) && i * i != n)
                result.push_back(n / i);
        }
    }
    sort(result.begin(), result.end());
    return result;
}

bool IsPrime(long num)
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main()
{
    long A, B;
    cin >> A >> B;
    int ans = 1;
    long num = gcd(A, B);
    auto v = Divisors<long>(num);
    rep(i, v.size())
    {
        if (IsPrime(v[i]))
            ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import numpy as np
N, M, X = (int(i) for i in input().split())  
arr = []
c_list = []
for _ in range(N):
  A = [int(i) for i in input().split()] 
  c_list.append(A[0])
  arr.append(A[1:])

comb_list = []
def recur(N, lis):
  comb_list.append(lis)
  if len(lis) == N:
    return
  
  for i in range(lis[-1]+1, N):
    recur(N, lis + [i])  

for i in range(N):
  recur(N, [i])

ans = np.inf
for Z in comb_list:
  tmp = np.zeros(M)
  tmp_c = 0
  for z in Z:
    tmp += arr[z]
    tmp_c += c_list[z]
  if np.all(tmp >= X):
    ans = min(ans, tmp_c)

if ans == np.inf:
  print('-1')
else:
  print(ans)

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

int main(){
  
  int A,B; cin >> A >> B;
  
  if((A*B)%2 == 1){
     cout << "Yes" << endl;
  }
  
  else if((A*B)%2 == 0){
    cout << "No" << endl;
  }
}
  
  
     
     

  

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

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> d(N);
  int ans = 0;
  for(int i=0; i<N; i++){
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  for(int i=d[(N/2)-1]+1; i <= d[N/2]; i++){
    ans++;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
    };

    let m = 1000000007;

    let mut dp: Vec<usize>;
    let mut pre: Vec<usize> = vec![0; 13];
    pre[0] = 1;

    for c in s {
        dp = vec![0; 13];

        let range = match c {
            '?' => 0..10,
            x => {
                let d = x.to_digit(10).unwrap() as usize;
                d..d+1
            }
        };

        for i in 0..13 {
            for j in range.clone() {
                let to = (10 * i + j) % 13;
                dp[to] += pre[i];
                dp[to] %= m;
            }
        }
        pre = dp;
    }
    println!("{}", pre[5]);
}

Measured memory_bytes: 4352
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


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


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    ans=0
    for i in range(1,n+1):
        if i%3==0:
            pass
        elif i%5==0:
            pass
        else:
            ans+=i
    print(ans)
if __name__ == '__main__':
    main()

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

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

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb push_back
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", " ;
	return out << "}" << endl;
}
template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

int n,m,w=-1;
vector<vi> v(4);

ll dfs(int i, int m){
	if(i<3){
		ll t=0, res=dfs(i+1, m);
		rep(j, v[i].size()){
			t+=v[i][j];
			if((w+i)*(j+1) > m) break;
			res = max(res, t + dfs(i+1, m - (j+1) * (w+i)));
		}
		return res;
	}else{
		int n = min((int)v[3].size(), m / (w+3));
		ll t = 0;
		rep(j,n) t += v[3][j];
		return t;
	}
}
int main(){
	cin >> n >> m;
	rep(i,n){
		int s,t;
		cin >> s >> t;
		if(w<0) w = s;
		v[s-w].pb(t);
	}
	rep(i,4){
		sort(v[i].rbegin(), v[i].rend());
	}
	cout << dfs(0, m) << endl;

	return 0;
}


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

using namespace std;

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

string solve() {
    ll n; cin >> n;
    string s = "";
    while (n > 0) {
        n -= 1;
        s += n % 26 + 'a';
        n /= 26;
    };
    reverse(s.begin(), s.end());

    return s;
}

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

    cout << solve() << endl;
}


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

int main (){
    ll k,x;
    cin>>k>>x;
    ll c=1000000,l=max(-c,x-k+1),r=min(c,x+k-1);
    for(ll i=l;i<=r;i++)    cout<<i<<" ";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;
 
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.first< right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.second < right.second;
}
 
lli f[1000000], rf[1000000];
lli inv(lli x) {
    lli res = 1;
    lli k = MOD - 2;
    lli y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    rep1(i, 1000000) f[i] = (f[i - 1] * i) % MOD;
    rep0(i, 1000001) rf[i] = inv(f[i]);
}
lli C(lli n, lli k) {
    lli a = f[n];
    lli b = rf[n-k];
    lli c = rf[k];
 
    lli bc = (b * c) % MOD;
 
    return (a * bc) % MOD;
}
 
void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}
 
lli gcd(lli a, lli b){
    if(a < b)return gcd(b, a);
    lli temp;
    while((temp = a%b)){
        a=b;
        b=temp;
    }
    return b;
}

struct nCr{
  vector<lli> f, rf;
  lli count=0;
  nCr(lli num): f(num), rf(num){
      count = num;
      f[0] = 1;
      rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
      rep0(i, num+1) rf[i] = inv(f[i]);
  }
    
  lli inv(lli x) {
      lli res = 1;
      lli k = MOD - 2;
      lli y = x;
      while (k) {
          if (k & 1) res = (res * y) % MOD;
          y = (y * y) % MOD;
          k /= 2;
      }
      return res;
  }
  lli C(lli n, lli k) {
      lli a = f[n];
      lli b = rf[n-k];
      lli c = rf[k];
   
      lli bc = (b * c) % MOD;
   
      return (a * bc) % MOD;
  }
};

struct UF{
    vector<int> par,size;

    UF(int N) : par(N), size(N, 1){
        rep0(i,N)par[i] = i;
    }

    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        size[rx] += size[ry];
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getSize(int x){
        return size[x];
    }
};
int main(){
  lli n, a, b;
  cin >> n >> a >>b;
  cout << n/(a+b)*a+(n%(a+b)>a?a:n%(a+b));
}


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

int main() {
  int A,B;
  cin >>A >>B;
  if(A>8){
    cout <<":(" <<endl;
    return 0;
  }
  if(B>8){
    cout <<":(" <<endl;
    return 0;
  }
  cout <<"Yay!" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long li;

const int maxn = 1e5;

int main(void) {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  if (n == 1) {
    if (a != b) puts("0");
    else puts("1");
    return 0;
  }
  if (a > b) {
    puts("0");
    return 0;
  }
  li ans = (a + (li)(n - 1) * b) - (b + (li)(n - 1) * a) + 1;
  printf("%lld\n", ans);
}


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

using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

ll h[50];
ll p[50];

ll calc(ll n, ll x){
  if (n==0){
    if (x <= 0) return 0;
    else return 1;
  }
  if (x == 1) return 0;
  if (1 < x && x <= h[n-1]+1) return calc(n-1, x-1);
  if (x == h[n-1]+2) return p[n-1] + 1;
  if (h[n-1]+2 < x && x <= 2*h[n-1]+2) return p[n-1] + 1 + calc(n-1, x-h[n-1]-2);
  if (x == 2*h[n-1]+3) return 2*p[n-1] + 1;
  //if (n==0){
  //  if (x <= 0) return 0;
  //  else return 1;
  //}
  //else if (x <= h[n-1]+1) return calc(n-1, x-1);
  //else return p[n-1] + 1 + calc(n-1, x-h[n-1]-2);
}

int main() {
  ll n, x;
  cin >> n >> x;
  h[0] = 1;
  p[0] = 1;
  for(int i=1;i<=50;i++){
    h[i] = 2*h[i-1] + 3;
    p[i] = 2*p[i-1] + 1;
  }
  
  ll ans = calc(n,x);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c,n,r,sum,list[300],result[1000][3],w,x,y,z,i;
	scanf("%d%d%d",&a,&b,&c);
	while(a!=0 && b!=0 && c!=0){
		scanf("%d",&n);
		sum=a+b+c;
		for(i=0; i<sum; i++){
			list[i]=2;
		}
		r=0;
		for(i=0; i<n; i++){
			scanf("%d%d%d%d",&x,&y,&z,&w);
			if(w==1){
				list[x-1]=1;
				list[y-1]=1;
				list[z-1]=1;
			}else{
				result[r][0]=x-1;
				result[r][1]=y-1;
				result[r][2]=z-1;
				r++;
			}
		}
		for(i=0; i<r; i++){
			x=result[i][0];
			y=result[i][1];
			z=result[i][2];
			if(list[x]==1 && list[y]==1){
				list[z]=0;
			}else if(list[y]==1 && list[z]==1){
				list[x]=0;
			}else if(list[z]==1 && list[x]==1){
				list[y]=0;
			}
		}
		for(i=0; i<sum; i++){
			printf("%d\n",list[i]);
		}
		scanf("%d%d%d",&a,&b,&c);
	}
	return 0;
}

Measured memory_bytes: 612
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int total = scan.nextInt();

        HashMap<String, Choice> map = new HashMap<>();
        ABC a = new ABC(scan.nextInt(), "A");
        ABC b = new ABC(scan.nextInt(), "B");
        ABC c = new ABC(scan.nextInt(), "C");
        map.put("AB", new Choice("AB", new ABC[]{a, b, c}));
        map.put("BC", new Choice("BC", new ABC[]{b, c, a}));
        map.put("AC", new Choice("AC", new ABC[]{a, c, b}));

        scan.nextLine();
        String[] inputs = new String[total];
        for (int i = 0; i < total; i++) {
            inputs[i] = scan.nextLine();
        }

        StringBuffer outPut=new StringBuffer();
        boolean ok=true;
        for (int i = 0; i < total; i++) {
            Choice choice = map.get(inputs[i]);
            String out;
            if (i < total - 1) {
                out = choice.autoChoose(map.get(inputs[i + 1]));
            } else {
                out = choice.autoChoose(null);
            }
            if (out == null) {
                ok=false;
                break;
            }
            outPut.append(out).append(System.getProperty("line.separator"));
        }
        if(ok){
            System.out.println("Yes");
            System.out.print(outPut);
        }else {
            System.out.println("No");
        }
    }
}

class ABC {
    int num;
    String id;

    public ABC(int num, String id) {
        this.num = num;
        this.id = id;
    }

    public boolean lessThen(ABC one) {
        return this.num < one.num;
    }
}

class Choice {
    public Choice(String type, ABC[] abc) {
        this.type = type;
        this.abc = abc;
    }

    String type;
    ABC[] abc;

    public String choose(int choice) {
        abc[choice].num++;
        abc[1 - choice].num--;
        return String.valueOf(type.charAt(choice));
    }

    public String autoChoose(Choice next) {
        int chooseNum;
        if (abc[0].num == 1 && abc[1].num == 1 && abc[2].num == 0) {
            if (next == null) {
                chooseNum = 0;
            } else {
                if (abc[0] == next.abc[0] || abc[0] == next.abc[1]) {
                    chooseNum = 0;
                } else {
                    chooseNum = 1;
                }
            }
        } else {
            if (abc[0].lessThen(abc[1])) {
                chooseNum = 0;
            } else {
                chooseNum = 1;
            }
        }
        String ret = choose(chooseNum);
        if (abc[0].num < 0 || abc[1].num < 0 || abc[2].num < 0) {
            ret = null;
        }
        return ret;
    }
}


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

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

  int road[6];
  for(int i = 0; i < 6; i++) {
    cin >> road[i];
  }

  int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
  for(int i = 0; i < 6; i++) {
    switch (road[i]) {
      case 1:
        count1 += 1;
        break;
      case 2:
        count2 += 1;
        break;
      case 3:
        count3 += 1;
        break;
      case 4:
        count4 += 1;
        break;
      default:
        break;
    }
  }
  if(count1 > 2 || count2 > 2 || count3 > 2 || count4 > 2) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100000

typedef struct node{
 int id;
 int childnum;
 int parentid;
 int depth;
 char type[20];
 int start;
 int last;
}node;

void depthcheck(int x,node N[],int A[]){
int i;
if(N[x].start!=-1){
for(i=N[x].start;i<=N[x].last;i++){
 N[A[i]].depth=N[x].depth+1;
 depthcheck(A[i],N,A);
}
}


return;
}


int main(){
int n,i,j;
node N[MAX];
int A[MAX];
int right=0;
int x,y,z;

scanf("%d",&n);


/*-------------ノードの初期化-------------*/
for(i=0;i<n;i++){
N[i].id=i;
N[i].depth=0;
N[i].childnum=0;
N[i].parentid=-1;
N[i].start=-1;
N[i].last=-1;
A[i]=-1;
}
/*--------------------------------------*/




for(i=0;i<n;i++){

 scanf("%d %d",&x,&y);
 N[x].childnum=y;
 
 if(y==0){strncpy(N[x].type,"leaf",4);N[x].type[4]='\0';}
 else{/*子供あり*/

  N[x].start=right;
  for(j=0;j<y;j++){
      scanf("%d",&z);
      N[z].parentid=x;
      A[right]=z;
      right++;
  }
  N[x].last=right-1;

 }
}/*for end*/


for(i=0;i<n;i++)if(N[i].parentid==-1)break;

depthcheck(i,N,A);


for(i=0;i<n;i++){
 printf("node %d: ",i);
 printf("parent = %d, ",N[i].parentid);
 printf("depth = %d, ",N[i].depth);

 if(N[i].parentid==-1){strncpy(N[i].type,"root",4);N[i].type[4]='\0';}
 else if(N[i].parentid!=-1 && N[i].type[0]!='l'){strncpy(N[i].type,"internal node",13);N[i].type[13]='\0';}
 
 printf("%s, ",N[i].type);
 
 if(N[i].childnum==0)printf("[]\n");
 else if(N[i].childnum==1)printf("[%d]\n",A[N[i].start]);
 else{
  printf("[");
  for(j=N[i].start;j<N[i].last;j++)printf("%d, ",A[j]);
  printf("%d]\n",A[N[i].last]);
 }

}


return 0;
}


Measured memory_bytes: 6396