akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define pb(x) push_back(x)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>

const int N = 1e5 + 7;

int n, m, a[N];

int main() {
	makefast;
	cin >> n >> m;
	int cf = 0;
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1)
			cf++;
	}
	if (n % 2 && cf > 1) {
		cout << "Impossible";
		return 0;
	}
	if (n % 2 == 0 && cf > 2) {
		cout << "Impossible";
		return 0;
	}
	vector <int> v;
	if (n % 2 == 0 && cf == 0) {
		if (a[1] % 4 == 2) {
			if (a[1] / 2 - 1)
				v.pb(a[1] / 2 - 1);
			v.pb(1);
			if (a[1] / 2 - 1)
				v.pb(a[1] / 2 - 1);
		}
		else {
			if (a[1] - 2)
				v.pb(a[1] - 2);
			v.pb(1);
		}
		for (int i = 2; i <= m; i++) {
			if (a[i] % 4 == 2) {
				v.pb(a[i] / 2 + 1);
				if (a[i] / 2 - 1)
					v.pb(a[i] / 2 - 1);
			}
			else {
				v.pb(a[i]);
			}
		}
		v.pb(1);
		for (int i = 1; i <= m; i++)
			cout << a[i] << ' ';
		cout << '\n';
		cout << v.size() << '\n';
		for (auto x: v)
			cout << x << ' ';
		return 0;
	}
	if (n % 2 == 0 && cf == 2) {
		int f1 = 0, f2 = 0;
		for (int i = 1; i <= m; i++)
			if (a[i] % 2 == 1)
				if (!f1)
					f1 = a[i];
				else
					f2 = a[i];
		for (int i = 2; i < f1; i += 2)
			v.pb(2);
		for (int i = 1; i <= m; i++)
			if (a[i] % 4 == 2) {
				v.pb(a[i] / 2 + 1);
				if (a[i] / 2 - 1)
					v.pb(a[i] / 2 - 1);
			}
			else if (a[i] % 4 == 0) 
				v.pb(a[i]);
		for (int i = 2; i <= f2 + 1; i += 2)
			v.pb(2);
		cout << f1 << ' ';
		for (int i = 1; i <= m; i++)
			if (a[i] % 2 == 0)
				cout << a[i] << ' ';
		cout << f2 << '\n';
		cout << v.size() << '\n';
		for (auto x: v)
			cout << x << ' ';
		return 0;
	}
	if (n % 2 == 1 && cf == 1) {
		int f = 0;
		for (int i = 1; i <= m; i++)
			if (a[i] % 2)
				f = a[i];
		for (int i = 2; i < f; i += 2)
			v.pb(2);
		for (int i = 1; i <= m; i++)
			if (a[i] % 4 == 2) {
				v.pb(a[i] / 2 + 1);
				if (a[i] / 2 - 1)
				v.pb(a[i] / 2 - 1);
			}
			else if (a[i] % 4 == 0)
				v.pb(a[i]);
		v.pb(1);
		cout << f << ' ';
		for (int i = 1; i <= m; i++)
			if (a[i] % 2 == 0)
				cout << a[i] << ' ';
		cout << '\n' << v.size() << '\n';
		for (auto x : v)
		cout << x << ' ';
		return 0;
	}
	cout << 1 / 0;
		

}


Measured memory_bytes: 640
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

maxv = -(10**9)
mina = a[0]

for i in range(1,n):
    maxv = max(maxv, a[i]-mina)
    mina = min(mina, a[i])

print(maxv)

Measured memory_bytes: 15644
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);

    int N[] = new int[1000];
    double SD[] = new double[1000];
    double Ave,Sum;
    int Num,K=0;

    while(true){
      Num = scanner.nextInt();
      Ave = 0;
      Sum = 0;
      if(Num==0){
        break;
      }
      for(int i=0;i<Num;i++){
        N[i] = scanner.nextInt();
        Ave += N[i];
      }
      Ave /= Num;

      for(int i=0;i<Num;i++){
        Sum += (N[i]-Ave)*(N[i]-Ave);
      }

      SD[K] = Math.sqrt(Sum/Num);
      K++;
    }

    for(int i=0;i<K;i++){
      System.out.println(SD[i]);
    }

  }
}



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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,m; cin>>n>>m;
  vi p(m);
  vector<string> s(m);
  rep(i,m) cin>>p[i]>>s[i];
  vector<bool> b(100005);
  vi cnt(100005);
  ll ok=0,fail=0;
  rep(i,m){
    if(b[p[i]]) continue;
    
    if(s[i]=="AC"){
      b[p[i]]=true;
      fail+=cnt[p[i]];
      ok++;
    }else{
      cnt[p[i]]++;
    }
  }
  cout<<ok<<" "<<fail<<endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
ll mx=1e9+7;
void solve()
{
    ll n;
    cin >> n;
    ll a,sum=0,p=0;
    for(ll i=0;i<n;i++)
    {
        cin >> a;
        sum+=a*p;
        p+=a;
        p=p%mx;
        sum=sum%mx;
    }
    
    cout << sum << endl;
}
 
int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int cnt = 0;
  while (true) {
    if (cnt % 2 == 0) {
      c -= b;
      if (c <= 0) {
        cout << "Yes" << endl;
        return 0;
      }
    } else {
      a -= d;
      if (a <= 0) {
        cout << "No" << endl;
        return 0;
      }
    }
    cnt++;
    cnt %= 2;
  }
  return 0;
}

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

using namespace std;
using ll = unsigned long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

// 入力
int N;
Graph G;
map<P, int> mp;
set<int> se;

// v を c に塗る。p は v の親
void dfs(int v, int p, int c) {
    int count = 1;
    if(count == c) ++count;
    for (auto& e : G[v]) {
        if (e.first == p){
            continue;
        }

        e.second = count;
        mp[{v, e.first}] = e.second;
        se.insert(count);
        dfs(e.first, v, count);

        ++count;
        if(count == c) ++count;
    }
}

void solve() {
    cin >> N;
    G.assign(N, vector<Edge>());
    vector<P> ans;
    ans.resize(N-1);

    for (int i = 0; i < N-1; ++i) {
        int u, v; cin >> u >> v;
        --u, --v;
        ans[i] = {u,v};
        G[u].push_back(Edge(v, 0));
        G[v].push_back(Edge(u, 0));
    }

    dfs(0, -1, -1);

    cout << se.size() << endl;
    for(int i = 0; i < N-1; ++i){
        cout << mp[ {ans[i].first, ans[i].second} ] << endl;
    }
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}



Measured memory_bytes: 15360
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

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


int main(){
    ll X;
    cin >> X;
    ll count = 1;
    ll sum = 0;
    while(1){
        sum += count;
        if(sum >= X){
            break;
        }
        count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MxN = 1e5+1;
int ar[MxN];
void solve() {
    int n;cin>>n;
    int r=0;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        ar[x-1]++;
        ar[x]++;
        ar[x+1]++;
        r = max(x+1, r);
    }
    int mx=0;
    for(int i=0;i<r;i++) {
        mx = max(ar[i], mx);
    }
    cout<<mx<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  int a[M];
  rep(i, M) cin >> a[i];

  int dp[N+1]; fill(all(dp, N+1), 0);
  dp[0] = 1;
  rep(i, N) {
    if (binary_search(all(a, M), i))
      continue;
    dp[i+1] += dp[i]; dp[i+1] %= MOD;
    dp[i+2] += dp[i]; dp[i+2] %= MOD;
  }
  out(dp[N]);

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 10000
using namespace std;
template<typename T>inline void read(T &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
	x*=p;
}
int n;
long long x,y;
int main()
{
//	freopen("SG.in","r",stdin);
//	freopen("SG.out","w",stdout);
	read(n);
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		read(x);read(y);
		while(x%y>0)x-=(x/y+1)*((x%y-1)/(x/y+1)+1);
		ans^=x/y;
	}
	if(ans)puts("Takahashi");
	else puts("Aoki");
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * for (int i = 0; i < N; i++) {}
 * System.out.println();
 * @author mj
 *
 */
public class Main implements Runnable { //クラス名はMain1

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

	public void run() {
		FastScannerMain1 sc = new FastScannerMain1(System.in);

		try {
			String S = sc.nextLine().trim();
			boolean a = false;
			boolean b = false;

			if (S.contains("A")) {
				a = true;
			}
			if (S.contains("B")) {
				b = true;
			}

			if (a && b) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

//高速なScanner
class FastScannerMain1 {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMain1(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 30292
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
# define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int x,y;
	cin>>x>>y;
	int c,t;
	c=((4*x)-y)/2;
	t=(y-(2*x))/2;
	//cout<<c<<" "<<t<<endl;
	if((abs(c)+abs(t))==x)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
	return 0;
}

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

int main()
{
    int n,k,q;
    std::cin>>n>>k>>q;
    std::vector<int> score(n,k-q);//各人の点数
    std::vector<int> a(q); //正解者
    for(int i=0;i<q;i++){
        std::cin>>a[i];
        a[i]--;
    }

    for(int i=0;i<q;i++){
        score[a[i]]++;
    }

    for(int i=0;i<n;i++){
        std::cout<<(score[i]<=0?"No":"Yes")<<std::endl;
    }
    
}

Measured memory_bytes: 1408
"use strict";

const main = input => {
  const lines = input.split('\n');
  const R = lines[0].split(' ').map(x => parseInt(x))[0];
  const G = lines[0].split(' ').map(x => parseInt(x))[1];
  const B = lines[0].split(' ').map(x => parseInt(x))[2];
  const N = lines[0].split(' ').map(x => parseInt(x))[3];

  var result = 0;
  const R_limit=Math.max(Math.ceil(N/R),1);
  const G_limit=Math.max(Math.ceil(N/G),1);
  const B_limit=Math.max(Math.ceil(N/B),1);
  for(var r=0;r<=R_limit;r++){
    for(var g=0;g<=G_limit;g++){
      if(r*R + g*G>N){break;}
        if((N-(r*R + g*G))%B==0){result++;}
    }
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
n,m = map(int,input().split())
res = [0 for _ in range(m)]
for _ in range(n):
    ka = [int(i) for i in input().split()]
    k = ka[0]
    a = ka[1:]
    for i in range(k):
        res[a[i]-1] += 1
ans = 0
for i in range(m):
    if res[i] == n:
        ans += 1
print(ans)

Measured memory_bytes: 3064
//Malfurion_Drake
#include<bits/stdc++.h>
#define Maxn 100005
using namespace std;

int n,a[Maxn];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

/*template<typename Drake>
inline Drake max(Drake Cmp1,Drake Cmp2){
	return(Cmp1>Cmp2 ? Cmp1 : Cmp2);
}

template<typename Drake>
inline Drake min(Drake Cmp1,Drake Cmp2){
	return(Cmp1<Cmp2 ? Cmp1 : Cmp2);
}

void addedge(int u,int v){
	++tot;
	ver[tot]=v;
	Next[tot]=head[u];head[u]=tot;
}*/

void init(){
	
	read(n);
	if(n==1){
		puts("Hello World");
	}
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	
}

int main(){
	init();
	
	
	return 0;
}

Measured memory_bytes: 768
N, K = map(int, input().split())
A = list(map(int, input().split()))

takahashi = 1
roop = [takahashi]
roop_flag = False
visited = [False] * N
visited[takahashi - 1] = True

for _ in range(K):
    takahashi = A[takahashi - 1]
    if visited[takahashi - 1]:
        roop_flag = True
        break
    else:
        roop.append(takahashi)
        visited[takahashi - 1] = True

if roop_flag:
    first, roop = roop[:roop.index(takahashi)], roop[roop.index(takahashi):]
    print(roop[(K - len(first)) % len(roop)])
else:
    print(roop[-1])

Measured memory_bytes: 32372
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto A = RD;
	auto B = RD;

	writeln(max(max(A+B, A * 2 - 1), B * 2 - 1));
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <string>
#include <iomanip>
// #include <cmath>
#include <cassert>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

typedef int128_t ll;

const int MAX_SIZE = 4000;
bool isprime[MAX_SIZE];
vector<ll> prime_num;
vector<ll> squered;
vector<ll> cubed;

// const ll infty = 10000000010;

void init() {
  fill(isprime, isprime+MAX_SIZE, true);
  isprime[0] = isprime[1] = false;
  for (auto i=2; i<MAX_SIZE; i++) {
    if (isprime[i]) {
      ll x = i;
      prime_num.push_back(x);
      squered.push_back(x*x);
      cubed.push_back(x*x*x);
      for (auto j=2; i*j<MAX_SIZE; j++) {
        isprime[i*j] = false;
      }
    }
  }
}

bool prime(long long x) { // 2 \leq x \leq MAX_SIZE^2
  if (x < MAX_SIZE) {
    return isprime[x];
  }
  for (auto e : prime_num) {
    if (x%e == 0) return false;
  }
  return true;
}

int N;
ll s[100010];
map<ll, int> M;

ll conj(ll k) {
  ll l = k;
  ll A = 1;
  ll B = 1;
  for (auto x : prime_num) {
    int t = 0;
    while (l % x == 0) {
      l /= x;
      t++;
    }
    if (t == 1) {
      A *= x;
    } else if (t == 2) {
      B *= x;
    }
  }
  ll red = k / (A * B * B);
  ll sq = sqrt(red);
  long long t = static_cast<long long>(sq);
  t = floor(t);
  // cerr << "red = " << red << " , sq = " << sq << endl;
  if (red == t * t) {
    B *= red;
  } else {
    A *= red;
  }
  return A * A * B;
}

int main() {
  init();
  cin >> N;
  int ans = 0;
  for (auto i = 0; i < N; i++) {
    cin >> s[i];
    for (auto x : cubed) {
      while (s[i]%x == 0) s[i] /= x;
    }
    if (M.find(s[i]) == M.end()) {
      M[s[i]] = 1;
    } else {
      M[s[i]]++;
    }
  }
  for (auto x : M) {
    ll k = x.first;
    int num = x.second;
    // cerr << k << " " << num << endl;
    if (k == 1 && num > 0) {
      ans += 1;
      continue;
    }
    ll c = conj(k);
    // cerr << "conj(" << k << ") = " << c << endl;
    if (M.find(c) == M.end()) {
      ans += num;
    } else {
      ans += max(num, M[c]);
      M[k] = 0;
      M[c] = 0;      
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12800
N, K = map(int, raw_input().split(' '))
x = map(int, raw_input().split(' '))

m = 1 << 128

for i in range(0, N - K + 1):
    a = x[i]
    b = x[i + K - 1]

    if a < 0 < b:
        if abs(a) > abs(b):
            cost = abs(b) * 2 + abs(a)
        else:
            cost = abs(a) * 2 + abs(b)
    else:
        cost = max(abs(a), abs(b))

    m = min(m, cost)

print m


Measured memory_bytes: 11340
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  ll tmp=200000000000000;
  for(ll i=1;i<=sqrt(N);i++){
        if(N%i==0){
          ll j=N/i;
          tmp=min(tmp,i+j-2);
        }
      }
cout<<tmp<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int X =Integer.parseInt(in.next(), 16);
		int Y =Integer.parseInt(in.next(), 16);
		if(X<Y)System.out.println("<");
		else if(X>Y)System.out.println(">");
		else System.out.println("=");
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	Int ans = 1e18;
	for(Int i=1; i*i<=n; ++i){
		if(n % i != 0) continue;
		ans = min(ans, i-1 + n/i-1);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
dict = {}
max = 1
for i in range(n):
  str = input()
  if str in dict:
    dict[str] = dict[str] + 1
    if dict[str] > max:
      max += 1
  else:
    dict[str] = 1
keys = [k for k, v in dict.items() if v == max]
keys.sort()
for i in range(len(keys)):
  print(keys[i])

Measured memory_bytes: 32096
#include <bits/stdc++.h>
#define aaa cout<<233<<endl;
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// mt19937 rnd(TM(0));
const int inf = 0x3f3f3f3f;//1061109567 > 1e9
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = 3.14159265358979;
const int maxn = 1e3 + 5;
const int maxm = 5e5 + 233;
const int mod = 1e9 + 7;

int n, a[maxn];
string s;
int main()
{
    // double pp = clock();
    // freopen("233.in", "r", stdin);
    // freopen("233.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n;){
        int j = i;
        while(s[j] == s[i])++j;
        i = j;
        ++ans;
    }
    cout << ans << endl;
    
    // cout << endl << (clock() - pp) / CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main(void){
    int a,b,c;
    scanf("%d %d",&a,&b);
    if(b<=9){
        c=10*a+b;
    }
    if(b>=10 && b<=99){
        c=100*a+b;
    }
    if(b==100){
        c=1000*a+b;
    }
    if(ceil(sqrt(c))==sqrt(c) && floor(sqrt(c))==sqrt(c)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int a, b;
	int i;
	char buffer[128];
	char answer[16];
	char *ch;

	fgets(buffer, sizeof(buffer), stdin);
	ch = strtok(buffer, " ");
	a = atoi(ch);
	ch = strtok(NULL, " ");
	b = atoi(ch);

	if(b < a) {
		for(i = 0; i < a; i += 1) {
			sprintf(&answer[i], "%d", b);
		}
	} else {
		for(i = 0; i < b; i += 1) {
			sprintf(&answer[i], "%d", a);
		}
	}

	printf("%s\n", answer);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const double PI = 3.1415926535897932;
const int i_INF = 2147483647;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
	int n;
	cin >> n;
	cout << n * n << endl;
	return 0;
}

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

int main() {
	int N; cin >> N;
	int sgs=0;
	for(int i=1; true; ++i){
	    int T=i;
	    long shin=0;
	    for(int j=0; T!=0; ++j){
	        shin += (T%4)*pow(10, j);
	        T /= 4;
	    }
	    long koho=0;
	    int A[3];
	    A[0]=0; A[1]=0; A[2]=0;
	    for(int j=0; shin!=0; ++j){
	        if(shin%10){
	            ++A[shin%10 - 1];
	            koho += (1+(shin%10)*2)*pow(10, j);
	            shin /= 10;
	        }
	        else break;
	    }
	    if(shin==0 && A[0]*A[1]*A[2]!=0 && koho<=N) ++sgs;
	    if(koho>=N) break;
	}
	cout << sgs << endl;
	return 0;
}

Measured memory_bytes: 256
# B

T = input()

# cnt = 0
# pre = ''

# for i in range(len(T)):
#   if T[i] == 'P':
#     pre == 'P'
#   elif T[i] == 'D':
#     cnt += 1
#     if pre == 'P':
#       cnt += 1

#     pre == 'D'
#   else:
#     cnt += 1
#     if pre == 'P':
#       cnt += 1

#     pre == 'D'

# print(cnt)

print(T.replace('?','D'))


Measured memory_bytes: 9496
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, q = map(int, input().split())
    edges = [[] for _ in range(n+1)]

    for a, b in readlines(n-1):
        edges[a].append(b)
        edges[b].append(a)

    counter = [0] * (n+1)
    for q, x in readlines(q):
        counter[q] += x

    def dfs(u, prev):
        for v in edges[u]:
            if v == prev:
                continue
            counter[v] += counter[u]
            dfs(v, u)

    dfs(1, 0)

    print(" ".join(map(str, counter[1:])))

main()

Measured memory_bytes: 269816
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  int n = s.size();
  string keys = "keyence";
  string l = "", r = "";
  rep(i, 0, keys.size()) {
    if (s[i] == keys[i])
      l += s[i];
    else
      break;
  }

  int c = keys.size();
  repr(i, (int)(n - keys.size()), n) {
    if (s[i] == keys[--c])
      r += s[i];
    else
      break;
  }
  reverse(r.begin(), r.end());

  vector<bool> true_count(7, false);
  rep(i, 0, l.size()) {
    if (keys[i] = l[i])
      true_count[i] = true;
  }

  int rs = r.size() - 1;
  repr(i, (int)(keys.size() - r.size()), keys.size()) {
    true_count[i] = r[rs];
    rs--;
  }

  rep(i, 0, keys.size()) {
    if (!true_count[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	string S;cin >> S;
	ll ans = 0,sum = 0;
	ll len = S.size();
	if (len % 2 != 0) {
		for (ll i =len - 2;i >= 0;i-=2) {
			for (ll j = 0;j <= i / 2;j++) {
				if (S[j] == S[j + (i / 2)])sum += 2;
				else break;
			}
			if (ans < sum) ans = sum;
			sum = 0;
		}
	}
	else{
		for (ll i = len - 1;i >= 0;i -= 2) {
			for (ll j = 0;j < i / 2;j++) {
				if (S[j] == S[j + (i / 2)])sum += 2;
				else break;
			}
			if (ans < sum) ans = sum;
			sum = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
#define NIL -1

struct Node{
  /*
  p is parent
  l is left
  r is right
  */
  int p, l, r;
};

struct Node T[MAX];
int n;

void preOrder(int );
void inOrder(int );
void postOrder(int );

void preOrder(int u){
  if( u == NIL ) return;
  printf(" %d", u);
  preOrder(T[u].l);
  preOrder(T[u].r);
}

void inOrder(int u){
  if( u == NIL) return;
  inOrder(T[u].l);
  printf(" %d", u);
  inOrder(T[u].r);
}

void postOrder(int u){
  if( u == NIL ) return;
  postOrder(T[u].l);
  postOrder(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, d, v, l, r;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++) T[i].p = NIL;

  for( i = 0 ; i < n ; i++){
    scanf("%d", &v);
    scanf("%d", &l);
    scanf("%d", &r);
    T[v].l = l;
    T[v].r = r;
    //親の設定
    if(l != NIL ) T[l].p = v;
    if(r != NIL ) T[r].p = v;
  }
for( i = 0 ; i < n ; i++){
    if( T[i].p == NIL ) d = i;
  }

  printf("Preorder\n");
  preOrder(d);
  printf("\n");
  printf("Inorder\n");
  inOrder(d);
  printf("\n");
  printf("Postorder\n");
  postOrder(d);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2048
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	W := nextInt()
	H := nextInt()
	x := nextInt()
	y := nextInt()
	r := nextInt()
	if x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



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

int main()
{
    int n;
    cin>>n;
    int A[n],B[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
        B[i]=A[i];
}
    sort(A,A+n);
    for(int i=0;i<n;i++){
        if(B[i]<=A[n/2-1]){
            cout<<A[n/2]<<endl;
        }else {cout<<A[n/2-1]<<endl;}
    }
}


Measured memory_bytes: 3712
KEYS =[
  ['.', ',', '!', '?', ' '],
  %w[a b c],
  %w[d e f],
  %w[g h i],
  %w[j k l],
  %w[m n o],
  %w[p q r s],
  %w[t u v],
  %w[w x y z]
]
SIZES = [5,3,3,3,3,3,4,3,4]

Q = gets.to_i
Q.times do
  puts(
    gets.chomp.split("0").delete_if(&:empty?).map do |i|
      KEYS[i[0].to_i-1][(i.length-1) % SIZES[i[0].to_i-1]]
    end.join
  )
end



Measured memory_bytes: 6940
#include <stdio.h>
typedef long long ll;

ll power(int x);

int main()
{
    ll m, k;
    ll max_e;

    scanf("%lld %lld", &m, &k);
    max_e = power(m);

    ll s = 0;
    for (ll i = 0; i < max_e; i++) {
        if (i != k) {
            s ^= i;
        }
    }

    if (s != k && k != 0) {
        printf("-1\n");
        return 0;
    }

    for (ll i = 0; i < max_e; i++) {
        if (i != k || k == 0) {
            printf("%lld ", i);
        }
    }
    if (k != 0) {
        printf("%lld ", k);
    }
    for (ll i = max_e - 1; i >= 0; i--) {
        if (i != k || k == 0) {

            if (i == 0 && k == 0) {
                printf("%lld", i);
            }
            else {
                printf("%lld ", i);
            }
        }
    }
    if (k != 0) {
        printf("%lld", k);
    }

    putchar('\n');
    
    return 0;
}

ll power(int x)
{
    ll res = 1;
    ll mul = 2;

    while (x) {
        if (x & 1) {
            res *= mul;
        }

        mul *= mul;
        x = x >> 1;
    }

    return res;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int minPts(int x,vector<int>&V,int n)
{
    int i,s=0;
    for(i=0;i!=n;i++)
        s += (x-V[i])*(x-V[i]);

    return s;
}

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

    int i;
    vector<int>V(n);
    for(i=0;i!=n;i++)
        cin>>V[i];

    int s = 0;
    for(i=0;i!=n;i++)
        s += V[i];

    int x = s/n;
    x = min(minPts(x,V,n),minPts(x+1,V,n));

    cout<<x;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp1[20][(1<<18)+5]={0},dp2[20][(1<<18)+5]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=0;i<(1<<n);i++) cin>>dp1[0][i];
  for(int t=0;t<n;t++){
    for(int m=0;m<(1<<n);m++){
      if(((m>>t)&1)==0){
        dp1[t+1][m]=dp1[t][m];
        dp2[t+1][m]=dp2[t][m];
      }
      else{
        ll m_=m&(~(1<<t));
        priority_queue<ll> pque;
        pque.push(dp1[t][m]);
        pque.push(dp2[t][m]);
        pque.push(dp1[t][m_]);
        pque.push(dp2[t][m_]);
        dp1[t+1][m]=pque.top();
        pque.pop();
        dp2[t+1][m]=pque.top();
        pque.pop();
      }
    }
  }
  ll ans=dp1[n][0]+dp2[n][0];
  for(int i=1;i<(1<<n);i++){
    ans=max(ans,dp1[n][i]+dp2[n][i]);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 82944
/* ex9_2
   tamayama */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int count=0;
    char cube[SIZE];
    int i=0;
    char dump;


    //最初のノードの指す先
    node *first = NULL;

    scanf("%s",cube);
    
    //スタックにノードを追加
    for(i=0;i<strlen(cube);i++){
        if(first == NULL || first->elem == cube[i]){
    //初めのキューブをスタックに入れる
    //または
    //ひとつ前のキューブの色が次のキューブの色と同じならスタックに入れる
            push(&first, cube[i]);
        }else{
    //ひとつ前のキューブの色が次のキューブの色と異なるならスタックから取り出す
            dump = pop(&first);
            count += 2;
        }
    }
    
    printf("%d",count);
    return 0;
}



Measured memory_bytes: 4884
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;


#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll h,n;cin>>h>>n;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll sum=0;
  rep(i,0,n){
    sum+=a[i];
  }

  if(sum>=h)out("Yes");
  else out("No");



  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br  = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	data = null;

		while ((data = parseData()) != null) {
			calc(data);
		}
	}

	private static void calc(int[] data) {
		int		n  = 0;
		double	dt = (double)data[9] / (double)(data[10] + data[11]);
		double	dl = (double)data[10] * dt;

		for (; n < 10; n++) {
			if (dl == (double)data[n] || dl < (double)data[n]) {
				break;
			}
		}

		System.out.println(n+1);
	}

	private static int[] parseData() {
		int[]	data  = null;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			String[]	aN = strIn.split(",");
			data = new int[12];
			for (int n = 0; n < data.length; n++) {
				data[n] = Integer.parseInt(aN[n]);
				if (1 <= n && n <= 9) {
					data[n] += data[n-1];
				}
			}
		}
		
		return data;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

using namespace std;
using ll = long long;

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

    int h1, h2, m1, m2, k;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = h2 * 60 + m2 - h1 * 60 - m1 - k;

    if(ans < 0) printf("0\n");
    else printf("%d\n", h2 * 60 + m2 - h1 * 60 - m1 - k);

    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define debug(a) cout<<a<<endl
#define clr(a) memset(a,0,sizeof(a))
#define clrne(a) memset(a,-1,sizeof(a))
#define clrinf(a) memset(a,0x3f,sizeof(a))
#define clrneinf(a) memset(a,0xc0,sizeof(a))
#define pb(a) push_back(a)
#define maxn 10001
#define mod 1000000007
#define eps 1e-9
#define inf 0x7fffffff
int a[110];
int n;
int main()
{
//  freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
    scanf("%d",&n);
    for (int i = 1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int res = unique(a+1,a+1+n) - a - 1;
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
#N=int(input())
#a = list(map(int,input().split()))

#x = []
#y = []
#for i in range(5):
#    x1,y1=[int(i) for i in input().split()]
#    x.append(x1)
#    y.append(y1)
import math

A,B,C,X,Y=[int(i) for i in input().split()]

v=2*C*max(X,Y)
for r in range(2*max(X,Y)+2):
    R=r//2
    p=max(math.ceil(X-R),0)
    q=max(math.ceil(Y-R),0)
#    print(p*A+q*B+C*r,p,q,r)
    v=min(v, p*A+q*B+C*r)

print(v)
    



Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int X,Y,S;
int solve(int X,int Y,int S);
int maxCheck(int max,int sum);
int tax(int ratio,int price);

int solve(int X,int Y,int S) {
  int max = 0;
  for (int i=1;i<S;i++) {
    for (int j=i;j<S;j++) {
      if (tax(X,i)+tax(X,j) == S) {
	max = maxCheck(max,(tax(Y,i)+tax(Y,j)));
      }
    }
  }
  return max;
}
int maxCheck(int max,int sum) {
  if (max>sum)
    return max;
  else
    return sum;
}
int tax(int ratio,int price) {
  return int(price*(100+ratio)/100.0);
}
int main() {
  while (cin >> X >> Y >> S && X>0) {
    cout << solve(X,Y,S) << endl;
  }
}

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

#define N 36

typedef struct node{
  int num;
  char value;
}C;

C c_1[N];
C c_2[N];
int n;

void BubbleSort(){
  int i,j;
  C v;
  
  for(i = 0; i < n; i++){
    for(j = n - 1; i+1 <= j; j--){
      if(c_1[j].num < c_1[j-1].num){
        v = c_1[j];
        c_1[j] = c_1[j-1];
        c_1[j-1] = v;
      }
    }
  }
}

void SelectionSort(){
  int i,j,minj;
  C v;

  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(c_2[j].num < c_2[minj].num)minj = j;
    }
    v = c_2[i];
    c_2[i] = c_2[minj];
    c_2[minj] = v;
  }
  
}

int judgeStable(){
  int i;
  for(i = 0; i < n; i++){
    if(c_1[i].value != c_2[i].value)return 0;
  }

  return 1;
}

int main(){
  int i,num,stable;
  char val;

  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf(" %c%d",&val,&num);
    c_1[i].value = c_2[i].value = val;
    c_1[i].num = c_2[i].num = num;
  }
  BubbleSort();
  SelectionSort();

  printf("%c%d",c_1[0].value,c_2[0].num);
  for(i = 1; i < n; i++)printf(" %c%d",c_1[i].value,c_1[i].num);
  printf("\n");
  printf("Stable\n");
  
  stable = judgeStable();
  printf("%c%d",c_2[0].value,c_2[0].num);
  for(i = 1; i < n; i++)printf(" %c%d",c_2[i].value,c_2[i].num);
  printf("\n");
  if(stable == 1)printf("Stable\n");
  else printf("Not stable\n");
}


Measured memory_bytes: 2108
import java.util.*;

public class Main{

    void run(){
        Scanner sc = new Scanner(System.in);
        int case_cnt = 1;
        while(true){
            int W = sc.nextInt();
            if(W == 0){
                break;
            }
            int N = sc.nextInt();
            int[] value = new int[N];
            int[] weight = new int[N];
            for(int i = 0; i < N; i++){
                String[] s = sc.next().split(",");
                value[i] = Integer.parseInt(s[0]);
                weight[i] = Integer.parseInt(s[1]);
            }
            int[] dp = new int[W+1];
            for(int i = 0; i < N; i++){
                for(int w = W; w >= 0 ; w--){
                    if( w + weight[i] <= W){
                        dp[w + weight[i]] = Math.max(dp[w + weight[i]], dp[w] + value[i]);
                    }
                }
            }
            int max = 0;
            for(int w: dp){
                max = Math.max(max,w);
            }
            int index = 0;
            for(int i = 0; i <= W; i++){
                if(dp[i] == max){
                    index = i;
                    break;
                }
            }
            System.out.println("Case " + case_cnt + ":");
            System.out.println(max);
            System.out.println(index);
            case_cnt++;
        }
        
    }

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

Measured memory_bytes: 25280
N,K=map(int,input().split())
b=0
c=0
ans=0

for i in range(0,K):
    b+=i
    c+=(N-i)
ans=c-b+1


for i in range(K,N+1):
    b+=i
    c+=N-i
    ans+=c-b+1

print(ans%(10**9+7))
 
    

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N;
    cin >> N;
    vector<int> A(N);
    REP (i, N) {
        cin >> A[i];
    }

    vector<int> dp(N,0);
    dp[0] = 1000;
    FOR(i,1,N){
        dp[i] = dp[i-1];
        REP(j,i) {
            dp[i] = max(dp[i], dp[j]+(A[i]-A[j])*(dp[j]/A[j]));
        }
    }
    cout << dp[N-1] << endl;


    /*

    int money = 1000;
    int now = 0;
    REP(i,N-1) {
        while (A[i] >= A[i+1] && i < N-2) {
            i++;
        }
        now = money / A[i];
        money = money % A[i];
        while (A[i] <= A[i+1] && i < N-1) {
            i++;
        }
        money += now * A[i];
        now = 0;
        money = max(1000,money);
    }
    ans = max(1000,money);
    cout << ans << endl;




    
    ans = 1000;
    int m = INF;
    int idm = 0;
    REP(i, N) {
        if (m > A[i]) {
            idm = i;
            m = A[i];
        }
    }
    int M = 0;
    int idM = 0;
    FOR(i,idm,N) {
        if (M < A[i]) {
            idM = i;
            M = A[i];
        }
    }
    ans = max(ans, 1000/m * M);

    M = 0;
    idM = 0;
    REP(i, N) {
        if (M < A[i]) {
            idM = i;
            M = A[i];
        }
    }
    m = INF;
    idm = 0;
    FOR(i,0,idM) {
        if (m > A[i]) {
            idm = i;
            m = A[i];
        }
    }
    ans = max(ans, 1000/m * M);
    cout << ans << endl;
    */
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_d && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(void){
    int n,j,a[100]={0}; //100個
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    cout<<a[n-1];
    
    for(int i=1; i<n; i++){
            j=(n-1)-i;
            cout << " " << a[j];
    }
    cout << endl;
}



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

int main() {
   int H;
   int W;
   cin >> H>>W;
//cout<<H<<W;

vector<int>vec(W);
for(int j=0; j<W+2; j++){
cout<<"#";
}
cout<<endl;
  
for(int i=0; i<H; i++){
  string Si; 
  cout<<"#";
  cin>>Si;
  cout<<Si;
  cout<<"#";
  cout<<endl;
}

for(int j=0; j<W+2; j++){
cout<<"#";
}
cout<<endl; 
}

/*
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
 
map<string, int> dp;
int direction[4] = { 1, -1, 4, -4};  //可以向左向右向上向下

//与前几?的bfs不同，?次的bfs没有明?的移??象，看似任意一个数都可以当成?象移?
//??我?只需要抓住一个格子就行，比如我?把0作?移??象，那?0在地?中漫游所有的格子得到的肯定就是??的解空?
//由于?目的?入是多个case，如果??个case都?行一遍bfs就会TLE
//??我?祭出dp技能，只需要一次bfs就将解空?算出来，以后?个case只要到解空?中去找就行了
//0漫游整个字串

void bfs()
{
    queue<string> que;
    que.push("01234567");
    dp["01234567"] = 0;

    while(!que.empty())
    {
        string now = que.front();
        que.pop();
        
        //p是'0'的位置
        int p = 0;

        for(int j = 0; j < 8; j++)
        {
            if(now[j] == '0')
            {
                p = j;
                break;
            }
        }
 
        for(int i = 0; i < 4; i++)
        {
            int n = p + direction[i];
            if(0 <= n && n < 8 && 
                !(p == 3 && i == 0) && // 右上角不能再往右了
                !(p == 4 && i == 1))   // 左下角不能再往左了
            {
                string next = now;
                swap(next[p], next[n]);
                if(dp.find(next) == dp.end())
                {
                    dp[next] = dp[now] + 1;
                    que.push(next);
                }
            }
        }
    }
}
 
int main()
{
 
    bfs();
    string line;

    while(getline(cin, line))
    {
        line.erase(remove(line.begin(), line.end(), ' '), line.end());
        cout << dp[line] << endl;
    }
 
    return 0;
}

/*
?目附?
?出0~7的序列（2*4），只能0和周?数字交?，?最少交?多少次可以是?出的序列?成0 1 2 3 4 5 6 7。
有一个2*4的8个格子
0 1 2 3
4 5 6 7
是最最初的状?
0代表?里没有放?牌，其他数字表示放了相?数字的?牌。
?可以?行如下操作：移?0周?的?牌到0，然后移?后，被移?的那个位置就没有?牌了。
?入??束的?个?牌的位置
比如：
1 0 2 3 4 5 6 7
1 0 2 3
4 5 6 7
只需要把1移?到0的位置，???1最少，?出此最少??。
*/

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  cin >> s;
  if (s == 'A') {
  	cout << "T" << endl;
  }else if (s == 'C') {
  	cout << "G" << endl;
  }else if (s == 'G') {
  	cout << "C" << endl;
  }else {
  	cout << "A" << endl;
  }
  return 0;
}

Measured memory_bytes: 256