akhauriyash/Code-Regression huggingface dataset:
import math
EPS = 1e-10


class P2():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.norm2 = (self.x**2 + self.y**2)**0.5

    def __add__(self, other):
        return P2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return P2(self.x - other.x, self.y - other.y)

    def smul(self, a):
        return P2(self.x * a, self.y * a)

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    def det(self, other):
        return self.x * other.y - self.y * other.x

    def rot90(self):
        return P2(-self.y, self.x)


def sgn(a: float):
    if a < -EPS:
        return -1
    elif a > EPS:
        return 1
    else:
        return 0


def simple_ccw(a, b, c):
    # Simple Counterclockwise test
    return sgn((b - a).det(c - a))


class Line():
    def __init__(self, dir: P2, b: P2):
        self.dir = dir
        self.b = b

    def crosspoint(self, other):
        b = other.b - self.b
        c = self.dir.det(other.dir)
        if sgn(c) == 0:
            # 2つの直線が平行だったら以下を返す
            return False, None
        a = -other.dir.rot90().dot(b) / c
        return True, self.dir.smul(a) + self.b


def gaisin(p1, p2, p3):
    l1 = Line((p2 - p1).rot90(), (p2 + p1).smul(0.5))
    l2 = Line((p3 - p1).rot90(), (p3 + p1).smul(0.5))
    return l1.crosspoint(l2)  # (bool, P2)


# l1 = Line(P2(2, 1), P2(0, 0))
# l2 = Line(P2(1, 1), P2(0, 1))
# is_exist, cp = l1.crosspoint(l2)
# print(is_exist, (cp.x, cp.y) if is_exist else "None")
# is_exist, cp = l2.crosspoint(l1)
# print(is_exist, (cp.x, cp.y) if is_exist else "None")

n = int(input())
p = [P2(*map(int, input().split())) for _ in range(n)]

cand = []
for i in range(n):
    for j in range(i + 1, n):
        # 中点
        cand.append((p[i] + p[j]).smul(0.5))
        for k in range(j + 1, n):
            # 3点の外心
            is_exist, cp = gaisin(p[i], p[j], p[k])
            if is_exist:
                cand.append(cp)

ans = 1000
for cp in cand:
    r_cand = max((pi - cp).norm2 for pi in p)
    ans = min(r_cand, ans)

print(ans)


Measured memory_bytes: 71128
#include <stdio.h>
#include <string.h>
int main(){
	char s[10];
	char a[10]="Sunny",b[10]="Cloudy",c[10]="Rainy";
	scanf("%s",s);
	if(strcmp(s,a)==0)printf("Cloudy\n");
	else if(strcmp(s,b)==0)printf("Rainy\n");
	else printf("Sunny\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int
main(void)
{
	int i, h, w;
	char str1[301];
	char str2[301];

	for (;;) {
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0)
			break;

		for (i = 0; i < w; i++) {
			str1[i] = '#', str2[i] = '.';
		}
		str2[0] = '#';
		str2[i - 1] = '#';
		str1[i] = '\0';
		str2[i] = '\0';

		puts(str1);
		for (i = 1; i < h - 1; i++)
			puts(str2);
		puts(str1);

		printf("\n");

	}

	return 0;
}



Measured memory_bytes: 2028
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#pragma warning( disable:4996 )
using namespace std;
typedef long long ll;
typedef long long Int;
#define MOD 1000000007

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a == b && a!=c) || (b == c && a!=c) || (c == a && a!=b)) {
		printf("Yes\n");
		
	}
	else {
		printf("No\n");
	}*/

	int n;
	int a[101];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)) {
			printf("DENIED\n");
			return 0;
		}
	}
	printf("APPROVED\n");
	return 0;
}

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

using namespace std;

const int N = 3e3 + 5;

vector <int> g[N];
int n, a[N], ans[N];
bool visited[N];

void dfs (int u) {
    ans[u] = 0;
    visited[u] = true;

    for (int v: g[u]) {
        if (a[v] >= a[u]) continue;
        if (!visited[v]) dfs(v);
        if (ans[v]) ans[u] = 1; //if there exist an adjacent vertex have lose state then current vertex have win state. Change ans[u] = 1 then simply apply ans[u] = 1 - ans[u] after.
    }

    ans[u] = 1 - ans[u];
}

void input(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }

    memset(visited, 0, sizeof(visited));
}

void solve(){
    for (int i = 1; i <= n; i++) if (!visited[i]) dfs(i);
    for (int i = 1; i <= n; i++) if (!ans[i]) printf("%d ", i);
}

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
#define double float
typedef pair<double,double>P;
 
int x[5000],y[5000];
int main(){
    int n,K;cin>>n>>K;
    rep(i,n){
        scanf("%d%d",&x[i],&y[i]);
    }
    vector<P>v;
    map<double,int>mpx;//x=a
    int cnt=K*(K-1)/2;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(x[i]==x[j]){
                mpx[x[i]]++;
            }
            else{
                double m=(y[i]-y[j])/(double)(x[i]-x[j]);
                v.push_back({m,-m*x[i]+y[i]});
            }
        }
    }
    sort(v.begin(),v.end());
    P prv={-1e9,-1e9};
    int c=0;
    rep(i,v.size()){
		if(prv!=v[i]){
			prv=v[i];
			c=1;
		}
		else c++;
		if(c>=cnt){
			puts("1");return 0;
		}
	}
    for(auto p:mpx){
        if(p.second>=cnt){
            puts("1");return 0;
        }
    }
    puts("0");
}


Measured memory_bytes: 68624
// https://atcoder.jp/contests/abc061/tasks/abc061_d
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

template <typename T> struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

// https://ei1333.github.io/luzhiled/snippets/graph/bellman-ford.html
template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(V, INF);
    dist[s] = 0;
    for (int i = 0; i < V; i++) {
        for (auto &e : edges) {
            if (dist[e.src] == INF)
                continue;
            if (dist[e.to] > dist[e.src] + e.cost) {
                dist[e.to] = dist[e.src] + e.cost;
                // n回目の経路長の更新で、頂点nが更新されたら
                // スコアに関わる閉路があると判断
                // 例えば最短経路を求める際に負の閉路を含む場合、
                // 閉路をループすれば距離が短くなり、答えが確定しない
                // コストを-1倍すれば最長経路を求めることができる
                if (i == V - 1 && e.to == V - 1) {
                    return vector<T>();
                }
            }
        }
    }
    // 負閉路を検出するロジックだが不要
    // for (auto &e : edges) {
    //     if (dist[e.src] == INF)
    //         continue;
    //     if (dist[e.src] + e.cost < dist[e.to])
    //         return vector<T>();
    // }
    return dist;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    Edges<ll> es;
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        // スコアの最大化のため、スコアは-1倍して最小化する
        es.emplace_back(a - 1, b - 1, -c);
    }
    auto dists = bellman_ford(es, N, 0);
    if (dists.size() == 0) {
        cout << "inf\n";
    } else {
        cout << -dists.back() << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;


int main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout << min(A,B) <<" ";
    cout << max(A+B-N,0)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
#define debug(x) cerr << #x << "=" << x << endl;
#define lgx cerr << "-----------" << endl;

const int CMax = 100002;
 
int X, W, Y, Z, n, A[CMax], B[CMax], ats;

int main() {
    while(~scanf("%d %d %d", &n, &Y, &Z)) {
 
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
 
    Y = A[n-1];
    ats = abs(Y - Z);
 
    if (n > 1) X = A[n-2];
    for (int i = n-2; i >= 0; i--) {
        if (abs(A[i] - Y) > ats && abs(A[i] - Y) <= abs(X - Y)) {
            ats = abs(A[i] - Y);
            X = A[i];
        }
    }
 
    printf("%d\n", ats);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int A,B,C,D,P;
scanf("%d %d %d %d %d",&A,&B,&C,&D,&P);
A=P*A;
if(C<P){
C=P-C;
D=D*C;
B=B+D;
}
if(A<B){
printf("%d\n",A);
}else if(B<=A){
printf("%d\n",B);
}
return(0);
}


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

int main(void){

    int N;
    cin>>N;
    vector<long> A(N+1),B(N+1);

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


    long sum=0, nokori=0, nokori_teki=0,tmp=0;
    for (int i = 0; i < N+1; ++i) {
        //前の残りで全て倒せるとき
        if(nokori >= A[i]){
            sum += A[i];
            nokori = B[i];
        }//前の残りと今ので倒せるとき
        else if(B[i]+nokori >= A[i]){
            sum += A[i];
            nokori = B[i]+nokori - A[i];
        }//倒しきれないとき
        else{
            sum += nokori + B[i];
            nokori = 0;
        }

    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int to[1010];
int main()
{
	int k,n;
	scanf("%d",&k);
	if(k==1)
	{
		printf("1\n1\n");
		return 0;
	}
	n=(k+3)/4*2;
	for(int i=0;i<n+n;i++)
		if(i+1<=k)
			to[i]=i+1;
		else
			to[i]=i+1-n;
	printf("%d\n",n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			printf("%d ",to[(i+j)%n+(i&1)*n]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count = 0;
    for (int i = 0; i < S.length() - 2; i++)
    {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int H, W;
  cin >> H >> W;

  vector<string> A(H);
  vector<string> B(H);
  REP(i, H){
    cin >> A[i];
    B[i] = A[i];
  }
  
  REP(i,H){
    int flag = 0;
    REP(j,W){
      if(A.at(i).at(j)!='.'){
        flag = 1;
      }
    }
    if(flag == 0){
      REP(j,W){
        B.at(i).at(j) = '0';
      }
    }
  }

  REP(j,W){
    int flag = 0;
    REP(i,H){
      if(A.at(i).at(j)!='.'){
        flag = 1;
      }
    }
    if(flag == 0){
      REP(i,H){
        B.at(i).at(j) = '0';
      }
    }
  }

  REP(i,H){
    int flag = 0;
    REP(j,W){
      if(B.at(i).at(j) == '0'){
        continue;
      }
      cout << B.at(i).at(j);
      flag = 1;
    }
    if(flag == 1){
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
//#include<string>

using namespace std;

int main(void){
  int max_diff=-2000000000;
//  int max=-1000000000;
  int min=1000000000;

  int num,loop;
  cin>>loop;
  for(int i=0;i<loop;i++){
    cin>>num;
    if(i!=0){
      if((num-min)>max_diff) max_diff=num-min;
    }
    if(min>num){
      min=num;
    }
  }
  cout<<max_diff<<endl;
  return 0;

}



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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> s(n+1);
    ll ans=0;
    rep(i,n){
        int j = 1;
        while((i+1)*j<=n){
            s[(i+1)*j]++;
            j++;
        }
        ans += (i+1) * s[i+1];
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 81316
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N,T = inm()
min_cost = 2000

for i in range(N):
    c,t = inm()
    if t <= T:
        min_cost = min(min_cost,c)

if min_cost == 2000:
    print("TLE")
else:
    print(min_cost)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    string s;
    cin >> s;
    if(s[0] != s[1] && s[1] != s[2] && s[2] != s[0]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3604
#include <stdio.h>


int main(void){
    int a, b;
    char op;

    scanf("%d %c %d", &a, &op, &b);
    while(op != '?'){
        switch(op){
        case '+':
            printf("%d\n", a+b);
            break;
        case '-':
            printf("%d\n", a-b);
            break;
        case '*':
            printf("%d\n", a*b);
            break;
        case '/':
            printf("%d\n", a/b);
            break;
        }
        scanf("%d %c %d", &a, &op, &b);
    }
    return 0;
}

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

using namespace std;
using ull = unsigned long long;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        string s = to_string(i);
        int n = 0;
        for (char c : s) {
            n += c - '0';
        }
        if (A <= n && n <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 380
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())

A = inpl()
B = A[:]

# 累積和
for i in range(1, N):
    B[i] = B[i] + B[i - 1]

ans = INF
mid_l = 0
mid_r = 2
t = B[-1]
for mid in range(1, N - 1):
    while mid_l < mid and abs(2 * B[mid_l] - B[mid]) >= abs(2 * B[mid_l + 1] - B[mid]):
        mid_l += 1
    while mid_r < N - 1 and abs(2 * B[mid_r] - B[mid] - t) >= abs(2 * B[mid_r + 1] - B[mid] - t):
        mid_r += 1

    p = B[mid_l]
    q = B[mid] - p
    r = B[mid_r] - p - q
    s = t - r - p - q

    ans = min(ans, max(p, q, r, s) - min(p, q, r, s))

print(ans)

Measured memory_bytes: 25676
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N = int(input().strip())
    V = map(int, input().strip().split())
    return N, V
    

def solve(N, V):
    V = list(sorted(V))
    ans = V[0]
    for v in V:
        ans = (ans + v) / 2
    return ans


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int h,m,s,is;
	scanf("%d",&is);
	
	h=is/3600;
	m=(is-3600*h)/60;
	s=is-3600*h-60*m;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}

Measured memory_bytes: 592
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		// ll a[n];
		c=n*n;
		cout<<c;

		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>

std::vector<int> edge[300000];

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    edge[a * 3    ].emplace_back(b * 3 + 1);
    edge[a * 3 + 1].emplace_back(b * 3 + 2);
    edge[a * 3 + 2].emplace_back(b * 3);
  }
  int s, t;
  scanf("%d%d", &s, &t);
  --s, --t;

  long long dist[300000];
  std::fill(dist, dist + 3 * n, 1e18);
  dist[s * 3] = 0;
  using pair = std::pair<long long, int>;
  std::priority_queue<pair, std::vector<pair>, std::greater<pair>> q;
  q.emplace(0, s * 3);
  while (q.size() > 0)
  {
    auto p = q.top(); q.pop();
    if (dist[p.second] < p.first) continue;
    for (const auto e : edge[p.second])
    {
      if (dist[e] > p.first + 1)
      {
        dist[e] = p.first + 1;
        q.emplace(p.first + 1, e);
      }
    }
  }
  printf("%lld\n", dist[t * 3] == 1e18 ? -1 : dist[t * 3] / 3);
  return 0;
}

Measured memory_bytes: 18944
#include <stdio.h>
#include <math.h>

int main()
{
    int a, b, c, t;
    scanf("%d %d %d",&a,&b,&c);
    if (a>b)
    {
        t = a;
        a = b;
        b = t;
    }
    if (b>c)
    {
        t = b;
        b = c;
        c = t;
    }
    if (a>b)
    {
        t = a;
        a = b;
        b = t;
    }
    printf("%d\n",a + b);
    return 0;
}


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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



// // 二分探索(最小値を出す問題は疑う)
// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < N; ++i){
// 		res += max(0ll, A[i]-x/F[i]);
//     }
//     return res <= K;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }

int main(){
 int N;
 cin >> N;
 vector<int> A(N);
 REP(i, N) cin >> A.at(i);
  int cnt = 0;
 REP(i, N) if(A.at(i) % 2 == 1) cnt++;

 if(cnt % 2 == 0) YES;
 else NO;

}


Measured memory_bytes: 640
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long  
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	int n;
 	cin>>n;
 		set<string>st;
 	while(n--)
 	{
 		string s;
 		cin>>s;
 		st.insert(s);
	 }
	 cout<<st.size();
 
}

Measured memory_bytes: 19288
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
  if a[i] >= b[i]:
    c += b[i]
  else:
    d = b[i] -a[i]
    if a[i+1] <= d:
      c += a[i] + a[i+1]
      a[i+1] = 0
    else:
      a[i+1] -= d
      c += b[i]
print(c)

Measured memory_bytes: 18624
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	vector<pair< ld, int>>rests;
	cout << fixed << setprecision(2);
	for (int i = 0; i < 3; ++i) {
		vector<pair< ld,int>>ps;
		for (int j = 0; j < 8; ++j) {
			int a; ld b; cin >> a >> b;
			ps.emplace_back(b, a);
		}
		sort(ps.begin(), ps.end());
		for (int j = 0; j < 2; ++j) {
			
			cout << ps[j].second << " " << ps[j].first << endl;
		}
		for (int j = 2; j < 4; ++j) {
			rests.emplace_back(ps[j]);
		}
	}
	sort(rests.begin(), rests.end());
	for (int i = 0; i < 2; ++i) {
		cout << rests[i].second << " " << rests[i].first << endl;
	}
	return 0;
}

Measured memory_bytes: 3228
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N;
    ulong K;
    scan(N, K);
    auto A = aryread!ulong();
    auto dp = new ulong[][](2, 61);

    foreach_reverse (i; 0 .. 60)
    {
        ulong[2] cnt;
        foreach (j; 0 .. N)
        {
            cnt[0] += A[j] & (1UL << i);
            cnt[1] += (A[j] & (1UL << i)) ^ (1UL << i);
        }

        if (K & (1UL << i))
        {
            dp[0][i] = dp[0][i + 1] + cnt[1];
            dp[1][i] = dp[0][i + 1] + cnt[0];
            if (dp[1][i + 1])
                dp[1][i] = dp[1][i].max(dp[1][i + 1] + cnt[1], dp[1][i + 1] + cnt[0],);
        }
        else
        {
            dp[0][i] = dp[0][i + 1] + cnt[0];
            if (dp[1][i + 1])
                dp[1][i] = max(dp[1][i + 1] + cnt[1], dp[1][i + 1] + cnt[0]);
        }
    }
    // writeln(dp[0]);
    // writeln(dp[1]);
    max(dp[0][0], dp[1][0]).writeln();
}


Measured memory_bytes: 4860
import sys
size = int(sys.stdin.readline())
for i in range(size):
    line = sys.stdin.readline()
    line = line.split(" ")
    inp = []
    for j in line:
        inp.append(int(j))
    inp.sort()
    if (inp[0]**2+inp[1]**2==inp[2]**2):
        print("YES")
    else:
        print("NO")

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

string s, t;
int n, ans, m;
vector<int> s0, t0;

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

	if (s == t) {
		cout << "0\n";
		return 0;
	}

	int ptr = n-1;
	for (int i = n-1; i >= 0; --i) {
		if (i > 0 && t[i] == t[i-1])
			continue;
		t0.push_back(i);
		if (ptr > i)
			ptr = i;
		while (ptr >= 0 && s[ptr] != t[i])
			ptr--;
		if (ptr == -1)
			continue;
		s0.push_back(ptr);
	}

	if (s0.size() != t0.size()) {
		cout << "-1\n";
		return 0;
	}

	reverse(s0.begin(), s0.end());
	reverse(t0.begin(), t0.end());
	m = s0.size();

	for (int i = 0; i < m; ++i) {
		if (s0[i] > t0[i]) {
			cout << "0\n";
			return 0;
		}
	}

	s0.push_back(n);
	ans = 0;

	for (int i = 0; i < m; ++i) {
		int lo = 0, hi = m-i;
		while (lo != hi) {
			int mid = (lo + hi)/2;
			if (s0[mid+i]-mid >= t0[i])
				hi = mid;
			else
				lo = mid+1;
		}

		ans = max(ans, lo);
	}

	cout << ans+1 << endl;
}

Measured memory_bytes: 12920
import sys

def Partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1, A


def Quicksort(A, p, r):
    if p < r:
        q, A = Partition(A, p, r)
        A = Quicksort(A, p, q-1)
        A = Quicksort(A, q+1, r)
    return A

n = int(sys.stdin.readline())
cards = []
for _ in range(n):
    s,t = sys.stdin.readline().split()
    cards.append([s, int(t)])

orig = cards[:]
Quicksort(cards, 0, n-1)
mm=[c[0] for c in cards]
nn=[c[1] for c in cards]
cc=[]
for k in nn:
    if k in cc: continue
    cc.append(k)
    if nn.count(k)<=1: continue
    a=[]
    b=[]
    for o in orig:
        if o[1]==k:  a.append(o[0])
    for p in cards:
        if p[1]==k:  b.append(p[0])
    if a!=b:
        print('Not stable')
        break
else:
    print('Stable')

for c in cards:
    print(c[0],c[1])


Measured memory_bytes: 20348
from collections import defaultdict
from math import sqrt

n, p = [int(i) for i in input().split()]

A = defaultdict(int)

def factorize(n):    
    i = 2
    
    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

factorize(p)
ans = 1
for k, v in A.items():
    if v >= n:
        ans *= k ** (v // n)

print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 2e5 + 5;

int n;
int a[N], b[N];
int xa[N], xb[N];
int fb[N];

void init() {
	fb[0] = 0;
	int l = 0;
	for (int i = 1; i < n; i++) {
		while (l > 0 && xb[i] != xb[l])
			l = fb[l - 1];
		if (xb[i] == xb[l])
			l++;
		fb[i] = l;
	}
}

void match() {
	int l = 0;
	for (int i = 0; i < n * 2 - 1; i++) {
		while (l > 0 && xb[l] != xa[i % n])
			l = fb[l - 1];
		if (xb[l] == xa[i % n])
			l++;
		if (l == n) {
			cout << i - n + 1 << " " << (a[i - n + 1] ^ b[0]) << "\n";
			l = fb[l - 1];
		}
	}

}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++) {
		xa[i] = a[i] ^ a[(i + 1) % n];
		xb[i] = b[i] ^ b[(i + 1) % n];
	}
	init();
	match();
	return 0;
}


Measured memory_bytes: 7424
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

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

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

int main(void) {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 1; i <= H; i++) {
			for (int i = 1; i <= W; i++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(void)
{
	int S, h, m, s;
	
	scanf("%d", &S);
	h = S/3600;
	m = (S-h*3600)/60;
	s = S-h*3600-m*60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll k, s;
  cin >> k >> s;
  
  ll res = 0;
  for (int i = 0; i <= k; i++){
    for (int j = 0; j <=k; j++){
      if (i + j <= s && s - i - j <= k){
        res++;
      }
    }
  }


  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int n, k; cin>>n>>k;

   if(n==1)
    cout<<1<<"\n";
    else 
        cout<<ceil(log(n)/log(k))<<"\n";


   














}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

int N;
int sum[3] = {0};

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        if(a % 4 == 0)sum[2]++;
        else if(a % 2 == 0)sum[1]++;
        else sum[0]++;
    }
    if(sum[1] + sum[2] == N)printf("Yes\n");
    else if(sum[0] <= sum[2])printf("Yes\n");
    else if(sum[0] == sum[2] + 1 && sum[0] + sum[2] == N)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

os = gets_nsp_list
es = gets_nsp_list

ans = []

while !os.empty? || !es.empty?
  ans.push os.shift
  ans.push es.shift
end

puts ans.join

Measured memory_bytes: 14572
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define X first
#define Y second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=1e9+7;
const ll MAXN=1e6+5;
const ll inf=1e18;

vector<bool > solved(MAXN,false);
vector<ll > cnt(MAXN,0);

int main()
{
    fastio;
    ll n,m;
    ll pen=0,c=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        ll a;
        string b;
        cin>>a;
        cin>>b;
        if(b=="AC" && solved[a]==false){
            pen+=cnt[a];
            c++;
            solved[a]=true;
        }else{
            cnt[a]++;
        }
    }
    cout<<c<<" "<<pen<<endl;
}


Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[9];
		for(int i = 0  ; i < N; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < 9 ; i++) {
			b[i] = 0;
		}
		for(int i = 0 ; i < N ; i++) {
			if(a[i] >= 1 && a[i] < 400) {
				b[0]++;
			} else if(a[i] >= 400 && a[i] < 800) {
				b[1]++;
			} else if(a[i] >= 800 && a[i] < 1200) {
				b[2]++;
			} else if(a[i] >= 1200 && a[i] < 1600) {
				b[3]++;
			} else if(a[i] >= 1600 && a[i] < 2000) {
				b[4]++;
			} else if(a[i] >= 2000 && a[i] < 2400) {
				b[5]++;
			} else if(a[i] >= 2400 && a[i] < 2800) {
				b[6]++;
			} else if(a[i] >= 2800 && a[i] < 3200) {
				b[7]++;
			} else {
				b[8]++;
			}
		}
		int max = 0, min = 0;
		for(int i = 0 ; i < 8 ; i++) {
			if(b[i] >= 1) {
				min++;
				max++;
			}
		}
		max += b[8];
		if(min == 0 && b[8] >= 1) {
			min++;
		}
		System.out.println(min + " " + max);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

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

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

    factorial_Initialize(1e6);

    // cumulative sum
    vector<long long int> prob(n+1);
    for(int i=0; i<n; i++){
        prob[i+1] = prob[i] + inverse[i+1];
        prob[i+1] %= MOD;
    }

    long long int ans = 0;
    for(int i=0; i<n-1; i++){
        ans += (x[i+1] - x[i]) * prob[i+1];
        ans %= MOD;
    }
  
    ans *= f[n-1];
    ans = (ans % MOD + MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35196
from fractions import gcd

def NK():
    return map(int,input().split())

def main():
    n,k = NK()
    ans = 0
    for i in range(1,n+1):
        ans += (n//i)*max((i-k),0) + max(n%i-max((k-1),0),0)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 65004
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

int gcd(ll a,ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b){
  return a * b / gcd(a, b);
}

using namespace std;
int main() {
  ll A,B;
  cin >> A >>B;
  cout << lcm(A,B);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,Y; cin >> n >> Y;
    int a,b,i,j,z,flag=0;
    Y = Y/1000;
    for(i=0; i<=n; i++){
        if (flag==1) break;
        for (j=0; j<=n-i; j++){
            z = n - i - j;
            if (z==(Y-10*i-5*j)) {flag=1; break;}
        }
    }
    if (flag==1) cout << i-1 << " " << j << " " << z << endl;
    else cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
// AOJ ALDS1_13_B 8 Puzzle
// 2018.5.8 bal4u

#include <stdio.h>

typedef unsigned char uchar;

#define HASHSIZ 543217
typedef struct { unsigned s; char x, v; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(unsigned s, int x)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) return hp->v;
		if (++hp == hashend) hp = hash;
	}
	return 0;
}

void insert(unsigned s, int x, char v)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) { hp->v = v; break; }
		if (++hp == hashend) hp = hash;
	}
	hp->s = s, hp->x = x, hp->v = v;
}

#define QMAX 50000
typedef struct { unsigned s; char x, v; } T;
T s[QMAX+3]; int top, end;
int hi[9] = {2,3,2,3,4,3,2,3,2};
int to[9][4] = {{1,3},{0,2,4},{1,5},{0,4,6},{1,3,5,7},{2,4,8},{3,7},{4,6,8},{5,7}};

void toArray(char *nine, unsigned s, int x)
{
	int i;
	
	for (i = 8; i >= 0; i--) {
		if (i == x) nine[i] = 0;
		else nine[i] = s & 0xf, s >>= 4;
	}
}

unsigned swap(char *nine, int zero, int nx)
{
	int i;
	unsigned res;
	
	res = 0;
	for (i = 0; i < 9; i++) {
		if      (i == zero) res <<= 4, res |= nine[nx];
		else if (i != nx)   res <<= 4, res |= nine[i];
	}
	return res;
}

#define MAGIC 20

int main()
{
	int i, x, nx, v, nv, t;
	unsigned a, na;
	unsigned gs; int gx;	// goal
	char nine[9];
	
	gs = 0; for (i = 0; i < 9; i++) {
		scanf("%d", &t);
		if (t == 0) gx = i;
		else gs <<= 4, gs |= t;
	}
	s[0].s = 0x12345678, s[0].x = 8;
	s[1].x = -1;
	top = 0, end = 2;
	insert(s[0].s, s[0].x, 0);
	v = 0;
	while (top != end) {
		a = s[top].s, x = s[top].x;
		if (++top == QMAX) top = 0; 
		if (x < 0) {
			if (v == MAGIC) break;
			v++;
			s[end].x = -1; if (++end == QMAX) end = 0;
			continue;
		}
		if (x == gx && a == gs) goto done;
		if (lookup(a, x) < v) continue;

		toArray(nine, a, x);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			na = swap(nine, x, nx), nv = v+1;
			t = lookup(na, nx);
			if (!t || nv < t) {
				s[end].s = na, s[end].x = nx;
				if (++end == QMAX) end = 0;
				insert(na, nx, nv);
			}
		}
	}

	s[0].s = gs, s[0].x = gx, s[1].x = -1;
	top = 0, end = 2;
	v = 0;
	while (top != end) {
		a = s[top].s, x = s[top].x;
		if (++top == QMAX) top = 0; 
		if (x < 0) {
			v++;
			s[end].x = -1; if (++end == QMAX) end = 0;
			continue;
		}
		if ((t = lookup(a, x)) > 0) { v += t; break; }

		toArray(nine, a, x);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			na = swap(nine, x, nx), nv = v+1;
			t = lookup(na, nx);
			if (!t || nv < t) {
				s[end].s = na, s[end].x = nx;
				if (++end == QMAX) end = 0;
			}
		}
	}
done:
	printf("%d\n", v);
	return 0;
}



Measured memory_bytes: 6484
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)




























int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n);
    REP(i, n){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    ll ans = 0;
    REP(i, k){
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll T(N);
  ll result = 0;
  REP(i, 0, N) {
    ll t;
    cin >> t;
    T[i] = t;
    if (i == 0) {
      result = t;
    } else {
      result = lcm(t, result);
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>

#define Maxn 200010
#define MOD 1000007
#define ULL unsigned long long

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n;

struct HashTable {
	int val[MOD + 2]; ULL id[MOD + 2];
	int ton(ULL x) {
		int now = x % MOD;
		while(id[now] != -1 && id[now] != x) {
			now += 107;
			if(now >= MOD) now -= MOD;
		}
		return now;
	}
	void insert(ULL pos, int v) {
		int now = ton(pos);  //if(id[now] != -1) return;
		id[now] = pos; val[now] = v;
	}
	int query(ULL pos) {
		int now = ton(pos);
		return val[now];
	}
	void reset() {
		memset(id, -1, sizeof(id));
		memset(val, 0, sizeof(val));
	}
}
Hash;

struct Node {
    int len, fap[27];
    string S;
}
node[Maxn];

int cmp(Node fir, Node sec) {
    return fir.len < sec.len;
}

int main() {
    n = read(); Hash.reset();
    for(int i = 1; i <= n; ++i) {
        cin >> node[i].S;
        node[i].len = node[i].S.length();
        for(int ch = 1; ch <= 26; ++ch) node[i].fap[ch] = node[i].len + 2;
        for(int k = 0; k < node[i].len; ++k) {
            int ch = node[i].S[k] - 'a' + 1;
            if(node[i].fap[ch] == node[i].len + 2) node[i].fap[ch] = k;
        }
    }
    sort(node + 1, node + n + 1, cmp);
    ULL ans = 0;
    for(int i = 1; i <= n; ++i) {
        // cout << node[i].S << " " << node[i].fap[0] << " " << node[i].fap[1] << endl;
        ULL has = 0;
        for(int k = node[i].len - 1; k >= 0; --k) {
            for(int ch = 1; ch <= 26; ++ch) {
                if(node[i].fap[ch] > k) continue;
                ULL newhas = has * 109 + ch;
                if(Hash.query(newhas)) ++ans;
            }
            has = has * 109 + node[i].S[k] - 'a' + 1;
        }
        has = 0;
        for(int k = node[i].len - 1; k >= 0; --k) has = has * 109 + node[i].S[k] - 'a' + 1;
        Hash.insert(has, 1);
        // cout << i << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 45220
#include<bits/stdc++.h>
#define ll long long
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int Maxn=50;
int a[Maxn],b[Maxn];
bool g[Maxn][Maxn];
bool v[Maxn];
int N,M;
void dfs(int vi)
{
    v[vi]=true;
    REP(i,N)
    {
        if(g[vi][i]==false) 
		{
			continue;
		}
        if(v[i]==true) 
		{
			continue;
		}
        dfs(i);
    }    
}
int main(void)
{
    cin>>N>>M;
    REP(i,M)
    {
        cin>>a[i]>>b[i];
        a[i]--;
		b[i]--;
        g[a[i]][b[i]]=true;
		g[b[i]][a[i]]=true;
    }
    int cnt=0;
    REP(i,M)
    {
        g[a[i]][b[i]]=false;
		g[b[i]][a[i]]=false;
        REP(j,N)
        {
            v[j]=false;
        }
        dfs(0);
        bool check=false;
        REP(j,N)
        {
            if(v[j]==false) 
			{
				check=true;
			}
        }
        if(check) 
		{
			cnt++;
		}
        g[a[i]][b[i]]=true;
		g[b[i]][a[i]]=true;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, k;

	while(scanf("%d%d", &n, &k)==2)
	{
		vi a(n);
		vvi f(n+1), b(n+1);

		for(int i=0;i<n;i++) scanf("%d", &a[i]);

		for(int i=0;i<=n;i++)
		{
			f[i].resize(k);
			b[i].resize(k);
			b[i][0]=f[i][0]=1;
		}

		for(int i=0;i<n;i++)
		{
			f[i+1]=f[i];
			for(int j=0;j+a[i]<k;j++)
			{
				if(!f[i][j]) continue;
				f[i+1][j+a[i]]=1;
			}
		}

		for(int i=n;i>0;i--)
		{
			b[i-1]=b[i];
			for(int j=0;j+a[i-1]<k;j++)
			{
				if(!b[i][j]) continue;
				b[i-1][j+a[i-1]]=1;
			}
		}

		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<k;j++)
			{
				if(b[i][j]) b[i][j]=j;
				else b[i][j]=b[i][j-1];
			}
		}

		int ans=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<k;j++)
			{
				if(!f[i][j]) continue;

				if(j+b[i+1][k-1-j]+a[i]>=k)
				{
					ans++;
					break;
				}
			}
		}
/*
printf("----- f -----\n");
for(auto e:f)
{
	for(auto ee:e) printf("%2d ", ee);
	printf("\n");
}
printf("----- b -----\n");
for(auto e:b)
{
	for(auto ee:e) printf("%2d ", ee);
	printf("\n");
}
*/
		printf("%d\n", n-ans);
	}

	return 0;
}


Measured memory_bytes: 195968
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int MAX_NUM = 100000000;
vector<bool> ps(MAX_NUM + 1, true);

int main() {
    ps[0] = ps[1] = false;
    for (int i = 4; i <= MAX_NUM; i += 2) {
        ps[i] = false;
    }
    for (int i = 3; i + i <= MAX_NUM; i += 2) {
        if (!ps[i]) {
            continue;
        }
        for (int j = i + i; j <= MAX_NUM; j += i) {
            ps[j] = false;
        }
    }

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        if (ps[k]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13332
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<numeric>

using namespace std;

int main() {
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    S[K-1]=S[K-1]+32;
    cout<<S<<endl;
    return 0;
}

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

class Main {

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        
        int a = sc.nextInt();
        String s = sc.next();

        if(a>=3200){
            System.out.println(s);
        }
        else{
            System.out.println("red");
        }

    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21076