akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

const int INF = 1001001001;

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    int A[N][M];
    int ans = INF;

    rep(i, N){
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }

    for(int s = 0; s < (1 << N); ++s){
        int cost = 0;
        vector<int> d(M);
        rep(i, N){
            if(s >> i & 1){
                cost += C[i];
                rep(j, M) d[j] += A[i][j];
            }
        }
        bool ok = true;
        rep(j, M) if(d[j] < X) ok = false;
        if(ok) ans = min(ans, cost);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;


}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    int low=0,high=1,ans=0,cnt=0;
    while(high<n) {
        if(v[low]>=v[high]) {
            cnt++;
            ans=max(ans,cnt);
             low++;
             high++;
        }
        else {
            low=high;
            high++;
            cnt=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
import math
n=int(input())
k=int(input())

def comb(n,k):
    s=1
    for i in range(k):
        s*=n-i
    for i in range(k):
        s//=i+1
    return s

def ans(n,k):

    s=0
    if int(str(n)[0])==0:
        return 0
    if len(str(n))<k:
        return 0
    elif len(str(n))==k:
        s+=(int(str(n)[0])-1) * comb(len(str(n))-1,k-1)*9**(k-1)
        if k-1==0:
            s+= 1
        else:
            s+= ans(int(str(n)[1:]),k-1)
        return s
    else:
        s += (int(str(n)[0]) - 1) * comb(len(str(n)) - 1, k - 1) * 9 ** (k - 1)
        if k-1==0:
            s+= 1
        else:
            s+= ans(int(str(n)[1:]),k-1)
        s+=comb(len(str(n))-1,k)*9**(k)
        return s

print(ans(n,k))

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

using Data = pair<long long, vector<int> >;

int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a, b, c, K;
    cin >> a >> b >> c >> K;
    vector<ll> A(a);
    vector<ll> B(b);
    vector<ll> C(c);
    for (int i = 0; i < a; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    for (int i = 0; i < b; ++i) cin >> B[i];
    sort(B.begin(), B.end(), greater<ll>());

    for (int i = 0; i < c; ++i) cin >> C[i];
    sort(C.begin(), C.end(), greater<ll>());

    priority_queue<Data> que;
    set<Data> se;
    que.push(Data(A[0] + B[0] + C[0], vector<int>({0, 0, 0})));
    for (int k = 0; k < K; ++k) {
        auto top = que.top();que.pop();
        cout << top.first << endl;

        if(top.second[0] + 1 < a){
            long long sum = top.first - A[top.second[0]] + A[top.second[0] + 1];
            auto num = top.second;
            num[0]++;
            auto d = Data(sum, num);
            if (!se.count(d)){
                se.insert(d), que.push(d);
            }
        }

        if(top.second[1] + 1 < b){
            long long sum = top.first - B[top.second[1]] + B[top.second[1] + 1];
            auto num = top.second;
            num[1]++;
            auto d = Data(sum, num);
            if (!se.count(d)){
                se.insert(d), que.push(d);
            }
        }

        if(top.second[2] + 1 < c){
            long long sum = top.first - C[top.second[2]] + C[top.second[2] + 1];
            auto num = top.second;
            num[2]++;
            auto d = Data(sum, num);
            if (!se.count(d)){
                se.insert(d), que.push(d);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}
int f(int n){
    vector<long long> a(2);
    a[0] = 2;
    a[1] = 1;
    int i = 2;
    while(a.size() <= 86){
        a.push_back(a[i-1]+a[i-2]);
        //cout << a[i] << "\n";
        i++;
    }
    cout << a[n];
}
 

int main(){
    int n;
    cin >> n;
    f(n);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define MOD 10e9+7

int main(){
    int A, B, C; cin >> A >> B >> C;
    if(A <= C  && C <= B) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char mat[105][105];
int dp[105][105], flag[105][105], x, y;
int f(int n, int m)
{
	if(n==0 && m==0){
		if(mat[0][0] == '.')return 0;
		else return 1;
	}
	if(n < 0 || m < 0)return 1000000;
	if(flag[n][m])return dp[n][m];
	int a = f(n,m-1);
	int b = f(n-1, m);
	if(n > 0){
		if(mat[n-1][m] == '.' && mat[n][m] == '#')b++;
	}
	if(m>0){
		if(mat[n][m-1] == '.' && mat[n][m] == '#')a++;
	}
	dp[n][m]=min(a,b);
	flag[n][m]=1;
	return dp[n][m];
}
int main()
{
	// if(mat[0][0] == '.'){
	// 	dp[0][0]=0;
	// }
	// else dp[0][0]=1;
	// flag[0][0]=1;
	scanf("%d%d",&x,&y);
	char dm;
	scanf("%c",&dm);
	for(int i = 0; i < x; i++){
		for(int j = 0; j < y; j++){
			scanf("%c",&mat[i][j]);
		}
		scanf("%c",&dm);
	}
	printf("%d\n",f(x-1,y-1));
	// for(int i = 0; i < x; i++){
	// 	for(int j = 0; j < y; j++){
	// 		printf("%d ",dp[i][j]);
	// 	}
	// 	cout << endl;
	// }
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int X,t; cin >> X >> t;
    cout << max(X-t,0) << endl;
    return 0;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int h,w,d;
  
  cin >> h >> w >> d;
  int total = h*w;
  vector<pair<int,int>> pos(total);
  
  int a;
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      cin >> a; a--;
      pos[a] = make_pair(x,y);
    }
  }
  vector<int> dd(total);
  for(int i=0;i<total;i++){
    if(i<d){
      dd[i] = 0; 
      continue;
    }
    dd[i] = dd[i-d] + abs(pos[i].first-pos[i-d].first) + abs(pos[i].second-pos[i-d].second);
  }
  
  int q;
  cin >> q;
  int l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r; l--; r--;
    cout << dd[r]-dd[l] << endl;
  }
  

  return 0;
}



Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	int mx = 0, id = 0;
	for(int i = 1; i <= n; i++){
		int d = i, cnt = 0;
		while(d)
		{
			d/=2;
			cnt++;
		}
		if(mx<cnt){
			mx=cnt;
			id=i;
		}
	}	
	cout<<id;
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

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

int main() {
  int x;
  cin>>x;
  while (1) {
    bool ok = true;
    for (int i = 2; i < x; ++i) {
      if (x%i == 0) {
        ok = false;
        break;
      }
    }
    if (ok) break;
    ++x;
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll K;
    cin >> K;

    ll ans = 0;
    for(ll i = 1; i <= K; i++){
        for(ll j = 1; j <= K; j++){
            for(ll k = 1; k <= K; k++){
                ans += gcd(gcd(i,j), k);
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}
int main(void){
   int N,d[100000];
   int i,k,cou=0,a=0;
   scanf("%d",&N);
   for(i=0;i<N;i++){
      scanf("%d",&d[i]);
   }
   quick_sort(d,0,N-1);
   if(d[N/2]!=d[N/2-1]){
   cou=d[N/2]-d[N/2-1]-1;
   }else{
      cou=0;
   }
   for(i=0;i<N;i++){
      if(d[i]<d[N/2]){
         a++;
      }
   }
   if(a==N/2){
      cou++;
   }
   a=0;
   for(i=0;i<N;i++){
      if(d[i]<d[N/2-1]){
         a++;
      }
   }
   if(a==N/2){
      cou++;
   }
   printf("%d",cou);
   return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long ans[55555];
int main()
{
	int n,x,y; 
	cin>>n>>x>>y;
	x--;
	y--;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			int dist=abs(i-j);
			dist=min(dist,abs(i-x)+1+abs(y-j));
			dist=min(dist,abs(i-y)+1+abs(x-j));
			ans[dist]++;
		}
	for(int i=1;i<=n-1;i++)
		cout<<ans[i]<<'\n';
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	static void main() throws Exception{
		HashMap<String, Integer>map=new HashMap<>();
		map.put("AC", 0);
		map.put("WA", 1);
		map.put("TLE", 2);
		map.put("RE", 3);
		String[]s=new String[] {"AC","WA","TLE","RE"};
		int[]cnt=new int[4];
		int n=sc.nextInt();
		while(n-->0) {
			cnt[map.get(sc.next())]++;
		}
		for(int i=0;i<4;i++) {
			pw.printf("%s x %s\n", s[i], cnt[i]);
		}
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 47232
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    h-=H;
    w-=W;

    cout << h*w << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from collections import Counter
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    s = input()
    c = Counter(s)
    if len(c) == 2 and set(c.values()) == {2}:
        print('Yes')
    else:
        print('No')



# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int main() {
    int N;
    string s; cin >> N >> s;
    if (N%2) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < N/2; i++) {
        if(s[i] != s[i+N/2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] a = new String[N];
		long sum= 0;
		HashMap<String,Long> map = new HashMap<String,Long>();
		for(int i = 0;i<N;i++) {
			a[i]=sc.next();
	        char []chars =a[i].toCharArray();
	        Arrays.sort(chars);
	        String sorted = new String(chars);

			if(map.containsKey(sorted)) {;
				sum+=map.get(sorted);
				map.put(sorted, map.get(sorted)+1);
			}
			else {
				map.put(sorted,1L);
			}
		}
		System.out.print(sum);
		}
}


Measured memory_bytes: 57632
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

ll suma,sumb,ans;
vector <pr> vec;
int vis[maxn],n,a[maxn],b[maxn];

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d %d",&a[i],&b[i]);
		suma += a[i] , sumb += b[i];
		vec.pb(mp(a[i],(int)i)) , vec.pb(mp(b[i],(int)i));
	}
	sort(vec.begin(),vec.end());
	ll ans = min(suma,sumb) , cur = 0;
	rep(i,0,n - 3){
		cur += vec[i].fi;
		vis[vec[i].se]++;
	}
	rep(i,1,n){
		if ( !vis[i] ) ans = min(ans,cur + a[i] + b[i]);
		else if ( vis[i] == 1 ){
		   	if ( vec[n - 2].se != i ) ans = min(ans,cur + vec[n - 2].fi + max(a[i],b[i]));
			else ans = min(ans,cur + vec[n - 1].fi + max(a[i],b[i]));
		}
		else ans = min(ans,cur + vec[n - 2].fi + vec[n - 1].fi);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3056
#include <iostream>
#include <map>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

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

    int no = 0;
    int ne = 0;
    map<int, int> mo, me;
    for(int i=0; i<n; i+=2){
        if(mo.count(v[i]) == 0) mo[v[i]] = 1;
        else mo[v[i]]++;
        no++;
    }
    for(int i=1; i<n; i+=2){
        if(me.count(v[i]) == 0) me[v[i]] = 1;
        else me[v[i]]++;
        ne++;
    }

    int o1 = -1;
    int o2 = -1;
    int mx = 0;
    for(auto it = mo.begin(); it != mo.end(); it++){
        if(it->second > mx){
            mx = it->second;
            o1 = it->first;
        }
    }
    mx = 0;
    for(auto it = mo.begin(); it != mo.end(); it++){
        if(it->first == o1) continue;
        if(it->second > mx){
            mx = it->second;
            o2 = it->first;
        }
    }

    int e1 = -1;
    int e2 = -1;
    mx = 0;
    for(auto it = me.begin(); it != me.end(); it++){
        if(it->second > mx){
            mx = it->second;
            e2 = e1;
            e1 = it->first;
        }
    }
    mx = 0;
    for(auto it = me.begin(); it != me.end(); it++){
        if(it->first == e1) continue;
        if(it->second > mx){
            mx = it->second;
            e2 = it->first;
        }
    }

    int ans = 0;
    if(o1 == e1){
        int t1 = no - mo[o1] + ne - me[e2];
        int t2 = no - mo[o2] + ne - me[e1];
        ans = min(t1, t2);
    }else{
        ans = no - mo[o1] + ne - me[e1];
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  int A, B, K; cin >> A >> B >> K;
  for(int i = min(A, B); i >= 1; --i){
    if(A%i == 0 && B%i == 0){
      --K;
      if(K == 0){
        cout << i << endl;
        return 0;
      }
    }
  }
  assert(false);
}

Measured memory_bytes: 256
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

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

using namespace std;

typedef long long ll;



int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N;
    cin >> N;
    int P[2*112345];
    int Q[2*112345];
    int ans = 0;
    repeat(i,N){
        cin >> P[i];
        Q[P[i]-1]=i;
    }
    int k=1,kmax=1;
    repeat(i, N-1){
        if(Q[i] < Q[i+1]){
            k++;
        }
        else{
            k=1;
        }
        kmax = max(kmax,k);
    }
    ans = N-kmax;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
fn main() {
	proconio::input!{
		n: usize,
		k: usize,
	}

	let mut v: Vec<usize> = vec![0; 100000];
	for _i in 0..n {
		proconio::input!{
			a: usize,
			b: usize,
		}
		v[a-1] += b;
	}
	let mut count = 0;
	for i in 0..v.len() {
		count += v[i];
		if count >= k {
			println!("{}", i+1);
			return;
		}
	}
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k;
  string s;
  cin >> n >> s >> k;

  char sk = s[k - 1];
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != sk) {
      s[i] = '*';
    }
  }

  cout << s << '\n';
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef complex<int> C;

P dp[2000][2000];
int field[2000][2000];
int min_x, max_x, min_y, max_y;

void setupField(int m){
    memset(field, 0, sizeof(field));
    C dir(1, 0), pos(1000, 1000);
    int count = 0, len = 1;
    min_x = max_x = min_y = max_y = 1000;

    for(int i=1;i<=m;i++){
        min_x = min(min_x, pos.real());
        max_x = max(max_x, pos.real());
        min_y = min(min_y, pos.imag());
        max_y = max(max_y, pos.imag());

        field[pos.imag()][pos.real()] = i;
        pos += dir;
        count++;
        if(count%len == 0){
            dir *= C(0, -1);
            if(count == 2*len){
                len++;
                count = 0;
            }
        }
    }
}

int main(){
    vector<bool> is_prime(1000001, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i*i<is_prime.size();i++){
        if(is_prime[i]){
            for(int j=i*i;j<is_prime.size();j+=i){
                is_prime[j] = false;
            }
        }
    }

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

        setupField(m);

        P ans(-1, 0);
        for(int y=max_y;y>=min_y;y--){
            for(int x=min_x;x<=max_x;x++){
                dp[y][x] = P(0, 0);
                if(field[y+1][x] != 0)dp[y][x] = max(dp[y][x], dp[y+1][x]);
                if(field[y+1][x+1] != 0) dp[y][x] = max(dp[y][x], dp[y+1][x+1]);
                if(field[y+1][x-1] != 0) dp[y][x] = max(dp[y][x], dp[y+1][x-1]);
                if(is_prime[field[y][x]]){
                    if(dp[y][x].first == 0) dp[y][x].second = field[y][x];
                    dp[y][x].first++;
                }
                if(field[y][x] == n){
                    ans = dp[y][x];
                    break;
                }
            }
            if(ans.first != -1) break;
        }
        cout << ans.first << " " << ans.second << endl;
    }
    return 0;
}

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

int main(){
	
	//fastio
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m,a,b;
	cin>>n>>m>>a>>b;

	char arr[n][m];

	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			arr[i][j] = '0';
		}
		for(int j=a;j<m;j++){
			arr[i][j] = '1';
		}
	}

	for(int i=b;i<n;i++){
		for(int j=0;j<a;j++){
			arr[i][j] = '1';
		}
		for(int j=a;j<m;j++){
			arr[i][j] = '0';
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) cout<<arr[i][j];
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N), F(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end());
    long long ub = 1e18, lb = -1;
    while(ub - lb > 1){
        long long mid = (ub + lb) / 2;
        long long cnt = 0;
        for(int i = 0; i < N; i++){
            if(mid < A[i] * F[N - 1 - i]) cnt += A[i] - mid / F[N - 1 - i];
        }
        if(cnt > K) lb = mid;
        else ub = mid;
    }
    cout << ub << endl;
}

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

using namespace std;

int main() {
    string s, p;
    getline(cin, s);
    getline(cin, p);
    for (int i = 0; i < s.length(); ++i) {
        for (int j = 0; j < p.length(); ++j) {
            if (s[(i + j) % s.length()] != p[j]) {
                break;
            }
            if (j == p.length() - 1) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3176
#ifdef ONPC
    # define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <unordered_set>
#include <complex>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <cassert>
#include <random>
#include <iomanip>

#ifdef ONPC
    #define deb(a) cerr << "      " << #a << " = " << a << endl;
#else
    #define deb(a)
#endif

#define sz(a) (a).size()

using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnd(time(0));

typedef long long ll;
typedef long double ld;

int c[26];
const ll MOD = 1e9 + 7;
int solve()
{
    int n;
    if (!(cin >> n))
        return 1;
    string s;
    for (int i = 0; i < 26; i++)
        c[i] = 0;
    cin >> s;
    for (int i = 0; i < n; i++)
        c[s[i] - 'a']++;
    ll ans = 1;
    for (int i = 0; i < 26; i++)
        ans = ans * (ll)(c[i] + 1) % MOD;
    ans = (ans + MOD - 1) % MOD;
    cout << ans << endl;
    return 0;
}

int32_t main()
{
    #ifdef ONPC
        freopen("in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1e9;
    //cin >> T;
    while (T--)
    {
        if (solve())
            break;
        #ifdef ONPC
            cout << "\n__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(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)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int a,b;
  cin>>a>>b;
  string ans="Even";
  if((a*b)%2==1)ans="Odd";
  cout(ans);
  return 0;
}

Measured memory_bytes: 126204
n = int(input())
al = list(map(int, input().split()))

buy = 201
ans = 1000
for i in range(n):
    if al[i] < buy:
        buy = al[i]

    elif al[i] > buy:
        ans = ans//buy*al[i] + ans%buy
        buy = al[i]
    # print(al[i], buy, ans)

print(int(ans))

Measured memory_bytes: 9156
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <set>
using std::vector;
using namespace std;

int main(){
  int N,K;
  string S;
  cin >> N >> K;
  cin >>S;
  vector<int> Nums;
  int now = 1;
  int cnt = 0;
  for(int i = 0; i < N; ++i){
    if(S[i] == (char)('0' + now))++cnt;
    else{
      Nums.push_back(cnt);
      cnt = 1;
      now = 1 - now;
    }
  }
  if(cnt != 0)Nums.push_back(cnt);
  if(Nums.size()%2 == 0)Nums.push_back(0);
  //for(int i = 0; i < Nums.size(); ++i)cout << Nums[i] << endl;
  
  int right = 0;
  int add = 2*K + 1;
  int ans = 0;
  int movingLeft = 0;
  int movingRight = 0;
  int tmp = 0;
  for(int left = 0; left < Nums.size(); left+=2){
    //int tmp = 0;
    right = min(left + add, (int)Nums.size());
    //cout << right << endl;
    while(movingLeft < left){
      tmp -= Nums[movingLeft];
      //cout << "Left" << Nums[movingLeft] << endl;
      ++movingLeft;
    }
    while(movingRight < right){
      tmp += Nums[movingRight];
      //cout << "Right" << Nums[movingRight] << endl;
      ++movingRight;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
char s[N];
int main()
{
	int n,q,k;
	scanf("%d%s%d",&n,s+1,&q);
	while(q--)
	{
		scanf("%d",&k);
		long long ans=0,sd=0,sm=0,sdm=0;
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='D')
				sd++;
			if(s[i]=='M')
				sm++,sdm+=sd;
			if(s[i]=='C')
				ans+=sdm;
			if(i<k)
				continue;
			if(s[i-k+1]=='D')
				sd--,sdm-=sm;
			if(s[i-k+1]=='M')
				sm--;
		}
		printf("%lld\n",ans);
	} 
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define psi std::pair<string,int>
#define pli std::pair<ll,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%I64d",&x)
#define prll(x) printf("%I64d ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vli std::vector<std::list<int>>
#define vlpi vector<list<pii>>
#define li std::list<int>
#define Endl printf("\n")
#define ma 1000000
#define mod 786433
#define FOR(i,a) for(int i=0; i<a; i++)

using namespace std;

int main() {

   int n , m ;
   cin >>  n >> m ;
       if (n==m)
            cout << "Yes" << endl  ;
       else
            cout << "No" << endl   ;

}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int H,W,N;
vector<int> A;

int main()
{
	scanf("%d%d%d",&H,&W,&N);
	A.assign(N,0);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	vector< vector<int> > ans(H,vector<int>(W));

	int color = 0;
	FOR(i,0,H){
		if(i % 2 == 0){
			FOR(j,0,W){
				while(color < N && A [color] == 0) color++;
				ans [i] [j] = color + 1;
				A [color]--;
			}
		}
		else{
			for(int j = W - 1;j >= 0;j--){
				while(color < N && A [color] == 0) color++;
				ans [i] [j] = color + 1;
				A [color]--;
			}
		}
	}

	FOR(i,0,H) FOR(j,0,W){
		printf("%d%s",ans [i] [j],j + 1 == W ? "\n" : " ");
	}

	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
using namespace std;
int main(void){
    int a1,a2,a3;
    scanf("%d %d %d",&a1,&a2,&a3);
    
    if(a1+a2+a3>=22) printf("bust\n");
    else printf("win\n");
    return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 INF = inf<i64>;
using P = pair<i64, i64>;
signed main() {
  const i64 M = 1000000007;
  i64 N;
  cin >> N;
  vector<i64> A(N);
  cin >> A;
  vector<i64> col(3, 0);
  i64 ans = 1;
  for (i64 a : A) {
    i64 alt = (col[0] == a ? 1 : 0) + (col[1] == a ? 1 : 0) + (col[2] == a ? 1 : 0);
    ans = (ans * alt) % M;
    if (col[0] == a) {
      col[0] += 1;
    } else if (col[1] == a) {
      col[1] += 1;
    } else if (col[2] == a) {
      col[2] += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    string s;
    cin>>s;
    if(s.length()==1){
        cout<<"YES"<<endl;
        return 0;
    }
    if(s.length()==2){
        if(s[0]==s[1])cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        return 0;
    }
    map<char,int>m;
    for(char x='a';x<='c';x++)m[x]=0;
    for(int i=0;i<s.length();i++)m[s[i]]++;
    int z=0,y=100000,kind=0;
    for(char x='a';x<='c';x++){
        if(m[x]==0)continue;
        z=max(z,m[x]);
        y=min(y,m[x]);
        kind++;
    }
    if(kind<3)cout<<"NO"<<endl;
    else{
        if(z-y>1)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
using System;

class Program
{
	static void Main(string[] args)
	{

		string[] input = Console.ReadLine().Split(' ');
		string s = input[0];
		string t = input[1];

		string[] input2 = Console.ReadLine().Split(' ');
		int a = int.Parse(input2[0]);
		int b = int.Parse(input2[1]);

		string u = Console.ReadLine();

		if(s==u)
		{
			a--;
		}
		else
		{
			b--;
		}
				Console.WriteLine(a+ " " + b);

		
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vec<ll> c(500,0),s(500,0),f(500,0);
    rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
    rep(i,n){
        ll t=0;
        for(ll j=i;j<n-1;j++){
            if(t<s[j]) t=s[j];
            else if(t%f[j]==0);
            else t=t+f[j]-t%f[j];
            t+=c[j];
        }
        cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{n:usize,k:usize,l:[i64;n]};
    let mut l = l;
    l.sort();
    l.reverse();
    println!("{}", &l[..k].iter().sum::<i64>());

}


Measured memory_bytes: 4352
N = int(input())
B = list(map(int,input().split()))
A = [0 for i in range(N)]

A[0] = B[0]
A[N-1] = B[N-2]

for j in range(1,N-1):
  A[j] = min(B[j],B[j-1])
  
print(sum(A))


Measured memory_bytes: 9052
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int count = 0;
        
        if(s.charAt(0) == '1')count++;
        if(s.charAt(1) == '1')count++;
        if(s.charAt(2) == '1')count++;
		
        System.out.println(count);
	 }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz size()
#define FORN(i,j,n) for(int i=j; i<(int)n;i++) 
#define FOR(i,n) FORN(i,0,n)
#define FORIT(i,x) for( auto i = x.begin() ; i != x.end() ; i++ )
#define MOD 998244353LL
#define LIM 262150
#define ones(x) __builtin_popcount(x)
#define trace(x)    cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
using namespace std;
 
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef vector <string> vs;
typedef vector <ii> vii;
ll h,w;
ll block[1005][1005];
ll dp[1005][1005];
int main() {
	fastio;
	cin>> h >> w;
	FORN(i,1,h+1){
		string cad; cin>> cad;
		FORN(j,1,w+1){
			char a;
			a = cad[j-1];
			if(a == '.') block[i][j] = 0;
			else block[i][j] = 1;
		}
	}
	FORN(i,1,h+1){
		FORN(j,1,w+1){
			dp[i][j] = 0;
		}
	}
	FORN(i,1,h+1){
		FORN(j,1,w+1){
			if(i == 1 && j == 1){ dp[i][j] = 1; continue; }
			if(block[i][j] == 1) continue;
			if(i >= 2){
				if(block[i-1][j] == 0) dp[i][j] += dp[i-1][j];
			}
			if(j >= 2){
				if(block[i][j-1] == 0) dp[i][j] += dp[i][j-1];
			}
			dp[i][j] = dp[i][j]%1000000007;
		}
	}
	cout<< dp[h][w]%1000000007 << '\n';
	return 0;
}

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

int solve(int *a,int size1,int n,int b);
int main(int argc, char** argv) {
    int size1, size2;
    scanf("%d",&size1);
    int array1[size1];
    for(int i=0;i<size1;i++)
    {
        scanf("%d",&array1[i]);
    }
    scanf("%d",&size2);
    int array2[size2];
    for(int i=0;i<size2;i++)
    {
        scanf("%d",&array2[i]);
    }
    for(int i=0;i<size2;i++)
    {
        if(solve(array1,size1,0,array2[i]))
            printf("yes\n");
        else
            printf("no\n");
    }

    
    return (EXIT_SUCCESS);
}

int solve(int *a,int size1,int n,int b)
{
    int diff = b-a[n];
    
    if(n<size1-1)
    {
        if(diff > 0 && solve(a,size1,n+1,diff))
            return 1;
        else if(diff==0||solve(a,size1,n+1,b))
            return 1;
        else 
            return 0;
    }
    else if(b>0 && diff == 0)
        return 1;
    return 0;
}


Measured memory_bytes: 2108