akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

bool judge(map<int,int> &map, int num) {
    if(num%3) return false;
    int sz = num/3;
    vector<int> arr;
    for(pii p: map) {
        arr.push_back(p.first);
        if(p.second != sz) return false;
    }
    ps(arr);
    vector<int> idx = {0, 1, 2};
    int flag = true;
    do {
        flag &= ((arr[idx[0]] ^ arr[idx[1]]) == arr[idx[2]]);
    } while(next_permutation(idx.begin(), idx.end()));
    return flag;
}

// a1 ^ a2 = a3
// a2 ^ a3 = a2 ^ (a1 ^ a2) = a1
int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    cins(arr);
    map<int, int> map;
    for(int i = 0; i < num; i++) map[arr[i]]++;
    bool ans = 0;

    switch(map.size()) {
        case 1:
            // 0 ... 0
            if(map[0] == num) ans = true;
            break;
        case 2:
            // 0 3 3 0 3 3
            if(map[0]*3 == num) ans = true;
            break;
        case 3:
            if(num%3 == 0) ans = judge(map, num);
            break;
        default:
            break;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 7096
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  cout << (char)toupper(s[0][0]) << (char)toupper(s[1][0]) << (char)toupper(s[2][0]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
void solve () {
	string s; cin >> s;
	string t; cin >> t;
	int id = -1;
	for (int i = 0; i < sz (s); i ++) {
		bool ok = true;
		for (int j = 0; j < sz (t); j ++) {
			if (i + j == sz (s)) {
				ok = false;
				break;
			}
			if (s[i + j] == t[j]) continue;
			if (s[i + j] == '?') continue;
			ok = false;
			break;
		}
		if (ok) id = i;
	}

	if (id == -1) {
		cout << "UNRESTORABLE";
	} else {
		int c = 0;
		for (int i = id;; i ++) {
			s[i] = t[c];
			c ++; 
			if (c == sz (t)) break;
		}
		for (int i = 0; i < sz (s); i ++)
			if (s[i] == '?')
				s[i] = 'a';

		cout << s;
	}
}

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

Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>
#include <queue>

using namespace std;

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

int A[100000];
int L[100000];
int R[100000];

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

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


	if (N == 2)
	{
		if (A[0] > A[1])
		{
			cout << A[0] << endl;
		}
		else
		{
			cout << A[1] << endl;
		}
	}
	else
	{
		L[0] = A[0];
		R[N - 1] = A[N - 1];

		for (int i = 1; i < N; i++)
		{
			L[i] = gcd(L[i - 1], A[i]);
			R[N-1-i] = gcd(R[N - i], A[N - 1 - i]);
		}

		int maxd = max(R[1], L[N-2]);

		for (int i = 1; i < N-1; i++)
		{
			maxd = max(maxd, gcd(L[i-1], R[i+1]));
		}

		cout << maxd << endl;
	}

	return 0;
}

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

int ca=0,cb=0,cc=0,cd=0;
int main(){
	int a=0,b=0,c=0;
	int l[3]={0,0,0};
	while(cin>>l[0]>>l[1]>>l[2]){
		sort(l,l+3);
		a=l[0];
		b=l[1];
		c=l[2];
		if(c>=a+b)break;
		ca++;
		
		if((a*a)+(b*b)==c*c){cb++;}
		if((a*a)+(b*b)>(c*c)){cc++;}
		if((a*a)+(b*b)<(c*c)){cd++;}
	}
	cout<<ca<<" "<<cb<<" "<<cc<<" "<<cd<<endl;
	return 0;
}

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

vector<bool> eratos(1000001, true);
void sieve_of_eratosthenes(){
  eratos[0] = false;
  eratos[1] = false;
  for(int i = 2; i * i <= 100000; ++i){
    if(eratos[i]){
      for(int j = i * i; j <= 100000; j += i){
        eratos[j] = false;
      }
    }
  }
}
vector<long long> sum(100001, 0);
void cumsum(){
  for(int i = 3; i <= 100001; i+=2){
    if(eratos[i] && eratos[(i + 1) / 2]) sum[i]++; 
  }
  for(int i = 1; i <= 100001; ++i) sum[i] += sum[i - 1];
}

void solve(int l, int r){
  cout << sum[r] - sum[l - 1] << endl;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  sieve_of_eratosthenes();
  cumsum();
  for(int i = 0, l, r; i < q; ++i){
    cin >> l >> r;
    solve(l, r);    
  }
}

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

int main()
{
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i <= X; i++)
    {
        if (2 * i + 4 * (X - i) == Y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

using ll = long long;
const int MAX = 1e5;

// 2部グラフ判定
vector<int> d(MAX, -1);
bool bfs(const vector<vector<int>> &G, int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      if (d[G[u][i]] == -1) {
        d[G[u][i]] = (d[u] + 1) % 2;
        q.push(G[u][i]);
      }
      else if (d[G[u][i]] == d[u]) return false;
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  ll n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  if (!bfs(G, 0)) {
    cout << n * (n - 1) / 2 - m << '\n';
    return 0;
  }
  
  ll one = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == 1) one++;
  }
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == 0) {
      ans += one - G[i].size();
    }
  }
  
  cout << ans << '\n';
  return 0;
}

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

A = [x]
where = {x: 0}
a = x
for i in range(1, n):
    a = A[-1]**2 % m
    if a in where:
        break
    where[a] = i
    A.append(a)

perstart = where[a]
res = sum(A)
rem = n - len(A)
per = len(A) - perstart
res += rem//per*sum(A[perstart:perstart+per])
res += sum(A[perstart:perstart + (rem%per)])

print(res)


Measured memory_bytes: 15684
#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;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


void fio()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | START | --------------------------------------///

/*
	LCS Problem
https://atcoder.jp/contests/dp/tasks/dp_f
*/


void solve()
{
	string s, t;
	cin >> s >> t;
	int m = s.size(), n = t.size();
	int dp[m + 5][n + 5];
	//mem(dp);
  	fr0(i,m+5) dp[i][0]=0;
  fr0(i, n+5) dp[0][i]=0;
	char path[m + 5][n + 5];
	//mem(path);
	fr(i, 1, m + 1) fr(j, 1, n + 1)
	{
		if (s[i - 1] == t[j - 1])
		{
			dp[i][j] = 1 + dp[i - 1][j - 1];
			path[i][j] = 'x';
		}

		else
		{
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (dp[i][j] == dp[i - 1][j])
				path[i][j] = 'd';
			else path[i][j] = 'l';
		}
	}
	string ans;
	int i = m, j = n;
	while (i != 0 && j != 0)
	{
		if (path[i][j] == 'x')
		{
			ans.pb(s[i - 1]);
			i--, j--;
		}
		else if (path[i][j] == 'd')	i--;
		else j--;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << nl;
}




int32_t main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	TIME(start, end);
	return 0;
}




Measured memory_bytes: 47700
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n;
    float m = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a.at(i);
        m += a.at(i);
    }
    m = round(m/n);

    int total = 0;
    for (int i = 0; i < n; ++i) {
        total += (m - a.at(i))*(m - a.at(i));
    }

    cout << total;
}

Measured memory_bytes: 512
import numpy as np
n,m,k=map(int,input().split())
a=[0]
c=list(map(int,input().split()))
b=list(map(int,input().split()))

for _ in range(n):
    a.append(c[_])

a.append(10**10)
b.append(10**10)

ara=np.array(a)
arb=np.array(b)
la=np.cumsum(ara)
lb=np.cumsum(arb)

ans=0

i=0
while la[i]<=k:
    rest=k-la[i]
    j=np.searchsorted(lb,rest,side="right")
    ans=max(i+j,ans)
    i+=1
print(ans)
    






Measured memory_bytes: 58448
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a+1, 0), q(b+1, 0), r(c+1, 0);
    for (int i = 0; i < a; i++)
        cin >> p[i];
    for (int i = 0; i < b; i++)
        cin >> q[i];
    for (int i = 0; i < c; i++)
        cin >> r[i];
    
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());
    
    vector<int> v;
    for (int i = 0; i < x; i++)
        v.push_back(p[i]);
    for (int i = 0; i < y; i++)
        v.push_back(q[i]);
    for (int i = 0; i < c; i++)
        v.push_back(r[i]);
    
    sort(v.begin(), v.end(), greater<int>());
    ll total = 0;
    for (int i = 0; i < x+y; i++)
        total += v[i];
    
    cout << total << endl;
    
    return 0;
}


Measured memory_bytes: 3572
#!/usr/bin/env python3

import functools


def judge(n, k, bs):
    for i in range(k, n):
        prev_first = bs[i - k]
        new_last = bs[i]
        yield prev_first < new_last


def main():
    n, k = (int(x) for x in input().split())
    bs = [int(b) for b in input().split()]
    for res in judge(n, k, bs):
        if res:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 31996
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1000000;
const int MOD = 1e9 + 7;
const int INV_2 = (MOD + 1) >> 1;
int n, K;
int s[MAXN], tot, f[MAXN];
int ans;

int quick_pow(int a, int x) {
    int res = 1;
    while (x) {
        if (x & 1)
            res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, x >>= 1;
    }
    return res;
}

int main() {
	scanf("%d %d", &n, &K);
    for (int i = 1; i * i <= n; i++)
        if (!(n % i)) {
            s[++tot] = i;
            if (i * i != n)
                s[++tot] = n / i;
        }
    sort(s + 1, s + tot + 1);
    for (int i = 1; i <= tot; i++) {
        f[i] = quick_pow(K, (s[i] + 1) >> 1);
        for (int j = 1; j < i; j++)
            if (!(s[i] % s[j]))
                f[i] = (f[i] - f[j] + MOD) % MOD;
        ans = (ans + 1ll * f[i] * ((s[i] & 1) ? s[i] : s[i] >> 1)) % MOD;
    }
    printf("%d", ans);
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	int i;
	bool t = 0;
	for (i = 0; i < 3; i++) {

		if (s.at(i) == '7') {
			t = 1;
		}

	}
	if (t == 1) {
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;
const int INF=1e9;

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

   string s; cin>>s;
   reverse(s.begin(),s.end());
   s+='0';
   int N=s.size();
   vector<vector<int>> dp(N+1,vector<int>(2,INF));
   dp[0][0]=0;
   for(int i=0;i<N;i++) for(int j=0;j<2;j++){
      int cur=s[i]-'0';
      cur+=j;
      for(int a=0;a<10;a++){
         if(a>=cur){
            int b=a-cur;
            dp[i+1][0]=min(dp[i+1][0],dp[i][j]+a+b);
         }else{
            int b=a+10-cur;
            dp[i+1][1]=min(dp[i+1][1],dp[i][j]+a+b);
         }
      }
   }
   cout<<dp[N][0]<<endl;
   return 0;
}


Measured memory_bytes: 56092
point = {}
for i in range(int(input())):
    name = input()
    if (name in point.keys()) == True:
        point[name] += 1
    else:
        point[name] = 1
for i in range(int(input())):
    name = input()
    if (name in point.keys()) == True:
        point[name] -= 1
    else:
        point[name] = -1
result = max(list(point.values()))
if result > 0:
    print(result)
else:
    print(0)

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 3005, P = 998244353;

int A, B, C, D, f[N][N];

void solve() {
	read(A), read(B), read(C), read(D);
	f[A][B] = 1;
	for (int i = A; i <= C; ++i) {
		for (int j = B; j <= D; ++j) {
			if (i == A && j == B) {
				continue;
			}
			f[i][j] = (1ll * f[i - 1][j] * j + 1ll * f[i][j - 1] * i - 1ll * f[i - 1][j - 1] * (i - 1) % P * (j - 1)) % P;
		}
	}
	print((f[C][D] + P) % P);
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}

Measured memory_bytes: 38640
#include <cstdio>

int main(){
  int N, K; scanf("%d%d", &N, &K);
  int x, y; scanf("%d", &y);

  long long ans = 0;
  for(int i = 2; i <= N; i++){
    x = y; scanf("%d", &y);
    if(x + y > K){
      ans += x + y - K; y -= x + y - K;
      if(y < 0){ x += y; y = 0; }
    }
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(b%a==0)
    return a;
    return gcd(b%a,a);
}
bool isprime(ll n)
{
    int a[10000000]={0};
    for(int i=2;i<1e7;i++)
    {
        if(a[i]==0)
        {
            for(int j=2*i;j<1e7;j+=i)
            {
                a[j]=1;
            }
        }
    }
    if(a[n]==0)
    return 1;
    else return 0;//return 1 for prime
}
long  dp[101][100001],w;
long  ks(int i, int wl,int weight[],long val[] )
{   long  ans;
    
    if(i>=0 && wl>=0){
    if(dp[i][wl]!=-1)
    return dp[i][wl];}
    //cout<<"going at i="<<i<<"weight lefft="<<wl<<endl;
    if(i<0 || wl==0)
    ans=0;
    else if(weight[i]>wl)
    {
        ans=ks(i-1,wl,weight,val);
    }
    else ans=max(ks(i-1,wl,weight,val),ks(i-1,wl-weight[i],weight,val)+val[i]);
   if(i>=0)
   dp[i][wl]=ans;
   //cout<<"for i="<<i<<"wl="<<wl<<"ans"<<ans<<endl;
    return ans;

}
 int main()
{
    for(int i=0;i<101;i++)
    for(int j=0;j<100001;j++)
    dp[i][j]=-1;
    int n;
    cin>>n>>w;
    int weight[n];long int val[n];
    for(int i=0;i<n;i++)
    cin>>weight[i]>>val[i];
    cout<<ks(n-1,w,weight,val);
    

    
    
}

Measured memory_bytes: 79104
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn next(nums: &mut [i32], m: i32) -> bool {
    let mut changed_i = 10000;
    let mut changed_to = 0;
    for i in (0..nums.len()).rev() {
        if nums[i] < m {
            nums[i] += 1;
            changed_i = i;
            changed_to = nums[i];
            break;
        }
    }
    if changed_i == 10000 {
        return false;
    } else {
        for i in changed_i..nums.len() {
            nums[i] = changed_to;
        }
    }
    return true;
}

fn score(nums: &[i32], crit: &[(usize, usize, i32, i32)]) -> i32 {
    let mut sum = 0;
    for &(a, b, c, d) in crit {
        //dbg!((a, b, c, d));
        if nums[b-1] - nums[a-1] == c {
            sum += d;
        }
    }
    sum
}

fn main() {
    let n: usize = read();
    let m: i32 = read();
    let q: i32 = read();

    let mut crit: Vec<(usize, usize, i32, i32)> = Vec::new();
    for _ in 0..q {
        crit.push((read(), read(), read(), read()));
    }

    let mut nums = vec![1; n];
    let mut max_score = 0;
    loop {
        max_score = std::cmp::max(max_score, score(&mut nums, &mut crit));

        if !next(&mut nums, m) {
            break;
        }
    }

    println!("{}", max_score);
}


Measured memory_bytes: 2088
#include <stdio.h>                                                              
                                                                                
int main(void){                                                                 
  int X,t;                                                                      
  scanf("%d",&X);                                                               
  scanf("%d",&t);                                                               
  int remain = X - t;                                                           
  if(remain < 0){                                                               
    printf("%d",0);                                                             
  }else{                                                                        
    printf("%d\n",X - t);                                                       
  }                                                                             
  return 0;                                                                     
}              

Measured memory_bytes: 128
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3f
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 998244353;
/*
ll nop = 70;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

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

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}
*/
ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num *= num;
        num %= mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    a %= mod;
    return mexp(a,mod-2);
}

void solve() {
    ll n;
    cin>>n;
    ll tmp = 1, mx = 1;
    int flag = 0,f2 = 0;
    for0(i,n) {
        ll a;
        cin>>a;
        if(a == 0) f2 |= 1;
        tmp *= a;
        if(tmp > (ll)1e18 || tmp < 0 || tmp < mx) {
            flag = 1;
        }
        mx = max(mx,tmp);
    }
    if(f2) cout<<0<<endl;
    else if(flag || tmp > (ll)1e18) cout<<-1<<endl;
    else cout<<tmp<<endl;
}


int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<fixed<<setprecision(8);
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


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

int main(){
  int N, Y; cin >> N >> Y;
  
  for (int i=0; i<=N; i++){
    for (int j=0; j<=N-i; j++){
      int k = N - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == Y){
        cout << i << ' '  << j << ' ' << k << endl;
        return 0;
      }
    }
  }


  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  int n,m,k; cin>>n>>m>>k;
  for(int i=0;i<=n;i++) {
    for(int j=0;j<=m;j++) {
      if (i*m+j*n-2*i*j==k) {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

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

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

using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  
  if(a%2==0 || b%2==0){
    cout<<"No";
  }else{
    cout<<"Yes";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

int main()
{
  long long n;
  cin >> n;
  const long long d = 1000000007;
  long long a = 1, b = 1, c = 1;
  for (long long i = 0; i < n; i++)
  {
    a *= 10;
    a %= d;
    b *= 9;
    b %= d;
    c *= 8;
    c %= d;
  }
  b = (b*2) % d;
  long long x = a-b+c;
  x = (x + 3*d) % d;
  cout << x << endl;
}

Measured memory_bytes: 3192
N, K = map(int, input().split())
X = list(map(int, input().split()))

minp = 0
if X[N-1] <0:
    minp = N-1
else:
    while X[minp] < 0:
        minp += 1

lidx = 0
if minp > K:
    lidx = minp - K
ridx = lidx + K - 1
left = X[lidx]
right = X[ridx]
mind = right - left + min(abs(left), abs(right))

while ridx < N and left <= minp:
    left = X[lidx]
    right = X[ridx]
    mind = min(mind, right - left + min(abs(left), abs(right)))
    lidx += 1
    ridx += 1

print(mind)

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

using namespace std;

int main(void) {

	int t = 0;

	int A[6];
	for (int i = 1; i <= 5; i++) { cin >> A[i]; }
	vector<int> V;
	for (int i = 1; i <= 5; i++) {
		if (A[i] % 10 != 0) { V.push_back(A[i] % 10); }
	}

	for (int i = 1; i <= 5; i++) {

		t += (A[i]/10)*10;
	}


	if (V.size() > 0) {
		sort(V.begin(), V.end());
		t += V[0];
	}

	for (int i = 1; i < (int)V.size(); i++) {
		t += 10;
	}

	cout << t << endl;

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

Measured memory_bytes: 256
SA = input()
SB = input()
SC = input()

now_turn = 'a'
while True:
    if now_turn == 'a':
        if len(SA) == 0:
            print('A')
            exit()
        now_turn = SA[0]
        SA = SA[1:]
    elif now_turn == 'b':
        if len(SB) == 0:
            print('B')
            exit()
        now_turn = SB[0]
        SB = SB[1:]
    else:
        if len(SC) == 0:
            print('C')
            exit()
        now_turn = SC[0]
        SC = SC[1:]

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a,b;
    cin >>a>>b;
    if (a==1){
        a=a+13;
    }
    if (b==1){
        b=b+13;
    }
    if (a>b){
        puts("Alice");
    }else if(a<b) {
        puts("Bob");
    }else{
        puts("Draw");
    }
}

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

int main(void){
    int c_min = 105, f_max = -1;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'C') {
            if (i < c_min) c_min = i;
        }
        if (s[i] == 'F') {
            if (i > f_max) f_max = i;
        }
    }
    if (c_min < f_max) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(m)]

AB.sort(key=lambda x: x[0])
x = n
l = 0
for a, b in reversed(AB):
  if b > x :
    continue
  else:
    x = a
    l += 1
    
print(l)


Measured memory_bytes: 29140
#include <iostream>
#include <vector>
using namespace std;
class DisjointSet{
    public:
    vector<int> rank,p;
    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i=0;i<size;i++)makeSet(i);
    }
    void makeSet(int x){
        p[x]=x;
        rank[x]=0;
    }
    bool same(int x,int y){
        return findSet(x)==findSet(y);
    }
    void unite(int x,int y){
        link(findSet(x),findSet(y));
    }
    void link(int x,int y){
        if(rank[x]>rank[y]){
            p[y]=x;
        }else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++;
            }
        }
    }
    int findSet(int x){
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};
int main(){
    int n,a,b,q;
    int t;
    cin>>n>>q;
    DisjointSet ds=DisjointSet(n);
    for(int i=0;i<q;i++){
        cin>>t>>a>>b;
        if(t==0) ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b))cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3172
// In god we trust

#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>


#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000
#define int long long

using namespace std;
using namespace std::chrono;


signed main(){
  int n, p;
  cin >> n >> p;
  string s;
  cin >> s;


  if (p == 2 or p == 5){
    int ans = 0;
    for (int i = 0; i < n; i++)
      if ((s[i] - '0') % p == 0)
	ans += i + 1;

    cout << ans << endl;
    return 0;

  }
  int r[n];
  r[n - 1] = (s[n - 1] - '0') % p;
  
  int zeros = 0;
  if (r[n - 1] == 0)
    zeros++;
  
  int fac = 10;
  for (int i = n - 2; i >= 0; i--){
    r[i] = r[i + 1] + (s[i] - '0') * fac;
    fac *= 10;
    fac %= p;
    r[i] %= p;
    if (r[i] == 0)
      zeros++;
  }

 
  set<int> set_;
  unordered_map<int, int> m;
  int ans = 0;
  for (int i = n - 1; i >= 0; i--){
    auto f = set_.find(r[i]);
    if (f != set_.end()){
      ans += m[r[i]];
      m[r[i]]++;	
    }else{
      set_.insert(r[i]);
      m[r[i]] = 1;
    }
  }

 
  cout << ans + zeros<< endl;
  
}


Measured memory_bytes: 2820
import java.lang.*;
import java.io.*;
import java.util.*;


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

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt(), T = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		
		for (int i=0; i<n; ++i) {
			a[i] = in.nextInt();
			b[i] = a[i];
		}
		
		for (int i=n-2; i>=0; --i) {
			b[i] = Math.max(b[i], b[i+1]);
		}
		
		int mx = -1;
		int ans = 0;
		
		for (int i=0; i<n-1; ++i) {
			if (b[i+1] > a[i])
				mx = Math.max(mx, b[i+1]-a[i]);
		}
		
		// out.println("mx = " + mx);
		for (int i=0; i<n-1; ++i)
			if (b[i+1] == a[i]+mx)
				++ans;
		
		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 36496
#include <stdio.h>

int main(void)
{
	int A, B, C, D;
	int L, R;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	L = A+B;
	R = C+D;
	
	if(L>R)
		printf("Left\n");
	else if(L==R)
		printf("Balanced\n");
	else
		printf("Right\n");
	
	return 0;
}

Measured memory_bytes: 128
A,B,C,D  =map(int,input().split())
AB = [str(i) for i in range(A,B+1)]
CD = [str(j) for j in range(C,D+1)]
count = 0

for a in range(101):
  if str(a) in AB and str(a) in CD:
    count += 1
if count == 0:
  print(0)
else:
  print(count-1)

Measured memory_bytes: 3064
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;

const int N = 100000;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,r,tc,t;
    string s;
    
    cin>>n>>q;
    
    cin>>s;
    
    int ara[n+9]={0};
    for(i=0;i<n-1;i++)
    {
    	if(s[i]=='A' && s[i+1]=='C')
    		ara[i+2]++;
	}
	
	for(i=1;i<=n;i++)
	{
		ara[i]+=ara[i-1];
	}
	
	while(q--)
	{
		cin>>l>>r;
		
		cout<<ara[r]-ara[l]<<endl;
	}

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
ll ans[55555];
int main()
{

	int n,x,y; cin>>n>>x>>y;
	x--; y--;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int dist=abs(i-j);
			dist=min(dist,abs(i-x)+1+abs(y-j));
			dist=min(dist,abs(i-y)+1+abs(x-j));
			ans[dist]++;
		}
	}
	for(int i=1;i<=n-1;i++)
		cout<<ans[i]<<"\n";
}

Measured memory_bytes: 256
Q,H,S,D = map(int,input().split())
N = int(input())
H=min(2*Q,H)
S=min(2*H,S)
if 2*S < D:
    print(N*S)
else:
    if N%2==0:
        print((N//2)*D)
    else :
        print((N//2)*D+S)


Measured memory_bytes: 2940
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define trace(x) cerr << #x << " = " << x << endl
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define pi acos(-1)
#define en '\n'
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

int main()
{
    speed();
    ll a,b,c;
    cin>>a>>b>>c;
    if(b*c>=a)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




return 0;
}


Measured memory_bytes: 3648
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int max = Math.max(Math.max(a,b), c);
    if(a == b && b == c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(Math.abs(x - a) < Math.abs(x - b)){
              System.out.println("A");
            } else {
              System.out.println("B");
            }
          }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,M,cnt[100005];
bool red[100005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>M;
	fill(cnt,cnt+N,1);
	red[0]=true;
	while(M--){
		int x,y;cin>>x>>y;x--;y--;
		if(red[x])red[y]=true;
		if(cnt[x]==1)red[x]=false;
		cnt[x]--;cnt[y]++;
	}
	int ans=0;
	rep(i,N)ans+=red[i];
	cout<<ans<<endl;
}


Measured memory_bytes: 4464
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
  int n;
  cin >> n;
  int num[n];
  int sum=0;
  int check = 10000;
  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> num[i];
    sum+=num[i];
    if(num[i]%10!=0)
      check=min(check, num[i]);
      if(num[i]%10==0)
        count++;
  }
  if(sum%10==0)
    sum-=check;
  if(count==n)
    sum=0;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				sum+=__gcd(__gcd(i,j),k);
			}
		}
	}
	cout<<sum<<endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll x; cin>>x;
  ireps(a,-1000,1000){
    ireps(b,-1000,1000){
      ll A=round(pow(a,5));
      ll B=round(pow(b,5));
      if(A-B==x){
        cout<<a<<' '<<b<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4088
#!/usr/bin/env python3

import numpy as np


def solve(N, A):
    return np.array(A).argsort() + 1


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    ans = solve(N, A)

    print(' '.join(map(str, ans)))


Measured memory_bytes: 24144
/************************************************
*Author        :  lrj124
*Created Time  :  2018.11.01.19:08
*Mail          :  1584634848@qq.com
*Problem       :  d
************************************************/
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int maxn = 100 + 10;
long long h,w,k,f[maxn][10],fib[maxn] = {1,1,2,3};
int main() {
	scanf("%lld%lld%lld",&h,&w,&k);
	for (int i = 4;i <= 100;i++) fib[i] = (fib[i-1]+fib[i-2])%MOD;
	f[0][1] = 1;
	for (int i = 1;i <= h;i++){
		f[i][1] = (f[i-1][1]*fib[w-1]%MOD+f[i-1][2]*fib[w-2]%MOD)%MOD;
		f[i][w] = (f[i-1][w]*fib[w-1]%MOD+f[i-1][w-1]*fib[w-2]%MOD)%MOD;
		for (int j = 2;j < w;j++) f[i][j] = ((f[i-1][j-1]*fib[j-2]%MOD*fib[w-j]%MOD+f[i-1][j+1]*fib[j-1]%MOD*fib[w-j-1]%MOD)%MOD+f[i-1][j]*fib[j-1]%MOD*fib[w-j])%MOD;
	}
	printf("%lld",f[h][k]);
	return 0;
}

Measured memory_bytes: 384
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

unsigned get_digit(unsigned long long x)
{
    return log10(x) + 1;
}

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    for (int i = ceil(sqrt(N)); i > 0; i--)
    {
        if (N % i == 0)
        {
            ll A = i, B = N / i;
            cout << get_digit(A > B ? A : B) << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3876
import java.util.*;
import java.io.*;
class Main{
    public static void main (String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	while(true){
	    try{
		String text = br.readLine();
		if(text.equals("."))break;
		char word[] = text.toCharArray();
		LinkedList<Character> list = new LinkedList<Character>();
		for(int i = 0; i < word.length;i++){
		    if(word[i] == ']'){
			if(!list.isEmpty()){
			    if(list.getLast() == '['){
				list.removeLast();
			    }else{
				list.add(word[i]);
			    }
			}else{
			    list.add(word[i]);
			}
		    }else if(word[i] == ')'){
			if(!list.isEmpty()){
			    if(list.getLast() == '('){
				list.removeLast();
			    }else{
				list.add(word[i]);
			    }
			}else{
			    list.add(word[i]);
			}
		    }else if(word[i] == '(' ){
			list.add(word[i]);
		    }else if(word[i] == '['){
			list.add(word[i]);
		    }
		}
		if(list.size() == 0 ){
		    System.out.println("yes");
		}else{
		    System.out.println("no");
		}
	    }catch(IOException e){
	    }
	}
    }
}

Measured memory_bytes: 29952
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> B(N, 0);
  REP(i, N){
    if(i%2 == 0) B[0] += A[i];
    else B[0] -= A[i];
  }

  REP(i, N){
    B[(i+1)%N] = 2*A[i]-B[i];
  }

  REP(i, N){
    cout << B[i]; SPBR(i, N);
  }

  return 0;
}

Measured memory_bytes: 2816
k,n=map(int,input().split())
a=list(map(int,input().split()))

d=[]
for i in range(n-1):
    d.append(a[i+1]-a[i])

d.append(k-a[-1]+a[0])
d=sorted(d,reverse=True)
print(sum(d[1:]))

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

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}


int main() {
  int N,M,X,Y;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int x[N+1],y[M+1];
  for (int i = 0; i < N; i++) {
    scanf("%d",&x[i]);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d",&y[i]);
  }
  x[N] = X;
  y[M] = Y;
  qsort(x,N+1,sizeof(int),compare_int);
  qsort(y,M+1,sizeof(int),compare_int);
  int Z = x[N]+1;
  if (Z <= y[0]) printf("No War\n");
  else printf("War\n");
  return 0;
}


Measured memory_bytes: 128