akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	// const int MAXN = 100000;
	// vector<vector<int>> graph(MAXN);
	// for (int a = 1; a <= MAXN; ++a) {
	// 	for (int p = 0; p <= 30; ++p) {
	// 		if (1 << p <= a) {
	// 			continue;
	// 		}
	// 		int b = (1 << p) - a;
	// 		if (b > MAXN || a == b) {
	// 			continue;
	// 		}
	// 		// cerr << a << " " << b << endl;
	// 		graph[a - 1].push_back(b - 1);
	// 		graph[b - 1].push_back(a - 1);
	// 	}
	// }

	int n;
	cin >> n;
	map<int, int> cnt;
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		cnt[num]++;
	}

	n = szof(cnt);

	vector<vector<int>> graph(n);
	vector<pii> have(cnt.begin(), cnt.end());

	for (int i = 0; i < n; ++i) { 
		auto p = have[i];
		for (int bp = 0; bp <= 30; ++bp) {
			if (1 << bp <= p.ff) {
				continue;
			}
			int v = (1 << bp) - p.ff;
			if (v > p.ff && cnt.count(v)) {
				int other = lower_bound(have.begin(), have.end(), make_pair(v, -1)) - have.begin();
				graph[i].push_back(other);
				graph[other].push_back(i);
			}
		}
	}

	vector<int> pows(n);
	queue<int> qu;
	vector<int> left(n);
	for (int i = 0; i < n; ++i) {
		left[i] = have[i].ss;
		pows[i] = szof(graph[i]);
		if ((pows[i] == 1 && __builtin_popcount(have[i].ff) != 1) || (pows[i] == 0 && __builtin_popcount(have[i].ff) == 1)) {
			qu.push(i);
		}
	}

	vector<bool> used(n);
	int ans = 0;
	while (szof(qu)) {
		int v = qu.front();
		qu.pop();
		used[v] = true;
		for (int to : graph[v]) {
			if (!used[to]) {
				int tmp = min(left[v], left[to]);
				left[to] -= tmp;
				ans += tmp;
				--pows[to];
				if ((pows[to] == 1 && __builtin_popcount(have[to].ff) != 1) || (pows[to] == 0 && __builtin_popcount(have[to].ff) == 1)) {
					qu.push(to);
				}
			}
		}

		if (__builtin_popcount(have[v].ff) == 1) {
			ans += left[v] / 2;
		}
	}

	cout << ans << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
int main(){
string A,B,C;
  cin>>A>>B>>C;
  if(A.at(A.size()-1)==B.at(0)  && B.at(B.size()-1)==C.at(0)){
  cout<<"YES";
  }
  else{
  cout<<"NO";
  }
}

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

const long N=1000000;

int main(){
	bool prime[N+1];
	
	for(long i=0; i<=N; ++i) prime[i]=true;
	prime[0]=prime[1]=false;
	for(long i=2; i<=N; ++i){
		if(prime[i]) for(long j=2; i*j<=N; ++j) prime[i*j]=false;
	}
	
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		
		long ans=0;
		for(int i=0; i<n; ++i){
			long p, m;
			scanf(" %ld %ld", &p, &m);	
			
			long x=0;
			int y=0;
			if((p+m)%2==0) y=1;
			
			if(p-m<=2) ++x;
			
			for(long j=p-m+y; j<=p+m-y; j+=2){
				//printf("j=%ld\n", j);
				if(j<2) continue;
				if(j>N) break;
				
				if(prime[j]) x++;
			}
			
			ans+=x-1;
			//printf("%ld\n", ans);
		}	
		
		printf("%ld\n", ans);
	}
}

Measured memory_bytes: 2160
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
long long p[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%lld",p+i);
	long long ret=inf;
	long long S=0;
	for(int i=0;i<a;i++)S+=p[i];
	long long T=0;
	ret=S;
	for(int i=0;i<a;i++){
		S-=p[i];
		T+=p[i];
		ret=min(ret,ABS(S-T));
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 1664
N = int(input())
l = []
for i in range(N):
    l.append(input())
l.sort()
a = l[0]
k = [1]
n = [str(l[0])]
for i in range(1,N):
    if a == l[i]:
        k[-1] += 1
    else:
        a = l[i]
        k.append(1)
        n.append(l[i])
m = max(k)
ans = []
for i in range(len(k)):
    if k[i] == m:
        ans.append(n[i])

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 135828
#include <iostream>

using namespace std;

int main()
{
    int k, a, b; cin >> k;
    cin >> a >> b;

    string ans = "NG";

    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            ans = "OK";
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long n,k,ret;
  long ii;
  long double sum = 0,one,div;
  cin >> n >> k;
  for(ii=1;ii<=n;ii++){
    one = 1.0/n;
    ret = ii;
    div = 1;
    while(ret < k){
      ret *= 2;
      //one /= 2.0;
      div *= 2;
    }
    //div = ret;
    //cout << ret << endl;
    one /= div;
    //cout << one << endl;
    sum += one;
  }
  //cout << sum << endl;
  printf("%.12Lf\n",sum);
  return 0;
}


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

#define MAX 2000001
#define VMAX 10000

int main(void)
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  for(i=0;i<=VMAX;i++) C[i] = 0;
  
  for(i=0;i<n;i++) {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
  
  for(j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++) {
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 9624
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let mut v = Vec::with_capacity(n);
    let mut sum = 0;
    for _ in 0..n {
        let tmp = get!(usize);
        sum += tmp;
        v.push(tmp);
    }
    if sum % 10 != 0 {
        println!("{}", sum);
        return;
    }
    v.sort();
    for i in 0..n {
        if (sum - v[i]) % 10 != 0 {
            println!("{}", sum - v[i]);
            return;
        }
    }
    println!("0");
}


Measured memory_bytes: 4352
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			for (int i = 1; i < 4; i++) {
				if (numA * numB * i % 2 != 0) {
					System.out.println("Yes");
					return;
				}
			}

			System.out.println("No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			String[] wk = new String[numN];

			Set<String> wkSet = new HashSet<String>();
			for (int i = 0; i < wk.length; i++) {
				String wkI = scanner.next();
				wk[i] = wkI;
				if (wkSet.contains(wk[i])) {
					System.out.println("No");
					return;
				}
				wkSet.add(wk[i]);
				if (i != 0) {
					String wkIm1 = wk[i - 1];
					if(wkIm1.charAt(wkIm1.length()-1)!=wkI.charAt(0)) {
						System.out.println("No");
						return;
					}

				}
			}

			System.out.println("Yes");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 22612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		UnionFind uf = new UnionFind(n);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int t = Integer.parseInt(sa[0]);
			int u = Integer.parseInt(sa[1]);
			int v = Integer.parseInt(sa[2]);
			if (t == 0) {
				uf.union(u, v);
			} else {
				pw.println(uf.same(u, v) ? 1 : 0);
			}
		}
		pw.flush();
		br.close();
	}

	/**
	 * UnionFind
	 */
	static class UnionFind {
		int[] parent, size;
		int num = 0; // 連結成分の数

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

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

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

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

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


Measured memory_bytes: 57588
#include <stdio.h>
#include <string.h>
int main(){
  char S[5];
  int a=0;
  scanf("%s",S);
  for(int i=0;i<3;i++){
  if(S[i]==S[i+1]){
  	printf("Bad");
  	break;
  }else a+=1;
  }
  if(a==3)printf("Good");
  return 0;
}

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

void solve(){
    LL n; cin >> n;
    LL ans = INFINITY;
    for (LL i = 1; i * i <= n; i++){
        if (n%i == 0){
            ans = min(ans, i + n / i - 2);
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n,k;
  while(scanf("%d%d",&n,&k),n+k){
    int s[k];
    REP(i,k) scanf("%d",&s[i]);
    REP(i,n) REP(j,k){
      int b; scanf("%d",&b);
      s[j] -= b;
    }
    bool ans = true;
    REP(i,k) if(s[i] < 0) ans = false;
    printf("%s\n",ans?"Yes":"No");
  }
  return 0;
}

Measured memory_bytes: 0
f=input().split()
(n,m,x,y)=(int(f[0]),int(f[1]),int(f[2]),int(f[3]))
ax=[int(i) for i in input().split()]
ay=[int(i) for i in input().split()]
ax.sort()
ay.sort()
b=ay[0]-ax[-1]
c=0
if x<ax[-1] and y>ax[-1]:
    c=1
elif x>ax[-1] and x<ay[0] and y<ay[0]:
    c=1
elif x>ax[-1] and y>ay[0] and x<ay[0]:
    c=1
if b>0 and c==1:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[112345], b[112345];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll plus = 0, minus = 0, cnt = 0;
    vector<ll> c(100000, 0);
    rep(i,n){
        if(a[i]>=b[i]){
            plus += a[i] - b[i];
            c.push_back(a[i] - b[i]);
        }
        if(a[i]<b[i]){
            minus += b[i] - a[i];
            cnt++;
        }
    }
    if(minus>plus)
        cout << -1 << endl;
    else{
        int ans = 0 ;
        sort(c.begin(), c.end());
        reverse(c.begin(), c.end());
        for (int i = 0; i < c.size();i++){
            if(minus>0){
                minus -= c[i];
                ans++;
            }
        }
        cout << ans + cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
    int x,a;
    cin>>x>>a;
    if(x < a)
        cout<<0<<endl;
    else
        cout<<10<<endl;
    return 0;
}

//a>b>c = c>b>a b>a>c = c>a>b b>c>a = a>c>b

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>=b && a>=c)cout<<a*10+b+c<<endl;
	else if(b>=a && b>=c)cout<<b*10+a+c<<endl;
	else cout<<c*10+b+a<<endl;
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
#print('N : ' + str(N))
#print('K : ' + str(K))
li = [0 for i in range(N)]

for i in range(0,K): 
  d = int(input())
 # print('')
 # print('d : ' + str(d))
  A = list(map(int, input().split()))
 # print('<A>')
  for j in A:
  #  print(j)
    li[j-1] = 1
sum = 0
#print(li)

for i in range(0,N):
  if li[i] == 0:
    sum += 1
print(sum)

Measured memory_bytes: 9144
#include <algorithm>
#include <cstdio>
typedef long long ll; 
int val[205][5005], st[5005], pre[5005], nxt[5005]; 
ll ans = -1e18, dis[5005], sum[5005][5005]; 
int main()
{
	// freopen("ARC067-F.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m); 
	for (int i = 1; i < n; i++)
	{
		int x; 
		scanf("%d", &x);
		dis[i] = dis[i - 1] + x; 
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			scanf("%d", val[j] + i); 
	}
	for (int i = 0; i < m; i++)
	{
		int tp = 0; 
		for (int j = 0; j < n; j++)
		{
			while (tp && val[i][st[tp - 1]] < val[i][j])
				tp--; 
			pre[j] = tp ? st[tp - 1] + 1 : 0; 
			st[tp++] = j; 
		}
		tp = 0; 
		for (int j = n - 1; j >= 0; j--)
		{
			while (tp && val[i][st[tp - 1]] < val[i][j])
				tp--; 
			nxt[j] = tp ? st[tp - 1] - 1 : n - 1; 
			st[tp++] = j; 
		}
		for (int j = 0; j < n; j++)
		{
			sum[pre[j]][j] += val[i][j]; 
			sum[j + 1][j] -= val[i][j]; 
			sum[pre[j]][nxt[j] + 1] -= val[i][j]; 
			sum[j + 1][nxt[j] + 1] += val[i][j]; 
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i)
				sum[i][j] += sum[i - 1][j]; 
			if (j)
				sum[i][j] += sum[i][j - 1]; 
			if (i && j)
				sum[i][j] -= sum[i - 1][j - 1]; 
			if (i <= j)
				ans = std::max(ans, sum[i][j] - dis[j] + dis[i]);
		}
	}
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 199808
n, k = map(int, input().split())

# a + b = kx
# b + c = ky
# c + a = kz
# a = k(x-y+z)/2

div = n // k
# kが奇数のとき,(a,b,c)はそれぞれkで割った余りは0になる
if k % 2 == 1:
    print(div ** 3)
# kが偶数のとき,(1) + (2)を足したもの
# (1) (a,b,c)それぞれkで割った余りが0
# (2) k/2余る
else:
    if div * k + k/2 <= n:
        print(div**3 + (div+1)**3)
    else:
        print(2*(div**3))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int N = 3, count = 0;

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

	for (int i = 0; i < N; i++) {
		count += a[i] - 1;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = ''.join(input().split())
Q = ''.join(input().split())

from itertools import permutations

arr = list()
for i in permutations(list(range(1, N + 1)), N):
    arr.append(''.join([str(x) for x in i]))

print(abs(arr.index(Q) - arr.index(P)))

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll k, s;
  cin >> k >> s;

  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      ll sum = i + j;
      ll z = s - sum;
      if (z >= 0 && z <= k) {
        ans++;
      }
    }
  }

  cout << ans << '\n';
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1)
        cout << 1 << endl;
    else
        cout << (H * W + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,m,n,p;
	scanf("%d %d",&a,&b);
	m=a+b;
	n=a-b;
	p=a*b;
	if(m>n)
	{
		if(m>p)
			printf("%d",m);
		else
			printf("%d",p);
	}
	else
	{
		if(n>p)
			printf("%d",n);
		else
			printf("%d",p);
	}
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int n,x,y;
long long ans;
int main() {
	scanf("%d",&n);
	for (long long i=1;i<=n;++i) ans+=i*(n-i+1);
	for (int i=1;i<n;++i) {
		scanf("%d%d",&x,&y);
		if (x>y) {int t=x; x=y; y=t;}
		ans-=(long long)x*(n-y+1);
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s="", t="", u= "";
   int a,b;
   cin>>s>>t;
   cin>>a>>b;
   cin>>u;

   if(u == s)
   a--;

   else if(u == t)
   b--;

   cout<<a<<" "<<b;
  return 0;
   
}


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

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

	if (400 <= n && n < 600)
	{
		cout << 8 << endl;
	}
	else if (600 <= n && n < 800)
	{
		cout << 7 << endl;
	}
	else if (800 <= n && n < 1000)
	{
		cout << 6 << endl;
	}
	else if (1000 <= n && n < 1200)
	{
		cout << 5 << endl;
	}
	else if (1200 <= n && n < 1400)
	{
		cout << 4 << endl;
	}
	else if (1400 <= n && n < 1600)
	{
		cout << 3 << endl;
	}
	else if (1600 <= n && n < 1800)
	{
		cout << 2 << endl;
	}
	else if (1800 <= n && n < 2000)
	{
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int n ; cin >> n;
    ll res = 1;
    rep(i, n){
        res *= (i+1);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#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 f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, x;
    cin >> n >> x;
    int l[n];
    int d = 0, newD; 
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    int cnt = 1;
    for(int i = 0; i < n; i++){
        newD = d + l[i];
        d = newD;
        if(d <= x) cnt++;
    }
    cout << cnt;
}

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

int main(){
  int n,d,x;
  cin>>n>>d>>x;
  vector<int>day(n);
  for(int i=0;i<n;i++){
    cin>>day.at(i);
  } 
  int choco=x;
  int i=0;
  for(int l=0;l<n;l++){
     while((i*day.at(l))+1<=d){
    choco++;
    i++;
     }
    i=0;
  }
  
  cout<<choco<<endl;
  
}

Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]
ans = 0
for t in T:
    idx = bisect_left(S, t)
    if idx != n and S[idx] == t:
        ans += 1
print(ans)



Measured memory_bytes: 16924
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());

            var data = new Dictionary<string, List<int>>();
            foreach (var i in Enumerable.Range(1, N))
            {
                var key = $"{this.GetMatsubi(i)},{i % 10}";
                if (!data.ContainsKey(key))
                {
                    data[key] = new List<int>();
                }

                data[key].Add(i);
            }

            var count = 0;
            foreach (var i in Enumerable.Range(1, N))
            {
                var key = $"{i % 10},{this.GetMatsubi(i)}";
                if (data.ContainsKey(key))
                {
                    count += data[key].Count;
                    // foreach(var num in data[key])
                    // {
                    //     Console.WriteLine($"({i},{num})");
                    // }
                }
            }

            Console.WriteLine(count);
            // foreach(var pair in data)
            // {
            //     Console.WriteLine($"{pair.Key}:{string.Join(",", pair.Value)}");
            // }
        }

        private int GetMatsubi(int num)
        {
            var tmp = num;
            while(tmp >= 10)
            {
                tmp = tmp / 10;
            }

            return tmp;
        }
    }
}


Measured memory_bytes: 19776
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct UnionFind{
	vi data;
	UnionFind(int size):data(size,-1){}
	int Find(int n){
		return data[n]<0?n:(data[n]=Find(data[n]));
	}
	void Unite(int a,int b){ // aの根をa∪bの根にする
		int ra=Find(a),rb=Find(b);
		if(ra!=rb){
			//if(-data[ra]<-data[rb])
			//	swap(ra,rb);
			data[ra]+=data[rb];
			data[rb]=ra;
		}
	}
	int Size(int n){
		return -data[Find(n)];
	}
};

int main()
{
	for(int n,q;cin>>n>>q,n|q;){
		vi par(n); par[0]=-1;
		repi(i,1,n) cin>>par[i],par[i]--;
		
		vector<pair<char,int>> qs;
		vi mark(n); mark[0]=1;
		rep(i,q){
			char t; int x; cin>>t>>x; x--;
			if(t=='Q')
				qs.emplace_back(t,x);
			else if(!mark[x]){
				mark[x]=1;
				qs.emplace_back(t,x);
			}
		}
		
		UnionFind uf(n);
		rep(i,n) if(!mark[i]) uf.Unite(par[i],i);
		
		ll res=0;
		per(i,qs.size())
			if(qs[i].first=='Q')
				res+=uf.Find(qs[i].second)+1;
			else{
				int x=qs[i].second;
				uf.Unite(par[x],x);
			}
		cout<<res<<endl;
	}
	
	return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> bool chmax(T &a,T &b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T &b){if(a>b){a=b;return true;}return false;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n;
    cin>>n;
    vector<vector<Pii>> connect(n);
    REP(i,1,n){
        connect[i].pb(mp((i+1)%n,1));
        connect[i].pb(mp((i*10)%n,0));
    }
    Vi dist(n,INF);
    dist[1]=0;
    
    priority_queue<Tiii,vector<Tiii>,greater<Tiii>> q;
    q.push(make_tuple(0,1,-1));
    while(!q.empty()){
        int nowdist,now,past;
        tie(nowdist,now,past)=q.top();
        q.pop();
        if(nowdist>dist[now]) continue;
        dist[now]=nowdist;
        if(now==0) break;
        REP(i,0,connect[now].size()){
            int next=connect[now][i].first,cost=connect[now][i].second;
            if(next!=past && nowdist+cost<dist[next]){
                q.push(make_tuple(nowdist+cost,next,now));
                dist[next]=nowdist+cost;
            }
        }
    }
    cout<<dist[0]+1<<endl;
    return 0;
}


Measured memory_bytes: 9720
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void primeFactorization(ll n, map<ll, int>& result)
{
	for (auto i = 2ll; i * i <= n; ++i)
	{
		while (n % i == 0)
		{
			++result[i];
			n /= i;
		}
	}

	if (n != 1)
	{
		++result[n];
	}
}

int main()
{
	int N;
	cin >> N;
	map<ll, int> m;
	for (auto i = 2; i <= N; ++i)
	{
		primeFactorization(i, m);
	}

	vector<int> num;
	for (auto& p : m)
	{
		num.push_back(p.second);
	}
	vector<vector<ll>> dp((int)num.size() + 1, vector<ll>(76));
	dp[0][1] = 1;
	for (auto i = 0; i < (int)num.size(); ++i)
	{
		for (auto k = 0; k <= 75; ++k)
		{
			for (auto j = 0; j <= num[i]; ++j)
			{
				if (k * (j + 1) > 75)
				{
					break;
				}
				dp[i + 1][k * (j + 1)] += dp[i][k];
			}
		}
	}

	cout << dp[(int)num.size()][75] << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else :
        d[s] = 1
m = max(d.values())
ans = sorted([i for i in d if d[i] == m])
for i in ans:
    print(i)

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

using namespace std;

using ll = long long;

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

    if (N == 0) {
        cout << "0" << endl;
        return 0;
    }

    std::deque<char> S;

    ll base = 1;
    while (N != 0) {
        if (N % (2 * std::abs(base)) != 0) {
            S.emplace_front('1');
            N -= base;
        } else {
            S.emplace_front('0');
        }
        base *= -2;
    }
    
    std::for_each(S.cbegin(), S.cend(), [](const auto c) { cout << c; });
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list(map(lambda x:int(x),input().split()))
q=int(input())
t=list(map(lambda x:int(x),input().split()))
c=0
for i in t:
    start=0
    end=n-1
    while start<=end:
        mid=(start+end)//2
        if s[mid]==i:
            c+=1
            break
        if s[mid]>i:
            end=mid-1
        if s[mid]<i:
            start=mid+1

print(c)



Measured memory_bytes: 16704
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;




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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
  int x,a=2,l,s=1;
  cin >> x;
  while (a*a<=x){
    l=1;
    while (l*a<=x) l*=a;
    s=max(s,l);
    a++;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, x, l;
    int cont = 1;
    int total = 0;
    
    scanf("%d %d", &n, &x);
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &l);
        total+=l;
        if(total <= x){
            cont++;
        }
    }

    printf("%d\n", cont);

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    string s;
    cin>>s;
    ll ans=0;
    rep(i,s.length()){
        if(s[i]=='2')ans++;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
# coding: utf-8
import math

while True:
    n = int(input())

    if n == 0:
        break
    
    s = [int(x) for x in input().split()]

    total = 0
    
    for i in s:
        total += i

    m = total / n
    
    d = 0
    
    for i in s:
        d += (i - m) ** 2

    print((d / n) ** (1 / 2))


Measured memory_bytes: 5728
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(b<c){
			System.out.print(b);
		}else{
			System.out.print(c);
		}
		System.out.print(" ");
		int d = b+c;
		if(d-a>=0){
			System.out.print(d-a);
		}else{
			System.out.print(0);
		}
	}
}

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

int main(){
	int n, a[1002], s, e, t;
	a[0] = 0;
	for(int i = 1;i <= 1000;i++)a[i] = i;
	while(cin >> n, n){
		s = 1, e = 2, t = 1;
		int ans = 0;
		while(e <= n){
			if(t == n){
				ans++;t += e++;
			}else if(t < n){
				t += e++;
			}else{
				t -= s++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<char> v(s.size()),w(s.size());
    for(int i=0;i<s.size();i++){v.at(i)=s.at(i);}
    for(int i=0;i<s.size();i++){
        if(v.at(i)=='0'){w.push_back('0');}
        else if (v.at(i)=='1'){w.push_back('1');}
        else{if(!v.empty()){w.pop_back();}}
    }
    for(char e:w){if(e!='\0'){cout << e;}}

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			d[i] = a-i-1;
		}
		
		Arrays.sort(d);
		int mid = d[n/2];
		
		long ans = 0;
		for(int i=0;i<n;i++){
			ans+=Math.abs(d[i]-mid);
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 64300
main = do
 getLine
 ss <- map read . words <$> getContents
 print (bugged ss)

bugged ss
 | mod (sum ss) 10 == 0 = sum ss - sm
 | otherwise = sum ss
 where
  sm = minimum' (filter (\x -> mod x 10 /= 0) ss)
  minimum' xs = if null xs then sum ss else minimum xs

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 15, INF = 1e8;
int n, m, x, ans = INF;
int c[max_n], a[max_n][max_n];
bool poss = false;

int main(){
    cin >> n >> m >> x;
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    for(int bit = 0; bit < (1 << n); bit++){
        int sum = 0;
        int pts[m] = {0};
        for(int i = 0; i < n; i++){
            if((bit >> i) & 1) {
                sum += c[i];
                for(int j = 0; j < m; j++) pts[j] += a[i][j];
            }
        }
        auto iter = min_element(pts, pts+m);
        if(*iter >= x && ans > sum) poss = true, ans = sum;
    }
    if(poss) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int n,m;
int a,b;


signed main(){
  cin >> n >> m;
  int r = 0;
  int l = 2000000;
  REP(i,m){
    int k1,k2;
    cin >> k1 >> k2;
    r = max(r,k1);
    l = min(l,k2);
  }
  if(l-r+1<0){
    cout  << 0 << endl;
  }
  else cout << l-r + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
dp = [[False] * 20000 for i in range(n+1)]
dp[0][0] = True
for i in range(n):
    s = int(input())
    for j in range(10000):
        if dp[i][j]:
            dp[i+1][j]=True
            dp[i+1][j+s]=True
f = False
for i in range(19999, -1, -1):
    if i%10==0:
        continue
    if dp[n][i]:
        print(i)
        f = True
        break
if not f:
    print(0)

Measured memory_bytes: 25200
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve() {
    LL n;
    cin >> n;
    if (n % 2) {
        cout << 0 << endl;
        return;
    }
    if (n < 10) {
        cout << 0 << endl;
        return;
    }
    if (n == 10) {
        cout << 1 << endl;
        return;
    }
    LL n2 = 0, n5 = 0;
    n /= 2;
    for (LL p = 2; p <= n; p *= 2) n2 += n / p;
    n *= 2;
    n /= 10;
    for (LL p = 5; p <= n; p *= 5) n5 += n / p;
    cout << min(n2, n5) + n << endl;
}

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int N=100010;
const int inf=(1<<29);
int p[N],memo[N],visited[N],res[N],n;
int func(int x)
{
	if (x>=n) return n-1;
	if (memo[x]<inf) return memo[x];
	if (p[x]==0) return memo[x]=x;
	if (visited[x]) return memo[x]=-1;
	visited[x]=1;
	int nx=x+p[x];
	nx=max(0,min(nx,n-1));
	return memo[x]=func(nx);
}
int main()
{
	while(~scanf("%d",&n)){
		for(int i=0;i<n;++i)scanf("%d",p+i);
		for(int i=0;i<=n;++i)memo[i]=res[i]=inf;
		memset(visited,0,sizeof(memo));
		queue<int> q;
		q.push(0);
		res[0]=0;
		while(!q.empty()){
			int x=q.front(); q.pop();
			if(x>=n-1)break;
			for(int i=1;i<=6;++i) {
				int nx=func(x+i);
				if (res[nx]<inf) continue;
				q.push(nx);
				res[nx]=res[x]+1;
			}
		}
		printf("%d\n",res[n-1]);
	}
	return 0;
}

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

ll C[51][51];

void comb_table(int N){
  for(int i=0;i<=N;++i)
    for(int j=0;j<=i;++j)
      if(j==0||j==i)
        C[i][j]=1;
      else
        C[i][j]=C[i-1][j-1]+C[i-1][j];
}

main(){
  int N,A,B;
  cin>>N>>A>>B;
  const int NMAX=50;
  ll v[NMAX];
  for(int i=0;i<N;++i)cin>>v[i];
  comb_table(N);
  sort(v,v+N);
  reverse(v,v+N);
  
  R max_average=0;  // average is max at A.
  for(int i=0;i<A;++i)max_average+=v[i];
  max_average/=A;
  
  int a_th_val_num=0;  // X. v_0 == v_i where 0 <= i <= N - 1.
  int a_th_val_pos=0;  // Y. v_0 == v_i where 0 <= i <= A - 1.
  for(int i=0;i<N;++i)
    if(v[i]==v[A-1]){
      ++a_th_val_num;
      if(i<A)++a_th_val_pos;
    }
  
  ll cnt=0;
  if(a_th_val_pos==A)   // v_0 == v_{A - 1}.
    for(a_th_val_pos=A;a_th_val_pos<=B;++a_th_val_pos)
      cnt+=C[a_th_val_num][a_th_val_pos];
  else                  // v_0 != v_{A - 1}.
    cnt+=C[a_th_val_num][a_th_val_pos];
  
  cout.precision(20);
  cout<<fixed<<max_average<<endl;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;

int main()
{
  int64_t n, m, sx = 0, sy = 0;
  cin >> n >> m;
  vector<int64_t> x(n), y(m);
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++)
  {
    cin >> y[i];
  }
  for (int i = 0; i < n; i++)
  {
    sx = (sx + i * x[i] - (n - 1 - i) * x[i]) % MOD;
  }
  for (int i = 0; i < m; i++)
  {
    sy = (sy + i * y[i] - (m - 1 - i) * y[i]) % MOD;
  }
  cout << (sx * sy) % MOD << endl;
}


Measured memory_bytes: 4848
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back


int main(void){
  int x,y,z;

  while(cin >> x >> y >> z,x+y+z){
    int ma=0;
    rep(i,z){
      rep(j,z){
        if(i==0||j==0)continue;
        int xa = int(i*(x+100))/100 + int(j*(x+100))/100;
        if(xa == z){
          ma = max(ma, int( i * ( y + 100 ) )/100 + int( j * ( y + 100 ) )/100);
        }
      }
    }
    cout << ma << endl;
  }


  return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n , a;
	
	cin >> n >> a;
	
	cout << n*n - a;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
  int N;
  cin >> N;
  double x[10], y[10];
  rep(i,N) cin >> x[i] >> y[i];
  vector<int> a;
  rep(i,N) a.emplace_back(i);
  vector<double> dis;
  double fac[10];
  fac[1]=1;
  for(int i=2; i<=8; i++) fac[i]=fac[i-1]*i;
  do {
    double sum=0;
    rep(i,N-1){
      int j=a[i], k=a[i+1];
      sum+=sqrt((x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k]));
    }
    dis.emplace_back(sum);
  } while(next_permutation(a.begin(),a.end()));
  double ans=0;
  for(auto i:dis) ans+=i;
  cout << setprecision(15) << ans/fac[N] << endl;

  return 0;
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int x,n;
	cin >> x >> n;
	int ans = 1000;
	int p[102] = {};
	int P;
	for(int i = 0; i < n; i++){
		cin >> P;
		p[P] = 1; 
	}

	for(int i = 0; i < 102; i++){
		if(!p[i]){
			ans = min(ans,abs(x-i));
		}
	}
	if(!p[x-ans]){
		cout << x-ans << endl;
	}
	else{
		cout << x + ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String p=sc.next();
		
		int[] num=new int[13];
		int sum, k=0, count=0, ans=0;
		
		for(int i=11; i>=0; i--) {
			if(p.charAt(11-i)=='?')	{
				k=i;
			}
			else {
				num[i]=p.charAt(11-i)-'0';
			}
		}
		
		for(int j=0; j<=9; j++) {
			num[k]=j;
			sum = 0;
			for(int n=11; n>=1; n--) {
				if(n<=6) {
					sum+=num[n]*(n+1);
				}
				else if(n>6) {
					sum+=num[n]*(n-5);
				}
			}
				sum %= 11;
				if(sum <= 1) sum=0;
				else sum=11-sum;
				if(sum == num[0]) {
					ans = num[k];
					count++;
				}
		}
		if(count>1)	System.out.println("MULTIPLE");
		else System.out.printf("%d\n", ans);
	}
}


Measured memory_bytes: 26360