akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

#define NO return puts("No"),0
#define it map<int,int > :: iterator 

map<int,int > t;
int n;

int main() {
    read(n);
    for(int i=1,x;i<=n;i++) read(x),t[x]++;
    if(t.size()>3) NO;
    if(t.size()==3) {
        if(n%3!=0) NO;int res=0;
        for(it i=t.begin();i!=t.end();i++) {
            res^=i->first;
            if(i->second!=n/3) NO;
        }if(res!=0) NO;
    } else if(t.size()==2) {
        if(n%3!=0) NO;
        if(t.begin()->first!=0) NO;
        if(t.begin()->second!=n/3) NO;
    } else if(t.begin()->first!=0) NO;puts("Yes");
    return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int h, w, t[55][55], u, dx[]={0,1,0,-1}, dy[]={-1,0,1,0};
char s[55][55];

main(){
    scanf("%d%d", &h, &w);
    for(int i=0; i<h; i++){
        scanf("%s", s[i]);
        for(int j=0; j<w; j++){
            t[i][j] = -1;
            u += (s[i][j]=='.');
        }
    }
    int que[3333], l=0, r=0;
    que[r++] = 0;
    t[0][0] = 1;
    while(r != l){
        int x = que[l]/100, y = que[l]%100;
        l++;
        for(int i=0; i<4; i++){
            int nx = x+dx[i], ny = y+dy[i];
            if(0<=nx&&nx<h && 0<=ny&&ny<w && t[nx][ny]==-1 && s[nx][ny]=='.'){
                t[nx][ny] = t[x][y] + 1;
                que[r++] = nx*100 + ny;
            }
        }
    }
    if(t[h-1][w-1] == -1)puts("-1");
    else printf("%d\n", u - t[h-1][w-1]);
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, ans = 0;
  cin >> N;

  if (N % 2 || N <= 3) {
    cout << 0 << endl;
    return 0;
  }

  for (ll base = 10; base <= N; base *= 5) {
    ans += N / base;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# 入力
N = int(input())
A = list(map(int, input().split()))

R = max(A)
prime_factor_counter = [0]*(R+1)

# D[x]にxを割り切れる最初の素数を格納
# 次に行う素因数分解で試し割りのムダを削減するための前準備
D = [0]*(R+1)
for i in range(2, R+1):
    if D[i]:
        continue
    n = i
    while n < R+1:
        if D[n] == 0:
            D[n] = i
        n += i

# 素因数分解し、素因子をカウント
# ex: 12 => 2と3のカウントを+1する
for a in A:
    tmp = a
    while tmp > 1:
        prime_factor = D[tmp]
        prime_factor_counter[prime_factor] += 1
        while tmp%prime_factor == 0:
            tmp //= prime_factor

# 回答出力
if max(prime_factor_counter) < 2:
    print('pairwise coprime')
elif max(prime_factor_counter) - A.count(1) < N:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 197232
#include<bits/stdc++.h>
using namespace std;
struct happy{
  int d,a,k,t;
  bool operator<(const happy h) const{
    if(d!=h.d) return d<h.d;
    return a<h.a;
  }
};
int main(){
  int n,m,l,i,j,k,a,b,ans=0;
  cin>>n>>m>>l;
  vector<happy> v;
  happy h;
  for(i=0;i<m;i++){
    cin>>h.d>>h.a>>h.k>>h.t;
    v.push_back(h);
  }
  sort(v.begin(),v.end());
  int dp[5][10][50]={};
  for(i=0;i<m;i++){
    for(j=0;j<=v[i].d;j++){
      for(k=0;k<=n+1;k++){
	if(j==v[i].d&&k>v[i].a) break;
	for(a=0;a<l;a++){
	  dp[v[i].d][v[i].a+v[i].k][a+1]
	    =max(dp[v[i].d][v[i].a+v[i].k][a+1],
		 dp[j][k][a]+v[i].t);
	  ans=max(ans,dp[v[i].d][v[i].a+v[i].k][a+1]);
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3160
package main

import (
	"bufio"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	A := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
		sum += A[i]
	}

	X := make([]int, N)
	X[0] = sum
	for i := 1; i < N; i += 2 {
		X[0] -= 2 * A[i]
	}

	for i := 1; i < N; i++ {
		X[i] = 2*A[i-1] - X[i-1]
	}

	writer := bufio.NewWriter(os.Stdout)
	writer.WriteString(strconv.Itoa(X[0]))
	for i := 1; i < N; i++ {
		writer.WriteString(" " + strconv.Itoa(X[i]))
	}
	writer.Flush()
}


Measured memory_bytes: 6400
num = (int)(input())
button = [0 for i in range(num + 1)]
for i in range(1, num + 1):
  button[i] = (int)(input())
temp = 1
count = 0
for i in range(1, num + 1):
  temp = button[temp]
  count += 1
  if temp == 2:
    break
else:
  count = -1
print(count)

Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
ll A,B,C,D;
map<ll,ll> memo;

ll solve (ll N) {
  if (N == 0) return 0;
  else if (N == 1) return D;
  else if (memo[N] != 0) return memo[N];
  else {
    ll l2 = (N/2) * 2;
    ll r2 = ((N+1)/2) * 2;
    ll l3 = (N/3) * 3;
    ll r3 = ((N+2)/3) * 3;
    ll l5 = (N/5) * 5;
    ll r5 = ((N+4)/5) * 5;
    ll res = pow(10LL,18LL);
    if (N < res/D) res = N*D;
    res = min(res,solve(l2 / 2) + A + (abs(N-l2) * D));
    res = min(res,solve(l3 / 3) + B + (abs(N-l3) * D));
    res = min(res,solve(l5 / 5) + C + (abs(N-l5) * D));
    res = min(res,solve(r2 / 2) + A + (abs(N-r2) * D));
    res = min(res,solve(r3 / 3) + B + (abs(N-r3) * D));
    res = min(res,solve(r5 / 5) + C + (abs(N-r5) * D));
    memo[N] = res;
    return res;
   }
}


int main() {
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    memo.clear();
    ll N;
    cin >> N >> A >> B >> C >> D;
    cout << solve(N) << endl;
  }
  return 0;
}

Measured memory_bytes: 4476
#include<stdio.h>

int main(void){
    int l,r,a,b,i,j,ans,min=3000;
    scanf("%d %d",&l,&r);
    a=l;
    b=r;
    l%=2019;
    r%=2019;
    //printf("%d %d ",l,r);
    if(l>=r){
        printf("0");
    }else{
        if(a+2019<b){
            printf("0");
        }else{
            a=a%2019;
            b=b%2019;
            for(i=a;i<b;i++){
                for(j=i+1;j<b+1;j++){
                    ans=(i*j)%2019;
                    if(ans<min){
                        min=ans;
                    }
                }
            }
            printf("%d",min);
        }
    }
    return 0;
}



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

int main() {
  int X, N, A, B;
  cin >> X >> N;
  A = X;
  B = X;
  
  if(N == 0){
    cout << X << endl;
    return 0;
  }
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  
  bool check0 = true;
  for (int i = 0; i < N; i++) {
    if(X == vec.at(i)){
      check0 = false;
      break;
    }
  }
  if(check0){
    cout << X << endl;
    return 0;
  }
  
  while(true){
    bool check1 = true;
    A--;
    for (int i = 0; i < N; i++) {
      if(A == vec.at(i)){
        check1 = false;
        break;
      }
    }
    if(check1){
      cout << A << endl;
      return 0;
    }
  
    bool check2 = true;
    B++;
    for (int i = 0; i < N; i++) {
      if(B == vec.at(i)){
        check2 = false;
        break;
      }
    }
    if(check2){
      cout << B << endl;
      return 0;
    }  
  }
  
  
}


Measured memory_bytes: 3632
// A - ringring

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = a + b + c - max(a, max(b, c));

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){
	int A, B, C; cin >> A >> B >> C;
	for(int s = A;s <= A*B; s += A){
		if(s%B == C){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int k; cin >> k;
    int x; cin >> x;
    for (int i=x-k+1; i<=x+k-1; i++){
        if (i != x+k-1){
            cout << i << " ";
        } else {
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int n,k;cin>>n>>k;
  cout << n-k+1 << endl;
}

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


Measured memory_bytes: 768
using System;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        if (N % 2 == 0)
        {
            bool iterationFlag = true;
            for(int i = 0; i < N / 2; i++)
            {
                if (S[i] != S[N / 2 + i]) iterationFlag = false;
            }
            if (iterationFlag == true) { Console.WriteLine("Yes"); }
            else { Console.WriteLine("No"); }
        }
        else
        {
            Console.WriteLine("No");
        }
    }
    
}

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld N;
    vector<lld> A;
    cin >> N;
    for (int i = 0; i < N; i++) {
        lld a;
        cin >> a;
        A.push_back(a);
    }
    dsort(A,lld);
    lld ans = 0;
    queue<lld> que;
    que.push(A[0]);
    for (int i = 1; i < N; i++) {
        ans += que.front();
        que.pop();
        que.push(A[i]);
        que.push(A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6324
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int i=0; i < N; i++) {
        cin >> vec.at(i);
    }

    int right = 0;
    int64_t sum = 0;
    int64_t count = 0;
    for (int left=0; left < N; left++) {
        while(right < N && (sum ^ vec[right]) == (sum + vec[right])) {
            sum += vec[right];
            right++;
        }

        count += right - left;
        if (left == right) {
            right++;
        }
        sum -= vec[left];
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys

S = input()

da = ""

for i in range(len(S)):

    if S[i] != "A":
        da += S[i]

if da != "KIHBR":
    print ("NO")
    sys.exit()

last = ""
na = 0
for i in range(len(S)):

    if S[i] == "A":
        na += 1

    else:
        last = S[i]
        na = 0

    if (last in ["","H","B","R"] and na > 1 ) or (last in ["K","I"] and na > 0):
        print ("NO")
        sys.exit()

print ("YES")


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

typedef long long ll;

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

int main(){
  int n,l;
  cin >> n >> l;
  string s[n];
  rep(i,n) cin >> s[i];

  sort(s,s+n);
  rep(i,n) cout << s[i];
  cout << endl;
  return 0;
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
   #define MAXN   1000005 
  
int spf[MAXN]; 
  

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
       
        spf[i] = i; 
  
   
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        
        if (spf[i] == i) 
        { 
           
            for (int j=i*i; j<MAXN; j+=i) 
  
             
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 

set<int> getFactorization(int x) 
{ 
    set<int> ret; 
    while (x != 1) 
    {  ;
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 





        int vis[1000005]={0};

    int main() {
        fastio;
         sieve(); 
       int n;
       cin>>n;
       int a[n];
       int gd=0;
       for(int i=0;i<n;i++)
       {
        cin>>a[i];
        gd=__gcd(a[i],gd);
       }
       if(gd>1)
        { cout<<"not coprime"<<endl;
        
        }
    
     else
     {
        int f=0;
       for(int i=n-1;i>=0;i--)
       {
              set<int> v = getFactorization(a[i]);

              for(auto j: v)
              {  
                  if(!vis[j])
                    vis[j]=1;
                  else
                  {
                    f=1;
                    break;
                  }
                  
              }
              if(f)
                break;         
       }

       if(f)
       {                                                                                                                                                                                                                                                                
        cout<<"setwise coprime"<<endl;
       }
       else
        cout<<"pairwise coprime"<<endl;


   }



    }

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


int main(){
  string A,B,C;
  int a,b,c;
  a=0;b=0;c=0;
  cin>>A;
  cin>>B;
  cin>>C;
  char ans;

  char turn = A.at(a);
  a++;
  while(1){
    if(turn =='a'){
      ans ='A';
      if(a==A.size())break;
      turn = A.at(a);
      a++;

    }else if(turn =='b'){
      ans ='B';
      if(b==B.size())break;
      turn = B.at(b);
      b++;

    }else if(turn =='c'){
      ans ='C';
      if(c==C.size())break;
      turn = C.at(c);
      c++;
    }
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,x,y,z,p,q;
    ll m,tmp;
    string s[200000];
    //string str;
    ll sum=0;
    ll strr[200005];
        double n;

    cin>>n;
    string str=":(";

    rep(i,50001){
        if(n==floor(i*108/100)){
            cout<<i<<endl;
            return 0;
        }
    }
        rep(i,2){
        printf("%c",str[i]);
        }


    return 0;
}

Measured memory_bytes: 1792
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll MOD = 998244353;
int n, s, a[MAXN];
ll dp[MAXN][MAXN], dp2[MAXN][MAXN];

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b) % MOD;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> s;
    FOR(i,1,n) cin >> a[i];
    dp[0][0] = 1;
    FOR(i,1,n)
        FOR(j,0,s) {
            dp[i][j] = dp[i-1][j];
            if (j >= a[i]) {
                if (j == a[i]) dp[i][j] = add(dp[i][j], i);
                else dp[i][j] = add(dp[i][j], dp[i-1][j-a[i]]);
            }
        }
    ll res = 0;
    FOR(i,1,n) res = add(res, dp[i][s]);
    cout << res;
    return 0;
}


Measured memory_bytes: 72064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long now = sc.nextLong();
        long k = sc.nextLong();
        long d = sc.nextLong();
        
        long ans = 0;
        
        // 10 5 8
        // 2回行くことになる。 now = -6
        // 残り3回はプラスマイナスを往復 2,-6,2 ans = 2;
        long needcount = (Math.abs(now) + d+1) / d;
        // System.out.println(needcount);
        
        if (needcount > k) {
            if (now < 0) {
                ans = now + k * d;
                // System.out.println(ans);
            } else {
                ans = now - k * d;
                // System.out.println(ans);
            }
        } else {
            long leftcount = k - needcount;
            if (now < 0) {
                now = now + needcount * d;
            } else {
                now = now - needcount * d;
            }
            // System.out.println(now);
            
            if (leftcount % 2 == 1) {
                if (now < 0) {
                    now += d;
                } else {
                    now -= d;
                }
            }
            
            ans = now;
            // System.out.println(now);
        }
        // if (Math.abs(now) > Math.abs(k * d))
        System.out.println(Math.abs(ans));
    }
}


Measured memory_bytes: 35708
# 解説放送

def main():
    from itertools import islice, tee

    k, q = map(int, input().split())
    *d, = map(int, input().split())
    for g in tee(d, q):
        n, x, m = map(int, input().split())
        g = map(lambda x: x % m, g)
        g1, g2, g3 = tee(g, 3)
        rep, rest = divmod(n - 1, k)
        last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest))
        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0)
        ans = (n - 1) - eq - (last // m - x // m)
        print(ans)


if __name__ == '__main__':
    main()


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

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

    int64_t ans;
    int64_t x, y;
    int64_t limit = sqrt(n);
    for (int i = 1; i <= limit; i++) {
        if (n % i == 0) {
            x = i;
            y = n / i;
        }
    }

    ans = x + y - 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		if(a<b && b<c)
		System.out.println("Yes");
		else
		System.out.println("No");
		scan.close();
	}
	
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a < 3200) {
        cout << "red";
    } else {
        cout << s ;
    }


    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int i;
char s[4];
scanf("%s", s);
for(i = 0; i < 3; ++i) {
if(s[i] == s[i+1]) {
printf("Bad\n");
return 0;
}
}
printf("Good\n");
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  int minN = -INF, maxN = INF;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    minN = max(minN, l);
    maxN = min(maxN, r);
  }
  int ans = maxN - minN + 1;
  if (ans < 0) ans = 0;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    string s; cin >> s;
    set<int> st;
    rep(i,3) st.insert(s[i]);
    if ((int)st.size() == 3) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<set>
#include<vector>
#define B 100000007
#define A 1000000007
using namespace std;

typedef unsigned long long ull;

int h,w,p;
ull im[1100][1100],pt[110][100];
string pic;
ull v,val[1100];
set<ull> pattern;

inline int bit(char c){
  if(c=='+')return 62;
  if(c=='/')return 63;
  if('A'<=c && c<='Z')return c-'A';
  if('a'<=c && c<='z')return c-'a'+26;
  return c-'0'+52;
}

ull hash_val(void){
  ull res = 0;
  for(int i=0;i<p;i++){
    ull tmp = 0;
    for(int j=0;j<p;j++)tmp = tmp*B + pt[i][j];
    res = res*A + tmp;
  }
  return res;
}

void rot(void){
  bool res[110][110];
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++)
      res[p-1-j][i] = pt[i][j];
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++)
      pt[i][j] = res[i][j];
}

void mirror_lr(void){
  for(int i=0;i<p;i++){
    for(int j=0;j<p/2;j++)swap(pt[i][j],pt[i][p-1-j]);
  }
}

void mirror_ub(void){
  for(int i=0;i<p/2;i++){
    for(int j=0;j<p;j++)swap(pt[i][j],pt[p-1-i][j]);
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  while(cin >> w >> h >> p,h||w||p){
    for(int i=0;i<h;i++){
      cin >> pic;
      for(int j=0;j<pic.size();j++){
	ull tmp = bit(pic[j]);
	int base = min(6,w-6*j);
	for(int k=0;k<base;k++){
	  im[i][6*j+k] = ( (tmp >> (5-k)) & 1ULL );
	}
      }
    }
    for(int i=0;i<p;i++){
      cin >> pic;
      for(int j=0;j<pic.size();j++){
	ull tmp = bit(pic[j]);
	int base = min(6,p-6*j);
	for(int k=0;k<base;k++){
	  pt[i][6*j+k] = ( (tmp >> (5-k)) & 1ULL );
	}
      }
    }

    pattern.clear();
    for(int i=0;i<4;i++){
      rot();
      pattern.insert(hash_val());

      mirror_ub();
      pattern.insert(hash_val());
      mirror_ub();

      mirror_lr();
      pattern.insert(hash_val());
      mirror_lr();
    }

    ull BASE = 1;
    for(int i=0;i<p;i++)BASE *= A;

    ull ans = 0;
    for(int j=0;j+p<=w;j++){
      ull v = 0;
      for(int y=0;y<h;y++){
	val[y] = 0;
	for(int x=0;x<p;x++)val[y] = val[y]*B + im[y][j+x];
	if(y<p)v = v*A + val[y];
      }

      if(pattern.find(v) != pattern.end())ans++;
      for(int i=0;i+p<h;i++){
	v = v*A - val[i]*BASE + val[i+p];
	if(pattern.find(v) != pattern.end())ans++;
      }
    }
    cout << ans << endl;
  }
}

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

int main(){
    int d,t,s;
    float ans;
    cin>>d>>t>>s;
    ans = float(d)/s;
    if(ans<=t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3556
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer a[] = new Integer[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());

        int alice = 0;
        int bob = 0;
        for(int i=0; i<n; i+=2){
            alice = alice + a[i];
        }
        for(int i=1; i<n; i+=2){
            bob = bob + a[i];
        }
        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 22996
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int field[8][8];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 8; j++) {
            for (int k = 0; k < 8; k++) {
                char c;
                cin >> c;
                field[j][k] = (int)(c - '0');
            }
        }
//        for (int j = 0; j < 8; j++) {
//            for (int k = 0; k < 8; k++) {
//                cout << field[j][k];
//            }
//            cout << endl;
//        }
        int sx, sy;
        cin >> sx;
        cin >> sy;
        field[sy-1][sx-1] = 0;
        cout << "Data " << i+1 << ":" << endl;
        queue<int> X;
        queue<int> Y;
        X.push(sx-1); Y.push(sy-1);
        while (!X.empty()) {
            int x = X.front(); X.pop();
            int y = Y.front(); Y.pop();
            for (int j = 0; j < 4; j++) {
                for (int k = 1; k <= 3; k++) {
                    int nx = x + k * dx[j];
                    int ny = y + k * dy[j];
                    if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
                        if (field[ny][nx] == 1) {
                            X.push(nx); Y.push(ny);
                        }
                        field[ny][nx] = 0;
                    }
                }
            }
        }
        for (int j = 0; j < 8; j++) {
            for (int k = 0; k < 8; k++) {
                cout << field[j][k];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

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

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	long long int h, n,m=0;
	cin >> h >> n;
	
	rep(i, n) {
		int a;
		cin >> a;
		m += a;
	}
	if (m >= h)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int main()
{
    int n;
    while (cin>>n, n) {
        int s=n>1;
        for(auto i=2LL; i*i<=n; ++i) {
            if (n%i==0) {
                s+=i;
                if (i!=n/i) s+=n/i;
            }
        }
        if (n==s)
            cout<<"perfect number"<<endl;
        else if (n>s)
            cout<<"deficient number"<<endl;
        else
            cout<<"abundant number"<<endl;
    }
}

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	int S,h,m,s;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		S = sc.nextInt();
		h = S/3600%60;
		m = S/60%60;
		s = S%60;
		
		System.out.print(h+":"+m+":"+s);
		System.out.println();
	}
		
    public static void main(String args[]){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17328
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,z,w,pok[2001];
    scanf("%d%d%d",&n,&z,&w);
    for(int i=0;i<n;i++)
        scanf("%d",&pok[i]);
    if(n==1)
        printf("%d\n",abs(pok[n-1]-w));
    else
        printf("%d\n",max(abs(pok[n-1]-pok[n-2]),abs(pok[n-1]-w)));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

int s[1005];
int main(){
    int n, k;
    scanf("%d %d",&n,&k);
    FOR(i, 1, n) scanf("%d",&s[i]);
    sort(s+1,s+1+n);
    int sum = 0;
    FOR(i, 1, k) sum += s[i];
    printf("%d",sum);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3828
a='abcdefghijklmnopqrstuvwxyz'
b=[0]*26
while True :
    try:
        moji=(input())
        for i in range (len(moji)) :
            if moji[i].lower() in a :
                b[a.index(moji[i].lower())] += 1
        
            
    except EOFError:
        break


for k in range(26) :
    print(a[k], ":", b[k])


Measured memory_bytes: 5564
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == ',') cout << " ";
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int gcd(int p, int q){
  if(p%q == 0) return q;
  return gcd(q, p%q);
}

int main() {
  int n;
  cin >> n;
  ll a[n+1],b[n+1],tmp;
  ll zero=0,xziku=0,yziku=0;
  map<pair<ll,ll>,pair<ll,ll>> muki;
  for(int i=1;i<=n;i++) cin >> a[i] >> b[i];
  for(int i=1;i<=n;i++){
    if(a[i]==0 && b[i]==0) zero++;
    else if(a[i]==0) yziku++;
    else if(b[i]==0) xziku++;
    else if(a[i]>0 && b[i]>0){
      muki[make_pair(a[i]/gcd(a[i],b[i]),b[i]/gcd(a[i],b[i]))].first++;
    }
    else if(a[i]<0 && b[i]>0){
      tmp=a[i];a[i]=b[i];b[i]=-tmp;
      muki[make_pair(a[i]/gcd(a[i],b[i]),b[i]/gcd(a[i],b[i]))].second++;
    }
    else if(a[i]<0 && b[i]<0){
      a[i]=-a[i];b[i]=-b[i];
      muki[make_pair(a[i]/gcd(a[i],b[i]),b[i]/gcd(a[i],b[i]))].first++;
    }
    else if(a[i]>0 && b[i]<0){
      tmp=a[i];a[i]=-b[i];b[i]=tmp;
      muki[make_pair(a[i]/gcd(a[i],b[i]),b[i]/gcd(a[i],b[i]))].second++;
    }
  }
  vector<ll> pow2(200002,1);
  for(int i=0;i<200001;i++){pow2[i+1]=2*pow2[i]; pow2[i+1]%=MOD;}
  ll multi=1;
  for(auto c : muki){
    multi *= pow2[c.second.first] + pow2[c.second.second] - 1; multi %= MOD;
  }
  if(yziku!=0 || xziku!=0){multi *= pow2[yziku] + pow2[xziku] - 1; multi %= MOD;}
  multi = (multi-1+MOD)%MOD;
  cout << (multi + zero)%MOD << endl;
}


Measured memory_bytes: 23432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int H, W;
  cin >> H >> W;
  string ans = "";
  rep(i, H) rep(j, W)
  {
    string S;
    cin >> S;
    if (S == "snuke")
    {
      string coll = to_string(i + 1);
      char row = j + 'A';
      ans += row;
      ans += coll;
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll n,m,ans;
map<ll,ll>ma;
signed main() {
    cin>>n;
    rep(i,n){
      cin>>m;
        auto itr = ma.find(m);
        if( itr != ma.end() )itr->second++;
        else ma.emplace(m,1);
    }
    for(auto itr = ma.begin(); itr != ma.end(); ++itr) {
        ll x=itr->first,y=itr->second;
        if(x<y)ans+=y-x;
        if(x>y)ans+=y;
    }
   cout<<ans<<endl;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  vector<vector<int>> a(3, vector<int>(3));
  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) cin >> a[i][j];
  }
  int n; cin >> n;
  int b;
  for(int i=0; i<n; i++) {
    cin >> b;
    for(int j=0; j<3; j++) for(int k=0; k<3; k++) {
      if(a[j][k] == b) a[j][k] = -1;
    }
  }

  for(int i=0; i<3; i++) {
    int c = 0;
    int r = 0;
    for(int j=0; j<3; j++) {
      if(a[i][j] == -1) c++;
      if(a[j][i] == -1) r++;
    }
    if(c == 3 || r == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1) {
    cout << "Yes" << endl;
    return 0;
  }
  if (a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}

// EOF



Measured memory_bytes: 256
a = Array.new(4){Array.new(3){Array.new(10,0)}}
b = gets.to_i
b.times do
  c = gets.split.map(&:to_i)
  a[c[0]-1][c[1]-1][c[2]-1] += c[3]
end
4.times do |i|
  3.times do |j|
    print " ", a[i][j].join(" "),"\n"
  end
  if (i < 3) then
    puts "#"*20
  end
end

Measured memory_bytes: 6116
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
const int MAXN=2005;

int N;
char A[MAXN],B[MAXN];
int left[MAXN],right[MAXN];
vector<pair<int,int>> range;
int best[MAXN];

int main()
{
	scanf("%s%s",A+1,B+1);
	N=strlen(A+1);
	
	bool flag=false;
	for(int i=1;i<=N&&!flag;i++)
		if(B[i]=='1')
			flag=true;
	if(!flag)
	{
		flag=true;
		for(int i=1;i<=N&&flag;i++)
			if(A[i]=='1')
				flag=false;
		if(!flag)
			puts("-1");
		else
			puts("0");
		return 0;
	}
	
	for(int i=1;i<=N;i++)
	{
		while(B[(i-left[i]-1+N)%N+1]!='1')
			left[i]++;
		while(B[(i+right[i]-1)%N+1]!='1')
			right[i]++;
	}
	int ans=0x3F3F3F3F;
	for(int i=0;i<N;i++)
	{
		int tmp=0;
		range.clear();
		for(int j=1;j<=N;j++)
			if(A[j]!=B[(j-i-1+N)%N+1])
			{
				tmp++;
				if(A[j]=='1')
					range.emplace_back(left[j],right[j]);
			}
		if(range.size()==0U)
		{
			ans=min(ans,tmp+i);
			continue;
		}
		sort(range.begin(),range.end(),greater<pair<int,int>>());
		best[0]=range[0].second;
		for(int i=1;i<(int)range.size();i++)
			best[i]=max(best[i-1],range[i].second);
		int p=range.size()-1;
		for(int l=i;l<N;l++)
		{
			while(p>=0&&range[p].first<=l)
				p--;
			int r=p==-1?0:best[p];
			ans=min(ans,tmp+r*2+l+(l-i));
		}
	}
	for(int i=0;i<N;i++)
	{
		int tmp=0;
		range.clear();
		for(int j=1;j<=N;j++)
			if(A[j]!=B[(j+i-1)%N+1])
			{
				tmp++;
				if(A[j]=='1')
					range.emplace_back(right[j],left[j]);
			}
		if(range.size()==0U)
		{
			ans=min(ans,tmp+i);
			continue;
		}
		sort(range.begin(),range.end(),greater<pair<int,int>>());
		best[0]=range[0].second;
		for(int i=1;i<(int)range.size();i++)
			best[i]=max(best[i-1],range[i].second);
		int p=range.size()-1;
		for(int r=i;r<N;r++)
		{
			while(p>=0&&range[p].first<=r)
				p--;
			int l=p==-1?0:best[p];
			ans=min(ans,tmp+l*2+r+(r-i));
		}
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int x[100][100];
int main(){
  int n,d;
  cin >> n >> d;
  rep(i,n)rep(j,d)cin >> x[i][j];
  int ans = 0;
  rep(i,n){
    REP(j,i + 1,n){
      int a = 0;
      rep(k,d)a += pow(x[i][k] - x[j][k],2);
      if((int)sqrt(a) * (int)sqrt(a)== a)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
s1 = s[:int((n-1)/2)]
s2 = s[int((n+3)/2-1):]
if s[::-1] == s and s1[::-1] == s1 and s2[::-1] ==  s2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
MOD=10**9+7

N=int(input())
a=[int(input()) for i in range(N)]
last={}
tmp={}

ans=1
x=a[0]
last[x]=0
tmp[x]=1

for i in range(1,N):
    x=a[i]
    last.setdefault(x,i)
    tmp.setdefault(x,0)
    if last[x]!=i-1: ans+=tmp[x]
    last[x]=i
    tmp[x]=ans%MOD
    ans=ans%MOD
    
print(ans)

Measured memory_bytes: 47276
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut n:usize = read!();
    let mut a:usize = 0;
    let mut max:usize = 0;
    for i in 0..n {
        let ai:usize = read!();
        if max<ai {
            max=ai;
        }
        else {
            a+=max-ai;
        }
    }
    println!("{}",a);
}

Measured memory_bytes: 2132
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

std::string s;
int K;

int main()
{
  std::cin >> s >> K;

  rep( i, s.size() )
  {
    int dist = ('z'-s[i])+1;

    if( s[i] != 'a' && dist <= K )
      K -= dist, s[i] = 'a';
  }

  if( K > 0 )
    s[s.size()-1] += K%26;

  std::cout << s << std::endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;
int dp[301];

void solve()
{
	vector<int> square;
	for(int i = 1; i * i <= 300; ++i)
	{
		square.push_back(i * i);	
	}
	dp[0] = 1;
	for(int i = 0;i < square.size() ; ++i)
	{
		for(int ii = square[i]; ii <= 300 ; ++ii)
		{
				dp[ii] += dp[ii-square[i]];
		}
	}

	int n;
	while(cin >> n, n)
	{
		cout << dp[n] << endl;
	}	
}

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

Measured memory_bytes: 1216
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.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
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);
        DRainFlowsIntoDams solver = new DRainFlowsIntoDams();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRainFlowsIntoDams {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long a[] = new long[n];
            long ans[] = new long[n];
            long sum = 0;
            long temp = in.nextLong();
            ArrayList<Long> b = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                a[i] = in.nextLong();
                if (i % 2 == 0) sum += a[i];
                else sum -= a[i];
            }
            a[n - 1] = temp;
            sum += a[n - 1];
            long x = sum / 2;
            temp = 2 * x;
            for (int i = 0; i < n; i++) {
                b.add(2 * x);
                x = (a[i] - x);
            }
            out.print(b.get(n - 1) + " ");
            for (int i = 0; i < b.size() - 1; i++) out.print(b.get(i) + " ");


        }

    }

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

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

    }
}



Measured memory_bytes: 52580
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n, k; cin >> n >> k;
    int ans  =  0;
    REP(i, n) {
        int h; cin >> h;
        if (h >= k) ans++;
    }
    cout << ans <<  endl;

}


Measured memory_bytes: 256
# ABC120B - K-th Common Divisor
def main():
    *AB, K = map(int, input().split())
    A, B = sorted(AB)
    div = [i for i in range(1, A + 1) if A % i == 0 and B % i == 0]
    div.sort(reverse=1)
    ans = div[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
int a[N], b[N];
priority_queue <pair <int,int> > pq;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	for(int i = 1; i <= n; i++)
	{
		cin >> b[i];
		if(b[i] < a[i])
			return cout << -1, 0;
		else if(b[i] > a[i])
			pq.push({b[i], i});
		
	}
	b[0] = b[n], b[n + 1] = b[1];
	int ans = 0;
	while(pq.size() > 0)
	{
		int i = pq.top().se;
		pq.pop();
		if(b[i] < b[i + 1] + b[i - 1])
			return cout << -1, 0;

		int tmp = (b[i + 1] + b[i - 1]);
		int step = (b[i] - a[i])/tmp;
		if(step == 0)
			return cout << -1, 0;
		ans += step;
		b[i] -= step * tmp;
		b[0] = b[n];
		b[n + 1] = b[1];

		if(b[i] > a[i])
			pq.push({b[i], i});
	}
	cout << ans;
}

Measured memory_bytes: 9072
#  --*-coding:utf-8-*--

def main():
    S = input()

    c = 0
    n = 0
    lastChar = None

    while c < len(S):
        if lastChar == None or lastChar != S[c]:
            lastChar = S[c]
            c += 1
            n += 1
        elif c < len(S)-1:
            lastChar = None
            c += 2
            n += 1
        else:
            c += 1

    print(n)



if __name__ == '__main__':
    main()


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}


signed main(){
    int N,M;
    scanf("%lld%lld",&N,&M);
    vint A(N);rep(i,N)scanf("%lld",&A[i]);
    priority_queue<pint>que;
    rep(i,M){
        int b,c;
        scanf("%lld%lld",&b,&c);
        que.emplace(c,b);
    }

    sort(all(A));

    int sum=accumulate(all(A),0ll);
    int ans=sum;
    
    rep(i,N){
        if(que.empty())break;
        auto p=que.top();
        que.pop();
        p.se--;
        sum+=p.fi;
        sum-=A[i];
        chmax(ans,sum);
        if(p.se)que.push(p);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3188
import sys

input = sys.stdin.readline
N = int(input())
As = [list(map(int, input().split())) + [-1] for _ in range(N)]

import collections

que = collections.deque([i for i in range(N)])
counters = [0] * N
days = [0] * N
while que:
    player = que.popleft()
    opponent = As[player][counters[player]] - 1
    if As[opponent][counters[opponent]] - 1 == player:
        days[player] = max(days[player], days[opponent]) + 1
        days[opponent] = days[player]
        counters[player] += 1
        counters[opponent] += 1
        que.append(player)
        que.append(opponent)
for c in counters:
    if c < N - 1:
        print(-1)
        break
else:
    print(max(days))

Measured memory_bytes: 63196