akhauriyash/Code-Regression huggingface dataset:
class SegTree:
    def __init__(self, init_val, ide_ele, seg_func):
        self.segfunc = seg_func
        n = len(init_val)
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        # k+1ではなくkでは？
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
import sys;input=sys.stdin.readline
mod = 998244353
N=int(input())
X = []
Y = []
for _ in range(N):
    x, d = map(int, input().split())
    X.append((x,d))
X.sort(key=lambda x:x[0])
for i, (x, d) in enumerate(X):
    Y.append((2*x,i,0))
    Y.append((2*x+2*d-1,i,1))
Y.sort(key=lambda x:x[0])
C = [0]*N
for x, i, t in Y:
    if t==0:
        j = i
    elif t==1:
        C[i] = j
st = SegTree(C, -1, max)
dp = [1]*(N+1)
for i in range(N-1, -1, -1):
    y=st.query(i, C[i]+1)
    st.update(i, y)
    dp[i] = (dp[i+1]+dp[y+1]) % mod
print(dp[0])


Measured memory_bytes: 122540
a = input()
b = input()
c = int(len(a))
d = int(len(b))
e = c-d+1
ans = int(0)
temp = int(0)
for i in range(e):
  temp = 0
  for j in range(d):
    if a[j+i] == b[j]:
      temp += 1
  if ans < temp:
    ans = temp

print(d-ans)
  


Measured memory_bytes: 8964
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  if(a.size() > b.size()){
    cout << "GREATER" << endl;
    return 0;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
    return 0;
  }
  else{
    for(int i = 0;i < a.size();i++){
      if(a[i] > b[i]){
        cout << "GREATER" << endl;
        return 0;
      }
      if(a[i] < b[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(int n,int a,int b,int c,int x){
    list<int> s; 
    int in;
    for(int i=0;i<n;i++){
        cin>>in;
        s.push_back(in);
    }
    for(int i=0;i<=10000;i++){
        if(*s.begin()==x){
            s.pop_front();
        }
        if(!s.size()){
            cout<<i<<endl;
            return;
        }
        x=(a*x+b)%c;
    }
    cout<<"-1"<<endl;
}



int main(void){
    int a,b,c,d,e;
    while(cin>>a>>b>>c>>d>>e,a){
        solve(a,b,c,d,e);
    }
}

Measured memory_bytes: 3008
from fractions import gcd

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


def lcm(a, b):
    return  (a * b) // gcd(a, b)


nbc = B - B // C
nbd = B - B // D
nbl = B - B // lcm(C, D)

nac = A - 1 - ((A - 1) // C)
nad = A - 1 - ((A - 1) // D)
nal = A - 1 - ((A - 1) // lcm(C, D))

b = nbc + nbd - nbl
a = nac + nad - nal

print(b - a)


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

using namespace std;

int N, K;
vector<int> v;

int calc(int l, int r)
{
  int sum = 0;
  priority_queue<int> q;
  for (int i = 0; i < l; i++) {
    sum += v[i];
    q.push(-v[i]);
  }
  for (int i = 0; i < r; i++) {
    sum += v[N-1-i];
    q.push(-v[N-1-i]);
  }
  int k = K - l - r;
  while (q.size() && k-- && q.top() > 0) {
    sum += q.top();
    q.pop();
  }
  return sum;
}

int main()
{
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  int res = 0;
  for (int l = 0; l < min(N, K) + 1; l++) {
    for (int r = 0; r < min(N, K) + 1; r++) {
      if (l + r > min(N, K)) break;
      res = max(res, calc(l, r));
    }
  }
  cout << res << endl;
}

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

using namespace std;

int main() {
    int N, W;
    scanf("%d %d", &N, &W);

    int w[N], v[N];

    int** dp = new int*[W + 1];
    for (int i = 0; i < W + 1; i++) {
        dp[i] = new int[N + 1];
        for (int k = 0; k < N + 1; k++) dp[i][k] = 0;
    }

    for (int i = 0; i < N; i++) {
        scanf("%d %d", &v[i], &w[i]);
    }

    for (int i = N - 1; i >= 0; i--) {
        for (int k = 1; k <= W; k++) {
            if (w[i] <= k) {
                dp[k][i] = max(dp[k][i + 1], dp[k - w[i]][i + 1] + v[i]);
            } else {
                dp[k][i] = dp[k][i + 1];
            }
        }
    }

    printf("%d\n", dp[W][0]);

    return 0;
}



Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int main(){
    int N; cin >> N;
    long long ans = 1;
    for(int i=1; i<=N; ++i){
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int c, n;
    cin >> c >> n;
    vector<string> p(n);
    for(int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int incorrect = 0;
    for(int i = 0; i < n / 2; ++i) {
        for(int j = 0; j < n / 2; ++j) {
            incorrect += p[i][j] != p[i][n - j - 1] || p[i][j] != p[n - i - 1][j];
        }
    }

    int ans = incorrect == 0;
    for(int i = 0; i < c - 1; ++i) {
        int d; cin >> d;
        for(int j = 0; j < d; ++j) {
            int r, c; cin >> r >> c;
            r--; c--;
            if(p[n - r - 1][c] == p[r][c] && p[r][c] == p[r][n - c - 1]) incorrect += 1;
            p[r][c] = (p[r][c] == '0') ? '1' : '0';
            if(p[n - r - 1][c] == p[r][c] && p[r][c] == p[r][n - c - 1]) incorrect -= 1;
        }
        ans += incorrect == 0;
    }

    cout << ans << endl;
}



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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextInt();
		}
		System.out.println(doSort(w));
	}
	
	public static int getIndex(int[] l, int x){
		for (int i = 0; i < l.length; i++) {
			if(l[i]==x) return i;
		}
		return -1;
	}
	
	public static int doSort(int[] w){
		int[] sortedList = w.clone();
		Arrays.sort(sortedList);
		
		int cost = 0;
		
		for (int i = 0; i < w.length; i++) {
			int x = getIndex(w, sortedList[i]);
			int y = 0;
			while (x>i) {
				y++;
				int k = getIndex(w, sortedList[x]);
				cost = cost + w[k];
				int comp = w[x];
				w[x] = w[k];
				w[k] = comp;
				x = k;
			}
			cost = cost + Math.min(sortedList[i]*y, sortedList[i]*2+sortedList[0]*(y+2));
		
		}
		return cost;
	}
	
}


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

int main() {
	string s;
	int cnt = 0;
	while (cin >> s) {
		string r = s;
		reverse(r.begin(), r.end());
		if (r == s)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

void
reverse(int *a, int *b, int n)
{
  int i;
  for (i = 0; i < n; i++) {
    b[i] = a[n - i - 1];
  }
}

int
main(void)
{
  int n, *a, *b, i;

  std::scanf("%d", &n);
  a = (int*)std::malloc(n * sizeof(int));
  b = (int*)std::malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    std::scanf("%d", &a[i]);
  }
  reverse(a, b, n);

  if (n > 0) {
    std::printf("%d", b[0]);
    for (i = 1; i < n; i++) {
      std::printf(" %d", b[i]);
    }
    std::printf("\n");
  }
  
  return 0;
}



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

#define mod 1000000007
#define MAX_N 200010
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];

void GetInv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}
void GetFactorial(){
    factorial[0] = 1; inv_factorial[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= mod;
        inv_factorial[i] = inv_factorial[i-1] * inv[i];
        inv_factorial[i] %= mod;
    }
}

long long combination(int n, int r) {
    long long ret = factorial[n] * inv_factorial[r];
    ret %= mod;
    ret *= inv_factorial[n-r];
    return ret % mod;
}

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    GetInv(); GetFactorial();
    int b, w; cin >> b >> w;
    int n = b + w;
    vector<long long> p(n+1, 0);
    for (int i = 0; i < b; i++) {
        long long pp = modpow(inv[2], (n-i-1)) * combination(n-i-2, w-1) % mod;
        long long c = pp * (b-i-1) % mod * inv[n-i-2] % mod;
        p[0] = (p[0] + c) % mod;
        p[n-i-2] = (mod + p[n-i-2] - c) % mod;
        p[n-i-1] = (p[n-i-1] + pp) % mod;
        p[n] = (mod + p[n] - pp) % mod; 
    }
    for (int i = 0; i < w; i++) {
        long long pp = modpow(inv[2], (n-i-1)) * combination(n-i-2, b-1) % mod;
        long long c = pp * (b-1) % mod * inv[n-i-2] % mod;
        p[0] = (p[0] + c) % mod;
        p[n-i-2] = (mod + p[n-i-2] - c + pp) % mod;
        p[n-i-1] = (mod + p[n-i-1] - pp) % mod;
    }
    for (int i = 0; i < n; i++) {
        p[i+1] = (p[i+1] + p[i]) % mod;
        cout << p[i] << endl;
    }
    return 0; 
}

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

namespace mondai0013
{
	class Program
	{
		static void Main(string[] args)
		{
			var	stack	= new Stack<string>();

			while( true ) {
				var	s	= Console.ReadLine();
				if( s == null ) {
					break;
				}
				if( s == "0" ) {
					Console.WriteLine( stack.Pop() );
				} else {
					stack.Push( s );
				}
			}
		}
	}
}

Measured memory_bytes: 5552
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define all(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
void solve(){
	string s ;
	cin >> s ;
	if(all_of(all(s),[&](char a){ return a == s[0]; } )){
		cout << "No" << endl; 
	}else{
		cout << "Yes" << endl; 
	}
}

signed main(){
	IOS;
	int test = 1; 
	while(test--)
		solve();
	return 0;
}







Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main() {
	int k;
	cin >> k;
	vector<ll> a(k);
	rep(i, 0, k)cin >> a[k - i - 1];
	ll M = 2ll, m = 2ll;
	if (a[0] != 2) {
		puts("-1");
		return 0;
	}
	rep(i, 0, k) {
		m = ((m - 1) / a[i] + 1) * a[i];
		M = M / a[i] * a[i] + a[i] - 1;
		if (m / a[i] >= M / a[i] && m != m / a[i] * a[i] || M < m) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld %lld\n", m, M);
	return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll x,y;
  cin >> x>>y;
  int cnt = 0;
  while(x<=y)
  {
    x*=2;
    cnt++;
  } 
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,c,d;
    long long int max,s1,s2,s3,s4;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    s1=a*c;
    s2=a*d;
    s3=b*c;
    s4=b*d;
    if(s1>=s2&&s1>=s3&&s1>=s4){printf("%lld\n",s1);}
    else if(s2>=s1&&s2>=s3&&s2>=s4){printf("%lld\n",s2);}
    else if(s3>=s2&&s3>=s1&&s3>=s4){printf("%lld\n",s3);}
    else if(s4>=s2&&s4>=s3&&s4>=s1){printf("%lld\n",s4);}
    return 0;

}


Measured memory_bytes: 1708
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
ll a[100100];

// 1 base
template<typename T, int max_n>
class BIT {
private:
    T bit[max_n + 1];
    int n;
public:
    BIT(int _n = max_n) {
        n = _n;
        memset(bit, 0, sizeof(bit));
    }
    // [1, i]
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // [a, b]
    T sum(int a, int b) {
        if (a > b) return 0;
        return sum(b) - sum(a-1);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    int lower_bound(T x) {
        int lb = 0, ub = n;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v < x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

    int upper_bound(T x) {
        int lb = 1, ub = n+1;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }
};

BIT<ll, 100100> bit;
BIT<ll, 100100> pos;

ll solve() {
    for (int i = 0; i < n; i++) {
        bit.add(i+1, a[i]);
        if (a[i] > 0)
            pos.add(i+1, a[i]);
    }

    ll res = 0;
    for (int i = 0; i <= n-k; i++) {
        ll m = bit.sum(i+1, i+k);
        res = max(res, max(m, 0LL) + pos.sum(1, i) + pos.sum(i+k+1, n));
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
long long k;
int x, y, a, b;
int main () {
    cin >> x >> y >> a >> b;
    int disx = b - y, disy = a - x;
  
    cout << a - disx << " " << b + disy << " " << x - disx << " " << y + disy << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    ll h, w; cin >> h >> w;
    ll s = h*w;

    if(s%3==0) {
        pr(0); return 0;
    }
    if(h==1 || w==1){
        pr(1); return 0;
    }

    ll ans = min(h, w);

    FOR(ih, 1, h){
        ll a = ih*w;
        ll b;
        b = (h-ih) * (w/2);
        ll c = s - b - a;
        // cout << "ih=" << ih << " " << a << " " << b << " " << c << endl;
        ll mx = max(a,max(b, c));
        ll mn = min(a, min(c, b));
        chmin(ans, mx - mn);
    }

    FOR(iw, 1, w){
        ll a = iw*h;
        ll b;
        b = (h/2) * (w-iw);
        ll c = s - b- a;
        ll mx = max(a,max(b, c));
        ll mn = min(a, min(c, b));
        // cout << "iw=" << iw << " " << a << " " << b << " " << c << endl;
        chmin(ans, mx - mn);
    }

    pr(ans);
    return 0;}

Measured memory_bytes: 3612
import Data.List

main :: IO ()
main = getLine >>= putStrLn . solve 

solve :: String -> String
solve = check "keyence"
    where
        check xxs@(x : xs) yys@(y : ys)
            | x == y = check xs ys
            | xxs `isSuffixOf` yys = "YES"
            | otherwise = "NO"
        check (_ : _) _ = "NO"
        check _ _ = "YES"

Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

int main(){
	long long k;
	std::cin>>k;

	long long var7= 7;
	long long addval =7;

	long long ans=-1;

	for(int i=0; i< 1000000; i++){
		if(var7%k==0){
			ans= i+1;
			break;
		}

		addval= (addval*10)%k;
		var7= (var7+ addval)%k;

	}


	std::cout<<ans<<std::endl;

	return 0;	
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  vector<int> W(N);
  rep(i, N) cin >> W[i];

  vector<int> left(N + 1);
  vector<int> right(N + 1);
  left[0] = 0;
  right[N] = 0;

  int sum = 0;
  rep(i, N)
  {
    sum += W[i];
    left[i + 1] = sum;
  }

  sum = 0;
  rep(i, N)
  {
    sum += W[N - 1 - i];
    right[N - 1 - i] = sum;
  }

  int mn = 1000000000;
  rep(i, N + 1)
  {
    int tmp = std::abs(left[i] - right[i]);
    if (mn > tmp)
      mn = tmp;
  }

  cout << mn << endl;

  return 0;
}


Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vector<ll> a(100005,0);
    rep(i,n){
        ll b;
        cin>>b;
        ++a[b];
    }
    
    ll cnt=0;
    rep1(i,100000){

        cnt=max(cnt,a[i]+a[i+1]+a[i-1]);
    }

    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3956
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N,M;
signed main(){
    scanf("%lld %lld",&N,&M);
    rep(i,M/2){
        printf("%lld %lld\n",1+i,(M/2)*2+1-i);
    }
    rep(i,M-M/2){
        printf("%lld %lld\n",(M/2)*2+2+i,M*2+1-i);
    }
    return 0;
}


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

/**
 * Created by bi16060 on 2019/03/24.
 */
public class Main{
    public static void main(String args[]) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

        int max_length = 0;
        int length = 0;

        for(String s : line) {
            switch (s) {
                case ("A"):
                case ("T"):
                case ("C"):
                case ("G"):
                    length+=1;
                    break;
                default:
                    if (length > max_length){
                        max_length = length;
                    }
                    length = 0;
                    break;
            }
        }
        if (length > max_length){
            max_length = length;
        }
        System.out.println(max_length);
    }
}



Measured memory_bytes: 20948
#include<stdio.h>
int main(void){
	char s[9][15] = {};
	int a[2][9] = {};
	int j, i = 0;

	while (i++ < 9){
		j = 0;
		scanf("%s", s);
		scanf("%d %d", &a[0][i], &a[1][i]);
		printf("%s", s);
		printf(" %d %d\n", a[0][i] + a[1][i], a[0][i] * 200 + a[1][i]*300);

	}
		return 0;
}

Measured memory_bytes: 596
input = gets.to_i
dp=Array.new(101).map{Array.new(4,0).map{Array.new(4,0).map{Array.new(4,0)}}}
#dp[101][4][4][4] = kazu
dp[0][3][3][3] = 1
mod = 10 ** 9 + 7
input.times{|kazu|
    4.times{|c1|
       4.times{|c2|
            4.times{|c3|
                4.times{|a|	
					#ダメな5つの条件をカットする
					if (a == 2 && c1 == 1 && c2 == 0) then next end
					if (a == 2 && c1 == 0 && c2 == 1) then next end
					if (a == 1 && c1 == 2 && c2 == 0) then next end
					if (a == 2 && c1 == 1 && c3 == 0) then next end
					if (a == 2 && c2 == 1 && c3 == 0) then next end
 
					dp[kazu + 1][a][c1][c2] += dp[kazu][c1][c2][c3]
					dp[kazu + 1][a][c1][c2] %= mod           
                }
            }
        } 
    }
}
ans = 0
4.times{|c1|
4.times{|c2|
4.times{|c3|
ans += dp[input][c1][c2][c3];
ans %= mod;
}
}
}
print ans

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

#define int long long


signed main(){
	
	string s;
	
	int f=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(f==0 && s[i]=='C')f=1;
		if(f==1 && s[i]=='F')f=2;
	}
	if(f==2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


Measured memory_bytes: 764
program prob2
    implicit none
    character(105) :: s
    integer :: i, l
    integer :: a(26)
    read(*,*) s
    do i = 1, 26
        a(i) = 0
    end do
    l = len_trim(s)
    do i = 1, l
        a(ichar(s(i:i)) - ichar('a')+1) = a(ichar(s(i:i)) - ichar('a')+1) + 1
    end do
    do i = 1, 26
        if(mod(a(i), 2) == 1) then
            write(*,'(a)') 'No'
            stop
        end if
    end do
    write(*,'(a)') 'Yes'


    stop
contains
end program prob2   

Measured memory_bytes: 2924
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,data;
	while(cin>>n,n){
		int ans=0;
		vector<int> dt;
		rep(i,n){
			cin>>data;
			dt.push_back(data);
		}
		while(1){
			if(ans>10000){
				ans=-1;
				break;
			}
			bool check=true;
			rep(i,dt.size())if(dt[i]!=i+1)check=false;
			if(check)break;
			ans++;
			int size=dt.size();
			rep(i,size)dt[i]--;
			dt.push_back(size);
			size++;
			vector<int>::iterator ite=dt.begin();
			for(int i=0;i<dt.size();){
				if(dt[i]==0)dt.erase(ite);
				else{
					i++;
					ite++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
         
using namespace std;
 
#define ll  long long
#define mod 1000000007
#define pb push_back
#define pie 3.141592653589
#define inf 1e9



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



    ll i,n,n2,m,t,j,l,r,pos,mpos,f=0,k,p,n1,z,q,x,y,x1,y1,x2,y2,x3,y3,x4,y4,w;

    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    ll dp[s1.length()+1][s2.length()+1];
    memset(dp,0,sizeof(dp));
    n=s1.length();
    m=s2.length();
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string s="";
    i=n;j=m;
     while(i>0&&j>0){
     
            if(s1[i-1]==s2[j-1])
            {
                s+=s1[i-1];
                i--;
                j--;
            }
            else
            {
                if(dp[i-1][j]>dp[i][j-1])
                {
                    i--;
                }
                else
                {
                    j--;
                }
            }
        }

        
    reverse(s.begin(),s.end());
    cout<<s;


  return 0;
}

Measured memory_bytes: 70656
def main():
    # n = int(input())
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))
    s = input()
    # h = [int(input()) for _ in rane(n)]
    if s == "A":
        print("T")
    if s == "T":
        print("A")
    if s == "C":
        print("G")
    if s == "G":
        print("C")


if __name__ == '__main__':
    main()


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

int main()
{
    ll h, ans = 1;
    cin >> h;
    for (ll i = 1; i < h;)
    {
        i = i * 2 + 1;
        ans = i;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int Saidai = 0;
  if(K <= A + B){
    if(K <= A){
      Saidai = K;
    }else{
    	Saidai = A;
    }  
  }else if (K > A + B){
    Saidai = A * 1+ (-1) * (K - A - B);
  }
  cout << Saidai << endl;
}



Measured memory_bytes: 3608
N = gets.to_i

require 'prime'

@m = (1 .. Math.log2(10**12).ceil).each_with_object([0]){|i, o| o << o.last + i}
f = ->(n){@m.bsearch_index{_1 > n} - 1}
puts N.prime_division.inject(0){|s, (p, e)| s + f[e]}

Measured memory_bytes: 14572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int hoge(char a, char b, char c) {
  int t = 0;
  t += (a - '0') * 100;
  t += (b - '0') * 10;
  t += (c - '0');
  //cout<<t<<endl;
  return abs(t - 753);
}

int main()
{
  string s;
  cin>>s;

  int l = s.length();
  int ans = INF;
  REP(i,l-2) {
    ans = min(ans, hoge(s[i], s[i+1], s[i+2]));
  }

   cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    long long n,m;
    cin>>n>>m;
    if(n*2==m)
    cout<<n;
    if(n*2>m)
    cout<<m/2;
    if(n*2<m)
    cout<<n+(m-(n*2))/4;
 
    return 0;
}    
    
     

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>a(h,vector<char>(w));
    queue<tuple<int,int,int>>q;
    int black=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            if(a[i][j]=='#'){
                q.push(make_tuple(i,j,1));
                black++;
            }
        }
    }
    int m=0;
    while(black<h*w){
        int x=get<0>(q.front()),y=get<1>(q.front()),d=get<2>(q.front());
        q.pop();
        m=max(m,d);
        if(x>0 && a[x-1][y]=='.'){
            a[x-1][y]='#';
            q.push(make_tuple(x-1,y,d+1));
            black++;
        }
        if(x<h-1 && a[x+1][y]=='.'){
            a[x+1][y]='#';
            q.push(make_tuple(x+1,y,d+1));
            black++;
        }
        if(y>0 && a[x][y-1]=='.'){
            a[x][y-1]='#';
            q.push(make_tuple(x,y-1,d+1));
            black++;
        }
        if(y<w-1 && a[x][y+1]=='.'){
            a[x][y+1]='#';
            q.push(make_tuple(x,y+1,d+1));
            black++;
        }
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 13328
N, K = map(int, input().split())

A = list(map(int, input().split()))
AA = []
for i in range(2):
    AA.extend(A)

x = 0
for i in range(N):
    for j in range(i+1, N):
        if A[j] < A[i]:
            x += 1
M = 10**9 + 7

y = 0
NN = N*2
for i in range(NN):
    for j in range(i+1, NN):
        if AA[j] < AA[i]:
            y += 1

a = (K*x)
b = (y - 2*x) * (K*(K-1)//2)
ans = ((a+b)  % M)
print(int(ans))

Measured memory_bytes: 3188
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int INF=1000000007;
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int a[]=new int[N];
		int sum=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		sum/=N;//heikin
		int ans=INF;
		
		for(int c=0;c<2;c++) {
			int tmp=0;
			for(int i=0;i<N;i++) {
				tmp+=(sum-a[i])*(sum-a[i]);
			}
			ans=Math.min(ans, tmp);
			sum++;
		}
		
		p(ans);
	
	}
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
int L[256],R[256],O[256];
int S,A,C;
double mi;
int main(){
    while(cin>>N,N){
        rep(i,N)cin>>L[i];

        mi=1001001001;
        rep(s,16)rep(a,16)rep(c,16){
            memset(O,0,sizeof(O));
            int latte=s;
            double H=0;
            rep(i,N){
                latte=(latte*a+c)%256;
                R[i]=latte;
                O[(L[i]+R[i])%256]++;
            }
            rep(i,256)if(O[i]){
                H-=O[i]*1.0/N*log(O[i]*1.0/N);
            }
            if(mi>1e-9+H){
                S=s;A=a;C=c;
                mi=H;
            }
        }

        cout<<S<<" "<<A<<" "<<C<<endl;
    }
    return 0;
}

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

using namespace std;

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

    while (n > 0) {
        int d = n % 10;
        if (d == 7) {
            cout << "Yes\n";
            return 0;
        }
        n = n / 10;
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000000000000000
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> P;

int main() {
	int a, b, ans = 0;
	char ca[100], cb[100];

	cin >> a;

	if (a < 1000) { cout << "ABC" << endl; }
	else { cout << "ABD" << endl; }
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G
typedef long long ll;
const ll INF=1e18;
const int Mod=998244353;

int n,m; int p[100010];
struct Edge{
	int to,nxt;
}edge[100010];
int cnt,last[100010];
inline void addedge(int x,int y){
	if (x>y) swap(x,y);
	edge[++cnt]=(Edge){y,last[x]},last[x]=cnt;
}
int mxa=-1,mxb=-1,mxc=-1;
int a[100010],b[100010],c[100010];
bool mrk[100010]; int sg[100010];
int main()
{
	n=read();
	p[0]=1; p[1]=INF%Mod; for (int i=2;i<=n;i++) p[i]=1LL*p[i-1]*p[1]%Mod;
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		a[sg[i]]=(a[sg[i]]+p[i])%Mod; mxa=max(mxa,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		b[sg[i]]=(b[sg[i]]+p[i])%Mod; mxb=max(mxb,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	m=read();
	cnt=0; memset(last+1,0,n*sizeof(int));
	for (int i=1;i<=m;i++) addedge(read(),read());
	for (int i=n;i;i--){
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=1;
		for (sg[i]=0;mrk[sg[i]];sg[i]++);
		c[sg[i]]=(c[sg[i]]+p[i])%Mod; mxc=max(mxc,sg[i]);
		for (int j=last[i],v;j;j=edge[j].nxt) mrk[sg[v=edge[j].to]]=0;
	}
	
	int ans=0;
	for (int i=0;i<=mxa;i++)
		for (int j=0;j<=mxb;j++)
			if ((i^j)<=mxc)
				ans=(ans+1LL*a[i]*b[j]%Mod*c[i^j])%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdbool.h>

int main(){
    int i, j, n;
    char mark;
    char marks[4]={'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13]={false};

    scanf("%d ", &n);
    for(i=0;i<n;i++){
        scanf("%c %d ", &mark, &num);
        for(j=0;j<4;j++){
            if(mark==marks[j]){
                cards[j][num-1]=true;
                break;
            }
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(!cards[i][j]){
                printf("%c %d\n", marks[i], j+1);
            }
        }
    }
    return 0;
}


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

using namespace std;

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

map<string, int> mp;

void p(string s) {
  cout << s << " x " << mp[s] << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    mp[s]++;
  }
  p("AC");
  p("WA");
  p("TLE");
  p("RE");
  return 0;
}


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

bool f(long long i , vector<long long> &A , vector<long long> &F , long long K){
  for(int j=0;j<A.size();j++){
    long long x = i/F[j];
    K -= max((long long)0,A[j]-x);
    if(K<0) return false;
  }
  return true;
}

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N),F(N);
  for(int i=0;i<N;i++) cin >> A[i];
  for(int i=0;i<N;i++) cin >> F[i];
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  sort(F.begin(),F.end());
  
  long long l=-1,r=A[0]*F[N-1];
  while(l+1!=r){
    long long i=(l+r)/2;
    if(f(i,A,F,K)) r=i;
    else l=i;
  }
  
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,a[3][N],qz[3][N];
signed main()
{
    n=read();
    for(ri int i=1;i<=2;i++)
    for(ri int j=1;j<=n;j++)
    a[i][j]=read(), qz[i][j]=qz[i][j-1]+a[i][j];

    int res=0;
    for(ri int i=1;i<=n;i++) res=max(res,qz[1][i]+qz[2][n]-qz[2][i-1]);
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3692
class Hit
  def initialize
    @result = []
    while line = $stdin.gets do
      @hit = 0
      @blow = 0
      @a = line.chomp.split(' ').map(&:to_i) 
      @b = $stdin.gets.chomp.split(' ').map(&:to_i) 
      check_hit
      check_blow
      @result.push([@hit, @blow])
    end

    @result.each do |ans|
      puts "#{ans[0]} #{ans[1]}"
    end
  end

  def check_hit
    @a.each_with_index do |a, index|
      if @a[index] == @b[index]
        @hit += 1
        @b[index] = 0
      end
    end
  end

  def check_blow
    @a.each_with_index do |a, index|
      @blow += [@a.count(a), @b.count(a)].min
      @b = @b.map do |n|
        if n == a
          0
        else
          n
        end
      end
    end
  end
end

h = Hit.new

Measured memory_bytes: 2372
#include<iostream>
#include<string>
#include<bitset>
#include<set>
using namespace std;
int N, K;

string cards[100];
set<string> ans;

void dfs(int k, bitset<100> c, string s)
{
  if(k == K)
  {
    ans.insert(s);
    return;
  }
  for(int i = 0 ;i < N; i++)
  {
    if(!c[i])
      continue;
    c[i] = false;
    dfs(k + 1, c, s + cards[i]);
    c[i] = true;
  }
  return;
}

int main()
{
  while(1)
  {
    ans.clear();
    cin >> N >> K;
    if(!N && !K)
      break;
    for(int i = 0; i < N; i++)
      cin >> cards[i];
    dfs(0, bitset<100>(0xFFFF), "");
    cout << ans.size() << endl;
  }
}

Measured memory_bytes: 1460
N=int(input())
A=list(map(int,input().split()))

B=[A[i]-(i+1) for i in range(N)]
B.sort()

B1=[abs(B[i]-B[N//2]) for i in range(N)]
B2=[abs(B[i]-B[N//2-1]) for i in range(N)]

print(min(sum(B1),sum(B2)))

Measured memory_bytes: 34784
def main():
    n, m = map(int, input().split())
    ab = (map(int, input().split()) for _ in range(m))

    # 死因 graph = [[0] * (n+1) for _ in range(n+1)]
    graph = [[] for _ in range(n+1)]

    for a, b in ab:
        graph[a].append(b)
        graph[b].append(a)

    from collections import deque

    q = deque()
    q.append(1)

    p = [0] * (n+1)

    while q:
        a = q.popleft()
        for b in graph[a]:
            if not p[b]:
                p[b] = a
                q.append(b)

    result = p[2:]

    is_yes = all(result)

    print('Yes' if is_yes else 'No')

    if is_yes:
        for r in result:
            print(r)


if __name__ == "__main__":
    main()


Measured memory_bytes: 96276
# -*- coding: utf-8 -*-

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 室温
    """
    X = int(input())

    return X


def main(X: int) -> None:
    """
    メイン処理.

    Args:\n
        X (int): 室温（-40 <= X <= 40, 整数）
    """
    # 求解処理
    ans = str()
    if X >= 30:
        ans = "Yes"
    else:
        ans = "No"

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    X = get_input()

    # メイン処理
    main(X)


Measured memory_bytes: 9104
#include<iostream>
using namespace std;
int main(){
  int X;
  int j;
  cin >> X;
  for(int i = X;i < 130000;i++){
    for(j = 2;j < i;j++){
      if(i % j == 0) break;
    }
    if(i == j){
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
import sys
import math

H =int(sys.stdin.readline())


sqrt = math.sqrt(H)

flag = 0
target = H
keisu = 1
attack = 1
if target == 1:
    print(attack)
else:
    while(flag == 0):
        target = target // 2
        attack += keisu * 2
        keisu = keisu*2
        if target == 1:
            flag = 1
    print(attack)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    int n,m,k;
	cin >> n >> m;
	int a[200];
	for(int i=0;i<2*n;i++)a[i]=i;
	for(int i=0;i<m;i++){
		cin >> k;
		int b[200];
		for(int j=0;j<2*n;j++)b[j]=a[j];
		if(k==0){
			for(int j=0;j<2*n;j++){
				if(j%2==0){
					a[j]=b[j/2];
				}
				else{
					a[j]=b[j/2+n];
				}
			}
		}
		else{
			for(int j=0;j<2*n-k;j++){
				a[j]=b[j+k];
			}
			for(int j=2*n-k;j<2*n;j++){
				a[j]=b[j+k-2*n];
			}
		}
	}
	for(int i=0;i<2*n;i++)printf("%d\n",a[i]+1);
    return 0;
}

Measured memory_bytes: 1148
h,w=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
hw=[[0 for i in range(w)] for j in range(h)]

k=0
for i in range(h):
    if i%2==0:
        for j in range(w):
            if a[k]!=0:
                hw[i][j]=k+1
                a[k]-=1
            else:
                k+=1
                hw[i][j]=k+1
                a[k]-=1
    else:
        for j in range(w-1,-1,-1):
            if a[k]!=0:
                hw[i][j]=k+1
                a[k]-=1
            else:
                k+=1
                hw[i][j]=k+1
                a[k]-=1
for i in range(h):
    for j in range(w):
        if j==w-1:
            print(hw[i][j])
        else:
            print(hw[i][j],end=" ")


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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int t;
  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> t;
    if(t >= a && t < b){
      continue;
    }else{
      count++;
    }
  }
  cout << count << endl;
} 

Measured memory_bytes: 256