akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

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

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

const int maxn = (int) 2e5 + 10;
int inv[maxn];

void precalc() {
  for (int i = 1; i < maxn; ++i) {
    inv[i] = power(i, mod - 2);
  }
}


pair<int, int> a[maxn];

int n;

int X, Y;

int read() {
  if (scanf("%d%d%d", &n, &X, &Y) < 3) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].second, &a[i].first);
    --a[i].second;
  }
  return 1;
}

int minc[maxn];

int cnt[maxn];

void solve() {
  sort(a, a + n);

  for (int i = 0; i < n; ++i) {
    minc[a[i].second] = inf;
    cnt[a[i].second] = 0;
  }

  for (int i = 0; i < n; ++i) {
    int c = a[i].second;
    if (minc[c] == inf) {
      minc[c] = a[i].first;
    } else {
      if (minc[c] + a[i].first <= X) {
        a[i].first = minc[c];
      }
    }
  }

  sort(a, a + n);

  int c = a[0].second;
  int cmn = a[0].first;


  int notc = inf;

  for (int i = 0; i < n; ++i) {
    if (a[i].first + cmn > Y) {
      break;
    }
    if (a[i].second != c) {
      notc = min(notc, a[i].first);
      ++cnt[a[i].second];
    }
  }

  for (int i = 0; i < n; ++i) {
    if (a[i].second != c) {
      continue;
    }
    if (notc + a[i].first <= Y) {
      ++cnt[c];
    }
  }

  int res = 1;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int c = a[i].second;

    int k = cnt[c];
    cnt[c] = 0;

    for (int j = 0; j < k; ++j) {
      ++sum;
      res = mult(res, sum);
      res = mult(res, inv[j + 1]);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 4096
from collections import defaultdict

def main(n,a,s,g):
    edg = [[] for i in range(n)]
    for _ in range(a):
        x,y,lab = input().split()
        x,y = int(x),int(y)
        edg[x].append((y,lab))
    inf = "{"
    dp = [[inf] * 2600 for i in range(n)]
    dp[s][0] = ""
    d = defaultdict(lambda: defaultdict(int))
    X = defaultdict(list)
    X[0] = [s]
    for leng in range(2500):
        for i in set(X[leng]):
            l = dp[i][leng]
            if l == inf: continue
            for e,lab in edg[i]:
                if leng+len(lab) > 2500: continue
                x = l + lab
                if dp[e][leng+len(lab)] > x:
                    d[e][leng+len(lab)] = d[i][leng] | (1 << i)
                    dp[e][leng+len(lab)] = x
                    X[leng+len(lab)].append(e)
    ans = inf
    for i in range(2500):
        if dp[g][i] < ans:
            ans = dp[g][i]
    if ans == inf:
        print("NO")
        return
    for leng in range(10):
        leng += 2400
        for i in range(n):
            l = dp[i][leng]
            for e,lab in edg[i]:
                x = l + lab
                if x < ans and ((d[g][len(ans)] & (1 << e)) or (e == g)):
                    print("NO")
                    return
    print(ans)



if __name__ == "__main__":
    while 1:
        n,a,s,g = map(int, input().split())
        if n == 0: break
        main(n,a,s,g)


Measured memory_bytes: 149456
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi t(n), a(n);
    rep(i, n) {
        cin >> t[i] >> a[i];
    }

    ll tt = 0, aa = 0;
    rep(i, n) {
        if(tt <= t[i] && aa <= a[i]) {
            tt = t[i];
            aa = a[i];
        } else {
            ll g = max(a[i], t[i]);
            ll z = 1, y = INT64_MAX/g;
            
            auto check = [&](ll& x) {
                if(tt <= t[i]*x and aa <= a[i]*x) {
                    return true;
                } else {
                    return false;
                }
            };
            ll x;
            while(y-z != 1) {
                x = (z+y)/2;
                if(check(x)) {
                    y = x;
                } else {
                    z = x;
                }
                //cout << x << endl;
            }


            tt = t[i]*y;
            aa = a[i]*y;
        }
    }

    cout << aa+tt << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var n int

func main() {
	fmt.Scan(&n)

	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
	}
	qs := make([]int, n)
	for i := range qs {
		fmt.Scan(&qs[i])
	}
	p := calc(ps)
	q := calc(qs)

	fmt.Println(abs(p - q))
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func calc(s []int) int {
	l := len(s)
	m := 1
	for i := 1; i <= l; i++ {
		m *= i
	}

	var sum int
	ms := make([]int, n)
	for _, v := range s {
		m /= l
		var cnt int
		for j := 0; j < n; j++ {
			if ms[j] == 0 {
				cnt++
				if j == v-1 {
					break
				}
			}
		}
		sum += m * (cnt - 1)
		ms[v-1] = 1
		l--
	}
	return sum + 1
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//C - Same Integers
int main(void){
   int num[3];
   std::cin >> num[0] >> num[1] >>num[2];
   sort(num,num+3);
   int i=0;
   while(num[0]!=num[1] || num[1]!=num[2]){
       if(num[2]!=num[1] ||num[0]==num[1]){
           num[0]++;
           num[1]++;
       }else{
           num[0]+=2;
           
       }
       sort(num,num+3);
       i++;
   }
   std::cout << i << std::endl;
   //std::cout << num[0] <<num[1]<<num[2]<< std::endl;
    
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
    int x=Integer.parseInt(sc.next());
    int y=Integer.parseInt(sc.next());
   if(x==0&&y==0)break; if(x<=y)System.out.println(x+" "+y);
    if(y<x)System.out.println(y+" "+x);
    
            }
}
}


Measured memory_bytes: 35784
s=input()
ans=0
for i in range(len(s)):
    if s[i]=='U' or s[i]=='D':
        ans+=1
    elif s[i]=='R' and i%2==0:
        ans+=1
    elif s[i]=='L' and i%2==1:
        ans+=1
if ans==len(s):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<iostream>
using namespace std;
const int MaxN = 2e5 + 5;

char mp[55][55];

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	for(int i = 1; i <= h; i++) scanf("%s", mp[i] + 1);
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			if(mp[i][j] == '#') {
				if(i == 1 && j == 1 && mp[i + 1][j] == '.' && mp[i][j + 1] == '.') {
					cout << "No" << endl;
					return 0;
				}
				else if(i == 1 && mp[i + 1][j] == '.' && mp[i][j + 1] == '.' && mp[i][j - 1] == '.') {
					cout << "No" << endl;
					return 0;
				}
				else if(j == 1 && mp[i + 1][j] == '.' && mp[i][j + 1] == '.' && mp[i - 1][j] == '.') {
					cout << "No" << endl;
					return 0;
				}
				else if(mp[i + 1][j] == '.' && mp[i][j + 1] == '.' && mp[i][j - 1] == '.' && mp[i - 1][j] == '.') {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(void){
    int n, m;
    cin>>n>>m;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    int sum=accumulate(v.begin(), v.end(), 0);
    int now=0;
    rep(i, n){
        if(sum%(4*m)==0 && v[i]==sum/(4*m)) now++;
        else if(v[i]>sum/(4*m)) now++;
    }
    if(now>=m) {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int H,W;
    cin >> H >> W;
    bool isEmpty[H][W];
    ll R[H][W];
    ll L[H][W];
    ll U[H][W];
    ll D[H][W];
    for(int yi = 0; yi< H; yi++){
        string tmp;
        cin >> tmp;
        for(int xi = 0;xi < W; xi++){
            isEmpty[yi][xi] = (tmp[xi] == '.');
            R[yi][xi] = -1;
            L[yi][xi] = -1;
            U[yi][xi] = -1;
            D[yi][xi] = -1;
        }
    }
    for(int yi = 0; yi < H; yi++){
        for(int xi = 0; xi < W; xi++){
            if(yi == 0){
                if(isEmpty[yi][xi]){
                    U[yi][xi] = 0;
                }
            }else{
                if(isEmpty[yi][xi]){
                    U[yi][xi] = U[yi - 1][xi] + 1;
                }
            }
        }
    }
    for(int yi = H - 1; yi >= 0; yi--){
        for(int xi = 0; xi < W; xi++){
            if(yi == H - 1){
                if(isEmpty[yi][xi]){
                    D[yi][xi] = 0;
                }
            }else{
                if(isEmpty[yi][xi]){
                    D[yi][xi] = D[yi + 1][xi] + 1;
                }
            }
        }
    }
    for(int xi = 0; xi < W; xi++){
        for(int yi = 0; yi < H; yi++){
            if(xi == 0){
                if(isEmpty[yi][xi]){
                    L[yi][xi] = 0;
                }
            }else{
                if(isEmpty[yi][xi]){
                    L[yi][xi] = L[yi][xi - 1] + 1;
                }
            }
        }
    }
    for(int xi = W - 1; xi >= 0; xi--){
        for(int yi = 0; yi < H; yi++){
            if(xi == W - 1){
                if(isEmpty[yi][xi]){
                    R[yi][xi] = 0;
                }
            }else{
                if(isEmpty[yi][xi]){
                    R[yi][xi] = R[yi][xi + 1] + 1;
                }
            }
        }
    }
    ll M = 1;
    for(int yi = 0; yi < H; yi++){
        for(int xi = 0; xi < W; xi++){
            if(isEmpty[yi][xi]){
                M = max(M,R[yi][xi] + L[yi][xi] + U[yi][xi] + D[yi][xi] + 1);
            }
        }
    }
    cout << M << endl;

}


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

bool f(string& s, ll e){
    rep(i, e/2){
        if (s[i] != s[i+e/2]){
            return false;
        }
    }
    return true;
}

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

    ll i = s.size();
    if (s.size() % 2 ==0){
        i -= 2;
    }else
    {
        i -= 1;
    }
    
    for(;i>0;i-=2){
        if (f(s, i)){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    int n,m;
    cin>>n>>m;
    int sum=0;
    int a=(n*(n-1))/2;
    int b=(m*(m-1))/2;
    if(a>=0)sum+=a;
    if(b>=0)sum+=b;
    cout<<sum<<endl; 
}


Measured memory_bytes: 3612
import itertools

n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]

li=[i for i in range(1,m+1)]
li=list(itertools.combinations_with_replacement(li,n))

result=[]

for j in li:
    ans=0
    for k in abcd:
        t1=k[1]-1
        t2=k[0]-1
        if j[t1]-j[t2]==k[2]:
            ans+=k[3]
    else:
        result.append(ans)

print(max(result))



Measured memory_bytes: 25224
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
typedef vector<i64> vi;
typedef vector<vi> vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n;
  cin >> n;

  vector<f80> p(n);
  rep(i,n) cin >> p[i];

  vector<vector<f80>> dp(n+1,vector<f80>(n+1,0));
  dp[0][0] = 1;

  rep(i,n){
    rep(j,i+1){
      dp[i+1][j] += dp[i][j]*(1-p[i]);
      dp[i+1][j+1] += dp[i][j]*p[i];
    }
  }
  f80 ans = 0;
  rep(i,n+1)
    if(n-i<i) ans += dp[n][i];

  cout << ans << endl;

}

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


Measured memory_bytes: 141056
import numpy as np

N, D = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if j == i:
            continue
        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))
        if dist.is_integer():
            count += 1
print(count // 2)

Measured memory_bytes: 21432
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type node struct {
	key                 int
	parent, left, right *node
}

var tree *node
var wtr = bufio.NewWriter(os.Stdout)

func inorder(u *node) {
	if u == nil {
		return
	}
	inorder(u.left)
	fmt.Fprintf(wtr, " %d", u.key)
	inorder(u.right)
}

func preorder(u *node) {
	if u == nil {
		return
	}
	fmt.Fprintf(wtr, " %d", u.key)
	preorder(u.left)
	preorder(u.right)
}

func printtree(u *node) {
	inorder(u)
	fmt.Fprintf(wtr, "\n")
	wtr.Flush()
	preorder(u)
	fmt.Fprintf(wtr, "\n")
	wtr.Flush()
}

func insert(tree **node, z *node) {
	// zの親になるノードをyとする
	var y *node
	// zの親になるノードを探す
	x := *tree
	for x != nil {
		y = x //仮親を設定
		if z.key < x.key {
			x = x.left
		} else {
			x = x.right
		}
	}
	z.parent = y  // zの親をyにする
	if y == nil { // tが空の場合(木に追加される最初の要素)
		*tree = z
	} else if z.key < y.key {
		y.left = z // zをyの左の子にする
	} else {
		y.right = z // zをyの右の子にする
	}
}

func find0(u *node, key int) bool { // 単純全探索 - TLEする
	if u == nil {
		return false
	}
	if u.key == key {
		return true
	}
	if u.left != nil {
		if find(u.left, key) {
			return true
		}
	}
	if u.right != nil {
		if find(u.right, key) {
			return true
		}
	}
	return false
}

func find(u *node, key int) bool { // keyを頼りに2分探索する
	if u == nil {
		return false
	}
	if u.key == key {
		return true
	}
	if key > u.key {
		if find(u.right, key) {
			return true
		}
	} else {
		if find(u.left, key) {
			return true
		}
	}
	return false
}

type cmd struct {
	command string
	key     int
}

func main() {
	var N int
	fmt.Scan(&N)
	var tree *node
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	// ans := make([]bool, 0)
	cmds := make([]cmd, N)
	for i := 0; i < N; i++ {
		sc.Scan()
		cmds[i].command = sc.Text()
		if cmds[i].command == "insert" || cmds[i].command == "find" {
			sc.Scan()
			cmds[i].key, _ = strconv.Atoi(sc.Text())
		}
	}
	for i := 0; i < N; i++ {
		if cmds[i].command == "insert" {
			z := new(node)
			z.key = cmds[i].key
			insert(&tree, z)
		} else if cmds[i].command == "find" {
			if find(tree, cmds[i].key) {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		} else if cmds[i].command == "print" {
			printtree(tree)
		}
	}
}



Measured memory_bytes: 40760
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

long long gcd(long long a, long long b) {
  if(a % b == 0) {
    return b;
  }
  long long d;
  a = a % b;
  swap(a, b);
  d = gcd(a, b);
  return d;
}

long long N, M;
long long a[100000];

int main() {
  cin >> N >> M;
  rep(i, N) {
    cin >> a[i];
  }
  rep(i, N) {
    a[i] /= 2;
  }
  long long l = a[0];
  rep(i, N-1) {
    long long d = gcd(l, a[i+1]);
    l = l * a[i+1] / d;
  }
  
  rep(i, N) {
    if((l / a[i]) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long ans;
  ans = M / l;
  if(ans % 2 == 0) {
    ans = ans / 2;
    cout << ans << endl;
  } else {
    ans = (ans + 1) / 2;
    cout << ans << endl;
  }
  // cout << l << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int vec[N];
  
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec, vec + N);
  
  cout << vec[N/2] - vec[N/2 - 1] << endl; 
  
       
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    int K = 0;
    for(int i=1; i<=N; i++){
        if(i*(i+1)/2 >= N){
            K = i;
            break;
        }
    }
    
    for(int i=1; i<=K; i++){
        if(i == K*(K+1)/2 - N) continue;
        cout << i << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}


class Program
{
    static void Main()
    {
        int[] xyzk = Console.ReadLine().ToIntArray();
        int X = xyzk[0];
        int Y = xyzk[1];
        int Z = xyzk[2];
        int K = xyzk[3];

        long[] ListA = Console.ReadLine().ToLongArray().OrderByDescending(n => n).ToArray();
        long[] ListB = Console.ReadLine().ToLongArray().OrderByDescending(n => n).ToArray();
        long[] ListC = Console.ReadLine().ToLongArray().OrderByDescending(n => n).ToArray();

        long[] ListAB = new long[X * Y];
        long[] ListABC = new long[K * Z];

        int i = 0;
        foreach(var a in ListA)
        foreach(var b in ListB)
        {
            ListAB[i] = a + b;
            i++;
        }
        Array.Sort(ListAB, (a, b) => Comparer<long>.Default.Compare(b, a));

        i = 0;

        foreach(var ab in ListAB.Take(K))
            foreach(var c in ListC)
        {
                ListABC[i] = ab + c;
                i++;
        }

        Array.Sort(ListABC, (a, b) => Comparer<long>.Default.Compare(b, a));

        i = 0;
        for(i = 0; i < K; i++)
        {
            Console.WriteLine(ListABC[i]);
        }
    }
}

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

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int N;
    cin >> N;
    for(int i=1;i<=50000;i++){
        if(floor(i*1.08)==N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


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

namespace AtCoder
{
    class Abc166C
    {
        public static void Main()
        {
            var nm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = nm[0];
            var m = nm[1];
            var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var max = new int[n];

            for (int i = 0; i < m; i++)
            {
                var ab = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray();
                if (max[ab[0]] < h[ab[1]])
                    max[ab[0]] = h[ab[1]];
                if (max[ab[1]] < h[ab[0]])
                    max[ab[1]] = h[ab[0]];
            }

            int count = 0;
            for (int i = 0; i < n; i++)
                if (max[i] < h[i])
                    count++;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 49488
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main() {
	ll N, K;
	cin >> N >> K;

	vec<ll> d(K, 0);
	for(int i = 1; i <= N; ++i) d[i%K]++;

	ll ans = 0;
	for(ll a = 0; a < K; ++a) {
		ll b = (-a + K * (ll)2e5) % K;
		ll c = (-a + K * (ll)2e5) % K;
		if ((b + c) % K != 0)continue;
		ans += d[a] * d[b] * d[c];
	}

	OUT(ans);
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int num = 0;
		if(a==b&&b==c){
		    num = 2;
		}else{
    		if(a==b){
    		    num++;
    		}
    		if(a==c){
    		    num++;
    		}
    		if(b==c){
    		    num++;
    		}
		}
		
		int kind = 3-num;
		// 出力
		System.out.println(kind);
    }
}


Measured memory_bytes: 9804
#include <stdio.h>
int main(void){
    char buf[100];
    int a;
    int b;
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d %d",&a,&b);
    
    
    int c;
    c = a - 1;
    int d;
    d = b - 1;
    
    int e = (a*c)/2;
    int f = (b*d)/2;
    
    
    int ans;
    ans = e + f;
    
    printf("%d",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int n;
  int ans = 0;
  
  cin >> n;
  vector<int> a(n);

  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  //二番目の値が中央値だった時、ansをカウントする
  for (int i = 1; i < n-1; ++i) {
    if (a[i-1] < a[i] && a[i] < a[i+1]) ++ans;
    else if (a[i-1] > a[i] && a[i] > a[i+1]) ++ans;
  }

  cout << ans << endl;
}


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

int main(){
    int N,K,Ans=0;
    cin>>N>>K;
    vector<int> d(K),ans(N,0);
    for(int i=0;i<K;i++){
        cin>>d.at(i);
        vector<int> A(d.at(i));
        for(int j=0;j<d.at(i);j++){
            cin>>A.at(j);
            ++ans.at(A.at(j)-1);
        }
    }

    for(int i=0;i<N;i++){
        if(ans.at(i)==0){
            ++Ans;
        }
    }

    cout<<Ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
const ll INF=4e18;
void solve()
{
	ll N;
	cin>>N;
	if(N%2)
	{
		cout<<0<<"\n";
		return;
	}
	ll val=10,ans=0;
	while(val<=N)
	{
		ans+=(N/val);
		val*=5;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main(void){

    int w, a, b;
    cin >> w >> a >> b;

    if(a > b){
        swap(a, b);
    }

    int ans = a+w-b;
    if(ans < 0){
        cout << -ans << "\n";
    }else{
        cout << 0 << "\n";
    }

    return 0;
}


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

int main(){
	int n,x;
	cin>>n>>x;
	vector<int>arr(n);
	long long ret = 0;
	for(int i=0; i<n; i++) cin>>arr[i];
	arr.push_back(0);
	for(int i=0; i<n; i++){
		if(arr[i]+arr[i+1]>x){
			int remove = arr[i]+arr[i+1]-x;
			ret+=remove;
			arr[i+1]-=min(arr[i+1],remove);
		}
	}
	cout<<ret;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long A,B;
  int maxi = 1;
  cin >> A >> B;
  for(int i = 1; i < 10*10*10*10*10; i++){
    if((A % i == 0) && (B % i == 0)){
      if(maxi < i){
      maxi = i;
      }
    }else if(A < i || B < i){
      break;
    }
  }
    cout << (A / maxi) * (B / maxi) * maxi << endl;
}
  

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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a%b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

int dp[500][500];

string t;
int recur(int pos,int last)
{

    if(pos==(int)t.size())
    {

        return 0;
    }

    if(dp[pos][last]!=-1){
        return dp[pos][last];
    }

    int mn=1e17;

    for(int i='a'; i<='z'; i++)
    {
        if(i!=last)
        {
            mn=min(mn,(t[pos]!=i)+recur(pos+1,i));
        }
    }

    return dp[pos][last]=mn;

}

void solve()
{

    long long k;
    cin>>t>>k;

    set<char> items;

    for(auto z:t){
        items.insert(z);
    }

    if(t.size()==1){

        cout<<k/2<<endl;
        return;
    }

    if(items.size()==1){
        cout<<((long long)t.size()*k)/2ll<<endl;
        return;
    }



    SET(dp);

    long long ans=recur(1,t.front());
    t+=t;
    SET(dp);
    long long dblans=recur(1,t.front());
    long long res=ans*k;

    debug(ans,dblans);

    if(ans*2ll!=dblans){
        res+=k-1ll;
    }


    cout<<res<<endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<algorithm>
using namespace std;
int dat[5000][5];
int m[5];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<5000;i++)
			for(int j=0;j<5;j++)dat[i][j]=0;
		for(int i=0;i<5;i++)m[i]=0;
		int count=0;
		for(int p=0;p<a;p++){
			int b,c,d;
			scanf("%d%d%d",&b,&c,&d);d--;
			count+=c;
			if(b==2){
				for(int i=0;i<c;i++){
					dat[m[d]][d]=1;
					bool ok=true;
					for(int j=0;j<5;j++)if(!dat[m[d]][j])ok=false;
					if(ok){
						for(int j=0;j<5;j++){
							dat[m[d]][j]=0;
							for(int k=m[d];k<4999;k++)dat[k][j]=dat[k+1][j];
							for(int k=4999;k>=0;k--){
								if(dat[k][j]){
									m[j]=k+1;break;}
								if(k==0)m[j]=0;
							}
						}
						count-=5;
					}else m[d]++;
				//	m[d]++;
				}
				//m[d]+=c;
			}else{
				int h=0;
				for(int i=0;i<c;i++)h=max(h,m[i+d]);
				for(int i=0;i<c;i++)dat[h][i+d]=1;
				for(int i=0;i<c;i++)m[i+d]=h+1;
				bool ok=true;
				for(int j=0;j<5;j++)if(!dat[h][j])ok=false;
				if(ok){
					for(int j=0;j<5;j++){
						dat[h][j]=0;
						for(int k=h;k<4999;k++)dat[k][j]=dat[k+1][j];
						for(int k=4999;k>=0;k--){
							if(dat[k][j]){m[j]=k+1;break;}
							if(k==0)m[j]=0;
						}
					}
					count-=5;
				}
			}
	//		for(int i=6;i>=0;i--,printf("\n"))for(int j=0;j<5;j++)printf("%d",dat[i][j]);
	//		printf("\n");
		}
		printf("%d\n",count);
	}
}

Measured memory_bytes: 1124
import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    ans = 0
    for A in range(1, N):
        ans += N // A
        if N % A == 0:
            ans -= 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9948
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int a= Integer.parseInt(i[0]);
		int b= Integer.parseInt(i[1]);
		double c=(double)a/(double)b;
		System.out.print(a/b+" "+a%b+" ");
		System.out.printf("%.8f\n",c);
	}
}

Measured memory_bytes: 17080
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define str string
#define sec .second
 
ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30;
ll A[1000000] = {}, B[1000000] = {}, weight[1000] = {}, value[1000] = {};
ll dp[1000][100100] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, n = 0, su = 0, ma = INF, mi = -1;
double ans;
pair<str, ll> S[1000];
bool an = true, bn = false;
long long mod = 1e9 + 7;
 
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;
}
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Code Line
	cin >> n >> a;
	for (int i = 0; i < n; i++)cin >> weight[i] >> value[i];
 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= a; j++) {
			
			if (j >= weight[i])dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i + 1][j]);
			dp[i + 1][j] = max(dp[i][j],dp[i+1][j]);
		}
	}
	cout << dp[n][a] << endl;
 
		return 0;
}


Measured memory_bytes: 81408
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
void stat();
constexpr ll mod = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    vec<int> v(n);
    rep(i, n)
    {
        int a;
        cin >> a;
        v[i] = --a;
    }
    ll ans = 0;
    int next = 0;
    rep(i, n)
    {
        if (v[next] == 1)
        {
            cout << ans+1 << endl;
            return 0;
        }
        ++ans;
        next = v[next];
    }
    cout << -1 << endl;
    return 0;
}
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat()
{
#ifdef local
    rep(i, 2) { std::cout << "local enable" << std::endl; }
#endif
#ifdef hacks
    rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}


Measured memory_bytes: 3704
#include <stdio.h>
int main(void)
{
    long int n, m, l[100000], r[100000], i, maxl=-1, minr=10000000, ans;
    scanf("%ld %ld", &n, &m);
    for(i=0;i<m;i++){
        scanf("%ld %ld", &l[i], &r[i]);
    }
    for(i=0;i<m;i++){
        if(l[i]>maxl) maxl=l[i];
        if(r[i]<minr) minr=r[i];
    }
    if(maxl>minr) ans=0;
    else ans=minr-maxl+1;
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 1664
#include<string>
#include <vector>
#include<iostream>
#include <algorithm>
#include <functional>

using namespace std;
int n;
string name;
int price;
int a;
int b;
int c;
int d;
int e;
int seedCount;
int seedPrice;
int Time;

struct G{
	string name;
	double value;
};
bool operator>(const G& left, const G& right)
{
	if(left.value>right.value){
		return true;
	}else if(left.value<right.value){
		return false; 
	}else{
		return left.name<right.name;
	}
}

bool operator<(const G& left, const G& right)
{
  	if(left.value>right.value){
		return false;
	}else if(left.value<right.value){
		return true; 
	}else{
		return left.name>right.name;
	}
}



int main(){
	while(true){
		cin >>n;
		vector<G> s;
		if(n==0){
			break;
		}
		for(int i=0;i<n;i++){
			cin >>name;
			cin >>price;
			cin >>a;
			cin >>b;
			cin >>c;
			cin >> d;
			cin >> e;
			cin >> seedCount;
			cin >> seedPrice;
			cin >> Time;
			struct G g ={name,(double)(Time*seedCount*seedPrice-price)/((a+b+c)+(d+e)*Time)};
			s.push_back(g);
		}
		std::sort(s.begin(),s.end(),std::greater<G>());//昇順ソート

		for(int i=0;i<n;i++){
			
			cout << s[i].name <<endl;
		}
		cout << "#" <<endl;
	}
}

Measured memory_bytes: 1220
import collections
import sys
def input(): return sys.stdin.readline().rstrip()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
count = 0
prime_list = collections.Counter(prime_factorize(N))

for key in prime_list:
    num = prime_list[key]
    for i in range(1, num+1):
        if i <= num:
            num -= i
            count += 1
        else:
            break

print(count)

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

int main() {
    int a, b;
    cin >> a >> b;

    // b の桁
    int d;
    if (b < 10) d = 10;
    else if (b < 100) d = 100;
    else d = 1000;

    int num = a*d + b;
    
    bool ans = false;
    for (int i = 0; i < num; i++) {
        if (num == i*i) {
            ans = true;
            break;
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s1, s2, s3 string
	fmt.Scan(&s1, &s2, &s3)
	fmt.Printf("%s%s%s", strings.ToUpper(s1[0:1]), strings.ToUpper(s2[0:1]), strings.ToUpper(s3[0:1]))
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b){
  return *(int*)b-*(int*)a;
}
int main(void){
  int n,i,s=0;
  scanf("%d",&n);
  int l[n];
  for(i=0;i<n;scanf("%d",&l[i++]));
  qsort(l,n,sizeof(int),comp);
  for(i=1;i<n;s+=l[i++]);
  if(s>l[0])printf("Yes");
  else printf("No");
}


Measured memory_bytes: 128
import math

# K = 1
# A, B = 11, 11

K = int(input())
A, B = map(int, input().split())

a = math.ceil(A/K)
# b = B//K
C = K * (a)

# if K > B:
    # print ("NG")


if C <= B:
    print ("OK")
else:
    print ("NG")

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, d; cin >> n >> d;

    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            int t = 0;
            for (int k = 0; k < d; ++k) {
                t += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
            }

            for (int l = 0; l < 20000; ++l) {
                if (l * l == t) ++ans;
            }
        }
    }

    cout << ans << endl;
}

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

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

int main() {
  int N; cin >> N;
  vector<int> ans(N);
  rep(i, N - 1) {
    int tmp; cin >> tmp;
    ++ans[tmp - 1];
  }
  for (int i = 0; i < N; ++i) cout << ans[i] << "\n";
}


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

using namespace std;


int main(void){

	string A,B;
	bool f;

	cin>>A>>B;

	f=false;
	for(int i=0;i<=A.size()-B.size();i++){
		for(int j=0;j<=B.size()-1;j++){
			if(A[i+j]!=B[j]&&B[j]!='_') break;
			if(j==B.size()-1) f=true;
		}
		if(f) break;
	}

	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 1188
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
UVW = zip(m,m,m)

# 木が保証されているので、必ず実現できる

graph = [[] for _ in range(N+1)]
for u,v,w in UVW:
    graph[u].append((v,w))
    graph[v].append((u,w))

color = [0] * (N+1)
stack = [1]
parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y,w in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        color[y] = color[x]^(w&1)
        stack.append(y)

print('\n'.join(map(str,color[1:])))

Measured memory_bytes: 52080
N = int(input())

result_dic = dict(AC=0, WA = 0, TLE = 0, RE = 0)

for n in range(N):
  s = input()
  
  result_dic[s] += 1
  
print("AC x " + str(result_dic['AC']))
print("WA x " + str(result_dic['WA']))
print("TLE x " + str(result_dic['TLE']))
print("RE x " + str(result_dic['RE']))


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  vector<int> count(m),now(n),updated(n);
  bool okflag,ngflag;
  for(int k=1;k<=n;k++){
    // cout << k << endl;
    for(int i=0;i<m;i++) count[i]=0;
    for(int i=0;i<n;i++) now[i]=0,updated[i]=1;
    ngflag=false;
    while(1){
      okflag=true;
      for(int i=0;i<n;i++){
        if(updated[i]==1){
          count[a[i][now[i]]]++;
          updated[i]=0;
        }
      }
      // for(int i=0;i<n;i++){
      //   cout << a[i][now[i]] << " ";
      // }
      // cout << endl;
      // for(int i=0;i<m;i++){
      //   cout << count[i] << " ";
      // }
      // cout << endl;
      for(int i=0;i<n;i++){
        if(count[a[i][now[i]]]>k){
          while(count[a[i][now[i]]]>k){
            if(now[i]==m-1){
              ngflag=true;
              break;
            }
            now[i]++;
          }
          updated[i]=1;
          okflag=false;
        }
      }
      if(ngflag) break;
      if(okflag){
        cout << k << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    bool n[4] = {false};
    if(a == 1 || b == 1 || c == 1 || d == 1){
        n[0] = true; 
    }
    if(a == 9 || b == 9 || c == 9 || d == 9){
        n[1] = true; 
    }
    if(a == 7 || b == 7 || c == 7 || d == 7){
        n[2] = true; 
    }
    if(a == 4 || b == 4 || c == 4 || d == 4){
        n[3] = true; 
    }

    if(n[0] && n[1] && n[2] && n[3]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N, Y;
    cin >> N >> Y;

    for (int x = 0; x <= N; x++) {
        for (int y = 0; x + y <= N; y++) {
            int z = N - (x + y);
            if (x * 10000 + y * 5000 + z * 1000 == Y) {
                printf("%d %d %d\n", x, y, z);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

vector<string> cands;
vector<string> temp;

void dfs(int last, string str)
{
 //   cout << str << endl;
    if(last >= 6)
    {
        cands.push_back(str);
        return;
    }
    
    if(last % 2 == 0)
    {
        dfs(last + 1, str + temp[last + 1]);
    }
    else
    {
        dfs(last + 1, str);
        dfs(last + 1, str + temp[last + 1]);
    }
    
    
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    temp.push_back("A");
    temp.push_back("KIH");
    temp.push_back("A");
    temp.push_back("B");
    temp.push_back("A");
    temp.push_back("R");
    temp.push_back("A");
    
    dfs(-1, "");
    
    for(auto str : cands)
    {
        if(str == s)
        {
            cout << "YES"; return 0;
        }
    }
    
    cout << "NO";
    return 0;
}


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

public class Main {
	public void run() throws Exception {
		FastReader file = new FastReader();
		long n = file.nextLong(), k = file.nextLong();
		long div = n / k;
		System.out.println(Math.min(Math.abs(n - div * k - k), n - div * k));
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 21204
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
 
 
 
int main() {
    
    fastio;
    int n, w;
    cin >> n >> w;
    ll wt[n], v[n];
    rep(i, n)
    cin >> wt[i] >> v[i];
    ll dp[n+1][w+1];
    rep(i, n+1)
    {
        rep(j, w+1)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(wt[i-1] <= j)
                dp[i][j] = max(v[i-1]+dp[i-1][j-wt[i-1]], dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][w];
    return 0; 
}

Measured memory_bytes: 79232
#include <iostream>

using namespace std;

int min(int a, int b) {
	if (a < b)
		return a;
	else
		return b;
}

int max(int a, int b) {
	if (a > b)
		return a;
	else
		return b;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int minv, midv, maxv;
	minv = min(min(a, b), c);
	maxv = max(max(a, b), c);
	
	int t1 = max(a, b);
	int t2 = max(b, c);
	int t3 = max(a, c);
	midv = min(min(t1, t2), t3);

	cout << minv << " " << midv << " " << maxv << endl;

	return 0;
}


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

using namespace std;

int main() {
    long long A,B,K;
    cin >> A >> B >> K;

    if (K <= A) {
        A -= K;
    } else if (K > A && K <= A+B) {
        B -= K-A;
        A = 0;
    } else {
        A = 0;
        B = 0;
    }

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 3548