akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

		for(int i = 0; i < N; i++){
			untreatedArr[i] = scan.nextInt();
		}

		dispArr(untreatedArr);
		insertionSort(untreatedArr,N);

		scan.close();
	}

	public static void insertionSort(int[] A,int N){
		for(int i = 1; i <= N - 1; i++){
			int v = A[i];
			int j = i - 1;

			while(j >= 0 && A[j] > v){
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			dispArr(A);
		}
	}

	public static void dispArr(int[] A){
		for(int i = 0; i < A.length; i++){
			if(i != A.length - 1) System.out.print(A[i] + " ");
			else System.out.println(A[i]);
		}
	}

}

Measured memory_bytes: 31772
#include <iostream>
using namespace std;
int main ()
{
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int k;
    cin >> k;
    for (int i = 0; i < k; i++)
        cout << "ACL";
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

bool f = 1, e[100][100];
int n;

void dfs(int now, int par, VI &visit){
    if (visit[now]){
        if (now == par) f = 0;
        return;
    }
    visit[now] = 1;
    REP(i,n){
        if (e[now][i]) dfs(i, par, visit);
    }
}

int main() {
    int m;
    cin >> n >> m;
    VVI h(n, VI(m, 1000)), l(n, VI(m));
    REP(i,n){
        int k;
        cin >> k;
        while (k--){
            int j, x;
            string s;
            cin >> j >> s >> x;
            if (s == ">=") l[i][j-1] = max(l[i][j-1], x);
            else h[i][j-1] = min(h[i][j-1], x);
        }
    }
    REP(i,n) REP(j,m) if (l[i][j] > h[i][j]) f = 0;
    REP(i,n) REP(j,n){
        bool g = 0;
        REP(k,m) if (l[i][k] > h[j][k]) g = 1;
        e[i][j] = g;
    }

    REP(i,n){
        VI visit(n);
        dfs(i, i, visit);
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}

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

const int MAXN = 1e5 + 10;

int vis[MAXN][3],dp[MAXN][3],N,A[3][MAXN];

int solve(int pos,int last){

	if(pos == N + 1) return 0;

	if(vis[pos][last]) return dp[pos][last];
	vis[pos][last] = 1;

	int best = 0;

	for(int i = 0;i<3;i++){
		if(i != last) best = max(best, A[i][pos] + solve(pos+1,i) );
	}

	return dp[pos][last] = best;

}

int main(){

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

	printf("%d\n", max(solve(1,0), max(solve(1,1),solve(1,2)) ) );

	return 0;

}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"a > b"<<endl;}
  if(a<b){
    cout<<"a < b"<<endl;}
  if(a==b){
    cout<<"a == b"<<endl;}
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
vector<string> del_col(vector<string> const& input){
    int h=input.size();
    int w=input[0].size();
    vector<string> res;
    rep(i,h){
        bool flag=false;
        rep(j,w){
            if(input[i][j]=='#')flag=true;
        }
        if(flag)res.push_back(input[i]);
    }
    return res;
}
vector<string> del_row(vector<string> const& input){
    int h=input.size();
    int w=input[0].size();
    vector<string> res;
    rep(j,w){
        bool flag=false;
        string buf;
        rep(i,h){
            buf+=input[i][j];
            if(input[i][j]=='#')flag=true;
        }
        if(flag)res.push_back(buf);
    }
    return res;
}
void output(vector<string> const& a){
    int h=a.size();
    int w=a[0].size();
    rep(j,w){
        rep(i,h){
            cout<<a[i][j];
        }
        cout<<endl;
    }
}
signed main(){
  int h,w;cin>>h>>w;
  vector<string> a(h);
  rep(i,h)cin>>a[i];
  a=del_col(a);
  a=del_row(a);
  output(a);
  return 0;
}

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

int main(){
    int N;
    long long K;
    cin >> N >> K;
    vector<pair<int,int>> v;    
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < (int)v.size(); i++){
        K -= v[i].second;
        if(K <= 0 ){
            cout << v[i].first << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1400
al = [chr(i) for i in range(97,97 + 26)]

def cnt(s,t):
	ret = 0
	for c in al:
		if c in s and c in t:ret+=1
	return ret

n=int(input())
s = input()
ans = 0
for i in range(1,n):
	ans = max(ans,cnt(s[:i],s[i:]))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;

#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

/*
文字列操作の問題再び！！！
10^100はめちゃ大きい数で実際に操作はできない
RLと向かいあってるところに収束する

R[RL]LLL[RL]R[RL]L
[]以外は全部０になって、
RRLLLL 3 3　（6/2なのだろうな）
RL 1 1
RRLL 2 2
みたいな感じになる
最初は必ずRで始まるらしくて優しい笑
*/

int main()
{
  string S;cin>>S;
  
  ll n = S.size();
  ll i=0;
  ll num=0;//何個に分けられるか（絶対偶数）
  vector<ll> a(n+1,0); //何個同じのが続いてるか
  while (i<n)
  {
    ll count=0;
    while (S[i]==S[i+1]){
      i++; 
      count++;
    }
    a[num]=count+1;
    num++;
    i++;
  }
  
  vector<ll> ans(n+1,0);//答えを格納する配列
  ll now = 0;
  for (int i=0;i<num;i+=2)
  {
    ll mx; //大きい方の番号
    
    if (a[i]%2!=a[i+1]%2)
    { 
      if (max(a[i],a[i+1])%2==0)
      {
        ans[now+a[i]+1]=(a[i]+a[i+1])/2+1;
        ans[now+a[i]]=(a[i]+a[i+1])/2;
        if (a[i]<a[i+1]) swap(ans[now+a[i]+1],ans[now+a[i]]);
      }
      else{
       ans[now+a[i]+1]=(a[i]+a[i+1])/2;
       ans[now+a[i]]=(a[i]+a[i+1])/2+1;
       if (a[i]<a[i+1]) swap(ans[now+a[i]+1],ans[now+a[i]]);
      }
    }
    else
    {
      ans[now+a[i]]=(a[i]+a[i+1])/2;
      ans[now+a[i]+1]=(a[i]+a[i+1])/2;
    }
    now += a[i]+a[i+1];
  }
  
  for (int i=1;i<=n;i++)
    cout<<ans[i]<<" ";
}

Measured memory_bytes: 2176
def resolve():
    S = input()
    table=[0]*2019
    table[0]=1
    x = 0
    x_10 =1
    for i in S[::-1]:
 
        x = (x+ int(i)*x_10)%2019
 
        table[x]+=1
 
        x_10*=10
        x_10 %= 2019
 
    ans =0
    for i in table:
        ans += i*(i-1)//2
    
    print(ans)
 
 
 
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9332
#include <stdio.h>

int main(void){
  int n[2],sub,big,small;
  scanf(" %d %d",&n[0],&n[1]);
  if(n[1] < n[0]){
    big = n[0];
    small = n[1];
  }
  else{
    big = n[1];
    small = n[0];
  }
  while(1){
    sub = small;
    small = big % small;
    big = sub;
    //printf("big = %d,small = %d\n",big,small);
    if(small == 0){
      printf("%d\n",big);
      break;
    }
  }
  return 0;
}


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

vector<int> factor(int N){
	vector<int> ans;
    ans.push_back(1);
    ans.push_back(N);
	for(int i=2;i*i<=N;i++){
		if(N%i==0){
			ans.push_back(i);
			if(i*i!=N)ans.push_back(N/i);
		}
	}
	sort(ans.begin(),ans.end());
	return ans;
}

signed main(){
	int X; cin>>X;
    vector<int> fact=factor(X);
    pair<int,int> ans;
    if(X==1 || X==-1){
        ans.first=X;
    }
    for(int i=0;i<fact.size();i++){
        int now=fact[i];
        for(int b=-1000;b<=1000;b++){
            int a=b+now;
            if(pow(a,5)-pow(b,5)==X){
                ans.first=a,ans.second=b;
                goto end;
            }
        }
        for(int b=-1000;b<=1000;b++){
            int a=b-now;
            if(pow(a,5)-pow(b,5)==X){
                ans.first=a,ans.second=b;
                goto end;
            }
        }
    }
    end:
    cout<<ans.first<<' '<<ans.second<<endl;

}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
vector<P> kn[3005];
bool used[3005];
ll mincost[3005]={0};
bool dfs(ll pos,ll goal){
  if(pos==goal) return true;
  for(int i=0;i<kn[pos].size();i++){
    ll to=kn[pos][i].first;
    if(!used[to]){
      used[to]=true;
      if(dfs(to,goal)) return true;
    }
  }
  return false;
}
int main(){
  ll n,m,p;
  cin>>n>>m>>p;
  for(int i=1;i<=m;i++){
    ll s,t,cos;
    cin>>s>>t>>cos;
    cos-=p;
    kn[s].push_back(P(t,-cos));
  }
  ll gs=0;
  vector<P2> node;
  for(int i=1;i<=n;i++){
    for(int j=0;j<3005;j++) used[j]=false;
    used[i]=true;
    if(dfs(i,n)){
      for(int j=0;j<3005;j++) used[j]=false;
      used[1]=true;
      if(!dfs(1,i)) continue;
      for(int j=0;j<kn[i].size();j++) node.push_back(P2(i,kn[i][j]));
      gs++;
    }
  }
  for(int i=2;i<=3005;i++) mincost[i]=17441744174417;
  int cnt=0;
  while(1){
    bool upd=false;
    for(int i=0;i<node.size();i++){
      ll s=node[i].first,t=node[i].second.first,cos=node[i].second.second;
      if(mincost[s]+cos<mincost[t]){
        upd=true;
        mincost[t]=mincost[s]+cos;
      }
    }
    cnt++;
    if(!upd) break;
    if(upd&&cnt>=gs){
      cout<<"-1"<<endl;
      return 0;
    }
  }
  cout<<max(mincost[n]*-1,(ll)0)<<endl;
  return 0;
}


Measured memory_bytes: 836
#include <iostream>

int main()
{
  int n;
  int k;
  int h;
  int number=0;

  std::cin >> n;
  std::cin >> k;

  for (int x=0; x < n; ++x){
    std::cin >> h;
    if (h >= k){
      ++number;
    }
  }

  std::cout << number << std::endl;
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Bits
import Data.Int
import Debug.Trace

main = do
  [n,q] <- map read . words <$> getLine :: IO [Int]
  queries <- replicateM q $ map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine :: IO [[Int]]


  let inf = 2147483647

  seg <- stToIO $ newSegmentTree n inf :: IO (IOSegmentTree Int)

  forM_ queries $ \[com,x,y] -> do
    when (com == 0) $ do
      stToIO $ updateSegmentTree seg x y min
      --print =<< V.freeze seg
    when (com == 1) $ do
      a <- stToIO $ findSegmentTree seg x (y+1) inf min
      --print =<< V.freeze seg
      print a



type STSegmentTree s a = VM.MVector s a
type IOSegmentTree a = STSegmentTree RealWorld a

newSegmentTree :: Num a => Int -> a ->  ST s (STSegmentTree s a)
newSegmentTree n x = V.thaw $ V.replicate m x
  where m = 2 * (2 ^ (ceiling $ logBase 2 (fromIntegral n))) - 1


updateSegmentTree :: Num a => STSegmentTree s a -> Int -> a -> (a -> a -> a) -> ST s ()
updateSegmentTree tree i x f = do
  let
    n = (VM.length tree + 1) `div` 2
    j = i + n - 1
  VM.write tree j x
  aux ((j-1)`div`2) x
  where
    aux i x = do
      when (i >= 0) $ do
        a <- VM.read tree (i*2+1)
        b <- VM.read tree (i*2+2)
        VM.write tree i (f a b)
        aux ((i-1)`div`2) x
      

findSegmentTree :: Num a => STSegmentTree s a -> Int -> Int -> a -> (a -> a -> a) -> ST s a
findSegmentTree tree x y e f = do
  let n = (VM.length tree) `div` 2 + 1
  aux 0 0 n

  where
    aux i l r
      | r <= x || y <= l = return e
      | x <= l && r <= y = VM.read tree i
      | otherwise = f <$> aux (i*2+1) l ((l+r)`div`2) <*> aux (i*2+2) ((l+r)`div`2) r



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

using namespace std;

const int maxn = 1010;
char mat[maxn][maxn];
int h, w;
const int mod = 1e9 + 7;

void add_self(int &a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

void go() {

    vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;

    for (int row = 0; row < h; row++) {
        for (int col = 0; col < w; col++) {
            for (int r2 :{row, row + 1}) {
                int c2 = col;
                if (r2 == row)
                    c2 += 1;
                if (r2 < h && c2 < w && mat[r2][c2] == '.')
                    add_self(dp[r2][c2], dp[row][col]);
            }
        }
    }
    cout << dp[h - 1][w - 1];
}

int main() {
    cin >> h >> w;

    for (int u = 0; u < h; u++) {
        for (int j = 0; j < w; j++)
            cin >> mat[u][j];
    }

    go();
}

Measured memory_bytes: 5120
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n = Scanner.nextInt
	val a = Array.fill(n)(Scanner.nextLong).sortWith(_ > _)

	pw.println(a(0) + 2L * a.tail.take((n-2) / 2).sum + (if (n % 2 == 0) 0 else a((n-1) / 2)))
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 64424
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n,x;
    cin>>n>>x;
    int w[n],v[n];
    int mxv = 0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        mxv = max(mxv,v[i]);
    }
    mxv*=n;
    int dp[n+1][mxv+1];
    for(int i=0;i<n;i++)
        for(int j=0;j<=mxv;j++)
            dp[i][j]=1e9;
    dp[0][0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=mxv;j++)
        {
            if(j<v[i])
            dp[i+1][j] = dp[i][j];
            else{
                dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
            }
        }
    }
    int ans = 0;
    for(int i=0;i<=mxv;i++)
    {
        if(dp[n][i]<=x)
        ans=i;
    }
    cout<<ans;
}


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

int main(void){

	while (true){
		int a, b, c, d, e, f;
		cin>>a>>b>>c>>d>>e>>f;
		if (cin.eof()) break;

		float x, y, tmp;
		tmp = (a*e-b*d);
		if (tmp>0){
			x = (c*e-b*f)/tmp;
			y = -(c*d-a*f)/tmp;
		}
		else{
			x = (-c*e+b*f)/(-tmp);
			y = (c*d-a*f)/(-tmp);
		}

		cout<<fixed<<setprecision(3);
		cout<<x<<" "<<y<<endl;
	}
	return 0;
} 

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

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

        public static long[] Reads()
        {

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






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


            var x = Read();
            Console.WriteLine((long)Math.Ceiling(x / 11.0) * 11 - x >= 5 ? (long)Math.Ceiling(x / 11.0) * 2 - 1 : (long)Math.Ceiling(x / 11.0) * 2);
            
            Console.WriteLine();
         
            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};
struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

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

    bool isSame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A--, B--;
        uf.merge(A, B);
    }
    set<int> st;
    for (int i = 0; i < N; i++)
        st.insert(uf.root(i));
    cout << st.size() - 1 << endl;
    return 0;
}


Measured memory_bytes: 7608
#include<vector>
#include<algorithm>
#include<iostream>
#include<utility>
#include<climits>
using namespace std;

class RMQ{//RangeMinimumQuery
	int n;
	std::vector<int> dat,idx;
	static int calcsize(int n){
		int res=1;
		while(res<n)res<<=1;
		return res;
	}
	int query(int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return dat.size()-1;
		if(a<=l&&r<=b)return idx[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2,r);
			return dat[vl]<dat[vr]?vl:vr;
		}
	}
public:
	RMQ(){}
	~RMQ(){}
	void build(const std::vector<int> &a){
		n=calcsize(a.size());
		idx.resize(2*n-1);
		for(int i=0;i<(int)a.size();i++)idx[n-1+i]=i;
		for(int i=a.size();i<n;i++)idx[n-1+i]=a.size();
		dat=a;
		dat.push_back(INT_MAX);
		for(int i=n-2;i>=0;i--){
			idx[i]=dat[idx[i*2+1]]<dat[idx[i*2+2]]?idx[i*2+1]:idx[i*2+2];
		}
	}
	int query(int a,int b)const{//[a,b)の最小値
		return query(a,b,0,0,n);
	}
};


class LCA{
	vector<int> eulertour;
	vector<int> vertex;
	//SparseTableRMQ rmq;
	RMQ rmq;
	void dfs(const vector<int> edge[],int n,vector<int> &depth,int d,int u){
		eulertour[u]=vertex.size();	
		vertex.push_back(u);
		depth.push_back(d);
		for(int i=0;i<edge[u].size();i++){
			dfs(edge,n,depth,d+1,edge[u][i]);
			vertex.push_back(u);
			depth.push_back(d);
		}
	}
public:
	LCA(const vector<int> edge[],int n,int root):eulertour(n){
		vector<int> depth;
		dfs(edge,n,depth,1,root);
		vertex.push_back(root);
		depth.push_back(0);
		rmq.build(depth);
	}
	int query(int u,int v)const{
		if(u==v)return u;
		if(eulertour[u]>eulertour[v])swap(u,v);
		return vertex[rmq.query(eulertour[u], eulertour[v])];
	}
};


vector<int> edge[100000];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,v;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			edge[i].push_back(v);
		}
	}
	LCA lca(edge,n,0);
	int q,u,v;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>u>>v;
		cout<<lca.query(u,v)<<endl;
	}
	return 0;
}

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

long long calc(int MOD, vector<int> hairetu, int n){
    long long result=0;
    long long sum=0;

    for(int i=0; i<n; i++){
        sum += hairetu[i];
        if(i%2 == MOD && sum <= 0){
            result += (1-sum);
            sum = 1;
        }else if(i%2 != MOD && sum >= 0){
            result += (sum+1);
            sum = -1;
        }

    }

    return result;
}



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

    vector<int> hairetu(num);
    for(int i=0; i<num; i++){
        cin >> hairetu[i];
    }

    cout << min(calc(0, hairetu, num), calc(1, hairetu, num)) << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
using namespace std;
int x;

int main()
{
    cin >> x;
    for(int i = 0;;i++) {
        for(int j = i; j >= 0; j--) {
            if(pow(i,5) - pow(j,5) == x) {
                cout << i << " " << j;
                return 0;
            }
            if(pow(i,5) + pow(j,5) == x) {
                cout << i << " " << -j;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4100
#include <stdio.h>

int main(){
  int num1,num2,sum,count;
 while(scanf("%d %d",&num1,&num2)!=EOF){
 sum=num1+num2;
 count=0;
 if(sum>0){
  count++;
  if(sum>9){
   count++;
    if(sum>99){
     count++;
      if(sum>999){
       count++;
        if(sum>9999){
         count++;
          if(sum>99999){
           count++;
            if(sum>999999){
             count++;}
         }
        }
       }
      }
     }
    }
  printf("%d\n",count);
}
 return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int MaxN = 2e5 + 5;

vector<int> gb[MaxN], gr[MaxN];

int dep[MaxN], fa[MaxN], d[MaxN];
bool safe[MaxN], vis[MaxN];

void Dfs(int x, int f) {
  ::fa[x] = f;
  for (int k : gb[x]) {
    if (k != f) {
      dep[k] = dep[x] + 1;
      Dfs(k, x);
    }
  }
}

#define fin cin
#define fout cout

int main() {
  ios_base::sync_with_stdio(false);
  int n, sx, sy;
  fin >> n >> sx >> sy;
  for (int i = 1; i < n; ++i) {
    int x, y;
    fin >> x >> y;
    gr[x].emplace_back(y);
    gr[y].emplace_back(x);
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    fin >> x >> y;
    gb[x].emplace_back(y);
    gb[y].emplace_back(x);
  }
  Dfs(sy, -1);
  for (int i = 1; i <= n; ++i) {
    for (int k : gr[i]) {
      if (![](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
      } (i, k)) {
        safe[i] = safe[k] = true;
      }
    }
  }
  if (safe[sx]) {
    fout << -1 << endl;
    return 0;
  }
  int ans = 0;
  memset(d, 0xff, sizeof d);
  d[sx] = 0;
  queue<int> Q;
  Q.push(sx);
  while (!Q.empty()) {
    int k = Q.front();
    Q.pop();
    if (d[k] >= dep[k]) {
      continue;
    }
    if (safe[k]) {
      fout << -1 << endl;
      return 0;
    }
    ans = max(ans, dep[k] * 2);
    for (int x : gr[k]) {
      if (!vis[x] && d[k] + 1 < dep[x] && [](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
        } (k, x)) {
        d[x] = d[k] + 1;
        vis[x] = true;
        Q.push(x);
      }
    }
  }
  fout << ans << endl;
  return 0;
}


Measured memory_bytes: 33532
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int ans=111;
  while(ans<N)ans+=111;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

bool eq(char a, char b) {
  if (a == '?' || b == '?') return true;
  return a == b;
}

vector<int> g(string a, string b) {
  vector<int> res(a.size() + 1);
  for (int i = 0; i <= a.size(); i++) {
    for (int j = 0; i + j < a.size() && j < b.size(); j++) {
      if (eq(a[i + j], b[j])) {
        res[i]++;
      } else break;
    }
  }
  return res;
}

int f(string a, string b, string c) {
  int res = INT_MAX;
  auto ab = g(a, b);
  auto ac = g(a, c);
  auto bc = g(b, c);
  const int A = a.size();
  const int B = b.size();
  const int C = c.size();
  for (int i = 0; i <= A; i++) {
    for (int j = 0; i + j <= A || j <= B; j++) {
      bool ok = true;
      ok &= min(A - i, B) == ab[i];
      ok &= j >= B || min(B - j, C) == bc[j];
      ok &= i + j >= A || min(C, A - (i + j)) == ac[i + j];
      if (ok) {
        res = min(res, max({A, i + B, i + j + C}));
      }
    }
  }
  return res;
}

int main() {
  string a, b, c; cin >> a >> b >> c;
  int ans = INT_MAX;
  ans = min(ans, f(a, b, c));
  ans = min(ans, f(a, c, b));
  ans = min(ans, f(b, a, c));
  ans = min(ans, f(b, c, a));
  ans = min(ans, f(c, a, b));
  ans = min(ans, f(c, b, a));
  cout << ans << endl;
}

Measured memory_bytes: 256
def v():
 from collections import deque
 H,W,N=map(int,input().split())
 e='X'*(W+2)
 M=e+''.join('X'+input()+'X'for _ in[0]*H)+e
 m=(1,-1,W+2,-W-2)
 def f(s,g):
  p,t=s,0
  q=deque()
  b=[1]*len(M);b[s]=0
  while 1:
   for d in m:
    n=p+d
    if'X'!=M[n]and b[n]:
     if M[n]==g:return(n,t+1)
     b[n]=0;q.append([n,t+1])
   p,t=q.popleft()
 s=M.find('S')
 a=0
 for i in range(1,N+1):
  s,t=f(s,str(i))
  a+=t
 print(a)
v()


Measured memory_bytes: 14952
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

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

    int n, l;

    cin>>n>>l;

    vector<int> arr;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        arr.push_back(l + i - 1);
        sum += l + i - 1;
    }

    int Min = 1e6, idx;
    for(int i = 0; i < arr.size(); i++){
        int temp = sum - arr[i];
        if(abs(sum - temp) < Min){
            Min = abs(sum- temp);
            idx = i;
        }
    }

    cout<<sum - arr[idx]<<endl;

    return  0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int cnt = 0;
    for (int i = 0; i < S.length(); i++) {
      for (int j = 0; j < S.length(); j++) {
        if (S.charAt(i) == S.charAt(j)) {
          cnt++;
        }
      }
    }
    if (cnt - S.length() == 0) {
      System.out.println("yes");
    } else {
      System.out.println("no");
    }
  }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	cin >> n;
	
	int ans = 0;
	int mxc = -1;
	for(int i = n; 1 <= i; --i){
		int tmp = i;
		int count = 0;
		while(tmp % 2 == 0){
			tmp /= 2;
			count++;
		}
		if(mxc < count){
			mxc = count;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll a,b,x; cin>> a >> b >> x;
    ll res = b/x - max(0LL,(a-1))/x;
    out(res + (a==0));
}


Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
nums = list(map(int, stdin.readline().split()))

# Gives TLE
def naive_2D_dp(n, nums):
    # let dp[i][j]: maximum sum of j elements chosen from the first i elements where no two are adjacent.

    # dp[i][j] = max(dp[i-2][j-1] + nums[i], dp[i-1][j]); maximum between selecting the ith element and not selecting it. If we select, we have to use dp[i-2][j-1] to prevent adjacent.

    dp = [[0]*(n//2 + 1) for i in range(n+1)]

    # sum of 0 to select 0 elements
    for i in range(1, n+1):
        dp[i][0] = 0

    # to select one out of one.
    dp[1][1] = nums[0]

    for i in range(1, n+1):
        for j in range(1, i//2 + 1):
            dp[i][j] = max(nums[i-1] + (dp[i-2][j-1] if i>1 and j>0 else 0), dp[i-1][j] if i>0 else 0)

    print(dp[n][n//2])


# Source: https://icode54.blogspot.com/p/dp-1-atcoder-beginner-contest-162.html
def oneD_dp(n, nums):
    # let dp[i] be the maximum sum after picking i/2 elements. Two cases: i is odd, i is even. In both we choose the max from selecting i, and not selecting i.


    # Case 1) i is even (pick exactly i/2 elements): dp[i] = max(dp[i-2] + nums[i], odd indices sum). 
    # 1 2 3 4 5 6. If you pick 6 (i) you check the max of (i-2). If you don't pick 6, to pick i/2 elements you ave to pick the odd indices : 1, 3, 5.

    # Case 2) i is odd (i/2 is same as (i-1)/2 if we don't pick): dp[i] = max(dp[i-2] + nums[i], dp[i-1])

    # odd indices prefix sum needed for even case.
    oddpref = [0]*(n+1)
    oddpref[1] = nums[0]

    for i in range(3, n+1, 2):
        if i%2:
            oddpref[i] += oddpref[i-2] + nums[i-1]
    
    dp = [0]*(n+1)
    dp[0] = 0
    dp[1] = 0
    for i in range(2, n+1):
        if i%2 == 0:
            dp[i] = max(dp[i-2] + nums[i-1], oddpref[i-1])
        else:
            dp[i] = max(dp[i-2] + nums[i-1], dp[i-1])
    print(dp[n])

oneD_dp(n, nums)

Measured memory_bytes: 91980
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{	
	int N,K,X,Y,sum=0;
	cin>>N>>K>>X>>Y;
	for(int i=1;i<=N;i++)
	{
		if(i<(K+1)){sum=i*X;}
		if(i>=(K+1)){sum=K*X+(i-K)*Y;}
	}
	cout<<sum<<endl; 
	return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(1){
   if (x->left!=NIL){
    x=x->left;
    return x;
  }
   else{
     break;
   }
  }
}

Node treeMaximum(Node x){
  while(1){
   if (x->right!=NIL){
    x=x->right;
    return x;
  }
   else{
     break;
   }
  }
}

Node treeSearch(Node u, int k){

}

Node treeSuccessor(Node x){

}

void treeDelete(Node z){
  Node y; 
  Node x; 



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(1){
  if(x==NIL){
      break;
    }
    else{
      y=x;
      if(x->key < z->key){
    x=x->right;
      }
      else{
    x=x->left;
      }
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
  if(z->key < y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }
  }
}

void inorder(Node u){
  if( u == NIL ) return ;
  inorder( u->left );
  printf(" %d",u->key);
  inorder( u->right );
}
void preorder(Node u){
  if( u == NIL ) return ;
  printf(" %d",u->key);

  preorder( u->left );
  preorder( u->right );
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 25180
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 300000;
int P[N], Q[N];
int X[20][N];
int ask(int l, int r)
{
    int d = log2(r - l + 1);
    return (Q[X[d][l]] < Q[X[d][r - (1 << d) + 1]]? X[d][l]: X[d][r - (1 << d) + 1]);
}
int task(int l, int r)
{
    if (l & 1) return ask(l / 2 + 1, (r + 1) / 2) * 2 - 1;
    else return (ask(l / 2 + n / 2, r / 2 + n / 2) - n / 2) * 2;
}
vector <int> ans;
struct node
{
    int l, r, w;
};
int operator < (node a, node b) {return a.w > b.w;}
priority_queue <node> H;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> P[i];
    for (int i = 1; i <= n / 2; ++ i)
        Q[i] = P[i * 2 - 1], Q[i + n / 2] = P[i * 2];
    for (int i = 1; i <= n; ++ i) X[0][i] = i;
    for (int i = 1; i < 20; ++ i)
        for (int j = 1; j <= n; ++ j)
            X[i][j] = (Q[X[i - 1][j]] < Q[X[i - 1][j + (1 << (i - 1))]]? X[i - 1][j]: X[i - 1][j + (1 << (i - 1))]);

    H.push((node){1, n, P[task(1, n)]});
    while (!H.empty())
    {
        node t = H.top(); H.pop();
        int l = task(t.l, t.r), r = task(l + 1, t.r);
        ans.push_back(P[l]); ans.push_back(P[r]);
        if (t.l <= l - 1) H.push((node){t.l, l - 1, P[task(t.l, l - 1)]});
        if (l + 1 <= r - 1) H.push((node){l + 1, r - 1, P[task(l + 1, r - 1)]});
        if (r + 1 <= t.r) H.push((node){r + 1, t.r, P[task(r + 1, t.r)]});
    }
    for (int i = 0; i < ans.size(); ++ i) cout << ans[i] << ' ';
}


Measured memory_bytes: 27816
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
char S[2001][2001];
int vorsum[2001][2001]={};
int yokoedgesum[2001][2001]={},tateedgesum[2001][2001]={};
int main(){
	int N,M,Q;
	scan(N);scan(M);scan(Q);
	rep(i,N){
		scan(S[i]);
	}
	rep(i,N){
		rep(j,M){
			vorsum[i+1][j+1]=vorsum[i+1][j]+S[i][j]-'0';
		}
	}
	rep(j,M+1){
		rep(i,N){
			vorsum[i+1][j]+=vorsum[i][j];
		}
	}
	rep(i,N){
		rep(j,M){
			yokoedgesum[i+1][j+1]=yokoedgesum[i+1][j]+(j>0 ? ((S[i][j-1]-'0')&(S[i][j]-'0')) : 0);
		}
	}
	rep(j,M+1){
		rep(i,N){
			yokoedgesum[i+1][j]+=yokoedgesum[i][j];
		}
	}
	rep(j,M){
		rep(i,N){
			tateedgesum[i+1][j+1]=tateedgesum[i][j+1]+(i>0 ? ((S[i-1][j]-'0')&(S[i][j]-'0')) : 0);
		}
	}
	rep(i,N+1){
		rep(j,M){
			tateedgesum[i][j+1]+=tateedgesum[i][j];
		}
	}
	rep(i,Q){
		int x1,y1,x2,y2;
		scan(x1);scan(y1);scan(x2);scan(y2);
		int vortex=vorsum[x2][y2]+vorsum[x1-1][y1-1]-vorsum[x2][y1-1]-vorsum[x1-1][y2];
		int yokoedge=yokoedgesum[x2][y2]+yokoedgesum[x1-1][y1]-yokoedgesum[x2][y1]-yokoedgesum[x1-1][y2];
		int tateedge=tateedgesum[x2][y2]+tateedgesum[x1][y1-1]-tateedgesum[x2][y1-1]-tateedgesum[x1][y2];
		prin(vortex-yokoedge-tateedge);
	}
	return 0;
}


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

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int k, a, b;
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++){
		if(i % k == 0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3660
$n=<>;
for(1..$n){
    $a=<>;
    push(@A,$a);
}
$p=0;
while($A[$p]!=-1){
    $t=$A[$p]-1;
    $k++;
    last if($t==1);
    $A[$p]=-1;
    $p=$t;
}
print+($t==1)?$k:-1

Measured memory_bytes: 10752
#include<stdio.h>
#define N 8
int row[N],col[N],pos[2*N-1],neg[2*N-1],A[N][N],i=0,j=0,k,r,c;
void print(void);

void recursive(int i){
  int j;
  if(i==N){
    print();
    return;
  }

  for(j=0; j<N; j++){
    if(row[j]==1 || pos[i+j]==1 || neg[i-j+N-1]==1)
			continue;
		col[i] = j;
    row[j] = pos[i+j] = neg[i-j+N-1] = 1;
    recursive(i+1);
    col[i] = row[j] = pos[i+j] = neg[i-j+N-1] = -1;
  }
}

void initial(){
  int i=0;
	while(i<N){
    row[i] = -1;
    col[i] = -1;
    i++;
	}
	i=0;
  while(i<2*N-1){
    pos[i] = -1;
    neg[i] = -1;
    i++;
  }
}

void print(){
  int i=0,j;
  while(i<N){
    j=0;
    while(j<N){
      if(A[i][j] == 1)
				if(col[i]!=j) return;
      j++;
    }
    i++;
  }
    i=0;
  while(i<N){
    j=0;
    while(j<N){
      if(col[i]==j) printf("Q");
      else printf(".");
      j++;
    }
    printf("\n");
    i++;
  }
}

int main(){
  initial();

  while(i<N){
    while(j<N){
      A[i][j] = -1;
      j++;
    }
    i++;
  }
  scanf("%d",&k);
  i=0;
  while(i<k){
    scanf("%d%d",&r,&c);
    A[r][c] = 1;
    i++;
  }

  recursive(0);

  return 0;
}


Measured memory_bytes: 2084
#include <stdio.h>
int gc(int a, int b)
{
	int r, r2, tmp;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
	int gcd(int a, int b, int c)
	{
		int r,r2;
		r =gc(a, b);
		r2 = gc(r, c);
//		printf("%d %d %d -%d\n", a,b,c,r2);
		return r2;
	}
	int main(void)
	{
		int i, j, m;
		int cnt = 0, K;
		scanf("%d", &K);
		for (i = 1; i <= K; i++)
		{
			for (j = 1; j <= K; j++)
			{
				for (m = 1; m <= K; m++)
				{
					cnt += gcd(i, j, m);
				}
			}
		}
		printf("%d\n", cnt);
		return 0;
	}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll n, k;
	ll ans = 0;

	cin >> n >> k;

	ans = min(abs(n % k), abs(k - n % k));

	cout << ans << "\n";
}

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

	solve_abc();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int digit_count(int n){
    int i =0;
    while(n != 0){
        n /= 10;
        i++;
    }
    return(i);
}

int f(int a,int b){
    return(max(digit_count(a), digit_count(b)));
}
int main() {
    long long N;
    int mi=11;
    cin>>N;
    for(int i=sqrt(N)+1;i>0;i--){
        if(N%i==0){
            mi=min(mi,f(i,N/i));
            break;
        }
    }
    cout <<mi<<endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappop,heappush

N,M,S,T = map(int, input().split())
S -= 1; T -= 1
G = [[] for _ in range(N)]
for _ in range(M):
    u,v,a,b = map(int, input().split())
    G[u-1].append({"to":v-1, "yen":a, "snuuk":b})
    G[v-1].append({"to":u-1, "yen":a, "snuuk":b})

def dijkstra(sta:int, how:str):
    """
    頂点staから各頂点への最小コスト
    how: "yen" or "snuuk"
    """
    cost = [float("inf")] * N
    cost[sta] = 0
    que = [(0, sta)]

    while que:
        c,v = heappop(que)
        if cost[v] < c: continue
        for e in G[v]:
            if cost[e["to"]] > cost[v] + e[how]:
                cost[e["to"]] = cost[v] + e[how]
                heappush(que, (cost[e["to"]], e["to"]))
    
    return cost

# 頂点i - T をスヌークで移動
snuuk = dijkstra(T, "snuuk")
# S - 頂点i を円で移動
yen = dijkstra(S, "yen")

cost = [s + y for s,y in zip(snuuk,yen)]

ans = []
MINCOST = float("inf")
for year in range(N - 1, -1 ,-1):
    MINCOST = min(MINCOST, cost[year])
    ans.append(10 ** 15 - MINCOST)

print(*reversed(ans),sep="\n")

Measured memory_bytes: 108756
// in the name of god 
// vaght hast vali kam ast !

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

const int MAXN = 1e6 + 100 ;

int sz[MAXN] ; 
vector<int> ver[MAXN] ;
void dfs(int v , int par = 0){
	sz[v] = 1 ; 
	int tmp = 0 ; 
	for(auto u : ver[v]){
		if(u == par)continue ; 
		dfs(u , v) ; 
		tmp += sz[u] % 2 ; 
		sz[v] += sz[u] ; 
	}
	if(tmp > 1){cout << "First" ; exit(0) ; }
}
int32_t main(){
	ios_base::sync_with_stdio(0) ;
	cin . tie(0) ; cout . tie(0) ; 

	int n ; cin >> n ;  

	for(int i = 1 ; i < n ; i ++){
		int x , y ; cin >> x >> y ; 
		x -- , y -- ; 
		ver[x] . push_back(y) ; 
		ver[y] . push_back(x) ; 
	}
	if(n % 2) return cout << "First" , 0; 
	dfs(0) ; 
	cout << "Second" ; 
}

Measured memory_bytes: 28032
#include <stdio.h>

int main(void) {
	char s[3];
	scanf("%s", s);
	int i;
	int count = 0;
	for (i = 0; i < 3; i++) {
		if (s[i] == '1') count++;
	}
	printf("%d\n", count);
	return 0;
}


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

using namespace std;

int main()
{
    int n,d,x;
    cin>>n;
    int str[n+5];
    cin>>d>>x;
    int i,j;
    for(i=1; i<=n; i++)
        cin>>str[i];
    int sum=0;
    for(j=1; j<=n; j++)
    {
        for(i=1; i<=d;)
        {
            if(i==1)
            {
                sum++;
                i=i+str[j];
            }
            else
            {
                sum++;
                i=i+str[j];
                if(i>d)
                    break;
            }
        }
    }
    cout<<sum+x;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int H, W;
    cin >> H >> W;
    auto a = make_v<char>(H, W);
    rep(i, H) rep(j, W) cin >> a[i][j];
    for (int i = 0; i < a.size(); i++)
    {
        bool erase = true;
        for (int j = 0; j < W; j++)
        {
            if (a[i][j] == '#')
                erase = false;
        }
        if (erase)
        {
            a.erase(a.begin() + i);
            i--;
        }
    }

    for (int j = 0; j < a[0].size(); j++)
    {
        bool erase = true;
        for (int i = 0; i < a.size(); i++)
        {
            if (a[i][j] == '#')
                erase = false;
        }
        if (erase)
        {
            for (int i = 0; i < a.size(); i++)
            {
                a[i].erase(a[i].begin() + j);
            }
            j--;
        }
    }

    rep(i, a.size())
    {
        rep(j, a[0].size()) cout << a[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, fractions, itertools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, H: "List[int]"):
    c = H[-1]
    for h in reversed(H):
        if h-1 > c:
            print('No')
            return
        elif h - 1 == c:
            pass
        elif h == c:
            pass
        else:
            c = h
    print('Yes')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17620
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        Integer[] A = new Integer[200001];
        Arrays.fill(A, 0);
        for (int i = 0; i < N; i++) {
            A[sc.nextInt()]++;
        }
        Arrays.sort(A, Collections.reverseOrder());

        int sum = 0;

        for (int i = K; i < 200000; i++) {
            sum += A[i];
        }

        System.out.printf("%d\n", sum);
        sc.close();
    }
}

Measured memory_bytes: 87704
import sys
h, n = [int(i) for i in sys.stdin.readline().split()]
ls = []
INF = 10**9
for i in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    ls.append([a, b])
memo_ls = [[INF for j in range(h+1)] for i in range(n+1)]
memo_ls[0][0] = 0
for i, (a, b) in enumerate(ls, 1):
    for j in range(h+1):
        memo_ls[i][j] = min(memo_ls[i][max(0, j-a)] + b, memo_ls[i-1][j])
print(memo_ls[-1][-1])

Measured memory_bytes: 125788