akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int[][] A;
	int[] b;
	int N;
	boolean result = true;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		this.A = new int[3][3];
		for (int i = 0; i < 3; ++i) {
			String[] tokens = in.readLine().split(" ");
			for (int j = 0; j < 3; ++j) {
				A[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		N = Integer.parseInt(in.readLine());
		b = new int[N];
		for (int i = 0; i < N; ++i) {
			b[i] = Integer.parseInt(in.readLine());
		}

	}

	void replace(int val) {
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				if (A[i][j] == val) {
					A[i][j] = 0;
				}
			}
		}
	}

	boolean check() {
		boolean result = false;
		// 横
		for (int i = 0; i < 3; ++i) {
			boolean cond = true;
			for (int j = 0; j < 3; ++j) {
				if (A[i][j] != 0) {
					cond = false;
					break;
				}
			}
			if (cond) {
				result = true;
			}
		}
		// たて
		for (int j = 0; j < 3; ++j) {
			boolean cond = true;
			for (int i = 0; i < 3; ++i) {
				if (A[i][j] != 0) {
					cond = false;
					break;
				}
			}
			if (cond) {
				result = true;
			}
		}
		// 斜め
		boolean condA = true;
		for (int i = 0; i < 3; ++i) {
			if (A[i][i] != 0) {
				condA = false;
				break;
			}
		}
		if (condA) {
			result = true;
		}
		condA = true;
		for (int i = 0; i < 3; ++i) {
			if (A[i][2 - i] != 0) {
				condA = false;
				break;
			}
		}
		if (condA) {
			result = true;
		}
		return result;
	}

	void calc() {
		for (int i = 0; i < N; ++i) {
			replace(b[i]);
		}
		this.result = check();
	}

	void showResult() {
		System.out.println((result ? "Yes" : "No"));
	}

}


Measured memory_bytes: 23124
#!/usr/bin/env python3
import string
n = int(input())
f = [ float('inf') ] * 26
for _ in range(n):
    s = input()
    for i, c in enumerate(string.ascii_lowercase):
        f[i] = min(f[i], s.count(c))
for i, c in enumerate(string.ascii_lowercase):
    print(c * f[i], end='')
print()


Measured memory_bytes: 3832
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int a[N];
   for(int i=0; i<N; ++i)
      std::cin >> a[i];

   int count = 0;
   for(int i=0; i<N-1; ++i){
      if(a[i]==a[i+1]){
	 ++count;
	 ++i;
      }
   }
   std::cout << count << std::endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    val t = sc.next()
    println(problem148b(n, s, t))
}

fun problem148b(n: Int, s: String, t: String): String {
    var str = ""
    for (i in 0 until n) {
        str += s[i].toString() + t[i].toString()
    }
    return str
}

Measured memory_bytes: 31136
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int main(){
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
	return 0;
}


Measured memory_bytes: 3108
main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  ai <- map (read :: String -> Int) . words <$> getLine
  putStrLn $ show $ ans ai

ans :: [Int] -> Int
ans ai = (\(a,b,c,d) -> if b == 1 then d-2*a else d) $ foldl func (10^5+1,0,False,0) ai where
  func (mi,minusN,if0,sumabs) k
    | k == 0 || if0 = (mi,0,True,sumabs + abs k)
    | k < 0 = (min mi (abs k),mod (1+minusN) 2,if0,sumabs + abs k)
    | otherwise = (min mi k,minusN,if0,sumabs + abs k)

Measured memory_bytes: 81276
#include <cstdio>
 
int main()
{
    int matrix[4][4];
 
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            scanf("%d", &matrix[i][j]);
 
    int A[4];
    int B[4];
 
    A[1] = 5;
    B[1] = matrix[1][1] - A[1];
    B[2] = matrix[1][2] - A[1];
    B[3] = matrix[1][3] - A[1];
    A[2] = matrix[2][1] - B[1];
    A[3] = matrix[3][1] - B[1];
 
    int is_possible = true;
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            if(A[i] + B[j] != matrix[i][j])
                is_possible = false;
 
    printf(is_possible ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import math 
MOD = 10**9+7
def comb(n,k):
    nCk = 1
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

def main():
    N,A,B = map(int,input().split())
    print((pow(2,N,MOD)-1-comb(N,A)-comb(N,B))%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
typedef long long Int;

Int H, W, K, h, w, v;
Int dp[5500][5500][4], fld[5500][5500];

int main() {
  cin >> H >> W >> K;
  for (int _ = 0; _ < K; _++) {
    cin >> h >> w >> v;
    fld[h - 1][w - 1] = v;
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      Int v = fld[i - 1][j - 1];
      for (int k = 0; k < 4; k++) {
        dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
        if (0 < i) {
          dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + v);
        }
        dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
        if (0 < k - 1) {
          dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + v);
        }
      }
    }
  }

  Int ans = 0;
  for (int i = 0; i < 4; i++) {
    ans = max(ans, dp[H][W][i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 376464
#pragma GCC optimize("O2") 
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;

int main(){
	//freopen("in.txt","r",stdin);    
	ios::sync_with_stdio(0); cin.tie(0);
	LL A,B,C,D;
	cin >> A >> B >> C >> D;
	LL ans = B-A+1;
	--A;
	LL a = B/C - A/C;
	LL b = B/D - A/D;
	LL lcm = C/__gcd(C, D)*D; 
	LL c = B/lcm - A/lcm;
	cout << ans - (a+b-c) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string a = "CODEFESTIVAL2016", b;
	int ans = 0;
	cin >> b;
	REP(i, 16) {
		if (a[i] != b[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A, B, C = MAP()

if any(x%2 for x in [A, B, C]):
	print(0)
	exit()
elif A == B == C:
	print(-1)
	exit()

cnt = 0
while 1:
	a = (B+C)/2
	b = (A+C)/2
	c = (A+B)/2
	cnt += 1
	if any(x%2 for x in [a, b, c]):
		print(cnt)
		break
	else:
		A, B, C = a, b, c



Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int_Max 2147483647
#define ll_Max 9223372036854775807
#define REP(i,f,n) for(int i=f; i<(n); i++)

ll sigu(ll a){
  ll ans = 0;
  REP(i,1,a + 1){
    ans += i;
  }
  return ans;
}

int main()
{
  ll ans = 0, cnt = 0, muki = 0, maenaga = -1;
  string s;

  cin >> s;

  ll n = s.length(), v[n+1];
  REP(i,0,n){
    if(s[i] == '<'){
      if(muki!=-1){
        ans += sigu(cnt) -cnt;
        if(maenaga > cnt)ans += maenaga;
        else ans += cnt;
        cnt=0;
        muki = -1;
      }
      cnt++;
    }else{
      if(muki!=1){
        ans += sigu(cnt) - cnt;
        maenaga = cnt;
        cnt=0;
        muki = 1;
      }
      cnt++;
    }
  }
  ans += sigu(cnt) - cnt;
  if(s[n-1]=='>'){
    if(maenaga > cnt)ans += maenaga;
    else ans += cnt;
  }else{
    ans += cnt;
  }
  cout << ans << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 4268
#include <stdio.h>

int main() {
	int N, X, L[100], i, cnt = 1, zahyou;

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

	i = 1;
	zahyou = L[0];
	while (zahyou <= X && i < N) {
		zahyou = zahyou + L[i];
		i++;
		cnt++;
	}

	if (zahyou <= X) {
		cnt++;
	}

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

	return 0;
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


int main(){
    int mod=2019;
    string S;
    cin>>S;
    int n;
    n=S.size();
    reverse(S.begin(),S.end());
    map<int,int> M;
    int mul=1;
    int pre=0;
    M[0]++;
    rep(i,n){
        int t=pre+(S[i]-'0')*mul;
        t%=mod;
        M[t]++;
        mul=(mul*10)%mod;
        pre=t;
 //       cout<<t<<" ";
    }
//    cout<<endl;
    ll ans=0;
    for(pair<int,int> p : M){
        ans+=p.S*(p.S-1)/2;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3752
n,m=map(int,input().split())
c=list(map(int,input().split()))
dp=[10**5 for i in range(50001)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
    for j in range(m):
        if i>=c[j]:
            dp[i]=min(dp[i-c[j]]+1,dp[i])
print(dp[n])


Measured memory_bytes: 7384
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  int u, v; cin >> u >> v;
  --u, --v;

  vvi edge(N, vi());
  int d[N], d2[N];
  rep(i, N)
    d[i] = d2[i] = INF;
  d[u] = 0;
  d2[v] = 0;

  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  stack<int> st;
  st.push(u);
  while(!st.empty()) {
    int p = st.top(); st.pop();
    for (const auto& e : edge[p]) {
      if (d[e] != INF)
        continue;
      d[e] = d[p] + 1;
      st.push(e);
    }
  }

  st.push(v);
  while(!st.empty()) {
    int p = st.top(); st.pop();
    for (const auto& e : edge[p]) {
      if (d2[e] != INF)
        continue;
      d2[e] = d2[p] + 1;
      st.push(e);
    }
  }
  int ans = 0;
  rep(i, N) {
    if (d2[i] >= d[i]) {
      debug(i+1 << ": " << d[i] << " " << d2[i]);
      ans = max(d2[i]-1, ans);
    }
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 6656
object Main extends App {

  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val line = readLine.trim
    if (line == "0") return
    val nums = line.split(' ').map(_.toInt)
    if (solve(nums(1), nums.drop(2))) println(1)
    else println(0)
    solve
  }
  def solve(stone: Int, players: Array[Int]): Boolean = {
    val memo = Array.tabulate(stone + 1){_ ⇒ Array.tabulate(players.length + 1){_ ⇒ None: Option[Boolean]}}
    def canWin(restStone: Int, currentPlayer: Int): Boolean = {
      if (restStone - 1 <= players(currentPlayer)) currentPlayer % 2 == 0
      else {
        memo(restStone)(currentPlayer) match {
          case None if currentPlayer % 2 == 0 ⇒ (1 to players(currentPlayer)).reverse.exists(take ⇒ canWin(restStone - take, (currentPlayer + 1) % players.length)).also(r ⇒ memo(restStone)(currentPlayer) = Some(r))
          case None ⇒ (1 to players(currentPlayer)).reverse.forall(take ⇒ canWin(restStone - take, (currentPlayer + 1) % players.length)).also(r ⇒ memo(restStone)(currentPlayer) = Some(r))
          case Some(r) ⇒ r
        }
      }
    }
    for (r ← 0 until stone by 100) canWin(r, 0)
    canWin(stone, 0)
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
    @inline
    def takeIf(@inline predicate: T ⇒ Boolean): Option[T] = Some(value).filter(predicate)
  }
}


Measured memory_bytes: 139512
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 1000000;
	public static int[] count = new int[MAX];
	
	public static int[] array = new int[6];
	public static int s_len = -1;
	public static int s_max = Integer.MIN_VALUE;
	
	public static int dps(int target, String in, int sum, LinkedList<Integer> list){
		//System.out.println(list);
		
		if("".equals(in)){
			if(target >= sum){
				count[sum]++;
				
				if(s_max < sum){
					int count = 0;
					for(int k : list){
						array[count] = k;
						count++;
					}
					s_len = list.size();
					
					s_max = sum;
				}
				
				return sum;
			}else{
				return Integer.MIN_VALUE;
			}
		}else{
			int max = Integer.MIN_VALUE;
			
			for(int i = 1; i <= in.length(); i++){
				final int t = Integer.parseInt(in.substring(0, i));
				
				if(sum + t <= target){
					list.addLast(t);
					max = Math.max(max, dps(target, in.substring(i), sum + t, list));
					
					list.removeLast();
				}
			}
			
			return max;
		}
	}
	
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		while(true){
			final int t = sc.nextInt();
			final String in = sc.next();
			
			if(t == 0 && "0".equals(in)){
				break;
			}
			
			Arrays.fill(count, 0);
			s_len = -1;
			s_max = Integer.MIN_VALUE;
			Arrays.fill(array, Integer.MIN_VALUE);
			
			int result = dps(t, in, 0, new LinkedList<Integer>());
			
			if(result == Integer.MIN_VALUE){
				System.out.println("error");
			}else if(count[result] > 1){
				System.out.println("rejected");
			}else{
				System.out.print(result);
				for(int i = 0; i < s_len; i++){
					System.out.print(" " + array[i]);
				}
				System.out.println();
			}
			
		}
	}

}

Measured memory_bytes: 24588
import numpy as np
N=int(input())
A = list(map(int,input().split()))
Aa = np.array(A) %4
if np.count_nonzero(Aa%4==2)==0 and N//2-np.count_nonzero(Aa%4==0)>0:
    print("No")
elif np.count_nonzero(Aa%4==2)==0 and N//2-np.count_nonzero(Aa%4==0)<=0:
    print("Yes")
elif np.count_nonzero(Aa%4==2)!=0:
    if N%2==np.count_nonzero(Aa%4==2)%2 and np.count_nonzero(Aa%2==1)-np.count_nonzero(Aa%4==0)>0:
        print("No")
    elif N%2 != np.count_nonzero(Aa%4==2)%2 and np.count_nonzero(Aa%2==1)+1-np.count_nonzero(Aa%4==0)>0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 23136
#include <iostream>
#include <cmath>

using namespace std;

int a, b, c, d;

int main()
{
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import shortest_path
import heapq
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append([w, v])
    edge[v].append([w, u])

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

Path_from_0 = dijkstra_heap(0)
for i in range(n):
    print(Path_from_0[i] % 2)



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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 60, mod = 1e9 + 7;

LL n, m;

bool check(LL x)
{
    LL tn = n, tm = m;
	if(tn < x) tm -= 2 * (x - tn);
	return tm >= 2 * x;
}

int main()
{
    cin >> n >> m;

    LL l = 0, r = 1e12;
    while(l < r)
    {
        LL mid = l + r + 1 >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }

    cout << l << endl;
    return 0;
}


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

 int N, K, p[1010];

 int main(){
 cin >> N >> K;
 for(int i = 0; i < N; ++i) cin >> p[i];
 sort(p, p + N);
 int ans = 0;
 for(int i = 0; i < K; ++i) ans += p[i];
 cout << ans << endl;
 }


Measured memory_bytes: 3660
#include <cstdio>

int main()
{
    int a;
    scanf("%d", &a);
    if (a == 25)
    {
        printf("Christmas");
    }
    
    else if (a == 24)
    {
        printf("Christmas Eve");
    }
    
    else if (a == 23)
    {
        printf("Christmas Eve Eve");
    }
    
    else if (a == 22)
    {
        printf("Christmas Eve Eve Eve");
    }
    
}

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

from collections import Counter

if __name__ == '__main__':
    N, M = map(int, input().split(' '))
    table = [[c + 1] + [int(i) for i in input().split(' ')] for c in range(M)]

    table = sorted(table, key=lambda r: r[2])
    counter = Counter()
    result = []
    for c, p, y in table:
        counter[p] += 1
        result.append((c, '{:06}{:06}'.format(p, counter[p])))

    for c, c_id in sorted(result, key=lambda r: r[0]):
        print(c_id)


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

const int N = 200005, MOD = 1E9 + 7;

int n, u, cur = 1, lst = 0, dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> u;
        if (u != lst) {
            lst = u;
            cur = ((dp[u] += cur) %= MOD);
        }
    }
    cout << cur;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
	int time;

	scanf("%d",&time);

	int h, m, s;

	h = time / 3600;
	m = (time - 3600 * h)/60;
	s = ((time - 3600 * h) - (m*60));

	printf("%d:%d:%d\n",h,m,s);


	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();
    
    int type;
    cin >> type;
    if (type == 1)
    	cout << "Hello World";
    else {
   		int x, y;
   		cin >> x >> y;
   		cout << x + y;
    }
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

int n;
int dp[N];
vector<int> e[N];

void dfs(int x, int last = -1)
{
	vector<int> t;
	for (auto to : e[x]) {
		dfs(to, x);
		t.push_back(dp[to]);
	}

	sort(t.begin(), t.end());
	for (int i = 0; i < t.size(); i++) {
		dp[x] = max(dp[x], (int)(t[i] + t.size() - i));
	}
}

void solve()
{
	cin >> n;
	REP(i, n - 1) {
		int x; cin >> x;
		e[x].push_back(i + 2);
	}
	dfs(1);
	cout << dp[1] << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 18880
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
l=[lnii() for i in range(n)]

ans=0
for i in [1,-1]:
  for j in [1,-1]:
    for k in [1,-1]:
      t_num=0
      t_l=[]
      for x,y,z in l:
        t_num=x*i+y*j+z*k
        t_l.append(t_num)
      t_l.sort(reverse=True)
      ans=max(ans,sum(t_l[:m]))

print(ans)

Measured memory_bytes: 9284
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,V,P = MI()
A = [0] + LI()
A.sort()

from bisect import bisect_left


def f(n):  # 下からn番目のスコアの問題が、採用される可能性があるか
    v = V-n  # スコア下位n問には全員が投票したとしてよい
    m = bisect_left(A,A[n]+M+1)
    if N-m+1 >= P:  # 上位P人に入れない
        return False
    else:
        v -= P-1  # スコア上位P-1人には全員が投票したとしてよい
        if v <= 0:
            return True
        else:
            if sum(A[n]+M-A[i] for i in range(n+1,N-P+2)) >= M*v:
                return True
            else:
                return False


left = 0  # 採用される可能性なし
right = N  # 採用される可能性あり
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(N+1-right)


Measured memory_bytes: 84620
n = int(input())
a_list = list(map(int, input().split(" ")))
b_list = list(map(int, input().split(" ")))

out = 0
for i in range(n):
    if a_list[i] < b_list[i]:
        val0 = a_list[i]
        out += val0
        b_list[i] -= val0
        #a_list[i] = 0
        if a_list[i+1] < b_list[i]:
            val1 = a_list[i+1]
            out += val1
            a_list[i+1] = 0
            #b_list[i] -= val1
        else:
            val1 = b_list[i]
            out += val1
            a_list[i+1] -= val1
    else:
        val0 = b_list[i]
        out += val0
        # b_list[i] = 0
        # a_list[i] -= val0

print(out)

Measured memory_bytes: 18476
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        string s;
        cin >> s;

        if(s == "ABC")
            cout << "ARC\n";
        else
            cout << "ABC\n";
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 3788
def cgd(x,y):
	while(True):
		r=x%y
		if r==0:
			m=y
			break
		x=y
		y=r
	
	return m

a,b=map(int,input().split())
if a>b:
	m=cgd(a,b)
elif a<b:
	m=cgd(b,a)
else:
	m=a
print(m)
	


Measured memory_bytes: 5600
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n; char s[11]; long long ans = 0;
  long long a[5] = {};
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%s", s);
    if(s[0] == 'M') a[0]++;
    else if(s[0] == 'A') a[1]++;
    else if(s[0] == 'R') a[2]++;
    else if(s[0] == 'C') a[3]++;
    else if(s[0] == 'H') a[4]++;
  }
  
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      for(int k = 0; k < 5; k++){
	if(i != j && i != k && j != k)ans += a[i] * a[j] * a[k];
      }
    }
  }

  printf("%lld\n", ans / 6);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 inf = 1001001001;
const ll linf = 1001001001001001001;

vi c,d;

struct edge {
    int to,a,b;
};

vector<vl> dijkstra(P start,const vector<vector<edge>>& v) {
    int n = v.size();
    vector<vl> dist(n,vl(6000,linf));
    priority_queue<pair<ll,P>,vector<pair<ll,P>>,greater<pair<ll,P>>> q;
    q.emplace(0LL,start);
    dist[start.first][start.second] = 0;
    while(!q.empty()) {
        auto p = q.top();
//        cout << p.second.first << " " << p.second.second << endl;
        q.pop();
        if(dist[p.second.first][p.second.second] < p.first) continue;
        for(auto e : v[p.second.first]) {
            if(p.second.second-e.a < 0) continue;
            if(chmin(dist[e.to][p.second.second-e.a],p.first+e.b)) {
                q.push({p.first+e.b,{e.to,p.second.second-e.a}});
            }
        }
        int nc = c[p.second.first];
        int nd = d[p.second.first];
        if(p.second.second+nc < 6000) {
            if(chmin(dist[p.second.first][p.second.second+nc],p.first+nd)) {
                q.push({p.first+nd,{p.second.first,p.second.second+nc}});
            }
        }
    }
    return dist;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m,s;
    cin >> n >> m >> s;
    vector<vector<edge>> G(n);
    rep(_,m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G[u].pb(edge{v,a,b});
        G[v].pb(edge{u,a,b});
    }
    c.resize(n);
    d.resize(n);
    rep(i,n) cin >> c[i] >> d[i];
    auto v = dijkstra({0,min(s,5999)},G);
    rep2(i,1,n) {
        ll ans = linf;
        rep(j,6000) chmin(ans,v[i][j]);
        cout << ans << endl;
    }
}


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

#define ll long long
#define size 100001

int a[size];
int b[size];
int c[size];
int dp[size][4];

int max_sum(int n, int p)
{
    if(n <= 0)
        return 0;
    if(n > 0 && dp[n][p] != -1)
        return dp[n][p];
    int ans = INT_MIN;
    if(p != 0)
    {
        ans = max(ans,a[n]+max_sum(n-1,0));
    }
    if(p != 1)
    {
        ans = max(ans,b[n]+max_sum(n-1,1));
    }
    if(p != 2)
    {
        ans = max(ans,c[n]+max_sum(n-1,2));
    }

    return dp[n][p] = ans;
}



int main()
{
  //OJ;
  int t = 1;
  //cin>>t;
  while(t--){
   memset(dp,-1,sizeof(dp));
  int n;
  cin>>n;

  for(int i = 1; i <= n; i++)
  {
      cin>>a[i]>>b[i]>>c[i];
  }
  cout<<max_sum(n,3)<<endl;
  }
   return 0;
}


Measured memory_bytes: 11048
def main():
    S = input()
    l = []
    l2 = []
    mod = (10 ** 9) + 7
    for i in range(6):
        d = [0] * 13
        d2 = [0] * 10
        for j in range(0, 10):
            t = (j *(10 ** i)) % 13
            d[t] += 1
            d2[j] = t
        l.append(d)
        l2.append(d2)
    r = 0
    c = [0] * 13
    c[0] = 1
    n = [0] * 13
    i = 0
    for v in reversed(S):
        if v == '?':
            k = 0
            for j in range(13):
                for k in range(13):
                    if l[i][j]:
                        kk = (j+k) % 13
                        n[kk] += c[k]
                        n[kk] %= mod
            c = n
            n = [0] * 13
        else:
            r += (l2[i][int(v)])
            r %= 13
        i += 1
        i %= 6
    r = (5 - r) % 13
    print(c[r] % mod)
main()



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

int a[1000001];

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    for(int i=1; i<n; i++){
        bool flag = false;
        if(s[i-1] == 'A' && s[i] == 'C'){
            a[i-1]++;
            a[i]++;
        }
        a[i+1] = a[i];
    }

    if(s.size() == 3){
        a[0] = 0; a[1] = 0; a[2] = 0;
        if(s[0] == 'A' && s[1] == 'C'){
            a[0]++;
            a[1]++;
        }
        if(s[1] == 'A' && s[2] == 'C'){
            a[1]++;
            a[2]++;
        }
    }

    for(int i=0; i<q; i++){
        int l, r;
        cin >> l >> r;
        // substr = 1
        if(l == r){
            cout << 0 << endl;
            continue;
        }
        //substr = 2
        if(r-l == 1 && s[l-1] == 'A' && s[r-1] == 'C'){
            cout << 1 << endl;
            continue;
        }
        else if(r - l == 1){
            cout << 0 << endl;
            continue;
        }

        //otherwise
        int ans = 0;
        string t = s.substr(l-1, r - l+1);

        if(t[0] == 'A' && t[1] == 'C') ans = 1;
        ans += (a[r-1] - a[l-1]);
        if(t[t.size()-1] == 'A' && (r+1) <= s.size() && s.substr(r-1, 2) == "AC") ans--;

        cout << ans << endl;

    }
}

Measured memory_bytes: 1408
#include<stdio.h>

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

    if(n == 1){
        printf("Hello World\n");
    }
    else{
        int a;
        int b;
        scanf("%d%d", &a, &b);
        printf("%d\n", a + b);
    }

    return 0;
}

Measured memory_bytes: 128
from sys import stdin

N = int(stdin.readline().rstrip())
V = [float(x) for x in stdin.readline().rstrip().split()]

V.sort(reverse=True)
ans = 0

while len(V) > 1:
    ans += (V[len(V) - 1] + V[len(V) - 2]) / 2
    new = (V[len(V) - 1] + V[len(V) - 2]) / 2
    V.pop()
    V.pop()
    V.append(new)

print(V[0])


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

int main()
{
    int N,M,L;
    cin >> N >> M >> L;
    long long int A[N][M], B[M][L], C[N][L];

    int n, m ,l;
    for ( n =0; n < N; n++){
        for ( m = 0; m < M; m++){
            cin >> A[n][m];
        }
    }

    for ( m =0; m < M; m++){
        for ( l = 0; l < L; l++){
            cin >> B[m][l];
        }
    }
    long long int sum =0;
    for ( n =0; n < N; n++){
        for ( l = 0; l < L; l++){
            sum=0;
            for ( m = 0; m < M; m++){
                sum += A[n][m]*B[m][l];
            }
            cout << sum ;
            if (l != L-1){
                cout<< " ";
            }
        }
        cout << endl;
    }

    return 0;
}


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

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

    string vs;
    vector<int> vi;

    vs += str[0];
    vi.push_back(1);
    for (int i = 1; i < str.size(); i++) {
        if (vs[vs.size()-1] == str[i]) {
            vi[vi.size()-1]++;
        } else {
            vs += str[i];
            vi.push_back(1);
        }
    }

    int ans = 0;
    for (int i = 0; i + 2 < vs.size(); i++) {
        if (vs[i] == 'J' && vs[i+1] == 'O' && vs[i+2] == 'I'
            && vi[i] >= vi[i+1] && vi[i+1] <= vi[i+2]) {
            ans = max(ans, vi[i+1]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9628
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<utility>
#include<climits>
#include<fstream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define inf 0x7f7f7f
#define p(x) (x)*(x)
#define PI 3.14159265358979
using namespace std;

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

vector<int> func(int n, int k);

int main()
{
	//ios::sync_with_stdio(false);
	int n = 0, k = 0;
	cin >> n >> k;
	auto mid = func(n, k);
	cout << mid.size() << endl;
    return 0;
}

vector<int> func(int n, int k)
{
	vector<int> v;
	while(n){
		v.push_back(n % k);
		n /= k;
	}
	return v;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    int n; cin >> n;
    int ac = 0, tle = 0, wa = 0, re = 0;
    while(n--)
    {
      string s; cin >> s;
      if(s == "AC") ac++;
      if(s == "TLE") tle++;
      if(s == "RE") re++;
      if(s == "WA") wa++;
    }
    cout << "AC x "<< ac <<"\n";
    cout << "WA x "<< wa <<"\n";
    cout << "TLE x "<< tle <<"\n";
    cout << "RE x "<< re <<"\n";
  }
}



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

using namespace std;
typedef long long ll;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;

  x = abs(x);
  ll f = x / d;
  
  if (f >= k) {
    ll ans = x - k * d;
    cout << ans << '\n';
    return 0;
  }

  x -= f * d;
  k -= f;
  if (k % 2 == 0) {
    cout << x << '\n';
  } else {
    cout << abs(x - d) << '\n';
  }
  return 0;
}



Measured memory_bytes: 3676
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>n;
    cout<<n/3<<endl;
    return 0;
}


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

signed main(){

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

  int q;
  cin>>q;
  map<string,int> mp;
  while(q--){
    int com;
    cin>>com;
    if(com==0){
      string k;
      int x;
      cin>>k>>x;
      mp[k]=x;
    }
    else if(com==1){
      string k;
      cin>>k;
      cout<< (mp.count(k)?mp[k]:0) <<"\n";
    }
    else if(com==2){
      string k;
      cin>>k;
      mp.erase(k);
    }
    else if(com==3){
      string l,r;
      cin>>l>>r;
      auto itr = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      while(itr!=end){
        cout<< (*itr).first <<" "<< (*itr).second <<"\n";
        itr++;
      }
    }
  }

}


Measured memory_bytes: 25876
#include <stdio.h>

void right_triangle(int a, int b, int c);

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int count = 0; count < n; ++count) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        right_triangle(x, y, z);
    }
    return 0;
}

void right_triangle(int a, int b, int c)
{
    if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

Measured memory_bytes: 1008
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int maxn = 100000 + 5;

int n, m, c, b[maxn];

int main() {
    cin >> n >> m >> c;
    for (int i = 1; i <= m; i++) scanf("%d", b + i);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int tot = c, x;
        for (int i = 1; i <= m; i++) {
            scanf("%d", &x);
            tot += x * b[i];
        }
        if (tot > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s;
    string str,str1;
    t=1;
    while(t--)
    {
          cin>>n;
          ll ans=0;
          for(int i=1;i<=n;i++)
          {
          	for(int j=1;j<=n;j++)
          	{
          		for(int k=1;k<=n;k++)
          		{
          			ans+=__gcd(__gcd(i,j),k);
          		}
          	}

          }
          cout<<ans<<endl;

    }
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int check(int x){
	int cnt=0;
	while(1){
		if(x%100==0){
			cnt++;
			x=x/100;
		}else{
			return cnt;
		}
	}
}

int main(){
	int D,N;
	cin >> D >> N;
	int cnt=0;
	for(int ans=1;;ans++){
		if(check(ans)==D)cnt++;
		if(cnt==N){
			cout << ans << endl;
			return 0;
		}	
	}
	return 0;
}

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;

ll cnt[1000];
ll a[1000], b[1000];

ll pw(ll p, ll q){
	ll ret = 1;
	for(; q; q >>= 1){
		if (q & 1)
			ret = ret * p % MM;
		p = p * p % MM;
	}
	return ret;
}

ll f[1000][1000];
ll sum[1000][1000];

void upd(ll & x, ll y){
	x += y;
	if (x >= MM) x -= MM;
}

int main(){
	int n, c;
	cin>>n>>c;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	for(int i = 1; i <= n; i++)
		cin>>b[i];
	f[0][0]= 1;
//	sum[0] = 0;
	for(int j = 0; j <= c; j++){
		sum[j][0] = 0;
		for(int i = 1; i <= 400; i++)
			sum[j][i] = (sum[j][i-1] + pw(i, j)) % MM;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= c; j++){
			for(int k = 0; k <= j; k++)
				upd(f[i][j], f[i-1][j-k] * ((sum[k][b[i]] - sum[k][a[i]-1] + MM) % MM) % MM);
		}
	}
	cout<<(f[n][c] % MM + MM) % MM << endl;
	/*
	for(ll i = 1; i <= 400; i++){
		cnt[i] = 1;
		for(int j = 1; j <= n; j++)
			cnt[i] = cnt[i] * max(0ll, min(b[j], i) - a[i]) % MM;
	}
	for(int i = 1; i <= 10; i++)
		cout<<cnt[i]<<' '; cout<<endl;
	for(int i = 400; i > 1; i--)
		cnt[i] -= cnt[i-1];
	for(int i = 1; i <= 10; i++)
		cout<<cnt[i]<<' '; cout<<endl;
	long long ans = 0;
	for(int i = 1; i <= 400; i++){
		ans = (ans + pw(cnt[i], c)) % MM;
	}
	cout<<ans<<endl;*/
	return 0;
} 

Measured memory_bytes: 6016
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

template<typename T>T&get(){T a;cin>>a;return a;}
template<typename T>T&rev(T&a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>a){sort(all(a));return a;}

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

const int inf = 1e9;
const ll linf = 3e18;

int I[1001], J[1001], K[1001];
bool ok[301];
int res[301];

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

    int a, b, c;
    while (cin >> a >> b >> c, a || b || c) {
        memset(res, -1, sizeof(res));
        memset(ok, false, sizeof(ok));

        int n; cin >> n;

        rep1(i, n) {
            bool f;
            cin >> I[i] >> J[i] >> K[i] >> f;
            if (f) {
                ok[I[i]] = ok[J[i]] = ok[K[i]] = true;
                res[I[i]] = res[J[i]] = res[K[i]] = 1;
            }
        }

        rep1(_, n) {
            int i = I[_], j = J[_], k = K[_];
            if (!ok[i] && res[i] == -1) {
                if (ok[j] && ok[k]) res[i] = 0;
            } else if (!ok[j] && res[j] == -1) {
                if (ok[i] && ok[k]) res[j] = 0;
            } else if (!ok[k] && res[k] == -1) {
                if (ok[i] && ok[j]) res[k] = 0;
            }
        }

        rep1(i, a + b + c) {
            printf("%d\n", res[i] == -1 ? 2 : res[i]);
        }
    }
}

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    ll n, cnt = 0;
    cin >> n;
    vector<vector<ll>>a(n,vector<ll>(2));
    rep(i,n) cin >> a[i][0] >> a[i][1];
    rep(i,n){
        if(a[i][0] == a[i][1]) cnt++;
        else cnt = 0;
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        } 
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		long mod = (long)(1e9+7);
		Scanner input = new Scanner(System.in);
		String S = input.next();
		String T = input.next();
		int n = S.length();
		System.out.println((T.substring(0,n).equals(S)?"Yes":"No"));
	}
}

Measured memory_bytes: 27016
#include <cstdio>
#include <algorithm>
#include <vector>

#define LL long long

using namespace std;
LL N, minim = 123;

LL numof(LL a)
{
    LL nr = 0;
    while(a)
    {
        a /= 10;
        ++nr;
    }
    return nr;
}

int main()
{
    scanf("%lld", &N);
    minim = numof(N);
    for(LL i = 2; i*i <= N; ++i)
    {
        if(N%i == 0)
        {
            //printf("check %d\n", i);
            minim = min(minim, max(numof(i), numof(N/i)));
        }
    }
    printf("%lld\n", minim);
    return 0;
}

Measured memory_bytes: 128
a,b = list(map(int, input().split()))

p = str(a)
q = str(b)
ans = ""

if(a==b):
  for i in range(a):
    ans += p
elif(a>b):
  for i in range(a):
    ans += q
elif(a<b):
  for i in range(b):
    ans += p
print(ans)

Measured memory_bytes: 3064