akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	vector<int> v;
	rep(i, 5) {
		int d; cin >> d;
		v.emplace_back(d);
	}
	int k; cin >> k;

	bool f = true;
	rep(i, 5) reps(j, i + 1, 5)if (v[j] - v[i] > k) f = false;
	printf("%s\n", f ? "Yay!" : ":(");
	return 0;
}

Measured memory_bytes: 256
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
c = {3:0, 5:0, 15:0, 25:0, 75:0}
n = int(input())
for p in primes:
  r = n//p
  a = 0
  while r>0:
    a += r
    r //= p
  for x in c.keys():
    if x-1 <= a:
      c[x] += 1
print(c[75]+c[25]*(c[3]-1)+c[15]*(c[5]-1)+c[5]*(c[5]-1)*(c[3]-2)//2)

Measured memory_bytes: 3064
import sys
for s in sys.stdin:
    n=s.count("@")
    m=0
    x=""
    for c in s[:-1]:
        if m==0:
            if c=="@":m=1
            else:x+=c
        elif m==1:
            a="0123456789".index(c)
            m=2
        elif m==2:
            x+=c*a
            m=0
    print x

Measured memory_bytes: 4208
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

vector<int> G[100001];
vector<int> indegree(100001,0);
vector<bool> visited(100001,false);
vector<int> dist(100001,0);

void dfs(int u){
    visited[u] = true;
    for(int v: G[u]){
        dist[v] = max(dist[v], dist[u]+1);
        indegree[v]--;
        if(indegree[v] == 0)
            dfs(v);
    }
}


int main()
{
    int n,m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int from, to; cin >> from >> to;
        G[from].push_back(to);
        indegree[to]++;
    }
    
    for(int i = 1; i <= n; i++){
        if(!visited[i] && indegree[i] == 0){
            dfs(i);
        }
    }
    
    /*for(int i = 1; i <= n; i++) cout << dist[i] << " ";
    cout << endl;*/
    
    int maxd = 0;
    for(int i = 1; i <= n; i++) maxd = max(maxd,dist[i]);
    
    cout << maxd << endl;
    
}

Measured memory_bytes: 9600
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] array = new int[100];
    
    int difference = 0;
    for(int i = 0; i < N; i++){
      array[i] = sc.nextInt();
    }
    Arrays.sort(array);
    
    int Alice = 0;
    int Bob = 0;
    for(int i = 99; i > 99-N; i--){
      if(i % 2 ==1){
        Alice += array[i];
      }else{
        Bob += array[i];
      }
    }
    System.out.println(Alice-Bob);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,e,f;
cin>>a>>b>>c>>d;
if(a<b)
{
e=a;
}
else
{
e=b;
}
if(c<d)
{
f=c;
}
else
{
f=d;
}
cout<<e+f;
return 0;
}

Measured memory_bytes: 256
fun main() {
    b()
}

fun a() {
    val N = readLong()
    val otsuri = (1000 - N%1000)%1000
    println("${otsuri}")
}

fun b() {
    val N = readLong().toInt()
    val map = mutableMapOf<String, Long>()
    repeat(N) {
        val s = readLine()!!
        map[s] = map.getOrDefault(s, 0) + 1
    }
    listOf("AC", "WA", "TLE", "RE").forEach {
        println("$it x ${map.getOrDefault(it, 0)}")
    }
}

fun readLong() = readLine()!!.toLong()
fun readLongList() = readLine()!!.split(" ").map { it.toLong() }

fun Long.print() { println(this) }

Measured memory_bytes: 59088
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

N=input()
A=map(int, raw_input().split())

l=1
for a in A:
	l=lcm(l,a)

x=0
for a in A:
	x+=l/a
	
print float(l)/x

Measured memory_bytes: 34792
def check():
    A, B, C, X, Y = [int(i) for i in input().split(' ')]
    if X > 0 and Y > 0:
        if 2*C < A+B:
            if X > Y:
                total = Y*2*C
                price = min(A, 2*C)
                total += (X-Y)*price
            else:
                total = X*2*C
                price = min(B, 2*C)
                total += (Y-X)*price
        else:
            total = A*X + B*Y
    elif X == 0:
        price = min(B, 2*C)
        total = price*Y
    else:
        price = min(A, 2*C)
        total = price*X
        
    print(total)
check()

Measured memory_bytes: 3064
from collections import Counter

N = int(input())


S = [input() for i in range(N)]

C = Counter(S)

print("AC x {}".format(C["AC"]))
print("WA x {}".format(C["WA"]))
print("TLE x {}".format(C["TLE"]))
print("RE x {}".format(C["RE"]))

Measured memory_bytes: 16612
#include<stdio.h>
int main(){
  int a,b,r,tmp;
  
  scanf("%d %d",&a,&b);
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a%b;
  while(r != 0){
    a = b;
    b = r;
    r = a%b;
  }
  printf("%d\n",b);

  return 0;
}



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

using ll = long long;

int N, M, Q;
vector<int> a(50), b(50), c(50), d(50);
vector<int> A(10, 1);

ll dfs(int n) {
	if (n == N) {
		ll res = 0;
		for (int i = 0; i < Q; ++i) {
			if (A[b[i] - 1] - A[a[i] - 1] == c[i]) res += d[i];
		}
		return res;
	}
	ll res = 0;
	for (int i = A[n]; i <= M; ++i) {
		A[n + 1] = i;
		res = max(res, dfs(n + 1));
	}
	return res;
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	ll ans = 0;
	for (int i = 1; i <= M; ++i) {
		A[0] = i;
		ans = max(ans, dfs(0));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		List<List<Long>> list = new ArrayList<List<Long>>();
		for (int i = 0; i < n; ++i) {
			long x = sc.nextLong();
			long y = sc.nextLong();
			long z = sc.nextLong();
			List<Long> tmp = new ArrayList<Long>();
			tmp.addAll(Arrays.asList(x, y, z));
			list.add(tmp);
		}
		sc.close();
		long ans = 0;
		int d[][] = { { -1, -1, -1 }, { -1, -1, 1 }, { -1, 1, -1 }, { -1, 1, 1 }, { 1, -1, -1 }, { 1, -1, 1 },
				{ 1, 1, -1 }, { 1, 1, 1 } };
		for (int i = 0; i < 8; ++i) {
			long tmp[] = new long[n];
			for (int j = 0; j < n; ++j) {
				for (int k = 0; k < list.get(j).size(); ++k) {
					tmp[j] += d[i][k] * list.get(j).get(k);
				}
			}
			Arrays.sort(tmp);
			long sum = 0;
			for(int j = 0; j < m; ++j) 
				sum += tmp[n - 1 - j];
			ans = Math.max(ans,  sum);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 27224
fn main() {
    let [h, w, k]: [usize; 3] = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        [
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        ]
    };

    let c = {
        let mut tmp = Vec::with_capacity(h);
        for _ in 0..h {
            let s: Vec<char> = {
                let mut buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
                buf.trim_end().chars().collect()
            };
            tmp.push(s);     
        }
        tmp
    };

    let mut ans = 0;
    for x in 0..(1 << h) {
        for y in 0..(1 << w) {
            let mut res = 0;
            for i in 0..h {
                for j in 0..w {
                    if (x & (1 << i)) > 0 && (y & (1 << j)) > 0 && c[i][j] == '#' {
                        res += 1;
                    }
                }
            }
            if res == k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2156
function bomb(ab,x,y,z){
   var dx=[-1,0,1,-1];
   var dy=[-1,-1,-1,0];
   var dz=[0,0,0,0];
   dy=dy.concat([-1,0,1,-1]);
   dz=dz.concat([-1,-1,-1,0]);
   dx=dx.concat([0,0,0,0]);
   dz=dz.concat([-1,0,1,-1]);
   dx=dx.concat([-1,-1,-1,0]);
   dy=dy.concat([0,0,0,0]);
   dx=dx.concat([1,-1,1,-1]);
   dy=dy.concat([-1,-1,-1,-1]);
   dz=dz.concat([-1,-1,1,1]);
   var max=0;
   for(var i=0;i<dx.length;i++){
      var X=x;
      var Y=y;
      var Z=z;
      while(true){
         X-=dx[i];
         Y-=dy[i];
         Z-=dz[i];
         if(X<0 || Y<0 || Z<0)break;
         if(X>=n || Y>=n || Z>=p)break;
      }
      var cnt=0;
      while(true){
         X+=dx[i];
         Y+=dy[i];
         Z+=dz[i];
         if(X<0 || Y<0 || Z<0)break;
         if(X>=n || Y>=n || Z>=p)break;
         if(ball[X][Y][Z]==ab)cnt++;
         else cnt=0;
         max=Math.max(max,cnt);
      }
   }
   return max;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var nmp=arr.shift();
   if(nmp=="0 0 0")break;
   nmp=nmp.split(" ").map(Number);
   var n=nmp[0];
   var m=nmp[1];
   var p=nmp[2];
   var ball=[];
   for(var i=0;i<n;i++){
      ball[i]=[];
      for(var j=0;j<n;j++){
         ball[i][j]=[];
         for(var k=0;k<p;k++){
            ball[i][j][k]=0;
         }
      }
   }
   var P=[];
   for(var i=0;i<p;i++)P.push(arr.shift().split(" ").map(Number));
   var ab=1;
   var draw=true;
   for(var i=0;i<p;i++){
      var xy=P[i];
      var x=xy[0]-1;
      var y=xy[1]-1;
      var cnt=0;
      while(true){
         if(ball[x][y][cnt]!==0)cnt++;
         else break;
      }
      ball[x][y][cnt]=ab;
      if(bomb(ab,x,y,cnt)>=m){
         console.log((ab==2)?"White":"Black",i+1);
         draw=false;
         break;
      }
      ab=2/ab;
   }
   if(draw)console.log("Draw");
}

Measured memory_bytes: 36020
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int N, X;
	cin >> N >> X;
	int A[1010];
	rep(i, N) cin >> A[i];

	sort(A, A+N);
	int sum = accumulate(A, A+N, 0);
	int ans = N;
	bool flg = true;
	while (flg) {
		sum += A[0];
		if (X-sum<0) flg = false;
		else ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i].first >> a[i].second;
        sort(a.begin(), a.end());

        int m;
        cin >> m;
        vector<pair<int, int> > b(m);
        for(int i=0; i<m; ++i)
            cin >> b[i].first >> b[i].second;
        sort(b.begin(), b.end());

        for(int i=0; i<m; ++i){
            int dx = b[i].first - a[0].first;
            int dy = b[i].second - a[0].second;
            int j = 0;
            int k = 0;
            while(j < n){
                pair<int, int> tmp(a[j].first + dx, a[j].second + dy);
                while(k < m && tmp != b[k])
                    ++ k;
                if(k == m)
                    break;
                ++ j;
            }
            if(j == n){
                cout << dx << ' ' << dy << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 0
//#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;
ll ten[5001][5001];
ll lnum[5001];
int main(){
	int N;
	ll K;
	int P[5001];
	ll C[5002];
	scan(N>>K);
	rep(i,N){
		scan(P[i]);
		P[i]--;
	}
	rep(i,N){
		scan(C[i]);
	}
	rep(i,N){
		int now=i;
		rep(j,N){
			ten[i][j+1]=ten[i][j]+C[P[now]];
			now=P[now];
			if(now==i){
				lnum[i]=j+1;
				break;
			}
		}
	}
	ll ans=-INFl;
	rep(i,N){
		ll sum=0;
		if(K<=lnum[i]||ten[i][lnum[i]]<=0){
			sum=ten[i][1];
			ll kaisu=min(lnum[i],K);
			rep1(j,kaisu){
				sum=max(sum,ten[i][j]);
			}
		}
		else{
			sum=0;
			ll amari=K%lnum[i];
			ll amarimax=0;
			ll sum1=(K/lnum[i]-1)*ten[i][lnum[i]]+ten[i][1];
			rep1(j,lnum[i]){
				sum1=max(sum1,(K/lnum[i]-1)*ten[i][lnum[i]]+ten[i][j]);
			}
			ll sum2=K/lnum[i]*ten[i][lnum[i]];
			rep1(j,amari){
				amarimax=max(amarimax,ten[i][j]);
			}
			sum2+=amarimax;
			sum=max(sum1,sum2);
		}
		debug(i,sum);
		ans=max(ans,sum);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 198972
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

int main() {
	int N;
	cin >> N;
	vector<int> input;
	for(int i=0; i<N; i++) {
		int p;
		cin >> p;
		input.push_back(p-1);
	}
	int cnt = 0;
	for(int i=0; i<N; i++)
		if( i == input[input[i]])
			cnt++;
	cnt /= 2;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1020
#include <stdio.h>

int main(void){
  int i, n, blood[4] = {0, 0, 0, 0};
  char abo[3];

  while(scanf("%d,%s", &n, abo) != EOF){
    if(abo[0] == 'A'){
      if(abo[1] == 'B'){
	blood[2]++;
      }else{
	blood[0]++;
      }
    }else if(abo[0] == 'B'){
      blood[1]++;
    }else{
      blood[3]++;
    }
  }
  for(i = 0; i < 4; i++){
    printf("%d\n", blood[i]);
  }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int h,w;
    cin>>h>>w;
    char s[h+2][w+2];
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            s[i][j] = '.';
        }
    }
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            cin>>s[i][j];
        }
    }

    bool ok = true;

    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(s[i][j] == '.') continue;
            ok = false;
            if(s[i-1][j] == '#') ok = true;
            else if(s[i+1][j] == '#') ok = true;
            else if(s[i][j-1] == '#') ok = true;
            else if(s[i][j+1] == '#') ok = true;
            else{
                ok = false;
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

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

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N, K;
    cin >> N >> K;
    pair<ll, ll> A[N];
    rep(i, N) cin >> A[i].first >> A[i].second;

    vector<ll> kouho;
    rep(i, N){
        pair<ll, ll> left = A[i];
        rep(j, N){
            pair<ll, ll> up = A[j];
            rep(k, N){
                pair<ll, ll> right = A[k];
                rep(l, N){
                    pair<ll, ll> down = A[l];
                    int cnt = 0;
                    rep(m, N){
                        ll x = A[m].first, y = A[m].second;
                        if(left.first <= x && x <= right.first && down.second <= y && y <= up.second) cnt++;
                    }
                    if(cnt >= K) kouho.push_back((right.first-left.first)*(up.second-down.second));
                }
            }
        }
    }
    cout << *min_element(kouho.begin(), kouho.end()) << endl;
    return 0;
}

void solve(){}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int zeller(int y, int m, int d) {
  if (m == 1 || m == 2) y--, m += 12;
  return (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + d) % 7;
}

const string s[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int m, d;
  while (cin >> m >> d, m) {
    cout << s[zeller(2004, m, d)] << endl;
  }

  return 0;
}


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

using namespace std;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int c = 0;
  for (auto s : S) {
    if (s == '1') c++;
  }
  int x = 0, y = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') x += pow(2, N - i - 1, c + 1), x %= c + 1;
    if (S[i] == '1' && c - 1 > 0) y += pow(2, N - i - 1, c - 1), y %= c - 1;
  }
  function<int(int)> rec = [&](int x) {
    if (x == 0) return 0;
    return rec(x % __builtin_popcount(x)) + 1;
  };
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') {
      if (c - 1 == 0) {
        cout << 0 << '\n';
      } else {
        cout << rec((y - pow(2, N - i - 1, c - 1) + (c - 1)) % (c - 1)) + 1 << '\n';
      }
    } else {
      cout << rec((x + pow(2, N - i - 1, c + 1)) % (c + 1)) + 1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>

#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define eb emplace_back
#define dbg(x) cout<<#x" = "<<((x))<<endl
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  int N;

  cin >> N;

#ifdef DEBUG
  cout << "N=" << N << endl;
#endif

  int ans = 0;
  for(int i = 1; i <= 9; ++i){
    if(N <= i*111) {ans = i*111; break;}
  }

  cout << ans << endl;
  
  return 0;
}


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

char a[50]="aabcdefghijklmnopqrstuvwxyz";

int main()
{
    string s;
    cin>>s;
    int p;
    for(int i=1;i<=26;i++)
    {
        p=0;
        for(int j=0;j<s.size();j++)
        {
            if(a[i]==s[j])
            {
                p=1;
                break;
            }
        }
        if(!p)
        {
            cout<<a[i];
            return 0;
        }
    }
    cout<<"None";
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A[i];
  sort(A.begin(), A.end());
  int ans = 0;
  for( int i = 0; i < K; i++ ) ans += A[i];
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include<string>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int n = int(s.length());
    string t = string(s);
    reverse(t.begin(), t.end());

    /*
    type_cnt[i][j]: i文字目からj文字目までの間 (閉区間) に何種類の文字があるか
    */
    ll type_cnt[n+1][n+1];
    fill(type_cnt[0], type_cnt[n+1], 0LL);
    for(int i=0;i<n;i++){
        type_cnt[i+1][i+1] = 1LL;
        bool alphabets[26];
        fill(alphabets, alphabets+26, false);
        alphabets[s[i]-'a'] = true;
        for(int j=i+1;j<n;j++){
            if(alphabets[s[j]-'a']){
                type_cnt[i+1][j+1] = type_cnt[i+1][j];
            }else{
                type_cnt[i+1][j+1] = type_cnt[i+1][j]+1LL;
                alphabets[s[j]-'a'] = true;
            }
        }
    }

    /*
    next_pos[k][i][j]: i文字目よりも後ろに登場する文字('a'+j)で最も近いものが何文字目か
    k = 0ならs，k=1ならt
    */
   ll next_pos[2][n+1][26];
   fill(next_pos[0][0], next_pos[1][n+1], n+1);
   for(int i=n-1;i>=0;i--){
       for(int j=0;j<26;j++){
           if(s[i] - 'a' == j){
               next_pos[0][i][j] = i+1;
           }else{
               next_pos[0][i][j] = next_pos[0][i+1][j];
           }
           if(t[i] - 'a' == j){
               next_pos[1][i][j] = i+1;
           }else{
               next_pos[1][i][j] = next_pos[1][i+1][j];
           }
       }
   }

    /*
    dp[i][j]: sをs[i-1]まで，tをt[j-1]まで見た
    */
    ll dp[n+1][n+1];
    fill(dp[0], dp[n+1], 0LL);
    dp[0][0] = 1LL;
    for(int k=0;k<26;k++){
        if(next_pos[0][0][k] != n+1 && next_pos[1][0][k] != n+1){
            dp[next_pos[0][0][k]][next_pos[1][0][k]]++;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j] %= MOD;
            if(dp[i][j]) for(int k=0;k<26;k++){
                if(next_pos[0][i][k] != n+1 && next_pos[1][j][k] != n+1){
                    dp[next_pos[0][i][k]][next_pos[1][j][k]] += dp[i][j];
                }
            }
        }
    }
    
    ll ans = 0LL;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(!dp[i][j]) continue;
            if(i+j <= n){
                ans += (dp[i][j] * (((i+1<=n-j)?type_cnt[i+1][n-j]:0LL)+1LL)) % MOD;
                ans %= MOD;
            }
        }
    }
    ans--;

    cout << ans << endl;
}


Measured memory_bytes: 66564
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int x, n;
    cin >> x >> n;
    vector<bool> p(110, true);
    rep(i, n) {
        int a;
        cin >> a;
        p[a] = false;
    }
    int ans;
    int v = INF;
    rep(i, 110) {
        if(!p[i]) continue;
        if(abs(x - i) < v) {
            ans = i;
            v = abs(x - i);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  bool match = false;
  T += T;
  for (int i = 0; i < S.size(); i++)
  {
    string tmp = T.substr(i, S.size());
    if (S == tmp)
    {
      match = true;
      break;
    }
  }
  if (match)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

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

int gcd(int a, int b)
{
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}

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

  int res=0;
  for (int a = 1; a < K+1; a++) {
    for (int b = 1; b < K+1; b++) {
      for (int c = 1; c < K+1; c++) {
        int x=gcd(a,b);
        int y=gcd(x,c);
        res+=y;        
      }        
    } 
  }

  cout << res << endl;
}

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

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

    map<string, int> m;
    int n;
    cin>>n;
  	int ans = 0;
  	string input;
    for(int i = 0; i < n; i++){
      cin>>input;
      if ( m.find(input) == m.end() ) {
        ans += 1;
        m.insert (pair<string,int>(input,1) );
  	// not found
	} else {
  // found
        continue;
		}
    }
  cout<<ans<<endl;
    return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N, S;

ll func(ll b, ll n)
{
    if (n < b)
    {
        return n;
    }
    return func(b, n / b) + n % b;
}

int main()
{
    cin >> N >> S;
    if (N == 1)
    {
        if (S == 1)
            cout << 2 << endl;
        else
            cout << -1 << endl;
        return 0;
    }
    ll i = 2;
    //! sqrt(N)はまでは直で計算
    for (; i * i <= N; ++i)
    {
        if (func(i, N) == S)
        {
            cout << i << endl;
            return 0;
        }
    }

    //! ここからは2桁の数、商で分類
    for (ll j = i; j > 1; --j)
    {
        ll min = N / j + 1;
        ll max = N / (j - 1);
        ll upper = func(min, N);
        ll lower = func(max, N);
        if (upper >= S && S >= lower)
        {
            if ((upper - S) % (j - 1) == 0)
            {
                cout << min + (upper - S) / (j - 1) << endl;
                return 0;
            }
        }
    }

    if (N == S)
        cout << N + 1 << endl;
    else
        cout << -1 << endl;
    return 0;
}

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

int main()
{
    INT a,b,k;

    cin>>a>>b>>k;

    if(a>=k){
        cout<<a-k<<" "<<b<<endl;
    }
    else if(a+b>=k){
        cout<<0<<" "<<b-(k-a)<<endl;
    }
    else {
        cout<<0<<" "<<0<<endl;
    }
} 

Measured memory_bytes: 3584
// #include "common.hpp"
// #include "bridge_decomposition.hpp"
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define fst first
#define snd second

#include <iostream>
using namespace std;

#include <vector>
#include <cstdlib>
#include <algorithm>

class BridgeDecomposition{
  std::vector<std::vector<int> >  G;
  std::vector<int> ord;
  std::vector<int> low;
  std::vector<int> par;
  void Dfs(int v, int &times);
  
public:
  std::vector<std::vector<int> > edge_group;
  BridgeDecomposition(const std::vector<std::pair<int, int> > &es);
};

void BridgeDecomposition::Dfs(int v, int &times){
  ord[v] = low[v] = times++;
  for (int w : G[v]){
    if (ord[w] == -1){
      par[w] = v;
      Dfs(w, times);
      low[v] = min(low[v], low[w]);
    } else if (w != par[v]){
      low[v] = min(low[v], low[w]);
    }
  }
}

BridgeDecomposition::BridgeDecomposition(const vector<pair<int, int> > &es){
  int V = 0;
  for (const auto &e : es) V = max(V, max(e.fst, e.snd) + 1);
  
  ord = vector<int>(V, -1);
  low = vector<int>(V, -1);
  par = vector<int>(V, -1);
  G   = vector<vector<int> >(V);
  for (const auto &e : es){
    G[e.fst].push_back(e.snd);
    G[e.snd].push_back(e.fst);
  }

  int times = 0;
  REP(v, V) if (ord[v] == -1){
    Dfs(v, times);
  }
  
  G.clear();
  G = vector<vector<int> > (V);
  
  for (size_t i = 0; i < es.size(); i++){
    pair<int, int> e = es[i];
    if (par[e.snd] != e.fst) swap(e.fst, e.snd);
    if (par[e.snd] != e.fst) continue;
    if (low[e.snd] > ord[e.fst]){
      edge_group.push_back(vector<int>(1, i));
      // e is bridge!
    } else {
      G[e.fst].push_back(e.snd);
      G[e.snd].push_back(e.fst);
    }
  }
}


int main(int argc, char *argv[])
{
  int n, m, u, v;
  cin >> n >> m;
  vector<pair<int, int> > es;
  REP(i, m){
    cin >> u >> v;
    if (u > v) swap(u, v);
    es.emplace_back(u, v);
  }
  BridgeDecomposition bd(es);
  vector<pair<int, int> > bs;
  REP(i, bd.edge_group.size()) if (bd.edge_group[i].size() == 1) {
    bs.push_back(es[bd.edge_group[i][0]]);
  }
  sort(bs.begin(), bs.end());
  for (const auto &e : bs){
    cout << e.fst << " " << e.snd << endl;
  }
  return 0;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b < c+d) {
    cout << "Right" << endl;
  } else if (a+b == c+d) {
    cout << "Balanced" << endl;
  } else {
    cout << "Left" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int k, s;
  cin >> k >> s;
  
  int ans = 0;
  for(int i = 0; i <= k; i++) {
    for(int j = 0; j <= k; j++) {
      int z = s - (i+j);
      if(z >= 0 && z <= k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int a, b;
    cin >> a >> b;
    int h = 100, w = 100;
    vector<vector<char>> s(h, vector<char>(w));
    for(int i = 0; i < 50; ++i){
        for(int j = 0; j < w; ++j){
            s[i][j] = '.';
        }
    }
    for(int i = 50; i < 100; ++i){
        for(int j = 0; j < w; ++j){
            s[i][j] = '#';
        }
    }
    --a, --b;
    for(int i = 0; i < 49; ++i){
        for(int j = (i % 2 == 0) ? 0 : 2; j < w; j += 4){
            if(b <= 0)  break;
            s[i][j] = '#';
            --b;
        }
        if(b <= 0)  break;
    }
    for(int i = 51; i < 100; ++i){
        for(int j = (i % 2 != 0) ? 0 : 2; j < w; j += 4){
            if(a <= 0)  break;
            s[i][j] = '.';
            --a;
        }
        if(a <= 0)  break;
    }
    cout << h << ' ' << w << '\n';
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cout << s[i][j];
        }
        cout << '\n';
    }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h> 
using namespace std; 
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   int index = L[m][n]; 
  
   char lcs[index+1]; 
   lcs[index] = '\0'; 
   
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
  
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1];
          i--; j--; index--;     
      } 
   
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   cout << lcs; 
} 
  
int main() 
{ string X,Y;
    cin>>X>>Y;
  int m = X.size(); 
  int n = Y.size(); 
  lcs(X, Y, m, n); 
  return 0; 
} 

Measured memory_bytes: 35456
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

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

  ll fl, ce;
  fl = floor(x / d);
  fl = (fl < 0) ? -fl : fl;
  ce = ceil(x / d);
  ce = (ce < 0) ? -ce : ce;

  if (fl == ce) {
    ce = fl + 1;
  }

  ll fl_val = (x > 0) ? x - fl * d : x + fl * d;
  ll ce_val = (x > 0) ? x - ce * d : x + ce * d;
  ll min_times = (abs(fl_val) < abs(ce_val)) ? fl : ce;

  if (fl > k && ce <= k) {
    cout << abs(ce_val) << endl;
  } else if (fl <= k && ce > k) {
    cout << abs(fl_val) << endl;
  } else if (fl > k && ce > k) {
    cout << abs((x > 0) ? x - d * k : x + d * k) << endl;
  } else {
    if ((k % 2 == 1 && min_times % 2 == 1) ||
        (k % 2 == 0 && min_times % 2 == 0)) {
      cout << abs((min_times == fl) ? fl_val : ce_val) << endl;
    } else {
      cout << abs((min_times == fl) ? ce_val : fl_val) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    string s,t;
    cin >> s >> t;
    string res = string(s.length(),'z');
    bool isAnser = false;
    if(s.length() < t.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    rep(i,s.length() - t.length() + 1){
        bool b = true;
        rep(j,t.length()){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                b = false;
                break;
            }
        }
        if(b){
            string ans = "";
            repp(j,0,i){
                if(s[j] != '?')ans += s[j];
                else ans += 'a';
            }
            ans += t;
            repp(j,i + t.length(),s.length()){
                if(s[j] != '?')ans += s[j];
                else ans += 'a';
            }
            isAnser = true;
            chmin(res,ans);
        }
    }
    if(isAnser)cout << res << endl;
    else cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    long long ans = 0;
    for(int i = 1; i < N; i++){
        if(A[i - 1] > A[i]){
            int h = (A[i - 1] - A[i]);
            ans += h;
            A[i] += h;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4840
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

data = ["AC","WA","TLE","RE"]
dp = [0 for i in range(4)]

for i in range(n):
	ppp = input()[:-1]
	for j in range(4):
		if ppp == data[j]:
			dp[j] += 1
for i in range(4):
	print("{0} x {1}".format(data[i],dp[i]))


Measured memory_bytes: 68412
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N, ac, wa, tle, re;
  ac = wa = tle = re = 0;
  string s;
  cin >> N;
  cout << endl;
  for(int i=0;i<N;i++){
    cin >> s;
    cout << endl;
    if(s == "AC"){
      ac++;
    }else if(s == "WA"){
      wa++;
    }else if(s == "TLE"){
      tle++;
    }else if(s == "RE"){
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

bool isprime(int n){
    for(int j=2;j<=floor(sqrt(n));j++){
        if (n % j == 0) return false;
    }
    return true;
}

int main(){
    bool p[246952];
    for(int j=2;j<246942;j++){
        p[j] = isprime(j);
    }
    int n;
    while(cin >> n && n>0) {
        int cnt=0;
        for(int j=n+1;j<=2*n; j++){
            if (p[j]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        k: i64, n: usize,
        a: [i64; n],
    }
    let mut mi = k;
    for i in 0..n {
        mi = min(mi, (a[i] - a[(i + 1) % n] + k) % k);
    }
    puts!("{}\n", mi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int k;
  string s;
  cin >> k >> s;

  if (s.length() <= k) cout << s << '\n';
  else cout << s.substr(0, k) << "..." << '\n';






  
  return 0;
}

Measured memory_bytes: 3656
def gcd(x, y):
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(x, y):
    return x // gcd(x, y) * y

n, m = map(int, input().split())
a = list(map(int, input().split()))

l = 1
for i in range(n):
    a[i] //= 2
    l = lcm(a[i], l)

flg = True
for x in a:
    if (l // x) % 2 == 0:
        flg = False
        break

if flg:
    print(m // l - m // (l * 2))
else:
    print(0)

Measured memory_bytes: 15060
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a, g = 0, h, i;
	for (i = 0; i < 5; i++)
	{
		cin >> a;
		if (a < 40)
			a = 40;
		g += a;
	}
	h = g / 5;
	cout << h << endl;
	return 0;
}

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

int main(){
    int N;
    int A, B;
    // vector<int> vp;
    // int vp[105];

    cin >> N >> A >> B;
    // for (int i=0; i<N; i++){
    //     cin >> vp[i];
    // }

    int res;
    if ( N*A <= B ) res = N*A;
    else res = B;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a=0,i,b,c,cut=0;
    string str1,str,mozi;
    cin >> str1 >> c;
    for(i=0;i<c;i++){
        cin >> str;
        mozi=str+str;
    int a=mozi.find(str1); //= str.find(str1);
    if(a!=-1){
        cut=cut+1;
    }
    }
    cout << cut <<"\n";
return 0;
}

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

// main.cpp

class dp {
private:
  std::int_fast64_t range_limit;
  std::int_fast64_t t;
  std::vector<std::vector<bool>> states;

  std::int_fast64_t to_index(const std::int_fast64_t& n) const {
    return n + this->range_limit;
  }
  std::int_fast64_t to_int(const std::int_fast64_t& index) const {
    return index - this->range_limit;
  }

public:
  dp(const std::int_fast64_t move_count, const std::int_fast64_t range_limit, const std::int_fast64_t start) :
    range_limit(range_limit),
    t(0),
    states(move_count + 1, std::vector<bool>(range_limit * 2 + 1, false)) {
    this->states[0][this->to_index(start)] = true;
  }

  void accept(const std::int_fast64_t move) {
    for (std::int_fast64_t i = -this->range_limit; i <= this->range_limit; ++i) {
      if (this->states[this->t][this->to_index(i)]) {
        this->states[this->t + 1][this->to_index(i - move)] = true;
        this->states[this->t + 1][this->to_index(i + move)] = true;
      }
    }
    ++this->t;
  }

  bool is_reachable(const std::int_fast64_t goal) const {
    return this->states.back()[this->to_index(goal)];
  }

  friend std::ostream& operator<<(std::ostream& os, const dp& self) {
    std::vector<std::int_fast64_t> ok;
    for (std::int_fast64_t i = -self.range_limit; i <= self.range_limit; ++i) {
      if (self.states[self.t][self.to_index(i)]) ok.push_back(i);
    }

    os << "{";
    std::string delimiter = "";
    for (const std::int_fast64_t& n : ok) {
      os << delimiter << n;
      delimiter = ", ";
    }
    return os << "}";
  }
};


int main() {
  std::string s;
  std::int_fast64_t x, y;
  std::cin >> s >> x >> y;

  std::int_fast64_t first_streak = 0;
  std::vector<std::int_fast64_t> horizontal_moves;
  std::vector<std::int_fast64_t> vertical_moves;
  {
    bool is_first_streak = true;
    std::int_fast64_t current_streak = 0;
    bool is_horizontal = true;
    s += 'T';
    for (const char& c : s) {
      switch (c) {
      case 'F':
        ++current_streak;
        break;
      case 'T':
        if (is_first_streak) {
          first_streak = current_streak;
          is_first_streak = false;
        } else {
          if (current_streak > 0) {
            if (is_horizontal) {
              horizontal_moves.push_back(current_streak);
            } else {
              vertical_moves.push_back(current_streak);
            }
          }
        }
        current_streak = 0;
        is_horizontal = !is_horizontal;
        break;
      }
    }
  }

  dp horizontal_dp(horizontal_moves.size(), s.size(), first_streak);
  for (const std::int_fast64_t& move : horizontal_moves) {
    horizontal_dp.accept(move);
  }

  dp vertical_dp(vertical_moves.size(), s.size(), 0);
  for (const std::int_fast64_t& move : vertical_moves) {
    vertical_dp.accept(move);
  }

  std::cout << (horizontal_dp.is_reachable(x) && vertical_dp.is_reachable(y) ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
    const int MAX = 510000;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
        signed main() {
            COMinit();
            int n;
            cin>>n;
            int c[n];
            for(int i=0;i<n;i++)cin>>c[i];
            sort(c,c+n);
            int ans=0;
           if(n==1){
              cout<< 2*c[0]%MOD;
              return 0;
           }
           int k=1;
           for(int i=0;i<n-2;i++)k=(k*2)%MOD;
            for(int i=0;i<n;i++){
                ans=(ans+(c[i]*(n+1-i)%MOD))%MOD;

            }
            int t=1;for(int i=0;i<n;i++)t=(t*2)%MOD;
            cout<<((ans*k)%MOD *t)%MOD;
         return 0;

        }


Measured memory_bytes: 13696
#define MOD 1000000007L
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

long pow(long a, long b) {
	if (!b) return 1L;
	long c = pow(a, b / 2L);
	if (b % 2L) c = a * c % MOD * c % MOD;
	else c = c * c % MOD;
	return c;
}

int main() {
	int N, A;
	cin >> N;
	vector<long> a((N + 1) / 2);
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (N % 2) {
			if (A % 2) {
				cout << 0 << endl;
				return 0;
			}
		}
		else {
			if (A % 2 == 0) {
				cout << 0 << endl;
				return 0;
			}
		}
		a[A / 2]++;
	}
	if (N % 2) {
		if (a.front() != 1L || any_of(a.begin() + 1, a.end(), [](long& a) { return a != 2L; })) {
			cout << 0 << endl;
			return 0;
		}
	}
	else {
		if (any_of(a.begin(), a.end(), [](long& a) { return a != 2L; })) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << pow(2L, static_cast<long>(N) / 2L) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string A, B, C;
    cin >> A >> B >> C;
    cout <<( (A[A.length() -  1] == B[0] and B[B.length() - 1] == C[0]) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
program speedrun
   implicit none
   integer::a,b,c
   integer::check=0
   read*,a,b,c
   if(a==b)check=check+1
   if(b==c)check=check+1
   if(c==a)check=check+1
   print"(A)",trim(merge("Yes","No ",check==1))
end program speedrun

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		String s = sc.next();
		int b=sc.nextInt();
		if(s.equals("+")){
			System.out.println(a+b);
		}else if(s.equals("-")){
			System.out.println(a-b);
		}
	}
}


Measured memory_bytes: 21844