akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("-O3")

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define vll vector<ll> 
#define vs vector<string>
#define vc vector<char>
#define vpll vector<pair<ll,ll>>
#define tc ll t=0;cin>>t;while(t--)
#define pb push_back
#define pop pop_back
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define maxe *max_element
#define mine *min_element
#define f first
#define s second
#define vli vll::iterator 
#define mp make_pair
#define unmap unordered_map
#define unmapll unordered_map<ll,llt>
#define max_val 99999999
#define min_val -99999999
#define mod 1000000007
const ld PI = 3.141592653589793;

bool isPowerOfTwo (int x) 
{ 
  return x && (!(x&(x-1))); 
} 


int main()
{
    IOS
    #ifdef LOCAL
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\input.txt","r",stdin);
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\output.txt","w",stdout);
        #endif
    
	ll s,w;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe";	    
    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var nk = Reads();
            var n = nk[0];
            var k = nk[1];
            Console.WriteLine(Math.Min(n - n / k * k, (n / k + 1) * k - n));
              
            
           
           
            



            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13268
n=int(input())
v=list(map(int,input().split()))
odd=[[0,0] for i in range(10**5+1)]
even=[[0,0] for i in range(10**5+1)]
for i in range(1,10**5+1):
    odd[i][1]=i
    even[i][1]=i
for i in range(n):
    if (i+1)%2==1:
        odd[v[i]][0]+=1
    else:
        even[v[i]][0]+=1
odd=sorted(odd,reverse=True)
even=sorted(even,reverse=True)
ans=0
if(odd[0][0]+even[0][0]==n): #odd[0][0]=n//2
    if(odd[0][1]==even[0][1]):
        ans=n//2
    else:
        ans=0

else:
    # odd 19,1 even 20,19のときに、(1+20)=21よりも(19+19)=38のほうがいいい。
    if(odd[0][1]==even[0][1]):
        if(odd[0][0]+even[1][0]<=odd[1][0]+even[0][0]):
            ans=(n//2-odd[1][0])+(n//2-even[0][0])
        else:
            ans=(n//2-odd[0][0])+(n//2-even[1][0])

    else:
        ans=(n//2-odd[0][0])+(n//2-even[0][0])
print(ans)


Measured memory_bytes: 75140
using System;
using System.Collections.Generic;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NM = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            List<Tuple<long, long, long>> xyz = Enumerable.Range(0, NM[0]).Select(i => {
                long[] tmp = Console.ReadLine().Split().Select(j => Convert.ToInt64(j)).ToArray();
                return new Tuple<long, long, long>(tmp[0], tmp[1], tmp[2]);
                }).ToList();
            long ans = 0;
            for (var flag = 0; flag < 8; flag++)
            {
                List<long> data = new List<long>();
                for (var i = 0; i < NM[0]; i++)
                {
                    long score = 0;
                    if ((1 & flag >> 0) == 1) score += xyz[i].Item1;
                    else score -= xyz[i].Item1;
                    if ((1 & flag >> 1) == 1) score += xyz[i].Item2;
                    else score -= xyz[i].Item2;
                    if ((1 & flag >> 2) == 1) score += xyz[i].Item3;
                    else score -= xyz[i].Item3;
                    data.Add(score);
                }
                ans = Math.Max(ans, data.OrderByDescending(i => i).Take(NM[1]).Sum());
            }
            Console.WriteLine(ans);
        }
    }
}


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



int main() {
	int n;
	cin >> n;
	vector<ll> a(n + 2);
	ll ans = 0;
	rep(i, n) cin >> a[i + 1];
	a[0] = 0;
	a[n + 1] = 0;
	rep(i, n+1) {
		ans += abs(a[i + 1] - a[i]);
	}
	rep(i, n) {
		ll ansi = ans;
		ansi -= (abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i + 1]));
		ansi += abs(a[i + 2] - a[i]);
		cout << ansi << endl;
	}
}

Measured memory_bytes: 2048
n,q = map(int,input().split())
commands = [0]*q
args = [[0,0] for _ in range(q)]
for i in range(q):
    tmp = list(map(int,input().split()))
    commands[i] = tmp[0]
    args[i] = tmp[1:3]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i in range(self.n) if self.parents[i] < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())

tree = UnionFind(n)

for i in range(q):
    if commands[i] == 0:
        tree.union(args[i][0],args[i][1])
    else:
        if tree.same(args[i][0],args[i][1]):
            print(1)
        else:
            print(0)





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

const int M = 505;
int n;
int a[M][M], b[M][M];
int dx[] = { 1, -1, 0,  0 };
int dy[] = { 0,  0, 1, -1 };

void upd(int x, int y, int na) {
    if (na + b[x][y] < a[x][y]) {
        a[x][y] = na + b[x][y];
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
            upd(nx, ny, a[x][y]);
        }
    }
}

int main () {
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                a[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j)) + 1,
                b[i][j] = 1;

        int res = 0;
        for (int i = 0; i < n * n; i++) {
            int x;
            scanf("%d", &x); 
            x--;
            int r = x / n, c = x % n;
            res += a[r][c] - 1;
            b[r][c] = 0;

            int minNeigh = 1e9;
            for (int d = 0; d < 4; d++) {
                int nx = r + dx[d], ny = c + dy[d];
                minNeigh = min(minNeigh, nx < 0 || ny < 0 || nx >= n || ny >= n ? 0 : a[nx][ny]);
            }
            upd(r, c, minNeigh);
        }
        printf("%d\n", res);
    }
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if(A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
s=[]
for i in range(m):
    s.append(input().split())
    s[i][0]=int(s[i][0])
cnt=[0]*n
cnt1=[0]*n
#print(s)
for i in range(m):
    if s[i][1]=='WA':
        if cnt[s[i][0]-1]!=0:
            continue
        else:
            cnt1[s[i][0]-1]+=1
    if s[i][1]=='AC':
        if cnt[s[i][0]-1]!=0:
            continue
        else:
            cnt[s[i][0]-1]+=1
    #print(cnt)
    #print(cnt1)
ans=0
ans1=0
#print(cnt,cnt1)
for i in range(n):
    if cnt[i]==0:
        continue
    else:
        ans+=cnt[i]
        ans1+=cnt1[i]
print(ans,ans1)

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<String> ans = new ArrayList<String>();
		
		int sum = 0;
		
		while (true) {
			
			String s = br.readLine();
			if (s == null) break;
			
			int d = Integer.parseInt(s);
			int temp = d;
			for (; d <= 600 - temp; d += temp) {
				sum += d * d * temp;
			}
			ans.add(String.valueOf(sum));
			sum = 0;
		}
		
		for (String a : ans)
			System.out.println(a);
		
	}
	
}

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

const int MOD = 998244353, MAXN = 300 * 1000 + 100;
int n, a, b, tav2[MAXN], fact[MAXN], inv[MAXN];
ll k;

int efraz(int a, ll b);
int RGB_Coloring();
void PreWorks();
int power(int a, int b);
int chose(int k, int n);

int main() {
	PreWorks();
	cin >> n >> a >> b >> k;
	cout << RGB_Coloring();
}

int power(int a, int b) {
	if (!b)
		return 1;
	int t = power(a, b / 2);
	return b % 2? (ll)t * t % MOD * a % MOD: (ll)t * t % MOD;
} 

void PreWorks() {
	fact[0] = 1;
	inv[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = (ll)fact[i - 1] * i % MOD;
		inv[i] = power(fact[i], MOD - 2);
	}
}

int efraz(int a, ll k) {
	if (k < 0)
		return 0;
	if (k % a)
		return 0;
	ll p = k / a;
	if (p > n)
		return 0;
	return (ll)chose(p, n);
}

int RGB_Coloring() {
	int ans = 0;
	for(int i = 0; i <= n; i++) {
		ll p = k - (ll)i * a;
//		cerr << b << ' ' << p << ' ' << efraz(b, p) << endl;
		ans += (ll)efraz(b, p) * chose(i, n) % MOD;
		ans %= MOD;
	}
	return ans;
}

int chose(int k, int n) {
	return (ll)fact[n] * inv[n - k] % MOD * inv[k] % MOD;
}


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

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

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

  string n;
  cin >> n;
  if (n.at(0) == n.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]

TF = [[False]*3 for i in range(3)]

N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == b:
        TF[j][k] = True

for i in range(3):
  res = True
  for j in range(3):
    res *= TF[i][j]
  if res:
    print('Yes')
    quit()

for i in range(3):
  res = True
  for j in range(3):
    res *= TF[j][i]
  if res:
    print('Yes')
    quit()

res = True
for i in range(3):
  res *= TF[i][i]
if res:
  print('Yes')
  quit()

res = TF[2][0] * TF[1][1] * TF[0][2]
if res:
  print('Yes')
  quit()

print('No')

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

int main(void){
		
	string s;
  	int N,l;
  	cin >> N;
  	cin >> s;
  	l = s.size();
  	for(int i = 0; i<l; i++){
		s[i] = (s[i] - 65 + N)%26 + 65;
    }
  	cout << s << endl;
  	
  	
	return 0;
  
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll a = in(), b = in(), c = in();
    cout << (a == b && c == b ? "Yes" : "No") << endl;
}

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

int main()
{
  int n, m, h, k;
  while(cin >> n >> m >> h >> k, n){
    vector< int > s(n), nums(n), pos(n);
    vector< Pi > data(m), buffer(m);
    for(int i = 0; i < n; i++){
      cin >> s[i];
      nums[i] = i;
    }
    for(int i = 0; i < m; i++){
      cin >> data[i].second >> data[i].first;
      --data[i].second;
    }
    sort( data.begin(), data.end());
    for(int i = 0; i < m; i++){
      swap( nums[data[i].second], nums[data[i].second + 1]);
      buffer[i] = make_pair( nums[data[i].second], nums[data[i].second + 1]);
    }

    int ret = 0, base = 0;
    for(int i = 0; i < n; i++){
      if(nums[i] < k) ret += s[i];
      pos[nums[i]] = i; // 位置
    }
    base = ret;

    for(int i = 0; i < m; i++){
      int crease = base;
      if(buffer[i].first < k){
        crease += s[pos[buffer[i].second]];
        crease -= s[pos[buffer[i].first]];
      }
      if(buffer[i].second < k){
        crease += s[pos[buffer[i].first]];
        crease -= s[pos[buffer[i].second]];
      }
      ret = min( crease, ret);
    }
    cout << ret << endl;
  }
  return(0);
}

Measured memory_bytes: 2640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif      
}
const ll N = 105, W = 1e5 + 5;
ll dp[N][W], weights[N], values[N];
int main() {

    localTest();
    fastio;
    ll n, w, ans = 0;
    cin >> n >> w;
    for(ll i = 1; i <= n; ++i) {
        cin >> weights[i] >> values[i];
    }
    for(ll j = 0; j <= w; ++j) {
        for(ll i = 1; i <= n; ++i) {
            dp[i][j] = dp[i - 1][j];
            if(weights[i] <= j) {
                dp[i][j] = max(dp[i][j], values[i] + dp[i - 1][j - weights[i]]);
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << "\n";


    return 0;
}

Measured memory_bytes: 81724
N = int(input())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]

count = 0
residual = A[0]

for i in range(N):
    if residual > B[i]:
        count += B[i]
        residual = A[i+1]
    elif residual + A[i+1] > B[i]:
        count += B[i]
        residual = residual + A[i+1] - B[i]         
    elif residual + A[i+1] <= B[i]:
        count += residual + A[i+1] 
        residual = 0
print(count)

Measured memory_bytes: 18432
#include <stdio.h>

int main()
{
    int m, n, odd = 0 , even = 0;
    scanf("%d %d", &m, &n);
    {
    for (int i = 2; i <= m; i++)
    odd = odd + i - 1;
    }
    {
    for (int i = 2; i <= n; i++)
        even = even + i - 1;
    }
    
    printf("%d", odd + even);
    
    return 0;
}


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

using namespace std;


int main(){
  int n,m;
  int p[30];
  int q[30];
  int kekka=0;
  cin>>n>>m;
  
  if(n==1){int k;
    cin>>k;
    cout<<k<<endl;}
  
  else{
    int first;
    cin>>first;
    for(int t=0;t<first;t++){
      cin>>q[t];}
    
    
  for (int i=1;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>p[j];
    }

    
    for(int z=0;z<first;z++){
       bool kasanari=false;
    for(int y=0;y<k;y++){
     
      if(q[z]==p[y]){
        kasanari=true;
      break;}
    }
      if(!kasanari){
        q[z]=9999;}
    }
    
    
  }
    
    
    
    
   
 
    for(int u=0;u<first;u++){
      if(q[u]<=30){
        kekka++;}
      
    }
      cout<<kekka<<endl;
  }
 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] cost = new long[N+1];
		HashMap<Integer, ArrayList<Edge>> adjl = new HashMap<Integer, ArrayList<Edge>>();
		for(int i=0; i<N; i++) {
			adjl.put(i+1, new ArrayList<Edge>());
		}
		for(int i=0; i<N-1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			long c = sc.nextLong();
			adjl.get(a).add(new Edge(b, c));
			adjl.get(b).add(new Edge(a, c));
		}
		int Q = sc.nextInt();
		int K = sc.nextInt();
		boolean[] visited = new boolean[N+1];
		long[] d = new long[N+1];
		for(int i=0; i<N+1; i++) {
			visited[i] = false;
		}
		ArrayDeque<Integer> dq = new ArrayDeque<Integer>();
		dq.add(K);
		while(!dq.isEmpty()) {
			int cur = dq.poll();
			visited[cur] = true;
			for(Edge e : adjl.get(cur)) {
				if(visited[e.next]) continue;
				dq.add(e.next);
				d[e.next] = d[cur] + e.weight;
			}
		}
		long[] ans = new long[Q];
		for(int i=0; i<Q; i++) {
//			print("Z");
			int x = sc.nextInt();
//			print("A");
			int y = sc.nextInt();
//			print("B");
			ans[i] = d[x] + d[y];
//			print("C");
		}
		for(int i=0; i<Q; i++) {
			System.out.println(ans[i]);
		}
	}
		
	static class Edge {
		int next;
		long weight;
		Edge(int next, long weight) {
			this.next = next;
			this.weight = weight;
		}
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 187572
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int odp = 10000;
    for (int mask = 0; mask < (1 << (n - 1)); ++mask)
    {
        vector< vector<int> > kom(__builtin_popcount(mask) + 1, vector<int>(m, 0));
        bool jeden = false;
        for (int j = 0; j < m; ++j)
        {
            int nrWieKom = 0;
            for (int i = 0; i < n; ++i)
            {
                int s = 0;
                while (i < n && (mask & (1 << i)) == 0)
                {
                    s += a[i][j] - '0';
                    ++i;
                }
                if (i < n)
                    s += a[i][j] - '0';
                kom[nrWieKom][j] = s;
                if (s > k)
                    jeden = true;
                ++nrWieKom;
            }
        }
        if (jeden)
            continue;
        int ilePio = 0, wie = __builtin_popcount(mask) + 1;
        vector<int> S(wie, 0);
        for (int i = 0; i < m; ++i)
        {
            while (i < m)
            {
                for (int j = 0; j < wie; ++j)
                    S[j] += kom[j][i];
                bool ok = true;
                for (int j = 0; j < wie; ++j)
                    if (S[j] > k)
                        ok = false;
                if (!ok)
                {
                    for (int j = 0; j < wie; ++j)
                        S[j] = 0;
                    --i;
                    break;
                }
                ++i;
            }
            ++ilePio;
        }
        odp = min(odp, ilePio - 1 + wie - 1);
    }
    cout << odp;
    return 0;

}


Measured memory_bytes: 384
from collections import deque
N = int(input())
V = {i: [] for i in range(1, N+1)}
for _ in range(N-1):
    a, b, c = map(int, input().split())
    V[a].append((b, c))
    V[b].append((a, c))
nq, k = map(int, input().split())
Q = []
for _ in range(nq):
    x, y = map(int, input().split())
    Q.append((x, y))

dist = {i: 0 for i in range(1, N+1)}
dq = deque()
dq.append(k)
dist[k] = 0
vstd = {i: False for i in range(1, N+1)}
while len(dq) > 0:
    u = dq.popleft()
    vstd[u] = True
    for vw in V[u]:
        v, w = vw
        if vstd[v]:
            continue
        dq.append(v)
        dist[v] = dist[u] + w

for q in Q:
    x, y = q
    print(dist[x] + dist[y])


Measured memory_bytes: 109668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();
    
    char c; cin >> c;
    cout << char(c + 1) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<ll> C(10,vec<ll>(10,0));

    auto high = [](int x){
        while(x/10){
            x /= 10;
        }
        return x;
    };

    for(int i=1;i<=N;i++){
        C[high(i)][i%10]++;
    }

    ll ans = 0;
    for(int i=1;i<=N;i++) ans += C[i%10][high(i)];
    cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

from collections import deque
# from pprint import pprint
moves=[(0,1),(1,0),(0,-1),(-1,0)]
# pp=pprint
INF=float("inf")

h,w,k=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())
maze=[list(input()) for _ in range(h)]
cost=[[INF]*w for _ in range(h)]

todo=deque()
todo.append((x1,y1))
cost[x1][y1]=0

while todo:
    x,y=todo.popleft()
    for vx,vy in moves:
        for kk in range(1,k+1):
            nx=x+vx*kk
            ny=y+vy*kk
            if not(0<=nx<h) or not(0<=ny<w):
                break
                # 更に伸ばす必要はない
            if maze[nx][ny]=="@":
                break
                # 蓮の向こうにはいけないので
            if cost[nx][ny]<=cost[x][y]:
                break
                # 更新を1回以上受けていて、更に良くならない場合はbreak
            if cost[nx][ny]==INF:
                cost[nx][ny]=cost[x][y]+1
                todo.append((nx,ny))
                # 更新されてなければ、[x][y]から1マス先を更新、キューに突っ込む


# pp(cost)
ans=cost[x2][y2]
if ans==INF:ans=-1
print(ans)

Measured memory_bytes: 145060
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

int N;
int w[maxn][3];
int f[maxn][3];
int main(){
    // debug;
    ios;
    cin>>N;
    for(int i = 1;i<=N;i++) cin>>w[i][0]>>w[i][1]>>w[i][2];
    f[1][0] = w[1][0],f[1][1] = w[1][1],f[1][2] = w[1][2];
    for(int i = 2;i<=N;i++){
        for(int j = 0;j<3;j++){
            for(int k = 0;k<3;k++){
                if(j != k) f[i][j] = max(f[i][j],f[i-1][k] + w[i][j]);
            }
        }
    }
    cout<<max(max(f[N][0],f[N][1]),f[N][2])<<'\n';


    
    return 0;
}


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

using namespace std;

typedef long long ll;

void solver_main()
{
	int k, x;
	cin >> k >> x;
	for (ll i = x - k + 1; i <= x + k - 2; i++) {
		cout << i << " ";
	}
	cout << x + k - 1 << endl;
}

int main(void)
{
	solver_main();
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
int C[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		C[A[i]]++;
	}
	ll ret=0;
	FOR(i,201010) ret+=1LL*C[i]*(C[i]-1)/2;
	FOR(i,N) {
		x=A[i];
		ret-=1LL*C[x]*(C[x]-1)/2;
		C[x]--;
		ret+=1LL*C[x]*(C[x]-1)/2;
		cout<<ret<<endl;
		ret-=1LL*C[x]*(C[x]-1)/2;
		C[x]++;
		ret+=1LL*C[x]*(C[x]-1)/2;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <cstring>

#define test(t) while(t--)
#define fo(i,k,n) for(int i=k;i<n;i++)
#define refl(a,x) for(auto& a:x)
#define MIN(a,b)  (a>b?b:a)
#define ll  long long int
#define MOD 1e9 + 7
#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define fi first
#define se second
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//typedef pair<int,int> pai;
//typedef pair<char,int> pac;



/*bool f(int x,int y){

return x>y;
}*/


using namespace std;


void solve(){ll a,b,c;
             in a>>b>>c;
             //ll p=a;

             out c<<sp<<a<<sp<<b<<"\n";
}


int main(){ fast()
             //freopen("input.txt","r",stdin);
	         //freopen("output.txt","w",stdout);
             ll t=1;
            //cin>>t;
            test(t){
            solve();
            }

return 0;}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x: x[1])
ans = 0

br = -1
for i in range(m):
    if ab[i][0] < br < ab[i][1]:
        continue
    else:
        br = ab[i][1] - 0.5
        ans += 1

print(ans)


Measured memory_bytes: 18172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
#define ll  long long;
int main()
{

  int a, b;
  double ans = a / b;
  cin >> a >> b;
  cout << a / b << " " << a % b << " ";
  keta(10);
  cout<<(double)a/(double)b<<endl;
}



Measured memory_bytes: 3276
($N,$M)=glob<>;
$%{0}=0;
$A=<>,$i=$C=0,map($C|=1<<$_-1,glob<>),map+($%{$_|$C}//=9e9)-=$-=$%{$_|$C}-$A-$%{$_},keys%%for 1..$M;
print$%{2**$N-1}//-1

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

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<long long> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    long long tmp = 0;
    for (int i = 0; i < N; ++i) {
        long long b;
        cin >> b;
        b -= a[i];
        if (b > 0) {
            tmp += b / 2;
        } else {
            tmp += b;
        }
    }

    if (tmp >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>

using namespace std;
int main() {
	int a, b;
	stack<int> s;
	string str;
	while (cin >> str) {
		if(str[0] == '+'){
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a + b);
		}else if(str[0] == '-'){
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a - b);
		}else if(str[0] == '*'){
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a * b);
		}else{
			s.push(atoi(str.c_str()));
		}
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int a,b;
double a1,b1;
cin>>a>>b;
a1=a;
b1=b;
cout<<fixed<<setprecision(8)<<a/b<<" "<<a%b<<" "<<a1/b1<<endl;
return 0;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
#define INF (1e9 + 7)
#define mp make_pair
#define pb push_back
#define MAXN 4004
using namespace std;
typedef long long int lo;
lo dp[MAXN];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("ot.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    lo a,b;
    cin >> a >> b;
    if(a == b) cout << "Yes";
    else cout << "No";

}



Measured memory_bytes: 256
//In the name of God

#include <bits/stdc++.h>
using namespace std;

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

const int N = 1e5+10 , mod = 1e9+7;

int a[4] , b[] = {1 , 4 , 7 , 9};

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   for(int i = 0 ; i < 4 ; i++)
      cin >> a[i];
   sort(a , a + 4);
   for(int i = 0 ; i < 4 ; i++)
      if(a[i] != b[i])
         return cout << "NO" , 0;
   cout << "YES";
   return 0;
}


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

using namespace std;

int main(){

    int P, Q, R;
    cin >> P >> Q >> R;

    int maxValue = P;
    if(Q > maxValue){
        maxValue = Q;
    }
    if(R > maxValue){
        maxValue = R;
    }
    cout << (P + Q + R) - maxValue << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		if(A + B == C + D) {
			System.out.println("Balanced");
		} else if(A + B > C + D) {
			System.out.println("Left");
		} else if(A + B < C + D) {
			System.out.println("Right");
		}
		scan.close();

	}

}


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

using i64 = int64_t;

constexpr i64 MOD = 1000000007;

i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) {
    i64 d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

i64 multi_inv(i64 a, i64 md) {
    i64 x, y;
    extgcd(md, a, x, y);
    return (y > 0 ? y : md + y);
}

vector<i64> set_ncr(i64 n) {
    vector<i64> ncr(n+1);
    ncr[0] = 1;
    for (i64 i = 1; i <= n; i++) {
        i64 inv = multi_inv(i, MOD);
        ncr[i] = (n - i + 1) * ncr[i - 1] % MOD;
        ncr[i] = ncr[i] * inv % MOD;
    }
    return ncr;
}

int main(){
    i64 n, k;
    cin >> n >> k;
    auto ncr = set_ncr(n);
    auto ncr2 = set_ncr(n-1);
    i64 ans = 0;
    for(i64 i=1;i<=min(n-1, k);++i){
        i64 tmp = ncr[i] * ncr2[i];
        tmp %= MOD;
        //cerr << tmp << endl;
        ans += tmp;
        ans %= MOD;
    }
    if(k>1){
        ans++;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main(){
  long long a,b,k;
  cin >> a >> b >> k;
  long long c,d;
  c = a;
  d = b;
    if(a >= k){
      c -= k;
    } else if(b >= k - a){
      d = b - k + a;
      c = 0;
    }
 	else{
      d = 0;
      c = 0;
  	}
    if(c < 0){
      c = 0;
    }
  	if(d < 0){
      d = 0;
    }
  cout << c << " " << d << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {int p = 0; while (n / 2) {n = n / 2; p++;} return p;}
int poww(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = ((pro % mod) * (x % mod) % mod); y = y >> 1; x = ((x % mod) * (x % mod) % mod);} return pro;}
int poww2(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = pro * x; y = y >> 1; x = x * x;} return pro;}
bool isprime(int n) { if (n == 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true;}
vector<vector<int>> adj(2e5);
vi visited(2e5, 0);
/*

*/

int solve() {
	int n, x, t;
	cin >> n >> x >> t;
	int ans = ceil(n / (double)x) * t;
	return cout << ans << '\n', 0;
}
int32_t main() {
	/*#ifndef ONLINE_JUDGE
	    //for getting input from input.txt
	    freopen("input.txt","r",stdin);
	    //for writing output to output.txt
	    freopen("output.txt","w",stdout);
	#endif*/
	fast;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 9444
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100005;
int n,l,q;
int nxt[N][20];

int main(){
	fast_io();
	cin >> n;	
	vector<int> v(n+1);
	cu(i,0,n)cin >> v[i];
	v[n] = v[n-1] + 1;
	cin >> l >> q;
	cu(i,0,n){
		int ind = upper_bound(v.begin(),v.end(), v[i] + l) - v.begin();
		nxt[i][0] = ind - 1;
	}
	cu(i,0,20)nxt[n][i] = n;
	cu(j,1,20){
		cu(i,0,n){
			nxt[i][j] = nxt[nxt[i][j-1]][j-1];
		}
	}
	cu(i,0,q){
		int cur = 0,dest;
		cin >> cur >> dest;
		if(cur > dest)swap(cur,dest);
		int ans = 0;
		--cur;--dest;
		int plen = 20;
		while(cur < dest){
			int len = 0;
			while(len < 19 && nxt[cur][len + 1] <= dest){
				++len;
			}
			ans += (1 << len);
			cur = nxt[cur][len];
			--plen;
			assert(plen > 0);
		}
		cout << ans << '\n';
	}
}


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

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

                int k = n - i - j;
                int total = 10000 *i + 5000*j + 1000*k;
                if (total == y) {
                    System.out.println(i+" "+j+" "+k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");

    }
}

Measured memory_bytes: 23252
# coding: utf-8
# Your code here!
import sys
x, n = map(int,input().split())
if n == 0:
    print(x)
    sys.exit()
p = input().split()
max_diff = 0
for i in p:
    max_diff = max(abs(x-int(i)),max_diff)
max_diff += 1
min_diff_int = 200
temp = 0
flag = False
for i in range(x-max_diff,x+max_diff+1):
    #print(i,end="")
    for j in p:
        if i == int(j):
            flag = True
            continue
    if flag:
        flag = False
        continue
    if min_diff_int > abs(x-i):
        min_diff_int = abs(x-i)
        temp = i
print(temp)



Measured memory_bytes: 9212
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n,k,q;cin>>n>>k>>q;
	vint cnt_ans(n,0);
	rep(i,q){
		int t; cin>>t;
		++cnt_ans[--t];
	}
	rep(i,n){
		if(k-q+cnt_ans[i]>0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<vector<bool>> vis(h, vector<bool>(h));
    vector<vector<int>> ans(h, vector<int>(w));
    vector<int> b(n + 1, 0);
    int color = 1, dir = 0, x = 0, y = 0;
    pii diff[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    for (int i = 0; i < h * w; i++) {
        int tx = x + diff[dir].fi, ty = y + diff[dir].se;
        if (tx < 0 || tx >= h || ty < 0 || ty >= w || vis[tx][ty]) {
            dir++;
            dir %= 4;
        }
        if (b[color] >= a[color])
            color++;
        ans[x][y] = color;
        vis[x][y] = true;
        b[color]++;
        x += diff[dir].fi, y += diff[dir].se;
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999

long gcd(long n, long m){
    long small,big;
    if(n>m){
        big=n;
        small=m;
    }
    else{
        small=n;
        big=m;
    }

    long r=0;
    while(1){
        if((r=big%small)==0){
            return small;
        }
        else{
            big=small;
            small=r;
        }
    }

    return 0;
}


int main(void){
    int N;
    scanf("%d",&N);
    long* A;
    NEW(A,N+1);//A[1]~A[N]
    for(int i=1;i<=N;i++){
        scanf("%ld",&A[i]);
    }

    //攻撃されたモンスターHP-=攻撃したモンスターHP

    long ans=A[1];
    for(int i=2;i<=N;i++){
        ans=gcd(ans,A[i]);
    }
    


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

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n, m; cin >> n >> m;
    vi cnt(n + 2);
    FOR(i, 1, m) {
        int l, r; cin >> l >> r;
        cnt[l]++, cnt[r + 1]--;
    }
    int ans = 0;
    FOR(i, 1, n) {
        cnt[i] += cnt[i - 1];
        if (cnt[i] == m) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
x=int(input())
if x%7==0:
   print("thu");
elif x%7==1:
   print("fri");
elif x%7==2:
   print("sat");
elif x%7==3:
   print("sun");
elif x%7==4:
   print("mon");
elif x%7==5:
   print("tue");
else :
   print("wed");


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	string S;
	cin>>S;
	char y1=S[0];
	char y2=S[1];
	char y3=S[2];
	char y4=S[3];
	char m1=S[5];
	char m2=S[6];
	char d1=S[8];
	char d2=S[9];
	int y=(int)(y1-'0')*1000+(int)(y2-'0')*100+(int)(y3-'0')*10+(int)(y4-'0');
	int m=(int)(m1-'0')*10+(int)(m2-'0');
	int d=(int)(d1-'0')*10+(int)(d2-'0');
	if(y>2019)cout<<"TBD"<<endl;
	else if(y==2019 && m>4)cout<<"TBD"<<endl;
	else cout<<"Heisei"<<endl;
	return 0;
}

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

int main() {
	char o[51];
	char e[51];
	scanf("%s %s", o, e);
	int n = strlen(o);
	int m = strlen(e);
	for(int i = 0; i < n + m; i++) {
		if(i % 2 == 0) {
			printf("%c", o[i / 2]);
		}else {
			printf("%c", e[i / 2]);
		}
	}
	printf("\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200002;
int n;
vector<int> vec[N];
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;i ++){
		int x; scanf("%d", &x);
		vec[x].push_back(i);
	}
	if(vec[1].empty()) return puts("-1"), 0;
	int now = 0;
	for(Rint i = 1;i <= n;i ++){
		auto it = upper_bound(vec[i].begin(), vec[i].end(), now);
		if(it == vec[i].end()) return printf("%d\n", n - i + 1), 0;
		now = *it;
	}
	puts("0");
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool sortByVal(const pair<string, int> &a,const pair<string, int> &b)
{
    return (a.second>b.second);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map<string,int>p;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        auto it=p.find(s);
        if(it==p.end())
        {
            p[s]=1;
        }
        else
        {
            p[s]++;
        }
    }
    vector<pair<string, int>> vec;
    map<string, int> :: iterator it2;
    for (it2=p.begin();it2!=p.end();it2++) 
    {
        vec.push_back(make_pair(it2->first, it2->second));
    }
    sort(vec.begin(), vec.end(), sortByVal); 
    ll max=vec[0].second;
    vector<string>ans;
    for(int i=0;i<n;i++)
    {
        if(vec[i].second==max)
        {
            ans.push_back(vec[i].first);
        }
        else
        {
            break;
        }
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}









Measured memory_bytes: 31340
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
int n;
int a[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll best = (ll)1e18;
    for (int it = 0; it < 2; it++) {
        ll sm = 0;
        ll cnt = 0;
        for (int i = 1; i <= n; i++) {
            sm += a[i];
            if (i % 2 == 1) {
                cnt += max(0LL, 1 - sm);
                sm = max(sm, 1LL);
            }
            else {
                cnt += max(0LL, sm + 1);
                sm = min(sm, -1LL);
            }
        }
        best = min(best, cnt);
        for (int i = 1; i <= n; i++) {
            a[i] *= -1;
        }
    }
    cout << best;
    return 0;
}

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

int main() {
  
  int r, D, x;
  cin >> r >> D >> x;
  int s;
  s = r*x - D;
  
  cout << s << endl;
  
  for (int i = 0; i < 9; i++){
    s = r*s - D;
    cout << s << endl;
  }
    
  
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    int N,M,sum=0;
    cin>>N>>M;
    double A[N];
    for(ll i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    sort(A,A+N);
    reverse(A,A+N);
    for(ll i=0;i<M;i++){
        if(A[i]*4*M<sum){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256