akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  bool z = false;
  rep(i,n){
    cin >> a[i];
    z |= (a[i]==0);
  }
  if(z){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  rep(i,n){
    if(1e18L/ans<a[i]){
      ans = -1; break;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3960
import java.util.*;

public class Main {

    private int N;
    private int[] A;

    public void inputData() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = new int[N+2];
        for (int i = 1; i <= N; i++) {
            A[i] = sc.nextInt();
        }
    }

    public void printAnswer() {
        int dist = 0;
        for (int i = 1; i < N+2; i++) {
            dist += Math.abs(A[i] - A[i-1]);
        }
        for (int i = 1; i <= N; i++) {
            System.out.println(dist - (Math.abs(A[i-1] - A[i]) + Math.abs(A[i] - A[i+1])) + Math.abs(A[i-1] - A[i+1]));
        }
    }

    public void run() {
        inputData();
        printAnswer();
    }

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

}


Measured memory_bytes: 65752
import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;
 
long count;
 
void main()
{
    long[] memo;
    long func(long n)
    {
        if(memo[n] != -1)
        {
            return memo[n];
        }
        memo[n] = func(n-1) + func(n-2);
        return memo[n];
    }
    long N = readln().strip.to!long;
    memo.length = N+1;
    memo[] = -1;
    memo[0] = 1;
    memo[1] = 1;
    writeln(format("%d", func(N)));
}
 


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

int main(void){
	int n;
	int box=0,sum=0;
	int a[100002];
	int d[100001];
	a[0] = 0;
	scanf("%d",&n);
	a[n+1] = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		d[i-1] = abs(a[i] - a[i-1]); 
	}
	d[n] = abs(a[n+1] - a[n]);
	for(int i=0;i<=n;i++)sum += d[i];
	for(int tag =1;tag<=n;tag++){
		box = sum;
		box -= d[tag-1];
		box -= d[tag];
		box += abs(a[tag+1]-a[tag-1]);
		printf("%d\n",box);
	}
	return 0;
}

Measured memory_bytes: 1920
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=5e5+5;
const ll MOD=1e9+7;

ll sum(ll a, ll b){
	ll ans = a+b+MOD;
	while(ans>=MOD) ans-=MOD;
	return ans;
}

ll mul(ll a, ll b){
	return (a*b)%MOD;
}

ll f[N], invf[N];

ll binpow(ll a, ll p){
	if(p==0) return 1;
	ll cur = binpow(a,p>>1);
	cur = mul(cur,cur);
	if(p&1) cur = mul(cur,a);
	return cur;
}

ll inv(ll x){
	return binpow(x, MOD-2);
}

void prec(){
	f[0]=1;
	invf[0]=1;
	For(i,1,N){
		f[i] = mul(i,f[i-1]);
		invf[i] = inv(f[i]);
	}
}

inline ll perm(ll a, ll b){
	return mul(f[a],invf[a-b]);
}

inline ll comb(ll a, ll b){
	return mul(f[a],mul(invf[b],invf[a-b]));
}

int main(){
	fastio;
	prec();
	int n, m; cin>>n>>m;
	ll ans = perm(m,n);
	ll other = 0;
	For(i,0,n+1){
		other = sum(other, (i&1? -1:1)*mul(comb(n,i),perm(m-i,n-i)));
	}
	cout << mul(ans,other) << endl;
	return 0;
}



Measured memory_bytes: 11420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,mod=1e9+7;
string s;
ll dp[N][2],n;
ll func(ll idx,ll flg){
    if(idx==n)return 1;
    if(dp[idx][flg]!=-1)return dp[idx][flg];
    ll &ans = dp[idx][flg];
    if(flg==0){
        if(s[idx]=='0')ans=func(idx+1,0);
        else ans = func(idx+1,1) + (2ll*func(idx+1,0))%mod;
    }
    else ans = 3ll*func(idx+1,1);
    ans%=mod;
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>s;n=s.size();
    cout<<func(0,0);
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll r;
  cin >> r;
  cout << 3 * r * r;
  return 0;
}

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

using namespace std;

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

ll mod = 1e9 + 7;

bool isok(ll a,ll b,ll t,ll x){
	ll d = to_string(t).length();
	ll tmp = a*t + b*d;
	return (tmp<=x);
}


int main(){
	string s;
	cin >> s;

	int l = s.length();
	int ans = 0;
	for(int i=0;i<l/2;i++){
		if(s[i]!=s[l-1-i]) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a=0;
int b[100];
int s=0;
int c=0;
int d=0;
int ss=0;
for(int i=0;i<100;i++){
b[i]=0;
}
scanf("%d",&a);
for(int i=0;i<a;i++){
scanf("%d",&b[i]);
s=s+b[i];

}

d=s%a;
c=s/a;

if(d>(a/2)){
c++;
}
for(int i=0;i<a;i++){
int j=b[i]-c;
ss=j*j+ss;
}
printf("%d",ss);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m=1e9+7,i;long long ans=1;cin>>n;
    vector<int> a(n),c(n+1,0);
    for(i=0;i<n;i++){cin>>a[i],++a[i];}
    c[0]=3;
    for(int x:a)(ans*=c[x-1]-c[x])%=m,++c[x];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4052
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean a[] = new boolean[n+10];
        for (int i = 0; i < m; i++) {
            a[sc.nextInt()] = true;
        }
        final long MOD = 1000000007L;
        long dp[] = new long[n+10];
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            if(a[i]) {
                dp[i] = 0;
            } else {
                dp[i] = dp[i-1];
                if(i> 1) dp[i] += dp[i-2];
                dp[i] %= MOD;
            }
        }
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 50568
#include<stdio.h>
int gcd(int a, int b)
{
    int i = 0;
    int r = a % b;
    while (r > 0)
    {
        a = b;
        b = r;
        r = a % b;
        i++;
    }
    return b;
}
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int i;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int max = 0;
    for (i = 0; i < n; i++)
        if (max < a[i])
            max = a[i];
    if (k > max)
    {
        printf("IMPOSSIBLE\n");
        return 0;
    }
    int g = a[0];
    for (i = 0; i < n; i++) {
        g = gcd(g, a[i]);
    }
    if (k%g == 0)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
//#include<iostream>
#define INT_MAX 2000000000
#define MAX 200000
typedef long long llong;
//using namespace std;
llong cnt = 0;
int L[MAX/2 + 2], R[MAX/2 + 2];
void Merge(int A[], int left, int mid, int right)
{
  int n1, n2;
  n1 = mid - left;
  n2 = right - mid;
  L[n1] = R[n2] = INT_MAX;
  for(int i=0; i<n1; i++)
    L[i] = A[left+i];
  for(int i=0; i<n2; i++)
    R[i] = A[mid+i];
  int i, j;
  i = j = 0;
  for(int k=left; k<right; k++)
  {
    if(L[i] <= R[j])
      A[k] = L[i++];
    else
    {
      A[k] = R[j++];
      cnt+= n1 - i;
    }
  }
}

void mergeSort(int A[], int left, int right)
{
  if(left + 1 < right)
  {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}
int main()
{
  int A[MAX], n;
  scanf("%d", &n);
  for(int i=0; i<n; i++)
    scanf("%d", &A[i]);
  mergeSort(A, 0, n);
  printf("%lld\n", cnt);

  return 0;
}



Measured memory_bytes: 4328
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
#define ll signed long long

int main() {
  ll X;
  cin >> X;

  ll ans = 0;
  ans += (X / 500) * 1000;
  ans += ((X % 500) / 5) * 5;
  cout << ans << endl;
  return 0;
}


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

const int N = 4e5 + 10, H = 505;
int n, h, deg[N];
bool tag, vis[N], mark[N];
vector<int> nxt[N];

void add(int x, int y) {
    x += H, y += H;
    mark[x] = mark[y] = 1;
    nxt[x].push_back(y);
    nxt[y].push_back(x);
    ++deg[y], --deg[x];
}

bool dfs(int x) {
    if ((x >= H && deg[x] > 0) || (x < H && deg[x] < 0)) return 0;
    vis[x] = 1;
    if (deg[x]) tag = 1;
    for (int i = 0; i < nxt[x].size(); i++) {
        int y = nxt[x][i];
        if (!vis[y]) if (!dfs(y)) return 0;
    }
    return 1;
}

int main() {
    cin >> n >> h;
    rep(i, 1, n) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        add(c ? -c : a, d ? d : -b);
    }
    rep(i, 1, H << 1) if (mark[i] && !vis[i]) {
        tag = 0;
        if (!dfs(i) || !tag) return puts("NO"), 0;
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 14452
N,K=map(int,input().split())
A=[int(i)-1 for i in input().split()]
def times(X,Y):
    return [X[Y[i]] for i in range(N)]
def exponen(X,n):
    if n==0:
        return [i for i in range(N)]
    if n==1:
        return X
    if n%2==0:
        Y=exponen(X,n//2)
        return times(Y,Y)
    if n%2==1:
        Y=exponen(X,n//2)
        return times(times(Y,Y),X)
B=exponen(A,K)
print(B[0]+1)


Measured memory_bytes: 244224
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

if max((b-a),(c-a),(d-a),(e-a),(c-b),(d-b),(e-b),(d-c),(e-c),(e-d)) > k:
  print(":(")
else:
  print("Yay!")


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(D: int, N: int):
    if N == 100:
        print((N + 1)* 100**D)
    else:
        print((100**D)*N)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(D, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll w[105],v[105],dp[105][100005];

ll solve(ll n,ll W)
{
    if(n==0 || W==0)
        return 0;
    if(dp[n-1][W]!=-1)
        return dp[n-1][W];
    if(w[n-1]>W)
        return dp[n-1][W]=solve(n-1,W);
    return dp[n-1][W]=max(solve(n-1,W),v[n-1]+solve(n-1,W-w[n-1]));
}

int main()
{
    ll W,n,i;
    cin>>n>>W;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    cout<<solve(n,W)<<endl;
}

Measured memory_bytes: 82304
#include <iostream>
using namespace std;
int main(){
  int k, a, b;
  cin >> k >> a >> b;
  bool hatena = false;
  for (int i = a; i < b + 1; i++)
  {
    if (i % k == 0){
      hatena = true;
      break;
    }
  }
  if (hatena){
    cout << "OK";
  } else{
    cout << "NG";
  }
  cout << endl;
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;  
public class Main {	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N=Integer.parseInt(st.nextToken()); int W=Integer.parseInt(st.nextToken());
		int[] val= new int[N]; int[] weight= new int[N]; long[][]memo= new long[N+1][W+1];
		for (int i = 0; i < N; i++) {
			st = new StringTokenizer(br.readLine());
			weight[i]=Integer.parseInt(st.nextToken());val[i]=Integer.parseInt(st.nextToken());
		}
		for (int i = N-1; i >= 0; i--) {
			for (int j = 0; j <= W; j++) {
				memo[i][j]=Math.max(j-weight[i]<0?Integer.MIN_VALUE:val[i]+memo[i+1][j-weight[i]], memo[i+1][j]);
			}
		}
		pw.print(memo[0][W]);
		pw.close();
	}
}

Measured memory_bytes: 130664
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
int ans=0;
rep(i,n){
    cin>>a[i];
    if(i>0){
        if(a[i]==a[i-1]){
            a[i]=101+ans;
            ans++;
        }
    }
}
cout<<ans<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ut,VI> PQ;
const int SIZE=2*1e5;
const LL INF=1LL<<60;
const LL p=7+1e9;
LL N,K,A[SIZE];
LL B[SIZE];
LL dist[SIZE];
LL solve(){
	LL ans=0;
	cin >> N >> K;
	FOR(i,1,N+1){
		cin >> A[i];
		B[A[i]]++;
	}
	queue<LL> qu;
	FOR(i,1,N+1){
		dist[i]=INF;
		if(B[i]==0){
			dist[i]=0;
			qu.push(i);
		}
		else if(A[i]==0){
			dist[i]=0;
			ans++;
		}
	}
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
		ans++;

		if(dist[A[now]]==INF){
			dist[A[now]]=dist[now]+1;
			if(dist[A[now]]<K)
				qu.push(A[now]);
		}
	}
	return ans;
}
int main(){
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 5788
import java.text.*;
import java.math.*;
import java.util.*;

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

		while(true) {
			num[0] = scan.nextInt();
			num[1] = scan.nextInt();
			if(num[0] == 0) break;
			for(int i1 = 0; i1 < num[0];i1++) {
				for(int i2 = 0;i2 < num[1];i2++) {
					if(i1 == 0 | i1 == num[0]-1) {
						System.out.print("#");
					}else if(i2 == 0|i2 == num[1]-1) {
						System.out.print("#");
					}else System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
		
	}
}

Measured memory_bytes: 24756
#include <cstdio>
#include <cstring>
using namespace std;
int square[15][15];
int main(){
	int n,x,y,count;
	while(scanf("%d",&n)){
		count = 1;
		if(!n) break;
		memset(square,0,sizeof(square));
		x = y = n / 2;
		++y;
		square[y][x] = count++;
		while(count <= (n * n)){
			++x;
			++y;
			if(y >= n) y = 0;
			if(x >= n) x = 0;
			if(x < 0) x = n - 1;
			if(y < 0) y = n - 1;
			if(square[y][x] == 0) 
				square[y][x] = count;
			else {
				--x;
				++y;
				while(x < 0 || n <= x || y < 0 || n <= y){
					if(y >= n) y = 0;
					if(x >= n) x = 0;
					if(x < 0) x = n - 1;
					if(y < 0) y = n - 1;
				}
				square[y][x] = count;
			}
			++count;
		}
		for(int i = 0;i < n;++i){
			for(int j = 0;j < n;++j){
				printf("%4d",square[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1048
A,B,K=[int(i) for i in input().split()]
for i in range(K):
    if i%2==0:
        if A%2==1:
            A-=1
        A=A/2
        B+=A
    else:
        if B%2==1:
            B-=1
        B=B/2
        A+=B
print("{} {}".format(int(A),int(B)))

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

using namespace std;
 
int main(){
    int Math,Greedy,Geometry,DP,Graph,Other;
 
    while(cin >> Math >> Greedy >> Geometry >> 
	  DP >> Graph >> Other){
 
	if(!Math && !Greedy && !Geometry && !DP &&
	   !Graph && !Other) break;
 
	int MD = Math + DP , GG = Greedy + Graph;
	int GO = Geometry + Other;
 
	int ans = 0;
	if(MD >= 0 && GG >= 0 && GO >= 0){
	    ans = max(ans, MD/3 + GG/3 + GO/3);
	}
	if(MD >= 1 && GG >= 1 && GO >= 1){
	    ans = max(ans, ((MD-1)/3 + (GG-1)/3 + (GO-1)/3) + 1);
	}
	if(MD >= 2 && GG >= 2 && GO >= 2){
	    ans = max(ans, ((MD-2)/3 + (GG-2)/3 + (GO-2)/3) + 2);
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,N[200001],M[200001],now;
int main(void){
	register int i;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",&N[i]);
	sort(N+1,N+n+1);
	scanf("%d",&m);
	for(i=1;i<=m;++i)
		scanf("%d",&M[i]);
	sort(M+1,M+m+1);
	now=1;
	for(i=1;i<=m;++i){
		if(now>n){
			puts("NO");
			return 0;
		}
		while(now<=n&&N[now]!=M[i])++now;
		if(now>n){
			puts("NO");
			return 0;
		}
		++now;
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <bitset> 
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define mp make_pair 
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=2e6+5;
const int mod= 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	ll n;
	cin >> n;
	ll ans = 0x3f3f3f3f3f3f3f3f;
	for(ll i=1;1ll*i*i <= n; i++)
		if(n%i==0){
			ans = min(ans, i + n/i -2);
		}
	cout << ans ;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;

bool is_prime[1000001];
int max_able_num[1000001];
int max_able_prime[1000001];
int price[30];

int main(){
    is_prime[1] = false; is_prime[0] = false;
    fill(is_prime,is_prime+1000001,true);
    for(int i=2;i<=1000000;i++){
        if(is_prime[i]){
            for(int j=2;j*i<=1000000;j++){
                is_prime[j*i] = false;
            }
        }
    }

    while(1){
        int n, x;
        scanf("%d %d",&n,&x);
        if(n==0) break;

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

        fill(max_able_num,max_able_num+x+1,-1);
        max_able_num[0] = 0;
        for(int i=0;i<=x;i++){
            if(max_able_num[i]>=0){
                for(int j=0;j<n;j++){
                    if(i+price[j]<=x){
                        max_able_num[i+price[j]] = i+price[j];
                    }
                }
            }else{
                max_able_num[i] = max_able_num[i-1];
            }
            //printf("%d %d\n",i,max_able_num[i]);
        }
        max_able_prime[0] = 0;
        for(int i=1;i<=x;i++){
            if(is_prime[max_able_num[i]]){
                max_able_prime[i] = max_able_num[i];
            }else{
                max_able_prime[i] = max_able_prime[i-1];
            }
            //printf("%d %d\n",i,max_able_prime[i]);
        }
        if(max_able_prime[x])cout << max_able_prime[x] << endl;
        else cout << "NA" << endl;

        /*
        priority_queue <int> que;
        que.push(max_able_num[x]);
        fill(checked,checked+x+1,false);
        checked[max_able_num[x]] = true;
        bool found = false;

        while(que.size()){
            int p = que.top(); que.pop();
            cout << p << endl;
            if(is_prime[p]){
                found = true;
                cout << p << endl;
                break;
            }
            for(int i=0;i<n;i++){
                int next_p = p-price[i];
                if(!checked[next_p] && next_p>=0){
                    checked[next_p] = true;
                    que.push(next_p);
                }
            }
        }

        if(!found){
            cout << "NA" << endl;
        }
        */
    }
    return 0;
}

Measured memory_bytes: 9996
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string alp = "abcdefghijklmnopqrstuvwxyz";
    static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static void Main()
    {
      var a = ScanIntArray();
      if(a[0] > a[1])
        for(int i=0; i<a[0]; i++)
          Write(a[1]);
      else
        for(int i=0; i<a[1]; i++)
          Write(a[0]);
        
      WriteLine();
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
    static public string RegaxReplace(this string arg1, string pattern, string replacement)
    {
      return Regex.Replace(arg1, pattern, replacement);
    }
  }
  
  static class MyMath {
    public static bool isPrime(this int p){
      if(p<=1) return false;
      for(int i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static bool isPrime(this long p){
      if(p<=1) return false;
      for(long i=2; i*i<=p; i++)
        if(p%i==0) return false;
      return true;
    }
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import heapq
def dijkstra(s,path):
    # 距離をinfで初期化
    d = [float('inf')]*len(path)
    d[s] = 0

    # sへの距離は0
    q = [(0,s)]
    heapq.heapify(q)

    # 距離が最小の頂点から更新していけば良い
    while q:
        c,p = heapq.heappop(q)

        # 頂点pまでの距離がheap内のpまでの距離より小さい場合、continue
        if d[p]<c:
            continue

        # 頂点pから伸びる、全ての辺の距離を確認
        for to,cost in path[p]:
            # 頂点pから行ける頂点の距離がpまでの距離とpからの距離の和より小さい場合 -> 距離を更新し、heapに追加
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q,(d[to], to))
    return d

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

path = [[] for i in range(h*w)]
for i in range(h*w):
    y = i//w
    x = i%w
    if maze[y][x]=='#':
        continue
    for dy in range(-2,3):
        for dx in range(-2,3):
            if dy==dx==0:
                continue
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                j = (y+dy)*w + x+dx
                if (dy==0 and abs(dx)==1) or (abs(dy)==1 and dx==0):
                    path[i].append((j,0))
                else:
                    path[i].append((j,1))

d = dijkstra(start,path)
print(-1 if d[goal]==float('inf') else d[goal])
    








Measured memory_bytes: 358696
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K,Q = MI()
    A = []
    for _ in range(Q):
        A.append(int(input()) -1 )
    
    ans = [Q-K]*N
    for a in A:
        ans[a] -= 1
    for a in ans:
        if a >= 0:
            print("No")
        else:
            print("Yes")
    #Q-K回は正解しないといけない
if __name__ == '__main__':
    main()

Measured memory_bytes: 11020
import sys
input = lambda: sys.stdin.readline().rstrip()
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

cakes = []

heappush(cakes, (-(A[0]+B[0]+C[0]),0, 0, 0))

visited = set((A[0], B[0], C[0]))

for i in range(K):
    v, a, b, c = heappop(cakes)
    print(-v)

    if a+1 <= len(A) - 1 and (a+1, b, c) not in visited:
        v = A[a+1] + B[b] + C[c]
        heappush(cakes, (-v, a+1, b, c))
        visited.add((a+1, b, c))
    if b+1 <= len(B) - 1 and (a, b+1, c) not in visited:
        v = A[a] + B[b+1] + C[c]
        heappush(cakes, (-v, a, b+1, c))
        visited.add((a, b+1, c))
    if c+1 <= len(C) - 1 and (a, b, c+1) not in visited:
        v = A[a] + B[b] + C[c+1]
        heappush(cakes, (-v, a, b, c+1))
        visited.add((a, b, c+1))

Measured memory_bytes: 56536
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<ll, ll>
#define pll pair<ll , ll>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define N 200005
#define INF 1000000000000000

int arr[200005][3];
int main()
{   
    fastio
    int n;
    cin>>n;
   ;
    for(int i = 0 ; i<n;i++)
    {
        for(int j= 0 ; j<3;j++)cin>>arr[i][j];
    }

    int dp[n][3];
    for(int i = 0 ; i<n;i++)
        for(int j = 0 ; j <3;j++)dp[i][j] = 0;

    for(int i = 0 ; i<3;i++)dp[0][i] = arr[0][i];

    for(int i = 1 ; i<n;i++)
    {   
        for(int k = 0 ; k<3;k++)
        {
            for(int j = 0 ; j<3;j++)
            {   
                if(k==j)continue;
                dp[i][k] = max(dp[i][k] , dp[i-1][j] + arr[i][k]);
            }
        }
    }

    int ans = max(dp[n-1][0] , dp[n-1][1]);
    ans = max(ans , dp[n-1][2]);
    
    cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v;
string S, T;
vl A, B;
void input() {
    rep(i, 5) {
        cin >> x;
        A.pb(x);
    }
}
void solve() {
    rep(i, 5) {
        if(A[i] == 0)
            cout << i + 1 << endl;
    }
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}

Measured memory_bytes: 3652
/* Name        : b
 * Creat       : Sat Jul 13 14:54:34 CST 2019
 * Accept      : Sat Jul 13 14:55:39 CST 2019
 * Author      : landcold7
 * Motto       : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 0; i < 10; ++i) {
    int y = r * x - d;
    x = y;
    cout << y << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace Is_it_a_Right_Triangle
{
	class Program
	{
		static void Main(string[] args)
		{
			var result = Enumerable.Range(0, int.Parse(Console.ReadLine()))
				.Select(_ => Console.ReadLine())
				.Select(x => x.Split(' ').Select(y => int.Parse(y)))
				.Select(x => x.OrderBy(y => y).ToArray())
				.Select(x => x[0] * x[0] + x[1] * x[1] == x[2] * x[2]);

			foreach (var item in result) {
				Console.WriteLine(item ? "YES" : "NO");
			}
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(),L.end());
    int ans=0;
    rep(i,n)rep(j,i){
        int ij = L[i]+L[j];
        int r = lower_bound(L.begin(),L.end(),ij) - L.begin();
        int l = i+1;
        ans += max(0,r-l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;

namespace AOJALDS15C
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = int.Parse(Console.ReadLine());
            var P1 = new Point(0.0, 0.0);
            var P2=new Point(100.0,0.0);
            Koch(d,P1,P2);
            Console.WriteLine("{0} {1}",P2.x,P2.y);
            Console.ReadLine();
        }

        private static void Koch(int d, Point Pi, Point Pj)
        {
            if (d == 0)
            {
                Console.WriteLine("{0} {1}",Pi.x,Pi.y);
                return;
            }

            else
            {
                Point s = new Point((2 * Pi.x + Pj.x) / 3, (2 * Pi.y + Pj.y) / 3);
                Point t = new Point((Pi.x + 2 * Pj.x) / 3, (Pi.y + 2 * Pj.y) / 3);

                double ux = (t.x - s.x) * Math.Cos(Math.PI / 3) - (t.y - s.y) * Math.Sin(Math.PI / 3) + s.x;
                double uy = (t.x - s.x) * Math.Sin(Math.PI / 3) + (t.y - s.y) * Math.Cos(Math.PI / 3) + s.y;

                Point u = new Point(ux, uy);

                Koch(d - 1, Pi, s);
                Koch(d - 1, s, u);
                Koch(d - 1, u, t);
                Koch(d - 1, t, Pj);

                return;
            }
        }

        private struct Point
        {
            public double x;
            public double y;

            public Point(double a, double b)
            {
                x = a;
                y = b;
            }
        }
    }
}



Measured memory_bytes: 17920
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1000006
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int L;
int main(){
    //freopen("data.txt","r",stdin);
    cin >> L;
    double top = (double)L * (double)L *(double)L;
    cout << fixed << setprecision(7) << (double)top / 27 << endl;
    return 0;
}

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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int[] T = new int[N];
			int total = 0;
			for(int i = 0; i < N; i++) {
				T[i] = in.nextInt();
				total += T[i];
			}
			int M = in.nextInt();
			int[] P = new int[M];
			int[] X = new int[M];
			for(int i = 0; i < M; i++) {
				P[i] = in.nextInt();
				X[i] = in.nextInt();
			}
			for(int i = 0; i < M; i++) {
				out.println(total - T[P[i] - 1] + X[i]);
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

	}
}


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

int main(){
  int n,a;
  cin >> n;
  a = n*100/108;
  if(a*108/100==n){
      cout << a <<endl;
  }else if((a+1)*108/100==n){
      cout << a+1 << endl;
  }else{
       cout << ":(" << endl;
  }
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	sort(a.begin(),a.end());
	ll ans = 0;
	for(int i = 0;i<n;i++)
	{
		for(int j = i+1;j<n;j++)
		{
			for(int k = j+1;k<n;k++)
			{
				if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k])continue;
				if(a[i]+a[j]>a[k])ans++;
			}
			
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 4000
ll n,m;
ll dp[N][N];
ll dp2[N][200];
int main(){
    n=in();
    string s;cin>>s;
    rep(i,n){
        dp[0][i]=1;
    }
    rep2(i,0,n-2){
        bool flag=true;
        if(s[i]=='>')flag=false;
        if(flag){
            dp[i+1][0]=dp[i][0];
            rep2(j,1,n-i-2){
                dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])%MOD;
            }
        }
        else{
            dp[i+1][n-i-2]=dp[i][n-i-1];
            rep3(j,n-i-3,0){
                dp[i+1][j]=(dp[i+1][j+1]+dp[i][j+1])%MOD;
            }
        }
    }
    cout<<dp[n-1][0];
    return 0;
}

Measured memory_bytes: 94464
//***___********* ___*****___****___***___*********//
/*  |   \  |   | |   |   |   \  |     |     |   |  **
/*  |   |  |   | |___|   |   _  |__   |___  |___|  **
/*  |   |  |   | |   \   |  | | |         | |   |  **
/*  |___/  |___| |    \  |__| | |___  ____| |   |  **
//*************************************************/
#include<bits/stdc++.h>
#define ff double
#define endl "\n"
#define M 1000000007
#define forever while(1)
#define ll long long
#define pb push_back
#define vi vector<long long>
#define mii map<int,int>
#define pii pair<int,int>
#define set_zero(arr) memset(arr,0,sizeof(arr))
#include <ext/pb_ds/tree_policy.hpp>
#define forn(i,n) for(int i=0;i<(n);i++)
#include <ext/pb_ds/assoc_container.hpp>
#define fori(i,a,b) for(int i=(a);i<=(b);i++)
#define TEST_CASE   int t;cin>>t;while(t--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
bool check(int n){
    int cnt = 0;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}

vi tre[100000];

bool ans = true;
bool vis[100000] = { false };
void dfs(int s){
    vis[s]=true;
    if(tre[s].size()>1){
        int cnt = 0;
        for(int i=0;i<tre[s].size();i++){
            int child = tre[s][i];
            if(tre[child].size()==1){
                cnt++;
            }
        }
        if(cnt<3){
            ans=false;
        }
    }
    for(int i=0;i<tre[s].size();i++){
        if(vis[tre[s][i]]==false)
            dfs(tre[s][i]);
    }
}
void solve(){
ll n,b,r;
cin>>n>>b>>r;
if(n<(b+r))cout<<min(n,b)<<endl;
else{
    ll k =n/(b+r);
    cout<<b*k+(min(n%(b+r),b))<<endl;
}

}


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



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

int main()
{
	int x, y, t;
	
	while (1) {
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		if (x > y) {
			t = x;
			x = y;
			y = t;
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int n;
vvi g;
vector<bool> is_root;
int root;

int MAX_LOG_V = 40;
vi depth;
vvi par;

void lca_dfs(int u, int prev, int d) {
  depth[u] = d;
  par[u][0] = prev;
  for (int v : g[u]) {
    if (v == prev) {
      continue;
    }
    lca_dfs(v, u, d+1);
  }
}

void lca_init() {
  lca_dfs(root, -1, 0);
  rep (k, MAX_LOG_V - 1) {
    rep (i, n) {
      if (par[i][k] < 0) {
        continue;
      } else {
        par[i][k+1] = par[par[i][k]][k];
      }
    }
  }
}

int lca(int u, int v) {
  if (depth[u] > depth[v]) {
    swap(u, v);
  }
  rep (k, MAX_LOG_V) {
    if ((((depth[v] - depth[u]) >> k) & 1) == 1) {
      v = par[v][k];
    }
  }
  if (u == v) { return u; }
  for (int k = MAX_LOG_V - 1; k >= 0; --k) {
    if (par[u][k] != par[v][k]) {
      u = par[u][k];
      v = par[v][k];
    }
  }
  return par[u][0];
}

int main() {
  scanf("%d", &n);
  g.resize(n);
  is_root.assign(n, true);
  rep (i, n) {
    int k;
    scanf("%d", &k);
    int c;
    rep (j, k) {
      scanf("%d", &c);
      g[i].push_back(c);
      g[c].push_back(i);
      is_root[c] = false;
    }
  }
  root = -1;
  rep (i, n) {
    if (is_root[i]) {
      root = i;
    }
  }
  depth.assign(n, 0);
  par.assign(n, vi(MAX_LOG_V, -1));
  lca_init();

  int q;
  scanf("%d", &q);
  rep (query, q) {
    int u, v;
    scanf("%d %d", &u, &v);
    printf("%d\n", lca(u, v));
  }

  return 0;
}

Measured memory_bytes: 32904
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt(), i = 0, j = N-1, t = 0;
		int[] a = new int[N];
		while (N-->0) a[i++] = sc.nextInt();
		Arrays.sort(a);
		while (K-->0) t+=a[j--];
		System.out.println(t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35628
#include<iostream>
using namespace std;
int main(){
    int a,b,n;
    a=b=0;

    while(cin>>n,n){
        a=b=0;
        while(n--){
            int x,y;
            cin>>x>>y;
            if(x>y)a+=x+y;
            else if(x<y)b+=x+y;
            else{
                a+=x;
                b+=x;
            }
        }
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int a,b;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
  cin>>a>>b;
  if(a<=5)cout<<0<<endl;
  else if(a<=12)cout<<b/2<<endl;
  else cout<<b<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail+1 == LEN+1){tail=0;}
  else tail++;
}

P dequeue(){
  P x;
  x=Q[head];
  if(head+1==LEN+1){head=0;}
  else head++;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  while(1)
    {
      if(head==tail)break;
      u=dequeue();
      u.t=u.t-q;
      if(u.t<=0)
      {
	elaps = elaps + q + u.t;
	printf("%s %d\n",u.name,elaps);
      }
      else
      {
	elaps = elaps + q;
	enqueue(u);
      }
    }

  
  return 0;
}



Measured memory_bytes: 11860
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n;
	cin >> n;
	vll p(n);
	rep(i,n)cin >> p[i];

	int mini = INF;
	int cnt = 0;
	rep(i,n){
		if(mini >= p[i])cnt++;
		chmin(mini,p[i]);
	}
	cout << cnt << endl;
	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc152.contest.atcoder.jp/tasks/abc152_c

Measured memory_bytes: 4844
from collections import deque

H, W = list(map(int, input().split()))

maze = []
for _ in range(H):
    maze.append(list(input()))

#bfsならうまく解ける!!
def bfs(i, j):
    q = deque([(i, j, 0)])
    seen = set([(i, j)])
    ans = 0
    while q:
        i, j, d = q.popleft()
        ans = max(ans ,d)
        for dx, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            x = i + dx
            y = j + dj
            if 0 <= x < H and 0 <= y < W and maze[x][y] == "." :
                if (x, y) not in seen:
                    seen.add((x, y))
                    q.append((x, y, d + 1))           
    return ans


res = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            res = max(res, bfs(i, j))
print(res)





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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int grid[3][3][2];
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> grid[i][j][0];
			grid[i][j][1] = 0;
		}
	}
	int n;
	cin >> n;
	while(n--) {
		int x;
		cin >> x;
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				if(grid[i][j][0] == x) {
					grid[i][j][1] = 1;	
				}
			}
		}
	}
	for(int i = 0; i < 3; i++) {
		bool ok_temp = 1;
		for(int j = 0; j < 3; j++) {
			if(grid[i][j][1] == 0) {
				ok_temp = 0;
			}
		}
		if(ok_temp) {
			cout << "Yes\n";
			return;
		}
	}
	for(int i = 0; i < 3; i++) {
		bool ok_temp = 1;
		for(int j = 0; j < 3; j++) {
			if(grid[j][i][1] == 0) {
				ok_temp = 0;
			}
		}
		if(ok_temp) {
			cout << "Yes\n";
			return;
		}
	}
	bool ok = 1;
	for(int i = 0; i < 3; i++) {
		if(grid[i][i][1] == 0) {
			ok = 0;
		}	
	}
	if(ok) {
		cout << "Yes\n";
		return;
	}
	ok = 1;
	for(int i = 0; i < 3; i++) {
		if(grid[i][2 - i][1] == 0) {
			ok = 0;
		}
	}
	if(ok) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}





	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 256