akhauriyash/Code-Regression huggingface dataset:
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


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

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


void solve(long long n, long long k, std::vector<long long> p){
    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), next(p.begin(), k), 0LL) << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
  ll n,p,a,t,ans=1;
  cin >> n >> p;
  if (n==1){
    cout << p << endl;
    return 0;
  }
  for (a=2;a*a<=p;a++){
    t=0;
    while (p%a==0){
      p/=a;
      t++;
    }
    for (int i=0;i<t/n;i++) ans*=a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm> 
using namespace std;

int main() {

    int A, B;
    cin >> A >> B;
    int A1, B1, A2, B2;
    
    A1 = A * 12.5 -1;
    A2 = (A+ 1) * 12.5;
    B1 = B * 10;
    B2 = (B + 1) * 10-1;
    //printf("%d\n%d\n%d\n%d\n", A1, B1, A2, B2);
    if ((A1 < B2) && (B1 < A2)) {
        printf("%d\n", max((25 * A + 1) / 2, 10 * B));
    }else {
        printf("%d", -1);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b && a!=c)
        printf("Yes\n");
    else  if(a==c && a!=b)
        printf("Yes\n");
    else  if(c==b && a!=c)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005



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

    int ans[n];
    if(n==3){
        ans[0] = 2; ans[1] = 5; ans[2] = 63;
    }else if(n<=15002){
        rep(i,n-2){
            ans[i] = (i+1)*2;
        }
        int x = n-2;
        if((n-2)%2==1)x = n-1;
        while(x%2==0){
            x /= 2;
        }
        if(x==1){
            x = n-2;
            if((n-2)%2==0){
                x = n-1;
            }
        }
        ans[n-2] = x;
        ans[n-1] = x*3;
    }else{
        int count = 0;
        int sum = 0;
        srep(i,1,30000){
            if(i%6==0)continue;
            if(i%2==0 || i%3==0){
                ans[count] = i;
                sum += i;
                count++;
            }
        }
        rep(i,n - 15002){
            ans[count] = 6*(i+1);
            sum += ans[count];
            count++;
        }
        ans[n-2] = 7;
        ans[n-1] = 35;
        if(sum%7!=0){
            if(n<17500){
                while(sum%7!=0){
                    ans[n-3] += 6;
                    sum += 6;
                }
            }else{
                sum += 30000 - ans[15000];
                ans[15000] = 30000;
                int i = 15000;
                while(sum%7!=0){
                    ans[i] = ans[i+1] - 6;
                    ans[i+1] = 30000;
                    sum -= 6;
                    i++;
                }
            }
        }
    }

    rep(i,n){
        cout << ans[i] << ' ';
    }
    cout << endl;
    
    return 0;
}
 
 


Measured memory_bytes: 384
from collections import deque

N, M = map(int, input().split())

matrix = [[0 for i in range(N)] for j in range(N)]

edge_list = []

for i in range(M):
    a, b = map(int, input().split())
    edge_list.append((min(a, b)-1, max(a, b)-1))
    matrix[min(a, b)-1][max(a, b)-1] = 1
    matrix[max(a, b)-1][min(a, b)-1] = 1
    
count = 0
    
for edge in edge_list:
    visited = [0] * N
    matrix[edge[0]][edge[1]] = 0
    matrix[edge[1]][edge[0]] = 0
    queue = deque()
    
    queue.append(0)
    visited[0] = 1
    
    while len(queue) > 0:
        target = queue.popleft()
        for i in range(N):
            if matrix[target][i] == 1 and visited[i] == 0:
                queue.append(i)
                visited[i] = 1

    if sum(visited) != N:
        count += 1
        
    matrix[edge[0]][edge[1]] = 1
    matrix[edge[1]][edge[0]] = 1
    

print(str(int(count)))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int a,b,c;
  int k;
  cin >> a >> b >> c;
  cin >> k;

  int ans;
  int mx = max(max(a,b),c);
  if(mx == a) ans = b + c;
  else if(mx == b) ans = a + c;
  else ans = a + b;
  for(int i=0;i<k;i++){
    mx *= 2;
  }

  ans += mx;
  cout << ans << endl;
}

Measured memory_bytes: 3580
h, w, n = [int(item) for item in input().split()]
sr, sc = [int(item) for item in input().split()]
sr -= 1
sc -= 1
s = input().rstrip()
t = input().rstrip()

x = sc
# Check left
for i in range(n):
    if s[i] == "L":
        x -= 1
    if x < 0:
        print("NO")
        exit()
    if t[i] == "R" and x+1 < w-1:
        x += 1

x = sc
# Check Right
for i in range(n):
    if s[i] == "R":
        x += 1
    if x > w-1:
        print("NO")
        exit()
    if t[i] == "L" and x > 0:
        x -= 1

y = sr
# Check Down
for i in range(n):
    if s[i] == "D":
        y += 1
    if y > h-1:
        print("NO")
        exit()
    if t[i] == "U" and y > 0:
        y -= 1

y = sr
# Check up
for i in range(n):
    if s[i] == "U":
        y -= 1
    if y < 0:
        print("NO")
        exit()
    if t[i] == "D" and y+1 < h-1:
        y += 1

print("YES")

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


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

  int yy;
  int mm;

  yy = (((int)yymm[0]-48) * 10) + ((int)yymm[1]-48);
  mm = (((int)yymm[2]-48) * 10) + ((int)yymm[3]-48);

  if(((yy > 12) || (yy == 0)) && ((mm > 12) || (mm == 0))){
    cout << "NA" << endl;
  }
  else{
    if((yy <= 12 && yy != 00) && (mm <= 12 && mm != 00)){
      cout << "AMBIGUOUS" << endl;
    }else if((yy > 12 || yy == 00)){
      cout << "YYMM" << endl;
    }else if((mm > 12 || mm == 00)){
      cout << "MMYY" << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed<<setprecision(pp)
#define FOR(I,N) for(I=0;I<N;++I)
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod	%1000000007
#define pi 3.141592653
#define MX 1000000007

int main()
{
	int n,x,t;
	cin>>n>>x>>t;
	int ans=(n+x-1)/x;
	ans*=t;
	cout<<ans;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    ll k, t;
    cin >> k >> t;
    ll ma = 0;
    ll sum = 0;
    rep(i, t)
    {
        ll a;
        cin >> a;
        sum += a;
        ma = max(a, ma);
    }

    ll ans = max((ll)0, 2 * ma - sum - 1);
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=998244353,INF=1e18;

const int MAX = 210000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpower(ll n,ll p){
    if(p==0){return 1;}
    if(p%2==1){return n*modpower(n,(p-1)/2)%MOD*modpower(n,(p-1)/2)%MOD;}
    else{return modpower(n,p/2)*modpower(n,p/2)%MOD;}
}

int main() {
    int N,M,K;
    cin>>N>>M>>K;
    COMinit();
    ll ans=0;
    rep(j,K+1){
        ll now=M;
        now*=modpower(M-1,N-j-1);
        now%=MOD;
        now*=COM(N-1,j);
        now%=MOD;
        ans+=now;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8560
void main() {
  problem();
}

void problem() {
  enum CONTESTS = 26;
  const days = scan!int;
  const dec = scan!long(CONTESTS);
  const inc = days.iota.map!(x => scan!long(CONTESTS)).array;

  long calcSatisfactionValue(long[] contests) {
    auto desat = new long[CONTESTS];
    long sat;

    foreach(i, c; contests) {
      sat += inc[i][c];
      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        sat -= desat[o];
      }
    }

    return sat;
  }

  long[] solve() {
    auto desat = new long[CONTESTS];
    auto value = new long[CONTESTS];
    const potential = CONTESTS.iota.map!(c => inc.map!(i => i[c]).sum).array;
    deb(potential);

    long decideNextContest(long day, const long[] inc, long[] dec) {
      long contestCanditate;
      long score = long.min;
      const sumDec = dec.sum;

      foreach(c; 0..CONTESTS) {
        long testScore = inc[c] + dec[c] - sumDec;
        if (score < testScore) {
          contestCanditate = c;
          score = testScore;
        }
      }
      return contestCanditate;
    }

    long[] ans;
    foreach(i; 0..days) {
      auto c = decideNextContest(i, inc[i], desat);
      ans ~= c;

      value[c] += inc[i][c];

      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        value[o] -= desat[o];
      }
    }

    foreach(__; 0..10) {
    long[] necks;
    foreach(_; 0..CONTESTS) {
      const worstIndex = value.minIndex;
      necks ~= worstIndex;
      value[worstIndex] = long.max;
    }

    foreach(n; necks[0..CONTESTS]) {
      auto newAns = ans.dup;
      long maxTry = 0;
      long maxValue = calcSatisfactionValue(ans);
      foreach(i; days/10..days*9/10) {
        const origin = newAns[i];
        newAns[i] = n;
        
        const v = calcSatisfactionValue(newAns);
        if (v > maxValue) {
          maxValue = v;
          maxTry = i;
        }

        newAns[i] = origin;
      }

      if (maxTry != 0) ans[maxTry] = n;
    }

    value[] = 0;
    desat[] = 0;
    foreach(i, c; ans) {
      value[c] += inc[i][c];
      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        value[o] -= desat[o];
      }
    }

    }

    calcSatisfactionValue(ans).deb;
    return ans;
  }

  const r = solve();
  debug{} else r.each!(c => writeln(c + 1));
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 3900
import java.text.DecimalFormat;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        final int N = sc.nextInt(), K = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                set.add(sc.nextInt());
            }
        }
        
        out.println(N - set.size());

        out.flush();
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


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

int n, m, q;
int a[55], b[55], c[55], d[55];
int res = 0;
void dfs(vector<int> &A) {
	if(A.size() == n) {
		int tmp = 0;
		for (int i = 0; i < q; i++)
		{
			if(A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
		}
		res = max(res, tmp);
		return;
	}
	int s;
	if(A.size() == 0) s = 1;
	else s = A[A.size()-1];
	for(int v = s; v <= m; v++) {
		A.push_back(v);
		dfs(A);
		A.pop_back();
	}
}

int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}
	vector<int> A;
	dfs(A);
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;
int main(){
    int a,b,c;
    cin >>a >>b >>c;
    if(a==b&&b==c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long count = 0;
        for (int i = 0; i < n; i++) {
            while (true) {
                if (a[i] % 2 == 0) {
                    a[i] /= 2;
                    count++;
                } else {
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


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

using namespace std;

typedef pair<int,int> P;
const int INF=1e9+10;
const int N=1e5+10;

struct edge
{
    int to,cost;
    edge(){}
    edge(int t,int c):to(t),cost(c){}
};

vector<edge> G[N];
int V,E,S;
int d[N];

void init(int n)
{
    for(int i=0;i<=n;i++) G[i].clear();
}

void Dijkstra(int s)
{
    fill(d,d+V,INF);
    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > q;
    q.push(P(0,s));

    while(!q.empty())
    {
        P tmp=q.top();q.pop();
        int v=tmp.second;
        if(d[v]<tmp.first) continue;
        for(int i=0;i<G[v].size();i++)
        {
            edge &e=G[v][i];
            if(d[e.to]>d[v]+e.cost&&d[v]!=INF)
            {
                d[e.to]=d[v]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
}

int main()
{
    while(scanf("%d %d %d",&V,&E,&S)!=EOF)
    {
        init(V);
        for(int i=0;i<E;i++)
        {
            int s,t,c;
            scanf("%d %d %d",&s,&t,&c);
            G[s].push_back(edge(t,c));
        }
        Dijkstra(S);
        for(int i=0;i<V;i++)
        {
            if(d[i]==INF)
            {
                puts("INF");
                continue;
            }
            printf("%d\n",d[i]);
        }
    }


    return 0;
}



Measured memory_bytes: 13052
#include<stdio.h>
int main(){
  int i,j,x,ans=1,ans2,f;
  scanf("%d",&x);
  for(i=2;i<x;i++){
    ans2=i*i;
    f=0;
    while(ans2<=x){
      ans2*=i;
      f=1;
    }
    if(f==1){
      ans2/=i;
    }
    if(ans<ans2 && ans2<=x){
      ans=ans2;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		int[] a = new int[m];
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]) - 1;
			b[i] = Integer.parseInt(sa[1]) - 1;
		}
		int[] c = new int[k];
		int[] d = new int[k];
		for (int i = 0; i < k; i++) {
			sa = br.readLine().split(" ");
			c[i] = Integer.parseInt(sa[0]) - 1;
			d[i] = Integer.parseInt(sa[1]) - 1;
		}
		br.close();

		UnionFind uf = new UnionFind(n);
		for (int i = 0; i < m; i++) {
			uf.union(a[i], b[i]);
		}

		int[] ans = new int[n];
		for (int i = 0; i < n; i++) {
			ans[i] = uf.size(i) - 1;
		}
		for (int i = 0; i < m; i++) {
			ans[a[i]]--;
			ans[b[i]]--;
		}
		for (int i = 0; i < k; i++) {
			if (uf.same(c[i], d[i])) {
				ans[c[i]]--;
				ans[d[i]]--;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(ans[i]).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}

	static class UnionFind {
		int[] parent, size;

		UnionFind(int n) {
			parent = new int[n];
			size = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
				size[i] = 1;
			}
		}

		void union(int x, int y) {
			int px = find(x);
			int py = find(y);
			if (px != py) {
				parent[px] = py;
				size[py] += size[px];
			}
		}

		int find(int x) {
			if (parent[x] == x) {
				return x;
			}
			parent[x] = find(parent[x]);
			return parent[x];
		}

		/**
		 * xとyが同一連結成分か
		 */
		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		/**
		 * xを含む連結成分のサイズ
		 */
		int size(int x) {
			return size[find(x)];
		}
	}
}


Measured memory_bytes: 63692
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2+y1-y2 << " " << y2+x2-x1 << " " << x1+y1-y2 << " " << y1+x2-x1;
}


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

int n,x,m[101],mins=10000;

int main(){
  int i,j;
  cin >> n >> x;
  for(i=0;i<n;i++){
    cin >> m[i];
    if(mins>m[i])mins = m[i];
    x -= m[i];
  }
  cout << n+x/mins << endl;
  

  return 0;
}


Measured memory_bytes: 256
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

if list_yoko == []:
	list_yoko = [0]

if list_tate == []:
	list_tate = [0]
	
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3980
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int[] a = new int[21];
			a[0] = cin.nextInt();
			int L = cin.nextInt();
			if(a[0]==0&&L==0){
				break;
			}
			int i = 1;
			label:while(true){
				String s = a[i-1]+"";
				while(s.length()<L)s+="0";
				char[] c = s.toCharArray();
				Arrays.sort(c);
				int max=0, min=0;
				for(int j=0;j<L;j++)min=min*10+(c[j]-'0');
				for(int j=L-1;j>=0;j--)max=max*10+(c[j]-'0');
				a[i] = max-min;
				//System.out.println(max + " " + min);
				for(int j = i-1; j >= 0;j--){
					if(a[j]==a[i]){
						System.out.println(j+" "+a[i]+" "+(i-j));
						break label;
					}
				}
				i++;
			}
			
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <complex>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>

#define mod 1000000007
#define point complex <double>
#define p pair<double,double>
#define ll long long
#define pi acos(-1)

using namespace std;

ll fact[2005], inv[2005], dp[2005][2005][2];

ll fp(int base, int power)
{
	if (power == 0) return 1;
	ll ans = fp(base, power / 2);
	ans = (ans * ans) % mod;
	if (power % 2 != 0) ans = (ans * (base % mod)) % mod;
	return ans;
}

void calc()
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= 2000; i++)
	{
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}

ll ncr(int n, int r)
{
	return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll stars_and_bars(int stars, int bars)
{
	return ncr(stars - 1, bars - 1);
}

// states: consecutive_blue cnt , all left red cnt , flag if prev is blue or not 

ll solve(int blue, int red, bool prev)
{
	if (!red && !blue) return 1;
	if (dp[blue][red][prev] != -1)return dp[blue][red][prev];
	ll ans = 0;
	if (blue && !prev) ans = (ans + solve(blue - 1, red, true)) % mod;
	if (red) ans = (ans + solve(blue, red - 1, false)) % mod;
	return dp[blue][red][prev] = ans;
}

int main()
{
	calc();
	memset(dp, -1, sizeof dp);
	int n, k, r;
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
		cout << (stars_and_bars(k, i) * solve(i, n - k, 0)) % mod << '\n';
	return 0;
}


Measured memory_bytes: 63232
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)
int main()
{
  int n,x,y;
  cin>>n>>x;
  loop(i,n-1)
  {
    cin>>y;
    x=__gcd(x,y);
  }
  cout<<x;
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;
ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return mod_pow(x * x % MOD, n / 2) % MOD;
    else return x * mod_pow(x, (n - 1)) % MOD;
}
ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;
    ll ret = 1;
    while (n) if (n & 1) ret = ret * x % MOD; x = x * x % MOD; n /= 2;
    return ret;
}
ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) ret *= (i + 1); ret %= MOD;
    return ret;
}
ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);
    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    int k; cin >> k;
    int a, b; cin >> a >> b;
    bool ret = false;
    for (int i = a; i < b+1; ++i) {
        if (i % k == 0) ret = true;
    }
    if (ret) cout << "OK";
    else cout << "NG";
}

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

Measured memory_bytes: 3656
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

int main() {
  int n, W;
  cin >> n >> W;
  vi w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];

  ll dp[n+1][W+1];
  rep(i, n+1) rep(j, W+1) dp[i][j] = 0;

  rep(i, n){
    rep(j, W+1){
      dp[i+1][j] = dp[i][j];
      if (j >= w[i]){
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      }
    }

    // rep(j, W+1) cout << dp[i+1][j] << " ";
    // cout << endl;
  }
  cout << dp[n][W] << endl;  
  return 0;
}

Measured memory_bytes: 79104
package main

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

func main() {
	s := wordScanner()
	n, a := scanNAndIntSlice(s)

	var l, r [100001]int
	for i := 0; i < n-1; i++ {
		l[i+1] = gcd(l[i], a[i])
	}
	for i := n - 1; i > 0; i-- {
		r[i] = gcd(r[i+1], a[i])
	}

	var ans, m int
	for i := 0; i < n; i++ {
		m = gcd(l[i], r[i+1])
		ans = max(ans, m)
	}
	fmt.Println(ans)
}

func wordScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func scanNAndIntSlice(s *bufio.Scanner) (int, []int) {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n, scanIntSlice(s, n)
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}

func gcd(x, y int) int {
	if x > y {
		x, y = y, x
	}
	for x%y != 0 {
		x, y = y, x%y
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 4608
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		sc.close();

		if (N >= 1000) {
			out.println("ABD");
		} else {
			out.println("ABC");
		}

	}

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


Measured memory_bytes: 22996
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Edge
{
	int a, b, cost;
	Edge(int a, int b, int cost)
		: a(a), b(b), cost(cost) {}
};
bool operator<(const Edge& a, const Edge& b)
{
	return a.cost < b.cost;
}


template <class T>
class UnionFind
{
public:
	UnionFind(int n)
		: g(n)
	{
		parent = new T[n];
		rank = new T[n];
		for (int i = 0; i < n; ++i)
		{
			parent[i] = i;
			rank[i] = 0;
		}
	}

	void unite(T a, T b)
	{
		T root_a = root(a);
		T root_b = root(b);
		if (root_a == root_b)
			return;

		--g;

		if (rank[root_a] < rank[root_b])
			parent[root_a] = root_b;
		else if (rank[root_a] > rank[root_b])
			parent[root_b] = root_a;
		else
		{
			parent[root_a] = root_b;
			++rank[root_a];
		}
	}

	bool same(T a, T b)
	{
		return root(a) == root(b);
	}

	int groups() { return g; }

private:
	T* parent;
	T* rank;
	int g;

	T root(T e)
	{
		if (parent[e] == e)
			return e;
		else
			return parent[e] = root(parent[e]);
	}
};
int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		vector<Edge> e;
		rep (i, m)
		{
			int a, b, w;
			cin >> a >> b >> w;
			--a, --b;
			e.push_back(Edge(a, b, w));
		}
		sort(all(e));

		const int INF = 1 << 26;
		int res = INF;
		for (int i = 0; i < e.size(); ++i)
		{
			UnionFind<int> u(n);
			for (int j = i; j < e.size() && e[j].cost - e[i].cost < res; ++j)
			{
				if (!u.same(e[j].a, e[j].b))
				{
					u.unite(e[j].a, e[j].b);
					if (u.groups() == 1)
					{
						res = e[j].cost - e[i].cost;
						break;
					}
				}
			}
		}

		if (res == INF)
			res = -1;
		cout << res << endl;
	}
}

Measured memory_bytes: 10000
n,m=map(int, input().split())

ac_=[0]*n
wa_=[0]*n
ac=0
wa=0

for i in range(m):
	q,r=input().split()
	q=int(q)-1
	if ac_[q]==0:
		if r=='WA':
			wa_[q]+=1
		if r=='AC':
			ac+=1
			wa+=wa_[q]
			ac_[q]=1

print(ac,wa)

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

vector<vector<int>> graph;
vector<int> d;
vector<bool> visited;

bool DFS(int v, int previous_v = -1){
    if(visited[v] == true){
        if((d[previous_v] - d[v]) % 2 == 0) return true;
        else return false;
    }
    visited[v] = true;
    if(previous_v != -1) d[v] = d[previous_v] + 1;

    bool flag = false;
    for(int adjacent_v : graph[v]){
        if(adjacent_v == previous_v) continue;

        flag |= DFS(adjacent_v, v);
    }
    return flag;
}

int main(){
    long long int n, m;
    cin >> n >> m;

    graph.resize(n);
    vector<int> degree(n);
    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        u -= 1;
        v -= 1;

        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u] += 1;
        degree[v] += 1;
    }

    long long int ans = 0;
    long long int a = 0, b = 0, c = 0;
    visited.assign(n, false);
    d.resize(n);

    for(int i=0; i<n; i++){
        if(degree[i] == 0){
            c += 1;
            ans += 2*n;
        }
        else if(visited[i] == false){
            bool odd_cycle = DFS(i);
            if(odd_cycle == false) a += 1;
            if(odd_cycle == true)  b += 1;
        }
    }
    ans -= c * c;

    ans += (a+b) * (a+b) + a * a;// 2 * a * a + 1 * ((a+b) * (a+b) - a * a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13296
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

  

int32_t main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    int count=0;
    cin>>n>>m;
    while(n--)
    {
		int x,y;
		cin>>x>>y;
		int a=abs(x-0)*(x-0);
		int b=abs(y-0)*(y-0);
		int k=a+b;
		double z=sqrt(abs((x-0)*(x-0))+abs((y-0)*(y-0)));
		//cout<<z<<endl;
		//double d=double(m);
		if((double)m>=z)
		count++;
		
		
	} 		
	
	cout<<count;
   

		
	
		  
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
using namespace std;
vector<int> v[9]; int N, M;
struct Node {
    int now = 1; int cnt[9] = {1,1,0};
};
int next(Node n) {
    if(n.cnt[n.now] > 1) return 0;
    if(n.cnt[0] == N) return 1;
    int root = 0;
    for(int x : v[n.now]) {
        if(n.cnt[x] == 1) continue;
        Node n2 = n;
        n2.cnt[n.now] += 1; n2.cnt[0] += 1; n2.now = x;
        root += next(n2);
    }
    return root;
}
int main() {
    cin >> N >> M;
    for(int i = 0, a, b; i < M; i++) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    Node n;
    cout << next(n);
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,m,x[200],y[200],a,z[24*60],zi,fun,f,i;
	for(i=0;i<24*60;i++){
		z[i]=0;
	}
	f=0;
	zi=0;
	fun=0;
	cin>>n;
	for(i=0;i<n;i++) cin>>x[i]>>y[i];
	cin>>m;
	for(i=n;i<n+m;i++) cin>>x[i]>>y[i];
	
	for(i=0;i<n+m;i++){
		a=x[i]*60+y[i];
		z[a]=1;
	}
	for(i=0;i<24*60;i++){
		if(z[i]==1 && f==1){
			zi=i/60;
			fun=i%60;
			if(fun/10!=0) cout<<' '<<zi<<':'<<fun;
			if(fun/10==0) cout<<' '<<zi<<':'<<'0'<<fun;
		}
		if(z[i]==1 && f==0){
			zi=i/60;
			fun=i%60;
			if(fun/10!=0) cout<<zi<<':'<<fun;
			if(fun/10==0) cout<<zi<<':'<<'0'<<fun;
			f=1;
		}
	}
	cout<<endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <cctype>
#include <algorithm>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); }
int n, m, q, col[N], u[N], d[N], w[N], f[N];
void dfs(int x, int d, int c)
{
    if(f[x]>>d&1) return;
    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;
    for(int i = head[x]; i&&d; i = edge[i].next)
    {
        int y = edge[i].to;
        dfs(y, d-1, c);
    }
}
int main()
{
    n = read(), m = read();
    for(int i = 1, x, y; i <= m; ++i) x = read(), y = read(), add(x, y);
    q = read();
    for(int i = 1; i <= q; ++i) u[i] = read(), d[i] = read(), w[i] = read();
    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);
    for(int i = 1; i <= n; ++i) printf("%d\n", col[i]);
    return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll p[100001] = {};
ll y[100001] = {};
map<ll, map<ll, ll>> mp;
int main() {
	ll n, m; cin >> n >> m;
	rep(i, 0, m) {
		cin >> p[i] >> y[i];
		mp[p[i]][y[i]];
	}
	for (map<ll, map<ll, ll>>::iterator it = mp.begin(); it != mp.end(); it++) {
		ll index = 1;
		for (map<ll, ll>::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++) {
			it2->second = index++;
		}
	}

	rep(i, 0, m) {
		printf("%06d%06d\n", p[i], mp[p[i]][y[i]]);
	}

	return 0;
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
int main () {
	string s, cs;
	cin >> s;
	for (int i=0; i<s.length(); i++) {
		if (s[i] == 'B' && cs.size()>0) {
			cs.erase(cs.size()-1,1);
		} else {
			if (s[i] != 'B') 
				cs += s[i];
		}
	}
	cout << cs;
	return 0;
}

Measured memory_bytes: 3600
N = int(input())
a = []
for i in range(5):
    a.append(int(input()))

mini = 1000000000000000000000
index = 0
for i in range(5):
    if mini > a[i] and a[i] > 0:
        index = i
        mini = a[i]


ans = (N-1)//mini + 1 + 4
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
long long mpow(long long a, long long b){
	long long cur=a;
	long long ans=1;
	for(;;){
		if(b==0)return ans;
		if(b&1){
			ans=ans*cur;

		}
		b=b>>1;
		cur=cur*cur;
	}
}
			
int main(){
    long long n,p;
    cin>>n>>p;
    if(n==1){cout<<p<<endl; return 0;}
    if(n>=40){cout<<'1'<<endl; return 0;}
    long long ans=1;
    long long arr[1000000];
    int ind=0;
    long long cnt=1;
    for(long long a=2;mpow(a,n)<=p;a=a+1){
    	cnt=a;
    }
 //   cout<<cnt<<endl;
    for(long long a=cnt;a>=1;a--){
    	if(p%mpow(a,n)==0){
    		cout<<a<<endl;
    		return 0;
    	}
    }
    	
   return 0;
   
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 入力から変数を初期化
N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
ans = H

# 振る刀の最大値
amax = max(a)

# 投げる刀を降順でソートしておく
b.sort(reverse=True)

# 攻撃力の高い刀から順にk本投げ、残りの体力をamaxを使って削る
damage_throw = 0
for k in range(N+1):
    damage_throw += 0 if k == 0 else b[k-1]
    H_minus_throw = H - damage_throw
    if H_minus_throw <= 0:
        tmp_ans = k
    else:
        num_swing = -(-H_minus_throw // amax)
        tmp_ans = k + num_swing
    ans = min(tmp_ans, ans)

print(ans)


Measured memory_bytes: 11296
#include<cstdio>
int a,b,c,i,j,n,s;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
    {
    	for (j=0;j<=b;j++)
    	{
      		if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ++s;
      	}
    }
    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define add(a, b) if (b > a.first) { a.second = a.first, a.first = b; } else if (b < a.second) { a.second = b; }
using namespace std;

struct Str {
    int first, second, id1, id2;
};

inline void add(Str & a, int b, int idb)
{
    if (b > a.first)
        a.second = a.first, a.id2 = a.id1, a.id1 = idb, a.first = b;
    else if (b > a.second)
        a.second = b, a.id2 = idb;
}

Str best[1 << 19];
int n;

inline Str maxim(Str a, Str b)
{
    Str ans;
    if (a.first > b.first) {
        ans.first = a.first;
        ans.id1 = a.id1;
    }
    else if (a.first < b.first || (a.first == b.first && a.id1 != b.id1)) {
        ans.first = b.first;
        ans.id1 = b.id1;
        swap(a, b);
    }
    else {
        ans = a;
        if (a.second < b.second)
            ans.second = b.second, ans.id2 = b.id2;
        return ans;
    }
    if (a.second > b.first)
        ans.second = a.second, ans.id2 = a.id2;
    else
        ans.second = b.first, ans.id2 = b.id1;

    return ans;
}

int a[1 << 19];


int main()
{
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
    cin >> n;

    n = 1 << n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int x = n - 1 - i;
        for (int j = x; j; j = (j - 1) & x)
            add(best[n - 1 - j], a[i], i);
        add(best[n - 1], a[i], i);
    }

    int sumprec = 0;

    for (int k = 1; k < n; k++) {
        Str ans = { 0, 0 };
        for (int i = k; i; i = (i - 1) & k)
            ans = maxim(ans, best[i]);

        sumprec = max(sumprec, ans.first + ans.second);
        cout << sumprec << '\n';
    }

    return 0;
}


Measured memory_bytes: 10368
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n, m; n = in(), m = in(), n || m;) {
		vector<pair <int, int>> p(m);
		for (auto &i: p)
			i.second = -(&i - &p[0] + 1);
		while (n--)
			for (auto &i: p)
				i.first += in();
		sort(p.rbegin(), p.rend());
		for (auto &i: p)
			out(&i == &p[0] ? "" : " ", -i.second);
		outl();
	}
}


Measured memory_bytes: 2340
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;

vector<ll> vec[200000], cntt[200000];
vector< pair<ll, ll> > col[200000];
ll n, p[200000], c[200000], r[200000], cnt[200000];
pair<ll, ll> tb[200000], cb[200000];

ll comb(ll a) {
  return a * (a + 1) / 2;
}

void dfs(ll a) {
  ll i;
  pair<ll, ll> tmp = cb[c[a]];
  tb[a] = tmp, cb[c[a]].first = a;
  for(i = 0; i < vec[a].size(); ++i) if(p[a] != vec[a][i]) 
    cb[c[a]].second = i, p[vec[a][i]] = a, r[vec[a][i]] = r[a] - 1, dfs(vec[a][i]);
  if(a) cnt[p[a]] += cnt[a];
  cb[c[a]] = tmp;
}

int main(void) {
  ll i, j, k, a, b, ans, tmp, now;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) cb[i] = make_pair(-1, 0), cnt[i] = 1;
  p[0] = -1;
  for(i = 0; i < n; ++i) scanf("%lld", &c[i]), c[i]--;
  for(i = 1; i < n; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    vec[b].push_back(a);
  }
  r[0] = 0;
  dfs(0);
  for(i = 0; i < n; ++i) col[c[i]].push_back(make_pair(r[i], i));
  for(i = 0; i < n; ++i) for(j = 0; j < vec[i].size(); ++j) {
    if(p[i] == vec[i][j]) cntt[i].push_back(0);
    else cntt[i].push_back(cnt[vec[i][j]]);
  }
  for(i = 0; i < n; ++i) sort(col[i].begin(), col[i].end());
  for(i = 0; i < n; ++i) {
    ans = comb(n), tmp = n;
    for(j = 0; j < col[i].size(); ++j) {
      now = col[i][j].second;
      for(k = 0; k < cntt[now].size(); ++k) ans -= comb(cntt[now][k]);
      if(tb[now].first != -1) cntt[tb[now].first][tb[now].second] -= cnt[now];
      else tmp -= cnt[now];
    }
    ans -= comb(tmp);
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 63096
// Problem : 
// 			B - String Palindrome
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

bool check(string s)
{
	int i=0;
	int j=sz(s)-1;
	while(i<=j)
	{
		if(s[i]!=s[j])
		return false;
		i++;
		j--;
	}
	return true; 
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s=" ",ss,s1="",s2="";
	cin>>ss;
	int n=sz(s);
	s+=ss;
	l00p(i,1,sz(s))
	{
		//cout<<s[i]<<nl;
		if(i<=(sz(s)-1)/2)
			s1+=s[i];
		else if(i>=(sz(s)+3)/2)
			s2+=s[i];
	}
	//cout<<s1<<" "<<s2;
	if(check(ss)&&check(s1)&&check(s2))
		cout<<"Yes"<<nl;
	else
		cout<<"No"<<nl;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3512
#include<iostream>
#include<string>

int main(){
    std::string N;
    std::cin >> N;
    
    if(N[0] == '7' || N[1] == '7' || N[2] == '7'){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = (int)sc.nextLong();
		long x = sc.nextLong();
		long a[] = new long[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
		}
		
		long ans = 0;
		
		for(int i = 0; i < N - 1; i++) {
			long sum = a[i] + a[i + 1];
			if(sum > x) {
				if(a[i] > x) {
					ans += a[i + 1];
					a[i + 1] = 0;
					ans += a[i] - (x - a[i + 1]);
				} else {
					ans += a[i + 1] - (x - a[i]);
					a[i + 1] = x - a[i];
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 60128
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	solve();
    }

    static void solve(){
	int sum1 = 0;
	double sum2 = 0;
	int cnt = 0;
	while(kbd.hasNext()){
	    String s = kbd.next();
	    String a="";
	    int x, y, i=0;
	    while(!s.substring(i, i+1).equals(",")){
		a += s.substring(i, i+1);
		i++;
	    }
	    x = Integer.parseInt(a);
	    a = "";
	    i++;
	    while(i<s.length()){
		a += s.substring(i, i+1);
		i++;
	    }
	    y = Integer.parseInt(a);

	    sum1 += x*y;
	    sum2 += y;
	    cnt++;
	}

	System.out.println(sum1);
	System.out.printf("%.0f\n", sum2/cnt);
    }
}

Measured memory_bytes: 15312