akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

using namespace std;

int main() {
    
    int d,n;
    
    cin >> d >> n;
    
    int ans=0;
    ans = pow(100, d);
    
    ans = ans * n;
    
    if(d==0){
        if(n==100){
            ans += 1;
        }
    }else if(d==1){
        if(n==100){
            ans += 100;
        }
    }else{
        if(n==100){
            ans += 10000;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		StringBuilder s = new StringBuilder();
		String o = sc.next(), e = sc.next();
		for (int i=0; i<e.length(); i++) s.append(o.charAt(i)).append(e.charAt(i));
		if (o.length()-e.length()==1) s.append(o.charAt(o.length()-1));
		System.out.println(s);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35440
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <string>
#include <cmath>

using namespace std;

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

    int64_t ans = 0;
    for(size_t i = 0; i < N.size(); ++i){
        ans += int(N[i] - '0');
    }
    int64_t sum = int(N[0] - '1');
    sum += 9 * (N.size() - 1);

    cout << max(sum, ans) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        //int x = sc.nextInt();
        //int a = sc.nextInt();
        
        if (x < a) {
        	System.out.println("0");
        } else {
        	System.out.println("10");
        }       
    }
}

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

int main() {
  int W, H, N, x, y, a;
  scanf("%d %d %d", &W, &H, &N);
  int x1 = 0;
  int x2 = W;
  int y1 = 0;
  int y2 = H;
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &x, &y, &a);
    if (a == 1) x1 = max(x1,x);
    else if (a == 2) x2 = min(x2,x);
    else if (a == 3) y1 = max(y1,y);
    else if (a == 4) y2 = min(y2,y);
    if(x2<=x1 || y2<=y1) {
      printf("%d\n",0);
      return 0;
    }
  }
  printf("%d\n",(x2-x1)*(y2-y1));
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/22/20 21:00:03
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int a,b,c; cin>>a>>b>>c;
  auto solve = [&]() {
    int s = a%b;
    while (s != c) {
      s=(s+a)%b;
      if (s == a%b)
        return false;
    }
    return true;
  };
  cout << (solve() ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)    

func main(){
    nums := make([]int, 3)
    fmt.Scanf("%d %d %d", &nums[0], &nums[1], &nums[2])
    
    sort.Ints(nums)
    fmt.Println(10*nums[2] + nums[1] + nums[0])
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    vector<int> p(n);
        rep(i,n) cin>>p.at(i);
    sort(all(p));
    rep(i,1000){
        int y=x-i;
        if(*lower_bound(all(p),y)!=y){
            cout<<y<<endl;
            return 0;
        }
        y=x+i;
        if(*lower_bound(all(p),y)!=y){
            cout<<y<<endl;
            return 0;
        }
    }
}/*
./problem.exe
*/

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}

int main(void) {
  int n;
  cin >> n;
  ll cnt = 0;
  int a;
  for (int c = 1; c < n; ++c) {
    for (a = 1; a * a < n - c; ++a) {
      if ((n - c) % a == 0) cnt += 2;
      // if ((n - c) == a * a) cnt--;
    }
    if ((n - c) == a * a) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    string s;cin>>s;
    ll n;n=s.size();
    ll dp[n+1][4];
    rep(j,0,2)dp[0][j]=0;
    dp[0][3]=1;
    rep(i,1,n){
        if(s[i-1]=='A'){
            dp[i][0]=dp[i-1][0]+dp[i-1][3];
            dp[i][1]=dp[i-1][1];
            dp[i][2]=dp[i-1][2];
            dp[i][3]=dp[i-1][3];
        }else if(s[i-1]=='B'){
            dp[i][0]=dp[i-1][0];
            dp[i][1]=(dp[i-1][1]+dp[i-1][0])%i_7;
            dp[i][2]=dp[i-1][2];
            dp[i][3]=dp[i-1][3];
        }else if(s[i-1]=='C'){
            dp[i][0]=dp[i-1][0];
            dp[i][1]=dp[i-1][1];
            dp[i][2]=(dp[i-1][2]+dp[i-1][1])%i_7;
            dp[i][3]=dp[i-1][3];
        }else if(s[i-1]=='?'){
            dp[i][0]=(dp[i-1][0]*3+dp[i-1][3])%i_7;
            dp[i][1]=(dp[i-1][1]*3+dp[i-1][0])%i_7;
            dp[i][2]=(dp[i-1][2]*3+dp[i-1][1])%i_7;
            dp[i][3]=(dp[i-1][3]*3)%i_7;
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,3){
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }*/
    
    cout<<dp[n][2]%i_7<<endl;
    return 0;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll n, cnt=0;
    string s,t;
    cin>>n>>s>>t;
    rep(i,n+1){
        if(s.substr(n-i) == t.substr(0,i)) cnt=i;
    }
    cout<<2*n-cnt<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = (1LL<<31)-1;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,ll)> P;
  ll n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(ll n_,F f,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>(),P p=[](E a,ll b){return a;}):
    f(f),g(g),h(h),d1(d1),d0(d0),p(p){
    init(n_);
    if(n_==(ll)v.size()) build(n_,v);
  }
  void init(ll n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(ll n_, vector<T> v){
    for(ll i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(ll i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(ll len,ll k){
    if(laz[k]==d0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=d0;
  }
  T update(ll a,ll b,E x,ll k,ll l,ll r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(ll a,ll b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(ll a,ll b,ll k,ll l,ll r){
    eval(r-l,k);
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(ll a,ll b){
    return query(a,b,0,0,n);
  }
};
    auto F = [](ll a, ll b){return min(a,b);};
    auto G = [](ll a, ll b){return b==INF?a:b;};
    auto H = G;
    auto P = [](ll a, ll b){return a;};
    SegmentTree<ll,ll> seg(MAX_N, F, G, H, INF, INF,vl(MAX_N,INF));
int main() { cin >> n >> q; 
while(q--){
    cin >> x;
    if(x==0){
        cin >> a >> b >> c;
        seg.update(a, b + 1, c);
    }
    else{
        cin >> a;
        cout << seg.query(a, a + 1)<<endl;
    }
}}




Measured memory_bytes: 27024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		ArrayList<int[]> arrayList = new ArrayList<int[]>();
		
		while (in.hasNextLine())
		{
			int lineNumber = in.nextInt();
			int[] array = new int[lineNumber];
			in.nextLine();
			
			int i = 0;
			
			while (i < lineNumber && in.hasNextInt())
			{
				array[i] = in.nextInt();
				i++;
			}
			
			arrayList.add(array);
			
			if (in.hasNextLine())
			{
				in.nextLine();
			}
		}
		
		int[] qArray = arrayList.get(1);
		int[] sArray = arrayList.get(0);
		int count = 0;
		
		for (int i = 0; i < qArray.length; i++)
		{
			boolean found = false;
			int j = 0;
			while (!found && j < sArray.length)
			{
				if (sArray[j] == qArray[i])
				{
					count++;
					found = true;
				}
				j++;
			}
		}
		
		System.out.println(count);
		
	}

}


Measured memory_bytes: 41752
#include <iostream>
#include <algorithm>
#include <cmath>

int calcCost(int x[], int size, int p) {
    int cost = 0;
    for(int i = 0; i < size; i++) {
        cost += std::pow(x[i] - p, 2);
    }
    return cost;
}

int getMinCost(int x[], int size) {
    int minCost = 0;

    std::sort(x, x + size);

    int minP = x[0];
    int maxP = x[size-1];

    for(int i = minP; i <= maxP; i++) {
        int cost = calcCost(x, size, i);

        if(minCost == 0) {
            minCost = cost;
            continue;
        }

        if(cost < minCost) {
            minCost = cost;
            continue;
        }

        break;
    }

    return minCost;
}

int main(int argc, const char * argv[]) {
    int N(0);
    std::cin >> N;

    int x[N];
    for(int i=0; i<N; i++) {
        std::cin >> x[i];
    }

    int minCost = getMinCost(x, N);

    std::cout << minCost;

  return 0;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string a, b;
  cin >> a >> b;
  int ab = stoi(a + b);
  bool ok = false;
  rep(i, 320) {
    if (i * i == ab) {
      ok = true;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif




int main(){
	int h,w;
	while(cin>>h>>w){
		if(h==0 && w==0)break;
		int a=9999,b=9999;

		for(int i=1;i<=150;i++){
			for(int j=i+1;j<=150;j++){
				if(h*h+w*w<i*i+j*j || (h*h+w*w==i*i+j*j && h<i )){
					if(i*i+j*j<a*a+b*b || ( i*i+j*j==a*a+b*b && i<a )){
						a=i;b=j;
					}
				}
			}
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
a,b=map(int,input().split())
L=list()
s=0
for i in range(a):
  x,y=map(int,input().split())
  L.append([x,y])
L=sorted(L)
for i in range(a):
  s+=L[i][1]
  if s>=b:
    print(L[i][0])
    break

Measured memory_bytes: 89904
#include <stdio.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int A,B,C;
  int maximam,minimam,middle;
  scanf("%d%d%d",&A,&B,&C);

  maximam = max(max(A,B),C);
  minimam = min(min(A,B),C);
  middle = A+B+C-maximam-minimam;

  int ans = maximam-middle;
  middle += ans; minimam += ans;

  if((maximam-minimam)%2 == 0){
    ans += (maximam-minimam)/2;
  }else{
    ans += (maximam-minimam)/2+2;
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<queue>
using namespace std;
int mt,my,mn,X,Y,T;
int field[9][1010][1010] = {0};
int dx[] = {-1,0,1,0},dy[] = {0,-1,0,1};
int mouse(int i,int x,int y,int time)
{//printf("%d %d %d\n",x,y,time);
    queue<int> QX,QY,QT;
    QX.push(x);QY.push(y);QT.push(time);
    field[i][x][y] = i + 2;
    while(QX.size())
    {
        /*for(int l = 0; l < 10; l++)
        {
            for(int j = 0; j < 10; j++)
            {
                printf("%3d",field[i][j][l]);
            }
            printf("\n");
        }printf("\n");*/
        for(int j = 0; j < 4; j++)
        {
            if(0 > QX.front() + dx[j] || QX.front() + dx[j] >= my || 0 > QY.front() + dy[j] || QY.front() + dy[j] >= mt);
            else if(field[i][QX.front() + dx[j]][QY.front() + dy[j]] == i + 1)
            {
                X = QX.front() + dx[j];Y = QY.front() + dy[j];T = QT.front() + 1;
                return 0;
            }
            else if(field[i][QX.front() + dx[j]][QY.front() + dy[j]] == 0)
            {
                QX.push(QX.front() + dx[j]);QY.push(QY.front() + dy[j]);QT.push(QT.front() + 1);
                field[i][QX.front() + dx[j]][QY.front() + dy[j]] = i + 2;
            }
        }
        QX.pop();QY.pop();QT.pop();
    }
}
int main()
{
    char cha;
    scanf("%d%d%d",&mt,&my,&mn);
    scanf("%c",&cha);
    for(int i = 0; i < mt; i++)
    {
        for(int j = 0; j < my + 1; j++)
        {
            scanf("%c",&cha);
            if(cha == 'S')
            {
                X = j;Y = i;T = 0;
            }
            else if(cha == 'X')
            {
                for(int k = 0; k < 9; k++)
                {
                    field[k][j][i] = -1;
                }
            }
            else if('0' <= cha && cha <= '9')
            {
                field[cha - '0' - 1][j][i] = cha - '0';
            }
        }
    }//ok
    /*for(int k = 0; k < 9; k++)
    {
        for(int i = 0; i < t; i++)
        {
            for(int j = 0; j < y; j++)
            {
                printf("%3d",field[k][j][i]);
            }
            printf("\n");
        }
        printf("\n");
    }*/
    for(int i = 0; i < mn; i++)
    {
        mouse(i,X,Y,T);
    }
    printf("%d\n",T);
    return 0;
}

Measured memory_bytes: 38312
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int b[n-1];
  for(int i=0;i<n-1;i++)
    cin>>b[i];
  int sum=b[0];
  for(int i=1;i<n-1;i++)
  {
    if(b[i]>b[i-1])
      sum+=b[i-1];
    else
      sum+=b[i];
  }
  sum+=b[n-2];
  cout<<sum;
  return 0;
}
  

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,a,b; cin>>n>>a>>b;
  if((a+b)%2==0){
    cout<<abs(a-b)/2<<endl;
  }else{
    if(a>b) swap(a,b);
    ll ans=min((n-b+1)+(b-a)/2, (a)+(b-a)/2);
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 3648
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())
ans = 1
for i in range(N):
    t = int(input())
    ans = lcm(ans, t)
print(ans)


Measured memory_bytes: 62416
n=int(input())
li=[list(map(int,input().split())) for k in range(n)]
ans=0
for i in range(0,n-1):
    for j in range(1,n-i):
        ans+=((li[i][0]-li[i+j][0])**2+(li[i][1]-li[i+j][1])**2)**0.5      
print((ans*2)/n)

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int h,w;
    for(;;){
        scanf("%d %d",&h,&w);
        if(h==0 && w==0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0 || i==h-1 || j==0 || j==w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> s(N);
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		s[i] = (c == 'x');
	}
	if (N % 3 == 0) {
		string ans(N, 'S');
		for (int i = 1; i < N - 1; i++) {
			if (ans[i] == 'S' && ans[i - 1] == 'S' && s[i] == 1) ans[i + 1] = 'W';
			if (ans[i] == 'S' && ans[i - 1] == 'W' && s[i] == 0) ans[i + 1] = 'W';
			if (ans[i] == 'W' && ans[i - 1] == 'S' && s[i] == 0) ans[i + 1] = 'W';
			if (ans[i] == 'W' && ans[i - 1] == 'W' && s[i] == 1) ans[i + 1] = 'W';
		}
		bool OK = true;
		if (ans[N - 1] == 'S' && s[N - 1] == 0 && ans[N - 2] != ans[0]) OK = false;
		if (ans[N - 1] == 'S' && s[N - 1] == 1 && ans[N - 2] == ans[0]) OK = false;
		if (ans[N - 1] == 'W' && s[N - 1] == 0 && ans[N - 2] == ans[0]) OK = false;
		if (ans[N - 1] == 'W' && s[N - 1] == 1 && ans[N - 2] != ans[0]) OK = false;
		if (s[0] == 0 && ans[N - 1] == 'W') OK = false;
		if (s[0] == 1 && ans[N - 1] == 'S') OK = false;
		if (OK) cout << ans << endl;
		else cout << -1 << endl;
		return 0;
	}
	else {
		int l = (N - 1) / 3;
		vector<int> ans(N);
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < l; j++) {
				ans[i] ^= (s[(i + 3 * j) % N] ^ s[(i + 1 + 3 * j) % N]);
			}
			ans[i] ^= s[(i + 3 * l) % N];
		}
		for (int i = 2; i < N; i++) {
			if (N % 3 == 1) ans[i] = s[(i - 1 + N) % N] ^ ans[i - 1] ^ ans[i - 2];
			else ans[i] = s[(N + i - 3) % N] ^ ans[i - 1] ^ ans[i - 2];
		}
		if (N % 3 == 1) {
			for (int a : ans) cout << (a ? "W" : "S");
			cout << endl;
		}
		else {
			for (int i = 2; i < N; i++) cout << (ans[i] ? "W" : "S");
			cout << (ans[0] ? "W" : "S") << (ans[1] ? "W" : "S") << endl;
		}
	}
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int main()
{
    long long N;
    cin >> N;
    string res = "";
    while (N)
    {
        --N;
        res += (char)('a' + (N % 26));
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;

}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

vector<vector<ll>> fmr;
int ln;
const char* num;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

void addFmr(int cnt, vector<ll> f) {

	if (cnt >= ln) {
		fmr.push_back(f);
		return;
	}

	vector<ll> v = f;
	int add = ctoi(num[cnt]);
	v[v.size() - 1] = v[v.size() - 1] * 10 + add;

	f.push_back(add);

	addFmr(cnt + 1, v);
	addFmr(cnt + 1, f);

	return;

}



int main() {


	string st;
	cin >> st;

	num = st.c_str();

	ll sum,tmp;
	int  ix = 0;
	sum = tmp = 0;

	while (num[ln] != '\0')
	{
		ln++;
	}


	vector<ll> f;
	f.push_back(ctoi(num[0]));
	addFmr(1, f);

	for (int i = 0;i < fmr.size();i++) {
		vector<ll> sp = fmr[i];
		tmp = 0;
		for (int k = 0; k < sp.size(); k++)
		{
			tmp += sp[k];
		}
		sum += tmp;
	}

	cout << sum << endl;
	return 0;
}



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

int main(){
  int N;
  int d[110];
  cin >> N;
  for(int i=0;i<N;i++) cin >> d[i];
  
  set<int> values;
  for(int i=0;i<N;i++){
    values.insert(d[i]);
  }
  
  cout <<values.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main() {
    int n, k;
    cin >> n >> k;
    int res = 1;
    for(int i=0; i<n; ++i) {
        if(res*2 < res+k) res *= 2;
        else res = res + k;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int main(){
  int h=0,i;
  int len;
  for(;;){
    string s;
    cin>>s;
    if(s.empty())
      break;
    len=s.length();
    if(h)
      cout<<endl;
    h=1;
    for(i=0;i<5-len;i++)
      cout<<"*";
    for(i=0;i<len;i++){
      if((s[i]-'0')/5)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
    for(i=0;i<5-len;i++)
      cout<<" ";
    for(i=0;i<len;i++){
      if((s[i]-'0')/5)
	cout<<"*";
      else
	cout<<" ";
    }
    cout<<endl<<"====="<<endl;
    for(i=0;i<5-len;i++)
      cout<<" ";
    for(i=0;i<len;i++){
      if((s[i]-'0')%5==0)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
    for(i=0;i<5-len;i++)
      cout<<"*";
    for(i=0;i<len;i++){
      if((s[i]-'0')%5==1)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
    for(i=0;i<5-len;i++)
      cout<<"*";
    for(i=0;i<len;i++){
      if((s[i]-'0')%5==2)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
    for(i=0;i<5-len;i++)
      cout<<"*";
    for(i=0;i<len;i++){
      if((s[i]-'0')%5==3)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
    for(i=0;i<5-len;i++)
      cout<<"*";
    for(i=0;i<len;i++){
      if((s[i]-'0')%5==4)
	cout<<" ";
      else
	cout<<"*";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N, M, X, Y = map(int, input().split())
L_X = [int(i) for i in input().split()]
L_Y = [int(i) for i in input().split()]

if max(L_X) < min(L_Y) and X < min(L_Y) and max(L_X) < Y:
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
n,m = map(int, input().split())
lst = []
for i in range(m):
    s,c = map(int, input().split())
    lst.append((s-1,c))

if n!=1:
    for i in lst:
        if i==(0,0):
            print(-1)
            exit()

# print(lst)
if n==1:
    for i in range(10):
        I = str(i)
        flag = 0
        for j in lst:
            if I[j[0]]!=str(j[1]):
                flag = 1
        if flag == 0:
            print(I)
            exit()
else:
    for i in range(10**(n-1),10**n):
        I = str(i)
        # print(I)
        flag = 0
        for j in lst:
            if I[j[0]]!=str(j[1]):
                flag = 1
        if flag == 0:
            print(I)
            exit()

print(-1)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC158
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            long[] nab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = nab[0], a = nab[1], b = nab[2];
            long sum = 0;
            long n1 = n / (a + b);
            long n2 = n % (a + b);
            sum += n1 * a + Math.Min(n2, a);
            Console.WriteLine(sum);
        }

    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int N, x;
int P[1000000 + 100];
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d%d", &N, &x);
	if (N == x && N == 1)
	{
		cout<<"Yes"<<endl;
		cout<<1<<endl;
		return 0;
	}
	if (x >= 2 * N - 1 || x <= 1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	int l = x - 2, r = x + 2, flag = 0; 
	if (x == 2)
	{
		l = 1, r = 5;
		flag = 1;
		if (2 * N - 1 < 5)
		{
			if (x == 2)
			{
				cout<<"Yes"<<endl;
				printf("1\n2\n3\n");
			}
			else
				cout<<"No"<<endl;
			return 0;
		}
	}
	if (x == 2 * N - 2)
	{
		l = 2 * N -	5, r = 2 * N - 1;
		flag = 2;
		if (l < 1)
		{
			if (x == 2)
			{
				cout<<"Yes"<<endl;
				printf("1\n2\n3\n");
			}
			else
				cout<<"No"<<endl;

			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for (int i = 1, Cnt = 1; i <= 2 * N - 1, Cnt <= (N - 3); ++i)
		if (i >= l && i <= r) continue;
		else cout<<i<<endl, P[i] = 1, ++Cnt;
	if (flag == 1)
		printf("5\n1\n2\n3\n4\n");
	else if (flag == 2)
	{
		int m = 2 * N - 1;
		printf("%d\n%d\n%d\n%d\n%d\n", m - 3, m, m - 1, m - 2, m - 4);
	}
	else 
		cout<<x + 2<<endl<<x - 1<<endl<<x<<endl<<x + 1<<endl<<x - 2<<endl;
	//cout<<r<<endl<<l + 1<<endl<<l + 2<<endl<<r - 1<<endl<<l<<endl;
	for (int i = 1, Cnt = 1; i <= 2 * N - 1, Cnt <= (N - 3); ++i)
		if ((i >= l && i <= r) || P[i]) continue;
		else cout<<i<<endl, ++Cnt;
	return 0;
}

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

int main() {
    int X, Y;

    cin >> X >> Y;

    if ((Y >= 2 * X) && (Y <= 4 * X)) {
        if (Y % 2 == 0) {
            cout << "Yes";
        } else {
            cout << "No";
        }
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3636
# coding: utf-8
# Here your code !

import math

def func():
    try:
        line = input().rstrip()
        numbers = line.split(" ")
        for i,item in enumerate(numbers):
            numbers[i]=int(item)
    except:
        print("input error")
        return -1
        
    a=numbers[0]
    b=numbers[1]
    
    print(str(a//b)+" "+str(a%b)+" "+"{0:f}".format(a/b))

func()
    

Measured memory_bytes: 7756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int maxn=5e4+10;
ll gcd(ll a, ll b){return (b==0)?a:gcd(b, a%b);}
bool isPrime(int n) {
    if(n<=3){
        return n>1;
    }
    if(n%6!=1&&n%6!=5){
        return false;
    }
    int sqr=sqrt(n);
    for(int i=5;i<=sqr;i+=6){
        if(n%i==0||n%(i+2)==0){
            return false;
        }
    }
    return true;
}
int dis[4][2]={0,1,0,-1,1,0,-1,0};
char s[20];
int n;
void fun(int num,int sum)
{
	if(sum==n)
	{
		for(int i=0;i<n;i++)
	    cout<<s[i];
	    cout<<endl;
	    return ;
	}
	if(num==1)
	{
		s[sum]='a';
		fun(1,sum+1);
		s[sum]='b';
		fun(2,sum+1);
	}
	else
	{
		int vis[26];memset(vis,0,sizeof(vis));
		for(int i=0;i<sum;i++)
		vis[s[i]-'a']++;
		int ans=0;
		for(int i=0;i<26;i++)
		if(vis[i])
		ans++;
		for(int i=0;i<=ans;i++)
		{
			s[sum]='a'+i;
			fun(2,sum+1);
		}/*
		int flag=1;
		
		for(int i=0;i<sum;i++)
		{
			if(s[i]!='a'+i)
			flag=0;
		}
		if(flag)
		{
			s[sum]='a'+sum;
			fun(2,sum+1);
		}*/
	}
}
int main()
{
	cin>>n;
	memset(s,0,sizeof(s));
	s[0]='a';
	fun(1,1);
} 

Measured memory_bytes: 1536
import java.util.*;
import java.util.Arrays;


public class Main{
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    int [] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    
    int i=0;
    while(x>0&&i<N){
      x-=a[i];
      i++;
    }
    if(x!=0){
      i--;
    }
    System.out.println(i);
    
    
  }
}
                          
                         
                    
    
    
    
    
    
    


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

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

    vp v;
    rep(i,n){
        P p;
        cin >> p.first >> p.second;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    int count = 0;

    int ans = 0;
    priority_queue<int> que;
    srep(i,1,m+1){
        while(count<n){
            if(v[count].first<=i){
                que.push(v[count].second);
                count++;
            }else{
                break;
            }
        }
        if(que.size()>0){
            ans += que.top();
            que.pop();
        }
    }

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


Measured memory_bytes: 2036
#include <iostream>
using namespace std;
int main(void)
{
  int value[9];
  int money;

  while(1) {
    cin >> money;
    if(money == 0) break;
    for(int i = 0 ; i < 9 ; i++) {
      cin >> value[i];
      money -= value[i];
    }
    cout << money << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n];
  int i=0;
  int ans=0;

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

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

  for (i=0;i<n-1;i++){
    cin >> c[i];
  }

  for(i=0;i<n;i++){
      ans+=b[a[i]];
      if(i>0 && a[i]==a[i-1]+1){
        ans+=c[a[i-1]];
      }
  }
  

  
  cout << ans << endl;

  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, k, ans;

int main() {
	cin >> n >> k;
	ans = k;
	rep(i,n-1) ans *= k-1;
	cout << ans << ln;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<double,double> pdd;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,k,q;

vector<vl> C(123, vl());
vector<vl> CW(123, vl());

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> k;
    vector<bool> K;
    a = k;
    for(int c1 = 0; c1 < 20; c1++){
        K.push_back(a%2);
        a/=2;
    }
    while(K[sz(K)-1] == 0){
        K.pop_back();
    }
    reverse(all(K));
    n = 1;
    m = 0;
    ll k2 = 0;
    /*
    C[0].push_back(1);
    C[0].push_back(1);
    CW[0].push_back(0);
    CW[0].push_back(1);
    k2 = 2;
    m = 2;
    */
    k2 = 1;
    for(int c1 = 1; c1 < sz(K); c1++){
        C[c1-1].push_back(c1);
        C[c1-1].push_back(c1);
        CW[c1-1].push_back(0);
        CW[c1-1].push_back(k2);
        if(K[c1] == 1){
            C[0].push_back(c1);
            CW[0].push_back(2*k2);
        }
        k2 *= 2;
        k2 += K[c1];
        m += 2+K[c1];
    }

    cout << sz(K) << " " << m << "\n";
    for(int c1 = 0; c1 < sz(K)+1; c1++){
        for(int c2 = 0; c2 < sz(C[c1]); c2++){
            cout << c1+1 << " " << C[c1][c2]+1 << " " << CW[c1][c2] << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int X,A,B;
int XA,XB;
scanf("%d %d %d", &X, &A, &B);
XA = A - X;
XB = B - X;
XA < 0 ? XA = XA* -1 : XA = XA * 1;
XB < 0 ? XB = XB* -1 : XB = XB * 1;
XA < XB ? printf("A\n") : printf("B\n");
return 0;
}


Measured memory_bytes: 1644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String s = sc.next();
		int total = n;
		
		if(n == 1) {
			System.out.println(1);
			return;
		}
		
		for(int i = 0; i <= n - 3; i++) {
			if(s.substring(i, i+1).equals(s.substring(i+1, i+2))){
				total--;
			}
		}
		
		if(s.substring(n-2, n-1).equals(s.substring(n-1))){
			total--;
		}
		
		System.out.println(total);
		

	}
}


Measured memory_bytes: 34044
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef pair<double, pdd> pddd;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
    int n;
    scanf("%d", &n);
    int r = 0;
    for(int a = 1; a <= n; a+=2) {
        int b = 0;
        for(int i = 1; i <= a; i++) {
            if(a%i==0) b++;
        }
        if(b == 8) {
            r++;
        }
    }
    printf("%d\n", r);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

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

int main () {
    int n;
    cin >> n;
    vector<ll> count(1000000);
    vector<ll> ball(n);
    ll a;
    rep(i,n){
        cin >> a;
        ball[i] = a;
        count[a]++;
    }
    ll total = 0;
    for (const ll& v: count) {
        total += v*(v-1)/2;
    }
    rep(k,n) {
        cout << total - (count[ball[k]] - 1) << endl;   
    }
    return 0;
}

Measured memory_bytes: 11904
n = int(input())
leaves = list(map(int, input().split()))
rest_leaves = [0 for i in range(n+2)]
for i in range(n, -1, -1):
	rest_leaves[i] = rest_leaves[i+1] + leaves[i]
# print("rest_leaves", rest_leaves)


def solve():
	nodes = 0
	current_active = 1
	for i in range(n+1):
		# print("i", i)
		current_active -= leaves[i]
		if current_active < 0:
			print(-1)
			return
		current_active = min(rest_leaves[i+1], current_active)
		if i == n:
			current_active = 0
		# print("current_active", current_active)
		nodes += current_active + leaves[i]
		current_active *= 2
	print(nodes)
	return


solve()



Measured memory_bytes: 85424
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int countL = 0;
    int countR = 0;
    String str = sc.next();
    for(int i = 0; i<n; i++){
      char ch = str.charAt(i);
      if(ch == '('){
        countL++;
      }else{
        if(countL > 0){
          countL--;
        }else{
          countR++;
        }
      }
    }
    for(int i = 0; i<countR; i++){
      System.out.print('(');
    }
    System.out.print(str);
    for(int i = 0; i<countL; i++){
      System.out.print(')');
    }
    System.out.println();
  }
}


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

using namespace std;
char a,b;
int main()
{
    cin>>a>>b;
    if(a=='H') cout<<b;
    if(a=='D')
    {
    	if(b=='H') cout<<"D";
    	else cout<<"H";
	}
    cout<<endl;
    
    return 0;	
}

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

int main(){
	int n,m;
	cin>>n>>m;
	vector<string>a(n),b(m),t(m);
	for(int i=0;i<n;++i)cin>>a.at(i);
	for(int i=0;i<m;++i)cin>>b.at(i);
	bool yes=false;
	for(int i=0;i<=n-m;++i){
		for(int j=0;j<=n-m;++j){
			for(int k=0;k<m;++k){
				t.at(k)=a.at(i+k).substr(j,m);
			}
			if(b==t)yes=true;
		}
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}


Measured memory_bytes: 256
n, t, s = gets.split.map &:to_i
items = $<.map{|s| s.split.map &:to_i}

table1 = [ Array.new(s+1, 0) ]
for k in 1..items.size
	table1 << [0] * (s+1)
	v, c = items[k-1]
	for i in 0..s
		table1[k][i] = table1[k-1][i]
		if i >= c
			x = table1[k-1][i-c] + v
			table1[k][i] = x if x > table1[k][i]
		end
	end
end

max = table1[-1][s]

table2 = (0..1).map{ Array.new(t-s+1, 0) }
k.times {|j|
	v, c = items.pop
	for i in 0..t-s
		table2[1][i] = table2[0][i]
		if i >= c
			x = table2[0][i-c] + v
			table2[1][i] = x if x > table2[1][i]
		end
	end
	table1.pop
	sum = table1[-1][s] + table2[1][t-s]
	max = sum if sum > max
	table2 << table2.shift
}

p max

Measured memory_bytes: 74996
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <limits>
#include <cstdlib>
using namespace std;

double inf = numeric_limits<double>::infinity();

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<vector<double>> d = vector<vector<double>>(n, vector<double>(n, inf));
    
    vector<int> v;
    for (int i = 0; i < r; i++) {
        int l;
        cin >>  l;
        v.push_back(l - 1);
    }
    
    sort(v.begin(), v.end());
    
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }
    
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    
    long min_dist = 1e9;
    do {
        long dist = 0;
        for (int i = 0; i < v.size() - 1; i++) {
            dist += d[v[i]][v[i + 1]];
        }
        min_dist = min(min_dist, dist);
    } while (next_permutation(v.begin(), v.end()));
    
    
    cout << min_dist << endl;
}


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

int main() {
  int n,k,c,ans=0;
  cin>>n>>k;
  int a=1-k;
  if(a<1) c=1;
  else if(a>n) c=n;
  else c=a;
  for(int i=0;i<n;i++){
    ans+=(i+k);
  }
  ans-=(k+c-1);
  cout<<ans<<endl;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

ll a[100010][3];
ll dp[100010][3];

int main() {

    ll n;
    cin >> n;

    REP(i, n + 1) {
        if (i == 0) continue;
        REP(j, 3) {
            cin >> a[i][j];
        }
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    REP(current_day, n + 1) {
        if (current_day == 0) continue;
        REP(before_action, 3) {
            REP(current_action, 3) {
                if (before_action == current_action) continue;
                dp[current_day][current_action] = max(dp[current_day][current_action],
                                                      dp[current_day - 1][before_action] +
                                                      a[current_day][current_action]);
            }
        }
    }

    MSG(max(max(dp[n][0], dp[n][1]), dp[n][2]))
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;

  for (int i = 0; i < s.size(); i++){
    if(s.at(i) == t.at(i)) cnt++;
  }
  
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  ll i,j,cnt=0;
  ll n;
  cin>>n;
  string s;
  cin>>s;
  for(i=0;i<n-2;i++){
      if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
          cnt++;
      }
  }
  cout<<cnt<<endl;
}

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

int main(){
    int n,a[4];
    
    cin>>n;
    
    for(int i=0;i<4;i++){
        a[i]=n%10;
        n/=10;
    }
    
    if(a[0]==a[1]&&a[1]==a[2])
        cout<<"Yes"<<endl;
    else if(a[1]==a[2]&&a[2]==a[3])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    int c = scanner.nextInt();
		    
		    if( a == 5 && b == 5 && c == 7 )
		    {
		    	System.out.println("YES");
		    }
		    else if(a == 5 && b == 7 && c == 5)
		    {
		    	System.out.println("YES");
		    }
		    else if(a == 7 && b == 5 && c == 5)
		    {
		    	System.out.println("YES");
		    }
		    else 
		    {
		    	System.out.println("NO");
		    }
		    scanner.close(); }
		  }

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

using namespace std;

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

int main(){
int n, x; cin >> n >> x;
int res = -1;
for(int i = 0; i<n; ++i){
int a; cin >> a;
if(!i) res = abs(x-a);
else res = gcd(res, abs(x-a));
}
cout << res;
return 0;
}

Measured memory_bytes: 256
<?php
# 整数の入力
//fscanf(STDIN, "%d", $a);
# スペース区切りの整数の入力
fscanf(STDIN, "%s %s %s", $a, $b, $c);
# 文字列の入力
//fscanf(STDIN, "%s", $s);

if ($a{(strlen($a)-1)} != $b{0}){
    exit('NO');
}

if ($b{(strlen($b)-1)} != $c{0}){
    exit('NO');
}
exit('YES');
//echo $a{0} . $b{} . $c;

# 出力
// echo ($a+$b+$c)." ".$s."\n";


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    for (size_t i = 1; i < s.size() - 1; i++) {
        // even length strings
        int length = (s.size() - i);
        bool is_ans = true;
        if (length % 2 == 0) {
            for (size_t i = 0; i < length / 2; i++) {
                if (s.at(i) != s.at(i + length / 2)) {
                    is_ans = false;
                }
            }
            if (is_ans) {
                cout << length;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3580