akhauriyash/Code-Regression huggingface dataset:
// compile in C++11. use -std=c++11.
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

// these require C++11
#include <unordered_set>
#include <unordered_map>
#include <random>

using namespace std;

#define int long long

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif


struct Ant{
    int number;
    bool to_left;
    int position;
    Ant(int _number,bool _to_left,int _position)
        : number(_number),to_left(_to_left),position(_position){}
};

// time,who
pair<int,int> solve(int l,vector<Ant> ants){
    l *= 2;
    for(Ant& a : ants){
        a.position *= 2;
    }
    // left_out = 0
    // right_out = 2*l
    int time = 0;
    for(const Ant& a : ants){
        if(a.to_left){
            time = max(time,a.position/2);
        }else{
            time = max(time,(l-a.position)/2);
        }
    }
    for(int t=0;t<time*2;t++){
        for(Ant& a : ants){
            if(a.to_left){
                a.position--;
            }else{
                a.position++;
            }
        }
        for(int i=0;i<ants.size();i++){
            for(int j=i+1;j<ants.size();j++){
                if(ants[i].position == ants[j].position and ants[i].position % 2 == 0){
                    ants[i].to_left = not ants[i].to_left;
                    ants[j].to_left = not ants[j].to_left;
                }
            }
        }
    }
    int number = -1;
    for(const Ant& a : ants){
        if(a.position == 0){
            number = a.number;
        }
        if(a.position == l and number == -1){
            number = a.number;
        }
    }
    return make_pair(time,number);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        int n,l;
        cin >> n >> l;
        if(n == 0 and l == 0) return 0;
        vector<Ant> ants;
        for(int i=0;i<n;i++){
            char d;
            int p;
            cin >> d >> p;
            ants.push_back(Ant(i+1,d=='L',p));
        }
        pair<int,int> p = solve(l,ants);
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll len = s.length();
    ll ans = 0;
    rep(i, 0, len)
    {
        if (s[i] != '0' + i % 2)
            ans++;
    }
    ll tmp = 0;
    rep(i, 0, len)
    {
        if (s[i] != '0' + (i + 1) % 2)
            tmp++;
    }
    ans = min(ans, tmp);
    cout << ans << endl;
}


Measured memory_bytes: 512
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;

void main()
{
    auto nab = readln.split.to!(int[]);
    auto a = nab[1];
    auto b = nab[2];
    auto xs = readln.split.to!(long[]);

    long ret, pos = xs[0];
    foreach (x; xs[1..$]) {
        auto d = (x - pos) * a;
        if (d > b) {
            ret += b;
            pos = x;
        } else {
            ret += d;
            pos = x;
        }
    }
    writeln(ret);
}

Measured memory_bytes: 4404
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

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

    s[5] = s[13] = ' ';

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3632
n = gets.to_i
x = gets.chomp.split.map(&:to_i)
sx = x.sort
lub = sx[n / 2 - 1]
rlb = sx[n / 2]
x.each do |xi|
  if xi <= lub
    puts rlb
  elsif xi >= rlb
    puts lub
  end
end


Measured memory_bytes: 25316
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,y;
  cin>>x>>y;
  if(x%y==0) cout<<-1<<'\n';
  else{
    int sum=0;
    while(true){
      sum+=x;
      if(sum%y!=0) break;
    }
    cout<<sum<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
using namespace std;
main(){
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,k;
    cin>>n>>k;
    long long arr[n];
    for(long long i=0;i<n;i++){
    	cin>>arr[i];
	}
	vector<long long> mn,mx;
	mn.push_back(0);
	mx.push_back(0);
	for(long long i=0;i<n;i++){
		if(arr[i] < 0){
			mn.push_back(abs(arr[i]));
		}
		else if(arr[i] > 0){
			mx.push_back(arr[i]);
		}
		else{
			k--;
		}
	}
	sort(mn.begin(),mn.end());
	sort(mx.begin(),mx.end());
	/*
	long long mini[mn.size()+1];
	long long maxi[mx.size()+1];
	mini[0] = 0;
	maxi[0] = 0;
	for(long long i=0;i<mn.size();i++){
		mini[i+1] = mini[i] + mn[i];
	}
	for(long long i=0;i<mx.size();i++){
		maxi[i+1] = maxi[i] + mx[i];
	}
	*/
	long long ans = 100000000000000;
	for(long long i=0;i<=k;i++){
		long long p = 0;
		long long flag = 0;
		if( i < mn.size() && k-i < mx.size()){
			p += mn[i];
			p += mx[k-i];
			p += min(mn[i],mx[k-i]);
	//		cout<<p<<endl;
			flag = 1;
		}
		if(flag)
		ans = min(ans,p);
	}
	cout<<ans;
	
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 110000

ll dp1[MAXN];
ll dp2[MAXN];
ll ans[MAXN];
ll n, m;
vector<vector<int>>edges(MAXN);

void dfs1(int now=1, int p=-1){
  dp1[now]=1;
  for(auto c: edges[now]){
    if(c==p)continue;
    dfs1(c, now);
    dp1[now]*=dp1[c];
    dp1[now]%=m;
  }
  dp1[now]++;
}

void dfs2(int now=1, int p=-1){
  if(p==-1)dp2[now]=1;

  int ec = edges[now].size();

  vector<ll>lprod(ec, 1);
  rep(i, ec){
    int c = edges[now][i];
    if(i)lprod[i] *= lprod[i-1];
    if(c==p)continue;
    lprod[i]*=dp1[c];
    lprod[i]%=m;
  }

  vector<ll>rprod(ec, 1);
  rrep(i, ec){
    int c = edges[now][i];
    if(i<ec-1)rprod[i] *= rprod[i+1];
    if(c==p)continue;
    rprod[i] *= dp1[c];
    rprod[i] %= m;
  }

  rep(i, ec){
    int c = edges[now][i];
    if(c==p)continue;
    dp2[c] = dp2[now];
    if(i)dp2[c] = dp2[c] * lprod[i-1] % m;
    if(i<ec-1)dp2[c] = dp2[c] * rprod[i+1] % m;
    dp2[c]++;
    dfs2(c, now);
  }
}

void dfs3(int now=1, int p=-1){
  ans[now] = dp2[now];
  for(auto c: edges[now]){
    if(c==p)continue;
    ans[now] *= dp1[c];
    ans[now] %= m;
    dfs3(c, now);
  }
}

int main(){
  cin>>n>>m;
  rep(i, n-1){
    int x,y;cin>>x>>y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  dfs1();
  dfs2();
  dfs3();

  rep1(i, n)cout<<ans[i]%m<<endl;

  return 0;

  rep1(i, n)cout<<dp1[i]<<' ';cout<<endl;
  rep1(i, n)cout<<dp2[i]<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 22452
#include <stdio.h>
int main(void){
int m, f, r,p,a;
    for (a=1 ;a<50;a++) {
    scanf("%d %d %d", &m, &f, &r);
    p=m+f;
    if(m == -1 && f == -1 && r == -1) break;
     else if(m==-1)
            printf("F\n");  
            else if(f==-1)
            printf("F\n");
        else if (80 <= p)
            printf("A\n");
        else if(65 <= p && p < 80)
            printf("B\n");
        else if(50 <= p && p < 65)
            printf("C\n");
        else if(30 <= p && p < 50&&r>=50)
            printf("C\n");
        else if(30 <= p && p < 50)
            printf("D\n");
        else if(p < 30)
            printf("F\n");  
                    
}
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
int prime(int n);
int main(void){



  int X;
  
  scanf("%d\n",&X);
  
  while(1){
  	if(prime(X)==1){
      	printf("%d\n",X);
    	break;
    }else{X++;}
  }
 
  return 0;
}

int prime(int n){
  
  if(n==2||n==3){return 1;}

  if(n%2==0){return 0;}

  if(n%3==0){return 0;}
  
  for(int i=2;i*i<=n;i++){
  
    if(n%i==0){return 0;}
  
  }

	
  return 1;
  
  
}



Measured memory_bytes: 256
Sa = input()
Sb = input()
Sc = input()

Sa = [c for c in Sa]
Sb = [c for c in Sb]
Sc = [c for c in Sc]

tmp = Sa.pop(0)

for _ in range(len(Sa)+len(Sb)+len(Sc)+1):
    if tmp == 'a':
        if len(Sa)==0:
            print('A')
            exit()
        else:
            tmp = Sa.pop(0)
    elif tmp == 'b':
        if len(Sb)==0:
            print('B')
            exit()
        else:
            tmp = Sb.pop(0)
    else:
        if len(Sc)==0:
            print('C')
            exit()
        else:
            tmp = Sc.pop(0)

Measured memory_bytes: 3064
n,m=map(int,input().split())
al=set([int(input()) for i in range(m)])
mod=1000000007
ansl=[0,1]
for i in range(1,n+1):
    if i in al:
        ansl.append(0)
    else:
        ansl.append((ansl[-2]+ansl[-1])%mod)
print(ansl[-1]%mod)

Measured memory_bytes: 13216
//Name: Stylish
//Level: 
//Category:
//Note:

/**
 */
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Line {
    int r, c, s;
    int indent;
    Line() : r(0), c(0), s(0), indent(0) {}
};

vector<Line> read_program(int N) {
    vector<Line> lines(N);
    for(int i = 0; i < N; ++i) {
        string str;
        getline(cin, str);
        bool top = true;
        for(char c : str) {
            if(top && c == '.') ++lines[i].indent;
            if(c != '.') top = false;
            if(c == '(') ++lines[i].r;
            else if(c == ')') --lines[i].r;
            else if(c == '{') ++lines[i].c;
            else if(c == '}') --lines[i].c;
            else if(c == '[') ++lines[i].s;
            else if(c == ']') --lines[i].s;
        }
    }
    return lines;
}

vector<int> do_indent(int r, int c, int s, const vector<Line> &lines) {
    static vector<int> res;
    res.clear();
    Line cur;
    res.push_back(0);
    for(const Line &l : lines) {
        cur.r += l.r;
        cur.c += l.c;
        cur.s += l.s;
        if((cur.r > 0 && r == -1)
            || (cur.c > 0 && c == -1)
            || (cur.s > 0 && s == -1))
        {
            res.push_back(-1);
        } else {
            res.push_back(cur.r*r + cur.c*c + cur.s*s);
        }
    }
    res.pop_back();
    return res;
}

bool solve() {
    int P, Q;
    cin >> P >> Q;
    if(!P && !Q) return false;
    cin.ignore();
    vector<Line> original = read_program(P);
    vector<Line> to_indent = read_program(Q);
    vector<int> ans;
    for(int r = 1; r <= 20; ++r) {
        for(int c = 1; c <= 20; ++c) {
            for(int s = 1; s <= 20; ++s) {
                vector<int> indents = do_indent(r, c, s, original);
                bool ok = true;
                for(int i = 0; i < P; ++i) {
                    if(original[i].indent != indents[i]) {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    vector<int> indents = do_indent(r, c, s, to_indent);
                    if(ans.size() == 0) {
                        ans = indents;
                    } else {
                        for(int i = 0; i < Q; ++i) {
                            if(indents[i] != ans[i]) {
                                ans[i] = -1;
                            }
                        }
                    }
                }
            }
        }
    }
    for(int i = 0; i < Q; ++i) {
        if(i > 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3fll
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define pi acos(-1.0)
#define lowbit(x) x &(-x)
const ll maxn = 1e5 + 10;
const ll mod = 1e9;

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	string f, b;
	int q;
	bool right = 1;
	cin >> q;
	_rep(i, 1, q){
		int op;
		cin >> op;
		if(op == 1){
			right = !right;
		}else {
			int o;
			cin >> o;
			if(!right) o = 3-o;
			char c;
			cin >> c;
			if(o == 1){
				f = c + f;
			}else b = b + c;
		}
	}
	s = f + s + b;
	if(!right){
		reverse(all(s));
	}
	cout << s << endl;
}


Measured memory_bytes: 1404
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double pardonDist = sc.nextDouble();
        int[][] coordinate = new int[n][2];
        for(int i=0; i<n; i++) for(int j=0; j<2; j++) coordinate[i][j] = sc.nextInt();
        int count = 0;
        double dist = 0;
        for(int i=0; i<n; i++) {
            dist = Math.sqrt(Math.pow(coordinate[i][0], 2) + Math.pow(coordinate[i][1], 2));
            if(dist <= pardonDist) count++;
        }

        System.out.println(count);
    }
}




Measured memory_bytes: 65412
# include <bits/stdc++.h>
# define rep(i,n) for (int i = 0; i < (n); ++i)
# define FI first
# define SE second
using namespace std;
using P = pair<string, int>;

int main() {
  int n; cin >> n;
  vector<P> towns(n);
  map<int, int> mp;
  rep (i, n) {
    string s; int p; cin >> s; cin >> p;
    towns[i].FI = s;
    towns[i].SE = p;
    mp[p] = i + 1;
  }
  
  sort(towns.begin(), towns.end(), [](P a, P b) {
    if(a.FI != b.FI){
        return a.FI < b.FI;
    } else {
        return a.SE > b.SE;
    }
  });
  
  rep (i, n) {
  	cout << mp[towns[i].SE] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3572
N,M = map(int,input().split())
L,R = [],[]
for i in range(M):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
l = max(L)
r = min(R)
if l > r:
  print(0)
else:
  print(r - l + 1)

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

using namespace std;

int BubbleSort(vector<int>& A) {
  int counter = 0;
  for (int i = 0; i < A.size(); ++i) {
    for (int j = A.size() - 1; j >= i + 1; --j) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j - 1]);
        ++counter;
      }
    }
  }
  return counter;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (auto& a : A)
    cin >> a;
  int counter = BubbleSort(A);

  for (int i = 0; i < A.size(); ++i) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << counter << endl;
}

Measured memory_bytes: 3088
#include<iostream>
#include<cstdlib>
#include<string>

using namespace std;
struct queue{
  string name;
  int time;
  int j=0;
};
int main(){
  int n,i,q,t=0,cnt,tmp;
  bool fin=true;
  
  cin>>n>>q;
  struct queue a[n];
  for(int i=0;i<n;i++){    
    cin>>a[i].name>>a[i].time;
  }  
  
  while(1){
    fin=true;
    for(i=0;i<n;i++){
      if(a[i].j==0){
	if(a[i].time-q<=0 && a[i].time!=0){
	  cout<<a[i].name<<" "<<t+a[i].time<<"\n";
	  t=t+a[i].time;
	  a[i].j=1;
	  a[i].time=0;
	}
	if(a[i].time>0 && a[i].time!=0){
	  a[i].time-=q;
	  t+=q;
	  cnt++;
	  tmp=i;
	}
	if(a[i].time!=0){
	  fin=false;
	}
	
      }
    }
    if(fin==true){
      break;
    }
    if(cnt==1){
      break;
    }
    cnt=0;
    
  }
  if(cnt==1){
    i=tmp;
    while(1){
      fin=true;
      if(a[i].j==0){
	if(a[i].time-q<=0 && a[i].time!=0){
	  cout<<a[i].name<<" "<<t+a[i].time<<"\n";
	    t=t+a[i].time;
	    a[i].j=1;
	    a[i].time=0;
	}
	if(a[i].time>0 && a[i].time!=0){
	  a[i].time-=q;
	  t+=q;
	  cnt++;
	  tmp=i;
	}
	if(a[i].time!=0){
	  fin=false;
	}
	
      }
      
      if(fin==true){
	break;
      }
    }
  }
  return 0;
}



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

#define F first
#define S second
#define psb push_back
#define mkp make_pair
#define All(x) x.begin(),x.end()
#define nxp next_permutation

typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;

int main(){
  int n=100001;
  vector<int> v(n,0);
  for(int i=2;i<=n;i++){
  v[i]=1;
  }
  for(int i=2;i<=n;i++){
    if(v[i]){for(int j=i*2;j<=n;j+=i)v[j]=0;}
  }
vector<int> a(n,0);
  for(int i=2;i<=n;i++){
  a[i]=i;
  if(v[i]&&v[(a[i]+1)/2])a[i]=1;
    else a[i]=0;
  }
  vector<int> s(n+2,0);
  s[0]=0;
  for(int i=0;i<=n;i++)s[i+1]=s[i]+a[i];
  int q;
  cin>>q;
  rep(i,q){
  int l,r;
    cin>>l>>r;
    cout<<s[r+1]-s[l]<<endl;
  }

  return 0;
}

Measured memory_bytes: 4560
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

X, Y, Z = MII_split()
print('{} {} {}'.format(Z, X, Y))

Measured memory_bytes: 3064
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let (r, g, b, n) = scan!(usize, usize, usize, usize);
    let mut ans = 0;
    for i in 0..3001 {
        for j in 0..3001 {
            if n >= (r * i + g * j) && (n - (r * i + g * j)) % b == 0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

ll froot(ll a){
    for(int i = -4000; i <= 4000;i++){
        ll il = (ll)i;
        il = il * il * il * il * il;
        if(a==il) return (ll)i;
    }
    return -100;
}

int main(){
    set<ll> s;
    for(int i = -4000; i <= 4000;i++){
        ll il = (ll)i;
        il = il * il * il * il * il;
        s.insert(il);
    }
    long long int xx; cin >> xx;
    for(auto x: s){
        ll a5 = x + xx;
        if(s.count(a5)!=0){
            cout << froot(a5) << " " << froot(x) << endl;
            return 0;
        }
    }
    assert(0);
    return 0;
}

Measured memory_bytes: 3976
#include<iostream>

int cnt[100005];
const long long mod = 998244353;
int max_val = 0;
long long ans = 1;

long long mpow(int a, int b) {
	if (!a) return 0LL;
	if (!b) return 1LL;
	return b%2 ? (long long)a * mpow(a, b-1) % mod : mpow((long long)a*a%mod, b/2);
}

int main(void) {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int d;
		std::cin >> d;
		if (d > max_val) max_val = d;
		if (!i && d || i && !d) {
			std::cout << 0 << '\n';
			return 0;
		}
		cnt[d]++;
	}

	for (int i = 2; i <= max_val; i++) {
		ans = (ans * mpow(cnt[i-1], cnt[i])) % mod;
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3976
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  list($s) = explode(" ", trim(fgets(STDIN)));

  if($n <= 2){
    echo $n-1;
    exit;
  }

  $ans = 0;

  if($s[0]=='R' && $s[1]=='R'){
    $ans++;
  }
  if($s[$n-1] == 'L' && $s[$n-2] == 'L'){
    $ans++;
  }

  for ($i=1; $i<$n-1; $i++) {  
    if(($s[$i] == 'R' && $s[$i+1] == 'R') ||
       ($s[$i] == 'L' && $s[$i-1] == 'L')){
      $ans++;
    }
  }

  $fukou = $n - 1 - $ans;

  $kou = $fukou / 2;

  if($k >= $kou){
    echo $n-1;
    exit;
  }else{
    echo $ans + $k * 2;
    exit;
  }

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main()
{
     ios;
     int n;
     cin >> n;
     for (int i = 1; i <= 9; ++i)
          for (int j = i; j <= 9; ++j)
               if (i * j == n)
               {
                    cout << "Yes\n";
                    return 0;
               }
     cout << "No\n";
     return 0;
}

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

int main(void)
{
    long long n, a, b; cin >> n >> a >> b;
    long long t = n / (a + b);
    long long s = n % (a + b);
    long long ans = a * t + min(s, a);
    cout << ans << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    string S,T; cin >> S >> T;
    int N = S.size();
    int ans = 0;
    REP(i,N){
        if(S[i] != T[i]) ans++;
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する
ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

int main() {
    int n;
    cin >> n;
    ll ans = 1LL;
    REP(i,0,n){
        ll in;
        cin >> in;
        ans = lcm(ans,in);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	string s;cin>>s;
  	int count=0;
  
    //1文字目はA
  	if(s.at(0)!='A'){cout<<"WA"<<endl; return 0;}
   	
  	//2文字目とラストは小文字
  	if(s.at(1)<'a' || s.at(1)>'z'){cout<<"WA"<<endl; return 0;}
  	if(s.at(s.size()-1)<'a' || s.at(s.size()-1)>'z'){cout<<"WA"<<endl; return 0;}
    
    //3文字目と末尾2文字目の間に’C'が1個ある。
    for(int i=2;i<=s.size()-2;i++){
    	if(s.at(i)=='C'){
              count++;
        }else if(s.at(1)<'a' || s.at(1)>'z'){cout<<"WA"<<endl; return 0;}
    }
  	if(count!=1){cout<<"WA"<<endl; return 0;}
  
  	cout<<"AC"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 
const double PI=3.14159265358979323846;
 
int main(void){
    char x;
    cin>>x;
    int m = x-'a';
    if((m>=0)&&(m<26))cout<<"a"<<endl;
    else cout<<"A"<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
int G[250001][22];
bool used[22][250001];

bool C(int v){
	for(int i=0;i<20;i++){
		memset(used[i+1],false,sizeof(used[i+1]));
		if((v>>i) & 1){
			for(int j=0;j<w*h;j++){
				if(used[i][j]){
					if(used[i+1][G[j][i]])return true;
					used[i+1][G[j][i]]=true;
				}
			}
		}else{
			for(int j=0;j<w*h;j++){
				used[i+1][j]=used[i][j];
			}
		}
	}
	return false;
}


int main(void){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int r,c;
			scanf("%d%d",&r,&c);
			G[i*w+j][0]=r*w+c;
		}
	}
	for(int i=0;i<n;i++){
		int r,c;
		scanf("%d%d",&r,&c);
		used[0][r*w+c]=true;
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<h*w;j++){
			G[j][i]=G[G[j][i-1]][i-1];
		}
	}
	int l=0,r=h*w+1;
	while(r-l>1){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r==h*w+1?-1:r);
	return 0;
}

Measured memory_bytes: 29828
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		
		int d = a - b;
		
		while(d >= c) {
			d = d - c;
		}
		
		System.out.println(d);
	}
}

Measured memory_bytes: 23764
//解説あり

#include <iostream>
#include <queue>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

ll ans, N, M;
priority_queue<int> A;

int main(void) {
    scanf("%lld %lld", &N, &M);

    REP(i, 0, N) {
    	int a;
    	scanf("%d", &a);
    	A.push(a);
    }

    REP(i, 0, M) {
    	int tmp = A.top(); A.pop();
    	A.push(tmp/2);
    }

    while (!A.empty()) {
    	ans += (ll)A.top();
    	A.pop();
    }
    
    printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 892
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long h, w, n;
    readlnTo(h, w, n);

    int[long][long] c;
    foreach(i; iota(n)) {
        long a, b;
        readlnTo(a, b);
        --a;
        --b;
        foreach(da; [-1, 0, 1]) {
            foreach(db; [-1, 0, 1]) {
                auto aa = a + da;
                auto bb = b + db;
                if(aa < 1 || bb < 1 || aa >= h-1 || bb >= w-1) {
                    continue;
                }
                ++c[aa][bb];
            }
        }
    }
    auto ans = new long[](10);
    foreach(ka, ca; c) {
        foreach(kb, n; ca) {
            ++ans[n];
            --ans[0];
        }
    }
    ans[0] += (h-2) * (w-2);
    ans.each!writeln();
}


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

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  
  if(s.size()>k){
    s.erase(k);
    s.insert(k,"...");
  }
  
  cout<<s<<endl;
  return 0;
  
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	int ans;
	switch(N){
	case 1:ans = 1;	break;
	case 2:ans = 2;break;
	case 3:ans = 4;break;
	case 4:ans = 6;break;
	case 5:ans = 16;break;
	case 6:ans = 12;break;
	case 7:ans = 64;break;
	case 8:ans = 24;break;
	case 9:ans = 36;break;
	case 10:ans = 48;break;
	case 11:ans = 1024;break;
	case 12:ans = 60;break;
	}

	printf("%d\n",ans);

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<ll, ll>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  ll x; cin >> x;
  for(int a = 0; 100*a <= x; ++a) {
    for(int b = 0; 101*b+100*a<= x; ++b) {
      for(int c = 0; 102*c +101*b+100*a <= x; ++c) {
        for(int d = 0; 103*d+102*c+101*b+100*a <= x; ++ d) {
          for(int e = 0; 104*e+103*d+102*c+101*b+100*a <= x; ++e) {
            for(int f = 0; 105*f+104*e+103*d+102*c+101*b+100*a <= x; ++f) {
              if(105*f+104*e+103*d+102*c+101*b+100*a == x ){
                cout << 1 << endl;
                return 0;
              }
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if a[i] >= b[i]: ans += b[i]
    else:
        prev = b[i] - a[i]
        ans += a[i]
        
        if a[i+1] >= prev:
            a[i+1] -= prev
            ans += prev
        else:
            ans += a[i+1]
            a[i+1] = 0
print(ans)

Measured memory_bytes: 18476
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>

using namespace std;
int main() {
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[2] == s[3] && s[0]!=s[2]) ||
		(s[0] == s[3] && s[1] == s[2]&& s[0]!=s[2]) ||
		(s[1] == s[3] && s[0] == s[2]&& s[0]!=s[1]))
		cout << "Yes";
	else cout << "No";
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    while(true){
      String tmp = str.replace("1B", "").replace("0B", "");
      if(tmp.equals(str)){
        break;
      }
      str = tmp;
    }
    System.out.println(str.replace("B", ""));
  }
}

Measured memory_bytes: 21332
#import sys
#input = sys.stdin.readline
Q = 10**9+7
def cmb(n,r):
    if n-r < r: r = n-r
    if r == 0: return 1
    denominator = 1                       #分母
    numerator = 1                         #分子
    for i in range(r):
        numerator *= n-i
        numerator %= Q
        denominator *= i+1
        denominator %= Q
    return numerator*pow(denominator, Q-2, Q)%Q
 
def main():
    S = int( input())
    ans = 0
    for i in range(1, S//3+1):
        t = S - i*3
        ans += cmb(t+i-1,i-1)
        ans %= Q
    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i=0; i<n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<int> dp(3);
    dp[0] = a[0], dp[1] = b[0], dp[2] = c[0];
    for(int i=1; i<n; i++) {
        vector<int> ndp(3);
        ndp[0] = a[i] + max(dp[1], dp[2]);
        ndp[1] = b[i] + max(dp[0], dp[2]);
        ndp[2] = c[i] + max(dp[0], dp[1]);
        dp = ndp;
    }
    cout << max(dp[0], max(dp[1], dp[2]));
    return 0;
}

Measured memory_bytes: 4292
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<pair<long long,long long>,long long>
#define f first
#define s second
#define pd pair<double,long long>
ll M=1e9+7;
ll fexpo(ll a,ll b) {
	ll res=1;
	while (b) {
		if (b&1)
			res*=a,res%=M;
		a*=a;
		a%=M;
		b>>=1;
	}
	return res;
}
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	while (t--) {
		cin>>n;
		if (n<2)
			cout<<0<<'\n';
		else {
			ll op = fexpo(10,n);
			ll op1 = fexpo(9,n);
			op1*=2;
			op1%=M;
			ll op2 = fexpo(8,n);
			op-=op1;
			op+=op2;
			op%=M;
			op+=M;
			op%=M;
			cout<<op<<'\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <algorithm>
int n;
long long a[100000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
		a[i] *= 100000;
		a[i] += i;
	}
	std::sort(a, a + n);
	for (int i = 0; i < n - 1; i++) {
		printf("%lld ", a[i] % 100000 + 1);
	}
	printf("%lld\n", a[n - 1] % 100000 + 1);
}

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

int main(){
  int N;
  cin >> N;
  bool ans = false;
  int d1, d2, cnt = 0;
  for (int i = 0; i < N; i++){
    cin >> d1 >> d2;
    if(d1 == d2){
      cnt++;
    }
    else cnt = 0;
    if(cnt >= 3) ans = true;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
n=gets.to_i
a=gets.split.map(&:to_i)
m=1000
k=0
f="f"
d=a[0]
n.times do |i|
  if f=="f"
    if a[i]>d
      k+=m/d
      m%=d
      f="u"
    elsif a[i]<d
      d=a[i]
    end
  elsif f=="u"
    if a[i]<a[i-1]
      m+=k*a[i-1]
      k=0
      f="d"
    end
  elsif f=="d"
    if a[i]>a[i-1]
      k+=m/a[i-1]
      m%=a[i-1]
      f="u"
    end
  end
end
m+=k*a[-1]
puts m


Measured memory_bytes: 14296
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

bool isPrime(int x) {
    if (x == 2)
        return true;

    for (int i = 2; i <=sqrt(x); i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;

}

int main() {

   // freopen("../files/in.txt", "r", stdin);
    int n, sum = 0, t;
    cin >> n;
    while (n > 0) {

        cin >> t;

        if(isPrime(t)){
            //cout<<t<<" "<<endl;
            sum++;
        }
        n--;

    }
    cout << sum << endl;

    return 0;
}

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

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ans = 0;
  if(n <= k) ans = n * x;
  else ans = k*x + (n-k)*y;
  cout << ans << endl;
}

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

int main() {
    int n,a,b, min;
    cin >> n >> a >> b;
    min = 0;
    for(int i = 0; i < n; i++) {
      min = min + a;
    }
    if(min > b) {
      cout << b << endl;
    } else {
      cout << min << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MOD 1000000007
#define MAX 100005

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit(void) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
};

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

int int_sort( const void * a , const void * b ) {
  return *(long *)a - *(long *)b;
};


int main(void){
    int long long ans=0,cmb;
    int n,k,i;
    int long a[MAX];
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++){
        scanf("%ld",&a[i]);
    };
    qsort(&a[1],n,sizeof(long),int_sort);
    /*for(i=1;i<=n;i++){
        printf("%d ",a[i]);
    };*/
    //putchar('\n');
    COMinit();
    for(i=k;i<=n;i++){
        cmb=COM(i-1,k-1);
        ans+=(a[i]*cmb)% MOD;
        ans%=MOD;
        //printf("a[%d]=%d, a[%d]=%d, f=%d, cmb=%lld, ans=%lld\n",i,a[i],j,a[j],f,cmb,ans);
    };
    for(i=1;i<=n-k+1;i++){
        cmb=COM(n-i,k-1);
        ans-=(a[i]*cmb)% MOD;
        ans%=MOD;
    };
    if(ans<0)ans+=MOD;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3312
n, k = gets.split.map(&:to_i)
candles = gets.split.map(&:to_i)
ans = []
(0...n).each do |start|
  goal = start + k - 1
  if goal < n
    tmp = 0
    if candles[start] < 0 && candles[goal] > 0
      ans << candles[start] * -2 + candles[goal]
      ans << candles[start] * -1 + candles[goal] * 2
    elsif candles[goal] < 0
      ans << candles[start] * -1
    elsif candles[start] >= 0
      ans << candles[goal]
    end
  end
end
puts ans.min


Measured memory_bytes: 9356
#include <cstdio>
#include <cstring>

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int K;	// 500円硬貨の枚数
int X;	// 金額


int main () {

	// 個数と長さの読込み
	scanf("%d %d", &K, &X);

	if(500 * K >= X) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 128
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,*ab = map(int, read().split())

    ab_zero = 0
    ratio = []
    for a, b in zip(*[iter(ab)]*2):
        if a == 0 and b == 0:
            ab_zero += 1
        else:
            g = gcd(a, b)
            a //= g
            b //= g
            ratio.append((a, b))
    ab_zero %= MOD
    
    s = Counter(ratio)

    bad = 1
    for k, v in s.items():
        if v == 0:
            continue
        
        a, b = k
        if (-a, -b) in s:
            v += s[(-a, -b)]
            s[(-a, -b)] = 0

        inv = 0
        if (-b, a) in s:
            inv += s[(-b, a)]
            s[(-b, a)] = 0
        if (b, -a) in s:
            inv += s[(b, -a)]
            s[(b, -a)] = 0

        bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
        bad %= MOD
        s[k] = 0

    ans = (bad + ab_zero -1) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 72960
# include <bits/stdc++.h>
# define ll int64_t
# 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

using namespace std;

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<string,ll> a,pair<string,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 factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    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;
}



int main(){
    ll n,c=0;
    string s;
    cin>>n>>s;
    rep(h,1000){
        ll o=0;
        ll p[3]={h/100,(h/10)%10,h%10};
        rep(i,n){
            if(s[i]==('0'+p[o])) o++;
            if(o==3) break;
        }
        if(o==3) c+=1;
    }
    cout<<c<<endl;
    return 0;
}

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

#define ll long long
#define inf pow(10,18);

vector<ll> arr;
vector<vector<ll>> dp;
vector<vector<ll>> cost;

pair<ll,ll> help(int i,int j) {
    if(i>j) return {0,0};
    if(i==j) {
        dp[i][j]=arr[i];
        cost[i][j]=dp[i][j];
        return {cost[i][j],dp[i][j]};
    }
    if(cost[i][j]!=-1) return { cost[i][j],dp[i][j] };

    ll mn=inf;
    for(int x=i;x<j;x++) {
        auto p1= help(i,x), p2= help(x+1,j);
        dp[i][j]= p1.second+ p2.second;
        mn= min( p1.first+ p2.first + dp[i][j], mn );
    }
    cost[i][j]=mn;
    return {cost[i][j],dp[i][j]};
}

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

    arr.resize(n);
    dp.resize(n,vector<ll>(n,-1));
    cost.resize(n,vector<ll>(n,-1));
    for(int i=0;i<n;i++) cin>>arr[i];
    auto x=help(0,n-1);
    cout<<x.first-x.second;
    return 0;
}

Measured memory_bytes: 2816