akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int t = in.nextInt();
        int[]cost = new int[n];
        int[]mx = new int[n];
        int mm = 0;
        ArrayList<Integer> store = new ArrayList<>();
        for(int i =0;i<n;i++){
            cost[i] = in.nextInt();
        }
        int m =0;
        for(int i=n-1;i>=0;i--){
            mx[i]=m;
            m = Math.max(m,cost[i]);
        }
        for(int i =0;i<n;i++){
            int next = mx[i]-cost[i];
            mm = Math.max(mm,next);
            store.add(next);
        }
        int s = 0;
        for (int v:store){
            if (v==mm)
                s++;
        }
        System.out.println(s);
    }
}

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

int ans = 0;

int r(int,int);

int main(){
    int n;
    while(-1!=scanf("%d", &n)){
        ans = 0;
        r(4,n);
        cout << ans << endl;
    }
    return 0;
}

int r(int d,int n){
    if(n==0){
        ans++;
        return 0;
    }
    if(n<0 || d <= 0) return 0;

    for(int i=0; i<=9; i++){
        r(d-1, n-i);
    }
    return 0;
}

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

int main(int argc, char const* argv[])
{
    int p_array[50];
    int p,n;
    int wan;
    while (1) 
    {
        int max_index=0;
        int max_p= 0;
        int k=0,l=0;
        cin >> n >> p;
        wan = p;
        if (n == 0 && p==0) 
        {
            break;
        }

        //init p_array
        for (int j = 0; j < n; j++) 
        {
            p_array[j] = 0;
        }
        while (max_p != p) 
        {
            if (wan != 0) 
            {
                wan--;
                p_array[k]++;
            }
            else if(wan == 0)
            {
                wan = p_array[k];
                p_array[k] = 0;
            }
            //search max_p
            for (l = 0; l < n; l++) 
            {
                if (max_p < p_array[l]) 
                {
                     max_p = p_array[l];
                     max_index = l;
                }
            }
            //for (int m = 0; m < n; m++) 
            //{
            //    cout << p_array[m] << " ";
            //}
            //cout << "max_index= " << max_index;
            //cout << endl;
            k++;
            k = k % n;
        }
        cout << max_index << endl;
    }
    return 0;
}

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

int main() {
  string N;

  while (1) {
    cin >> N;
    if (N == "0") break;
    int tot = 0;
    for (int i = 0; i < N.size(); i++) {
      int a = N.at(i) - '0';
      tot += a;
    }
    cout << tot << endl;
  }
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u)a--;
    else b--;
    cout << a << " " << b << endl;

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
import Data.List.Split

understandable :: Int -> Int -> Bool
understandable x y
    | x > 9 = False
    | y > 9 = False
    | x < 1 = False
    | y < 1 = False
    | otherwise = True

kuku :: Int -> Int -> Int
kuku x y = case understandable x y of
             True -> x * y
             False -> -1

main :: IO ()
main = do
    inputs <- getLine
    let (x:y:_) = map read $ splitOn " " inputs :: [Int]
    print $ kuku x y


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

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

int main(){
    string s,t;
    cin>>s>>t;
    int cnt=0;
    rep(i,3){
        if(s[i]==t[i]) cnt++;
    }
    cout<<cnt<<endl;
}

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

using namespace std;


int main(){
    int a,b,c,d,e,f;
    
    cin>>a>>b>>c>>d>>e>>f;
    
    if(a + b*5 + c*10 + d*50 + e*100 + f*500  >= 1000)cout<<"1"<<endl;
    else cout<<"0"<<endl;

    return 0;
}

Measured memory_bytes: 1160
n,*l=map(int,open(0).read().split())
A=B=C=0;M=max
for i in range(n):
	A,B,C=l[3*i]+M(B,C),l[3*i+1]+M(C,A),l[3*i+2]+M(A,B)
print(M(A,B,C))

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

b.sort()

su = 0
for i in range(len(b)):
    if b[i][1] >= m:
        su += b[i][0]*m
        m = 0
    else:
        su += b[i][0]*b[i][1]
        m -= b[i][1]

    if m == 0:
        break

print(su)


Measured memory_bytes: 27760
N, M, X, Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x_max = -101
for i in range(N):
    if x[i] > x_max:
        x_max = x[i]
y_min = 100
for i in range(M):
    if y[i] < y_min:
        y_min = y[i]
count = 0
for z in range(X+1,Y+1):
    if x_max < z:
        if z <= y_min:
            count = 1

if count:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  for(int i=0;i<N/7+1;i++){
    if((N-7*i)%4==0 && N-7*i>=0){
      cout<<"Yes"<<endl;
      break;
    }
    else{
      if(i==N/7){
        cout<<"No"<<endl;
        break;
      }
      else
        continue;
    }
  }
}
      

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#define MAXN 100005
using namespace std;

int dp[MAXN][2];
int n, k;
vector<int> stones;

void solve() {
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= 1; ++j) {
            for (auto it : stones) {
                if (i >= it) {
                    dp[i][j] |= !dp[i - it][!j];
                }
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    stones.assign(n, 0);
    for (int i = 0; i < n; ++i) cin >> stones[i];
    solve();
    printf(dp[k][0] ? "First" : "Second");
    putchar('\n');
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a, b, k;
  
  int count;
  
  cin >> a >> b >> k;
  
  for(int i = max(a, b); i >= 1; i--)
  {
    if(a % i == 0 && b % i == 0) count++;
    if(count == k) {cout << i << endl; break;}
  }
  
  return 0;
}

Measured memory_bytes: 256
while(True):
  n,x=(int(a) for a in input().split())
  if n==0 and x==0:
    break
  if x-3<3:
    print('0')
    continue

  if x-3>n:
    start=n
  else:
    start=x-3

  count=0
  for i in range(start,2,-1):
    for j in range(i-1,1,-1):
      if i+j>=x:
        continue
      for k in range(j-1,0,-1):
        if i+j+k>x:
          continue
        elif i+j+k==x:
          count+=1
  print(count)


Measured memory_bytes: 5600
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }
ll mod = 1e9+7;

signed main() {
    ll n; cin>>n;
    vector<pair<ll,ll>>a(n),b(n);
    rep(i,n)cin>>a[i].first>>a[i].second;
    rep(i,n)cin>>b[i].first>>b[i].second;
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end());
    
    rep(i, n) {
        int bx = b[i].first, by = b[i].second;
        rep(i,a.size()){
           int ax=a[i].first,ay=a[i].second;
           if(ax<bx&&ay<by){
               a.erase(a.begin()+i);
               break;
           }
        }
    }
    cout << n-a.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INF = 1LL << 60;

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    int count = 0;
    bool flag = true;
    while(flag){
        for(int i=0;i<N;i++){
            if(A[i]%2!=0) flag = false;
            else A[i] = A[i]/2;
        }
        if(flag) count++;

    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n; cin >> n;
    cout << (1+n)*(n/2)+(n%2)*(n/2+1) << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://abc063.contest.atcoder.jp/tasks/arc075_b
TLE
"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def Cond(monsters, A, B, mid):
    t = [x - (B * mid) for x in monsters]
    t.sort(reverse=True)
    additional_damage = (A - B)

    total_count = 0
    for m in t:
        if m < 1:
            break
        total_count += ceil(m / additional_damage)

    if total_count <= mid:
        return True
    else:
        return False


def main(args):
    # N = 2
    # A = 10
    # B = 4
    # monsters = [20, 20]
    N, A, B = map(int, input().split())
    monsters = [int(input()) for _ in range(N)]

    total_count = 0
    if N == 1:
        total_count = ceil(monsters[0] / A)
    else:
        monsters.sort(reverse=True)
        lb = ceil(monsters[0] / A)
        ub = ceil(monsters[0] / B)
        # lb = 0
        # ub = 1e10

        for _ in range(30):
            mid = (lb + ub) // 2
            if Cond(monsters, A, B, mid):
                ub = mid
            else:
                lb = mid
        total_count = int(ub)

    print(total_count)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 11236
#include <stdio.h>
int main()
{
    int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)
            break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i%2==0){
                    if(j%2==0)
                        printf("#");
                    else
                        printf(".");
                }
                else{
                    if(j%2==0)
                        printf(".");
                    else
                        printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1000
#include<stdio.h>
int main(void){
  int A,B,C;
  int MAX;
  int cont = 0;
  scanf("%d%d%d",&A,&B,&C);
  MAX = (A > B) ? A : ((B > C) ? B : C);
  if(MAX - A){
    if((MAX - A) % 2){
      cont += ((MAX - A) / 2);
       A = MAX - 1 ;
    }
    else {
       cont += ((MAX - A) / 2);
        A = MAX;
    }
  }
  if(MAX - B){
    if((MAX - B) % 2){
      cont += ((MAX - B) / 2);
        B = MAX - 1 ;
    }
    else {
       cont += ((MAX - B) / 2);
         B = MAX;
    }
  }if(MAX - C){
    if((MAX - C) % 2){
      cont += ((MAX - C) / 2);
       C = MAX - 1 ;
    }
    else {
      cont += ((MAX - C) / 2);
        C = MAX;
    }
  }
  if(MAX * 3 - (A + B + C) == 2){
    cont += 1;
    printf("%d",cont);
  }
  else if(MAX * 3 - (A + B + C) == 0){
     printf("%d",cont);
  }
  else if(MAX * 3 - (A + B + C) == 1){
    cont += 2;
     printf("%d",cont);
  }
    return 0;
}

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

ll solve() {
    ll D, N;
    cin >> D >> N;
    ll a = 1;
    for ( int i = 0; i < D; i++ ) {
        a *= 100;
    }
    ll ans = N * a;
    if ( N == 100 ) ans += a;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100003
using namespace std;

int main(){
    string s;
    int ans,l;
    cin>>s;
    l = ans = s.size();
    for(int i=1;i<l;i++){
        if(s[i]==s[i-1]) continue;
        ans = min(ans,max(i,l-i));
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    map< int, int, greater<int> > mp;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        mp[x]++;
    }
    
    int a = 0, b = 0;
    for(auto &it: mp) {
        if(it.second >= 2) {
            it.second -= 2;
            a = it.first;
            break;
        }
    }

    for(auto &it: mp) {
        if(it.second >= 2) {
            it.second -= 2;
            b = it.first;
            break;
        }
    }

    cout << 1LL * a * b << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    getline(cin,s);
    getline(cin,t);
    int k=0;
    for(int i=0;i<s.size();i++)
        if(t[i]!=s[i])
           k++;
    
    cout<<k;
    return 0;
}
     
   




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

int main() {
	vector<int> V_1(4);
	for (int i = 0; i < 4; i++) {
		cin >> V_1[i];
	}
	vector<int> V_2(2);
	for (int i = 0; i < 2; i++) {
		cin >> V_2[i];
	}
	sort(V_1.begin(), V_1.end());
	sort(V_2.begin(), V_2.end());	
	cout << V_1[3] + V_1[2] + V_1[1] + V_2[1] << endl;
}



Measured memory_bytes: 3156
n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0] * (s + 1) for _ in range(n + 1)]
for i in range(n):
    dp[i][0] = 1
for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
ans = 0
for i in range(n + 1):
    ans += dp[i][s]
    ans %= mod
print(ans)


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

using namespace std;

// #define int 		long long
#define endl 		"\n"
#define mod 		998244353
#define inf 		1e18
#define IOS 		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n, k, x, y;
	cin >> n >> k;

	vector<pair<int, int>> s(k);

	for (int i = 0; i < k; i++) {
		cin >> s[i].first >> s[i].second;

	}


	vector<int> dp(n + 1, 0);
	dp[1] = 1;

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

		for (int j = 0; j < k; j++) {
			if (i <= s[j].first)
				continue;

			int left = s[j].first;
			int right = min(s[j].second, i - 1);

			int val = (dp[i - left] - dp[i - right - 1] + mod) % mod;

			dp[i] = (dp[i] + val) % mod;
		}

		if (i != n)
			(dp[i] += dp[i - 1]) %= mod;
	}

	cout << dp[n] ;

	return 0;
}

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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  stack<char> s;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == '(') s.push('(');
    else {
      if (s.empty() || s.top() == ')') s.push(')');
      else s.pop();
    }
  }
  int cnt1 = 0, cnt2 = 0;
  while (!s.empty()) {
    if (s.top() == ')') cnt1++;
    else cnt2++;
    s.pop();
  }
  for (int i = 0; i < cnt1; i++) cout << "(";
  cout << S;
  for (int i = 0; i < cnt2; i++) cout << ")";
  cout << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskH solver = new TaskH();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskH {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int MODULO = (int) (1e+9) + 7;
            int n = in.nextInt();
            int m = in.nextInt();
            boolean[][] field = new boolean[n][m];
            for (int i = 0; i < n; i++) {
                String s = in.next();
                for (int j = 0; j < m; j++)
                    if (s.charAt(j) == '.')
                        field[i][j] = true;
            }
            int[][] dp = new int[n][m];
            dp[0][0] = 1;
            for (int i = 1; i < m; i++) {
                if (field[0][i])
                    dp[0][i] = 1;
                else
                    break;
            }
            for (int i = 1; i < n; i++)
                if (field[i][0])
                    dp[i][0] = 1;
                else
                    break;
            for (int i = 1; i < n; i++)
                for (int j = 1; j < m; j++)
                    if (field[i][j])
                        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MODULO;
            out.println(dp[n - 1][m - 1]);
        }

    }

    static 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());
        }

    }
}



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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll N;
ll a[222222];
ll b[222222];

int main() {
   cin >> N;
   rep (i, N) {
      cin >> a[i];
      b[i] = a[i];
   }

   repp (i, 1, N+1) {
      a[i] += a[i-1];
   }
   for (int i = N-1; i >= 0; i--) {
      b[i] += b[i+1];
   }

   ll ans = 1e18;
   rep (i, N-1) {
      // ll x = a[i];
      // ll y = a[N] - x;
      // debug2(x, y)
      // ans = min(ans, abs(x-y));
      // debug2(a[i], b[i+1])
      ans = min(ans, abs(a[i] - b[i+1]));
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 3328
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def solve():
    l, r, d = getList()
    ans = 0
    for i in range(l, r +1):
        if i % d == 0:
            ans += 1

    print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 62016
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


int n,m;
Edges<ll> es;
bool ans=false;



template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto lim = numeric_limits< T >::max();
  vector< T > dist(V, lim);
  dist[s] = 0;
  rep(i,V-1) {
    for(auto &e : edges) {
      if(dist[e.src] == lim) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }  

  bool neg[20000]={};

  rep(i,V){
    for(auto &e:edges){
      if(dist[e.src]==lim) continue;
      if(dist[e.to]>dist[e.src]+e.cost){
        dist[e.to]=dist[e.src]+e.cost;
        neg[e.to]=true;
      }
      if(neg[e.src])
        neg[e.to]=true;
    }
  }
  if(neg[V-1])
    return vector<T> ();
  
  return dist;

}

int main(){
  int p;
  cin>>n>>m>>p;
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    c-=p;
    es.PB(edge<ll>(a,b,-c));
  }

  vector<ll> s = bellman_ford(es,n,0);
  if(s.empty())
    cout<<-1<<endl;
  else
    cout<<max(0LL,-s[n-1])<<endl;

}

Measured memory_bytes: 512
def main():
    n = int(input())
    l = list()

    for _ in range(n):
        l.append(int(input()))

    minv = l[0]
    maxv = -1000000000

    for j in range(1, n):
        maxv = max(l[j] - minv, maxv)
        minv = min(minv, l[j])

    print(maxv)

main()


Measured memory_bytes: 13588
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll n,t,x=26ll,y=25ll,k,i,j,p,q;

    cin>>n;

    string st;

    string s[30]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

    while(n){

        k=n%x;

        if(k==0){

            k=26;
            n--;
        }
        n--;

        st+=s[--k];
        n/=x;
}

    reverse(st.begin(),st.end());

    cout<<st<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int v[300009];

int main(){
	DRI(n);
	REP(i,3*n)RI(v[i]);
	sort(v,v+3*n);
	LL ans=0;
	REP(i,n){
		ans+=v[3*n-2-2*i];
	}
	printf("%lld",ans);
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

int n , k;
int a[120000] , b[120000] , c[120000] , tot;
void work () {
	int i , j , l , ti;
	scanf ( "%d%d" , &n , &k );
	if ( 2 * k - 1 > n ) {
		printf ( "-1\n" );
		return ;
	}
	for ( i = 1 , j = k ; j <= k + n - 1 ; i++ , j += 2 ) {
		a[i] = j;
	}
	ti = i - 1; l = k + n;
	for ( j -= 2 ; j >= k ; j -= 2 , ti-- ) {
		b[ti] = l;
		l++;
	}
	l = k + n + n - 1;
	for ( j = k + 1 ; j <= k + n - 1 ; i++ , j += 2 ) {
		a[i] = j;
		b[i] = l;
		l--;
	}
	for ( i = 1 ; i <= n ; i++ ) c[i] = k + n + n + i - 1;
	for ( i = 1 ; i <= n ; i++ ) {
		printf ( "%d %d %d\n" , a[i] , b[i] , c[i] );
	}
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>

int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    int x;
    for (int i=0;i<5;++i){
        std::cin >> x;
        if (x == 0) {
            std::cout << (i+1);
            return 0;
        }
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vz;
typedef vector<vz> vvz;
typedef pair<ll, ll> pll;
#define sz(x) int((x).size())
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(ll i=(a); i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define os(x) cout<<x<<' '
#define on(x) cout<<x<<"\n"
#define nl cout<<"\n"
#define maxe(x) max_element(all(x))-(x).begin()
#define mine(x) min_element(all(x))-(x).begin()
const ll P=1e9+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("C:\\Users\\ASISH\\Desktop\\coding\\input1.txt", "r", stdin);
	freopen("C:\\Users\\ASISH\\Desktop\\coding\\output1.txt", "w", stdout);
#endif

	int tc=1;
	fo(q, tc)
	{
		ll h, w, m;
		cin>>h>>w>>m;

		map<pair<ll, ll>, ll> mp;
		
		vll cx(h+1), cy(w+1);

		fo(i, m){
			ll x, y;
			cin>>x>>y;
			mp[{x, y}]=1;
			cx[x]++;
			cy[y]++;
		}

		ll mx=0, my=0;
		fo(i, sz(cx)){
			mx=max(mx, cx[i]);
		}
		fo(i, sz(cy)){
			my=max(my, cy[i]);
		}

		vll vx, vy;
		fo(i, sz(cx)){
			if(cx[i] == mx) vx.pb(i);
		}
		fo(i, sz(cy)){
			if(cy[i] == my) vy.pb(i);
		}

		bool flag=0;
		for(auto i:vx){
			for(auto j:vy){
				if(!mp[{i, j}]){
					flag=1;
					break;
				}
			}
			if(flag) break;
		}
		if(flag) on(min(mx+my, m));
		else on(min(mx+my-1, m));
	}
	cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 35032
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
a=sorted(list(map(int,input().split())))
if n%2==0:
    l=[]
    for i in range(n//2):
        l.append(i*2+1)
        l.append(i*2+1)
else:
    l=[0]
    for i in range(n//2):
        l.append((i+1)*2)
        l.append((i+1)*2)

if a==l:
    print(pow(2,n//2,1000000007))
else:
    print(0)

Measured memory_bytes: 13880
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long N, M;
int main() {
    while (cin >> N >> M) {
        long long pow = 1LL<<M;
        long long ikkai = 1900LL * M + 100LL * (N - M);
        cout <<  ikkai * pow << endl;
    }
}






















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int K;
    string S;
    cin >> K >> S;
    if (S.size() <= K)
    {
        cout << S << endl;
    }
    else
    {
        for (int i = 0; i < K; ++i)
        {
            cout << S[i] << flush;
        }
        cout << "..." << endl;
    }
}

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

int main() {
  
  int N; cin >> N; int sum = 0;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  sort(vec.begin(), vec.end());
  
  for (int x : vec) sum += x;
  
  if (sum % 10 != 0) { cout << sum << endl; return 0; }
  
  for (int i = 0; i < N; i++) {
    
    int tmp = vec[i];
    
    if (tmp % 10 != 0) { cout << sum - tmp << endl; return 0; }
    
  }
  
  cout << 0 << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;

		ans += min(abs(2 * (K - x)), abs(2 * x));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define whyqx
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int l,r,ans=Inf;
int main()
{
	cin>>l>>r;
	for(int i=l;i<min(r,l+2019);i++)
		for(int j=i+1;j<=min(r,l+2019);j++)
			ans=min(ans,i%2019*(j%2019)%2019);
	cout<<ans<<endl;
	return 0;
}



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


int main (void) {
  int A, B, Q;
  std::cin >> A >> B >> Q;

  std::vector<long long> s(A);
  std::vector<long long> t(B);

  for(int i=0; i<A; i++) std::cin >> s[i];
  for(int i=0; i<B; i++) std::cin >> t[i];


  for(int i=0; i<Q; i++) {
    long long x; std::cin >> x;
    auto itr1 = std::lower_bound(s.begin(), s.end(), x);
    auto itr2 = std::lower_bound(t.begin(), t.end(), x);

    std::vector<long long> d;
    if ( itr1 != s.end() && itr2 != t.end() )
      d.push_back ( std::max( std::abs(*itr1-x), std::abs(*itr2-x) ) );
    if ( itr1 != s.begin() && itr2 != t.begin() )
      d.push_back ( std::max( std::abs(x-*std::prev(itr1)), std::abs(x-*std::prev(itr2)) ) );
    if ( itr1 != s.end() && itr2 != t.begin() )
      d.push_back ( std::abs(*itr1-x) + std::abs(x-*std::prev(itr2))*2 );
    if ( itr1 != s.end() && itr2 != t.begin() )
      d.push_back ( std::abs(*itr1-x)*2 + std::abs(x-*std::prev(itr2)) );
    if ( itr1 != s.begin() && itr2 != t.end() )
      d.push_back ( std::abs(*itr2-x) + std::abs(x-*std::prev(itr1))*2 );
    if ( itr1 != s.begin() && itr2 != t.end() )
      d.push_back ( std::abs(*itr2-x)*2 + std::abs(x-*std::prev(itr1)) );
    std::cout << *std::min_element(d.begin(), d.end()) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 2944
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n,m; cin>>n>>m;
  if(m%n==0){
    cout<<m/n; return;
  }
  ll ans=1,cnt=2;
  while(m-n*cnt>n){
    if((m-n*cnt)%cnt==0) ans=max(ans,cnt);
    cnt++;
  }
  cout<<ans;
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 256
def papers(n, arr):
    for ele in arr:
        if ele % 2 == 0:
            if ele % 3 == 0 or ele % 5 == 0:
                pass
            else:
                return 'DENIED'
        else:
            pass
    return 'APPROVED'

if __name__ == "__main__":
    n = int(input())
    arr = [int(s) for s in list(input().split())]
    print(papers(n, arr))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define maxn 5005
using namespace std;
int arr[maxn],brr[maxn][205];
int L[maxn][205];
ll seg[maxn<<2],tag[maxn<<2];
void push(int p,int lch,int rch) {
	seg[lch] += tag[p];		tag[lch] += tag[p];
	seg[rch] += tag[p];		tag[rch] += tag[p];
	tag[p] = 0;
}
void modify(int l,int r,int ql,int qr,int p,int add) {
	if(l == ql && r == qr) {
		seg[p] += add;
		tag[p] += add;
	}
	else {
		int mid = (l+r)>>1 , lch = p<<1 , rch = p<<1|1;
		push(p,lch,rch);
		if(qr <= mid)
			modify(l,mid,ql,qr,lch,add);
		else if(ql > mid)
			modify(mid+1,r,ql,qr,rch,add);
		else {
			modify(l,mid,ql,mid,lch,add);
			modify(mid+1,r,mid+1,qr,rch,add);
		}
		seg[p] = max(seg[lch],seg[rch]);
	}
}
ll query(int l,int r,int ql,int qr,int p) {
	if(l == ql && r == qr)
		return seg[p];
	else {
		int mid = (l+r)>>1 , lch = p<<1 , rch = p<<1|1;
		push(p,lch,rch);
		if(qr <= mid)
			return query(l,mid,ql,qr,lch);
		else if(ql > mid)
			return query(mid+1,r,ql,qr,rch);
		else
			return max(query(l,mid,ql,mid,lch),query(mid+1,r,mid+1,qr,rch));
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=2;i<=n;i++)
		cin >> arr[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin >> brr[i][j];
	ll ans = 0;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			int now = brr[i][j] , k = i-1;
			for(;k>=1;k--) {
				if(brr[k][j] > now)		break;
				modify(1,n,L[k][j],k,1,now - brr[k][j]);
				k = L[k][j];
			}
			L[i][j] = k + 1;
			modify(1,n,i,i,1,now);
		}
		if(i > 1)	modify(1,n,1,i-1,1,-arr[i]);
		ans = max(ans,query(1,n,1,i,1));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8576
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int H, W;
    vector<vector<char>> A;

    void input() {
        cin >> H >> W;
        A.resize(H, vector<char>(W));
        rep(i, 0, H) {
            rep(j, 0, W) {
                cin >> A[i][j];
            }
        }
    }

    void solve() {
        input();
        queue<pair<int, int>> que;
        vector<vector<int>> dist(H, vector<int>(W, INF));
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (A[i][j] == '#') {
                    que.push(make_pair(i, j));
                    dist[i][j] = 0;
                }
            }
        }

        while (!que.empty()) {
            auto top = que.front();
            int h = top.first;
            int w = top.second;
            que.pop();

            int dh[] = {-1, 0, 1, 0};
            int dw[] = {0, -1, 0, 1};

            for (int i = 0; i < 4; ++i) {
                int nh = h + dh[i];
                int nw = w + dw[i];

                if (nh >= 0 && nh < H && nw >= 0 && nw < W && dist[nh][nw] > dist[h][w] + 1) {
                    dist[nh][nw] = dist[h][w] + 1;
                    que.push(make_pair(nh, nw));
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                chmax(ans, dist[i][j]);
            }
        }

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


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

int main()
{   
	char N[55][55],M[55][55]; 
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>N[i][j];
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++)
			cin>>M[i][j];
	for(int i=1;i<=n-m+1;i++)
		for(int j=1;j<=n-m+1;j++)
			for(int k=i;k<=m+i-1;k++)
				for(int l=j;l<=m+j-1;l++)
				{
					if(N[k][l]!=M[k-i+1][l-j+1])
					{
						k=m+i;
						break;
					}
					if(l==m+j-1 && k==m+i-1)
					{
						printf("Yes\n");
						return 0;
					}
				}
	printf("No\n");
}

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

int main(int argc, const char * argv[]) {
    string S;
    int count = 0;
    
    cin >> S;
    
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'o') {
            count++;
        }
    }
    
    if (count >= 8) {
        cout << "YES" << endl;
    } else {
        if (count + (15 - S.length()) >= 8) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 764
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [h, w] <- getIntList
  if (h == 1) || (w == 1) then 
    print 1
  else do
    let s = h * w
    let d = s `div` 2
    let m = s `mod` 2
    if m == 0 then 
      print d
    else 
      print $ d + 1

Measured memory_bytes: 380
#include<atcoder/math>
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int64_t n;
vector <int64_t> fac;
int64_t ans = 1e18;


/// find answer a*x+b*y=gcd(a,b)
/// ref: cp-algo
int64_t ex_gcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
    x = 1, y = 0;
    int64_t x1 = 0, y1 = 1, a1 = a, b1 = b;
    while (b1) {
        int64_t q = a1 / b1;
        tie(x, x1) = make_tuple(x1, x - q * x1);
        tie(y, y1) = make_tuple(y1, y - q * y1);
        tie(a1, b1) = make_tuple(b1, a1 - q * b1);
    }
    return a1;
}


void brute(int64_t x, int64_t y) {
    int64_t foo, bar;
    ex_gcd(x, y, foo, bar);
    int64_t real_foo = foo * x;
    int64_t real_bar = -y * bar;
    assert(real_foo - real_bar == 1);
    if (real_bar > 0) ans = min(ans, real_bar);
    else {
        int64_t need = 1 - real_bar;
        int64_t add = (need + n - 1) / n;
        real_bar += add * n;
        ans = min(ans, real_bar);

    }

}

int main() {

    cin >> n;
    n <<= 1;

   // int64_t brute_ans = LLONG_MAX;
    ans = LLONG_MAX;
/*
    for (int64_t i = 1 ; i <= n * 2 ; ++ i) {
        if ((i * (i + 1)) % n == 0) {
            brute_ans = i;
            break;
        }
    }
*/
    fac.clear();
    {
        int64_t bar = n;
        for (int64_t i = 2 ; i * i <= bar ; ++ i) {
            if (bar % i == 0) {
                int foo = 0;
                int64_t mul = 1;
                do {
                    bar /= i;
                    foo += 1;
                    mul *= i;
                } while (bar % i == 0);
                fac.push_back(mul);
            }

        }
        if (bar != 1) fac.push_back(bar);
    }

    int m = fac.size();

    for (int j = 0 ; j < (1 << m) ; ++ j) {
        int64_t foo = 1;
        for (int bar = 0; bar < m ; ++ bar) {
            if (j >> bar & 1) foo *= fac[bar];
        }
        brute(foo, n / foo);
    }

    cout << ans << '\n';

    /**
        No more than 11 primes divide N
        brute force subset of prime?
        N | (k)(k + 1)

        if p1, p2, p3,..., px | k
            that means these primes won't divide k + 1
            so we can get it like
            foo = p1, ..., px some subset * C1
            bar = excludent * C2
            foo | (k)
            bar | (k + 1)
            k + 1 = bar(c2)
            k     = foo(c1)
            bar*c2 - foo*c1 = 1
            what is other restriction?
            bar = 1, foo = 22
            c2 = 1, c1 = 0 is not valid, but why?
            either c1, c2 can't be zeros
            1 | k 22 | (k + 1)

            k + 1 = bar * c2
            k = foo * c1
            k + 1 = x
            k = 22y
            Find minimal positive integer k that have solution?
            x - 22y = 1

    */
}
/*
    Why not Ventuswill?
*/


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

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;

        int p[55][1010];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                cin >> p[i][j];
            }
        }

        long long ans = 0;
        for (int i = 0; i < n; i++) {
            long long cal = 0;
            for (int j = 0; j < m; j++) {
                cal += p[j][i];
            }
            ans = max(ans, cal);
        }

        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3264
#include <stdio.h>
#include <stdlib.h>
void putinArray(int count, int d, int *array);
int main(int argc, char** argv) {
    int number1,number2;
    int readScan = scanf("%d", &number1);
    int array1[number1];
    for(int i=0;i<number1;i++)
    {
        int readScan = scanf("%d", &array1[i]);
    }
    int readScan1 = scanf("%d", &number2);
    int array2[number2];
    for(int i=0;i<number2;i++)
    {
        int readScan = scanf("%d", &array2[i]);
    }
    int key;
    int count=0;
    for(int i=0;i<number2;i++)
    {
        for(int j=0;j<number1;j++)
        {
            key=array2[i];
            if(key == array1[j])
            {
                count++;
                break;
            }
        }
    }
    printf("%d\n", count);
    return (EXIT_SUCCESS);
}




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

int main(){
int x;
cin >> x;
int max=0;

if(x == 1){
 cout << x << endl;
return 0; 
}

for(int i = x;i > 0;i--){
 for(int l = 1;l <= x;l++){
 for(int m = 2;m <= x;m++){
  if((int)pow(l,m) == i){
cout << i << endl;
return 0;
}else if((int)pow(l,m) > i){break;}
}
}
}
   //cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int S = sc.nextInt();
    int count = 0;
    for(int i=0;i<=K;i++){
      for(int j=0;j<=K;j++){
        if(S-i-j>=0&&S-i-j<=K){
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23636
#include<stdio.h>

int main(){
	long long int n,a[100010],b[100010],ans=0;
	scanf("%lld",&n);
	int i,j,tmp=0;
	for(i=0;i<n+1;i++){
		scanf("%lld",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%lld",&b[i]);
	}
	for(i=0;i<n;i++){
		if(a[i]>=b[i])
			ans+=b[i];
		else{
			if(a[i]+a[i+1]<=b[i]){
				ans +=a[i]+a[i+1];
				a[i+1]=0;
			}
			else{
				ans +=b[i];
				a[i+1]-=b[i]-a[i];
			}
		}
	}
	printf("%lld",ans);
	return 0;
}
			

Measured memory_bytes: 1664
n = int(input())
A = list(map(int, input().split()))

l = 0
r = 0
ans = 0
sum = A[0]
xor = A[0]
while True:
    if sum == xor:
        ans += r-l+1
        if r == n-1:
            break
        r += 1
        sum += A[r]
        xor ^= A[r]
    else:
        sum -= A[l]
        xor ^= A[l]
        if l == n-1:
            break
        l += 1

print(ans)


Measured memory_bytes: 24712
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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;
}

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int A, B;
    cin >> A >> B;

    if (A > 9 || B > 9) {
        cout << -1 << endl;
        return 0;
    }

    cout << A * B << endl;

    return 0;
}


Measured memory_bytes: 256