akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    VAR(int, N);
    vector<int> a(N);
    unordered_map<int, int> cnt;

    rep(i, 0, N) {
        read(a[i]);
        cnt[a[i]] += 1;
    }

    int ans = 0;
    for (i64 P = (1LL << 40); P >= 1; P >>= 1) {
        for (const i64 x : a) {
            const i64 y = P - x;
            const i64 xnum = cnt[x];
            const i64 ynum = (cnt.count(y) ? cnt[y] : 0);
            if (x == y) {
                if (xnum >= 2) {
                    ++ans;
                    cnt[x] -= 2;
                }
            } else {
                if (xnum >= 1 && ynum >= 1) {
                    ++ans;
                    cnt[x] -= 1;
                    cnt[y] -= 1;
                }
            }
        }
    }

    print(ans);

    return 0;
}


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

int main(){
    string S,left,right;
    ll Q;
    cin >> S;
    scanf("%lld",&Q);
    ll state = 1;

    rep(i,Q){
        ll T;
        scanf("%lld",&T);
        if(T == 1){
            state = state * (-1);
        }
        else{
            ll F;
            char C;
            scanf("%lld %c",&F,&C);
            if(F==2){
                F = -1;
            }
            ll put = state * F;
            if(put==1){
                left = left + C;
            }
            else{
                right = right + C;
            }
            // cout << left << S << right << endl;
        }
    }

    if(state==-1){
        // reverse(all(left));
        reverse(all(right));
        reverse(all(S));
        cout << right << S << left; 
    }
    else{
        reverse(all(left));
        cout << left << S << right;
    }

}

Measured memory_bytes: 1456
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#include <math.h>

int main() {

	int K,len;
	string S,ans;
	cin >> K >> S;

	len = S.length();

	if (len <= K) {
		ans = S;
	}
	else {
		ans = S.substr(0, K) + "...";
	}


	cout << ans;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
#include<map>
using namespace std;

int main(){
    int X,Y,Z;
    cin >> X >> Y >> Z ;
    int cor = X/(Y+Z);
    if(X%(Y+Z) < Z)cor -=1;
    cout << cor << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[1000005];
char s[1000005];
ll b[1000005];
int main()
{
	ll n;
	scanf("%lld",&n);
	scanf(" %s",s);
	bool one=0;
	for(ll i=0;i<n;i++)
	{
		a[i]=s[i]-'1';
		if(a[i]==1) one=true;
	}
	if(!one)
	{
		for(ll i=0;i<n;i++) a[i]/=2;
	}
	else
	{
		for(ll i=0;i<n;i++) a[i]%=2;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		if(((n-1)&i)==i)
		{
			ans^=a[i];
		}
	}
	if(!one)
	{
		ans*=2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 10752
#include<stdio.h>
#include<stdlib.h>
int fun(char *);
int fun(char *s)
{
    int px1=0,px2=0,py1=0,py2=0;
    while(*s)
    {
        if(*s=='E')
        {
            px1++;
        }
        if(*s=='W')
        {
            px2++;
        }
        if(*s=='N')
        {
            py1++;
        }
        if(*s=='S')
        {
            py2++;
        }
        s++;
    }
    if((px1>0&&px2==0)||(px1==0&&px2>0)||(py1>0&&py2==0)||(py1==0&&py2>0))
    {
        return 0;
    }
    return 1;
}
int main()
{
    char a[1001];
    scanf("%s",a);
    printf((fun(a)==1)?"Yes\n":"No\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define FLOOR 3
#define ROOM 10
#define BUILDING 4
using namespace std;
int main(){
	int uni_map[BUILDING][FLOOR][ROOM] = {0};
	int n, b, f, r, v, i, j, k;
	cin>>n;
	for(i = 0; i < n; i++){
		cin>>b>>f>>r>>v;
		uni_map[b-1][f-1][r-1] += v;
	}
	for(i=0;i<BUILDING;i++){
		for(j=0;j<FLOOR;j++){
			for(k=0;k<ROOM;k++){
				cout << " " << uni_map[i][j][k];
			}
			cout << endl;
		}
		if(i != BUILDING - 1) cout << "####################\n";
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <climits>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>

using namespace std;

const int maxn = 301;
const int minn = -301;

int getEdge(int x1, int y1, int x2, int y2) {
    return abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2);
}

void searchPoint(int x1, int y1, int x2, int y2, int edge2, int &x3, int &y3) {
    for (int x = minn; x <= maxn; ++x) {
        for (int y = minn; y <= maxn; ++y) {
            if (getEdge(x, y, x2, y2) == edge2) {
                if ((x - x2) * (y2 - y1) - (y - y2) * (x2 - x1) == -edge2) {
                    x3 = x;
                    y3 = y;
                    break;
                }
            }
        }
    }
}

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

    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int edge2 = getEdge(x1, y1, x2, y2);
    searchPoint(x1, y1, x2, y2, edge2, x3, y3);
    searchPoint(x2, y2, x3, y3, edge2, x4, y4);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();

      int[] a;
      a = new int[n];
      for (int i = 0; i < n; i++) {
         int s = sc.nextInt();
         a[i] = s;
      }

      int[] b;
      b = new int[n];
      for (int i = 0; i < n; i++) {
         b[i] = a[i];
      }

      Arrays.sort(b);

      int med1 = b[n / 2 - 1];
      int med2 = b[n / 2];

      for (int i = 0; i < n; i++) {
         if (a[i] <= med1) {
            System.out.println(med2);
         } else {
            System.out.println(med1);
         }
      }
   }
}


Measured memory_bytes: 118512
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define LL long long
using namespace std;
int read() {
	int f = 1,x = 0;char s = getchar();
	while(s < '0' || s > '9') {if(s == '-') f = -1;s = getchar();}
	while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
	return x * f;
}
int n,m,i,j,s,o,k,d;
int main() {
	n = read();m = read();
	int ans = 0;
	for(int i = 1;i <= n;i ++) {
		for(int j = 1;j <= m;j ++) {
			int d10 = j / 10;
			int d1 = j % 10;
			if(d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
				ans ++;
			}
		}
	}
	printf("%d\n",ans);
	return 0; 
}

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

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

  uint64_t ans = 0;

  for (uint64_t i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      for (uint64_t x = i; x <= n; x *= i) {
        if (n % x == 0) {
          n /= x;
          ans++;
        }
      }
      while (n % i == 0) {
        n /= i;
      }
    }
  }

  if (n > 1) ans++;

  cout << ans << endl;
}


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

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

            var n = long.Parse(Console.ReadLine());
            var a = new int[n + 1];
            long mod = 1000000007;
            for (int i = 2; i <= n; i++)
            {
                int x = i;
                for (int j = 2; j <= n; j++)
                {
                    int k = 0;
                    if (x % j == 0)
                    {
                        for (k = 0; x % j == 0; x /= j) k++;
                    }
                    a[j] += k;
                }
            }
            long ans = 1;
            for (int i = 2; i <= n; i++)
            {
                ans *= a[i] + 1;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if((a + b) % 2 ==0) {
			System.out.println((a+b)/2);
		} else {
			System.out.println((a+b)/2 +1);
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <numeric>
#include <array>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
    uint64_t N;
    cin >> N;
    vector<int> x(10);
    vector<int> y(10);
    for (int i = 1; i <= N; i++) {
        cin >> x[i] >> y[i];
    }

    vector< vector<double> > t(10, vector<double>(10));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            t[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }
    unsigned int n = 1;
    for (int i = 1; i <= N; i++) {
        n *= i;
    }

    vector<int> v(N);
    double sum = 0;
    iota(v.begin(), v.end(), 1);
    do {
        for (int i = 0; i < N - 1; i++) {
            sum += t[v[i]][v[i+1]];
        }
    } while( next_permutation(v.begin(), v.end()) );
    cout << setprecision(20) << sum / n << endl;

    return 0;
}

Measured memory_bytes: 256
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n,k = LI()
p = LI()

def a(num):
    return (num+1)/2

l = [a(i) for i in p]
ll = [0] + list(itertools.accumulate(l))
ans=0
for i in range(n-k+1):
    ans = max(ans,ll[i+k]-ll[i])
print(ans)

Measured memory_bytes: 27212
#include<stdio.h>
int main(void){
int A, B, C;
scanf("%d%d%d",&A, &B, &C);
if((A==B && B==C && C==A)|| (A!=B && B!=C && C!=A)){
    printf("No\n");
}else{
    printf("Yes\n");
}
 return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a, b, h;
    cin>>a>>b>>h;
    cout<<((a+b)*h)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	string s;
	cin>>s;
	for(int x=0;x<s.length()-1;x++){
		if(s[x]==s[x+1]){
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";







	
	
return 0;	
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)
	//i=m -> n

int main(){
  int ans=2000;
  string s,t;
  cin >> s >> t;
  LL range = s.size() - t.size() + 1;
  
  REP(i,0,range){
    int count = 0;
    REP(j,0,t.size()){
      if(t[j] != s[j+i]){
        count++;
      }
    }
    ans = min(count,ans);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int a, b, c, x, y;
	int ans;
	cin >> a >> b >> c >> x >> y;
	if ((a + b) / 2 >= c) {
		int ans1, ans2;
		int x1;

		ans1 = 2 * min(x, y) * c;
		x1 = min(x, y);
		x -= x1;
		y -= x1;

		ans = ans1;

	}
	else {
		ans = a * x + b * y;
		x = 0;
		y = 0;
	}
	//	cout << ans << endl;

	if (a >= 2 * c) {
		ans += 2 * x * c;
	}
	else {
		ans += a * x;
	}
	if (b >= 2 * c) {
		ans += 2 * y * c;
	}
	else {
		ans += b * y;
	}
	cout << ans << endl;

}

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

int main() {
  char c[3][3];
  for (int i = 0; i < 3; i++) for (int j = 0; j< 3; j++) cin >> c[i][j];
  cout << c[0][0] << c[1][1] << c[2][2] << endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    string S;
    cin >> S;

    ll date = (S[0]-'0')*10000000 + (S[1]-'0')*1000000 + (S[2]-'0')*100000 + (S[3]-'0')*10000
              + (S[5]-'0')*1000 + (S[6]-'0')*100 + (S[8]-'0')*10 + (S[9]-'0');

    if(date <= 20190430) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}

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

int main(){
int H,W;
while(1){
    cin>>H>>W;
    if(H==0&&W==0){
        break;
    }
    for(int i=0;i<H;i++){
        for(int n=0;n<W;n++){
           cout<<"#";
       }
    cout<<endl;
    }
    cout<<endl;
}
return 0;
}



Measured memory_bytes: 3080
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

int main(){
    int N, L;
    std::cin >> N >> L;
    int sum;
    sum = N * (L - 1) + N*(N + 1)/2;
    if(1 - L > N){
        sum = sum - L - N + 1;
    }
    if(1 - L <= 0){
        sum = sum - L;
    }
    std::cout << sum << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;
bool isp(string s) {
  int n = s.size();
  bool res = true;
  for(int i=0; i<=n/2; i++) {
    if(s[i] != s[(n-1)-i]) res = false;
  }
  return res;
}
int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i<=b; i++) {
    string s = to_string(i);
    int n = s.size();
    if(isp(s)) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
using namespace std;

int main(){
  string s; cin >> s; int ans=10e6;
  if(s[0] == '1'){
    int res=0;
    for(int i=1;i<s.size();i+=2){
      if(s[i] == '1') res++;
      if(s[i+1] == '0') res++;
    }
     ans = min(res,ans);
  }
  if(s[0] == '0'){
    int res=0;
    for(int i=1;i<s.size();i+=2){
      if(s[i] == '0') res++;
      if(s[i+1] == '1') res++;
    }
    ans=min(res,ans);
  }
   cout << ans <<endl;
  return 0;
}
  

Measured memory_bytes: 512
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int a,b,x; 
    cin>>a>>b>>x; 
    int begin=(a/x)*x;
    if (begin<a) begin += x;
    int end = (b/x)*x;
    int ans=0;
    if (begin<=end) ans = (end-begin)/x+1;
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,x[5000],M;
map<string,int> msi;
int par[5000],mn[5000],n[5000];
void init(int N){rep(i,N) par[i]=i,mn[i]=x[i],n[i]=1;}
int find(int x){
	if(x==par[x]) return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x),y=find(y);
	if(x==y) return;
	par[x]=y;
	mn[y]=min(mn[x],mn[y]);
	n[y]+=n[x];
}
int main(){
	cin>>N;
	rep(i,N){
		string s;
		cin>>s>>x[i];
		msi[s]=i;
	}
	init(N);
	cin>>M;
	rep(i,M){
		string a,b;
		cin>>a>>b;
		int p=msi[a],q=msi[b];
		unite(p,q);
	}
	int ans=0;
	rep(i,N) if(find(i)==i) ans+=mn[i]*n[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1860
n = int(input())
string = input()
start_cnt = 0
end_cnt = 0
tmp = 0
for s in string:
    if s == ")":
        if tmp == 0:
            start_cnt += 1
        else:
            tmp -= 1
    else:
        tmp += 1
tmp = 0
for s in string[::-1]:
    if s == "(":
        if tmp == 0:
            end_cnt += 1
        else:
            tmp -= 1
    else:
        tmp += 1
for _ in range(start_cnt):
    print("(", end = "")
    
print(string, end = "")

for _ in range(end_cnt):
    print(")", end = "")
    
print()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int n;
    cin >> n;
    int cnt1 = 0;
    int cnt2 = 0;
    int ans1 = 0;
    int ans2 = 0;
    vector<int>a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        cnt1+=a[i];
        cnt2+=a[i];
        if(i%2 == 0) {
            if(cnt1 <= 0) {
                ans1+=1-cnt1;
                cnt1 = 1;
            }
            if(cnt2 >= 0) {
                ans2+=cnt2+1;
                cnt2 = -1;
            }
        }
        if(i%2 == 1) {
            if(cnt1 >= 0) {
                ans1+=cnt1+1;
                cnt1 = -1;
            }
            if(cnt2 <= 0) {
                ans2+=1-cnt2;
                cnt2 = 1;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define mod 1000000007
#define INF 1e18
typedef  long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m;
	cin>>n>>m;	
	vector<vector<int>> g(n+1);
	for (int i = 0; i < m; ++i)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	// for (int i = 1; i < g.size(); ++i)
	// {
	// 	cout<<i<<" ";
	// 	for (int j = 0; j <g[i].size() ; ++j)
	// 	{
	// 		cout<<g[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	int vis[n+1];
	memset(vis,0,sizeof(vis));
	vector<vector<int>> con;
	for (int i = 1; i <g.size() ; ++i)
	{
		if(vis[i]==0){
			vector<int> temp;
			vis[i]=1;
			// temp.pb(i);
			queue<int> q;
			q.push(i);
			while(!q.empty()){
				int a=q.front();
				temp.pb(a);
				q.pop();
				for(auto j:g[a]){
					if(vis[j]==0){
						q.push(j);
						vis[j]=1;
					}
				}
			}
			con.pb(temp);
		}
	}
	// for (int i = 0; i < con.size(); ++i)
	// {
	// 	for (int j = 0; j <con[i].size() ; ++j)
	// 	{
	// 		cout<<con[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	int ans=INT_MIN;
	for (int i = 0; i < con.size(); ++i)
	{
		int s=con[i].size();
		ans=max(s,ans);
	}
	cout<<ans;
	return 0;
}

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

int main() {
  long H;
  cin >> H;
  if(H == 0){
    cout << 0 << endl;
  }else if(H == 1){
    cout << 1 << endl;
  }
  for(long i = 0; i <pow(10,12); i++){
    if(H == 0 || H == 1){
      break;
    }else if(pow(2,i) > H){
      cout << (long)pow(2,i)-1 << endl;
      break;
    }
  }
}    

Measured memory_bytes: 256
main(){long long n,i,x[10];while(scanf("%lld",&n)!=-1){for(i=0;i<10;i++){x[i]=n%10;n/=10;}printf("%lld\n",(x[0]+x[1]*9+x[2]*36+x[3]*84+x[4]*126+x[5]*126+x[6]*84+x[7]*36+x[8]*9+x[9])%10);}return 0;}

Measured memory_bytes: 600
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    
inline int mul(int a, int b){
    if(a < 0){
        a = (a + mod) % mod;
    }
    if(b < 0){
        b = (b + mod) % mod;
    }
    return (ll)a * b % mod;
}


int main(){
   IOS

    int n, k; cin>>n>>k;

    vi a(n);
    for(int & x : a)cin>>x;

    sort(all(a));

    ll product = 1;

    if(a[n-1] == 0 && (k & 1)){
        cout<<0<<"\n";
        return 0;
    }

    if(a[n-1] <= 0 && (k & 1)){
        for(int i = n-1; i >= n - k; --i){
            product = mul(product, a[i]);
        }
        cout<<product % mod<<"\n";
        return 0;
    }

    int l = 0, r = n - 1;
    if(k & 1){
        product = mul(product, a[r]);
        r--;
        k--;
    }

    k >>= 1;
    for(int it = 0; it < k; it++){
        ll lp = (ll)a[l] * a[l + 1];
        ll rp = (ll)a[r] * a[r-1];
        if(lp > rp){
            product = mul(product, lp % mod);
            l += 2;
        }else{
            product = mul(product, rp % mod);
            r -= 2;
        }
    }

    cout<<product<<"\n";

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3960
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };


int n, q;
vector<int>G[222222];
int cnt[222222];
bool visit[222222];

void dfs(int p,int sum) {
    if (visit[p])
        return;
    visit[p] = 1;
    sum += cnt[p];
    cnt[p] = sum;

    rep(i, G[p].size()) {
        int next = G[p][i];
        dfs(next,sum);
    }
}
int main() {
    cin >> n >> q;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    rep(i, q) {
        int a, c;
        cin >> a >> c;
        a--;
        cnt[a] += c;
    }
    dfs(0,0);

    rep(i, n)cout << cnt[i] << " "; cout << endl;
    return 0;
}


Measured memory_bytes: 24192
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

vector<array<int, 2>>MakeD(const int N, const int D) {

	vector<array<int, 2>>diff;
	rep(i, 2 * N)rep(j, 2 * N)if (i*i + j*j == D)diff.push_back({ i,j });
	return diff;
}

signed main()
{
	std::cin.sync_with_stdio(false);
	std::cin.tie(0);


	int N, D1, D2;
	cin >> N >> D1 >> D2;

	auto m1 = MakeD(N, D1);
	auto m2 = MakeD(N, D2);

	vector<vector<int>>color1(N * 2, vector<int>(N * 2, 0));
	vector<vector<int>>color2(N * 2, vector<int>(N * 2, 0));

	int count[4] = { 0 };
	const int dir[5] = { 1,1,-1,-1,1 };
	rep(i, N * 2)rep(j, N * 2) {
		
		if (color1[i][j] == 0) {
			stack<pair<int, int>>dfs;
			color1[i][j] = 1;
			dfs.push(make_pair(i, j));
			while (!dfs.empty()) {
				auto x = dfs.top();
				dfs.pop();
				for (auto k : m1) {
					rep(l, 4) {
						int ii = x.first + k[0] * dir[l];
						int jj = x.second + k[1] * dir[l+1];
						if (0 <= ii && ii < 2 * N && 0 <= jj && jj < 2 * N && color1[ii][jj] == 0) {
							color1[ii][jj] = 3 ^ color1[x.first][x.second];
							dfs.push(make_pair(ii, jj));
						}
					}
				}
			}
		}

		if (color2[i][j] == 0) {
			stack<pair<int, int>>dfs;
			color2[i][j] = 1;
			dfs.push(make_pair(i, j));
			while (!dfs.empty()) {
				auto x = dfs.top();
				dfs.pop();
				for (auto k : m2) {
					rep(l, 4) {
						int ii = x.first + k[0] * dir[l];
						int jj = x.second + k[1] * dir[l + 1];
						if (0 <= ii && ii < 2 * N && 0 <= jj && jj < 2 * N && color2[ii][jj] == 0) {
							color2[ii][jj] = 3 ^ color2[x.first][x.second];
							dfs.push(make_pair(ii, jj));
						}
					}
				}
			}
		}

		count[color1[i][j] == 1 ? 0 : 1]++;
		count[color2[i][j] == 1 ? 2 : 3]++;
	}

	int ans1 = count[0] >= count[1] ? 1 : 2;
	int ans2 = count[2] >= count[3] ? 1 : 2;

	int x = 0;
	rep(i, N * 2)rep(j, N * 2) {
		if(color1[i][j] == ans1 && color2[i][j] == ans2) {
			if(x++ < N*N)cout << i << " " << j << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=2e5+5;
const int MOD=1e9+7;
int a[N];
int b[N];
int n,k,m;
int cmp(int a,int b)
{
    return a>b;
}

map <int,int> mp;
string s;
int main()
{
    int D,T,S;
    cin>>D>>T>>S;
    if(T*S>=D) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}






Measured memory_bytes: 3592
def isMM(date):

    n_date= int(date)

    if 1 <= n_date <= 12:
        return True
    else:
        return False

def isYY(date):

    n_date = int(date)

    if 0 <= n_date <= 99:
        return True
    else:
        return False

def isYYMM(date):

    if isYY(date[0:2]) and isMM(date[2:4]):
        return True
    else:
        return False

def isMMYY(date):

    if isMM(date[0:2]) and isYY(date[2:4]):
        return True
    else:
        return False

def main(): 

    S = input()

    if isYYMM(S) and isMMYY(S):
        print('AMBIGUOUS')
    elif isYYMM(S):
        print('YYMM')
    elif isMMYY(S):
        print('MMYY')
    else:
        print('NA')

if __name__ == "__main__":
    main() 

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    static long INF = 1001001001001001001L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt();
        int V = 0;
        int[] weights = new int[n];
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            weights[i] = sc.nextInt();
            values[i] = sc.nextInt();
            V += values[i];
        }
        
        // dp[i][v]: 品物0~iまで考慮した上で、価値vでの最小重量
        long[][] dp = new long[n + 1][V + 1];
        // 初期化
        for (int i = 0; i <= n; i++) {
            for (int v = 0; v <= V; v++) {
                dp[i][v] = INF;
            }
        }
        dp[0][0] = 0;
        
        // 考慮する品物を1つずつ増やして考える
        for (int i = 0; i < n; i++) {
            for (int v = 0; v <= V; v++) {
                // 品物iを選択できる(重量[i]がw以下)
                if (v - values[i] >= 0) {
                    // 選択できる場合、選択する方/しない方の最善を選ぶ
                    // (選択するには重量[i]分少ないとこからなら遷移できる)
                    dp[i + 1][v] = Math.min(dp[i][v - values[i]] + weights[i], dp[i][v]);
                } else {
                    // 選択できない場合、品物i-1の時と変わらない
                    dp[i + 1][v] = dp[i][v];
                }
            }
        }
        
        // ans: 品物nまでなめた時の、重量がW以下で最大の価値
        int ans = 0;
        for (int v = V; v >= 0; v--) {
            if (dp[n][v] <= W) {
                ans = v;
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 125496
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

class DisjointSet {
  public:
    vector<ll> rank, p;

    DisjointSet() {}
    DisjointSet(ll size) {
      rank.resize(size, 0);
      p.resize(size, 0);
      rep(i, size) p[i] = i;
    }

    bool same(ll x, ll y) {
      return find_set(x) == find_set(y);
    }

    void unite(ll x, ll y) {
      link(find_set(x), find_set(y));
    }

    void link(ll x, ll y) {
      if (x == y) return;

      if (rank[x] > rank[y]) {
        p[y] = x;
      } else {
        p[x] = y;
        if (rank[x] == rank[y]) rank[y]++;
      }
    }

    ll find_set(ll x) {
      if (x != p[x]) {
        p[x] = find_set(p[x]);
      }
      return p[x];
    }
};

void solve() {
  ll n, m; cin >> n >> m;
  vector<P> e(m);
  rep(i, m) {
    cin >> e[i].first >> e[i].second;
    e[i].first--;
    e[i].second--;
  }

  ll ans = 0;
  for (int i = 0; i < m; i++) {
    DisjointSet ds = DisjointSet(n);
    for (int j = 0; j < m; j++) {
      if (i != j && !ds.same(e[j].first, e[j].second)) {
        ds.unite(e[j].first, e[j].second);
      }
    }

    set<ll> set;
    rep(j, n) set.insert(ds.find_set(j));
    if (set.size() > 1) ans++;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

int get(int n,int m)
{
    return n/m;
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int l,r,d;
        cin>>l>>r>>d;
        cout<<get(r,d) - get(l-1,d)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int gcd (int a, int b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  if (a < b) swap(a, b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int maxv(a[0]), g(a[0]);
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, a[i]);
    g = gcd(g, a[i]);
  }
  if (maxv >= k && !(k % g)) {
    cout << "POSSIBLE" << '\n';
  } else {
    cout << "IMPOSSIBLE" << '\n';
  }
  return 0;
}

Measured memory_bytes: 640
N = int(input())
A = [0] + list(map(int,input().split()))

for i in range(1, len(A)):
  A[i] += A[i - 1]
  
from collections import defaultdict
dic = defaultdict(int)

for i in range(len(A)):
  dic[A[i]] += 1
  
ans = 0
for n in dic.values():
  ans += (n * (n - 1)) // 2
  
print(ans)

Measured memory_bytes: 39500
s = input()
k = int(input())

alphabets = [chr(i + 97) for i in range(26)]

for char in alphabets:
    l = []
    for i in range(len(s)):
        if s[i] == char:
            l.append(s[i:])

    if l == []:
        continue

    if k == 1:
        print(l[0][0])
        exit()
    
    k -= 1

    strings = set([])
    for i in l:
        for j in range(2, min(k+2, len(i)+1)):
            strings.add(i[:j])
    strings = list(strings)
    strings.sort()
    
    if len(strings) >= k:
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)


Measured memory_bytes: 21496
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int a[200000];
int b[200000];
/*int sort(int a[],int low,int high)
{
	int i=low,j=high,base=a[low];
	if(i>=j)
		return 0;
	while(i<j)
	{
		while(i<j&&a[j]>=base)
			j--;
		a[i]=a[j];
		while(i<j&&a[i]<=base)
			i++;
		a[j]=a[i];
	}
	a[i]=base;
	sort(a,low,i-1);
	sort(a,i+1,high);
	return 0;
}*/
int main()
{
	int i,k,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	k=(n-1)/2;
	for(i=0;i<n;i++)
	{
		if(b[i]>a[k])
			printf("%d\n",a[k]);
		else
			printf("%d\n",a[k+1]);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void)
{
    int x, y;
    scanf("%d %d",&x, &y);
    for (int i = 0; i <= x; i++)
    {
        if (((4 * x) - (2 * i)) == y)
        {
            printf("Yes\n");
            return 0;
        }
        else
        {
            continue;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 2052
import numpy as np
pi=np.pi
a, b, x=map(int, input().split())

if x>=a*a*b/2:
  c=2*x/(a*a)-b
  theta=180*np.arctan((b-c)/a)/pi
else:
  c=2*x/(a*b)
  theta=180*np.arctan(b/c)/pi
  
print(theta)

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

int N;
vector<int> A;

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

void input_init(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
}

int solve(void) {
	int ret = A[0];
	for (int i = 1; i < N; ++i)
		ret = gcd(A[i], ret);
	return ret;
}

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

	input_init();
	int ans = solve();

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


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int A[1000];
  int N,i,j,k,v;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
    for(i=0;i<N;i++){
      v=A[i];
      j=i-1;
	while(j>=0&&A[j]>v){
	  A[j+1]=A[j];
	  j--;
	A[j+1]=v;
	}
	for(k=0;k<N;k++){
    if(k>0)printf(" ");
    printf("%d",A[k]);
	}
  printf("\n");
	
    }
	return 0;
}



    



Measured memory_bytes: 2128
fun main(args: Array<String>) {
   val a = readLine()!!.toInt()
   val s = (0 until a).map{ readLine()!!.toInt()}
   var b = 1
   var c = 0
   while(c <= a && b != 2){
      c += 1
      b = s[b - 1]
   }
   println(if (c > a) "-1" else c)
}

Measured memory_bytes: 40984
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
string s;
int x, y;

vector<int> vx;
vector<int> vy;

bool dpx[4010][16010];  //iブロック目のx方向への移動で座標jに到達かのうか?
bool dpy[4010][16010];

/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>s>>x>>y;
    int dir = 1;    //x方向
//    int ind = 0;
//    while(ind < s.size()){
//        if(s[ind] == 'T') dir *= (-1), ind++;
//        else{
//            int cnt = 0;
//            while(s[ind] == 'F'){
//                cnt++;
//                ind++;
//                if(ind == s.size()) break;
//            }
//            if(dir == 1) vx.push_back(cnt);
//            else vy.push_back(cnt);
//        }
//    }
    int cnt = 0;
    REP(i,0,s.size()){
        if(s[i] == 'T'){
            if(dir == 1) vx.push_back(cnt);
            else vy.push_back(cnt);
            dir *= (-1);
            cnt = 0;
        }else{
            cnt++;
        }
    }
    if(cnt != 0){
        if(dir == 1) vx.push_back(cnt);
        else vy.push_back(cnt);
    }

    dpx[0][8000] = true;
    REP(i,0,vx.size()){
        REP(posx, -8000, 8001){
            if(dpx[i][(posx+8000)]){
                if(i != 0) dpx[i+1][(posx+8000)-vx[i]] = true;
                dpx[i+1][(posx+8000)+vx[i]] = true;
            }
        }
    }

    dpy[0][8000] = true;
    REP(i,0,vy.size()){
        REP(posy, -8000, 8001){
            if(dpy[i][(posy+8000)]){
                dpy[i+1][(posy+8000)-vy[i]] = true;
                dpy[i+1][(posy+8000)+vy[i]] = true;
            }
        }
    }


    if(dpx[(int)vx.size()][x+8000] && dpy[(int)vy.size()][y+8000]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 123648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct SAComp{
	const int h,*g;
	SAComp(const int h, const int* g) : h(h), g(g) {}
	bool operator()(const int a, const int b){
		return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a+h] < g[b+h];
	}
};
vector<int> buildSA(const string &t){
	int n=t.size();
	int g[n],b[n];
	vector<int>suff(n);
	for(int i=0;i<n;i++)suff[i]=i,g[i]=t[i];
	b[0]=b[n-1]=0;
	sort(suff.begin(),suff.end(),SAComp(0,g));
	for(int h=1;b[n-1]!=n-1;h<<=1){
		SAComp comp(h,g);
		sort(suff.begin(),suff.end(),comp);
		for(int i=0;i<n-1;i++)b[i+1]=b[i]+comp(suff[i],suff[i+1]);
		for(int i=0;i<n;i++)g[suff[i]]=b[i];
	}
	return suff;
}
vector<int> buildLCP(const string &t, const vector<int> &suff){
	int n=t.size();
	int rank[n];
	vector<int>lcp(n);
	for(int i=0;i<n;i++)rank[suff[i]]=i;
	lcp[0]=0;
	for(int h=0,i=0;i<n-1;i++){
		int j=suff[rank[i]-1];
		if(h>0)h--;
		for(;j+h<n && i+h<n; h++){
			if(t[j + h]!=t[i + h])break;
		}
		lcp[rank[i]-1]=h;
	}
	return lcp;
}
int main(){
	int T;
	string s;cin>>s;s+='$';
	vector<int> suff=buildSA(s),lcp=buildLCP(s,suff);
	cout<<s.size()-1-*max_element(lcp.begin(),lcp.end())<<endl;
}

Measured memory_bytes: 2048
#!/usr/bin/env python3
import sys

s = input()
s2 = s[:(len(s) - 1) // 2]
s3 = s[(len(s) + 3) // 2 - 1 :]

if s == s[::-1]:
    if s2 == s2[::-1]:
        if s3 == s3[::-1]:
            print("Yes")
            sys.exit()

print("No")


Measured memory_bytes: 9064
# 16D8101022L 小林勇希 ID:k_mb python


def insertion_sort(A,n):
    for i in range(n):
        v = A[i]
        j = i-1
        while(j>=0 and A[j]>v):
            A[j+1] = A[j]
            j = j-1
        A[j+1] = v
        for i in range(n-1):
            print(A[i],"",end="")
        print(A[n-1])

n = int(input())
A_idx = [int(i) for i in input().split()]

insertion_sort(A_idx,n)


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  sort(p.begin(), p.end());
  int min = 0;
  for (int i = 0; i < k; i++) min += p[i];
  cout << min << endl;
}

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

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

  for (int k = 1; k < 4; k++) {
    if (s[k] == s[k-1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    S = SI()

    if len(S) <= K:
        print(S)
    else:
        print(S[:K]+'...')

if __name__ == '__main__':
    main()

Measured memory_bytes: 68868
#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>;

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }

  mint &operator/=(const mint a) { return *this *= a.inv(); }

  mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
  vector<mint> fact, ifact;

  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }

  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll x, y;
  cin >> x >> y;
  ll xy = x + y;
  ll n = xy / 3;
  if (xy % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  // i + 2, j + 1 の個数
  ll v = -1;
  for (ll i = 0; i <= n; i++) {
    ll xx = 2 * i + 1 * (n - i);
    if (xx == x) {
      v = i;
      break;
    }
  }
  ll res = combination(n)(n, v).x;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 13468
#include <iostream>
using namespace std;
int cnt=0;

void merge(int *A, int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    int *L,*R;
    L = new int[n1+1];
    R = new int[n2+1];

    for(int i=0;i<n1;i++)
        L[i] = A[left+i];
    for(int i=0;i<n2;i++)
        R[i] = A[mid+i];
    
    L[n1] = 1000000001;
    R[n2] = 1000000001;
    int i = 0;
    int j = 0;

    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }

    delete[] L;
    delete[] R;
}

void mergeSort(int *A, int left, int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
} 

int main(){
    int n, *S;
    cin >> n;
    S = new int[n];
    for(int i=0;i<n;i++)
        cin >> S[i];
    mergeSort(S,0,n);

    cout << S[0];
    for(int i=1;i<n;i++)
        cout << " " << S[i];
    cout << endl << cnt << endl;

    delete[] S;
    return 0;
}


Measured memory_bytes: 6744