akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k; cin >> n >> k;
    vector<int> l(n);
    for(int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans=0;
    for(int i = n - 1; i > n - k - 1; i--)
    {
        ans += l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//最古の遺跡

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
using namespace std;
int N, A, B, MAX, MIN;
int main() {
	cin >> N >> A >> B;
	MAX = min(A, B);
	if (A + B <= N)MIN = 0;
	else {
		MIN = A + B - N;
	}
	cout << MAX << " " << MIN << endl;

	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string s = io.r<string>();
        string u = s.ToUpper();
        string l = s.ToLower();
        for (int i = 0; i < s.Count(); i++)
        {
            if (s[i] == u[i])
            {
                io.w(l[i], false);
            }
            else
            {
                io.w(u[i], false);
            }
        }
        io.w("");
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=b)
    {
        for(int i=1;i<=b;++i)
            cout<<a;
    }
    else
    {
        for(int i=1;i<=a;++i)
            cout<<b;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b;
    int ttl;

    cin >> a >> b;
    ttl = a + b;
    if(ttl < (a - b)) ttl = a - b;
    if(ttl < (a * b)) ttl = a * b;

    cout << ttl << '\n';

    return 0;
}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		int a = ni();
		int b = ni();
		int uncovered = a - 2 * b;
		System.out.println(uncovered >= 0 ? uncovered : 0);
	}

	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

int main() {
  int month, date;
  int day[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  const char *label[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
  int day_sum[12];
  int x;

  day_sum[0] = 0;
  for (int i=1; i<12; i++) {
    day_sum[i] = day_sum[i-1] + day[i-1];
  }

  while (1) {
    cin >> month >> date;
    if (!month && !date) break;
    x = day_sum[month-1] + date + 2;
    cout << label[x%7] << endl;
  }

  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
bool b[50001];
int a[50001];
int main(){
  b[0]=b[1]=1;
  for(int i=2;i<50001;i++)
    for(int j=i+i;j<50001;j+=i)
      b[j]=1;
  for(int i=4;i<50001;i++){
    for(int j=2;j<=i/2;j++){
      if(!b[j]){
        if(j+j==i||(!b[i-j]))a[i]++;
      }
    }
  }
  int n;
  while(cin>>n,n)cout<<a[n]<<endl;
}

Measured memory_bytes: 3248
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
int inp[100005];
vector<int> v;
 
int N;
int tree[200005];
const int BASE = 1e5 + 2;

void update(int i, int v) {
	i += BASE;
	while (i < 200005) {
		tree[i] += v;
		i += i & -i;
	}
}
 
int find(int i) {
	i += BASE;
	int ret = 0;
	while (i) {
		ret += tree[i];
		i -= i & -i;
	}
	return ret;
}
 
ll cal(int cur) {
	memset(tree, 0, sizeof tree);
	update(0, 1);
	int st = 0;
	ll ret = 0;
	for (int i = 1; i <= N; i++) {
		st += inp[i] <= cur ? 1 : -1;
		ret += find(st - 1);
		update(st, 1);
	}
	return ret;
}
 
int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		int x; scanf("%d", &x);
		inp[i] = x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (int i = 1; i <= N; i++) {
		inp[i] = lower_bound(v.begin(), v.end(), inp[i]) - v.begin();
	}
	ll tot = (ll)N * (N + 1) / 2;
	ll target = tot / 2 + 1;
 
	int l = -1, r = v.size();
	while (l + 1 < r) {
		int mid = l + r >> 1;
		if (cal(mid) >= target) r = mid;
		else l = mid;
	}
	printf("%d", v[r]);
}

Measured memory_bytes: 1912
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> x >> y;
  if (x == 3)
    ans += 100000;
  else if (x == 2)
    ans += 200000;
  else if (x == 1)
    ans += 300000;

  if (y == 3)
    ans += 100000;
  else if (y == 2)
    ans += 200000;
  else if (y == 1)
    ans += 300000;

  if (x == 1 && y == 1) ans += 400000;

  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    loop {
        let g: String = sc.read();
        if g == "#" {
            break;
        }
        let y: usize = sc.read();
        let m: usize = sc.read();
        let d: usize = sc.read();
        if (y, m, d) <= (31, 4, 30) {
            println!("HEISEI {} {} {}", y, m, d);
        } else {
            println!("? {} {} {}", y - 30, m, d);
        }
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 5036
def main():
  a,b,c = map(int,input().split())
  s = [a,b,c]

  cnt = 0
  while (a % 2 == 0) and (b % 2 == 0) and (c % 2 == 0):
    
    a1,b1,c1 = a,b,c
    a = (b1+c1)//2
    b = (a1+c1)//2
    c = (a1+b1)//2
    
    if [a,b,c] == s:
      return -1
    
    cnt += 1
    #print(a,b,c)
    
  return cnt    
    

ans = main()
print(ans)

Measured memory_bytes: 9212
#include <cstdio>
#include <string>
using namespace std;

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

  int i = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++)
  {
    int sum = 0;
    string str = to_string(i);
    for (int j = 0; j < str.length(); j++)
    {
      sum += str[j] - '0';
    }
    if (a <= sum && sum <= b)
    {
      ans += i;
    }
  }

  printf("%d\n", ans);
}

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

bool changeX, changeY;

int sx, sy, tx, ty;

int main() {
    changeX = changeY = false;
    scanf( "%d%d%d%d", &sx, &sy, &tx, &ty );
    tx -= sx;
    ty -= sy;
    sx = sy = 0;
    if( tx < 0 ) {
        tx = -tx;
        changeX = true;
    }
    if( ty < 0 ) {
        ty = -ty;
        changeY = true;
    }
    string ans;
    if( sx == tx ) {
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'U';
        }
        ans += 'R';
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'D';
        }
        ans += 'L';
        ans += 'R';
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'U';
        }
        ans += 'R';
        ans += "URR";
        for( int i = 0; i < ty-sy+1; ++i ) {
            ans += 'D';
        }
        ans += "LLU";
    } else if( sy == ty ) {
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'R';
        }
        ans += 'U';
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'L';
        }
        ans += 'D';
        ans += 'D';
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'R';
        }
        ans += 'U';
        ans += "RUU";
        for( int i = 0; i < ty-sy+1; ++i ) {
            ans += 'L';
        }
        ans += "DDR";
    } else {
        for( int i = 0; i < tx-sx; ++i ) {
            ans += 'R';
        }
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'U';
        }
        for( int i = 0; i < tx-sx; ++i ) {
            ans += 'L';
        }
        for( int i = 0; i < ty-sy; ++i ) {
            ans += 'D';
        }
        ans += 'D';
        for( int i = 0; i < tx-sx+1; ++i ) {
            ans += 'R';
        }
        for( int i = 0; i < ty-sy+1; ++i ) {
            ans += 'U';
        }
        ans += 'L';
        ans += 'U';
        for( int i = 0; i < tx-sx+1; ++i ) {
            ans += 'L';
        }
        for( int i = 0; i < ty-sy+1; ++i ) {
            ans += 'D';
        }
        ans += 'R';
    }

    int size = ans.size();
    if( changeX ) {

        for( int i = 0; i < size; ++i ) {
            if( ans[i] == 'L' ) {
                ans[i] = 'R';
            } else if( ans[i] == 'R' ) {
                ans[i] = 'L';
            }
        }
    }
    if( changeY ) {
        for( int i = 0; i < size; ++i ) {
            if( ans[i] == 'U' ) {
                ans[i] = 'D';
            } else if( ans[i] == 'D' ) {
                ans[i] = 'U';
            }
        }
    }
    cout<<ans<<endl;
}






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

using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<long long> size;

    UnionFind(int N) : par(N), size(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
            size[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    long long unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return 0; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        long long ret = size[rx] * size[ry];
        size[ry] += size[rx];
        return ret;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
    long long  N,M;
    long long  A[100000], B[100000];

    cin >> N >> M;
    for (int i=0; i<M; i++) {
        int a,b;
        cin >> a >> b;
        A[i] = a-1;
        B[i] = b-1;
    }
    cerr << "ok" << endl;
    long long  hubensa_add[100000];
    UnionFind G(N);
    for (int k = M-1; k >= 0; k--) {
        if (G.same(A[k], B[k])) {
            cerr << k+1 << " " << A[k]+1 <<" "<< B[k] + 1 << " same" << endl;
            hubensa_add[k] = 0;
        } else {
            cerr << k+1 << " " << A[k]+1 <<" "<< B[k] + 1 << endl;
            cerr << "size" << " " << G.size[A[k]] <<" "<< G.size[B[k]] << endl;
            // A-group <=> B-group 's max strength is k
            hubensa_add[k] = G.unite(A[k], B[k]);
        }
    }
    long long hubensa = 0;
    for (int i=0; i<M; i++) {
        hubensa += hubensa_add[i];
        cout << hubensa << endl;
    }

    return 0;
}

Measured memory_bytes: 4864
#include<iostream>

int main(){

    size_t n, cnt = 0;
    size_t h1;

    std::cin >> n;

    for(size_t i = 0; i < n; i++){
        if(i == 0){
            std::cin >> h1;
            cnt++;
        }else{
            size_t tmp;
            std::cin >> tmp;
            if(tmp == h1){
                cnt++;
            }else if(tmp > h1){
                cnt++;
                h1 = tmp;
            }
        }
    }

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


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

L = [LIST() for i in range(N-1)]

color = [0] * N
color[0] = 1

graph = defaultdict(list)

for u, v, w in L:
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))

# q = []
# q.append((0, 0))

def dfs(n):
    q = [n]
    while q:
        n = q.pop()
        for node, w in graph[n]:
            if color[node] == 0:
                if w % 2 == 0:
                    color[node] = color[n]
                else:
                    color[node] = color[n] * (-1)
                q.append(node)
# dfs(0)
dfs(0)
# print(color)
for c in color:
    if c == 1:
        print(0)
    else:
        print(1)







    


    

    


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

# define ll long long

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

    ll n,k;
    cin>>n>>k;
    ll sum=0;
    ll ar[n];
    for(ll i=0;i<n;i++)
        cin>>ar[i];
    sort(ar,ar+n);
    for(int i=0;i<k;i++)
        sum+=ar[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
 
void insertionSort(int A[],int N);
 
 int main(void)
 {
    int i,N;
    scanf("%d",&N);
    int A[N];
    for (i = 0;i < N;i++) {
        scanf("%d",&A[i]);
    }
    insertionSort(A,N);
    return 0;
 }

 void insertionSort(int A[],int N)
 {
  int i,v,j,e;
   for (i = 1;i < N + 1;i++) {
     for (e = 0;e < N;e++) {
	if (e == N - 1)
		printf("%d\n",A[e]);
        else printf("%d ",A[e]);
     }
     if (i == N)
	return;
     v = A[i];
     j = i - 1;
     while (j >= 0  && A[j] > v) {
       A[j + 1] = A[j];
       j--;
     A[j + 1] = v;
     }
   }
 }


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

using namespace std;

int main() {

    char num[10][10];

    while(1) {

        for(int i = 0; i < 10; ++i) {
            if(!(cin >> num[0][i])) {
                return 0;
            }
            num[0][i] -= '0';
        }

        for(int i = 1; i < 10; ++i) {
            for(int j = 0; j < 10 - i; ++j) {
                num[i][j] = (num[i - 1][j] + num[i - 1][j + 1]) % 10;
            }
        }

        cout << (int)num[9][0] << endl;

    }

}

Measured memory_bytes: 1140
from collections import deque,defaultdict
import sys
sys.setrecursionlimit(10**7)
N,Q=map(int,input().split())
table=[[] for i in range(N)]
ddcost=defaultdict(tuple)
for i in range(N-1):
    a,b,c,d=map(int,input().split())
    a,b,c=a-1,b-1,c-1
    table[a].append(b)
    table[b].append(a)
    ddcost[(min(a,b),max(b,a))]=(c,d)
#print(table)
#print(ddcost)
H=deque()
H.append(0)
visit=[-1]*N
visit[0]=0
parent=[[-1]*N for i in range(18)]
while H:
    x=H.popleft()
    for y in table[x]:
        if visit[y]!=-1:
            continue
        parent[0][y]=x
        visit[y]=visit[x]+1
        H.append(y)
for k in range(17):
    for i in range(N):
        if parent[k][i]<0:
            parent[k+1][i]=-1
        else:
            parent[k + 1][i]=parent[k][parent[k][i]]
def lca(u,v):
    if visit[u]>visit[v]:
        u,v=v,u
    for k in range(18):
        if ((visit[v]-visit[u] )>>k)&1:
            v=parent[k][v]
    if u==v:
        return u
    for k in range(17,-1,-1):
        if parent[k][u]!=parent[k][v]:
            u=parent[k][u]
            v=parent[k][v]
    return parent[0][u]

query=[]
sakidori=[set() for i in range(N)]
for i in range(Q):
    x,y,u,v=map(int,input().split())
    x,u,v=x-1,u-1,v-1
    if u>=v:
        u,v=v,u
    pa=lca(u,v)
    sakidori[u].add(x)
    sakidori[v].add(x)
    sakidori[pa].add(x)
    query.append((x,y,u,v,pa))
ddcolorsum=defaultdict(int)
ddcolornum=defaultdict(int)
W=deque()
colorsum=[0]*(N)
colornum=[0]*(N)
dist=[0]*N
vi=[0]*N
W.append((0,0,1))

while W:
    #print(W)
    pa,ci,vector=W.pop()
    if vector==-1:
        color,dis=ddcost[(min(pa,ci),max(pa,ci))]
        colorsum[color]-=dis
        colornum[color]-=1
        #print(colorsum, colornum, pa, ci, vector)
        continue
    if pa==0 and ci==0:
        for y in table[ci]:
            W.append((ci, y, 1))
        for co in sakidori[0]:
            ddcolorsum[(0,co)]=0
            ddcolornum[(0,co)]=0
        continue
    color,dis=ddcost[(min(pa,ci),max(pa,ci))]
    dist[ci]=dist[pa]+dis
    colorsum[color]+=dis
    colornum[color]+=1
    for co in sakidori[ci]:
        ddcolorsum[(ci, co)] = colorsum[co]
        ddcolornum[(ci, co)] = colornum[co]
    #print(colorsum,colornum,pa,ci,vector)
    W.append((pa,ci,-1))
    for y in table[ci]:
        if y==pa:
            continue
        W.append((ci,y,1))
#print(ddcolorsum)
#print(ddcolornum)
#print(dist)
def dista(x,y,u):
    return dist[u]-ddcolorsum[(u,x)]+y*ddcolornum[(u,x)]
for x,y,u,v,pa in query:
    #print(x,y,u,v,pa)
    #print(dista(x,y,u),dista(x,y,v),dista(x,y,pa))
    print(dista(x,y,u)+dista(x,y,v)-2*dista(x,y,pa))

Measured memory_bytes: 183104
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£????????????
		Scanner sc = new Scanner(System.in);
		//??\???????????????????????£?????????
		String word =sc.nextLine();
		//
		StringBuilder out = new StringBuilder();
		//??£?¨?
		 String w;
		 //
		 for(int i =0; i<word.length();i++){
			 w= word.substring(i,i+1);
			//?????£?????\?????????????°???????????????§???????????????
			 if(w.equals(w.toLowerCase())){
				 w = w.toUpperCase();
			//?????£?????\??????????????§?????????????°????????????????
			}else if(w.equals(w.toUpperCase())){
				w = w.toLowerCase();
			}
			 System.out.append(w);
		 }

		 //??¨???
		 System.out.println(out);
	}
}

Measured memory_bytes: 27320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {
	ll h, a;
	cin >> h >> a;
	cout << (h % a == 0 ? h / a : h / a + 1)  << endl;
}

Measured memory_bytes: 256
def num():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    a=sorted(a,reverse=True)
    for i in range(m):
        if a[i]<(sum(a)/(4*m)):
            # print(sum(a)/12)
            return "No"
    return "Yes"
print(num())


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int p(int A,int B){
  if(B<0)return 0;
  if(!B)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
signed main(){
  string S;
  cin>>S;
  int N=S.size();
  map<char,int> mp,mp2;
  for(char c:S)mp[c]++;
  int ans=0,p1=p(3,mp['?']),p2=p(3,mod-2);
  for(char c:S){
    mp[c]--;
    if(c=='B'){
      ans=(ans+mp2['A']*mp['C']%mod*p1%mod)%mod;
      ans=(ans+mp2['A']*mp['?']%mod*p1%mod*p2%mod)%mod;
      ans=(ans+mp2['?']*mp['C']%mod*p1%mod*p2%mod)%mod;
      ans=(ans+mp2['?']*mp['?']%mod*p1%mod*p(p2,2)%mod)%mod;
    }else if(c=='?'){
      ans=(ans+mp2['A']*mp['C']%mod*p1%mod*p2%mod)%mod;
      ans=(ans+mp2['A']*mp['?']%mod*p1%mod*p(p2,2)%mod)%mod;
      ans=(ans+mp2['?']*mp['C']%mod*p1%mod*p(p2,2)%mod)%mod;
      ans=(ans+mp2['?']*mp['?']%mod*p1%mod*p(p2,3)%mod)%mod;
    }
    mp2[c]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=110;
string s[maxn];
set<string>st;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        st.insert(s[i]);
    }
    if(st.size()!=n)
        cout<<"No"<<endl;
    else
    {
        for(int i=2;i<=n;i++)
        {
            string s1=s[i-1];
            string s2=s[i];
            int k=s1.size();
            if(s1[k-1]!=s2[0])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<map>
using namespace std;
int par1[200005],par2[200005];
int rank1[200005],rank2[200005];
typedef pair<int,int> P;
map<P,int>m;
int find(int *par,int x)
{
    if(x==par[x])
        return x;
    else
        return par[x]=find(par,par[x]);
}
void unite(int *par,int *rank,int x,int y)
{
    x=find(par,x);
    y=find(par,y);
    if(x==y)
        return ;
    else
    {
        if(rank[x]>rank[y])
            par[y]=x;
        else
        {
            par[x]=y;
            if(rank[x]==rank[y])
                rank[y]++;
        }
    }
}
int main()
{
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    int p,q;
    for(int i=1;i<=n;i++)
    {
        par1[i]=par2[i]=i;
        rank1[i]=rank2[i]=0;
    }
    for(int i=0;i<k;i++)
    {
        scanf("%d%d",&p,&q);
        unite(par1,rank1,p,q);
    }
    for(int i=0;i<l;i++)
    {
        scanf("%d%d",&p,&q);
        unite(par2,rank2,p,q);
    }
    for(int i=1;i<=n;i++)
    {
        find(par1,i);
        find(par2,i);
    }
    for(int i=1;i<=n;i++)
    {
        m[P(par1[i],par2[i])]++;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",m[P(par1[i],par2[i])]);
    }
    return 0;
}


Measured memory_bytes: 15104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  double n;
  double a[5];
  cin >> n;
  REP(i,5){
    cin >> a[i];
  }
  
  double mn = a[0];
  REP(i,5){
    mn = min(mn, a[i]);
  }

  cout << (llong)ceil(n / mn) + 4 << endl;

  return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  long long res = 1LL<<60;
  for (int i = 0; i <= N; ++i) {
    long long val = (1LL<<i) + K * (N-i);
   	res = min(res, val);
  }
  cout << res << endl;
}

Measured memory_bytes: 3544
n,m,x,y=list(map(int,input().split()))
l_x=list(map(int,input().split()))
l_y=list(map(int,input().split()))
x_max=max(l_x)
y_min=min(l_y)
for i in range(x_max+1,y_min+1):
    if x<i<=y:
        print('No War')
        exit()
print('War')



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <sstream>
#include <numeric>
using namespace std;

int main(){
    string s ;
    cin >> s ;
    if (s.size() == 3)
    {
        reverse(s.begin(),s.end()) ;
        cout << s << endl ;
    }else
    {
        cout << s << endl ;
    }
    
    
}

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


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

bool prime(long long x)
{
    long long max;
    max = pow(x, 0.5);
    bool ans = true;
    for (long long i = 2; i <= max; i++)
    {
        if(x%i==0)
            ans = false;
    }
    return ans;
}

int main() 
{
    long long x;
    cin >> x;
    for (long long i = x;true;i++)
    {
        if(prime(i)==true)
        {
            cout << i << endl;
            return 0;
        }
    }

        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=200005;
ll dp[50][2],BIT[50],BIT2[50];
vll v;
ll f(ll idx,ll c)
{
	if(idx==41)
		return 0;
	ll &ans=dp[idx][c];
	if(ans!=-1)
		return ans;
	if(c==0)
		ans=f(idx+1,0)+max(BIT[40-idx],BIT2[40-idx]);
	else
	{
		if(v[idx]==0)
			ans=f(idx+1,1)+BIT[40-idx];
		else
			ans=max(f(idx+1,1)+BIT2[40-idx],f(idx+1,0)+BIT[40-idx]);
	}
	return ans;
}
void solve()
{
	ll n,k,a[N],i,j;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{	
		cin>>a[i];
		for(j=40;j>=0;j--)
			if(a[i]&(1LL<<j))
				BIT[j]+=(1LL<<j);
			else
				BIT2[j]+=(1LL<<j);
	}

	for(i=40;i>=0;i--)
	{
		if(k&(1LL<<i))
		v.pb(1);
		else
		v.pb(0);

	}

	memset(dp,-1LL,sizeof dp);
	cout<<f(0,1);
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#define MOD  1000000007
#define BIG  200001
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define vi vector<int>
#define pi pair<int,int>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define all(n) n.begin(),n.end()

typedef  long long ll;
using namespace std;

int main()
{
    // freopen("input.txt", "r", stdin);
    IO ;
  int a ,b ;
  cin >> a >>b ;
  int sum , mul , sub ;
  sum = a+b ;
  mul = a*b ;
  sub = a-b ;
  cout << max(sub  , max( sum , mul ))<< endl ;
    return 0 ;
}


Measured memory_bytes: 256
# 図を書いて整理すればいいですね 差分の配列を利用
n = int(input()) 
a = [0] + list(map(int, input().split())) + [0]
b = [0 for _ in range(n+1)]
for i in range(n+1):
  b[i] = abs(a[i] - a[i+1])

s = sum(b)

for i in range(n):
  print(s - (b[i]+b[i+1]) + abs(a[i+2] - a[i]))


Measured memory_bytes: 14176
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
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=(ll)1e+18+1;
int INF=1e+9+1;
pair<vll,vll > prime_factor_decomp(ll n) {
    vll p, e;
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        int c = 0;
        while (m % i == 0) c++, m /= i;
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return mp(p, e);
}
vll yakusu(ll n){
	vll ret;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n) ret.push_back(n/i);
		}
	}
	sort(ALL(ret));
	return ret;
}
int main(){
	ll N;
	scan(N);
	pair<vll,vll > pe1=prime_factor_decomp(N-1);
	vll p1=pe1.first,e1=pe1.second;
	ll ans=1;
	rep(i,e1.size()){
		ans*=e1[i]+1;
	}
	ans--;
	vll yaku=yakusu(N);
	for(auto m:yaku){
		ll now=N;
		if(m==1) continue;
		while(now>=m){
			if(now%m==0) now/=m;
			else now%=m;
		}
		if(now==1) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  vecint a(n);
  for(auto&& e:a)cin>>e;
  int sum=0;
  for(auto&& e:a)sum+=e;
  int cnt=0;
  for(auto&& e:a) {
    if (e * 4 * m >= sum) ++cnt;
  }
  cout<<(cnt>=m?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

ll mod = 1e9 + 7;
ll cnt[100003][30];

int main() {
	int n; cin >> n;
	string s; cin >> s;
	for (int i = n - 1; i >= 0; i--) {
		for (int c = 0; c <= 'z' - 'a'; c++) {
			cnt[i][c] = cnt[i + 1][c];
			if (s[i] == 'a' + c) cnt[i][c]++;
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll w = 1;
		for (int c = 0; c <= 'z' - 'a'; c++) {
			if (c + 'a' == s[i]) continue;
			w *= cnt[i][c] + 1;
			w %= mod;
		}
		ans = (ans + w) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23936
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	sort.Ints(h)
	res := make([]int, n)
	for i := 1; i < n; i++ {
		res[i] = h[i] - h[i-1] + res[i-1]
	}

	min := math.Inf(1)
	for i := k - 1; i < n; i++ {
		tmp := float64(res[i]) - float64(res[i-k+1])
		if min > tmp {
			min = tmp
		}
	}

	fmt.Println(int(min))
}


Measured memory_bytes: 3840
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

alpha2num = lambda c: ord(c) - ord('a') + 1

s = input()
ans = "WA"
if s[0] == "A" and s.count("C") == 1:
    if 2 <= s.index("C") <= len(s) - 2:
        for i in range(1, len(s)):
            if i == s.index("C"):
                continue
            elif 1 <= alpha2num(s[i]) <= 26:
                ans = "AC"
            else:
                ans = "WA"
                break
print(ans)

Measured memory_bytes: 3064
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == -1 {
			break
		}
		if n == 0 {
			fmt.Println(0)
			continue
		}
		ans := make([]int, 0)
		for n > 0 {
			ans = append([]int{n % 4}, ans...)
			n = n / 4
		}

		buf := make([]string, len(ans))
		for i := range ans {
			buf[i] = strconv.Itoa(ans[i])
		}
		fmt.Println(strings.Join(buf, ""))
	}
}



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

using namespace std;

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

vector<int> a;

long long solve(int pos, vector<int> &c) {
    if(pos == a.size()) {
        return 1;
    }
    int counts = 0;
    for(int i : c) if(a[pos] == i) ++counts;
    int p = -1;
    for(int i = 0; i < 3; ++i) {
        if(c[i] == a[pos]) {
            p = i;
            break;
        }
    }
    ++c[p];
    long long res = solve(pos + 1, c) * counts;
    res %= mod;
    --c[p];
    return res;
}

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        a.push_back(x);
    }
    vector<int> c({0, 0, 0});
    cout << solve(0, c) << endl;
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    int t[N], a[N];
    int time, time1, x, y, x1, y1;
    rep(i, N){
        cin>>time1>>x1>>y1;
        if(i==0){
            t[0]=time1;
            a[0]=abs(x1)+abs(y1);
            x=x1;
            y=y1;
            time = time1;
        }
        else{
            t[i]=time1-time;
            a[i]=abs(x1-x)+abs(y1-y);
            x=x1;
            y=y1;
            time=time1;
        }
    }
    int check=0;
    rep(i, N){
        if(t[i]%2!=a[i]%2){
            cout<<"No"<<endl;
            check=1;
            break;
        }
        else if(t[i]<a[i]){
            cout<<"No"<<endl;
            check=1;
            break;
        }
    }
    if(check==0){
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
const int N=10500,INF=1e9;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int S,T;
int B[2*N][3],A[N],B0=1;
int Hv[N],H[N];
void link(int q,int w,int e,int e1=1)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w,B[B0][2]=e;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q,B[B0][2]=e1;
}
int aug(int q,int e)
{
	if(q==T)return e;
	int mi=T+10;
	efo(i,q)if(B[i][2])
	{
		if(H[B[i][1]]+1==H[q])
		{
			int t=aug(B[i][1],min(e,B[i][2]));
			if(t)
			{
				B[i][2]-=t;
				B[i^1][2]+=t;
				return t;
			}
		}
		mi=min(mi,H[B[i][1]]);
	}
	if(!(--Hv[H[q]]))H[S]=T+10;
	++Hv[H[q]=mi+1];
	return 0;
}
int main()
{
	int q,w;
	read(n),read(m);
	S=0,T=n+m+1;
	fo(i,1,n)
	{
		char ch=' ';
		for(;ch!='.'&&ch!='o'&&ch!='S'&&ch!='T';ch=getchar());
		fo(j,1,m)
		{
			if(ch=='o')link(i,j+n,1);
			if(ch=='S')link(S,j+n,INF,0),link(S,i,INF,0);
			if(ch=='T')link(j+n,T,INF,0),link(i,T,INF,0);
			ch=getchar();
		}
	}
	for(Hv[0]=T+1;H[0]<T;ans+=aug(S,INF));
	if(ans>=INF)printf("-1\n");
		else printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int N;
    int C[501],S[501],F[501],Result[501];
    int i,j;
    scanf("%d",&N);
    for (i=0;i<N-1;i++)
    {
        scanf("%d%d%d",&C[i],&S[i],&F[i]);
    }
    for (i=0;i<N-1;i++)
    {
        Result[i]=S[i]+C[i];
        for (j=i+1;j<N-1;j++)
        {
            if (Result[i]<S[j])
            {
                Result[i]=S[j];
            }
            else
            {
                if (Result[i]%F[j]!=0)
                {
                    Result[i]=Result[i]-(Result[i]%F[j])+F[j];
                }
            }
            Result[i]+=C[j];
        }
    }
    Result[N-1]=0;
    for (i=0;i<N;i++)
    {
        printf("%d\n",Result[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(void){
  ll n;
  cin >> n;
  vector<int> btn(n,0);
  for(int i=0;i<n;i++){
    cin >> btn.at(i);
  }
  int light=1,count=0;




  for(int i=0;i<n;i++){
    light = btn.at(light - 1);
    count++;
    if(light == 2){
      cout << count << endl;
      return 0;
      }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3768
def inint(): return int(input())
def inlint(): return list(map(int, input().split()))
def infloat(): return float(input())
def inlffloat(): return list(map(float, input().split()))
def inl(): return list(input())
def putlint(): return "".join(list(map(str, ans)))

a,b = inlint()

if (a>b and b>1) or (a==1 and b==13):
    print("Alice")
elif a==b:
    print("Draw")
else:
    print("Bob")

Measured memory_bytes: 3064
// ARC103C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5 + 200;

int n, fa[MAX_N];
char str[MAX_N];

int main()
{
    scanf("%s", str + 1), n = strlen(str + 1);
    if (str[1] == '0' || str[n] == '1')
        puts("-1"), exit(0);
    for (int i = 1, j = n - 1; i <= j; i++, j--)
        if (str[i] != str[j])
            puts("-1"), exit(0);
    int root = 1;
    for (int i = 2; i <= n; i++)
    {
        printf("%d %d\n", root, i);
        if (str[i - 1] == '1')
            root = i;
    }
    return 0;
}

Measured memory_bytes: 1536
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def potworny_Jan_Kanty():
    N = wczytaj_liste()[0]
    potwory = wczytaj_liste()
    wynik = [[None for i in range(N+1)]for j in range(N+1)]
    for dlugosc_przedzialu in range(1,len(potwory)+1):
        for poczatek in range(len(potwory)-dlugosc_przedzialu+1): 
            koniec = dlugosc_przedzialu + poczatek
            if dlugosc_przedzialu == 1:
                wynik[poczatek][koniec] = 0
            else:
                odp = 10**18
                for i in range(1, dlugosc_przedzialu):
                    kandydat = wynik[poczatek+i][koniec]+wynik[poczatek][poczatek+i]
                    if kandydat < odp: 
                        odp = kandydat
                wynik[poczatek][koniec] = odp+sum(potwory[poczatek:koniec])
    print(wynik[0][N])
    
potworny_Jan_Kanty()

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

int main(){
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());
    int ans=a[0]+a[1];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

long long a[100010][3];
long long dp[100010][3];

int main()
{
    int N; cin >> N;
    rep (i, 0, N) {
        rep (j, 0, 3) {
            cin >> a[i][j];
        }
    }

    rep (i, 0, N) {  // 0日目から開始
        rep (j, 0, 3) {  // 活動j
            rep (k, 0, 3) {  // 活動k
                if (j == k) continue;  // i日目とi+1日目の活動は異なる
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long ans = -1;
    rep (j, 0, 3) {  // N日目の幸福度が最大になる活動を探索
        ans = max(ans, dp[N][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
/**
 *    Author  : Ador
 *    Created : 24.07.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
        //freopen("input.txt", "r", stdin) ;
        //freopen("output.txt", "w", stdout) ;
    ll n , i , sum = 0 ; cin >> n ;
    for(i = 1 ; i <= n ; ++i)
    {
        ll x = (n / i) ;
        sum += i * ((x * (x + 1)) / 2) ;
    }
    cout << sum << "\n" ;
    return 0 ;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
string s;
int n;
bool check(){
	for(int i=0;i< n>>1 ;i++)if(s[i]!=s[n-i-1])return 0;
	for(int i=0;i< n>>2 ;i++)if(s[i]!=s[ (n>>1)-i-1])return 0;
	for(int i= (n+3>>1)-1;i<n;i++)if(s[i]!=s[n + (n+3>>1)-2 -i ])return 0;
	return 1;
}
int main(){
	cin>>s;
	n=s.size();
	puts(check()?"Yes":"No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3],b[3];
	for(int i=0; i<3; i++){
		scanf("%d",&a[i]);
		b[i] = i;
	}
	int res = 1234567;
	do{
		int cur = 0;
		for(int i=1; i<3; i++){
			cur += labs(a[b[i-1]] - a[b[i]]);
		}
		res = min(res, cur);
	}while(next_permutation(b,b+3));
	printf("%d\n",res);
	return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
   int n, k;
   cin >> n >> k;

   int x = 1;
   for (int i = 0; i < n; i++) {
      x = min(x * 2, x + k);
   }

   cout << x << endl;

   return 0;
}

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

int main(){
    int i,j,n,m;
    scanf("%d %d",&n,&m);
    int dp[m+1][n+1];
    fill(dp[0],dp[m],1e9);
    int l[m+1];
    for(i=1;i<m+1;i++){
        scanf("%d",&l[i]);
    }
    sort(l,l+m+1);
    for(i=0;i<n+1;i++){
        dp[0][i]=1e9;
    }
    for(i=0;i<m+1;i++){
        dp[i][0]=0;
    }
    for(i=1;i<m+1;i++){
        for(j=1;j<n+1;j++){
            if(j-l[i]>=0){
                dp[i][j]=min(dp[i-1][j],dp[i][j-l[i]]+1);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    int res=1e9;
    for(i=1;i<m+1;i++){
        res=min(res,dp[i][n]);
    }
    printf("%d\n",res);
    return 0;
}



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

using namespace std;

int main()
{
    long long int a, b;
    scanf("%lld %lld", &a, &b);

    int i;
    for(i = 0; i < 60; i++) {
        long long int tmp = a * (1LL << i);
        if(tmp > 0 && tmp <= b)
            continue;
        break;
    }
    printf("%d\n", i);

    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
	static void Main(string[] args)
	{
		Int64 x = Int64.Parse(Console.ReadLine());
		Int64 okane = 100;
		int i = 1;
		while(true)
		{
			okane = (Int64)(okane * 1.01);
			if (okane >= x)
			{
				Console.WriteLine(i);
				return;
			}
			i++;
		}

		return;
	}
}

Measured memory_bytes: 27532
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String first = a.substring(0,1);
        String last = a.substring(a.length() - 1, a.length());
        int body = a.substring(1, a.length() - 1).length();
        System.out.println(first + body + last);
    }
}


Measured memory_bytes: 20692