akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = 2 * n;
    for (int i = n - 1; i >= 0; i--) {
        if (s.substr(i, n - i) == t.substr(0, n - i)) {
            int tmp = (s.substr(0, i) + t).size();
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,ans=0;
	int n,a,flg[114514];
	cin>>n;
	for(i=0;i<=114514;i++) flg[i]=0;
	for(i=0;i<n;i++) {
		cin>>a;
		flg[a]++;
	}
	for(i=0;i<114514;i++) {
		if(flg[i]) ans++;
	}
	if(ans%2) cout<<ans<<endl;
	else cout<<ans-1<<endl;
}
	
	

Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String[] s = new String[h];
    int[][] sk = new int[h][w];
    for(int i = 0; i < h; i++) {
      s[i] = sc.next();
    }
    for(int i = 0; i < h; i++) {
      String str = s[i];
      for(int j = 0; j < w; j++) {
        if(str.charAt(j) == '#') sk[i][j] = 1;
      }
    }
    int[][] rightm = new int[h][w];
    int[][] leftm = new int[h][w];
    int[][] abovem = new int[h][w];
    int[][] belowm = new int[h][w];
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(i == 0) {
          if(sk[i][j] == 1) {
            abovem[i][j] = 0;
          } else {
            abovem[i][j] = -1;
          }
        } else {
          if(sk[i][j] == 1) {
            abovem[i][j] = i;
          } else {
            abovem[i][j] = abovem[i - 1][j];
          }
        }
        if(j == 0) {
          if(sk[i][j] == 1) {
            leftm[i][j] = 0;
          } else {
            leftm[i][j] = -1;
          }
        } else {
          if(sk[i][j] == 1) {
            leftm[i][j] = j;
          } else {
            leftm[i][j] = leftm[i][j - 1];
          }
        }
      }
    }

    for(int i = h - 1; i >= 0; i--) {
      for(int j = w - 1; j >= 0; j--) {
        if(i == h - 1) {
          if(sk[i][j] == 1) {
            belowm[i][j] = h - 1;
          } else {
            belowm[i][j] = h;
          }
        } else {
          if(sk[i][j] == 1) {
            belowm[i][j] = i;
          } else {
            belowm[i][j] = belowm[i + 1][j];
          }
        }
        if(j == w - 1) {
          if(sk[i][j] == 1) {
            rightm[i][j] = w - 1;
          } else {
            rightm[i][j] = w;
          }
        } else {
          if(sk[i][j] == 1) {
            rightm[i][j] = j;
          } else {
            rightm[i][j] = rightm[i][j + 1];
          }
        }
      }
    }
    int ans = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(sk[i][j] != 1) {
          int a = rightm[i][j] - leftm[i][j] - 1;
          int b = belowm[i][j] - abovem[i][j] - 1;
          ans = Math.max(ans, a + b - 1);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 161724
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int N;
long long ans = 0;
int main(){
    
    cin >> N;
    
    int a;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ans += a;
    }
    ans -= N;
    cout << ans << endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MAXN = 51;
ll memo[MAXN];

ll powfunc(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll dfs(ll n, ll x) {
	if (n == 0){
		return memo[0] = 1;
	}
	if (memo[n] != 0) {
		return memo[n];
	}

	//A[n-1]の長さを求める
	ll alen = powfunc(2, n+1) - 3;
	if (x > 2 * (alen + 2)){
		return memo[n] = 2 * dfs(n-1, alen) + 1;
	} else if (x > alen + 2) {
		return dfs(n-1, x - (alen + 2)) + 1 + dfs(n-1, alen);
	} else if (x > alen + 1) {
		return 1 + dfs(n-1, alen);
	} else if (x > 1) {
		return dfs(n-1, x-1);
	} else {
		return 0;
	}
}

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

	ll ans = dfs(N, X);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s==t;
}
int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) &&  is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

bool cmp(array<int,3> a,array<int,3> b){
	return a[1] < b[1];
}
int main(){
	int n,l;
	while(cin >> n >> l && n){
		vector< array<int,3> > sim(n);
		for(int i = 0 ; i < n ; i++){
			char c;
			cin >> c;
			int p;
			cin >> p;
			p *= 2;
			sim[i] = array<int,3>{c=='R'?1:-1,p,i+1};
		}
		int tm = 0,last=-1;
		while( sim.size() ){
			for(int i = 0 ; i < sim.size() ; i++){
				for(int j = i+1 ; j < sim.size() ; j++){
					if( sim[i][1] == sim[j][1] && sim[j][1] % 2 == 0){
						swap(sim[i][0],sim[j][0]);
						
					}
				}
			}

			for( auto &x : sim ){
				x[1] += x[0];
			}
			sort(sim.begin(),sim.end(),cmp);
			vector< array<int,3> > newSim;

			for(int i = sim.size() -1 ; i >= 0 ; i--){
				auto x = sim[i];
				if( x[1] != 0 && x[1] != 2*l ){
					newSim.push_back(x);
				}else{
					last = x[2];
				}
				
			}
			sim = newSim;
			tm++;
		}
		cout << tm/2 << " " << last << endl;
	}
}

Measured memory_bytes: 1220
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[] ary = new int[n+1];
    int left = 0;
    int right = 0;

    for(int i = 0; i < m; i++){
      ary[i] = sc.nextInt();
      if(ary[i] < x){left++;}
      else{right++;}
    }

    System.out.println(Math.min(left, right));

  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}int n,a[1000000],d;
signed main(){
	n=read();for (int i=1;i<=n;i++)a[i]=read();d=n;
	for (;d>=1;d-=2)cout<<a[d]<<' ';d+=2;if (d==2)d=1;else d=2;
	for (;d<=n;d+=2)cout<<a[d]<<' ';
}


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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 1000010;

int solve(int k) {
    int n = 0;
    REP(i, MAX_N) {
        n *= 10;
        n += 7;
        n %= k;
        if(n == 0) { return i + 1; }
    }
    return -1;
}
signed main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int K;
    cin >> K;

    int ans = solve(K);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3732
h, w = map(int, input().split())
while h != 0 or w != 0:
    print("#" * w)
    h -= 2
    while h >= 1:
        print("#{}#".format("." * (w - 2)))
        h -= 1
    print("#" * w)
    print("")
    h, w = map(int, input().split())



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
vector<int> a;
signed main() {

    cin >> n;
    a.resize(n);

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

    int p = 1;
    int c = 0;
    for(int i = 0; i < n; i++) {
        if(p == a[i]) {
            p++;
        }
        else
            c++;
    }

    if(p == 1) cout << -1 << endl;
    else cout << c << endl;
  
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,i,l[9],ans;
void dfs(int x,int A,int B,int C,int s){
	if(x>n){
		if(A&&B&&C)ans=min(ans,s+abs(a-A)+abs(b-B)+abs(c-C));
		return;
	}
	dfs(x+1,A,B,C,s);
	dfs(x+1,A+l[x],B,C,s+10*(A>0));
	dfs(x+1,A,B+l[x],C,s+10*(B>0));
	dfs(x+1,A,B,C+l[x],s+10*(C>0));
}
int main(){
	ans=1e9;
	cin>>n>>a>>b>>c;
	for(i=1;i<=n;i++)cin>>l[i];
	dfs(1,0,0,0,0);
	printf("%d",ans);
  return 0;
}


Measured memory_bytes: 256
import math

def is_lunlun(num):
    if num < 10:
        return True
    str_num = str(num)
    length = len(str_num)
    for i in range(length - 1):
        left = int(str_num[i])
        right = int(str_num[i + 1])
        # 頭からi+1 桁目とi+2桁目の差がおかしい
        if abs(left - right) > 1:
            if left > right:
                # 下の桁を上げる
                return i + 2
            # 頭の桁を上げて、そこの頭から
            return [i + 1, left + 1]
            
    return True

k = int(input())

i = 1
counta = 0
lunlun = 0
while(True):
    lunlun = is_lunlun(i)
    if lunlun == True:
        counta += 1
        if counta >= k:
            break
        i += 1
    elif type(lunlun) == int:
        length = len(str(i))
        i += 10 ** (length - lunlun)
        continue
    else:
        length = len(str(i))
        div = 10 ** (length - lunlun[0])
        i = math.floor(i / div / 10) * div * 10 + lunlun[1] * div
print(i)

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;

    vector<ll> A(N);

    REP(i,N){
        cin >>A.at(i);
    }

    ll tmp=A.at(0)^A.at(1);
    if(N>=3){
        for (ll i = 2; i < N; i++)
        {
            tmp=tmp^A.at(i);
        }
    }

    vector<ll> B(N);

    REP(i,N){
        B.at(i) = tmp ^ A.at(i);
    }
    REP(i,N){
        cout << B.at(i) << " ";
    }
    return 0;
}


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

using namespace std;
using ll = long long;

const ll mx = LLONG_MAX;

int n, k;
vector<ll> h, dp;

int main(){
    cin>>n>>k;
    h.resize(n); dp.resize(n, mx);
    for(int i = 0; i < n; i++){
        cin>>h[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i - 1; j >= i - k && j >= 0; j--){
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    }
    ll res = dp[n-1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
n=int(input())
s=input()
i,j=0,len(s)-1
while(i<len(s) and s[i]=='R'):
    i+=1
while(j>=0 and s[j]=='W'):
    j-=1
c=0
while i<j:
    
    if s[i]=='W' and s[j]=='R':
        c+=1
        i+=1
        j-=1
        while i<len(s) and s[i]=='R':
            i+=1
        while(j>=0 and s[j]=='W'):
            j-=1
    
print(c)
        

Measured memory_bytes: 73600
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, k;
int a[110];
int dp[110][N];

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];

	for (int i = 0; i <= n; i++) dp[i][0] = 1;

	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= k; j++) {
		dp[i][j] = dp[i][j - 1];
		dp[i][j] += dp[i - 1][j];
		if (j > a[i]) dp[i][j] -= dp[i - 1][j - a[i] - 1];
		dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
	}

	cout << dp[n][k] << endl;

	return 0;
}

Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    map<int, int> l, r;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(i % 2) r[a]++;
        else l[a]++;
    }
    vector<pair<int, int>> left, right;
    for(auto itr : l){
        auto newitr = make_pair(itr.second, itr.first);
        left.push_back(newitr);
    }
    for(auto itr : r){
        auto newitr = make_pair(itr.second, itr.first);
        right.push_back(newitr);
    }
    sort(left.begin(), left.end(), greater<pair<int, int>>());
    sort(right.begin(), right.end(), greater<pair<int, int>>());
    left.emplace_back(0,0);
    right.emplace_back(0,0);
    if(left[0].second != right[0].second) cout << n - left[0].first - right[0].first << "\n";
    else cout << n - max(left[0].first + right[1].first, left[1].first + right[0].first) << "\n";
    /*for(auto itr : left) cout << itr.first << " " << itr.second << "\n";
    cout << "\n";
    for(auto itr : right) cout << itr.first << " " << itr.second << "\n";*/
    return 0;
}

Measured memory_bytes: 8848
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
using namespace std;

inline int read()
{
    ll s = 0, f = 1;
    char ch = getchar();
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
    for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
    return s * f ;
}

int main()
{
    int n;
    ll num[100];
    num[0] = 2;
    num[1] = 1;
    for(int i = 2 ; i <= 86 ; i++)
    	num[i] = num[i-1] + num[i-2];
	while(cin>>n)
	{
		cout<<num[n]<<endl;
	} 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int a, b;
int count;
int gaet;
int main(void)
{
	scanf("%d %d", &a, &b);
	count = a;
	if(b == 1)
	{
		printf("0");
		return 0;
	}
	for(int i = 1 ; ; i++)
	{
		if(count >= b)
		{
			printf("%d", i);
			return 0;
		}	
		count += a;
		count -= 1;
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>

int main (int argc, char **argv)
{
  int n = 0;
  int q = 0;
  char *s = NULL;
  int *sn = NULL;
  int count = 0;
  int l = 0;
  int r = 0;
  int i = 0;

  scanf("%d %d", &n, &q);

  s = (char *)malloc((n + 1) * sizeof(char));
  scanf("%s", s);

  sn = (int *)malloc(n * sizeof(int));

  sn[0] = 0;
  for(i = 1; i < n; i++)
  {
    if((s[i] == 'C') && (s[i - 1] == 'A'))
    {
      count++;
    }
    sn[i] = count;
  }

  for(i = 0; i < q; i++)
  {
    scanf("%d %d", &l, &r);
    printf("%d\n", sn[r - 1] - sn[l - 1]);
  }

  free(s);
  free(sn);

  return 0;
}



Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main(){
    int n, card[13*4]={0};

    cin >> n;
    for (int i = 0; i < n; i++) {
        char s;
        int r;
        cin >> s >> r;
        switch (s) {
            case 'S': card[13*0 + r-1] = 1; break;
            case 'H': card[13*1 + r-1] = 1; break;
            case 'C': card[13*2 + r-1] = 1; break;
            case 'D': card[13*3 + r-1] = 1; break;
        }
    }

    for (int i = 0; i < 13*4; i++)
        if (card[i] == 0) {
            if (i < 13*1)      cout << "S ";
            else if (i < 13*2) cout << "H ";
            else if (i < 13*3) cout << "C ";
            else               cout << "D ";
            cout << i%13+1 << endl;
        }

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7

int main(){
    int n,k;
    cin >> n >> k;
    vll p(n);
    vll c(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    ll best_score=-1e18;

    //Pは1-Nの順列だから、どの要素も必ずループの中身
    for(int i=0;i<n;i++){
        ll now_score=0;
        int next;
        next=p[i];
        ll loop_score=c[next];
        int loop_count=1;
        while(1){
            loop_count++;
            next=p[next];
            loop_score+=c[next];
            if(next==i) break;
        }
        ll now_max=-1e18;
        ll score=0;
        if(loop_score>0){
            now_score+=loop_score*(k/loop_count);
            int temp=k%loop_count;
            if(temp==0){
                now_score-=loop_score;
                temp=loop_count;
            }
            next=i;
            for(int j=0;j<temp;j++){
                next=p[next];
                score+=c[next];
                now_max=max(now_max,score);
            }
            if(now_max>0||now_score==-1e18){
                now_score+=now_max;
            }
        }else{
            int temp=min(k,loop_count);
            next=i;
            for(int j=0;j<temp;j++){
                next=p[next];
                score+=c[next];
                now_max=max(now_max,score);
            }
            now_score+=now_max;
        }
        best_score=max(best_score,now_score);
    }
    cout << best_score << endl;
    return 0;
}

Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,j,N,sum=0,f=0,ans=0;
  cin>>N;
  vec v(N);
  rep(i,N){cin>>v[i];sum+=v[i];}
  if(sum%N)f=1;
  j=sum/N;
  rep(i,N)ans+=(j-v[i])*(j-v[i]);
  if(f){
    ll res=0;
    j++;
    rep(i,N)res+=(j-v[i])*(j-v[i]);
    chmin(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{	
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int a, b = 0, c = 0;
		bool f = 1;
		for (int j = 0; j < 10; j++) {
			cin >> a;

			if (a > b && ((a > c && b >= c) || a < c))
				b = a;
			else if (a > c && ((a > b && b < c) || a < b))
				c = a;
			else {
				f = 0;
				break;
			}
		}

		if (f)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}



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

int32_t main()
{
	int a, b, c;
	cin>>a>>b>>c;
	if(a==b && b==c)
		cout<<"No"<<endl;
	else if(a==b || a==c || b==c )
		cout<<"Yes"<<endl;
	else
		cout<<"No";


}
	

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  flag = true;

  string s[3];
  for (int i = 0; i < 3; ++i) cin >> s[i];

  int tern = 0;

  while (true) {
    if (s[tern].length() == 0) {
      break;
    }
    int next = s[tern][0] - 'a';
    s[tern] = s[tern].substr(1);
    tern = next;
  }

  if (tern == 0) cout << "A";
  if (tern == 1) cout << "B";
  if (tern == 2) cout << "C";
  cout << endl;
  
  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt(), K = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt();
                System.out.println(N * X + Math.max(0, N - K) * (Y - X));
        }
}

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

using namespace std;

using ll = long long;

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    srand(time(0));

#ifdef HOME
    freopen("/home/acarus/Desktop/io/input.txt", "r", stdin);
//    freopen("/home/acarus/output.txt", "a+", stdout);
#endif

    int n;
    cin >> n;

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

    vector<vector<ll>> dp(2, vector<ll>(n + 1, INT_MAX));
    dp[0][1] = 1;
    dp[1][1] = 1;
    for (int i = 2; i <= n; ++i) {
        if (v[i] >= v[i - 1]) {
            dp[0][i] = dp[0][i - 1];
        }

        if (v[i] <= v[i - 1]) {
            dp[1][i] = dp[1][i - 1];
        }

        dp[0][i] = min(dp[0][i], min(dp[0][i - 1], dp[1][i - 1]) + 1);
        dp[1][i] = min(dp[1][i], min(dp[0][i - 1], dp[1][i - 1]) + 1);
    }
    cout << min(dp[0][n], dp[1][n]) << endl;
    return 0;
}

Measured memory_bytes: 3456
def main():
    n,x  = map(int,input().split())
    a = [int(x) for x in input().split()]
    ans = 0
    for i in range(1,n):
        if a[i]+a[i-1]<=x:
            pass
        else:
            if (a[i]+a[i-1])-x<=a[i]:
                ans += (a[i]+a[i-1])-x
                a[i] -= (a[i]+a[i-1])-x
            else:
                ans += (a[i]+a[i-1])-x 
                a[i] = 0
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 63984
#include<algorithm>
#include<set>
#include<iostream>
using namespace std;
#define MOD 1000000
#define ll long long
set<ll> distFirst;
set<ll> locFirst;
int main()
{
    ll H,W;
    scanf("%lld %lld", &H, &W);
    for(ll i = 0; i < W; i ++)
    {
        distFirst.insert(i);
        locFirst.insert(i * MOD + i);
    }
    for(ll i = 0; i < H; i ++)
    {
        ll l,r;
        scanf("%lld %lld", &l, &r);
        l -= 1;
        r -= 1;
        set<ll>::iterator firstOne = locFirst.lower_bound(l * MOD);
        set<ll>::iterator last = locFirst.end();
        if(distFirst.empty())
        {
            printf("-1\n");
            continue;
        }
        while(firstOne != last && *firstOne < ((r + 1) * MOD))
        {
            if(next(firstOne) != last && *next(firstOne) < ((r + 1) * MOD))
            {
                ll deletableLoc = *firstOne / MOD;
                ll deletablePrevLoc = *firstOne % MOD;
                ll deletableDist = deletableLoc - deletablePrevLoc;
                ++firstOne;
                locFirst.erase(deletableLoc * MOD + deletablePrevLoc);
                distFirst.erase(deletableDist * MOD + deletableLoc);
            }
            else
            {
                ll deletableLoc = *firstOne / MOD;
                ll deletablePrevLoc = *firstOne % MOD;
                ll deletableDist = deletableLoc - deletablePrevLoc;
                locFirst.erase(deletableLoc * MOD + deletablePrevLoc);
                distFirst.erase(deletableDist * MOD + deletableLoc);
                if(r != W - 1)
                {
                    locFirst.insert((r + 1) * MOD + deletablePrevLoc);
                    distFirst.insert((r + 1 - deletablePrevLoc) * MOD + r + 1);
                }
                break;
            }
        }
        // for (std::set<ll>::iterator it=locFirst.begin(); it!=locFirst.end(); ++it)
        //   std::cout << ' ' << *it;
        // std::cout << '\n';
        // for (std::set<ll>::iterator it=distFirst.begin(); it!=distFirst.end(); ++it)
        //   std::cout << ' ' << *it;
        // std::cout << '\n';
        if(distFirst.empty())
        {
            printf("-1\n");
        }
        else
        {
            ll ans = (*distFirst.begin()) / MOD;
            printf("%lld\n",ans + i + 1);
        }
    }
}

Measured memory_bytes: 22484
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    print . minimum . tail . init $ zipWith (\x y -> abs (x - y)) (scanl (+) 0 as) (scanr (+) 0 as)

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int a, b;
    cin >> a >> b;
    int ret = max({a + a - 1, a + b, b + b - 1});
    cout << ret << endl;
}


Measured memory_bytes: 256
w = input()

mode = 1
c_s = 0
ans = 0

for i in w:
#    print(i)
    if i == 'S':
        c_s += 1
    else:
        if c_s > 0:
            ans += 1
            mode = 1
            c_s -= 1

print(len(w)-(2*ans))


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
    int n;
    cin >> n;
    int prev = -1;
    ll ans = 0;
    forn(i, n) {
        int a;
        cin >> a;
        if (a > prev + 1) {
            puts("-1");
            return 0;
        }
        if (i > 0 && a == prev + 1) {
            ans++;
        } else {
            ans += a;
        }
        prev = a;
        debug(ans);
    }
    
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	int i, j, N, M, K, ans = 0;



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

	ll t = 0;
	for (i = 0; i < M; i++){
		cin >> b[i];
		t += b[i];
	}

	j = M;

	for (i = 0; i < N + 1; i++){
		while (j > 0 && t > K)
		{
			--j;
			t -= b[j];
		}

		if (t > K)break;
		ans = max(ans, i + j);
		if (i == N)break;
		t += a[i];
	}



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

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,m;
  cin>>n>>m;
  string s;
  cin>>s;
  vector<vecint> g(n);
  vecint ca(n, 0);
  vecint cb(n, 0);
  for(auto&& i:irange(0,m)) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
    if (s[a] == 'A') {
      ++ca[b];
    } else {
      ++cb[b];
    }
    if (s[b] == 'A') {
      ++ca[a];
    } else {
      ++cb[a];
    }
  }
  queue<int> q;
  vector<bool> vis(n, false);
  for(auto&& i:irange(0,n)) {
    if (ca[i] == 0 || cb[i] == 0) {
      q.push(i);
      vis[i] = true;
    }
  }
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for(auto&& to:g[i]) {
      if (s[i] == 'A') {
        --ca[to];
        if (ca[to] == 0 && !vis[to]) {
          q.push(to);
          vis[to] = true;
        }
      } else {
        --cb[to];
        if (cb[to] == 0 && !vis[to]) {
          q.push(to);
          vis[to] = true;
        }
      }
    }
  }
  bool ok = false;
  for(auto&& i:irange(0,n)) {
    if (!vis[i]) ok = true;
  }
  if(ok) {
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 12164
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N; string s[200010],t;

int main(){
    cin >> N;

    int i,j,cnt_b=0,cnt_s=0;
    for (i=1; i<=N; i++) cin >> s[i];
    cin >> t;

    string aux;
    for (i=1; i<=N; i++){
        bool sml=0,big=0;
        aux=s[i];
        for (j=0; j<aux.length(); j++)
            if (aux[j]=='?') aux[j]='a';

        if (aux<=t) sml=1;

        aux=s[i];
        for (j=0; j<aux.length(); j++)
            if (aux[j]=='?') aux[j]='z';

        if (aux>=t) big=1;
        if (sml && !big) cnt_s++;
        else if (big && !sml) cnt_b++;
    }

    for (i=cnt_s+1; i<=N+1-cnt_b; i++){
        if (i==cnt_s+1) cout << i;
        else cout << " " << i;
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define INF 1e9
#define fs first
#define sc second
typedef unsigned long long ull;
typedef long long ll;


int main(){
	ll n,p;
	cin >> n;
	
	rep(i,0,n){
		cin >> p;
		if(p % 2){
			cout << "first" << endl;
			return 0;
		}
	}
	
	cout << "second" << endl;
	
	return 0;
}


Measured memory_bytes: 256
//omajinai c++ atcoder
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<cmath>
#include<iomanip>
#include<type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
#define yes() printf("Yes\n")
#define no() printf("No\n")
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;

int main() {
    long int a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;


    if(abs(a-b)<=(v-w)*t){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (X).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  bool flag=false;
  reps (i, 10) {
    reps(j, 10) {
      if (i*j == N) {
        flag = true;
        break;
      }
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
  
signed main() {
  vector<bool> A(100100,true);
  for(int i=2;i<=100010;i++){
    int up=sqrt(i)+1;
    for(int j=2;j<up;j++){
      if(i%j==0){
         A[i]=false;
        break;
      }
    }
  }

  vector<int> B(50050);
  for(int i=3;i<=100010;i+=2){
    B[i/2]=B[(i-2)/2];
    if(A[i]&&A[(i+1)/2]){
      B[i/2]++;
    }
  }
  int q;
    scanf("%d",&q);
  for(int i=0;i<q;i++){
    int l,r;
      scanf("%d%d",&l,&r);
    if(l==1){
      l+=2;
    }
    printf("%d\n",B[r/2]-B[(l-2)/2]);
  }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<bool> change(3, false);

void typea(ll k, ll x, ll y, ll n) {
  vector<pair<ll, ll>> ans;
  pair<ll, ll> res = {0, 0};
  while (res.second - k >= -((k * n - x - y) / 2)) {
    res.second -= k;
    ans.push_back(res);
  }
  ll r = k - (res.second + (k * n - x - y) / 2);
  res = {r, -(k * n - x - y) / 2};
  ans.push_back(res);
  while (res.first + k <= x) {
    res.first += k;
    ans.push_back(res);
  }
  r = k - (x - res.first);
  res = {x, r - (k * n - x - y) / 2};
  ans.push_back(res);
  while (res.second < y) {
    res.second += k;
    ans.push_back(res);
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) {
    if (change[2]) swap(ans[i].first, ans[i].second);
    if (change[0]) ans[i].first *= -1;
    if (change[1]) ans[i].second *= -1;
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

void typeb(ll k, ll x, ll y) {
  vector<pair<ll, ll>> ans;
  pair<ll, ll> res = {0, 0};
  res = {x, -(k - x)};
  ans.push_back(res);
  res = {x + (k + x - y) / 2, (k - x + y) / 2 - (k - x)};
  ans.push_back(res);
  res = {x, y};
  ans.push_back(res);
  cout << 3 << endl;
  rep(i, 3) {
    if (change[2]) swap(ans[i].first, ans[i].second);
    if (change[0]) ans[i].first *= -1;
    if (change[1]) ans[i].second *= -1;
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

int main() {
  ll k, x, y;
  cin >> k >> x >> y;

  if (x < 0) {
    change[0] = true;
    x = -x;
  }
  if (y < 0) {
    change[1] = true;
    y = -y;
  }
  if (x < y) {
    change[2] = true;
    swap(x, y);
  }
  if ((x + y) % 2 == 1 && k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if ((x + y) < k) {
    if ((x + y) % 2 == 1) {
      typeb(k, x, y);
    }
    else {
      typea(k, x, y, 2);
    }
  }
  else {
    ll c = (k - ((x + y) % k)) % k;
    if (c == 0) {
      if ((x + y) / k == 1) {
        if (change[2]) swap(x, y);
        if (change[0]) x = -x;
        if (change[1]) y = -y;
        cout << 1 << endl;
        cout << x << " " << y << endl;
      }
      else typea(k, x, y, (x + y) / k); 
    }
    else if (c % 2 == 0) typea(k, x, y, (x + y) / k + 1);
    else typea(k, x, y, (x + y) / k + 2);
  }




  
  return 0;
}

Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  vint C(n);
  vint S(n);
  vint F(n);
  rep(i,n-1){
    cin >> C[i] >> S[i] >> F[i];
  }
  C[n-1] = 0;
  S[n-1] = 0;
  F[n-1] = 0;
  rep(i,n){
    int ans = 0;
    for(int j = i;j<n;j++){
      if(j != n-1){
        if(ans < S[j]){
          ans = S[j] + C[j];
        }
        else if(ans % F[j] == 0){
          ans += C[j];
        }
        else{
          ans += F[j] - (ans%F[j]) + C[j];
        }
      }
      else{
        cout << ans << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    int n;
    cin >> n;
    string s = "pphbhhphph";
    cout << s[n%10] << "on" << endl;
    return 0;
}

Measured memory_bytes: 3076
#include<cstdio>
using namespace std;
int n;
double a[3005][3005],ans;
int main()
{
	scanf("%d",&n);
	a[0][0]=1.0;
	for(int i=1;i<=n;i++)
	{
		double temp;
		scanf("%lf",&temp);
		a[i][0]=a[i-1][0]*(1-temp);
//		printf("%.10lf ",a[i][0]);
		for(int j=1;j<=n;j++)
		{
			a[i][j]=a[i-1][j-1]*temp+a[i-1][j]*(1-temp);
//			printf("%.10lf ",a[i][j]);
		}
//		printf("\n");
	}
	for(int i=n/2+1;i<=n;i++)
	{
		ans+=a[n][i];
	}
	printf("%.10lf\n",ans);
} 

Measured memory_bytes: 70528
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
string str[10];
P t[10];
int n=-1,a,b,c;
int main(){
  cin>>n;
  while(1){
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str[i]>>a>>b>>c;
      t[i].first=(a*3+c)*-1;
      t[i].second=i;
    }
    sort(t,t+n);
    
    for(int i=0;i<n;i++){
      cout<<str[t[i].second]<<','<<t[i].first*-1<<endl;
    }
    cin>>n;
    if(n==0)break;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

int main()
{
    int ara[6];
    int idx=0;
    for(int i=1;i<=5;i++)
    {
        cin>>ara[i];
        if(ara[i]==0)
            idx=i;
    }
    cout<<idx<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll X; cin >> X;
  ll x = X / 500;
  ll y = X % 500;
  ll z = y / 5;
  cout << x * 1000 + z * 5 << endl;

  return 0;
}



Measured memory_bytes: 256
s = input()
ans = []
def pm(i,h,k):
  if i == 3:
    if k == 7:
      ans.append(s[0]+h[0]+s[1]+h[1]+s[2]+h[2]+s[3]+'='+'7')

      
  else:
    pm(i+1,h + ['+'],k+int(s[i+1]))
    pm(i+1,h + ['-'],k-int(s[i+1]))
pm(0,[],int(s[0]))
print(ans[0])

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

int main() {
  rep(i, 5) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3632
S = input()


flg = True

for i in range(len(S)):
    if flg == True and S[i] == "h":
        flg = False
        continue
    elif flg == False and S[i] == "i":
        flg = True
        continue
    else:
        print("No")
        break
else:
    if flg == False:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll N,K;
    cin >> N >> K;
    vector<pair<ll,ll>> v;
    FOR(i,0,N){
        ll t,d;
        cin >> t >> d;
        t--;
        v.pb(make_pair(t,d));
    }
    sort(ALL(v),greater<pair<ll,ll>>());
    FOR(i,0,N){
        cerr << v[i].first << ' ' << v[i].second << endl;
    }
    bool used[N] = {0};
    vl yay;
    vl yay2;
    ll pre = -1;
    FOR(i,0,N){
        if(pre != v[i].first){
            yay.pb(v[i].second);
            used[i] = 1;
        }
        pre = v[i].first;
    }
    FOR(i,0,N){
        if(!used[i]){
            yay2.pb(v[i].second);
        }
    }
    ll ans = 0;
    sort(ALL(yay),greater<ll>());
    sort(ALL(yay2),greater<ll>());
    DEBUG(yay)
    DEBUG(yay2)
    FOR(i,1,yay.size())yay[i] += yay[i-1];
    FOR(i,1,yay2.size())yay2[i] += yay2[i-1];
    FOR(i,max(K-yay2.size(),1),min(K,yay.size())+1){
        ll answer = yay[i-1] + i*i;
        ll counter = K - i;
        if(counter == 0)chmax(ans,answer);
        else if(counter-1 < yay2.size()){
            answer += yay2[counter-1];
            chmax(ans,answer);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696