akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    ll n, m; cin >> n >> m;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(all(a));
    vector<Pll> x;
    rep(i, m){
        ll b, c;
        cin >> b >> c;
        x.push_back(make_pair(c, b));
    }
    sort(all(x), greater<Pll>());
    vll y;
    ll nums = 0;
    auto itr = x.begin();
    while (nums < n && itr < x.end()){
        ll add = min(n - nums, (*itr).second);
        rep(i, add){
            y.push_back((*itr).first);
        }
        nums += add; 
        advance(itr, 1);
    }
    ll tmp_ans = accumulate(all(a), 0LL);
    ll ans = tmp_ans;
    ll N = min(y.size(), a.size());
    rep(i, N){
        tmp_ans += y[i] - a[i];
        ans = max(ans, tmp_ans);
    }
    cout << ans << endl;

}

Measured memory_bytes: 7428
# D
from collections import deque
from bisect import bisect_left as bl

f=lambda:map(int,input().split())
N,M=f()
D=[[] for _ in [0]*(N+1)]
F=[0]*(N+1)
F[0]=1
for _ in range(M):
    a,b=f()
    D[a].append(b)
    D[b].append(a)

q=deque()
res=0


while bl(F,1):
    index=bl(F,1)-1
    q.append(index)
    tmp=0
    while q:
        k=q.pop()
        if F[k]!=1:
            tmp+=1
            F[k]=1
            for d in list(set(D[k])):
                if F[d]!=1:
                    q.append(d)
            D[k]=0
    res=max(res,tmp)

print(res)

Measured memory_bytes: 113880
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

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

  int H,N; cin >> H >> N;
  vector<int> A(N), B(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
  }

  vector<vector<ll>> dp(N+1, vector<ll>(H+1, 1ll<<60));
  dp[0][0] = 0;

  rep(i, N) {
    for (int j = 0; j <= H; ++j) {
      chmin(dp[i + 1][j], dp[i][j]);
      chmin(dp[i + 1][min(j + A[i], H)], dp[i + 1][j] + B[i]);
    }
  }

  cout << dp[N][H] << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<long long>H(N);
  vector<int>F(N,0);
  int count=0;
  int maxv=0;
  for(int i=0;i<N;i++){
    cin>>H.at(i);
    if(i>0){
      if(H.at(i-1)>=H.at(i))F.at(i-1)=1;
    }
  }
  for(int i=0;i<N;i++){
    count+=F.at(i);
    if(i>0){
      if(i==N-1||(F.at(i-1)==1&&F.at(i)==0)){
        maxv=max(maxv,count);
        count=0;
      }
    }
  }
  cout<<maxv<<endl;
}


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

void dfs(int N, int x,int y, int &counter){
    if(x+y>N) return;
    counter++;
   
        for(int i=0; i<=9; i++){
            dfs(N,10*(x+i), y,counter);
        }


}

void subdfs(int N,int x,int y,int &counter){
    if(x+y>N) return;
    counter++;
    
    for(int i=0; i<=9; i++){
        subdfs(N,10*(x+i),y, counter);
    }

}



int main() {
    int N;
    cin>>N;
    long long sum=0;
    for(int j=10; j<=90; j+=10){
     for(int k=1; k<=9; k++){
        int  acounter=0;
        int bcounter=0;
        dfs(N,j,k,acounter);
        dfs(N,10*k,j/10,bcounter);
        sum+=acounter*bcounter;
     }
    }
    if(N<10){cout<<sum+N<<endl;}
    else{
    for(int j=1; j<=9; j++){
        int ccounter=0;
        subdfs(N,10*j,j,ccounter);
        sum+=(2*ccounter+1);
    }
    cout<<sum<<endl;
    }
}

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

public class Main {
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		String x = "";
		try {
			while ((x = in.readLine()) != null) {
				int nico = Integer.parseInt(x);
				
				boolean[] flag = new boolean[nico + 1];
				for (int i = 0; i < (nico + 1); i++) {
					flag[i] = true;
				}
				
				for (int i = 2; i * i <= nico; i++) {
					for (int j = i * 2; j <= nico; j = j + i) {
						if (flag[j] == false) continue;
						flag[j] = false;
					}
				}
				
				int count = 0;
				for (int i = 2; i < (nico + 1); i++) {
					if (flag[i]) count++;
				}
				System.out.println(count);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 39608
#include<bits/stdc++.h>
using namespace std;
int n;
int dp[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	memset(dp,63,sizeof(dp));
	dp[n]=0;
	for(int i=n;i>0;i--){
		for(int j=6;j<=i;j*=6)
			dp[i-j]=min(dp[i-j],dp[i]+1);
		for(int j=9;j<=i;j*=9)
			dp[i-j]=min(dp[i-j],dp[i]+1);
	}
	int res=1e9;
	for(int i=0;i<=n;i++){
		res=min(res,dp[i]+i);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_4-A
??¶?´?
    n \leq 10,000
    q \leq 500
    0 \leq S???????´? \leq 10^9
    0 \leq T???????´? \leq 10^9
    T ???????´???????????????°??????
=end
class Main
  def initialize()

    #fh = open("/home/muz/Downloads/ALDS1_4_A_in8.txt")
    fh = STDIN
    n = fh.gets.chomp.to_i
    s = fh.gets.chomp.split.map{|x| x.to_i}
    q = fh.gets.chomp.to_i
    t = fh.gets.chomp.split.map{|x| x.to_i}

    abort("number of s not equal to n") if n != s.length
    abort("number of t not equal to q") if q != t.length

    ans = 0
    t.each {|x|
      if s.index(x) then
        ans += 1
      end
    }
    puts ans
  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    int one = 0, zero = 0, ans = 0;
    for(char c: s){
        if(c == '1'){
            one++;
            if(zero > 0){
                ans += 2;
                one--;
                zero--;
            }
        }
        else{
            zero++;
            if(one > 0){
                ans += 2;
                one--;
                zero--;
            }
        }
    }
    cout << ans ;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i=0;
  cin>>n;
  vector< pair< pair<string,int>,int > > v;
  string s;
  int p;
  while(n--)
  {
    i++;
    cin>>s>>p;
    v.push_back({{s,-p},i});
  }
  sort(v.begin(),v.end());
  for(auto q:v) cout<<q.second<<endl;
  return 0;
}

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

# 両端に各コマがあったとして、１．偶数の時　２．奇数の時どちらが勝つ？
# 奇数の時、先に動かすと勝つ
# 偶数の時、先に動かすと負ける
if (b - a) % 2:
  print('Borys')
else:
  print('Alice')

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/
int x, a, b;
char solve()
{
    int dista = abs(x - a);
    int distb = abs(x - b);
    return dista < distb ? 'A' : 'B';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
    cin >> x >> a >> b;

    cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;cin>>A>>B;
  int counter=0;
  int p,q,r,s;
  for(int i=A;i<=B;i++){
    p=i%10;
    q=(i-p)/10%10;
    s=i/10000;
    r=i/1000-s*10;
    if(p==s && q==r)counter++;
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()


int main(){
  int p,q,r,ans;
  cin >> p >> q >> r;

  ans= min(p+q,min(q+r,p+r));

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       in.lines()
           .map(Integer::valueOf)
           .sorted(Comparator.reverseOrder())
           .limit(3)
           .forEach(System.out::println);
    }
}

Measured memory_bytes: 30928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

priority_queue<ll> pq;
ii d[MAXn];
int main(){
    IOS();
    ll n,m;
    cin >> n >> m;
    REP (i,n) {
        ll a,b;
        cin >> a >> b;
        d[i] = ii(a,b);
    }
    sort(d,d+n);
    ll lst = 0, ans = 0;
    REP1 (i,m) {
        while (lst < n && d[lst].X <= i) pq.emplace(d[lst++].Y);
        if (SZ(pq)) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}


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

int main() {
  char s;
  cin >> s;
  if(s == 'A')
    cout << 'T' << endl;
  if(s == 'T')
    cout << 'A' << endl;
  if(s == 'G')
    cout << 'C' << endl;
  if(s == 'C')
    cout << 'G' << endl;
  
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int niza[n];
    for(int i=0; i<n; i++)
    {
        cin>>niza[i];
    }
    int res=0;
    sort(niza,niza+n);

    int cnt = 0;

    for( int i = n-1; i >= 1; i--)
    {
        int l = 0, r = i-1;
        while( l < r)
        {
            if( niza[l] + niza[r] > niza[i])
            {
                cnt += r - l ;
                r--;
            }
            else
                l++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
s = [sorted(input()) for _ in range(N)]
s.sort()
sum = 0
i = 1

for j in range(1,N):
  if s[j] == s[j-1]:
    i += 1
  else:
    if i > 1:
      sum += combinations_count(i, 2)
    i = 1
if i > 1:
      sum += combinations_count(i, 2)
    
  
print(sum)

Measured memory_bytes: 25516
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	string s;
	cin>>s;

	int l=s.length(),cnt=0;

	for(i=0;i<s.length()/2;i++)
	{
		if(s[i]!=s[l-i-1])
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;

}

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

int main(){
	int n;
	cin >> n;
	
	vector<int> a(n);
	
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=n-1; i>0; i--){
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
	return 0;
}


Measured memory_bytes: 3096
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input()
    T = input()
    ans = 0
    for i in range(3):
        if S[i] == T[i]: ans += 1;
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
from math import factorial


def cmb(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))


n,p=map(int,input().split())
A=list(map(int,input().split()))
A=[A[i]%2 for i in range(n)]

cnt=A.count(0)
B=2**cnt

ans=0
for i in range(p,n-cnt+1,2):
    ans +=cmb(n-cnt,i)
print(ans*B)

Measured memory_bytes: 38256
import java.util.Scanner;

//Nim
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int s = sc.nextInt();
			int[] m = new int[2*n];
			for(int i=0;i<2*n;i++)m[i]=sc.nextInt();
			boolean[][] dp = new boolean[2*n][s+1];
			for(int j=2;j<=s;j++)for(int i=0;i<2*n;i++){
				boolean w = false;
				for(int p=1;p<=m[i];p++){
					if(j-p<=0)break;
					if(!dp[(i+1)%(2*n)][j-p])w=true;
				}
				dp[i][j] = w;
			}
			System.out.println(dp[0][s]?1:0);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const long long INF = 1e18;

int main(){

    int N, M, P;
    cin >> N >> M >> P;
    vector<vector<pair<int, int>>> E(N);
    int a, b, c;
    for(int i = 0; i < M; i++){
        cin >> a >> b >> c;
        E[a - 1].push_back(make_pair(b - 1, c - P));
    }

    vector<long long> currentCost(N, -INF);
    vector<long long> nextCost(N, -INF);

    currentCost[0] = 0;
    nextCost[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            long long nodeCost = currentCost[j];
            if(nodeCost == -INF){
                continue;
            }
            for(auto e: E[j]){
                nextCost[e.first] = max(nextCost[e.first], nodeCost + e.second);
            }
        }

        for(int i = 0; i < N; i++){
            currentCost[i] = nextCost[i];
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            long long nodeCost = currentCost[j];
            if(nodeCost == -INF){
                continue;
            }
            for(auto e: E[j]){
                long long tempCost = nextCost[e.first];
                long long next = nodeCost + e.second;
                if(next > tempCost){
                    nextCost[e.first] = next;
                    if(e.first == N - 1){
                        cout << -1 << endl;
                        return 0;
                    }   
                }
            }
        }

        for(int i = 0; i < N; i++){
            currentCost[i] = nextCost[i];
        }
    }

    cout << max(0LL, currentCost[N - 1]) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdint>
#include <iostream>
#include <string>

int main(int argc, char** argv) {
  long long a;
  char b[4];
  std::cin >> a >> b[0] >> b[1] >> b[2] >> b[3];
  long long ruleb = 0;
  ruleb = b[0] - '0';
  ruleb *= 10;
  ruleb += b[2] - '0';
  ruleb *= 10;
  ruleb += b[3] - '0';

  long long ans = 0;
  ans = a * ruleb / 100;
  //  std::cout << std::fixed;
  //  std::cout << "a:" << a << std::endl;
  //  std::cout << "b:" << ruleb << std::endl;
  std::cout << ans << std::endl;
}

Measured memory_bytes: 3176
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long s = sc.nextLong();
		if(n==s){
			System.out.println(n+1);
			return;
		}
		long a=(long)Math.sqrt(n);
		for(long i = 2; i<=a; i++){
			if(s==co(i,n)){
				System.out.println(i);
				return;
			}
		}
		for(long i=a; i>=1; i--){
			long b = ((n-s)/i)+1;
			if(b>1 && co(b,n)==s){
				System.out.println(b);
				return;
			}
		}
		System.out.println(-1);
	}
	static long co(long i,long n){
		long re=0;
		while(n>0){
			re+=n%i;
			n/=i;
		}
		return re;
	}
}


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


int main()
{
	while (1){
		char suuji[1000];
		int suuti[1000];
		int sum = 0;

		cin >> suuji;
		if (suuji[0] == '0'){
			break;
		}
		for (int i = 0; i < 1000; i++){
			if (suuji[i] == NULL){
				break;
			}
			suuti[i] = suuji[i] - '0';
			sum = sum + suuti[i];
		}
		cout << sum << endl;
	}

	
	return 0;
}


Measured memory_bytes: 3072
import math
n,k = map(int,input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) if n-r >= 0 else 0

for i in range(1,k+1):
    red = n - k
    blue = i
    print(combinations_count(red+1,blue)*combinations_count(k-1,i-1)%(10**9+7))

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

struct Block {
  int w, s, v;
};
bool operator<(Block a, Block b) {
  return a.s+a.w < b.s+b.w;
}

Block a[1000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i].w >> a[i].s >> a[i].v;
  sort(a, a+n);
  int maxs = 1e4+1;
  vector<ll> dp(maxs,0);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    vector<ll> ndp = dp;
    for (int j = 0; j <= a[i].s; j++) {
      ll score = dp[j]+a[i].v;
      ans = max(ans, score);
      if (j+a[i].w < maxs)
	ndp[j+a[i].w] = max(ndp[j+a[i].w], score);
    }
    swap(dp, ndp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll a,b,c,d;
  cin >> a >> b >> c;
  d=0;
  
  printf("%lld ",min(c,b));
  printf("%lld",max(c+b-a,d));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  map<int, int> count;
  for(int i=0;i<n;i++){
  	int a;cin>>a;count[a]++;
  }
  int ans=0;
  for(auto itr=count.begin();itr!=count.end();itr++){
  	int d = itr->second - itr->first;
    if(d>=0)ans+=d;
    else ans+=itr->second;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>

using namespace std;


int main()
{unsigned int b[10];

for (int i=0;i<10;i++)
    {
      cin>>b[i];
      }
for (int j=0;j<10;j++)
    {
     for (int k=0;k<10-j;k++)
         {
          if (b[k]>b[k+1])swap(b[k],b[k+1]);
          }
        }

      cout<<b[10]<<endl;
      cout<<b[9]<<endl;
      cout<<b[8]<<endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int INF = -(1e9+123);
int a[N],b[N],c[N],dp[N][3];
int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    cout << endl;
    dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0;
    for(int i = 1; i <= n; i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
        //cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

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

int main() {
  int N,count;  count = 1;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++)
   cin >> vec.at(i);
  sort(vec.begin(),vec.end());
  
  for(int i=1; i<N; i++){
   if (vec.at(i) == vec.at(i-1))
    continue;
   else
     count++;
  }

  cout << count << endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(3020);
  for(int i=0;i<N;i++){cin >> a.at(i);}
  int b=0; 
  int c=N;
  for(int i=0;i<N;i++){
    b+=a.at(i)-1;
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,mx,x,y,a[500010],now;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)if(a[i]>=i)mx=i;
	x=(a[mx]-mx)%2;
	now=mx;
	while(a[now+1]>=mx)now++,y^=1;
	if(x||y)puts("First");
	 else puts("Second");
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

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

int main()
{
	int n,k;
	cin >> n >> k;
	int a;
	cin >> a;
	bool ans = (a >= k);
	int g = a;
	FOR(i,1,n){
		int a;
		cin >> a;
		if(a >= k)ans = true;
		g = gcd(g,a);
	}
	if(ans && k % g == 0){
		ANS("POSSIBLE");
	}else{
		ANS("IMPOSSIBLE");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int arr[5];
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
        if(arr[i]==0)
        {
        cout<<i+1<<"\n";
        break;
        }
    }
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	int t;
	int d;
	int ans = 0;
	for (int l = 0; l <= k; l++) {
		for (int r = 0; r <= k - l; r++) {
			if (l + r > n) {
				break;
			}
			
			int d = k - l - r;
			vector<int> s;
			t = 0;
			for (int i = 0; i < l; i++) {
				t += a[i];
				s.push_back(a[i]);
			}
			for (int i = n - r; i < n; i++) {
				t += a[i];
				s.push_back(a[i]);
			}
			sort(s.begin(), s.end());

			for (int i = 0; i < d; i++) {
				if (i == s.size()) {
					break;
				}
				if (s[i] < 0) {
					t -= s[i];
				}
				else {
					break;
				}
			}

			ans = max(ans, t);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

a,b,x = inpf
alx = x/a
sa = a*b - alx
if(alx > a*b/2)
  p Math.atan(sa/(a*a/2))*180/Math::PI
else
  p 90 - Math.atan(alx/(b*b/2))*180/Math::PI
end


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

using namespace std;

int N, x[1009], y[1009], r[1009], ap[1009];
double INF = 1e14, eps = 1e-9, d[1009], mat[1009][1009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &x[1], &y[1], &x[2], &y[2]);
scanf ("%d", &N);
for (int i=3; i<=N + 2; i++)
    scanf ("%d %d %d", &x[i], &y[i], &r[i]);
for (int i=1; i<=N + 2; i++)
    for (int j=i + 1; j<=N + 2; j++)
    {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        double D;
        if (1LL * dx * dx + 1LL * dy * dy <= 1LL * (r[i] + r[j]) * (r[i] + r[j])) D = 0.0;
        else D = (double) sqrt ((double) ((long long) 1LL * dx * dx + 1LL * dy * dy)) - r[i] - r[j];
        mat[i][j] = mat[j][i] = D;
    }
for (int i=1; i<=N + 2; i++)
    d[i] = INF;
d[1] = 0.0;
while (1)
{
    double mini = INF;
    int x = -1;
    for (int i=1; i<=N + 2; i++)
        if (d[i] < mini && ap[i] == 0)
            mini = d[i], x = i;
    if (x == -1) break;
    ap[x] = 1;
    for (int i=1; i<=N + 2; i++)
        if (ap[i] == 0 && d[x] + mat[x][i] < d[i] && i != x)
            d[i] = d[x] + mat[x][i];
}
printf ("%.10f\n", d[2]);
return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define LL long long
#define maxn 200005

using namespace std;

int n,m,ans=0x7fffffff,sum[15][1005],num[15],k;
char s[15][1005];
vector<int> blo[15];

bool Check(int last,int i,int cnt)
{
    for (int j=0;j<cnt;j++)
    {
        int cur=0;
        for (int k=0;k<blo[j].size();k++)
        {
            int row=blo[j][k];
            if (last!=0) cur+=sum[row][i]-sum[row][last-1];
            else cur+=sum[row][i];
        }
        if (cur>k) return 0;
    }
    return 1;
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<n;i++) scanf("%s",s[i]);
    for (int i=0;i<n;i++)
        for (int j=0;j<m;j++)
        {
            if (j==0) sum[i][j]=s[i][j]-'0';
            else sum[i][j]=sum[i][j-1]+s[i][j]-'0';
        }
    for (int flag=0;flag<(1<<(n-1));flag++)
    {
        int last=0,cnt=0,ret=0;
        for (int i=0;i<n-1;i++) blo[i].clear();
        for (int i=0;i<n-1;i++) if ((1<<i)&flag)
        {
            ret++;
            for (int j=last;j<=i;j++) blo[cnt].push_back(j);
            cnt++; last=i+1;
        }
        for (int j=last;j<n;j++) blo[cnt].push_back(j);
        cnt++;
        last=0;
        bool f=1;
        for (int i=0;i<m;i++) if (!Check(last,i,cnt))
        {
            if (last==i) {f=0; break;}
            else
            {
                last=i,ret++;
                if (i==m-1 && !Check(last,i,cnt)) f=0;
            }
        }
        if (f) ans=min(ans,ret);
    }
    printf("%d\n",ans);
    return 0;
}


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




int main(){
    string S;
    cin >> S;
    vector<string> DAY={"SN","SAT","FRI","THU","WED","TUE","MON","SUN"};
    for(int i=0;i<8;i++){
        if(S==DAY[i]){cout<<i<<endl;break;}
    ;}
    return 0;


}




Measured memory_bytes: 256
"use strict";
function I(t, i) {
  (this._s = t.split("\n")), (this._c = 0), (this._l = 0), (this._f = i || Number);
}
(I.prototype.a = function(t) {
  var i = this._s[this._l];
  if (i) {
    var s = i.trim().split(" "),
      h = s[this._c];
    return this._c++, s.length === this._c && ((this._c = 0), this._l++), t ? t(h) : this._f(h);
  }
}),
  (I.prototype.l = function(t) {
    var i = this._s[this._l];
    if (i) return (this._c = 0), this._l++, i.split(" ").map(t || this._f);
  }),
  (module.exports = I);

function main(input) {
  var o = new I(input);

  const N = o.a();
  const H = o.l();

  let currentMinHeight = 0;
  let isPossible = true;
  for (let i = 0; i < H.length; i++) {
    if (H[i] > currentMinHeight) {
      // try to decrease Hi as much as possible
      currentMinHeight = H[i] - 1;
    } else if (H[i] === currentMinHeight) {
      currentMinHeight = H[i];
    } else {
      isPossible = false;
      break;
    }
  }

  console.log(isPossible ? "Yes" : "No");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  char c1 = toupper(s1.at(0));
  char c2 = toupper(s2.at(0));
  char c3 = toupper(s3.at(0));
  cout << c1 << c2 << c3 << endl;
  return 0;
}


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

int main() {
    string s;
    int coun = 0;

    cin >> s;
    for (int i = 0; i < 3; i++){
        if (s[i] == '1'){
            coun += 1;
        }
    }

    cout << coun << endl;
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())
for i in range(k):
  if i%2==0:
    if a%2==1:
      a-=1
    b+=a//2
    a-=a//2
  else:
    if b%2==1:
      b-=1
    a+=b//2
    b-=b//2
print(a,b)

Measured memory_bytes: 3060
N, Q = map(int, input().strip().split())
v_list = [set() for i in range(N)]

for _ in range(N - 1):
	a, b = map(int, input().strip().split())
	a -= 1
	b -= 1
	v_list[a].add(b)
	v_list[b].add(a)

queue = [0]
while queue:
	cur = queue.pop()
	for child in v_list[cur]:
		v_list[child].remove(cur)
		queue.append(child)

x_table = [0] * N

for _ in range(Q):
	p, x = map(int, input().strip().split())
	p -= 1
	x_table[p] += x

values = [None] * N
values[0] = x_table[0]
queue = [0]
while queue:
	cur = queue.pop()
	value = values[cur]
	for child in v_list[cur]:
		values[child] = value + x_table[child]
		queue.append(child)

print(" ".join(map(str, values)))


Measured memory_bytes: 93084
#   AtCoder abc087 a
#   ストレッチ課題

#   入力
balance = int(input())
price_cake = int(input())
price_doughnut = int(input())

#   処理
# balance = balance - price_cake      # ケーキ購入後の残高
# balance = balance % price_doughnut  # ドーナツ購入後の残高
balance = (balance - price_cake) % price_doughnut

#   出力
print(balance)



Measured memory_bytes: 9140
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

const int N = 100 * 1001;
int n, sz[N];
bool ok;
vector<int> adj[N];


void dfs(int u, int par = -1) {
	sz[u] = 1;
	int cnt = 0;
	for (auto v: adj[u])
		if (par != v) {
			dfs(v, u);
			sz[u] += sz[v];
			if (sz[v] % 2)
				cnt++;
		}
	if (cnt >= 2)
		ok = true;

}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	if (n % 2) {
		cout << "First\n";
		return 0;
	}
	dfs(0);
	if (ok) 
		cout << "First\n";
	else
		cout << "Second\n";
}

Measured memory_bytes: 9584
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct Dinic {
  #define MAX_V 30000
  struct Edge { int to, cap, rev; };
  vector<Edge> G[MAX_V];
  int level[MAX_V], iter[MAX_V];
  void add_edge(int x, int y, int cap) {
    G[x].pb({ y, cap, (int)G[y].size() });
    G[y].pb({ x, 0, (int)G[x].size()-1 });
  }
  void bfs(int s) {
    rep(i, MAX_V) level[i] = INF;
    queue<int> q;
    q.push(s);
    level[s] = 0;
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (Edge e : G[x]) {
        if (e.cap > 0 && level[e.to] == INF) {
          level[e.to] = level[x]+1;
          q.push(e.to);
        }
      }
    }
  }
  int dfs(int x, int goal, int f) {
    if (x == goal) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int w = dfs(e.to, goal, min(f, e.cap));
        if (w > 0) {
          e.cap -= w;
          G[e.to][e.rev].cap += w;
          return w;
        }
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] == INF) return flow;
      rep(i, MAX_V) iter[i] = 0;
      while (true) {
        int f = dfs(s, t, INF);
        if (f == 0) break;
        flow += f;
      }
    }
  }
};
Dinic dinic;

int H, W;
char A[100][100];
int IN[100][100], OUT[100][100];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  int V = 0;
  rep(y, H) {
    rep(x, W) {
      cin >> A[x][y];
      if (A[x][y] == 'X') {
        IN[x][y] = OUT[x][y] = V++;
      }
      else {
        IN[x][y] = V++;
        OUT[x][y] = V++;
        dinic.add_edge(IN[x][y], OUT[x][y], 1);
      }
    }
  }
  int s = V++, t = V++;
  rep(x, W) rep(y, H) {
    if (A[x][y] == 'X') dinic.add_edge(s, IN[x][y], INF);
  }
  rep(x, W) rep(y, H) if (x == 0 || x == W-1 || y == 0 || y == H-1) {
    if (A[x][y] == 'X') {
      cout << -1 << "\n";
      return 0;
    }
    dinic.add_edge(OUT[x][y], t, INF);
  }
  rep(x, W-1) rep(y, H) dinic.add_edge(OUT[x][y], IN[x+1][y], INF), dinic.add_edge(OUT[x+1][y], IN[x][y], INF);
  rep(x, W) rep(y, H-1) dinic.add_edge(OUT[x][y], IN[x][y+1], INF), dinic.add_edge(OUT[x][y+1], IN[x][y], INF);
  cout << dinic.max_flow(s, t) << "\n";
  return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<vector>

using namespace std;

int main(void){
	while(1){
		vector<vector<int> > kek[31];
		
		int n;
		scanf("%d",&n);
		if(n==0){break;}
		
		for(int i=1;i<=n;i++){
			vector<int> hn;
			hn.push_back(i);
			kek[i].push_back(hn);
			
			for(int j=i-1;j>0;j--){
				
				for(int k=0;k<kek[i-j].size();k++){
					int flg=0;
					
					for(int p=0;p<kek[i-j][k].size();p++){
						if(kek[i-j][k][p]>j){
							flg=1;
							break;
						}
					}
					
					if(flg==1){
						continue;
					}
					
					vector<int> u;
					u.push_back(j);
					
					for(int p=0;p<kek[i-j][k].size();p++){
						u.push_back(kek[i-j][k][p]);
					}
					kek[i].push_back(u);
				}
			}
		}
		
		for(int j=0;j<kek[n].size();j++){
			printf("%d",kek[n][j][0]);
			for(int k=1;k<kek[n][j].size();k++){
				printf(" %d",kek[n][j][k]);
			}
			puts("");
		}
	}
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		String sa0 = sa[0];
		sa = br.readLine().split(" ");
		int red = Integer.parseInt(sa[0]);
		int blue = Integer.parseInt(sa[1]);
		String u = br.readLine();
		if(u.equals(sa0)) {
			red--;
		}else {
			blue--;
		}
		System.out.println(red+ " " +blue);
		
	}

}


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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct card {
	char Rc[3],Rcc[3];//　重大注意！！！:配列の数はEOS（空白分も入れ無くてはならない）
	int R,Ri;
};

int SelectionSort(struct card R[], int N);
int BubbleSort(struct card R[], int N);
void Swap(int *a, int *b, char aa[], char bb[]);
void isStable(struct card c[], int N);


int main(void) {

	int N ;
	char p;

	scanf("%d\n", &N);//半角スペースで区切ることができる。

	struct card c[36];
	
	int t, k;
	
	for (t = 0; t < N; t++) {scanf("%s", &c[t].Rc);}

	for (t = 0; t < N; t++) {
		p = c[t].Rc[1];
		c[t].R = atoi(&p);		
		strcpy(c[t].Rcc, c[t].Rc);
		c[t].Ri = c[t].R;
	}

	BubbleSort(c, N);
	for (k = 0; k < N; k++) {
		if (k > 0) { 
			printf(" "); }
		printf("%s", c[k].Rc);
	}
	printf("\n");
	isStable(c,N);
	
	for (t = 0; t < N; t++) {
		strcpy(c[t].Rc, c[t].Rcc);
		c[t].R = c[t].Ri;
	}
	
	SelectionSort(c, N);
	
	for (k = 0; k < N; k++) {
		if (k > 0) {
			printf(" ");
		}
		printf("%s", c[k].Rc);
		
	}
	printf("\n");
	isStable(c, N);
	
	return 0;
}

int SelectionSort(struct card c[], int N) {
	int i, j, minj;
	int count = 0;
	for (i = 0; i < N - 1; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (c[j].R < c[minj].R) {
				minj = j;
			}
		}
		Swap(&c[i].R, &c[minj].R, c[i].Rc, c[minj].Rc);
		if (i != minj) {
			count++;
		}
	}
	return count;
}
int  BubbleSort(struct card c[], int N) {
	int flag = 1;
	int count = 0;
	int j;
	while (flag != 0) {	//forにして、ソートを終える場所を少しづつ変えていけば完璧。（恐らくオーダーは変わらない。）
		flag = 0;
		for (j = N - 1; j >= 1; j--) {
			if (c[j].R < c[j-1].R) {
				Swap(&c[j].R, &c[j - 1].R, c[j].Rc, c[j - 1].Rc);
				flag = 1;
				count++;
			}
		}
	}
	return count;
}
void Swap(int *a, int *b,char aa[] ,char bb[]){
	int k,i;
	char t[2];
	
	k = *a;
	*a = *b;
	*b = k;

	for (i = 0; i < 2; i++) {
		t[i] = aa[i];
		aa[i] = bb[i];
		bb[i] = t[i];
	}
}
void isStable(struct card c[], int N) {
	int i, j, a, b;
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			for (a = 0; a < N; a++) {
				for (b = a + 1; b < N; b++) {
					if (c[j].Ri == c[i].Ri && strcmp(c[i].Rcc,c[b].Rc) == 0 && strcmp(c[j].Rcc,c[a].Rc) == 0){
						printf("Not stable\n");
						return ;
					}
				}
			}
		}
	}
	printf("Stable\n");
	return ;
}


Measured memory_bytes: 2108
from sys import stdin
readline = stdin.readline


from itertools import accumulate

while True:
    trip_cost = int(readline())
    if trip_cost == 0:
        break
    saving = []
    for _ in range(12):
        income, outgo = map(int, readline().split())
        saving.append(income - outgo)

    for i, accumulative_saving in enumerate(accumulate(saving)):
        if trip_cost <= accumulative_saving:
            print(i + 1)
            break
    else:
        print('NA')

Measured memory_bytes: 6732
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))

Measured memory_bytes: 70076
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

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

    cin >> a >> b >> c;

    if (a <= c && c <= b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <cmath>
#include <regex>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  cout << (a*b%2==0 ? "Even": "Odd") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;



int a[100005];
int main()
{
    int n,ans=0,cnt,sum;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    a[0]=0;a[n+1]=0;
    for(int i=0;i<n+2;i++)
    {
    ans+=abs(a[i+1]-a[i]);
    }
    for(int i=1;i<=n;i++)
    cout<<ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
    //system("pause");
    return 0;
}  

Measured memory_bytes: 1664
n, m = map(int, input().split())

x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

sx = 0
pre = 0
for i in range(1, n) :
    pre += (x[i]-x[i-1]) * i
    sx += pre
    sx %= MOD
    
sy = 0
pre = 0
for i in range(1, m) :
    pre += (y[i]-y[i-1]) * i
    sy += pre
    sy %= MOD
    
print(sx*sy%MOD)

Measured memory_bytes: 84068
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

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

int n, w, m[100][2], dp[101][10001];

int main() {
	scanf("%d %d", &n, &w);
	for (int i = 0; n > i; i++) scanf("%d %d", &m[i][1], &m[i][0]);
	for (int i = 0; n > i; i++) {
		for (int j = 0; w >= j; j++) {
			if (m[i][0] > j) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = max(dp[i][j], dp[i+1][j - m[i][0]] + m[i][1]);
		}
	}
	printf("%d\n", dp[n][w]);
	return 0;
}

Measured memory_bytes: 5100
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
         
        ll n,d;cin>>n>>d;
        
        int c=0;
        for(int i=0;i<n;i++)
        {
            ll x,y;cin>>x>>y;
            
            ll d1=x*x+y*y;
            
            if(d1<=d*d) c++;
        }
        
        cout<<c<<"\n";
        
    }
}

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MAX = 1e5+1;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

int a, b;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> a >> b;
	cout << max(a*b, max(a+b, a-b));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(void){
	std::string s;
	std::cin>>s;
	int length=s.length();
	int p=0,g=0;
	for(int i=0;i<length;i++){
		if(s[i]=='p'){
			p++;
		}else {
			g++;
		}
	}
	std::cout<<length/2-p<<std::endl;
	return 0;
}

Measured memory_bytes: 512
N, K = map(int, input().split())
if N < K:
    print(min(N, abs(N-K)))
elif N == K:
    print(N-K)
else:
    cnt = N//K
    ans = abs(N - K*(cnt+1))
    ans2 = abs(N- K*cnt)
    print(min(ans,ans2))

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

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

  if (isupper(s))
  {
    cout << 'A' << endl;
  }
  else
  {
    cout << 'a' << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,k,a[150],dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i>=a[j])
            {
                if(dp[i-a[j]]==0)
                {
                    dp[i]=true;
                }
            }
        }
    }   
    if(dp[k]==1)cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 640