akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

        int n = in.nextInt(), m = in.nextInt();
        while (n != 0 && m != 0) {
            long[] p = new long[n];
            long[] q = new long[n];
            for (int i = 0; i < m; i++) {
                int s = in.nextInt();
                int k = in.nextInt();
                if (k == 1) {
                    int c = in.nextInt() - 1;
                    q[c] += s;
                    p[c] += s;
                } else {
                    for (int j = 0; j < k; j++) {
                        p[in.nextInt() - 1] += s;
                    }
                }
            }

            long[] pl = new long[n + 1], pr = new long[n + 1];
            for (int i = 0; i < n; i++) {
                pl[i + 1] = Math.max(pl[i], p[i]);
            }
            for (int i = n - 1; i >= 0; i--) {
                pr[i] = Math.max(pr[i + 1], p[i]);
            }
            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans = Math.max(ans, 1 + Math.max(pl[i], pr[i + 1]) - q[i]);
            }
            out.println(ans);

            n = in.nextInt();
            m = in.nextInt();
        }
        out.close();
    }
}



Measured memory_bytes: 162672
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
        }
        for(int l = 1; l*l <= kyori; l++){
          if(l*l == kyori){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 21716
def Bellman_Ford(node_num:int,start:int,goal:int,VWC:list)->list:
    Ans = [float("inf")]*(node_num + 1)
    node = start
    Ans[start] = 0        
    for _ in range(node_num-1):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    Pre = list(Ans)
    for _ in range(node_num-1):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    if Ans[goal] == Pre[goal]:
        return Ans[goal]
    else:
        return float("inf")
def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) for _ in  range(M)]
    newABC = [[a,b,-c] for a,b,c in ABC]
    ans = Bellman_Ford(N,1,N,newABC)
    print(-ans if ans < float("inf") else "inf")
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 47192
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  ll res = 0;
  for (int i = 1; i < n; i++) {
    if(s[i] == 'L' && s[i-1] == 'L') res++;
  }
  for (int i = 0; i < n-1; i++) {
    if(s[i] == 'R' && s[i+1] == 'R') res++;
  }
  res += 2 * k;
  cout << min(n-1, res) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
typedef long long LL;
priority_queue<int, vector<int>, greater<int> >Q;
pair<int,int>P[maxn];
int main()
{
  int n , m;
  scanf("%d%d",&n,&m);
  for(int i = 0 ; i < n ; i++)
  {
    int t;scanf("%d",&t);
    Q.push(t);
  }
  for(int i = 0 ; i < m ; i++)
  {
    int k , t;scanf("%d%d",&P[i].first,&P[i].second);
  }
  sort(P,P+m,[](pair<int,int>A,pair<int,int>B)
  {
    return A.second > B.second;
  });
  int flag = 0;
  for(int i = 0 ; i < m ; i++)
  {
    while(P[i].first--)
    {
      if(P[i].second > Q.top()) Q.pop() , Q.push(P[i].second);
      else {flag = 1;break;}
    }
    if(flag) break;
  }
  LL ans = 0;
  while(!Q.empty())
  {
    ans += Q.top();
    Q.pop();
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 1528
#include <stdio.h>

int main()
{
  int i,a,b,c=0;
  while (scanf("%d %d",&a,&b)){
    if ((a==0) && (b==0))
      break;
    int judge=0;
    if (c==1)
      printf("\n");
    for (i=a;i<=b;i++){
      if (i%400==0){
        printf("%d\n",i);
        judge=1;
        c=1;
      }else if(i%100==0){

      }else if (i%4==0){
        printf("%d\n",i);
        judge=1;
        c=1;
      }
    }
    if (judge==0){
      printf("NA\n");
      c=1;
    }
  }

  return 0;
}

Measured memory_bytes: 616
N = int(input())
 
DP = list(range(N+1))
L = []

i = 1
while True:
    if 6**i > N:
        break
    L.append(6**i)
    i += 1
 
i = 1
while True:
    if 9**i > N:
        break
    L.append(9**i)
    i += 1

for l in sorted(L):
    for j in range(l, N+1):
        DP[j] = min(DP[j], DP[j-l] + 1)

print(DP[-1])

Measured memory_bytes: 40048
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
    int h, w; scanf("%d%d%d", &h, &w);
    vector <string> lines(h);
    vector <int> cols(h, 0), rows(w, 0);
    for(int i=0;i<h;i++)cin >> lines[i];
    for(int col=0;col<h;col++){
        for(int row=0;row<w;row++){
            if(lines[col][row]=='#'){cols[col]=1;rows[row]=1;}        
            }
    }
    for(int col=0;col<h;col++){
        // if(cols[col]==1){
            for(int row=0;row<w;row++){
                if((rows[row]==1)&&(cols[col]==1))printf("%c", lines[col][row]);
            }
            if(cols[col]==1)printf("\n");
        // }
    }
    return 0;
}

Measured memory_bytes: 3676
n, m = map(int, input().split())
uf = [-1]*n
def root(x):
    if uf[x] < 0:
        return x
    uf[x] = root(uf[x])
    return uf[x]
def unite(x,y):
    rx, ry = root(x), root(y)
    if rx == ry:
        return False
    if uf[rx] > uf[ry]:
        rx, ry = ry, rx
    uf[rx] += uf[ry]
    uf[ry] = rx
    return True

for i in range(m):
    x,y,z = map(int, input().split())
    unite(x-1,y-1)
ans = 0
for i in range(n):
    if uf[i] < 0:
        ans += 1
print(ans)

Measured memory_bytes: 67416
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3];
	int sum=0;
for(int i=0;i<3;i++){
	scanf("%d",&a[i]);
}
sort(a,a+3);
printf("%d",a[1]-a[0]+a[2]-a[1]);
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  char op;
  int a, b;
  
  cin>>a;
  while(cin>>op) {
    if(op=='=') { cout<<a<<endl; break; }
    if(op=='+') { cin>>b; a+=b; }
    if(op=='-') { cin>>b; a-=b; }
    if(op=='*') { cin>>b; a*=b; }
    if(op=='/') { cin>>b; a/=b; }
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MAX = 200000;

int main() {
    char C;
    cin >> C;
    for (char i = C; i <= 'z'; i++)
    {
        if (i == C)
        {
            continue;
        }
        cout << i << endl;
        return 0;
    }
    
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
const int MAXN=50+5;
char a[MAXN];int l;
int main()
{
	scanf("%s",a+1);
	l=strlen(a+1);
	for(int i=1;i<l;i++)
		if(a[i]=='A' && a[i+1]=='C')
		{
			printf("Yes");
			return 0;
		}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean roopFlag=false;
		List<Integer>test=new ArrayList<Integer>();
		while(!roopFlag) {
			int x=sc.nextInt();
			if(x!=0) {
				test.add(x);
			}else {
				roopFlag=true;
			}

		}
		for (int i = 0; i < test.size(); i++) {
			System.out.println("Case "+(i+1)+": "+test.get(i));
		}

	}

}



Measured memory_bytes: 43740
a,b = gets.split(" ")
a = a.to_i
b = b.to_i
i = 1
t = ((a-1) * i) + 1
while b > t
    i = i + 1
    t = ((a-1) * i) + 1
end

if b == 1
    puts 0
else
    puts i
end

Measured memory_bytes: 1788
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<algorithm>
#include<vector>
#include<string>
#include<iomanip>
#include<map>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
int main() {
	int N;
	while (cin >> N, N) {
		vector<string> s;
		REP(i,N){
			string t;
			cin >> t;
			s.push_back(t + "1");
			cin >> t;
			s.push_back(t + "0");
		}
		sort(ALL(s));
		int lb = 0;
		int ub = N;
		auto f = [&](int cnt) {
			for (auto &it : s) {
				if (it.back() == '1')cnt--; else cnt++;
				if (cnt < 0)return false;
			}
			return true;

		};
		while (ub - lb > 1) {
			const int mid = (lb + ub) / 2;
			if (f(mid))ub = mid;
			else lb = mid;
		}
		cout << ub << endl;
	}

}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::vector<int> a(5);
	for(int i = 0; i < 5; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a)); reverse(begin(a), end(a));
	
	int sum = 0;
	for(int i = 0; i < a.size(); i++) sum += (a[i] + 9) / 10 * 10;
	
	int ans = 1 << 30;
	for(int i = 0; i < 5; i++) {
		int tmp = (a[i] + 9) / 10 * 10;
		
		ans = std::min(ans, sum - tmp + a[i]);
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int imp = int.Parse(Console.ReadLine());
            if(imp%2==0){
                Console.Write((imp/2)*(imp/2));
            }
            else
            {
                Console.Write((imp/2)*(imp/2+1));
            }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
int bills;
long int howMuch (int a);

int main () {
	int v;
	long int x;
	while (scanf ("%d", &v) != EOF) {
		if (v == -1) break;
		bills = 0;
		x = 4280 - howMuch (v);
		printf ("%ld\n", x);
	}
	
	return 0;
}

long int howMuch (int v) {
	if (v <= 10) {	// volume ? 10
		bills += 1150;
		return bills;
	} else if ((v > 10) && (v <= 20)) {	// 10 < volume ? 20
		if ((v % 10) == 0) {
			bills += 1250;
			return howMuch(v-10);
		} else {
			bills += (v % 10) * 125;
			return howMuch(v-(v%10));
		}
	} else if ((v > 20) && (v <= 30)) {	// 20 < volume ? 30
		if ((v % 10) == 0) {
			bills += 1400;
			return howMuch(v-10);
		} else {
			bills += (v % 10) * 140;
			return howMuch(v-(v%10));
		}
	} else {	// 30 < volume
		if ((v % 30) == 0) {
			bills += (v - 30) * 160;
			return howMuch(30);
		} else {
			bills += (v % 30) * 160;
			return howMuch(v-(v%30));
		}
	}
}

Measured memory_bytes: 600
N=int(input())
ab=[[0 for i in range(9)] for j in range(9)]
for i in range(1,N+1):
  if(i%10!=0):
    s=str(i)
    ab[int(s[0])-1][int(s[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=ab[i][j]*ab[j][i]
print(ans)

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

VI g[MAX];
bool U[MAX];
int del[MAX];
queue<int> q;
int ST[MAX];


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n-1)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		g[x].PB(y);
		g[y].PB(x);

		ST[x]++;
		ST[y]++;
	}

	FOR (i, 0, n)
	{
		if (ST[i] == 1)
		{
			q.push(i);
		}
	}

	while(SZ(q))
	{
	/*	FOR (i, 0, n)
		{
			cout<<i+1;
		}
		cout<<endl;
		FOR (i, 0, n)
		{
			if (del[i]) cout<<"d"; else
			if (U[i]) cout<<"u"; else
			cout<<"-";
		}
		cout<<endl;*/
		int x = q.front();
		q.pop();
		if (del[x]) continue;
		if (U[x]) continue;
		del[x] = true;

		int v = -1;
		FOR (i, 0, SZ(g[x]))
		{
			int to = g[x][i];
			if (del[to]) continue;
			if (U[to]) continue;
			v = to;
			break;
		}

	//	cout<<x<<' '<<v<<endl;

		if (v == -1)
		{
			cout<<"First"<<endl;
			return 0;
		}

		U[v] = true;
		FOR (i, 0, SZ(g[v]))
		{
			int to = g[v][i];
			ST[to]--;
			if (ST[to] == 1)
			{
				q.push(to);
			}
		}
	}

	cout<<"Second"<<endl;

}


Measured memory_bytes: 6784
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int n;
LL memo[31];

LL solve(int cnt){
	if(cnt >= n) return cnt > n? 0 : memo[cnt] = cnt == n;
	if(memo[cnt] != -1) return memo[cnt];
	LL res1 = solve(cnt + 1);
	LL res2 = solve(cnt + 2);
	LL res3 = solve(cnt + 3);
	return memo[cnt] = res1 + res2 + res3;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while(1){
		rep(i,31)
			memo[i] = -1;
		cin >> n;
		if(n == 0) break;
		LL ans = solve(0);
		ans = (ans + 10 - 1) / 10;
		ans = (ans + 365 - 1) / 365;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define N 100005
#define db double
#define ll long long
int n,A[N];ll ans1,ans2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	if(A[n]^2) {puts("-1");return 0;}
	ans1=A[n],ans2=A[n]*2;
	for(int i=n-1;i;i--)
	{
		ans1=((ans1-1)/A[i]+1)*A[i],ans2=((ans2-1)/A[i]+1)*A[i];
		if(ans1==ans2) {puts("-1");return 0;}
		//cout<<i<<" "<<ans1<<" "<<ans2<<"\n";
	}
	cout<<ans1<<" "<<ans2-1<<"\n";
	return 0;
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-
# 整数の入力

n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
h=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

ans_list = [i for i in h if i >= k ]
print(len(ans_list))


Measured memory_bytes: 11908
import sys
sys.setrecursionlimit(100000)

N = int(input())
tree = [[] for i in range(N)]
color = [-1] * N
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append((v-1, w))
    tree[v-1].append((u-1, w))


def dfs(u):
    for v, w in tree[u]:
        if color[v] == -1:
            color[v] = color[u] ^ (w % 2)
            dfs(v)


color[0] = 0
dfs(0)
print('\n'.join(map(str, color)))


Measured memory_bytes: 79340
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int a, k;
		cin >> a >> k;
		while (a % k != 0) {
			int x = a / k + 1;
			a -= max(1, a % k / x) * x;
		}
		ans ^= a / k;
	}
	cout << (ans ? "Takahashi" : "Aoki") << endl;
	return 0;
}

Measured memory_bytes: 256
// 提出時に消す
// package app;

import java.util.Scanner;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        String n = sc.next();
        int check = 0;
        for (int i = 0; i < n.length(); i++) {
            check += Integer.valueOf(n.substring(i, i + 1));
        }

        if (check == 0 || check % 9 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<n+1;i++)
		cin>>a[i];
	vector<ll> v;
	unordered_set<ll> us;
	v.push_back(1);
	us.insert(1);
	int i=0,req;
	while(1){
		//cout<<a[v[i]]<<"  ";
		if(us.count(a[v[i]]) == 0){
			v.push_back(a[v[i]]);
			us.insert(a[v[i]]);
		}
		else {
			req=a[v[i]];
			break;
		}
		i++;
	}
	ll nn=v.size();
	ll bc,ac;
	for(int i=0;i<nn;i++){
		if(v[i]==req){
			bc=i;
			ac=nn-i;
			break;
		}
	}
	//cout<<bc<<" "<<ac<<endl;
	if(k<bc) {
		cout<<v[k]<<endl;
	}
	else{
		k=k-bc;

		ll need=k%ac;
		cout<<v[need+bc]<<endl;
	}

	/*for(ll x :v)
		cout<<x<<"  ";
	cout<<endl;*/

	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

vector<ll> dijkstra(vector<vector<P>> &g,int r){
	priority_queue<P,vector<P>,greater<P>> que;

	int n = g.size();
	vector<ll> dist(n,INF);
	dist[r]=0;
	que.push(P(dist[r],r));
	while(!que.empty()){
		ll dist_from=que.top().first;
		ll node_from=que.top().second;
		que.pop();

		if(dist[node_from]<dist_from) continue;
		for(P p: g[node_from]){
			ll w=p.second;
			int node_to=p.first;
			if(dist[node_to]>dist_from+w){
				dist[node_to]=dist_from+w;
				que.push(P(dist[node_to],node_to));
			}
		}
	}

	rep(i,n){
		if(dist[i]==INF)dist[i] = -1;
	}
	return dist;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<P>> g(n);
	rep(i,m){
		int l,r;
		ll c;
		cin>>l>>r>>c;
		l--,r--;
		g[l].push_back(P(r,c));
	}
	rep(i,n-1){
		g[i+1].push_back(P(i,0LL));
	}

	vector<ll> dist = dijkstra(g,0);

	cout<<dist[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 9340
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int sum=0;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i];
  }
  int avg1=sum/n;
  int avg2 = avg1+1;
  int answer=0;
  int answer2=0;
  for(int i=0;i<n;i++)
  {
   answer+=(a[i]-avg1)*(a[i]-avg1);
   answer2+=(a[i]-avg2)*(a[i]-avg2);
    
  }
  
  cout<<(answer<answer2?answer:answer2);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char a,b,c,d,e,f;
int main(){
	cin>>a>>b>>c>>d>>e>>f;
	cout<<(a=='1')+(b=='1')+(c=='1')+(d=='1')+(e=='1')+(f=='1')<<endl;
	return 0;
}


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

signed main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; ++i) {
    int u, v;
    cin >> u >> v;
    if (n == 1) {
      u = v = min(u, v);
    }
    while (u != v) {
      if (u > v) {
        swap(u, v);
      }
      v = (v + n - 2) / n;
    }
    cout << u << '\n';
  }
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    int ans=0;
    REP(i,n){
        string tmp=to_string(i);
        if((int)tmp.size()%2==1)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int,int>

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int minus_cnt=0;
  int d=INT_MAX;
  rep(i,n){
    cin>>a[i];
    d=min(abs(d),abs(a[i]));
    if(a[i]<0) minus_cnt++;
  }
  ll ans=0;
  rep(i,n) ans+=abs(a[i]); 
  if(minus_cnt%2==0) cout<<ans<<endl;
  else cout<<ans-2*(ll)d<<endl;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const ll INF=1000000000000001;
int main() {
	int n,x,t;
	cin >>n>>x>>t;
	int ans=0;
	ans=ceil((float)n/x)*t;
	cout <<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int vis[20];int n,s;int ans ;


void dfs(int step,int cur,int sum)
{
    if(step == n && sum == s){
        ans++;
        return ;
    }
    if(step == n || sum > s) return;
    for(int i = cur; i <= 9 ; i++){
        if(!vis[i] && sum + i <= s){
            vis[i] = 1;dfs(step + 1,i + 1,sum + i);vis[i] = 0;
        }
    }
}





int main()
{
    ios::sync_with_stdio(0);
    while(cin >> n >> s){
        if(n == 0 && s == 0) break;
        if(s > 45) {
            cout << 0 << endl;continue;
        }
        memset(vis,0,sizeof(vis));ans = 0;
        dfs(0,0,0);cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int,int> pii;
const long long linf=1LL<<62;
const int iinf=1000000009;
const double dinf=1e17;
const int Mod=1e9+9;
typedef long long ll;
typedef long double ld;
const int maxn=1000005;
char s[maxn];
void solve(){
	iossy;
	cin>>s+1;
	int l=strlen(s+1);
	For(i,1,l) {
		if(s[i]=='1') s[i]='9';
		else if(s[i]=='9') s[i]='1';
	}
	cout<<s+1<<endl;
}
int main(){
	int t=1;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 256
const koch = (n, p1, p2) => {
  if (n === 0) return;

  const th = Math.PI * 60.0 / 180.0;

  const s = {
    x: (2.0 * p1.x + 1.0 * p2.x) / 3.0,
    y: (2.0 * p1.y + 1.0 * p2.y) / 3.0,
  };
  const t = {
    x: (1.0 * p1.x + 2.0 * p2.x) / 3.0,
    y: (1.0 * p1.y + 2.0 * p2.y) / 3.0,
  };
  const u = {
    x: (t.x - s.x) * Math.cos(th) - (t.y - s.y) * Math.sin(th) + s.x,
    y: (t.x - s.x) * Math.sin(th) + (t.y - s.y) * Math.cos(th) + s.y,
  };

  koch(n - 1, p1, s);
  console.log(`${s.x} ${s.y}`);
  koch(n - 1, s, u);
  console.log(`${u.x} ${u.y}`);
  koch(n - 1, u, t);
  console.log(`${t.x} ${t.y}`);
  koch(n - 1, t, p2);
};

const proc = (nStr) => {
  const p1 = {x: 0, y:0};
  const p2 = {x: 100, y:0};

  console.log(`${p1.x} ${p1.y}`);
  koch(Number(nStr), p1, p2);
  console.log(`${p2.x} ${p2.y}`);
};

let inputStr = '';
process.stdin.on('data', (input) => { inputStr += input; });
process.stdin.on('data', () => { proc(inputStr); });


Measured memory_bytes: 20720
A, B, C = map(int, input().split())
K = int(input())

ans = "No"
for a in range(K+1):
  for b in range(K+1):
    for c in range(K+1):
      if a+b+c<=K and (A<<a)<(B<<b)<(C<<c):
        ans = "Yes"
print(ans)


Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<string, char>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<P> s;
    s.emplace_back("", 'a' - 1);
    REP(i, 0, n) {
        vector<P> ss;
        for (auto &tt : s) {
            char mx = tt.second + 1;
            for (char c = 'a'; c <= mx; c++) {
                ss.emplace_back(tt.first + c, max(c, tt.second));
            }
        }
        s = ss;
    }
    for (auto &ss : s) {
        cout << ss.first << endl;
    }
    dump(s.size());
    return 0;
}


Measured memory_bytes: 10984
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main(){
	int n,W;
	scanf("%d%d",&n,&W);
	long long int i,j,dp[W+1],w[n+1],v[n+1];
	for(i=1;i<=n;i++)
		scanf("%lld%lld",&w[i],&v[i]);
	for(i=0;i<=W;i++)
		dp[i]=0;
	for(i=1;i<=n;i++)
		for(j=W;j>=w[i];j--)
			dp[j] = max(v[i]+dp[j-w[i]],dp[j]);
	printf("%lld\n",dp[W] );
	return 0;
}


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

void solve() {
	int n;
	cin>>n;
	int a, b, c;
long long cnt = 0;
int flag  = 0;
	for(int a = 1; a < n; a++) {
		for(int b = 1; b<n; b++) {
			if(a*b >= n) break;
			else cnt++;
		}
	}
	cout<<cnt;
}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

ll battles(ll hp){
  if(hp==1) { return 1; }
  else {
    ll wk_l = hp/2;
     return battles(wk_l)*2 + 1;}
}

int main() {
  ll H; cin >> H; //元ＨＰ：１～10^12

  cout << battles(H) << endl;

}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;
int n, c;

vector<vector<int>> cost;
vector<vector<int>> field;


vector<vector<int>> cost_init(){
  vector<vector<int>> cost(c, vector<int>(c, 0));
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin >> cost[i][j];
    }
  }
  return cost;
}

vector<vector<int>> field_init(){
  vector<vector<int>> field(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> field[i][j];
      field[i][j]--;
    }
  }
  return field;
}


vector<int> dfs1(){
  vector<int> cost_set(c, 0);
  for (int k = 0; k < c; k++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int index = (i + j) % 3;
        if(index == 0){
          int now_color = field[i][j];
          sum += cost[now_color][k];
        }
      }
    }
    cost_set[k] = sum;
  }
  return cost_set;
}

vector<int> dfs2(){
  vector<int> cost_set(c, 0);
  for (int k = 0; k < c; k++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int index = (i + j) % 3;
        if(index == 1){
          int now_color = field[i][j];
          sum += cost[now_color][k];
        }
      }
    }
    cost_set[k] = sum;
  }
  return cost_set;
}

vector<int> dfs3(){
  vector<int> cost_set(c, 0);
  for (int k = 0; k < c; k++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int index = (i + j) % 3;
        if(index == 2){
          int now_color = field[i][j];
          sum += cost[now_color][k];
        }
      }
    }
    cost_set[k] = sum;
  }
  return cost_set;
}

int main(){
  cin >> n >> c;
  cost = cost_init();
  field = field_init();
  vector<int> cost_set1 = dfs1();
  vector<int> cost_set2 = dfs2();
  vector<int> cost_set3 = dfs3();

  // print(cost_set1);
  // print(cost_set2);
  // print(cost_set3);

  int res = INT_MAX;
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      for (int k = 0; k < c; k++) {
        if(i == j || j == k || i == k) continue;
        res = min(res, cost_set1[i] + cost_set2[j] + cost_set3[k]);
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];

//int a[100005];

 int main(){

 long long n; cin>>n;

  int a[n+5];
 for(int i=0;i<n;i++)
    cin>>a[i];

  int searchs = 1,cnt=0;

  for(int i=0;i<n;i++){

    if(a[i] == searchs)
        searchs++;
    else
        cnt++;
  }

  if(searchs == 1 && cnt)
    cout<<"-1"<<endl;
  else
    cout<<cnt<<endl;


return 0;
 }


Measured memory_bytes: 4384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
#define INF 1000000000
int field[100][100];
int dx[] = {0,0,1,-1},dy[] = {1,-1,0,0};
int n,m;
int func(int x,int y,int cnt){
	if(field[y][x] == 0)return cnt - 1;
	if(x < 0 || x >= n || y < 0 || y >= m)return cnt-1;
	field[y][x] = 0;
	int ret = cnt;
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i],ny = y + dy[i];
		ret = max(ret,func(nx,ny,cnt+1));
	}
	field[y][x] = 1;
	return ret;
}
int main(){
	while(scanf("%d%d",&n,&m),(n|m)){
		memset(field,0,sizeof(field));
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				scanf("%d",&field[i][j]);
			}
		}
		int ans = 0;
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				if(field[i][j] == 1){
					ans = max(ans,func(j,i,1));
				}
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
int main(){
	int a,b,c,d,train[100];
	b=0;
	c=0;
	
	int g;
	int cont = 0;
	
	for(a=0;a<1000;a++){
		if(scanf("%d",&g)==-1){
			break;
		}
		
		if(g != 0){
			train[cont] = g;
			cont++;
		}
		else{
			printf("%d\n",train[cont-1]);
			cont--;
		}
		/*
		if(cont == 0){
			break;
		}
		*/
		/*
		if(train[a]==0){
			c++;
		}else{
			b++;
		}
		if(b==c){
		break;
		} 
		*/
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main{

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

        // input
        int num = scan.nextInt();
        List<Integer> memory = new ArrayList<>();
        memory.add(num);

        while(true){
            if(num % 2 == 0){
                num /= 2;
            } else {
                num = num * 3 + 1;
            }
            if(memory.contains(num)){
                System.out.println(memory.size() + 1);
                break;
            } else {
                memory.add(num);
            }
        }

    }
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=550;
int n,k;
ll a[N];
priority_queue<ll,vector<ll>,greater<ll> >q;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    ll ans=0;
    for(int i=0;i<=k;i++)
        for(int j=0;i+j<=min(k,n);j++)
    {
        for(int h=1;h<=i;h++)
            q.push(a[h]);
        for(int h=1,t=n;h<=j;h++)
        {
            q.push(a[t]);
            t--;
        }
        int p=k-i-j;
        ll res=0;
        while(!q.empty()&&p&&q.top()<0)
        {
            q.pop();
            p--;
        }
        while(!q.empty())
        {
            res+=q.top();
            q.pop();
        }
        ans=max(ans,res);
    }
    printf("%lld\n",ans);
} 

Measured memory_bytes: 384
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b;
int32_t main(){
cin>>a>>b;
cout<<max(a+b,max(a-b,a*b));
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


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

	ll a = X / 500;

	X %= 500;

	ll b = X / 5;

	cout << a * 1000 + b * 5;

	system("PAUSE");
}


Measured memory_bytes: 504
h,w= map(int, input().split())
s = []
a = []
for i in range(h):
    temp = input()
    if '#' in temp:
        s.append(temp)
for j in range(w):
    flag = False
    for i in s:
        if i[j] == '#':
            flag = True
            break
    a.append(flag)
s = ["".join(j[i] for i in range(w) if a[i]) for j in s]
 
for x in s:
    print(x)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;

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

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
using namespace std;
int main () {
	int n;
	cin >> n;
	int a[n];
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	for (int i=2; i<n; i++) {
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N;
    int[] A,M;
    private void solve() {
        N = nextInt();
        A = nextIntArray(N);

        M = new int[1000000 + 1];
        for(int i = 0;i < N;i++) {
            M[A[i]]++;
        }

        int ans = 0;
        for(int i = 0;i < N;i++) {
            boolean ok = true;
            M[A[i]]--;
            for(int j = 1; j * j <= A[i];j++) {
                if (A[i] % j == 0) {
                    if (M[A[i] / j] > 0 || M[j] > 0) {
                        ok = false;
                        break;
                    }
                }
            }
            M[A[i]]++;

            if (ok) {
                ans++;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

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

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

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

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

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

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

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

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

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

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 51748
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
#define mod 1000000007
#define fi first
#define se second
#define be begin()
#define en end()
#define re reverse
#define Set setprecision
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define No cout<<"No\n"
#define Yes cout<<"Yes\n"
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
    return max(a,b)-min(a,b);
}
template<typename T> T lcm(T a,T b){//最小公倍数
    return (a*b)/gcd(a,b);
}
int gcd(int a,int b){//最大公約数
    int c=a%b;
    while(true){
	if(c==0) break;
	a=b;
	b=c;
	c=a%b;
    }
    return b;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    int s,c;
    bool num[10]={};
    int date[10]={};
    bool f=true;
    cin>>n>>m;
    for(int i=0;i<9;i++){
	date[i]=-1;
    }
    for(int i=0;i<m;i++){
	cin>>s>>c;
	if(num[s]==1){
	    if(date[s]!=c) f=false;
	}
	else{
	    num[s]=1;
	    date[s]=c;
	}
    }
    if(n==1&&m==0){
	cout<<"0";
    }
    else{
	if(f==true&&date[1]!=0){
	    if(num[1]==1) cout<<date[1];
	    else cout<<"1";
	    for(int i=2;i<=n;i++){
		if(num[i]==1) cout<<date[i];
		else cout<<"0";
	    }
	}
	else{
	    if(date[1]==0&&n==1) cout<<"0";
	    else cout<<"-1";
	}
    }
    cout<<"\n";
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from collections import Counter

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()


H, W = in_intlist()
a_list = []
for _ in range(H):
    s = in_strings()
    a_list.extend(list(s))

a_count = Counter(a_list)
sym4 = [0, 0]
sym2 = [0, 0]
sym1 = [0, 0]
sym4[0] = (H//2) * (W//2) 
sym2[0] = (H%2) * (W//2) + (H//2) * (W%2)
sym1[0] = (H%2) * (W%2)

for i in a_count.values():
    sym4[1] += i // 4
    sym2[1] += (i % 4) // 2
    sym1[1] += i % 2

if sym4[1] >= sym4[0]:
    sym2[1] += 2 * (sym4[1] - sym4[0])
    if sym2[1] == sym2[0]:
        print('Yes')
        exit()

print('No')




Measured memory_bytes: 3444
#include<iostream>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int num = (n / 2) + (n % 2);
    double ans;
    ans = (double)num / (double)n;
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N, K, *I = map(int, open(0).read().split())
    A, F = I[:N], I[N:]

    A.sort()
    F.sort(reverse=True)

    ng, ok = -1, 10 ** 12
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if sum(max(0, a - mid // f) for a, f in zip(A, F)) <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()


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

using ll = long long;
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)
#define IN(i,a,b) (a<=i&&i<=b)

const int mod = 1e9+7;

ll modpow(ll a, ll b) {
	return b?modpow(a*a,b/2)*(b&1?a:1)%mod:1;
}

void add(ll &a, ll b) {
	if (b>=mod) b%=mod;
	a += b;
	if (a>=mod) a-=mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n,k; cin>>n>>k;
	int a[k+1],b[k+1];
	f(i,0,k) cin>>a[i]>>b[i];
	f(i,0,k) a[i]--,b[i]--;
	ll g[2*n+1];
	f(i,0,2*n+1) g[i] = i<2?i:g[i-2]*i%mod;
	fr(i,1,2*n+1) g[i] = g[i-1];
	g[0] = 1;
	ll z[2*n];
	fill(z,z+2*n,1);
	f(i,0,k) z[a[i]] = z[b[i]] = 0;
	f(i,1,2*n) z[i] += z[i-1];
	ll dp[2*n][2*n];
	f(i,0,2*n) f(j,0,2*n) dp[i][j] = 0;
	ll ans = 0;
	f(l,0,2*n) f(i,0,2*n-l) {
		int j = i+l;
		dp[i][j] = 0;
		bool found = 0;
		f(x,0,k) found |= IN(a[x],i,j)^IN(b[x],i,j);
		if (found) continue;
		int x = z[j] - (i?z[i-1]:0);
		int y = 2*n-2*k-x;
		add(dp[i][j],g[x]);
		f(kk,i+1,j) {
			int zz = x-(z[kk]-(i?z[i-1]:0));
			add(dp[i][j],mod-dp[i][kk]*g[zz]%mod);
		}
		add(ans,dp[i][j]*g[y]);
	}
	cout << ans << endl;


#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main() {
	ll  n,x;cin >>n>> x;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i)cin >>a[i];
	ll sum =0;
	ll ans=0;
	for(int i = 0; i < n; ++i){
		sum +=a[i];
		if(sum>x){
			a[i] -=(sum-x);
			ans+=(sum-x);
                }
                sum=a[i];
      }
      cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

static const int N = 100;

int main(){
  int M[N][N];
  int n, i, j, u, k, v;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j){
	printf(" ");
      }
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1001001001;

bool used_1[2505];
bool used_n[2505];
vector<int> graph[2505];
vector<int> rev[2505];
vector<P> edges(5005);
vector<int> cost(5005);
vector<int> dist(2505, INF);
int n, m, p;

void reachable_from_1(int u){
    if(used_1[u])   return;
    used_1[u] = true;
    for(int v : graph[u]){
        reachable_from_1(v);
    }
    return;
}

void reachable_to_n(int u){
    if(used_n[u])   return;
    used_n[u] = true;
    for(int v : rev[u]){
        reachable_to_n(v);
    }
    return;
}

int bellman_ford(int s, int t){
    dist[s] = 0;
    bool update = false;
    for(int i = 0; i < n; ++i){
        update = false;
        for(int j = 0; j < m; ++j){
            int u = edges[j].first;
            int v = edges[j].second;
            if(dist[u] == INF)  continue;
            if(!used_1[u] || !used_1[v] || !used_n[u] || !used_n[v])    continue;
            if(dist[v] > dist[u] + cost[j]){
                dist[v] = dist[u] + cost[j];
                update = true;
            }
        }
    }
    if(update)  return -1;
    return max(0, -dist[t]);
}

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

    cin >> n >> m >> p;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b >> cost[i];
        --a, --b;
        cost[i] -= p;
        cost[i] *= -1;
        graph[a].push_back(b);
        rev[b].push_back(a);
        edges[i] = P(a, b);
    }
    reachable_from_1(0);
    reachable_to_n(n-1);
    cout << bellman_ford(0, n-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[210],s;
int main(){
	int i,n;
	scanf("%d",&n);
	for(i=1;i<=n*2;++i)scanf("%d",a+i);
	sort(a+1,a+n*2+1);
	for(i=1;i<=n;++i)s+=a[i*2-1];
	printf("%d",s);
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

sPY = sorted(PY, key=lambda py: (py[0], py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[(p, y)] = i
    i += 1

for p, y in PY:
    i = d[(p, y)]
    print("{0:06}{1:06}".format(p, i))


Measured memory_bytes: 34948