akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    if(k==0){
        Cout(n*n);
    }
    else{
    rrep(b,1,n+1){
        ll r=(n+1)/b;
        ans+=r*max(b-k,0LL);
        tmp=(n+1)%b;
        ans+=max(tmp-k,0LL);
    }
    Cout(ans);
    }
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	string s,t;
	cin >> s >> t;
	rep(i,s.length()) {
		t.pb(s[i]);
	}
	cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll a,b;
    cin >> a >> b;
    string s;
    if(a<b)
        s = "<";
    else if(a>b)
        s = ">";
    else
        s = "==";

    cout << "a " << s << " b" << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 3009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
//int T,cas=1;

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    //scanf("%d",&T);
    //while(cas<=T)
    //{
    //    cas++;
    //}
    char s1[maxn],s2[maxn];
    scanf("%s",s1);
    scanf("%s",s2);
    int len1=strlen(s1),len2=strlen(s2);
    int ans=-1;
    if(len1<len2)
        ans=-1;
    else if(len1>len2)
        ans=1;
    else
    {
        ans=0;
        for(int i=0;i<len1;i++)
        {
            if(s1[i]<s2[i])
            {
                ans=-1;
                break;
            }
            else if(s1[i]>s2[i])
            {
                ans=1;
                break;
            }
        }
    }
     if(ans==-1)
        cout<<"LESS\n";
    else if(ans==0)
        cout<<"EQUAL\n";
    else
        cout<<"GREATER\n";
    return 0;
}


Measured memory_bytes: 256
import bisect

A,B,Q = map(int, input().split())
INF = 10**18

s =[-INF] + [int(input()) for i in range(A)] +[INF]
t =[-INF] + [int(input()) for i in range(B)] +[INF]

for q in range(Q):
    x = int(input())
    b, d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
            res = min(res, d1,d2)
    print(res)

Measured memory_bytes: 14360
#include<stdio.h>
main(){
  char str[15];
  int a[10][10],i,j,n;
  while(scanf("%s",str)!=EOF){

  
  for(i=0;i<10;i++){
    a[0][i]=str[i]-48;
  }

  for(i=1,n=9;i<9;i++,n--){
    for(j=0;j<n;j++){
      a[i][j]=(a[i-1][j]+a[i-1][j+1])%10;
    }
  }
  printf("%d\n",(a[8][0]+a[8][1])%10);
  }
  return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#define M 100000
#define N 200005
using namespace std;
vector<int>son[N];
int E,L,R,mark[N];
void dfs(int x,int flg){
	E++;
	if(mark[x])return;
	mark[x]=1;
	if(flg)L++;
	else R++;
	for(int i=0;i<son[x].size();i++){
		int y=son[x][i];
		dfs(y,!flg);
	}
}
int main(){
	int n,x,y;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&x,&y),son[x].push_back(y+M),son[y+M].push_back(x);
	long long ans=0;
	for(int i=1;i<=M;i++){
		if(!mark[i]){
			E=L=R=0;
			if(son[i].size()==0)continue;
			dfs(i,1);
			if(L<2||R<2)continue;
			E/=2;
			ans+=1ll*L*R-E;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11776
n = gets.to_i
x = gets.chomp
c = x.count(?1)

up1 = c + 1
down1 = [c - 1, 1].max

pow2_mod_up1 = [up1 == 1 ? 0 : 1]
pow2_mod_down1 = [down1 == 1 ? 0 : 1]
(n-1).times do |i|
    pow2_mod_up1.unshift(pow2_mod_up1[0] * 2 % up1)
    pow2_mod_down1.unshift(pow2_mod_down1[0] * 2 % down1)
end

x_mod_up1 = x_mod_down1 = 0
n.times do |i|
    next if x[i] == ?0
    x_mod_up1 += pow2_mod_up1[i]
    x_mod_down1 += pow2_mod_down1[i]
end

n.times do |i|
    if x[i] == ?0
        a = (x_mod_up1 + pow2_mod_up1[i]) % up1
    else
        if c == 1
            puts 0
            next
        end
        a = (x_mod_down1 - pow2_mod_down1[i]) % down1
    end

    ans = 1
    while a != 0
        a %= a.to_s(2).count(?1)
        ans += 1
    end
    p ans
end

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;i++) cin >> a[i];
    queue<int> que;
    for (int i=0;i<N;i++){
        for (int j=0;j<a[i];j++){
            que.push(i+1);
        }
    }
    int side = 0;
    vector<vector<int>> color(H,vector<int>(W));
    for (int h=0;h<H;h++){
        if (side == 0) {
            for(int w=0;w<W;w++){
                int p = que.front();que.pop();
                color[h][w] = p;
            }
            side = 1;
        } else {
            for (int w=W-1;w>=0;w--){
                int p = que.front();que.pop();
                color[h][w] = p;
            }
            side = 0;
        }
    }
    for (int h=0;h<H;h++){
        for (int w=0;w<W;w++){
            cout << color[h][w];
            if (w == W-1) cout << "\n";
            else cout << " ";
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[][] candy = new int[n][2];
    for(int i = 0; i < n; i++) {
      candy[i][0] = Integer.parseInt(sc.next());
    }
    for(int i = 0; i < n; i++) {
      candy[i][1] = Integer.parseInt(sc.next());
    }
    for(int i = 1; i < n; i++) {
      candy[i][0] += candy[i-1][0];
    }
    candy[0][1] += candy[0][0];
    for(int i = 1; i < n; i++) {
      candy[i][1] += Math.max(candy[i-1][1], candy[i][0]);
    }
    System.out.println(candy[n-1][1]);
  }
}


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

int a[9],i,j;

int main(){
	for(i=0;i<3;i++){
		scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]);
		for(j=0;j<3;j++){
			if(a[5-j]<a[2-j]){
				a[4-j]--;
				a[5-j]=a[5-j]+60;
			}
			a[8-j]=a[5-j]-a[2-j];
		}
		for(j=0;j<3;j++)printf("%d%c",a[6+j],(j==2)?('\n'):(' '));
	}
	
	return 0;
}

Measured memory_bytes: 0
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("Ofast")
    using namespace std;
    //library
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double
    //scankar
    #define sz(x) (int)(x).size()
    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    typedef map<int,int> mii;
    typedef map<int,bool> mib;
    typedef map<char,int> mci;
    typedef map<string,int> msi;
    
    const int INF = 1e18L + 5;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    //direction
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;
    //debugger

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int a[MAX];
    
    void solve()
    {
        n=5;
        fo(i,1,n+1)cin>>a[i];
        fo(i,1,n+1)
        {
            if(a[i]==0)
            {
                cout<<i<<endl;
                return;
            }
        }
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3652
//
// Created by watemus on 17.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

vector<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif


void run() {
    int n;
    cin >> n;
    if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n %10 == 7 || n % 10 == 9) {
        cout << "hon";
    } else if (n % 10 ==3) {
        cout << "bon";
    } else {
        cout << "pon";
    }
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

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

signed main(){
    int r,g,b;
    cin >>r>>g>>b;
    int k=100*r+10*g+b;
    if(k%4==0)cout << "YES";
    else cout <<"NO";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        double x1,y1,x2,y2,x3,y3,x4,y4;
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        if (abs((y3-y4)*(x1-x2)-(y1-y2)*(x3-x4))<1e-10) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3224
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0].split("");

    var cnt_t = 0; var cnt_f = 0;
    for (var i = 0; i < S.length; i++) { S[i] === "o" ? cnt_t++ : cnt_f++; }

    if (8 - cnt_t > 15 - S.length) { console.log("NO") }
    else { console.log("YES"); }
});

Measured memory_bytes: 21320
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;


int main() {
  int n; cin>>n;
  int cnt = 0;
  for (int i=1; i<=n; i++){
    int num; cin>>num;
    if (i%2==1 && num%2==1) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3100
n, k, q = map(int, input().split())
p = int(k - q)
if p > 0:
    for _ in range(n): print("Yes")
else:
    a = {}
    for _ in range(q):
        a_i = str(input())
        if a_i not in a.keys():
            a[a_i] = 1
        else:
            a[a_i] += 1
    for i in range(1, n+1):
        if str(i) not in a.keys(): print("No")
        else: print("Yes") if p + a[str(i)] > 0 else print("No")

Measured memory_bytes: 10216
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int MXN=500;
    ll ans[MXN][MXN];
    vector<bool> is_prime(10000,true);
    is_prime[0]=is_prime[1]=false;
    vl p;
    FOR(i,2,10000){
        if(is_prime[i]){
            if(i>=500){
                p.pb(i);
            }
            ll j=2*i;
            while(j<10000){
                is_prime[j]=false;
                j+=i;
            }
        }
    }
    rep(i,MXN){
        rep(j,MXN){
            if(i%2==j%2){
                ans[i][j]=p[i+j]*(250-(j-i)/2);
            }
            else{
                ans[i][j]=1;
            }
        }
    }
    rep(i,MXN){
        rep(j,MXN){
            if((i+j)%2==1){
                if(i!=0)ans[i][j]=lcm(ans[i][j],ans[i-1][j]);
                if(j!=0)ans[i][j]=lcm(ans[i][j],ans[i][j-1]);
                if(i!=MXN-1)ans[i][j]=lcm(ans[i][j],ans[i+1][j]);
                if(j!=MXN-1)ans[i][j]=lcm(ans[i][j],ans[i][j+1]);
                ans[i][j]++;
            }
        }
    }
    rep(i,N){
        rep(j,N){
            cout << ans[i][j] << ( j==N-1 ? '\n' : ' ' );
        }
    }
}


Measured memory_bytes: 5608
# 入力は1行で[数値 数値]
def return_number(n, k):
    return n * k - k*k + k + 1


il1 = input().split()
N = int(il1[0])
K = int(il1[1])

answer = 0
mod = 10**9 +7

for k in range(K, N+2):
    num  = return_number(N, k)
    answer = answer + num

print(answer%mod)


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

typedef struct point
{
	int l, r;
}point;

int a[100005],b[100005];
point A[100005];

bool cmp(point a,point b)
{
	return a.r<b.r;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		A[i].l=a[i]-b[i];
		A[i].r=a[i]+b[i];
	}
	sort(A+1,A+1+n,cmp);
	int tmp = -1000000001;
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(A[i].l>=tmp) 
		{
			ans++;
			tmp = A[i].r;
		}
	}
	cout<<ans;
	return 0;
}

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

int main(){
  
  char n[1000000];
  int i,sum = 0;
  
  scanf("%s",n);
  
  int len = strlen(n);
  
  //printf("len = %d\n",len);
  
  for(i = 0; i < len; i++)sum += n[i] - '0';
  
  if(sum % 9 == 0){
    puts("Yes");
  }else{
    puts("No");
  }
  
  return 0;
  
}



Measured memory_bytes: 1820
#include <iostream>
#include <string>
int main()
{
  std::string S;
int count = 0;
  std::cin >> S;

  for(int i = 0; i < S.length(); i++)
  {
    if( S[i] == 'o' )
    {
      count++;
    }
  }
  if(  ( 15 - S.length() ) + count >= 8 )
  std::cout << "YES" <<std::endl;
  else
  std::cout << "NO" <<std::endl;

  return 0;
}


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		if(a%2==0 || b%2==0)
		System.out.println("Even");
		else System.out.println("Odd");
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;


int main()
{
	int S, W;

	cin >> S >> W;

	cout << (W>=S? "unsafe" :"safe");
	 
	return 0;
	
}

Measured memory_bytes: 3636
N = int(input())
S = input()

ans = [''] * N

def other(s):
  if s == 'S':
    return 'W'
  else:
    return 'S'

def calc(S):
  global ans
  for i, s in enumerate(S):
    if s == 'o':
      if ans[i] == 'S':
        ans[(i+1)%N] = ans[i-1]
      else:
        ans[(i+1)%N] = other(ans[i-1])
    else:
      if ans[i] == 'S':
        ans[(i+1)%N] = other(ans[i-1])
      else:
        ans[(i+1)%N] = ans[i-1]

ans[-1] = 'S'
ans[0] = 'S'
calc(S)
if (ans[0], ans[-1]) == ('S', 'S'):
  print(''.join(ans))
  quit()

ans[-1] = 'S'
ans[0] = 'W'
calc(S)
if (ans[0], ans[-1]) == ('W', 'S'):
  print(''.join(ans))
  quit()

ans[-1] = 'W'
ans[0] = 'S'
calc(S)
if (ans[0], ans[-1]) == ('S', 'W'):
  print(''.join(ans))
  quit()

ans[-1] = 'W'
ans[0] = 'W'
calc(S)
if (ans[0], ans[-1]) == ('W', 'W'):
  print(''.join(ans))
  quit()

print(-1)

Measured memory_bytes: 4212
// Coloring Colorfully
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    string S;
    cin >> S;

    int len = S.size();

    vector<char> tmp1;
    tmp1.assign(len,' ');
    vector<char> tmp2;
    tmp2.assign(len,' ');

    for (int i = 0; i < len; i++) {
        tmp1[i] = i % 2 == 0 ? '1' : '0';
    }
    for (int i = 0; i < len; i++) {
        tmp2[i] = i % 2 == 0 ? '0' : '1';
    }

    int count1 = 0;
    int count2 = 0;

    for (int i = 0; i < len; i++) {
        char c = S[i];
        if (c != tmp1[i]) {
            count1++;
        }
        if (c != tmp2[i]) {
            count2++;
        }
    }
    
    int result = count1 < count2 ? count1 : count2;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 512
N,M = map(int,input().split())
path = [[] for _ in range(N)]
save = []
for _ in range(M):
    a,b = map(int,input().split())
    save.append([a-1,b-1])
    path[b-1].append(a-1)
    path[a-1].append(b-1)


def dfs(now):
    global cnt
    if not 0 in vis: 
        cnt += 1
        return None
    for new in path[now]:
        if vis[new] == 0:
            vis[new] = 1
            dfs(new)
cnt = 0
for i in range(M):
    vis  = [0 for _ in range(N)]
    a = save[i][0]
    b = save[i][1]
    path[a].remove(b)
    path[b].remove(a)
    vis[0] = 1
    dfs(0)
    path[a].append(b)
    path[b].append(a)
print(M-cnt)



Measured memory_bytes: 70436
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int a,b,c,d,e;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  int m=10;
  if(a%10>0){
    m=min(a%10,m);
    a=(a/10+1)*10;
  }
  if(b%10>0){
    m=min(b%10,m);
    b=(b/10+1)*10;
  }
  if(c%10>0){
    m=min(c%10,m);
    c=(c/10+1)*10;
  }
  if(d%10>0){
    m=min(d%10,m);
    d=(d/10+1)*10;
  }
  if(e%10>0){
    m=min(e%10,m);
    e=(e/10+1)*10;
  }
  cout << a+b+c+d+e+m-10 << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int tmp;
  int a[100][100];
  int b[100];
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      scanf("%d", &tmp);
      a[i][j] = tmp;
    }
  }
  for (int i = 0; i < m; i++)
  {
    scanf("%d", &tmp);
    b[i] = tmp;
  }
  long long int sum;
  for (int i = 0; i < n; i++)
  {
    sum = 0;
    for (int j = 0; j < m; j++)
    {
      sum += a[i][j] * b[j];
    }
    printf("%lld\n", sum);
  }
}


Measured memory_bytes: 3208
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
thx
https://beta.atcoder.jp/contests/arc087/submissions/1876515
*/
struct Trie{
	Trie *son[2];
	Trie(){
		son[0]=son[1] = NULL;
	}
};

Trie* root;

void Insert(string str){
	int size = str.size();//文字サイズ
	Trie* node = root;//初期ノード
	for(int i=0;i<size;++i){
		int index = str[i]-'0';
		if( node->son[index] == NULL ){
			node->son[index] = new Trie();
		}
		//次のノードへ
		node = node->son[index];
	}
}

LL getGrundy(LL x){
	return x & -x;
}
LL L;
LL dfs(Trie* node,int depth){
	LL ret = 0;
	for(int i=0;i<2;++i){
		if(node->son[i] == NULL ){
			ret ^= getGrundy(L - depth);
		}else{
			ret ^= dfs(node->son[i],depth+1);
		}
	}
	return ret;
}
void solve(){
	int N;
	
	cin>> N >> L;
	root = new Trie();
	for(int i=0;i<N;++i){
		string str;
		cin>> str;
		Insert( str );
	}
	LL ret = dfs(root,0);
	cerr << ret << endl;
	if( ret ){
		cout<< "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 8172
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];

    sort(S.begin(), S.end());
    for(int i = 0; i < N; i++) cout << S[i]; cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, K;
    cin >> n >> K;
    vector<pair<LL, LL>> a(n);
    vector<LL> b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> c[i];
        a[i] = {b[i], c[i]};
    }
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    sort(c.begin(), c.end());
    c.erase(unique(c.begin(), c.end()), c.end());
    int w = b.size(), h = c.size();
    vector<vector<int>> zb(w), qzh(w + 1);
    for (auto& i : zb) i.resize(h);
    for (auto& i : qzh) i.resize(h + 1);
    for (auto& i : a) {
        int x = lower_bound(b.begin(), b.end(), i.first) - b.begin();
        int y = lower_bound(c.begin(), c.end(), i.second) - c.begin();
        zb[x][y]++;
    }
    for (int i = 1; i <= w; i++) {
        for (int j = 1; j <= h; j++) {
            qzh[i][j] = qzh[i][j - 1] + zb[i - 1][j - 1];
        }
    }
    for (int j = 1; j <= h; j++) {
        for (int i = 1; i <= w; i++) {
            qzh[i][j] += qzh[i - 1][j];
        }
    }
    LL ans = numeric_limits<LL>::max();
    for (int i = 0; i < w; i++) {
        for (int j = i; j < w; j++) {
            for (int k = 0; k < h; k++) {
                int l = k, r = h;
                while (l < r) {
                    int mid = (l + r) / 2;
                    if (qzh[j + 1][mid + 1] - qzh[j + 1][k] - qzh[i][mid + 1] + qzh[i][k] < K) l = mid + 1;
                    else r = mid;
                }
                if (r == h) continue;
                ans = min(ans, (b[j] - b[i]) * (c[r] - c[k]));
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int K, A, B; std::cin >> K >> A >> B;
  LL ans = 1;

  int up = B - A;
  if (up <= 1) {
    std::cout << K + 1 << std::endl;
    return 0;
  }

  int num = K - A + 1;
  ans = A + (num%2);

  LL time = num/2;
  ans += time * up;
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
n,x = map(int,input().split())
l = [[1,1],[5,3]]

for i in range(2,n):
    a = l[-1][0]
    b = l[-1][1]
    l.append([a*2+3,b*2+1])

ans = 0
for i in range(n-1,0,-1):
    if x >= l[i][0]+2:
        ans += l[i][1]+1
        x -= l[i][0]+2
    else:
        x -= 1

if x > 0:
    b = [0,1,1,1,0]
    ans += b[:x].count(1)
print(ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine());
        int counter = 0;

        int[][] result = new int[n][2];
        for(int i=0; i < n; i++){
            result[i][0] = sc.nextInt();
            result[i][1] = sc.nextInt();
        }

        for(int i=0; i< n; i++){
            if(result[i][0] == result[i][1]){
                counter++;
                if(counter == 3){
                    break;
                }
            }else {
                counter = 0;
            }
        }

        if(counter == 3){
            System.out.println("Yes");
        }else {
            System.out.println(("No"));
        }

    }
}


Measured memory_bytes: 36016
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public class Combination
{
    private readonly long[] Fact;
    private readonly long[] InvFact;  // モジュラ逆数

    public Combination(long n)
    {
        Fact = new long[n + 1];
        InvFact = new long[n + 1];

        long f = 1;
        Fact[0] = f;
        for (long i = 1; i <= n; i++)
        {
            f *= i;
            f %= Mod;
            Fact[i] = f;
        }

        long inv = ModInt.GetInv(f).Num;

        InvFact[n] = inv;
        for (long i = n - 1; i >= 0; i--)
        {
            InvFact[i] = (InvFact[i + 1] * (i + 1)) % Mod;
        }
    }

    // nCr
    public ModInt GetCombination(long n, long r)
    {
        if (n < r)
        {
            return 0;
        }

        var comb = Fact[n] * InvFact[r] % Mod;
        comb = comb * InvFact[n - r] % Mod;
        return new ModInt(comb);
    }
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];

        var comb = new Combination(N);
        var patterns = new List<ModInt>();
        for (int i = 1; i <= K; i++)
        {
            var pattern = comb.GetCombination(K - 1, i - 1) * comb.GetCombination(N - K + 1, i);
            patterns.Add(pattern);
        }

        Console.WriteLine(string.Join(Environment.NewLine, patterns));
    }
}

Measured memory_bytes: 13396
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N;
  string S;
  cin >> N >> S;
  ll R_num = 0, G_num = 0, B_num = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'R') R_num++;
    if (S[i] == 'G') G_num++;
    if (S[i] == 'B') B_num++;
  }
  ll cnt = R_num * G_num * B_num;
  ll wrong_cnt = 0;
  for (int j = 1; j < N; j++) {
    for (int diff = 1; diff < N; diff++) {
      if (j + diff < N && 0 <= j - diff && S[j + diff] != S[j] &&
          S[j - diff] != S[j] && S[j + diff] != S[j - diff])
        wrong_cnt++;
    }
  }
  cout << cnt - wrong_cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<998244353>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int x;
    cin >> x;

    int ans = 0;
    ans += 1000*(x / 500);

    x %= 500;

    ans += 5*(x/5);

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

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

//解説参考
int main(){
	int x;
	cin>>x;
	
	int tmp[1001];
	tmp[1]=1;
	for(int i=2;i<=x;i++) tmp[i]=0;
	for(int i=2;i<=x;i++){
		int v=i*i;
		while(v<=x){
			tmp[v]=1;
			v*=i;
		}
	}
	
	for(int i=x;i>=1;i--){
		if(tmp[i]){
			cout<<i<<endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    long long n,i,num,a[200000],b[200000]={},ans=0;
    scanf("%lld\n",&n);
    for(i=0; i<n; i++){
        scanf("%lld ",&a[i]);
        b[a[i]-1]++;
    }
    for(i=0; i<n; i++){
        ans+=b[i]*(b[i]-1)/2;
    }
    for(i=0; i<n; i++){
        num=b[a[i]-1]-1;
        printf("%lld\n",ans-num);
    }
    return 0;
}

Measured memory_bytes: 5632
#include<stdio.h>
main(){
  int n,i,j,sum,sosu[1000000];
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<=n;i++)sosu[i]=0;
    sum=0;
  for(i=2;i<=n;i++){
    if(sosu[i]==0){
      sum++;
    for(j=2;i*j<=n;j++){
      sosu[i*j]=1;
    }
    }
  }
  printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#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> ostream &operator << (ostream &_s,deque<_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()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    set<ll> m;
    int n;
    cin >> n;
    vector<ll> a(n);

    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        if(m.count(a[i])){
            cout << "NO" << endl;
            return 0;
        }
        m.insert(a[i]);
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 11264
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <utility>

#define MAX_N (40)
#define INF (1 << 30)

using namespace std;

void create_list(map<pair<int, int>, int> &m, int *as, int *bs, int *cs,
                 int n) {
  for (int k = 0; k < 1 << n; k++) {
    int a = 0, b = 0, c = 0;
    for (int l = 0; l < n; l++) {
      if (k & (1 << l)) {
        a += as[l];
        b += bs[l];
        c += cs[l];
      }
    }
    map<pair<int, int>, int>::iterator it = m.find(pair<int, int>(a, b));
    if (it != m.end()) {
      it->second = min(c, it->second);
    } else {
      m[pair<int, int>(a, b)] = c;
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, Ma, Mb, as[MAX_N], bs[MAX_N], cs[MAX_N];
  scanf("%d %d %d", &N, &Ma, &Mb);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &as[i], &bs[i], &cs[i]);
  }

  // create list of (amount a, amount b) -> cost
  // that can be created by using the first 20 elements
  // and the rest
  const int N1 = N / 2, N2 = N - N1;
  map<pair<int, int>, int> m1, m2;
  create_list(m1, as, bs, cs, N1);
  create_list(m2, as + N1, bs + N1, cs + N1, N2);

  // iterate one of the lists and find its match in the other
  int ans = 1 << 30;
  for (map<pair<int, int>, int>::iterator it = m1.begin(), e = m1.end();
       it != e; ++it) {
    const int a = it->first.first, b = it->first.second, c = it->second;
    for (int i = 1; i <= N; i++) {
      // try to achieve (Ma * i, Mb * i)
      const int a2 = Ma * i - a, b2 = Mb * i - b;
      map<pair<int, int>, int>::iterator it2 = m2.find(pair<int, int>(a2, b2));
      if (it2 != m2.end()) {
        ans = min(ans, c + it2->second);
      }
    }
  }
  if (ans < INF) {
    printf("%d\n", ans);
  } else {
    printf("-1\n");
  }

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ENDL "\n"

typedef long long int llint;

int main()
{
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<llint> A(X), B(Y), C(Z);
  for (int i = 0; i < X; i++)
  {
    cin >> A[i];
  }
  for (int i = 0; i < Y; i++)
  {
    cin >> B[i];
  }
  for (int i = 0; i < Z; i++)
  {
    cin >> C[i];
  }
  vector<llint> AB;
  for (llint a : A)
  {
    for (llint b : B)
    {
      AB.push_back(a + b);
    }
  }
  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  vector<llint> ABC;
  int counter = 0;
  for (llint ab : AB)
  {
    for (llint c : C)
    {
      ABC.push_back(ab + c);
    }
    counter++;
    if (counter == K)
    {
      break;
    }
  }
  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  for (int i = 0; i < K; i++)
  {
    cout << ABC[i] << ENDL;
  }
  return 0;
}


Measured memory_bytes: 43368
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            int x = i;
            if (i % 3 == 0) {
                System.out.print(" " + i);
                continue;
            } else {
                while (x != 0) {
                    if (x % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
                    x = x / 10;
                }
            }
        }
        System.out.println("");
    }
}



Measured memory_bytes: 28916
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, q;

struct ST {
	int st[4 * N];
	int lazy[4 * N];

	ST() {
		memset(lazy, 1, sizeof lazy);
	}

	void build(int v, int tl, int tr) {
		if (tl == tr) {
			st[v] = n;
			return;
		}
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		st[v] = n;
	}

	void push(int v) {
		st[v * 2] = min(st[v * 2], lazy[v]);
		st[v * 2 + 1] = min(st[v * 2 + 1], lazy[v]);

		lazy[v * 2] = min(lazy[v * 2], lazy[v]);
		lazy[v * 2 + 1] = min(lazy[v * 2 + 1], lazy[v]);

		lazy[v] = INT_MAX;
	}

	void update(int v, int tl, int tr, int l, int r, int val) {
		if (l > r) {
			return;
		}
		if (tl == l && tr == r) {
			st[v] = min(st[v], val);
			lazy[v] = min(lazy[v], val);
			return;
		}
		push(v);
		int tm = (tl + tr) / 2;
		update(v * 2, tl, tm, l, min(r, tm), val);
		update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
		st[v] = min(st[v * 2], st[v * 2 + 1]);
	}

	int query(int v, int tl, int tr, int idx) {
		if (tl == idx && tl == tr) {
			return st[v];
		}
		push(v);
		int tm = (tl + tr) / 2;
		if (idx <= tm) {
			return query(v * 2, tl, tm, idx);
		}
		return query(v * 2 + 1, tm + 1, tr, idx);
	}
};

ST stx, sty;

int query(ST &st1, ST &st2, int x) {
	int ns = st1.query(1, 1, n, x);
	st2.update(1, 1, n, 1, ns, x);
	return ns - 2;
}

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

	cin >> n >> q;

	stx.build(1, 1, n);
	sty.build(1, 1, n);

	long long ans = (long long) (n - 2) * (n - 2);

	int op, x;
	for (int qi = 0; qi < q; qi++) {
		cin >> op >> x;

		if (op == 1) {
			ans -= (long long) query(stx, sty, x);
		}
		else {
			ans -= (long long) query(sty, stx, x);
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 14016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	string a;
	cin>>a;
	int n=a.size();
	n--;
	if(a[n]=='s') a+="es";
	else a+="s";
	cout<<a;
	return 0;
}

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

int main()
{
	string s;
	int m = 0, n = 0;

	cin >> s;

	for (unsigned int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')
			n++;
		else {
			if (n > m)
				m = n;
			n = 0;
		}
	}

	if (n > m)
		m = n;

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
T = a[0]
A = a[1]
K = a[2]

if T >= K:
  T = T - K
elif T + A >= K:
  A = A - K + T
  T = 0
else:
  T = 0
  A = 0

print(T,end=" "),print(A)

Measured memory_bytes: 3064
import sys

s=list(input())
t=list(input())


start=[-1]*26
end=[-1]*26

for i in range(len(s)):
    a=ord(s[i])-ord('a')
    b=ord(t[i])-ord('a')
    if(start[a]!=-1 or end[b]!=-1):
        if(start[a]!=b or end[b]!=a):
            print("No")
            sys.exit()
    start[a]=b
    end[b]=a
print("Yes")

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

int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  vector<long long> X(N);
  for (int i=0;i<N;i++){
    cin >> X[i];
  }
  long long ans=0;
  for (int i=0;i<N-1;i++){
    if (A*(X[i+1]-X[i])<B){
      ans+=A*(X[i+1]-X[i]);
    }
    else {
      ans+=B;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import deque

H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]

def bfs(i, j):
    b, w = 0, 0
    visited[i][j] = True
    que = deque([(i, j)])

    while que:
        ci, cj = que.popleft()
        if S[ci][cj] == '#':
            b += 1
        else:
            w += 1

        for di, dj in move:
            ni, nj = ci + di, cj + dj
            if not (0 <= ni < H and 0 <= nj < W) or visited[ni][nj]:
                continue
            if S[ci][cj] != S[ni][nj]:
                visited[ni][nj] = True
                que.append((ni, nj))

    return b * w


result = 0
for i in range(H):
    for j in range(W):
        if visited[i][j]:
            continue
        result += bfs(i, j)
print(result)


Measured memory_bytes: 48604
n,k,q = gets.split.map(&:to_i)

a = Array.new(n, k-q)

q.times { a[gets.chomp.to_i - 1] += 1 } 

a.each { |e|
    if e > 0
        puts "Yes"
    else
        puts "No"
    end
} 

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

using namespace std;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int turn = 1;
	while(true) {
		if(turn) {
			c -= b;
			if(c <= 0) {
				cout << "Yes\n";
				break;
			}
		}
		else {
			a -= d;
			if(a <= 0) {
				cout << "No\n";
				break;
			}
		}
		turn = 1 - turn;
	}
	
	return 0;
}

Measured memory_bytes: 3652