akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int a[200000], b[200000];
int max(int aa, int bb);
int main() {

	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		cin >> b[i];
	}
	long long int counter = 0;
	long long int counterA = 0, counterB = 0;

	for (i = 0; i < n; i++) {
		counterA = counterA + a[i];
		counterB = counterB + b[i];
		if (b[i] < a[i]) {
			cout << -1;
			//cout << 'a';
			return 0;
		}
	}
	int reducedflag = 0;
	int maxa;
	int k;
	int bbb;
	//cout << 111;
	while (counterB >= counterA) {
		reducedflag = 0;
		for (i = 0; i < n; i++) {
			bbb = b[i] + b[(i + 2) % n];
			if (b[(i + 1) % n] > bbb) {
				if (b[(i + 1) % n] > a[(i + 1) % n]) {
					//maxa = max(a[(i + 1) % n], max(b[i], b[(i + 2) % n]));
					k = b[(i + 1) % n] - a[(i + 1) % n];
					//cout << k;
					//cout << bbb;
					if (k >= bbb) {
						b[(i + 1) % n] = (b[(i + 1) % n] - (k - (k % bbb)));
						counter = counter + (k - (k % bbb)) / bbb;
						counterB = counterB - (k - (k % bbb));
						reducedflag = 1;
						if (counterB == counterA) {
							cout << counter;
							return 0;
						}
					}

				}
			}
		}
		if (reducedflag == 0) {
			cout << -1;
			//cout << 'i';
			return 0;
		}
	}


	//cout << 'u';
	cout << -1;
	return 0;
}
int max(int aa, int bb) {
	if (aa >= bb) {
		return aa;
	}
	else {
		return bb;
	}
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(void){
  string a,b,c;
  cin >> a >> b >> c;
  string ans;
  ans += a[0]-'a'+'A';
  ans += b[0]-'a'+'A';
  ans += c[0]-'a'+'A';
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np
N=int(input())
A=np.array([int(i) for i in input().split()])
B=np.abs(A)
if np.sum(np.where(A<0,1,0)) % 2 == 1 :
    print(np.sum(B)-np.min(B)*2)
else:
    print(np.sum(B))

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 1e5+5;

ll n , k , mod=1e9+7 , fac[N] , inv[N] , ans=1;

vector<int> adj[N];

ll fp(ll b , ll p)
{
    if (!p) return 1;
    ll ans = fp(b , p/2);
    ans = (ans*ans)%mod;
    if (p%2) ans = (ans*b)%mod;
    return ans;
}

void pre()
{
    fac[0]=1 , inv[0]=1;
    for(ll i=1; i<N; i++)
    {
        fac[i] = (i*fac[i-1])%mod;
        inv[i] = fp(fac[i] , mod-2);
    }
}

ll nCr(ll nn , ll r)
{
    if (r > nn) return 0;
    return (((fac[nn] * inv[r])%mod)*inv[nn-r])%mod;
}

void imp()
{
    cout << "0\n";
    exit(0);
}

void dfs(int node , int p)
{
    if (node == 1) ans = (ans*k)%mod;

    ll cnt=0 , rem = k-1;
    for(auto ch : adj[node])
    {
        if (ch != p) cnt++;
    }
    if (cnt == 1)
    {
        if (node != p) rem--;
       // cout << rem << ' ' << cnt << " how\n";
        if (rem <= 0) imp();
        ans = (ans*rem)%mod;
    }
    else if (cnt > 1)
    {
        if (node != p) rem--;
        if (cnt > rem) imp();
        ll tmp = (nCr(rem , cnt)*fac[cnt])%mod;
        ans = (ans*tmp)%mod;
    }

    for(auto ch : adj[node])
    {
        if (ch != p)
        {
            dfs(ch , node);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;

    for(int i=1; i<n; i++)
    {
        int x,y;
        cin >> x >> y;
        adj[x].push_back(y) , adj[y].push_back(x);
    }

    pre();
    dfs(1,1);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 14136
#include<bits/stdc++.h>
using namespace std;
char a[100010];
int root,sum;
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	for (int i=len;i>=1;i--) a[i]=a[i-1];
	if (a[len]=='1'){
		printf("%d\n",-1); return 0;
	}
	for (int i=1;i<=len-1;i++)
	 if (a[i]!=a[len-i]) {
	 	printf("%d\n",-1); return 0;
	 }
	if (a[1]=='0'){
		printf("%d\n",-1); return 0;
	} 
	root=1; sum=2;
    printf("%d %d\n",1,2);
	for (int i=2;i<=(len+1)/2;i++)
	if (a[i]=='1')
	{
		printf("%d %d\n",root,++sum);
		root=sum;
	}
	else{
		printf("%d %d\n",root,++sum);
	}
	for (int i=sum+1;i<=len;i++) printf("%d %d\n",root,i);
}

Measured memory_bytes: 1536
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define X first
#define Y second
#define MP(x,y) make_pair(x,y)
using namespace std;


const int  MAX_V = 2000;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  // cout << "dfs" << endl;
  used[v] = true;
  rep(i,G[v].size()){
    int u = G[v][i], w = match[u];
    if( w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bi(){
  int res = 0;
  memset(match, -1, sizeof(match));
  rep(v, V){
    if(match[v] < 0){
      memset(used, 0, sizeof(used));
      if(dfs(v)){
        res++;
      }
    }
  }
  return res;
}

int b[1000];
int r[1000];

bool is_p(int x){
  if(x <= 1) return false;
  for(int i = 2; i*i <= x; ++i){
    if(x % i == 0){
      return false;
    }
  }
  return true;
}

vector<int> primes[1280000];

int main(void){
  int n,m;

  while(cin >> n>> m, n){
    rep (i, MAX_V) G[i].clear();
    V = 2000;
    rep(i,n)cin >> b[i];
    rep(j,m)cin >> r[j];
    rep(i,n)rep(j,m){
      if(__gcd(b[i], r[j]) != 1){
        // cout << i << " <-> " << j  << endl;
        // cout << i << " <-> " << j + 1000 << endl;
        add_edge(i,j+1000);
      }
    }
    cout << bi() << endl;;

  }

}

Measured memory_bytes: 35032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			//String[] s = str.split(" ",0);
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < str.length();i += 2) {
				sb.append(str.charAt(i));
			}

			System.out.println(new String(sb));

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}

}


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

int main() {
	int n;
    cin >> n;
    map<long, int> m;
    for(int i=0; i<n; i++){
        long tmp;
        cin >> tmp;
        m[tmp]++;
    }
    
    long ans = 0;
    for(auto c: m){
        ans += c.second >= c.first? c.second - c.first: c.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 105


ll A,E,S,R;
ll dp[SIZE][SIZE];
char X[SIZE],Y[SIZE],work_X[SIZE];

void func(){

	scanf("%s",Y);

	scanf("%lld",&A);
	scanf("%lld",&E);
	scanf("%lld",&S);
	scanf("%lld",&R);

	int len_X,len_Y;

	for(len_X = 0; X[len_X] != '\0'; len_X++);
	for(len_Y = 0; Y[len_Y] != '\0'; len_Y++);

	ll ans = HUGE_NUM;

	for(int start = 0; start <= len_X-1; start++){

		for(int i = 0; i < len_X; i++){
			work_X[i] = X[(start+i)%len_X];
		}

		for(int row = 0; row <= len_Y; row++){
			for(int col = 0; col <= len_X; col++){
				dp[row][col] = HUGE_NUM;
			}
		}

		dp[0][0] = 0;

		for(ll col = 1; col <= len_X; col++){
			if(col <= len_X-start){
				dp[0][col] = dp[0][col-1]+E;
			}else{
				dp[0][col] = dp[0][col-1]+E-R;
			}
		}

		for(ll row = 1; row <= len_Y; row++){
			dp[row][0] = A*row;
		}


		ll cost,calc_E;

		for(int row = 1; row <= len_Y; row++){
			for(int col = 1; col <= len_X; col++){
				if(work_X[col-1] == Y[row-1]){
					cost = 0;
				}else{
					cost = S;
				}
				if(col <= len_X-start){

					calc_E = E;

				}else{

					calc_E = E-R;
				}
				dp[row][col] = min(dp[row-1][col-1]+cost,min(dp[row-1][col]+A,dp[row][col-1]+calc_E));
			}
		}

		ans = min(ans,dp[len_Y][len_X]+R*start);
	}

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


int main(){

	while(true){

		scanf("%s",X);
		if(X[0] == '#')break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3272
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;



int main(){

  string s; cin >> s;

  if (s == "Sunny"){ cout << "Cloudy";}
  else if (s == "Cloudy"){ cout << "Rainy";}
  else {cout << "Sunny";}


  return 0;
}


Measured memory_bytes: 764
N,M = map(int, input().split())
Xkari = list(map(int, input().split()))
X = sorted(Xkari)

if N >= M:
  print(0)
else:
  D = []
  for i in range(M - 1):
    D.append(X[i + 1] - X[i])
  D = sorted(D)[::-1]
  D = D[:N-1]
  ans = X[M - 1] - X[0] - sum(D)
  print(ans)

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

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

using namespace std;

int main(void){
    bool ok = true;
    vector<int> a;
    int k;
    a.resize(5);
    rep(i,a.size()) cin >> a[i];
    cin >> k;

    rep(i,a.size()){
        rep(j,a.size()){
            if(abs(a[i]-a[j]) >k){
                ok = false;
            }
        }
    }
    if(ok){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;


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

const double EPS = 1e-10;
const double INF = 100000000;




int main(){
    int n;
    cin>>n;
    rep(i,n){
        double x[4],y[4],ax,ay,bx,by,ans;
        
        rep(j,4){
            cin>>x[j]>>y[j];
        }
        
        ax=x[1]-x[0];
        ay=y[1]-y[0];
        bx=x[3]-x[2];
        by=y[3]-y[2];
        
        ans=ax*by-bx*ay;
        if(fabs(ans)<=EPS)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
    }

    return 0;
}

Measured memory_bytes: 1224
#include <atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;


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

    string ans = "";
    rep(i,K) ans += "ACL";
    cout << ans<< endl;
}

Measured memory_bytes: 3612
read n a b
ans=0
for (( k = 1; k <= n; k++ )); do
    sum=$(( (k / 10000) % 10 + (k / 1000) % 10 + (k / 100) % 10 + (k / 10) % 10 + k % 10 ))
    (( sum >= a && sum <= b )) && (( ans += k ))
done
echo ${ans}


Measured memory_bytes: 376
def Pto1(C):
    d = C.copy()
    for q in range(0,10):
        for i in range(0,10):
            for j in range(0,10):
                d[i][j] = min(d[i][j], d[i][q]+d[q][j])
    return [d[0][1],d[1][1],d[2][1],d[3][1],d[4][1],d[5][1],d[6][1],d[7][1],d[8][1],d[9][1]]

H,W = map(int,input().split(' '))
C = []
for i in range(0,10):
    cline = list(map(int,input().split(' ')))
    C.append(cline)
C1 = Pto1(C)
A = []
for j in range(0,H):
    aline = list(map(int,input().split(' ')))
    A.append(aline)
h=0
w=0
counter=[0]*10
while h<H:
    w=0
    while w<W:
        if A[h][w]>=0:
            counter[A[h][w]] += 1
        w+=1
    h+=1
Cmin = 0
for k in range(0,10):
    Cmin += C1[k]*counter[k]
print(int(Cmin))

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  ll x = accumulate(a.begin(), a.end(), 0ll) / 2;
  for (int i = 1; i < n; i += 2) {
    x -= a[i];
  }
  vector<ll> ans;
  ans.push_back(x * 2);
  for (int i = 0; i < n - 1; i++) {
    x = a[i] - x;
    ans.push_back(x * 2);
  }

  for (auto aa : ans)
    cout << aa << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 5020
#include "bits/stdc++.h"
using namespace std;

int main(){
  int h,m,s,h2,m2,s2,ans;

  for(int i=0;i<3;++i){
    cin >> h >> m >> s >> h2 >> m2 >> s2;

    ans = h2*3600 + m2*60 + s2 - (h*3600 + m*60 + s);

    cout << ans/3600 << " ";
    ans%=3600;
    cout << ans/60 << " ";
    ans%=60;
    cout << ans << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3096
#include <cstdio>
#include <cstdlib>

struct stack{
    int a[101];
    unsigned n;
    stack():a(),n(0){}
    int& top(){return a[n-1];}
    int pop(){return a[--n];}
    void push(int in){a[n++]=in;}
};

int main(){
    stack s;
    char buf[100];

    while(scanf("%s",buf) != EOF){
        int a;
        switch(buf[0]){
            case '+' : a = s.pop(); s.top() += a; break;
            case '-' : a = s.pop(); s.top() -= a; break;
            case '*' : a = s.pop(); s.top() *= a; break;
            default  : s.push(atoi(buf));
        }
    }
    printf("%d\n",s.top());
}

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

typedef long long ll;

using namespace std;

ll f(ll b, ll n) {

	if (n < b) return n;
	else
		return f(b, n / b) + n % b;

}

int main() {

	ll n, s; cin >> n >> s;

	if (s == n) {

		cout << n + 1;
		return 0;

	}

	for (ll b = 2; b * b <= n; b++)
		if (f(b, n) == s) {

			cout << b;
			return 0;

		}

	ll ans = -1;

	for (ll x = 1; x * x < n; x++) {

		ll b = (n - s) / x + 1;

		if (b >= 2 && f(b, n) == s) ans = b;

	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define INF 10000000;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> H(n);
    int ans=1;
    int tmp_max = INF;
    for (int i=0;i<n;i++) cin >> H[i];
    tmp_max= H[0];
    for (int i=1;i<n;i++){
        if (tmp_max<=H[i]){
            ans += 1;
            tmp_max = H[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int data[4],a,b;
  for(int i=0;i<4;i++){
    cin >> data[i];
  }
  cin >> a >> b;
  for(int i=0;i<3;i++){
    if(data[i] < data[i+1]){
      swap(data[i],data[i+1]);
    }
  }
  if(a > b){
    cout << data[0]+data[1]+data[2]+a << endl;
  } else{
    cout << data[0]+data[1]+data[2]+b << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#include<iostream>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cstdio>
using namespace std;

int main(){
    long long int n;
    long long int sum=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        if(i%3 != 0 && i%5 != 0){
            sum += i;
        }

    }
    cout << sum <<endl;
return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <numeric>
#include <cmath>
#include <cctype>
#include <memory>
//#include <unordered_map>

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N,M; cin>>N>>M;  
  ll ans;
  for(ll i=1;i<=sqrt(M);++i){
    if(M%i==0){
      if(i>=N){ ans = M/i; break;}
      if(i<=M/N){ ans = i;}
    }
  }
  cout << ans <<"\n";
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n,_ = strconv.Atoi(NextLine())
  return n
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var n int = NextInt()
  var a []int = NextIntArray()
  if n == 1 {
    fmt.Println(1)
    os.Exit(0)
  }
  var m int = 1
  var inc bool = true
  var set bool = true
  for i:=0;i<n-1;i++ {
    if a[i] == a[i+1] { continue }
    if set {
      inc = a[i] < a[i+1]
      set = false
    }
    if inc == (a[i] < a[i+1]) { continue }
    m++
    set = true
  }
  fmt.Println(m)
}

Measured memory_bytes: 6016
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    ll a, b;
    cin >> a >> b;
    if ((a + b) % 2 != 0) {
        std::cout << "IMPOSSIBLE" << '\n';
    } else {
        std::cout << (a+b)/2 << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def Yes(x):print("Yes")if x==True else print("No")
n=N()
l=L()
if n==0:
    if l[0]==1:
        print(1)
    else:
        print(-1)
    quit()
if l[0]==1:
    if sum(l)==1:
        print(1)
    else:
        print(-1)
    quit()
ans=[0]*(n+1)
v=1
ans[0]=1
for i in range(1,n+1):
    v*=2
    ans[i]=v
    v-=l[i]
    if v<0:
        print(-1)
        quit()
for i in range(n,0,-1):
    ans[i]-=v
    if ans[i]>=ans[i-1]-l[i-1]:
        break
    v=ans[i-1]-l[i-1]-ans[i]
print(sum(ans))

Measured memory_bytes: 706656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];

int main(){
    int a,N,ans=0;
    cin >> N;
    vector<int> A(N+5,0);
    vector<int> B(N+5,0);
    vector<int> C(N+5,0);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N-1; i++) cin >> C[i];

    for(int i = 0; i < N; i++){
        ans += B[A[i]-1];
        if(i > 0){
            if(A[i] == 1+A[i-1]){
                ans += C[A[i-1]-1];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<tuple>

// North, west, south, east
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};

int main(void){
    int h, w;
    std::cin >> h >> w;

    int countAll = h * w;
    int countOriginalBlack = 0;

    std::vector<std::vector<char>> board(h, std::vector<char>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cin >> board[i][j];
            if(board[i][j] == '#') countOriginalBlack++;
        }
    }

    int sx = 0;
    int sy = 0;
    int gx = h - 1;
    int gy = w - 1;

    std::queue<std::pair<int,int>> que;
 
    // //11/08/2019 added: to record the distance from the start 
    std::vector<std::vector<int>> distance(h, std::vector<int>(w));
 
    // //11/08/2019 added: not to  check the position already visited 
    std::vector<std::vector<int>> dualcheck(h, std::vector<int>(w));

    //the distance from the start to the start must be 0
    distance[sx][sy] = 0;
    dualcheck[sx][sy]++;

    //push the Coordinate 
    que.push({sx, sy});

    while(que.size()){
        int y, x;
        std::tie(y,x) = que.front();
 
        //after completing addition to the tie, que.front must be deleted
        que.pop();
        for(int i = 0; i < 4; i++){
 
            //neighborhood of the maze[y][x]
            int ny = y + dy[i];
            int nx = x + dx[i];
 
            //Outside of the maze, or the wall is inappropriate
            if(ny < 0 || ny >= h || nx < 0 || nx >= w || board[ny][nx] == '#'){
                continue;
            }
 
            //11/08/2019 added: not to count the place already visited
            if(dualcheck[ny][nx] != 0) continue;
            
            //the coordinate can be plus 1
            distance[ny][nx] = distance[y][x] + 1;
 
            //11/08/2019 added: not to count the place already visited
            dualcheck[ny][nx]++;
            que.push({ny, nx});
        }
    }

    int minRouteLength = distance[gx][gy];
    int ans = countAll - countOriginalBlack - minRouteLength - 1;

    if(!distance[gx][gy]) ans = -1;

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int vis[100000];

int main(){
	int a,b,c,d,ans = 0;
	cin >> a >> b >> c >> d;
	d--;
	b--;
	for(int i = a;i <= b;i++) vis[i] = 1;
	for(int i = c;i <= d;i++) if(vis[i] == 1) ans++;
	cout << ans;
}

Measured memory_bytes: 256
def main():
    nvertices, nedges = map(int, input().split())
    edges = [[0 for i in range(nvertices)] for j in range(nvertices)]
    for i in range(nedges):
        u, v, c = map(int, input().split())
        edges[u][v] = c

    ans = 0
    while True:
        val = bfs(0, nvertices - 1, edges)
        if val is None:
            break
        f, path = val
        ans += f
        for i in range(1, len(path)):
            u, v = path[i - 1], path[i]
            edges[u][v] -= f
            edges[v][u] += f

    print(ans)


def bfs(s, t, edges):
    visited = [False] * len(edges)
    INF = float('inf')
    que = [(s, INF, [s])]
    while que:
        u, f, path = que.pop()
        visited[u] = True
        if u == t:
            return (f, path)

        for v in range(len(edges)):
            if visited[v]:
                continue
            if edges[u][v] == 0:
                continue
            p = path[:]
            p.append(v)
            que.insert(0, (v, min(f, edges[u][v]), p))

    return None


main()

Measured memory_bytes: 8404
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            String s = reader.readLine();

            s = s.replace(" ", "");

            final int x = Integer.parseInt(s);

            boolean flg = false;
            for (int i = 2; i <= x; i++) {
                int i2 = i * i;
                if (x < i2) break;
                if (x == i2) {
                    flg = true;
                    break;
                }
            }

            System.out.println(flg ? "Yes" : "No");
        }
    }
}


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


int a,b;
int c[60],d[60];
bool graph[60][60];
bool vis[60];

void dfs(int x){
 
  vis[x] =true ;
  for(int i=0;i<a;i++){
    
    if (graph[x][i] == false)continue;
    if(vis[i] == true)continue;
      dfs(i);
    }
  }

int main(void){
  	cin >>a >>b;
  for (int i=0;i<b; i++){
    cin >> c[i] >> d[i];
    c[i]--;
    d[i]--;
    graph[c[i]][d[i]]=graph[d[i]][c[i]]=true;
  }
  int e=0;
  for (int i=0;i<b; i++){
    
    graph[c[i]][d[i]]=graph[d[i]][c[i]]=false;
    
    for(int j=0;j<a;j++)vis[j]=false;
    dfs(0);
    
    bool connect = false;
    for(int j=0;j<a;j++)
      
      if(vis[j] == false ) connect = true;
    if(connect) e++;
    graph[c[i]][d[i]]=graph[d[i]][c[i]]=true;
  }
  
      cout << e << endl;
  return 0;
}


Measured memory_bytes: 256
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,b;
  cin >> n >> b;
  vector<int> v;
  while(n/b)
  {
    int a = n%b;
    n = n/b;
    v.pb(a);
  }
  v.pb(n%b);
  if(n/b)
    v.pb(n/b);
  cout << v.size();
  return 0;
}


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

const ll mod=1E9+7;
const int N=1e5+5;
int n;
ll fact[N];

ll fpow(ll a,ll p){
	ll res=1;
	while(p){
		if(p&1) res=res*a%mod;
		a=a*a%mod;
		p>>=1LL;
	}
	return res;
}

ll nCk(ll N,ll K){
	ll res=fact[N];
	res=res*fpow(fact[K],mod-2LL)%mod;
	res=res*fpow(fact[N-K],mod-2LL)%mod;
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	fact[0]=1;
	for(ll i=1;i<N;++i)
		fact[i]=fact[i-1]*i%mod;
	cin>>n;
	vector<int> a(n+1),cnt(n+5,0);
	int dup;
	for(int& x:a){
		cin>>x;
		cnt[x]++;
		if(cnt[x]==2)
			dup=x;
	}
	int l=0,r=n;
	while(a[l]!=dup) l++;
	while(a[r]!=dup) r--;
	int k=l+n-r;
	cout<<n<<'\n';
	for(int i=2;i<=n+1;++i){
		ll res=0;
		(res+=nCk(n+1,i))%=mod;
		if(i-1<=k) 
			(res=res-nCk(k,i-1)+mod)%=mod;
		cout<<res<<'\n';
	}
}




Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll K;
    cin >> K;
    ll count = 1;
    ll ans = -1;
    ll num = 7;
    for (ll i = 1; i <= 1000000; i++){
        if (num % K == 0){
            ans = count;
            break;
        }
        else{
            num = (num * 10 + 7) % K;
            count++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
signed main(){
	
    int n,a[111111];
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n,greater<>());
    rep(i,n-1){
        for(int j=i+1;j<n-1;j++){
            int ok=j,ng=n,lim=a[i]-a[j];
            while(abs(ok-ng)>1){
                int mid=(ok+ng)/2;
                if(a[mid]>lim)ok=mid;
                else ng=mid;
            }
            ans+=ok-j;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	A, B = map(int, input().split(" "))
	
	if 8 < A or 8 < B:
		print(":(")
		sys.exit()
		
	if A + B > 16:
		print(":(")
		sys.exit()
		
	print("Yay!")
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 13700
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

constexpr int N = 2020;
constexpr int INF = 1e9;
int dp[N][N];

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

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

    x--, y--;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;

            int a = i, b = j;
            if(a > b) swap(a,b);
            dp[i][j] = b - a;
        }
    }

    dp[x][y] = 1;
    dp[y][x] = 1;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            dp[i][j] = min({dp[i][j], dp[i][x] + dp[y][j] + 1, dp[i][y] + dp[x][j] + 1});
        }
    }

    map<int,int> mp;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            mp[dp[i][j]]++;
        }
    }

    for(int i = 1; i < n; i++){
        cout << mp[i] / 2 << endl;
    }

}

Measured memory_bytes: 32256
while True:
    h, w = map(int, input().split())
    if h == 0 or w == 0:
        break
    for i in range(1, h+1):
        if i % 2 == 0:
            for j in range(1, w+1):
                if j % 2 == 0:
                    print("#",end="")
                else:
                    print(".", end="")
            print()
        else:
            for t in range(1, w+1):
                if t % 2 == 0:
                    print(".", end="")
                else:
                    print("#", end="")
            print()
    print()



Measured memory_bytes: 7004
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,i,x,y,ans,top,zhan[200005];
struct nyh{
	int l,r;
}o[200005];
bool cmp(nyh u,nyh v){
	return u.l<v.l||u.l==v.l&&u.r<v.r;
}
set<int> s;
set<int> :: iterator it;
set<pair<int,int> > t;
set<pair<int,int> > :: iterator it2;
int main(){
	//freopen("camp.in","r",stdin);
	//freopen("camp.out","w",stdout);
	n=read();m=read();
	for(i=0;i<=m;i++)
		s.insert(i);
	s.insert(1000000000);
	for(i=1;i<=n;i++){
		o[i].l=read();
		o[i].r=read();
	}
	sort(o+1,o+n+1,cmp);
	for(i=1;i<=n;i++){
		t.insert(make_pair(o[i].r,i));
		it=s.lower_bound(1);
		if((*it)<=o[i].l){
			s.erase(it);
		}
		else{
			it2=t.begin();
			top++;
			zhan[top]=(it2->first);
			t.erase(it2);
		}
	}
	for(i=1;i<=top;i++){
		it=s.lower_bound(zhan[i]);
		if((*it)==1000000000)
			ans++;
		else
			s.erase(it);
	}
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 11904
#include <cstdio>

int dist[9];

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    int a;
    scanf("%d", &a);
    if (a >= 3200) dist[8]++;
    else dist[a / 400]++;
  }
  int c = 0;
  for (int i = 0; i < 8; ++i)
  {
    if (dist[i] > 0) ++c;
  }
  printf("%d %d\n", c ? c : 1, c + dist[8]);
  return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X = il()
    A = il()

    ret = 0
    if A[0] > X:
        ret += A[0] - X
        A[0] = X

    for n in range(N - 1):
        a = A[n] + A[n + 1]
        if a > X:
            A[n + 1] -= a - X
            ret += a - X
    print(ret)


if __name__ == '__main__':
    main()


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

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

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

    // start
    int n, k, res;
    cin >> n >> k;
    res = k;
    rep(i, n - 1) res *= k - 1;
    cout << res << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s[2];
  cin>>s[0];
  cin>>s[1];
    
    if(s[0]==1||s[1]==1)
    {
     if(s[0]==2||s[1]==2)
       cout<<3;
      else 
        cout<<2;
    }
        else
          cout<<1;

}

Measured memory_bytes: 256
#include <stdio.h>

#define M 500002

#define parent(i) (i/2)
#define left(i) (i*2)
#define right(i) (i*2+1)

void maxHeapify(int *,int);
void buildMaxHeap(int *);

int num;

int main(){
  int i;
  int A[M];

  scanf("%d",&num);
  for(i=1;i<=num;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1;i<=num;i++)printf(" %d",A[i]);
  printf("\n");
  
  return 0;
}

void buildMaxHeap(int *A){
  int i;
  for(i=num/2;i>=1;i--) maxHeapify(A,i);
}

void maxHeapify(int *A,int i){
  int l,r,large,temp;

  l=left(i);
  r=right(i);

  if(l<=num && A[l]>A[i]) large=l;
  else large=i;
  if(r<=num && A[r] > A[large]) large=r;
  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    maxHeapify(A,large);
  }
}



Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
	int[][] ta = new int[16][4096];
	int ptr = 0;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
    	//int[] ar = new int[3];
    	//ar[0]=Integer.parseInt(sc.next());
    	//Arrays.parallelSort(ar);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		//long a = Long.parseLong(sc.next());
		//String s = sc.next();
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//ArrayList<Str_4> lists = new ArrayList<Str_4>();
		//lists = new ArrayList;
		PrintWriter out = new PrintWriter(System.out);
		//int[] ra = new int[r];
		//ArrayList<ArrayList<Integer>> lists = new ArrayList<>();

		//out.println(a[5]);
		int ans = a+ b;
		if (ans < a - b)
		{
			ans = a-b;
		}
		if (ans < a *b)
		{
			ans = a*b;
		}
		out.println(ans);
		out.flush();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 23252
n, m = map(int, input().split())
dp = [float("inf") for i in range(2 ** n)]
dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    num = 0
    for j in range(b):
        num += 2 ** (c[j] - 1)
    for k in range(2 ** n):
        dp[k | num] = min(dp[k | num], dp[k] + a)
if dp[2 ** n - 1] == float("inf"):
    print(-1)
else:
    print(dp[2 ** n - 1])

Measured memory_bytes: 75988
#include <bits/stdc++.h>
using namespace std;
const int maxn=2000;
typedef long long ll;
const ll mod=998244353;
ll x[maxn],y[maxn],power[maxn];
/*ll power(ll a,ll b)
{
    ll ret;
    if (b==0) return 1LL;
    ret=pow(a,b/2);
    ret=ret*ret%mod;
    if (b%2) ret=ret*a%mod;
    return ret;
}*/
int main()
{
  //  freopen("text.in","r",stdin);
    ll i,ans,tmp,j,k,n;
    scanf("%lld",&n);
    power[0]=1LL;
    for (i=1;i<=n;i++) {
        power[i]=power[i-1]*2LL%mod;
        scanf("%lld%lld",&x[i],&y[i]);
    }
    ans=((power[n]-n-1)%mod+mod)%mod;
    ans=((ans-(n-1)*n/2)%mod+mod)%mod;
    for (i=1;i<=n;i++) {
        for (j=i+1;j<=n;j++) {
            tmp=0;
            for (k=j+1;k<=n;k++) {
                if ((y[j]-y[i])*(x[k]-x[j])==(y[k]-y[j])*(x[j]-x[i])) tmp++;
                //if ((y[k]-y[i])*(x[j]-x[i])==(x[k]-x[i])*(y[j]-y[i])) tmp++;
            }
            //ans=((ans-/*power(2LL,tmp)*/power[tmp])%mod+mod)%mod;
            ans=((ans-/*power(2LL,tmp)*/power[tmp]+1)%mod+mod)%mod;
        }
    }
    printf("%lld\n",(ans%mod+mod)%mod);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ul = unsigned long;
std::vector<ul> A,A_backup;
ul N =0;
int func(ul i,ul j){
  	if(A_backup[i] == A[j] && i < N && j < N){
    	return A[j+1];
    }
  	return A[j];
}

int main(){
  	ul a;
  	std::cin >> N;
  	for(int i = 0; i < N; i++){
    	std::cin >> a;
      	A.push_back(a);
    }
  	
  	A_backup = A;
  	std::sort(A.begin(),A.end(),std::greater<ul>());
  	for(int i = 0; i<N;i++){
    	std::cout << func(i,0) << std::endl;
    }
}


Measured memory_bytes: 4848
#include<iostream>
#include<algorithm>
#include<deque>
#define rep(i, s, n) for(int i = s; i < (int)(n); i++)
using namespace std;


int N; string S;
int i;
int main() {
	cin >> N >> S;
	int cnt = 0, pre = 0;
	rep(i, 0, N) {
		if (S[i] == '(') cnt++;
		else {
			cnt--;
			if (cnt < 0) pre = max(pre, -cnt);
		}
	}
	rep(i, 0, pre) S = "(" + S;
	N += pre;

	cnt = 0;
	rep(i, 0, N) {
		if (S[i] == '(') cnt++;
		else cnt--;
	}
	rep(i, 0, cnt) S = S + ")";

	cout << S << endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    long long int a,b,r,m,ans=1;
    for(int i=0;i<n;i++){
        cin>>m;
        a = (ans>m)?ans:m;
        b = (ans>m)?m:ans;
        while(b!=0){   //求最大公约数
            r = a%b;
            a = b;
            b = r;
        }
        ans = ans/a*m;  //求最小公倍数  
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
Iroha Loves Strings (ABC Edition)
*/

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int N, L;
    std::cin >> N >> L;
    std::vector<std::string> list;
    for (int i=0; i<N; i++)
    {
        std::string curr;
        std::cin >> curr;
        list.push_back(curr);
    }
    std::sort(list.begin(), list.end());
    std::string res = "";
    for (int i=0; i<N; i++)
    {
        res += list[i];
    }
    std::cout << res << "\n";
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                cnt += 1

print(cnt)

Measured memory_bytes: 9140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int a, b, c, d;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        solve();
    }

    void solve() {
        if (a * b > c * d) {
            System.out.println(a * b);
        } else {
            System.out.println(c * d);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
#include <stdio.h>

int main(void){
  char x;
  int i = 0, a = 0, z = 0, f = 0;
  while((scanf("%c", &x)) == 1){
    if(f == 0 && x == 'A'){
      a = i;
      f = 1;
    }else if(x == 'Z'){
      z = i;
    }
    i++;
  }
  printf("%d\n", z - a + 1);
  
  return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007


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

   int N;
   cin>>N;
   vector<int>h(N);
   for(int i=0;i<N;i++)cin>>h[i];

   vector<ll>dp(N,1<<30);
   dp[0] = 0;
   for(int i=1;i<N;i++){
      if(i==1)dp[i] = min(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
      else dp[i] = min(dp[i],min(dp[i-1]+abs(h[i-1]-h[i]) , dp[i-2]+abs(h[i-2]-h[i])));
   }

   //for(auto it:dp)cout<<it<<endl;
   cout<<dp[N-1]<<endl;
   return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979


int main()
{
    int n;
    cin >> n;
    int i = n;
    while (i % 1000 != 0)
    {
        i++;
    }
    
    cout << i - n << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	char c;
	cin >> c;

	switch (c)
	{
	case 'A':
		printf("T");
		break;
	case 'T':
		printf("A");
		break;
	case 'C':
		printf("G");
		break;
	case 'G':
		printf("C");
		break;		
	default:
		break;
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 int x,y;
 cin >> x >>y;
 if(x<y){
  cout << "a " <<"<"<< " b" <<endl;
 }
 else if(x>y){
  cout << "a " <<">"<< " b" <<endl;
 }
 else if(x==y){
  cout << "a " <<"=="<<" b" <<endl;
 }
}


Measured memory_bytes: 3084
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
 *
 * @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);
        AHarmony solver = new AHarmony();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHarmony {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long ans = a + b;
            if (ans % 2 == 0) {
                out.println(ans / 2);
            } else {
                out.println("IMPOSSIBLE");
            }
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 22868
n,m = map(int,input().split())
l_li = []
r_li = []
for i in range(m):
  li = list(map(int,input().split()))
  l_li.append(li[0])
  r_li.append(li[1])
l_m = max(l_li)
r_m = min(r_li)
if r_m - l_m + 1> 0:
  print( r_m - l_m + 1)
else:
  print("0")

Measured memory_bytes: 11060