akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
ll mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> f(10);
	vector<vector<int>> p(n,vector<int>(11));
	vector<int> a(n);
	rep(i,n){
		rep(j,10){
			cin >> f[j];
		}
		a[i]=f[0];
		rep(j,9){
			a[i]*=2;
			a[i]+=f[j+1];
		}
	}
	rep(i,n){
		rep(j,11){
			cin >> p[i][j];
		}
	}
	ll ans=-1000000000,sum=0,cnt=0,x=0;
	for(int i=0;i<(1<<10);++i){
		if(((1<<10)-1)&i==0) continue;
		rep(j,n){
			x=a[j]&i;
			while(x>0){
				cnt+=x%2;
				x/=2;
			}
			sum+=p[j][cnt];
			cnt=0;
		}
		ans=max(ans,sum);
		sum=0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, y = map(int, input().split())

def search():
    for i in range(n+1):
        for j in range(n-i+1):
            k = (n - i - j)
            if i * 10000 + j * 5000 + 1000 * k == y:
                return i, j, k
    return -1, -1, -1
print(*search())

Measured memory_bytes: 3060
#include<stdio.h>
#define N 100001
  
typedef struct
{
  char mark;
  int num, id;
}Cards;
  
Cards A[N];
void QuickSort(int, int);
int Partition(int, int);
  
int main()
{
  int n, i, key, flag = 0;
  char temp;
  scanf("%d%c", &n, &temp);
  for (i = 0; i < n; i++)
    {
    scanf("%c%d%c", &A[i].mark, &A[i].num, &temp);
    A[i].id = i;
  }
  QuickSort(0, n-1);
  for (i = 1; i < n; i++)
    if ((A[i].num == A[i-1].num) && (A[i].id<=A[i-1].id))
      {
      printf("Not stable\n");
      flag = 1;
      break;
    }
  
  if (flag == 0)
    printf("Stable\n");
  
  for (i = 0; i < n; i++)
    printf("%c %d\n", A[i].mark, A[i].num);
   
  return 0;
}

void QuickSort(int p, int r)
{
  int q;
  
  if (p < r)
    {
    q = Partition(p, r);
    QuickSort(p, q-1);
    QuickSort(q+1, r);
  }
}
  
int Partition(int p, int r)
{
  int x, i, j;
  Cards temp;
  x = A[r].num;
  i = p-1;
  
  for (j = p; j <= r-1;j++)
    if (A[j].num <= x)
      {
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}
  

Measured memory_bytes: 1780
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

inline int getsg(int x, int k) {
    if (x % k == 0) return x / k;
    int d = x / k, t = (x - k * d - 1) / (d + 1) + 1;
    return getsg(x - t * (d + 1), k);
}

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    int n, ans = 0, x, k;
    cin >> n;

    while (n--) {
        scanf("%d%d", &x, &k);
        ans ^= getsg(x, k);
    }

    if (ans == 0) puts("Aoki");
    else puts("Takahashi");
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;C*=2;
    int ans;
    if(X>=Y){
        ans=X*C;
        ans=min(ans,C*Y+(X-Y)*A);
        ans=min(ans,A*X+B*Y);
    }
    else{
        ans=Y*C;
        ans=min(ans,C*X+(Y-X)*B);
        ans=min(ans,A*X+B*Y);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n,x,y = map(int,input().split())

dis = [0] * (n-1)

# 頂点iから頂点jまでの距離
for i in range(1, n):
    for j in range(i+1, n+1):
        if i <= x:
            if j <= x:
                tmp = j-i
            if x < j < y:
                tmp = (x-i) + min(j-x, y-j+1)
            if j >= y:
                tmp = (x-i) + (j-y) + 1

        if x < i < y:
            if x < j < y:
                tmp = min(j-i, (i-x)+(y-j)+1)
            if j >= y:
                tmp = min(i-x+1, y-i) + (j-y)
        
        if i >= y:
            tmp = j-i

        dis[tmp-1] += 1

for ans in dis:
    print(ans)



Measured memory_bytes: 47580
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  string S, T;
  cin >> S >> T;
  int n = S.size();
  rep(i, 0, n) {
    char tail = S[n - 1];
    string r = tail + S.substr(0, n - 1);
    if (r == T) {
      cout << "Yes" << endl;
      return 0;
    }
    S = r;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

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

int main() {

    int A, B, K;
    cin >> A >> B >> K;
    int tmp = 0;
    int i = min(A, B) + 1;
    while(tmp < K){
        i--;
        if (A % i == 0 && B % i == 0){
            tmp++;
        }
        
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2+1 if a[-1]%2==1 else a[-1]//2
m = 10**9
x = 0
for i in range(N-1):
  if abs(a[i]-X)<m:
    m = abs(a[i]-X)
    x = i
print(a[-1],a[x])

Measured memory_bytes: 66348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
set<ll > G[n];
ll t[n] = {};
rep(i, n-1)
{
    ll a,b;
    cin >> a>>b;
    G[a-1].insert(b-1);
    G[b-1].insert(a-1);
}
ll sum=0;
rep(i,n){
    cin >> t[i];
    sum+=t[i];
}
ll an[n]={};
sort(t,t+n);
ans=sum-t[n-1];
//startきめる
vector<ll> str;

rep(i,n){
    if(G[i].size()==1){
        str.push_back(i);
    }
}
//操作開始
ll con=0;
ll con2=0;
ll see=str[con2];
con2++;
an[see]=t[con];
con++;



while(con<n){
    
//そこに数字を入れてよいか
ll too=*G[see].begin();
//cout << see+1<<" "<<too+1 <<" "<<G[too].size()<< endl;
if(G[too].size()<=2){
    bool aa=G[see].erase(too);
    bool a=G[too].erase(see);
    see=too;
    an[too]=t[con];
    con++;
    //cout << aa<<a<< endl;
}
else{
    bool aa=G[see].erase(too);
    bool a=G[too].erase(see);
    //cout << aa<<a << endl;
    see=str[con2];
    con2++;
    an[see]=t[con];
    con++;
}
}
cout << ans << endl;
rep(i,n){
    cout << an[i] << " ";
}
cout  << endl;
return 0;
}

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

#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define endl "\n"

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep(i,n)      for(i = 0; i < n; i++)
#define repit(it,type)  for(auto it = type.begin(); it != type.end(); it++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int main()
{
    IOS
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll i,n,k,cnt=0;

    cin>>k;

    if(k==1||k==7)
    	cout<<1<<endl;
    else
    {
    	n = 7;
    	for(i = 2; i <= 1100000; i++)
    	{
    		n = n*10+7;
    		n%=k;

    		if(n==0)
    		{
    			cout<<i<<endl;
    			return 0;
    		}
    	}
    	cout<<-1<<endl;

    }

     return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		String[] strArray = new String[n];
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		PriorityQueue<Node> pq = new PriorityQueue<Node>();
		
		for(int i = 0; i < n; i++) {
			strArray[i] = br.readLine();
			if(!map.containsKey(strArray[i])) {
				map.put(strArray[i], 1);
			}
			else {
				map.put(strArray[i], map.get(strArray[i]) + 1);
			}
			
			pq.add(new Node(strArray[i], map.get(strArray[i])));
		}
		
		int maxCount = pq.peek().count;
		
		while(!pq.isEmpty() && maxCount == pq.peek().count) {
			System.out.println(pq.poll().str);
		}
	}	

}

class Node implements Comparable<Node>{
	String str;
	int count;
	
	Node(String str, int count){
		this.str = str;
		this.count = count;
	}
	
	@Override
	public int compareTo(Node node) {
		// TODO Auto-generated method stub
		return node.count == this.count ? this.str.compareTo(node.str) : node.count - this.count;
	}
	
}


Measured memory_bytes: 76972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}



int main() {
	int n,d,x; cin >> n >> d >> x;
	std::vector<int> A(n);
	for (int i = 0; i < n; ++i) cin >> A[i];
	for (int i = 0; i < n; ++i) A[i] = (d-1)/A[i] + 1;

	int sum;
	for (int i = 0; i < n; ++i)
	{
		sum += A[i];
	}
	cout << x + sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b,A, B;
	while (cin >> a >> b)
	{
		int c = a;
		int d = b;
		if (a <= b)
		{
			while (a != 0)
			{
				int r = b%a;
				b = a;
				a = r;
			}
			A = b;
		}
		else
		{
			while (b != 0)
			{
				int r = a%b;
				a = b;
				b = r;
			}
			A = a;
		}
		B = c / A*d;
		cout << A << " " << B << endl;
	}
	return 0;
}

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

int  N, A[128];

int main() {
	A[0] = 1;
	for (int i = 1; i <= 32; ++i) {
		A[i] = A[i - 1];
		if (i >= 2)
			A[i] += A[i - 2];
		if (i >= 3)
			A[i] += A[i - 3];
	}
	while (cin >> N && N > 0 && N <= 30)
		cout << ((A[N]+9)/10 + 364) / 365 << endl;

	}

Measured memory_bytes: 1160
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]


for a, b in AB:
    distance = float('inf')
    ans = 0
    for i in range(M):
        newDistance = abs(a - CD[i][0]) + abs(b - CD[i][1])
        if distance > newDistance:
            distance = newDistance
            ans = i+1
    print(ans)

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int x,y;

    x = a * b;
    y = c * d;

    if(x > y){
        cout << x << endl;
    } else {
        cout << y << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using System.Numerics;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int n = NextInt;
            var a = LongList;

            var result = new BigInteger(1);
            for (int i = 0; i < n; i++)
            {
                result = result * a[i];
                if (result > 1000000000000000000L || result < 0) result = -1;
            }
            System.Console.WriteLine(result);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 49084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	queue<int> a[n];
	rep(i,n){
		rep(j,n-1){
			int aa; cin >> aa;
			a[i].push(--aa);
		}
	}
	vector<int> v(n); rep(i,n) v[i] = i;
	for(int d = 1; ; ++d) {
		if(v.size() == 0) {
			cout << d - 1 << endl;
			return 0;
		}
		bool used[n] = {};
		bool flg = false;
		vector<int> next;
		for(int i : v) {
			if(a[i].empty()) {
				continue;
			}
			if(used[i]) {
				next.push_back(i);
				continue;
			}
			int b = a[i].front();
			if(not used[b] and i == a[b].front()) {
				a[i].pop();
				a[b].pop();
				used[i] = used[b] = true;
				flg = true;
				if(!a[i].empty()) {
					next.push_back(i);				
				}
				if(!a[b].empty()) {
					next.push_back(b);				
				}
			}
		}
		v = next;
		if(!flg) {
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 14052
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		int count  = 0;
		for (int i = 0; i < A.length; i++) {
			if (i % 2 == 0 && A[i] % 2 != 0)count++;
		}
		System.out.println(count);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

int main (void) {
  int K;
  cin >> K;
  
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[K-1] << endl;
  
  return 0;
  
}
  


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

signed main(){
    int n,m;
    cin >> n >> m;
    priority_queue<int> que;
    rep(i,n){
        int a;
        cin >> a;
        que.push(a);
    }
    rep(i,m){
        int v = que.top();
        que.pop();
        v=v/2;
        
        que.push(v);
    }
    int ans=0;
    while(!que.empty()){
        int p=que.top();
        que.pop();
        ans+=p;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		String Comparisonn;
		if(a>b){
		     Comparisonn = ">";
		}else if(a<b){
		     Comparisonn = "<";
		}else{
		     Comparisonn = "==";
		}
		
		System.out.printf("a %s b\n", Comparisonn);
	}
}	



Measured memory_bytes: 26376
use std::io::{self, BufRead};
use std::cmp::max;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut ones: Vec<usize> = vec![0; 20];
  let mut zeros: Vec<usize> = vec![0; 20];
  let mut count: usize = 0;
  for i in 0..n {
    let mut l: usize = 0;
    for k in 0..20 {
      let is_one = xs[i] & (1 << k) != 0;
      l = max(l, if is_one { ones[k] } else { zeros[k] });
      if is_one {
        zeros[k] = ones[k];
        ones[k] = i + 1;
      }
    }
    count += i - l + 1;
  }
  println!("{}", count);
}

Measured memory_bytes: 10492
// A Dynamic Programming based 
// C# program to find minimum 
// number operations to 
// convert str1 to str2 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{
    static int min = int.MaxValue;
    public static void Main()
    {
        var input1 = Console.ReadLine().Split(' ');
        var A = int.Parse(input1[0]);
        var B = int.Parse(input1[1]);
        var M = int.Parse(input1[2]);
        var AA = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var BB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        for (int i = 0; i < M; i++)
        {
            var MM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            NiceShopping(AA, BB, MM);
        }

        var miA = AA.Min();
        var miB = BB.Min();
        var miMb = miA + miB;
        if (miMb < min)
            Console.Write(miMb);
        else
            Console.Write(min);
    }

    static void NiceShopping(int[] rf, int[] mic, int[] dis)
    {
        var r = rf[dis[0]-1];
        var m = mic[dis[1]-1];
        var val = r + m - dis[2];
        min = Math.Min(min, val);
    }





}



Measured memory_bytes: 36444
// coded by- mrNOBODY_

#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin.sync();

    int x,y;
    cin>>x>>y;
    int c,t;
    c = ((4*x) -y)/2;
    t = (y- (2*x))/2;

    if((c+t == x )&&(c>=0)&&(t>=0))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 3652
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    A = [0]*102
    cnt = 0
    res = float('Inf')
    for n in range(N):
        A[P[n]] += 1
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    print(man)
else:
    print(X)

Measured memory_bytes: 9048
A = [int(input()) for i in range(5)]

def make_ten(i):
    ans = 0
    while i % 10 != 0:
        i += 1
        ans += 1
    return [i,ans]

anslist = []
diflist = []
for i in range(5):
    anslist.append(make_ten(A[i])[0])
    diflist.append(make_ten(A[i])[1])

print(sum(anslist)-max(diflist))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

ll dp[100010];
ll massiv[100010];
ll n;

int main(){
FLASH;
cin>>n;
for(ll i=1;i<=n;i++)cin>>massiv[i];
for(ll i=2;i<=n;i++)
{
  dp[i]=LLONG_MAX;
  if(i-1>0)dp[i]=dp[i-1]+abs(massiv[i]-massiv[i-1]);
  if(i-2>0)dp[i]=min(dp[i-2]+abs(massiv[i]-massiv[i-2]),dp[i]);	
}
cout<<dp[n]<<endl;






return 0;
} 


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<((a[1]-a[0])/2+2*((a[1]-a[0])%2)+(a[2]-a[1])) <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
int inf = 1000000000;
int main() {
	int d, g, p[11], c[11], ans = inf;
	cin >> d >> g;
	for (int i = 0; i < d; i++)cin >> p[i] >> c[i];
	for (int i = 0; i < (1 << d); i++) {
		int k = 0, cnt = 0;
		for (int j = 0; j < d; j++) {
			if ((i >> j) & 1) {
				cnt += p[j] * (j + 1) * 100 + c[j];
				k += p[j];
			}
		}
		for (int j = d - 1; j >= 0; j--) {
			if (!((i >> j) & 1)){
				if (g > cnt) {
					if ((g - cnt + 100 * (j + 1) - 1) / (100 * (j + 1)) <= p[j]) {
						k += ((g - cnt + 100 * (j + 1) - 1) / (100 * (j + 1)));
						cnt += ((g - cnt + 100 * (j + 1) - 1) / (100 * (j + 1))*((j + 1) * 100));
					}
					else goto age;
				}
				break;
			}
		}
		if (ans > k&&g - cnt <= 0)ans = k;
	age:;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

bool dp[1000001];
int main(){
	int n,a,b;
	while(~scanf("%d %d %d",&n,&a,&b)){
		if(n==0 && a==0 && b==0) break;

		memset(dp,0,sizeof(dp));

		dp[0] = true;

		for(int i=0;i<=n;i++){
			if(i+a <= 1000000) dp[i+a] |= dp[i];
			if(i+b <= 1000000) dp[i+b] |= dp[i];
		}

		int c=0;
		for(int i=0;i<=n;i++){
			if(!dp[i]){
				c++;
			}
		}

		printf("%d\n",c);
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int lli;

int main(){
    int flag1;
    lli N, *H, tmp, i;
    scanf("%lld", &N);
    H = (lli *)malloc(sizeof(lli)*N);
    for(i=0; i<N; i++)scanf("%lld", &H[i]);
    if(i==0)
    {
        fprintf(stdout,"Yes\n");
        free(H);
        return 0;
    }
    flag1 = 0;

    for(i=0; i<N-1; i++)
    {
        tmp = H[i+1]-H[i];
        if(tmp>=1)
        {
            flag1 = 0;
            continue;
        }else if(tmp==0)continue;
        else if(tmp == -1)
        {
            if(flag1 == 1)
            {
              flag1 = 2;
              break;              
            }
            flag1 = 1;
        }else{
            flag1 = 2;
            break;
        }
    }    
    if(flag1 == 2)fprintf(stdout,"No\n");
    else fprintf(stdout,"Yes\n");
    free(H);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main (){
    long N, m;
    cin >> N >> m;
    long a[m];
    long ans = 1;
    for (int i = 0; i < m;i++){
        cin >> a[i];
    }
    long list[N+3];
    list[0] = 1;
    list[1] = 1;
    for (int i = 0; i <= N;i++){
        list[i + 2] = (list[i + 1] + list[i]) % 1000000007;
    }
    long now = 0;
    for (int i = 0; i < m;i++){
        int step;
        step = a[i] - now - 1;
        if (step < 0){
            cout << 0 << endl;
            return 0;
        }
        ans = ans * list[step] % 1000000007;
        now = 1+a[i];
    }
    ans = ans * list[N - now]% 1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  string S, T;
  cin >> S >> T;
  int count = 0;
  for (int i = 0; i < S.length(); ++i){
    if (S[i] != T[i]) {
      ++count;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 3436
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        int C = Integer.parseInt(scanner.next());
        int X = Integer.parseInt(scanner.next());
        scanner.close();

        int count = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    int sum = i * 500 + j * 100 + k * 50;
                    if (sum == X) count++;
                }
            }
        }

        System.out.println(count);
    }
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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 gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    COMint();
    int N=in();
    int M=in();
    ll ans;
    if(N==M){
        ans=2*fac[N]*fac[M]%MOD;
    }else if(N-M==1||M-N==1){
        ans=fac[N]*fac[M]%MOD;
    }else{
        ans=0;
    }
    print(ans);
}

Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

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

    int cnt = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
int dp[10010][100][2];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	string k;
	int d;
	cin >> k >> d;
	int n = k.size();
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < d; j++) {
			int c = k[i - 1] - '0';
			dp[i][(j + c) % d][0] += dp[i - 1][j][0];
			dp[i][(j + c) % d][0] %= mod;
			for (int k = 0; k < c; k++) {
				dp[i][(j + k) % d][1] += dp[i - 1][j][0];
				dp[i][(j + k) % d][1] %= mod;
			}
			for (int k = 0; k < 10; k++) {
				dp[i][(j + k) % d][1] += dp[i - 1][j][1];
				dp[i][(j + k) % d][1] %= mod;
			}
		}
	}
	cout << (dp[n][0][0] + dp[n][0][1] + mod - 1) % mod << endl;
}

Measured memory_bytes: 16000
/// [Amberjack] CUT BEGIN
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define __GET_REP_MACRO(_1,_2,_3,NAME,...) NAME
#define __REP0(i,n) for(_loop_int i=0;i<(n);++i)
#define __REP1(i,a,b) for(_loop_int i=(a);i<(b);++i)
#define __REPR0(i,n) for(_loop_int i=(n)-1;i>=0;--i)
#define __REPR1(i,a,b) for(_loop_int i=(b)-1;i>=(a);--i)
#define REP(...) __GET_REP_MACRO(__VA_ARGS__,__REP1,__REP0)(__VA_ARGS__)
#define REPR(...) __GET_REP_MACRO(__VA_ARGS__,__REPR1,__REPR0)(__VA_ARGS__)

#ifdef BURI
#define __DEBUG0() "Hello"
#define __DEBUG1(x) #x"("<<(x)<<")"
#define __DEBUG2(x,...) #x"("<<(x)<<"), " __DEBUG1(__VA_ARGS__)
#define __DEBUG3(x,...) #x"("<<(x)<<"), " __DEBUG2(__VA_ARGS__)
#define __DEBUG4(x,...) #x"("<<(x)<<"), " __DEBUG3(__VA_ARGS__)
#define __DEBUG5(x,...) #x"("<<(x)<<"), " __DEBUG4(__VA_ARGS__)
#define __GET_DEBUG_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define __DEBUG(...) __GET_DEBUG_MACRO(__VA_ARGS__,__DEBUG5,__DEBUG4,__DEBUG3,__DEBUG2,__DEBUG1,__DEBUG0)(__VA_ARGS__)
#define DEBUG(...) cerr<<__DEBUG(__VA_ARGS__)<<endl
#else
#define DEBUG(...)
#endif

#define gc getchar_unlocked
inline void getll(ll &x){
  int sgn=1;x=0;
  char c=gc();
  while(c!='-'&&(c<'0'||c>'9'))c=gc();
  if(c=='-') sgn=-1; else x=c-'0';
  c=gc();
  while('0'<=c&&c<='9'){
    x*=10;
    x+=c-'0';
    c=gc();
  }
  x*=sgn;
}
inline void read(ll &x){getll(x);}
inline void read(int &x){ll y;getll(y);x=y;}
inline void read(float &x){scanf("%f",&x);}
inline void read(double &x){scanf("%lf",&x);}
inline void read(long double &x){scanf("%Lf",&x);}
inline void read(char *s){char *t=s;char c;while((c=gc())==' '||c=='\n');while(c!=' '&&c!='\n'){*t++=c;c=gc();}}
inline void read(string &s){int len=s.size();char *buf=(char*)malloc(len*sizeof(char));scanf("%s",buf);s=string(buf);free(buf);}
inline void read(char &c){char *buf=(char*)malloc(5*sizeof(char));scanf("%s",buf);c=buf[0];free(buf);}
inline void read(){}
template<typename S,typename ...T>
inline void read(S& first, T&... rest){
  read(first);
  read(rest...);
}
/// [/Amberjack] CUT END

int n,a,b;
char s[125252];
int main(){
  read(n,a,b,s);
  REP(i,n){
    if(s[i]=='a'){
      if(a+b>0){
        puts("Yes");
        --a;
      }else{
        puts("No");
      }
    }else if(s[i]=='b'){
      if(a+b>0 && b>0){
        puts("Yes");
        --b;
      }else{
        puts("No");
      }
    }else{
      puts("No");
    }
  }
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
void solve()
{
	int n;cin>>n;
	int ld=n%10;
	if(ld==2||ld==4||ld==5||ld==7||ld==9){
		cout << "hon";
	}
	else if(ld==0||ld==1||ld==6||ld==8){
		cout << "pon";
	}
	else cout << "bon";
}
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	solve();
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) (int)x.size()
#define pb push_back

const int mn=1e5+5;

int n,x;
int a[mn];

int main(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<=n;i++) if (x>=a[i]) x-=a[i],ans++;
    if (x&&ans==n) ans--;
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    ll n,k;
    cin >> n >> k;
    if(k == 0){
        cout << n * n << endl;
        return 0;
    }
    ll ans = 0;
    for(ll b = 1; b <= n; b++){
        ans += max((ll)0, (b - k) * (n / b)) + max((ll)0, n - b * (n / b) - k + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c,k = map(int,input().split())
ans = 0
if a >= k:
    ans += k
    print(ans)
    quit()
else:
    ans += a
    k -= a

if b >= k:
    print(ans)
    quit()
else:
    k-=b
    ans += (-1*k)
    print(ans)

Measured memory_bytes: 9132
#include<iostream>
#include<math.h>
#include<string.h>

using namespace std;

int maxx(int n, int*d) {
	int max = 0;
	max = d[0];
	for (int i = 1; i < n; i++) {
		if (max < d[i]) {
			max = d[i];
		}
	}

	return max;
}
int main() {

	int n;
	cin >> n;

	char s[128];
	cin >> s;
	int count[128] = {};

	/*char *xx = s;
	char *yy = &s[2];*/

	int max = 0;

	for (int i = 1; i < n; i++) {
		char *x = s;
		
		int bag[26] = {};
		
		for (int j = 0; j < i; j++) {
			bag[x[j]-'a']=1;	
		}
		for (int j = i; j < n; j++) {
			if (bag[x[j]-'a'] == 1)bag[x[j]-'a'] = 2;
			//bag[x[j] -'a']++;
		}

		for (int j = 0; j < 26; j++) {
			if (bag[j] > 1)count[i]++;
		}
		if (max < count[i])max = count[i];
	}
	//int max = 0;
	
	//max = maxx(n,count);

	printf("%d", max);
		return 0;
}


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

signed main(){
  int A,B;
  cin>>A>>B;
  int ans=max(A*B,max(A+B,A-B));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3600
module app;

import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto input = parseInput();
    auto result = (input.b - 1) / (input.a - 1);
    auto q = (input.b - 1) % (input.a - 1);
    if (q > 0)
        result++;
	
	writefln("%d", result);
}

struct Input
{
	int a;
    int b;
}

Input parseInput()
{
	Input input = void;
    auto ab = readln().strip().split();
	input.a = ab[0].to!int;
	input.b = ab[1].to!int;
	return input;
}


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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;




int main() {
    char c;
    cin >> c;
    if (c == 'A') cout << "T";
    if (c == 'T') cout << "A";
    if (c == 'G') cout << "C";
    if (c == 'C') cout << "G";
}


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

int main() {
  int i,num,count;
  string s;
  cin >> s;
  num = s.size();

  for(i=0; i < num; i++) {
    count++;
  }

  cout << s[0] << count - 2 << s[count-1] << endl;

  return 0;
}


Measured memory_bytes: 256
n, T = map(int, input().split())
a = set()
min_ = 1001
for i in range(n):
    c, t = map(int, input().split())
    a.add(c)
    if t <= T and c < min_:
        min_ = c
    a.remove(c)
if min_ == 1001:
    print('TLE')
else:
    print(min_)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,m,cut[2010][2010],tp[2010][2010],fa[2010][2010],ans;
vector<int> e[2010];
void dfs(int x,int dad,int rt){
	fa[rt][x]=dad;
	for(int v:e[x]) if(v!=dad) dfs(v,x,rt);
}
void add(int x,int y){
	if(cut[x][y]||cut[y][x]||tp[x][y]==y||tp[y][x]==x) return;
	if(tp[x][y]){add(tp[x][y],y);return;}
	if(tp[y][x]){add(tp[y][x],x);return;}
	tp[x][y]=y;tp[y][x]=x;
	queue<int> q;
	vector<pair<int,int> > V;
	q.push(y);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int v:e[u]) if(fa[x][u]!=v){
			if(tp[x][v]==v){
				V.emplace_back(v,y);
				cut[x][v]=cut[v][x]=1;
			}
			else{
				q.push(v);
				tp[x][v]=y;
			}
		}
	}
	q.push(x);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int v:e[u]) if(fa[y][u]!=v){
			if(tp[y][v]==v){
				V.emplace_back(v,x);
				cut[y][v]=cut[v][y]=1;
			}
			else{
				q.push(v);
				tp[y][v]=x;
			}
		}
	}
	for(auto pr:V) add(pr.first,pr.second);
}
void getans(int x,int dad,int now){
	if(!cut[x][now]&&tp[now][x]==x) ans++,now=x;
	for(int v:e[x]) if(v!=dad) getans(v,x,now);
}
int main(){
	read(n);read(m);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for(int i=1;i<=n;i++) dfs(i,0,i);
	while(m--){
		int x,y;read(x);read(y);
		add(x,y);
	}
	for(int i=1;i<=n;i++)
		for(int v:e[i])
			getans(v,i,i);
	cout<<ans/2<<'\n';
	return 0;
}


Measured memory_bytes: 48000
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string s;
	cin >> s;
	int ans = 0;
	int count = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		count = ((s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') ? count + 1 : 0);
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    long long int A;
    cin >> A;
    int p = ceil(sqrt(A));
    int flag = 0;
    int ans = 0;
    long long int min=1000000000000;
    for(int i=1; i<=p; i++){
        if(A % i == 0){
            flag = 1;
            if(i + (A/i) < min){
                min = i + (A/i);
            }
        }
    }

    if(flag == 0){
        cout << A-1;
    }else{
        cout << min -2;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ull = unsigned long long;

ull r[500][500];
char x[500][500] = {};

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

    int n;
    cin >> n;

    auto transpose = [&](auto a) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                swap(a[i][j], a[j][i]);
            }
        }
    };

    int s[2][500];
    ull u[2][500];
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            cin >> s[h][i];
        }
    }
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            cin >> u[h][i];
        }
    }

    for (int k = 0; k < 64; k++) {
        ull l = 1ULL << k;
        memset(x, -1, sizeof(x));

        for (int h = 0; h < 2; h++) {
            for (int i = 0; i < n; i++) {
                int b = (bool)(u[h][i] & l);
                if (!(s[h][i] ^ b)) continue;
                for (int j = 0; j < n; j++) {
                    x[i][j] = b;
                }
            }
            transpose(x);
        }
        for (int g = 0; g < 2; g++) {
            for (int h = 0; h < 2; h++) {
                for (int i = 0; i < n; i++) {
                    int b = (bool)(u[h][i] & l);
                    if (s[h][i] ^ b) continue;
                    int j1 = -1;
                    for (int j = 0; j < n; j++) {
                        if (x[i][j] == b) { j1 = -1; break; }
                        if (x[i][j] < 0) {
                            if (j1 >= 0) { j1 = -1; break; }
                            j1 = j;
                        }
                    }
                    if (j1 >= 0) x[i][j1] = b;
                }
                if (g) break;
                transpose(x);
            }
        }
        int i0 = -1, j0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (x[i][j] < 0) {
                    if (i0 < 0) {
                        i0 = i;
                        j0 = j;
                    }
                    x[i][j] = (i == i0) ^ (j == j0);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                r[i][j] ^= (ull)x[i][j] << k;
            }
        }
    }

    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < n; i++) {
            ull p[2] = { numeric_limits<ull>::max(), 0 };
            for (int j = 0; j < n; j++) {
                p[0] &= r[i][j];
                p[1] |= r[i][j];
            }
            if (p[s[h][i]] != u[h][i]) {
                cout << -1 << endl;
                exit(0);
            }
        }
        transpose(r);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << r[i][j] << " \n"[j == n - 1];
        }
    }

    return 0;
}

Measured memory_bytes: 7652
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include<queue>
#include<list>
#include<algorithm>
#include <utility>
#include <tuple>

int main()
{
    int n;
    std::cin>>n;
    std::vector< std::tuple<long long,long long, char, long long, std::string> > a(n);
    for(int i = 0; i < n; i++)
    {
        std::cin>>std::get<0>(a[i])>>std::get<1>(a[i])>>std::get<2>(a[i])>>std::get<3>(a[i])>>std::get<4>(a[i]);
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++)
    {
        std::cout<<std::get<0>(a[i])<<" "<<std::get<1>(a[i])<<" "<<std::get<2>(a[i])<<" "<<std::get<3>(a[i])<<" "<<std::get<4>(a[i])<<std::endl;
    }
    return 0;
}



Measured memory_bytes: 12980
#include <stdio.h>

#define NROW 8
#define NCOL 8
#define NBIT (NROW*NCOL)
#define LENGTH (NCOL+2)
#define NPATTERN 7

int search_offset(char *bit);
int calc_indicator(char *bit, int offset);
char indicator2pattern(int indicator);

int main(){
   int nline, i, j, offset, indicator;
   char pattern;
   char line[NROW][LENGTH], bit[NBIT];
   while(!feof(stdin)){
      nline=0;
      if(fscanf(stdin,"%s",line[nline])==1){
         for(nline=1;nline<NROW;nline++) fscanf(stdin,"%s",line[nline]);
         for(i=0;i<NROW;i++){
            for(j=0;j<NCOL;j++) bit[i*NCOL+j]=line[i][j];
         }
         offset=search_offset(bit);
         indicator=calc_indicator(bit,offset);
         pattern=indicator2pattern(indicator);
         printf("%c\n",pattern);
      }
   }
   return 0;
}

int search_offset(char *bit){
   int i;
   for(i=0;i<NBIT;i++){
      if(bit[i]!='0') return i;
   }
   return -1;
}

int calc_indicator(char *bit, int offset){
   int i, indicator;
   for(i=offset+1,indicator=0;i<NBIT;i++){
      if(bit[i]!='0') indicator+=(i-offset);
   }
   return indicator;
}

/*
  A : 1+8+9   = 18
  B : 8+16+24 = 48
  C : 1+2+3   =  6
  D : 7+8+15  = 30
  E : 1+9+10  = 20
  F : 8+9+17  = 34
  G : 1+7+8   = 16
*/
char indicator2pattern(int indicator){
   int i;
   int match[NPATTERN]={ 18, 48, 6, 30, 20, 34, 16 };
   char pattern[]="ABCDEFG";
   for(i=0;i<NPATTERN;i++){
      if(indicator==match[i]) return pattern[i];
   }
   return '?';
}

   

Measured memory_bytes: 548
#include <stdio.h>
#include <math.h>
 
int main(void)
{
   int i,s[1000]={},sum;
   double m,aa,a,bun,n;
    
   while(1)
   {
       sum=0; aa=0;
       for(i=0;i<1000;i++)
       {
           s[i]=0;
       }
       scanf("%lf",&n);
       if(n==0) break;
       else
       {
           for(i=0;i<n;i++)
           {
               scanf("%d",&s[i]);
               sum+=s[i];
           }
           m=sum/n;
           for(i=0;i<n;i++)
           {
               aa+=(s[i]-m)*(s[i]-m);
           }
           bun=aa/n;
           a=sqrt(bun);
           printf("%f\n",a);
       }
   }
    
    return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define db double
#define pdd pair<db,db>
using namespace std;
int n;db x,y,mx;
vector<pdd> v;
#define fi first
#define se second
int main(){
	cin>>n;
	rep(i,1,n) cin>>x>>y,v.pb(mp(x,y));
	rep(i,0,359){
		db tarx=cos(i),tary=sin(i),tx=0,ty=0;
		rep(j,0,n-1)
			if((tarx*v[j].fi+tary*v[j].se)>0)
				tx+=v[j].fi,ty+=v[j].se;
		db tans=sqrt(tx*tx+ty*ty);
		mx=max(mx,tans);
	}
	printf("%.12lf",mx);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

const int MAXN = (int)2e5;
const int P = (int)1e9 + 7;

std::vector<int> edges[MAXN];
int size[MAXN];     // size of subtree(i).
int64_t f[MAXN];    // subtree(i), 先选i, 的方案数.
int64_t ans[MAXN];  // 整棵树, 先选i, 的方案数.
int64_t factorial[MAXN];

// inv of P.
int64_t inv(int64_t x) {
  int y = P - 2;
  int64_t ans = 1;
  while (y > 0) {
    if (y & 1) ans = ans * x % P;
    x = x * x % P;
    y >>= 1;
  }
  return ans;
}

// Calc C(x, y).
int64_t comb(int x, int y) {
  if (y == 0 || y == x) return 1;
  return factorial[x] * inv(factorial[y] * factorial[x - y] % P) % P;
}

void calc_f(int u, int pa) {
  size[u] = 0;
  f[u] = 1; 
  for (const auto& v : edges[u]) {
    if (v == pa) continue;
    calc_f(v, u);
    size[u] += size[v];
    f[u] = f[u] * comb(size[u], size[v]) % P * f[v] % P;
  }
  ++size[u];
}

// ans[v] = (size[v] / (n - size[v])) * ans[u].
void calc_ans(int u, int pa, int n) {
  for (const auto& v : edges[u]) {
    if (v == pa) continue;
    ans[v] = ans[u] * size[v] % P * inv(n - size[v]) % P;
    calc_ans(v, u, n);
  }
}

void solve(int n) {
  factorial[0] = 1;
  for (int i = 1; i <= n; ++i) {
    factorial[i] = factorial[i - 1] * i % P;
  }

  calc_f(0, -1);
  ans[0] = f[0];
  calc_ans(0, -1, n);
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    std::cin >> u >> v;
    --u, --v;
    edges[u].emplace_back(v);
    edges[v].emplace_back(u);
  }
  solve(n);
  for (int i = 0; i < n; ++i) std::cout << ans[i] << std::endl;

  return 0;
}


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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009

int main()
{
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();
    int n, k;
    cin >> n >> k;
    vector<int> ht(n);
    for (int i = 0; i < n; i++)
        cin >> ht[i];
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + k; j++)
        {
            if (j < n)
            {
                dp[j] = min(dp[j], dp[i] + abs(ht[i] - ht[j]));
            }
        }
    }

    cout << dp[n - 1];

    return 0;
}


Measured memory_bytes: 1024