akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()

const int MAX = 1000000;
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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;
}

int main()
{
    int X,Y,a,b;
    cin >> X >> Y;
    if((X+Y)%3!=0){
        cout << "0" << endl;
    }
    else{
        a = (2*X-Y)/3;
        b = (2*Y-X)/3;
        // 前処理
        COMinit();

        // 計算例
        cout << COM(a+b, min(a,b)) << endl;
    }
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> p(A), q(B), r(C);
  for (int i = 0; i < (int)(A); ++i) cin >> p[i];
  for (int i = 0; i < (int)(B); ++i) cin >> q[i];
  for (int i = 0; i < (int)(C); ++i) cin >> r[i];
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());

  vector<int> cands;
  for (int i = 0; i < (int)(min(X, A)); ++i) cands.push_back(p[i]);
  for (int i = 0; i < (int)(min(Y, B)); ++i) cands.push_back(q[i]);
  for (int i = 0; i < (int)(min(X + Y, C)); ++i) cands.push_back(r[i]);
  sort(cands.rbegin(), cands.rend());

  ll ans = 0;
  for (int i = 0; i < (int)(X + Y); ++i) ans += cands[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll a, mi=10, ans=0;
	rep(i, 5){
		cin >> a;
		if (a%10==0){
			ans += a/10*10;
		}else{
			ans += a/10*10+10;
			chmin(mi, a%10);
		}
	}
	ans -= 10-mi;
	cout << ans << endl;

}








Measured memory_bytes: 256
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]
dydx = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]


def check(h, w):
  count = 0
  for dy, dx in dydx:
    if 0 <= h + dy < H and 0 <= w + dx < W and S[h+dy][w+dx] == '#':
      count += 1
  return count

for h in range(H):
  for w in range(W):
    if S[h][w] == '.':
      S[h][w] = str(check(h, w))
  res = "".join(S[h])
  print(res)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define int long long
    class dsu{
    public:
    	void init(int n){
    		pai.clear() , peso.clear();
    		pai.resize(n) , peso.resize(n);
    		f.resize(n);
    		ciclou.resize(n);
    		for(int i = 0 ; i < n; i++){
    			pai[i] = i , peso[i] = 1;
    		}
    	}
    	int get(int x){
    		return pai[x] == x ? x : pai[x] = get(pai[x]);
    	}
    	int get_f(int x){
    		return ciclou[get(x)];
    	}
    	void add_f(int x){
    		ciclou[get(x)] |= 1;
    	}
    	int get_p(int x){
    		return peso[get(x)];
    	}
    	void add(int x , int y){
    		x = get(x) , y = get(y);
    		if(x == y) return;
    		if(peso[x] < peso[y]) swap(x,y);
    		pai[y] = x, peso[x] += peso[y];
    		ciclou[x] |= ciclou[y];
    	}
    private:
    	vector<int> pai , peso , f , ciclou;
    };
    struct query{
    	int u , v , w;
    }; 

    int32_t main(){
    	int n , l , c;
    	scanf("%lld%lld%lld" , &n , &l , &c);
    	vector<	query > v(n);
    	for(int i = 0 ; i < n; i ++) cin>>v[i].u  >> v[i].v >> v[i].w;
    	sort(v.begin() , v.end() , [&](query a,  query b){
    		return a.w > b.w;
    	});
    	dsu t;
    	t.init(l+ c+ 3);
    	int ans = 0;
    	for(int i = 0 ; i < n ; i ++){
    		if(t.get(v[i].u) != t.get(v[i].v + l) && !(t.get_f(v[i].u) & t.get_f(v[i].v + l))){
    			t.add(v[i].u , v[i].v + l);
    			ans += v[i].w;
    		}
    		else{
    			if(t.get(v[i].u) == t.get(v[i].v + l)){
    				if(!t.get_f(v[i].u)){
    					t.add_f(v[i].u);
    					ans += v[i].w;
    				}
    			}
    		}
    	}
    	printf("%lld\n" , ans);
    } 

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();
		if(a <= 0 && b >= 0) {
			System.out.println("Zero");
		}else if(b < 0) {
			long l = Math.abs(b - a);
			if(l % 2 == 1) {
				System.out.println("Positive");
			}else {
				System.out.println("Negative");
			}
		}else {
			System.out.println("Positive");
		}
	}
}

Measured memory_bytes: 23764
N = int(input())
S = input()
character = []

for i in range (0, len(S)):
    if ord(S[i]) + N <= 90:
        character.append(chr(ord(S[i]) + N))
    else :
        character.append(chr(ord(S[i]) + N - 89 +63))

answer = "".join(character)

print(answer)

Measured memory_bytes: 3064
#include"stdio.h"
#include <string.h>

int main(){
  int flag=1;
  char s[101];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++){
  if(i%2==1&&s[i]=='R'){flag=0;break;}
  if(i%2==0&&s[i]=='L'){flag=0;break;}
  }
  if(flag==1)printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ADayOfTakahashi {
public:
	void solve(istream& in, ostream& out) {
        int a, b;
        in >> a >> b;
        if(a <= b) out << a << endl;
        else out << a - 1 << endl;
	}
};

int main() {
	ADayOfTakahashi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
def sort(a, b)
  if a > b
    t = a
    a = b
    b = t
  end
  return a, b
end

n = gets.chomp.split(" ").map &:to_i

n[0], n[1] = sort(n[0], n[1])
n[1], n[2] = sort(n[1], n[2])
n[0], n[1] = sort(n[0], n[1])

puts "#{n[0]} #{n[1]} #{n[2]}"

Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long 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;
    }
}
// 二項係数計算
long long 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;
}
int main() {
  int n,k,sum=0;cin>>n>>k;
  int maxim,mini;maxim=max(n,k);mini=min(n,k);
  rep(i,maxim){
      sum=sum*10+mini;
  }
  cout<<sum<<endl;
}

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

int main() {
int H;
  int N;
  cin>>H>>N;
  vector<int>im(N);
  int A=0;
    for(int i=0;i<N;i++)
  {int m;
   cin>>m;
   im.at(i)=m;}
  for(int i=0;i<N;i++)
      {A=A+im.at(i);}
      
     if(A>=H)
     {cout<<"Yes"<<endl;
     }
  else if(A<H)
  {cout<<"No"<<endl;
  }
  }

Measured memory_bytes: 640
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 163 -B
int main(void) {
	int  i, n,m, a;
	

	scanf("%d %d", &m,&n);
	for (i = 0; i < n; i++) {
		scanf("%d",&a);
		m -= a;
	}
	
	(m < 0) ? printf("-1\n") : printf("%d\n",m);

	return 0;
}

Measured memory_bytes: 2148
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[100000];
int ret[10];
int val[10000];
int used[10000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int at=0;
	if(a<200){
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				if(i==j)str[j]='1';
				else str[j]='0';
			}
			printf("?%s\n",str);
			fflush(stdout);
			int c;
			scanf("%d",&c);
			if(c)ret[at++]=i+1;
		}
		printf("!");
		for(int i=0;i<b;i++){
			printf("%d",ret[i]);
			if(i<b-1)printf(" ");
			else printf("\n");
		}
		fflush(stdout);
		return 0;
	}
	for(int i=0;i<a;i++)val[i]=i;
	int n=a/2;
	for(int i=0;i<b;i++){
		int d=0;
		do{
			for(int j=0;j<50000;j++){
				int l=rand()%a;
				int r=rand()%a;
				int z=val[l];
				val[l]=val[r];
				val[r]=z;
			}
			for(int j=0;j<a;j++)str[j]='0';
			int ind=0;
			for(int j=0;ind<n;j++){
				if(!used[val[j]]){
					str[val[j]]='1';
					ind++;
				}
			}
			printf("?%s\n",str);
			fflush(stdout);
			scanf("%d",&d);
		}while(!d);
		int left=-1;
		int right=n+1;
		while(left+1<right){
			int M=(left+right)/2;
			for(int j=0;j<a;j++)str[j]='0';
			int ind=0;
			for(int j=0;ind<M;j++){
				if(!used[val[j]]){
					str[val[j]]='1';
					ind++;
				}
			}
			printf("?%s\n",str);
			fflush(stdout);
			scanf("%d",&d);
			if(d)right=M;
			else left=M;
		}
		int V=0;
		int P=0;
		for(int j=0;V<right;j++){
			if(!used[val[j]]){
			//	str[val[j]]='1';
				V++;P=j;
			}
		}
		used[val[P]]=1;
		ret[at++]=val[P]+1;
	}std::sort(ret,ret+b);
	printf("!");
	for(int i=0;i<b;i++){
		printf("%d",ret[i]);
		if(i<b-1)printf(" ");
		else printf("\n");
	}
	fflush(stdout);
}

Measured memory_bytes: 1296
#include <iostream>

using namespace std;

int main(void) {
  int n;

  cin >> n;
  for (int i = 0; i < n || i < 100; ++i) {
    int a;
    cin >> a;
    if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) {
      cout << "DENIED" << endl;
      return 0;
    }
  }

  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
/*************************************************************************
    > File Name: B.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com 
    > Created Time: 2019年02月16日 星期六 20时11分18秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

using namespace std;
int a[100];
int main()
{
	int n,m,k,x;
	cin >> n >> m;
	for(int i = 0; i < n; ++i) {
		cin >> k;
		for(int j = 0; j < k; ++j) {
			cin >> x;
			a[x]++;
		} 
	}
	int cnt = 0;
	for(int i = 1; i <= m; ++i) {
		if(a[i] == n) cnt++;
	}
	cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))
    M = [10**5]*201
    if len(P) == 0:
        print(X)
        return
    min_abs = 10**5
    for i in range(102):
        if X-i not in P and X+i not in P:
            if min_abs > abs(X-(X-i)):
                min_abs = min(min_abs, abs(X-(X-i)))
                M[min_abs] = min(M[min_abs], X-i)
            elif min_abs > abs(X-(X+i)):
                min_abs = min(min_abs, abs(X-(X+i)))
                M[min_abs] = min(M[min_abs], X+i)
        if X-i not in P:
            if abs(X-(X-i)) < min_abs:
                min_abs = abs(X-(X-i))
                M[min_abs] = min(M[min_abs], X-i)
        if X+i not in P:
            if abs(X-(X+i)) < min_abs:
                min_abs = abs(X-(X+i))
                M[min_abs] = min(M[min_abs], X+i)
    print(min(M))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9280
#include<stdio.h>
int main(void){
char a[10001];
int i,j,cou,cou2;
while(scanf("%s",&a)!=EOF){
    cou=0,cou2=0;
for(i=0;a[i];i++){
    if(a[i]=='J'&&a[i+1]=='O'&&a[i+2]=='I')cou++;
    else if(a[i]=='I'&&a[i+1]=='O'&&a[i+2]=='I')cou2++;
    }
    printf("%d\n%d\n",cou,cou2);
}
return 0;
}

Measured memory_bytes: 980
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;

int main(){
	int N;
	cin>>N;
	vector<pair<ll,ll> > data;
	rep(i,N){
		ll x,y;
		cin>>x>>y;
		data.pb(mp(x,y));
	}
	ll ans=N;
	rep(i,N){
		for(int j=i+1;j<N;j++){
			ll p=data[i].first-data[j].first;
			ll q=data[i].second-data[j].second;
			ll cnt=N;
			rep(x,N){
				rep(y,N){
					ll A=data[y].first-data[x].first;
					ll B=data[y].second-data[x].second;
					if(A==p&&B==q)cnt--;
				}
			}
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0;i < n;i++){
            a.add(sc.nextInt());
        }
        List<Integer> cnt = new ArrayList<>();
        for(Integer it : a){
            int x = 0;
            while(it != 0){
                if(it % 2 != 0){
                    break;
                }
                x++;
                it /= 2;
            }
            cnt.add(x);
        }
        //System.out.println(cnt);
        int sum = 0;
        for(Integer it : cnt){
            sum += it;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 38160
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]

ls = []

for i in range(N):
    h = int(stdin.readline().rstrip())
    ls.append(h)

ls = sorted(ls)

minval = ls[K-1] - ls[0]

for i in range(1, N-K+1):
    tmp = ls[i+K-1] - ls[i]
    minval = min(minval, tmp)

print(minval)


Measured memory_bytes: 8256
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_4-C: Dictionary

#include <cstdio>

const int NOT_FOUND = -1;
static int binary_search(const int as[], int f, int t, const int target) {
  while (f < t) {
    int m = (f+t)/2; // f+(t-f)/2
    if (target < as[m]) {
      t = m;
    } else if (as[m] < target) {
      f = m+1;
    } else { // as[m] == target
      return m;
    }
  }
  return NOT_FOUND;
}

int main(void) {
  int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  int q;
  std::scanf("%d", &q);
  int c = 0;
  for (auto i = 0; i < q; ++i) {
    int t;
    std::scanf("%d", &t);
    auto j = binary_search(ss, 0, n, t);
    if (j != NOT_FOUND) ++c;
  }

  std::printf("%d\n", c);

  return 0;
}
// end

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int res =0;
  for (int a = 0; a<= A; ++a) {
    for (int b = 0; b<=B; ++b) {
      for (int c = 0; c<=C; ++c) {
        int total = 500*a + 100*b + 50*c;
        if (total == X) ++res;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <numeric>
#include <memory>
#include <functional>
#include <stdexcept>
#include <typeinfo>
#include <limits>
#include <complex>
#include <locale>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define Debug2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<")\n";
#define Debug_arr(v,n) for(int i=0;i<n;++i) cerr<<#v<<"["<<i<<"]"<<" = "<<v[i]<<endl;
#define SET(p,v) fill((__typeof(**p)*)p,(__typeof(**p)*)p+sizeof(p),v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
#define X first
#define Y second
//#define FILE_JUDGE
//#define TIMES
//#define LINES
//#define home
string s;
long long ans;
map<char,long long> mp;
int main()
{
	#ifdef FILE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	cin>>s;
	for (auto c:s)
	{
		mp[c]++;
	}
	int n=(int)s.size();
	ans=(long long)n*(n-1)/2+1;
	for (char c='a';c<='z';++c)
	{
		long long t=mp[c],x=t*(t-1)/2;
		ans-=x;
	}
	cout<<ans<<endl;
	#ifdef TIMES
	eprintf("Times = %d ms.\n",clock());
	#endif
	#ifdef LINES
	eprintf("lines : %d line.\n",__LINE__+3);
	#endif
	return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{
	int m, f, r;

	int sum = 0;

	while (1) {

		scanf("%d %d %d", &m, &f, &r);
		sum = m + f;

		if (sum == -2 && r == -1)
			break;
		else if (m == -1 || f == -1)
			printf("F\n");

		else if (sum >= 80)
			printf("A\n");
		else if (sum >= 65 && sum < 80)
			printf("B\n");
		else if (sum >= 50 && sum < 65)
			printf("C\n");
		else if (sum >= 30 && sum < 50)
			if (r >= 50)
				printf("C\n");
			else
				printf("D\n");
		else 
			printf("F\n");

	}
	return 0;

}


Measured memory_bytes: 2572
digits = input()
digits = list(map(int, digits[::-1]))
digits.append(0)

ans = 0
for i in range(len(digits)):
    if digits[i] < 5:
        ans += digits[i]
    elif digits[i] == 5:
        if digits[i + 1] < 5:
            ans += digits[i]
        else:
            digits[i + 1] += 1
            ans += 10 - digits[i]
    else:
        # digits[i] > 5
        digits[i + 1] += 1
        ans += 10 - digits[i]

print(ans)


Measured memory_bytes: 14532
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t1,t2,a1,a2,b1,b2;
int main() {
	cin>>t1>>t2;
	cin>>a1>>a2;
	cin>>b1>>b2;
	if(a1*t1+a2*t2>b1*t1+b2*t2) swap(a1,b1),swap(a2,b2);
	a1*=t1;a2*=t2;
	b1*=t1;b2*=t2;
	ll tota=a1+a2,totb=b1+b2;
//	cout<<"tota = "<<tota<<" totb = "<<totb<<'\n';
//	cout<<"a1 = "<<a1<<" a2 = "<<a2<<'\n';
//	cout<<"b1 = "<<b1<<" b2 = "<<b2<<'\n';
	if(tota<totb && a1<b1) {
//		cout<<"went here\n"; 
		cout<<"0";
		return 0;
	}
	if(tota==totb) {
		cout<<"infinity";
		return 0;
	}
	if((a1-b1)%(totb-tota))cout<<(a1-b1)/(totb-tota)*2+1<<'\n';
	else cout<<(a1-b1)/(totb-tota)*2<<'\n';
//	if()
	return 0;
}

Measured memory_bytes: 256
let to_z x = if x = -0. then 0. else x;;
let read_str u = read_line u |> Str.split (Str.regexp_string " ")
           |> List.map (fun x-> float_of_string x) |> List.nth;;
let () =
  let fl = read_str () in
  let x0, y0, x1, y1 = fl 0, fl 1, fl 2, fl 3 and
      n = read_int () in
  let rec read i =
    let fl2 = read_str () in
    let x2, y2 = fl2 0, fl2 1 in
    let p1_sqr = ( (x1-.x0)**2. +. (y1-.y0)**2. ) and
        in_p = ((x1-.x0)*.(x2-.x0)+.(y1-.y0)*.(y2-.y0)) in
    let xt,yt = 2.*.in_p*.(x1-.x0)/.p1_sqr +. 2.*.x0 -.x2 , 2.*.in_p*.(y1-.y0)/.p1_sqr +. 2.*.y0 -. y2 in
    Printf.printf "%.10f %.10f\n" (to_z xt) (to_z yt);
    if i > 0 then read (i-1)
  in read (n-1);;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<vector<ll>> g(K*2,vector<ll>(K*2,0));
  rep(i,N){
    int x,y;
    char c;
    cin>>x>>y>>c;
    x%=(2*K);
    y%=(2*K);
    if(c=='B'){
      if((x<K&&y<K)||(x>=K&&y>=K)){
        if(x>=K&&y>=K) {x-=K;y-=K;}
        g[0][0]++;
        g[K-x][0]--;
        g[0][K-y]--;
        g[K-x][K-y]+=2;
        if(x!=0){
          g[2*K-x][0]++;
          g[2*K-x][K-y]-=2;
        }
        if(y!=0){
          g[0][2*K-y]++;
          g[K-x][2*K-y]-=2;
        }
        if(x!=0&&y!=0) g[2*K-x][2*K-y]+=2;
      }
      else{
        if(x>=K) x-=K;
        if(y>=K) y-=K;
        g[K-x][0]++;
        g[0][K-y]++;
        g[K-x][K-y]-=2;
        if(x!=0){
          g[2*K-x][0]--;
          g[2*K-x][K-y]+=2;
        }
        if(y!=0){
          g[0][2*K-y]--;
          g[K-x][2*K-y]+=2;
        }
        if(x!=0&&y!=0) g[2*K-x][2*K-y]-=2;
      }
    }
    else{
      if((x<K&&y<K)||(x>=K&&y>=K)){
        if(x>=K&&y>=K) {x-=K;y-=K;}
        g[K-x][0]++;
        g[0][K-y]++;
        g[K-x][K-y]-=2;
        if(x!=0){
          g[2*K-x][0]--;
          g[2*K-x][K-y]+=2;
        }
        if(y!=0){
          g[0][2*K-y]--;
          g[K-x][2*K-y]+=2;
        }
        if(x!=0&&y!=0) g[2*K-x][2*K-y]-=2;
      }
      else{
        if(x>=K) x-=K;
        if(y>=K) y-=K;
        g[0][0]++;
        g[K-x][0]--;
        g[0][K-y]--;
        g[K-x][K-y]+=2;
        if(x!=0){
          g[2*K-x][0]++;
          g[2*K-x][K-y]-=2;
        }
        if(y!=0){
          g[0][2*K-y]++;
          g[K-x][2*K-y]-=2;
        }
        if(x!=0&&y!=0) g[2*K-x][2*K-y]+=2;
      }
    }
  }
  rep(i,2*K){
    rep(j,2*K-1){
      g[i][j+1]+=g[i][j];
    }
  }
  rep(i,2*K){
    rep(j,2*K-1){
      g[j+1][i]+=g[j][i];
    }
  }
  ll ans = 0;
  rep(i,2*K){
    rep(j,2*K) chmax(ans,g[i][j]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 34668
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
from fractions import gcd
from functools import reduce
def resolve():
    N,K=pin()
    A=list(pin())
    A.sort()
    maxK=A[-1]
    step=reduce(gcd,A)
    cond=1
    if K>maxK or (maxK-K)%step!=0:cond=0
    print(["IMPOSSIBLE","POSSIBLE"][cond])

#%%submit!
resolve()

Measured memory_bytes: 88172
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function(chunk){
    var lines = chunk.toString().split("\n");
    var N = parseInt(lines[0],10);
//レート3200未満の人達の色の数を調べるため配列作成
    var Ary =new Array(8);                  
    Ary.fill(0);　　　　　　　　　　　　　　　
//  3200以上の選べる人たち
    var rate_ab3200 = 0;
    var  N_color =0; //色の種類
 
//各色の人数を把握する    >=400 && rate<800
    var rate_all = lines[1].split(" ");
   
/*
   for(i=0; i<N; i++){
       console.log(rate_all[i]);
   }
*/   
   for(i=0; i<N; i++){
       var rate =parseInt(rate_all[i],10);
       if(rate < 400){
           Ary[0]++;
           }else if(rate>=400 && rate<800){
             Ary[1]++;
              }else if(rate>=800 && rate<1200){
                    Ary[2]++;
                    }else if(rate>=1200 && rate<1600){
                        Ary[3]++;
                        }else if(rate>=1600 && rate<2000){
                            Ary[4]++;
                            }else if(rate>=2000 && rate<2400){
                                Ary[5]++;
                                }else if(rate>=2400 && rate<2800){
                                    Ary[6]++;
                                    }else if(rate>=2800 && rate<3200){
                                        Ary[7]++;
                                        }else{
                                            rate_ab3200++;
                                            }
   }
 
    //        console.log(Ary);
    //        console.log(rate_ab3200);
 
//色の数(3200未満の人々)
    for(i=0; i<8; i++){
        if(Ary[i] >0){
            N_color++;
        }
    }
 
    //       console.log(N_color);
 //3200以上の人が8人以上の場合
    //console.log(Ary[1]);
    if(rate_ab3200>=8){
        if(N_color===0){
            console.log(1+" "+rate_ab3200);
        }else{
            console.log(N_color+" "+(rate_ab3200+N_color));
        }
//200以上の人が8人未満の場合
    }else{                      
//3200未満の色数が0の時、そうでないとき
            if(N_color === 0){
                console.log(1+" "+rate_ab3200);
            }else{
//3200以上の人数人数とい3200未満の色数が8以上の時、そうでないとき
            //    if((rate_ab3200+N_color)>=8){
                console.log(N_color+" "+(rate_ab3200+N_color));
          //      }else{
            //        console.log(N_color+" "+(rate_ab3200+N_color));
            //    }
            }
        }
 
    });


Measured memory_bytes: 7500
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i w acc =
        if i = n then acc else
            if s.[i] = 'B' then loop (i + 1) w acc else
                loop (i + 1) (w + 1) (acc + i - w)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4556
N, M = map(int, input().split())
AC = [False] * (N+1)
WA = [0] * (N+1)
for i in range(M):
    p, S = input().split()
    p = int(p)
    if S == 'AC':
        AC[p] = True
    else:
        if not AC[p]:
            WA[p] += 1
C_AC = 0
A_WA = 0
for i in range(N+1):
    if AC[i]:
        C_AC += 1
        A_WA += WA[i]

print(C_AC, A_WA)

Measured memory_bytes: 10464
#include <iostream>
#include <map>
using namespace std;
#define N 212345
int main() {
  int n;
  cin >> n ;
  if(n==10||n==100||n==1000||n==10000||n==100000){
    cout << 10;
  }else{
    int sum=0;
    for(int i=100000;i>=1;i/=10){
      sum += n/i;
      n-=i*(n/i);
    }
    cout << sum;
  }
  // 9 = 4+5
  // 910 = 909+1 900 10
  // 10000 = 9000+1000
}

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

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

    int d,t,s;
    cin >> d >> t >> s;
    if (d <= s*t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3688
#include<iostream>
using namespace std;
int main () {
  int n,cnt = 0;
  cin >> n;
  int p[n];

  for(int i = 0; i < n; i++) {
    cin >> p[i];
  }

  for(int i = 1; i < n-1; i++) {
    if((((p[i-1] < p[i]) && p[i] == p[i+1])) || ((p[i+1] < p[i]) && p[i] == p[i-1]) || ((p[i] > p[i-1]) && (p[i+1] > p[i])) || ((p[i-1] > p[i]) && (p[i] > p[i+1]))) {
      cnt++;
    }
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

typedef struct Edge {
    ll to, cost;
} Edge;
map<int,ll> mp;

vector<vector<Edge>> g;

vector<int> vi;
vector<ll> ans;

void solve(int x, int count) {
    if (vi[x]) return;
    vi[x] = true;
    count += mp[x];
    ans[x]+=count;

    for (auto &&e: g[x]) {
        solve(e.to,count);
    }
    return;
}

int main(int argc, char const *argv[]) {
    int n,q;
    cin>>n>>q;
    g.resize(n);
    vector<P> a(n-1);
    rep(i,n-1) {
        int x,y; cin>>x>>y;
        --x,--y;
        a[i]={x,y};
    }
    rep(i,q) {
        int x,y; cin>>x>>y;
        --x;
        mp[x]+=y;
    }
    rep(i,n-1) {
        int x = a[i].first; int y = a[i].second;
        g[x].push_back({y,mp[x]});
    }

    vi.resize(n,false);
    ans.resize(n);
    solve(0,0);
    rep(i,n) {
        cout<<ans[i];
        if (i!=n-1) cout<<" ";
        else cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 46976
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
#define nl "\n"
#define X first
#define Y second

#define MAX INT_MAX
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define check() {printf("OK\n");}
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i,a,b) for(int i =(a); i <=(b); ++i)
#define maxv(v) *max_element(v.begin(),v.end())
#define minv(v) *min_element(v.begin(),v.end())

#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define f() {ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);}
#define unq(v) srt(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define MOD 1000000007   // (int)1e9+7


int main(){f();

            int n;
            cin>>n;
            vector<int>v(n);
            for(int i = 1; i<=n; i++)
            {
                cin>>v[i];
            }
            int m;
            cin>>m;
            while(m--)
            {

                int p,x;
                cin>>p>>x;
                int sum =0;
                for(int i = 1; i<=n;i++){
                   if(i==p){
                    sum+=x;
                   }
                   else{
                    sum+=v[i];
                   }
                }
                cout<<sum<<nl;
            }


return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000
using namespace std;
int n,m,d,q;
ll mmp[maxn][maxn];
ll ans[maxn];
struct Node{
	int x,y;
	Node (int xx=0,int yy=0){
		x=xx,y=yy;
	}
}a[maxn*maxn];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>d; int l,r;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	cin>>mmp[i][j],a[mmp[i][j]]=Node(i,j);
	for (int i=1;i<=d;i++){
		int s=i;
		while(s<n*m){
			int v=s+d;
			ans[v]=ans[s]+abs(a[v].x-a[s].x)+abs(a[v].y-a[s].y);
			s+=d;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r;
		cout<<ans[r]-ans[l]<<endl;
	}
	return 0;
}

Measured memory_bytes: 11644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.NothingToLearn
{
    class ABC111_A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string n = Read();
            string res = "";
            for(int i = 0; i < 3; i++)
            {
                if (n[i] == '1') res += '9';
                else if (n[i] == '9') res += '1';
                else res += n[i];
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ss second
#define ff first

int main() 
{
    ll n,i,j,k,x,y,w,flag=0;
    string s,t;
    cin>>s>>t;
    ll dp[s.length()+1][t.length()+1];
    for(i=0;i<=s.length();i++)
    {
        for(j=0;j<=t.length();j++)
        {
            if(i==0 || j==0)
            dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    
    string lcs="";
    for(i=s.length(),j=t.length();i>0 && j>0;)
    {
        if(dp[i][j]==dp[i-1][j])
        i--;
        else if(dp[i][j]==dp[i][j-1])
        j--;
        else
        {lcs=s[i-1]+lcs;i--;j--;}
    }
    cout<<lcs;
    return 0;
}


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
long long sum, n, m;
int main(){
    n = read(), m = read();
    for (int i = 1; i <= m; i++){
        int a = read();
        sum += a;
    }
    n -= sum;
    if (n < 0){
        cout << -1 << endl;
    }
    else{
        cout << n << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct __scanner__{ bool e; operator bool(){ return e; } } IN = { false };
inline __scanner__& operator>>(__scanner__& in,int &n)
{ in.e = scanf("%d",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,ll &n)
{ in.e = scanf("%lld",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,double &n)
{ in.e = scanf("%lf",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,char &n)
{ in.e = scanf(" %c",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,string &n) // BUFFER SIZE!
{ static char buf[1000000]; in.e = scanf(" %s",buf)==1; n = buf; return in; } 

int main(){
  string s;
  while (cin >> s) {
    vector<char> v;
    REP(i,s.length()) {
      if (v.size() && v[v.size()-1] == 'S' && s[i] == 'T') {
	v.pop_back();
      } else {
	v.push_back(s[i]);
      }
    }
    cout << v.size() << endl;
  }
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  ll x;
  cin >> x;
  for (ll aa = 1; aa <= 200; aa++) {
    for (ll bb = -200; bb <= 200; bb++) {
      if ((aa * aa * aa * aa * aa - bb * bb * bb * bb * bb) == x) {
        cout << aa << " " << bb << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '7') {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";

  return 0;
}


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

using namespace std;

int a,b;
int main()
{
	// freopen("read.in","r",stdin);
	cin >> a >> b;
	if(a%b==0) puts("-1");
	else 
	{
		int x=a;
		while(x%b==0)
			x+=a;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readInt
	val Array(s1, t1) = scala.io.StdIn.readLine.split(" ").map(_.toList)

	var ans: String = ""

	for(i<-0 until N){
		ans = ans + s1(i) + t1(i)
	}

	println(ans)

}

Measured memory_bytes: 25548
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[100005];
int dfs(int x,vector<vector<int>> & ki) {
    if(dp[x] != -1) {
        return dp[x];
    }
    int res = 0;
    for(int i = 0; i < ki[x].size(); i++) {
        res = max(res,dfs(ki[x][i],ki)+1);
    }
    return dp[x] = res;
}
int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>>ki(N);
    for(int i = 0; i < M; i++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        ki[x].push_back(y);
    }
    for(int i = 0; i < N; i++) {
        dp[i] = -1;
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans,dfs(i,ki));
    }
    cout << ans << endl;
}


Measured memory_bytes: 11108
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define sz(x) (int)x.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(a) (1ll<<(a))
#define endl "\n"
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
/*并查集
 * int f[];
 * int Find(int x){x==f[x]?return f[x]:f[x]=Find(f[x]);}
 * int join(int x,int y){if(Find(x)!=Find(y))f[Find(x)]=Find(y);}
 * 快速幂*/
int qpow(ll a,ll b,ll m){ll c=1;while(b){if(b&1)c=c*a%m;b>>=1;a=a*a%m;}return c;}
int main(){
	ios::sync_with_stdio(false);
	int k,a,b;
	cin>>k>>a>>b;
	int y=0;
	rep(i,a,b+1){
		if(i%k==0){
			y=1;
			break;
		}
	}
	if(y)cout<<"OK";
	else cout<<"NG";
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>

using namespace std;

int main(){
    int N; cin >> N;
    long long cnt = 0;

    set<int> s;
    long long counter = 0;

    if(N %7 == 0){
        N /= 7;
    }

    int keta = 1;
    while(true){
        keta %= N;
        cnt++;
        if(s.count(keta) > 0){
            cnt = -1;
            break;
        }else{
            s.insert(keta);
        }

        if(keta == 0) break;

        keta = keta* 10+1;
        keta %= N;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 50388
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int n,b,f,r,v;cin>>n;
	int room[4][3][10]={0};
	while(n--){
		cin>>b>>f>>r>>v;b--;f--;r--;
		room[b][f][r]+=v;
	}
	for(b=0;b<4;b++){
		for(f=0;f<3;f++){
			for(r=0;r<10;r++){
				cout<<" "<<room[b][f][r];
			}
			cout<<endl;
		}
		if(b<3){for(r=0;r<20;r++){cout<<'#';}cout<<endl;}
		
	}
	RE;
}


Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Long.parseLong;
import static java.lang.Integer.parseInt;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = parseInt(in.readLine());
      long[] seq = new long[n];

      for(int i=0; i<n; i++)
        seq[i] = parseLong(in.readLine());

      Arrays.parallelSort(seq);

      long[] resU = new long[n];  // /\/\Pattern
      long[] resD = new long[n];  // \/\/Pattern

      int l = n-1;
      resU[0] = -1;
      resD[0] =  1;
      for(int i=1; i<l; i++) {
        resU[i] = (i&1) == 1 ?  2 : -2;
        resD[i] = (i&1) == 1 ? -2 :  2; 
      }
      resU[l] = (n&1) == 0 ?  1 : -1;
      resD[l] = (n&1) == 0 ? -1 :  1;

      Arrays.parallelSort(resU);
      Arrays.parallelSort(resD);

      long sumU=0,sumD=0;
      for(int i=0; i<n; i++) {
        sumU += seq[i] * resU[i];
        sumD += seq[i] * resD[i];
      }

      System.out.println(Math.max(sumU, sumD));
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 34924