akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

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

    int r = 0;
    int n = gi();
    for (int i = 1; i <= n && i < 10; i++)
        r++;
    for (int i = 100; i <= n && i < 1000; i++)
        r++;
    for (int i = 10000; i <= n && i < 100000; i++)
        r++;

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int n;
string s;
ll R, G, B;

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> n >> s;
    forn(i, s.size())
    {
        if(s[i] == 'R') R++;
        else if(s[i] == 'G') G++;
        else B++;
    }
    ll ko = 0;
    forn(i, s.size()) for(int j=i+1; j<s.size(); j++)
    {
        if(2*j-i<s.size() && s[i]!=s[j] && s[j]!=s[2*j-i] && s[2*j-i]!=s[i]) ko++;
    }
    cout << R*G*B-ko << '\n';
}


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

static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int res = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 0;i <= m;i++)c[i][0] = 0;
	for (int j = 1;j <= n;j++)c[0][j] = 0;

	for (int i = 1;i <= m;i++) {
		for (int j = 1;j <= n;j++) {
			if (X[i] == Y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);

			}
			res = max(res, c[i][j]);
		}
	}
	return res;
}

int main() {
	string s1, s2;
	int n; cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;

	}
	return 0;
}


Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, x, y; cin >> n >> x >> y; --x, --y;
  	int a[n + 1]; for (int i = 1; i <= n; ++i) a[i] = 0;
  	for (int i = 0; i < n; ++i) {
    	for (int j = i + 1; j < n; ++j) {
        	++a[min({abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x)})];
        }
    }
  	for (int i = 1; i < n; ++i) {
    	cout << a[i] << endl;
    }
  	return 0;
}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (N == i * j) {
	cout << "Yes\n";
	return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
long double ps[1000][MAX];

int main()
{
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  for (int i = 1; i <= N; i++)
  {
    double tmp = 1.0;
    int n = i;
    while (n < K)
    {
      n *= 2;
      tmp *= 0.5;
    }
    ans += tmp;
  }
  ans /= (double)(N);
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

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

  int ret = 0;
  int cur = 1;
  for (int i = 0; i < n; ++i) {
    int ai;
    cin >> ai;
    if (ai == cur) {
      ++cur;
    } else {
      ++ret;
    }
  }
  if (ret == n) ret = -1;
  cout << ret << endl;

  return 0;
}


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

int main() {
	int i, cnt_zero, cnt_one;
	char s[100000];
	
	scanf("%s", &s);

	cnt_zero = 0;
	cnt_one = 0;
	for (i = 0; i < strlen(s); i++) {
		if (s[i] == '0') cnt_zero++;
		else cnt_one++;
	}
	printf("%d", 2 * ((cnt_zero < cnt_one) ? cnt_zero : cnt_one));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int sum[2];
	int info, math, sci, eng;
	int i;
	
	for (i = 0; i < 2; i++){
		scanf("%d %d %d %d", &info, &math, &sci, &eng);
		sum[i] = info + math + sci + eng;
	}
	
	if (sum[0] > sum[1]){
		printf("%d\n", sum[0]);
	}
	else if (sum[0] < sum[1]){
		printf("%d\n", sum[1]);
	}
	else {
		printf("%d\n", sum[0]);
	}
	
	return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <iomanip>

int main(void) {
	using namespace std;
	double a, b, c, d, e, f;
	double x, y;
	while (std::cin >> a >> b >> c >> d >> e >> f) {
		y = (double)(f*a - d*c) / (e*a - d*b);
		x = (c - b*y) / a;
		cout << showpoint << fixed << setprecision(3)<< x << ' ' << y << endl;
	}

	return 0;
}

Measured memory_bytes: 3164
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val N = readInt()
  val arr = readLine.split(" ").map(_.toInt)

  def bubbleSort(A: Array[Int], N: Int): Int = {
    var flag = true
    var count = 0
    while (flag) {
      flag = false
      for (j <- N - 1 to 1 by -1) {
        if (A(j) < A(j - 1)) {
          val tmp = A(j)
          A(j) = A(j - 1)
          A(j - 1) = tmp
          count += 1
          flag = true
        }
      }
    }
    count
  }

  val ans = bubbleSort(arr, arr.length)

  println(arr.mkString(" "))
  println(ans)
}


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

int main()
{
    long long int n,i,h[100005],dp[100005];
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>h[i];
    dp[0] = 1e12;
    dp[1] = 0;
    for(i=2;i<=n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
        // cout<<"i = "<<i<<" dp = "<<dp[i]<<endl;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
def lcm(x, y):
	return (x*y) // gcd(x, y)
aa = a[0]
for i in a[1:]:
	aa = lcm(aa,i)
#if aa-max(a) <= 0:
#	aa += aa
s = 0
for i in a:
	s += (aa-1)%i
print (s)


Measured memory_bytes: 5344
import sys

input = sys.stdin.readline


def update_coord(H, W, i, j):
    # --->
    if i % 2 == 0:
        if j == W - 1:
            i += 1
        else:
            j += 1
    # <---
    else:
        if j == 0:
            i += 1
        else:
            j -= 1
    return i, j


def main():
    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))

    ans = [[0] * W for _ in range(H)]
    i, j = 0, 0
    for k, aa in enumerate(a):
        for _ in range(aa):
            ans[i][j] = k + 1
            i, j = update_coord(H, W, i, j)

    for i in range(H):
        print(" ".join(map(str, ans[i])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int mat[4][N],val[N],n,num[2],v[N];
#define lowbit(x) ((x) & (-(x)))
void add(int p,int val) {
  for ( ; p <= n ; p += lowbit(p))
    v[p] += val;
}
int query(int p) {
  int ret = 0;
  for ( ; p ; p -= lowbit(p))
    ret += v[p];
  return ret;
}
void fail() {
  puts("No");
  exit(0);
}
int main() {
  scanf("%d",&n);
  for (int i = 1 ; i <= 3 ; ++ i)
    for (int j = 1 ; j <= n ; ++ j)
      scanf("%d",&mat[i][j]);
  for (int i = 1 ; i <= n ; ++ i) {
    if (mat[1][i] % 3 == 0) {
      if (mat[2][i] == mat[1][i] - 1 && mat[3][i] == mat[1][i] - 2)
	val[i] = - mat[1][i] / 3;
      else fail();
    } else if (mat[3][i] % 3 == 0) {
      if (mat[2][i] == mat[3][i] - 1 && mat[1][i] == mat[3][i] - 2)
	val[i] = mat[3][i] / 3;
      else fail();
    } else fail();
  }
  for (int i = 1 ; i <= n ; i += 2) {
    if (val[i] < 0) num[1] ^= 1, val[i] = -val[i];
    if (val[i] % 2 == 0) fail();
  }
  for (int i = 2 ; i <= n ; i += 2) {
    if (val[i] < 0) num[0] ^= 1, val[i] = -val[i];
    if (val[i]&1) fail();
  }
  for (int i = 1 ; i <= n ; i += 2) {
    if ((query(n) - query(val[i]))&1) num[0] ^= 1;
    add(val[i],1);
  }
  memset(v,0,sizeof v);
  for (int i = 2 ; i <= n ; i += 2) {
    if ((query(n) - query(val[i]))&1) num[1] ^= 1;
    add(val[i],1);
  }
  if ((!num[0]) && (!num[1]))
    puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 2176
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;
int main() {

	cin >> N;

	cout << std::setprecision(20)<< double(pow(N,3)/27) << endl;
	return 0;
}



Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
H, W = map(int, input().split())
c = [None] * 10
for i in range(10):
    c[i] = [int(cij) for cij in input().split()]
D = floyd_warshall(c)
cost = 0
for i in range(H):
    for Aij in input().split():
        Aij = int(Aij)
        if Aij == -1:
            continue
        cost += D[Aij][1]
print(int(cost))

Measured memory_bytes: 17580
#include<stdio.h>

int main(){
	int d,s,i;
	while(scanf("%d",&d)!=-1){
		for(s=0,i=1;i*d<600;i++){
			s+=i*i*d*d*d;
		}
	printf("%d\n",s);	
	}
	return 0;
}

Measured memory_bytes: 596
N,K=map(int,input().split())
S=input()
start=[0]
end=[]
bef=S[0]
if bef=='0':
    end.append(0)
for i in range(1,N):
    if S[i]!=bef:
        if bef=='0':
            start.append(i)
        else:
            end.append(i-1)
        bef=S[i]
if S[-1]=='1':
    end.append(N-1)
ans=0
for i in range(len(end)):
    if i-K<0:
        x=0
    else:
        x=start[i-K]
    ans=max(ans,end[i]-x+1)
if S[-1]=='0' and K!=0:
    if len(start)-K<0:
        x=0
    else:
        x=start[-1*K]
    ans=max(ans,N-x)
print(ans)

Measured memory_bytes: 7260
#include<stdio.h>
int main(void){

  //変数の受け取り
  int A, B;
  scanf("%d%d", &A, &B);
  
  if(1 <= A && A <= 9 && 1 <= B && B <= 9){
  	printf("%d\n", A*B);
  }else{
  	printf("-1\n");
  }
}  

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n;
    cin >> n;
    vector<int> v(n);
    FOR(i, n)
        cin >> v[i];

    int sol = 0;
    int crt = 1;
    FOR(i, n){
        if (v[i] == crt){
            crt++;
        }
        else{
            sol++;
        }
    }
    if (crt == 1)
        cout << -1 << endl;
    else
        cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

ll countAB(string str) {
    ll cnt = 0;
    while (str.find("AB") != string::npos) {
        cnt++;
        str = str.substr(str.find("AB")+1, str.size());
    }

    return cnt;
}


ll x = 0, y = 0, z = 0;
void checktype(string str) {
    if (str[0] == 'B' && str[str.length()-1] == 'A') {
        z++;
    } else if (str[str.length()-1] == 'A') {
        x++;
    }else if (str[0] == 'B') {
        y++;
    }
}

void solve(){
    ll N;
    cin >> N;

    vector<string> strs(N);
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> strs[i];
        cnt += countAB(strs[i]);
        checktype(strs[i]);
    }

    if (x == 0 && y == 0) {
      	if (z >= 2) {
        	cout << cnt + z - 1 << endl;
        } else {
          cout << cnt << endl;
        }
    } else {
        cout << cnt + min(x,y) + z << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (n % 2 == 0 ? n : 2 * n) << endl;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(M)]

result = []
for a, b in AB:
  tmp = []
  for c, d in CD:
    tmp.append(abs(a-c) + abs(b-d))
  result.append(tmp.index(min(tmp))+1)
for r in result:
  print(r)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
   
int main()
{
  int n;
 
  while (cin >> n, n){
    int a, b, n_a, n_b;
    a = b = 0;

    for (int i = 0; i < n; i++){
      cin >> n_a >> n_b;
      if (n_a == n_b){
        a += n_a;
        b += n_b;
      }
      else if(n_a > n_b){
        a += n_a + n_b;
      }
      else {
        b += n_a + n_b;
      }
    }
                                                                                                                                                                                 
    cout << a << ' ' << b << endl;
  }
}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int a , v , b , w;
   cin >> a >> v >> b >> w;
   int t;
   cin >> t;
   if(v <= w)
      return cout << "NO" , 0;
   int diff = v - w;
   if(1ll * t * diff >= abs(a - b))
      cout << "YES";
   else
      cout << "NO";
   return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] f;
	int c=0, fb=0;
	f = new int[100];
	while(true){
	    String s = sc.nextLine();
	    int l = s.length();
	    if(s.charAt(0)=='.') break;
	    outer:for(int i=0;i<l;i++){
		if(s.charAt(i)=='('){
		    f[c]=0; c++; fb=1; 
		}else if(s.charAt(i)=='['){
		    f[c]=1; c++; fb=1;
		}else if(s.charAt(i)==']'){
		    f[c]=2; c++; fb=1;
		}else if(s.charAt(i)==')'){
		    f[c]=3; c++; fb=1;
		}
		while(fb==1 && c!=0 &&(f[c-1]==2 || f[c-1]==3)){
		    if(c==1) break outer;
		    else if((f[c-1]==2 && f[c-2]==1) || (f[c-1]==3 && f[c-2]==0)) c-=2;
		    else break;
		}
		fb=0;		
	    }
	    if(c==0) System.out.printf("yes\n");
	    else System.out.printf("no\n");
	    c=0;	    
	}	
    }
}

Measured memory_bytes: 48012
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    int ans = 0;
    rep(i, n) {
        if(a[a[i]] == i) {
            ans++;
        }
    }
    
    ans /= 2;

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

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int H, W;
char map[55][55];
int used[55][55];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int main(void)
{
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		for(int y = 1; y <= H; y++){
			for(int x = 1; x <= W; x++){
				cin >> map[x][y];
			}
		}
		if(map[1][1] == '#' || map[1][H] == '#' || map[W][H] == '#' || map[W][1] == '#'){
			cout << "NO" << endl;
			continue;
		}
		if(map[1][2] = '#' && map[2][1] == '#'){
			cout << "NO" << endl;
			continue;
		}
		map[1][1] = '4';
		map[1][H] = '1';
		map[W][H] = '2';
		map[W][1] = '3';
		
		for(int x = 1; x <= W; x++){
			for(int y = 1; y <= H; y++){
				used[x][y] = 0;
			}
		}
		
		int x = 1, y = 1, dir = 3;
		for(int i = 1; i <= 4; i++){
			while(1){
				for(dir = (dir+3)%4; ; dir = (dir+1)%4){
					int nx = x + dx[dir], ny = y + dy[dir];
					if(nx < 1 || nx > W || ny < 1 || ny > H) continue;
					if(map[nx][ny] != '#') break;
				}
				x += dx[dir], y += dy[dir];
				if(map[x][y] >= '1' && map[x][y] <= '4'){
					if(map[x][y] != i + '0'){
						cout << "NO" << endl;
						goto end;
					}
					break;
				}
				if(used[x][y] != 0 && used[x][y] != i){
					cout << "NO" << endl;
					goto end;
				}
				used[x][y] = i;
			}
		}
		cout << "YES" << endl;
		end:;
	}
	
	return 0;
}


Measured memory_bytes: 3076
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

main = do
    a <- getLine
    b <- getLine
    let la = length a
    let lb = length b
    let tb = init b
    putStrLn $ if la +1 == lb && tb == a then "Yes" else "No"


Measured memory_bytes: 3792
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<deque>
#include<cctype>
using namespace std;
int main() 
{
	string s;
	cin>>s;
    cout<<"ABC"+s; 
    return 0; 
}
    

Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <iostream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 5e5 + 10;
const int mod = 1e9 + 7;

int A, B, C; 

int main() {
  std :: ios :: sync_with_stdio(false);
  std :: cin.tie(0);
  std :: cout.tie(0);
  while(cin >> A >> B >> C) {
    int cnt = 0;
    ll S;
    while(1) {
      if(A & 1 || B & 1 || C & 1) break;
      if(A == B && B == C) {
        cnt = -1;
        break;
      }
      S = 1ll * A + B + C;
      A = (S - A) / 2, B = (S - B) / 2, C = (S - C) / 2;
      ++ cnt;
    }
    cout << cnt << '\n';
  } 
  return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
int N,K;
int X[K+1];
 
int min(int a, int b){
if(a<=b) return a;
if(a>b)   return b;
}
 
scanf("%d", &N);
scanf("%d", &K);
for(int i =0; i<N; i++){
     scanf("%d",&X[i]);
     }
int sum =0;
for(int i =0; i <N; i++){
     int tmp = min( X[i], K-X[i]);
     sum = sum + tmp;
}
printf("%d", sum*2);
 return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  vector<int> diff(M-1);
  for(int i=0; i<M; i++) cin >> X.at(i);
  sort(X.begin(), X.end());
  for(int i=0; i<M-1; i++){
    diff.at(i)=X.at(i+1)-X.at(i);
  }
  sort(diff.begin(),diff.end());
  int ans = 0;
  for(int i=0; i<M-N; i++){
    ans+=diff.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
if __name__ == "__main__":
    # test()
    res = []
    r, c = map(int, input().split())
    for _ in range(r):
        res.append(list(map(int, input().split())))

    last_row = []

    #縦に足す
    for i in range(c):
        sum_of_i = 0
        for e in res:
            sum_of_i += e[i]
        last_row.append(sum_of_i)
    res.append(last_row)

    #横に足す
    for e in res:
        e.append(sum(e))

    #結果出力
    for r in res:
        print(*r)



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

int main()
{
	int a,b;
	cin>>a>>b;
	
	if(a!=13&&b!=13)
	{
		if(a>b) cout<<"Alice";
		else if(a<b) cout<<"Bob";
		else cout<<"Draw";
	}
	else if(a==13)
	{
		if(b==1) cout<<"Bob";
		else if(a==b) cout<<"Draw";
		else cout<<"Alice";
	}
	else if(b==13)
	{
		if(a==1) cout<<"Alice";
		else if(a==b) cout<<"Draw";
		else cout<<"Bob";
	}
	
	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> fw(n, 0);
  int wSum, eSum = 0;
  for (int i = 0; i < m; i++){
    string s;
    cin >> s;
    for (int j = 0; j < n; j++){
      if (s[j] == 'W') fw[j]++;
    }
  }
  for (int i = 0; i < n; i++){
    wSum += fw[i];
  }
  int mi = wSum + eSum;
  //cout << mi << endl;
  int mind = -1;
  for (int i = 0; i < n; i++){
    int w = fw[i];
    int e = m - fw[i];
    wSum -= w;
    eSum += e;
    var cur = wSum + eSum;
    //cout << cur << endl;
    if (cur < mi){
      mi = cur;
      mind = i;
    }
  }
  cout << mind + 1 << " " << mind + 2 << endl;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define fs first
#define sc second

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef pair<P,P> L;
typedef pair<D,int> pdi;

const D EPS = 1e-8;

inline D func(int x, P a, P b){
  D difx = b.fs - a.fs;
  D dify = b.sc - a.sc;
  return (D)dify/difx * (x-a.fs) + a.sc;
}

int main(){
  int m;
  while(cin >> m,m){
    vector<P> p(m);
    rep(i,m)cin >> p[i].fs >> p[i].sc, p[i].first*=2;
    vector<L> s(m);
    rep(i,m){
      s[i] = L(p[i],p[(i+1)%m]);
      if(s[i].fs > s[i].sc)swap(s[i].fs,s[i].sc);
    }

    int ans = 0;
    for(D x = -3999;x<4000;x+=2){
      vector<pdi> inv;
      rep(i,m){
	if(s[i].fs.fs < x+EPS && x< s[i].sc.fs+EPS){
	  inv.push_back(pdi(func(x,s[i].fs,s[i].sc), i));
	}
      }

      sort(all(inv));
      int prv = -10000;
      for(int i=0;i<(int)inv.size();i+=2){
	int u = inv[i+1].sc, b = inv[i].sc;
	int up = ceil(max(func(x-1,s[u].fs,s[u].sc),
			  func(x+1,s[u].fs,s[u].sc))-EPS);
	int bot = floor(min(func(x-1,s[b].fs,s[b].sc),
			    func(x+1,s[b].fs,s[b].sc))+EPS);
	if(bot<prv)bot = prv;
	ans += up - bot;
	prv = up;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1204
import sys
input = sys.stdin.readline

n,a,b,c = map(int,input().split())
ans = []
abc = [a,b,c]

d = {'AB\n':(0,1),'AC\n':(0,2),'BC\n':(1,2)}

if(a+b+c==0):
    print('No')
    exit()

if(a+b+c >= 3)|(a+b+c==1):
    for _ in range(n):
        s = input()
        x,y = d[s]
        if(abc[x]==0)&(abc[y]==0):
            print('No')
            exit()
        if(abc[x] < abc[y]):
            x,y = y,x
        abc[x] -= 1
        abc[y] += 1
        ans.append(y)

elif(a+b+c==2):
    ss = [input() for _ in range(n)]
    if(max(abc)==2):
        #(2,0,0)
        case = True
    else:
        case = False

    for i in range(n):
        s = ss[i]
        x,y = d[s]
        if(case)|(i==n-1):
            if(abc[x]==0)&(abc[y]==0):
                print('No')
                exit()
            if(abc[x] < abc[y]):
                x,y = y,x
            abc[x] -= 1
            abc[y] += 1
            case = False
        else:
            if(abc[x]!=abc[y]):
                if(abc[x] < abc[y]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
                case = False
            else:
                sn = ss[i+1]
                if(x in d[sn]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
                case = True
        ans.append(y)

print('Yes')
for i in ans:
    print(chr(i+ord('A')))


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



// main
int main(){
    int N;
    cin >> N;
    vector<int> P(N,0);
    for(int i = 0; i < N; ++i){
        cin >> P[i];
    }

    int count = 0;
    int min = P[0];

    for(int i = 0; i < N; ++i){
        if(min > P[i]){
            min = P[i];
        }
        if(min >= P[i]){
            count++;
        }
    }

    cout << count << "\n";
    return 0;
}

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

int main()
{
    // 入力
    int N,H;
    cin>>N>>H;
    int a,b[N];
    int a_max=0;
    for(int i=0;i<N;i++){
    	cin>>a;
    	a_max=max(a,a_max);
    	cin>>b[i];
    }
    int max_turn=0;
    sort(b,b+N);
    for(int i=N-1;i>=0;i--){
    	if(H<=0 || b[i]<a_max) break;
    	max_turn++;
    	H-=b[i];
    }

    if(H>0) max_turn+= (H+a_max-1)/a_max;
    cout<<max_turn<<endl;

    return 0;
}

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

using namespace std;

struct request_t {
  int a;
  int b;

  constexpr request_t(int a_, int b_) : a(a_), b(b_) {}
  request_t() {}

  explicit operator bool() const noexcept { return a < b; }
  bool operator!() const noexcept { return !static_cast<bool>(*this); }
};

request_t operator&(const request_t& t1, const request_t& t2) {
  return request_t(std::max(t1.a, t2.a), std::min(t1.b, t2.b));
}

int calc(std::vector<request_t>& rs, int n) {
  if (n <= 2) {
    return 1;
  }
  if (rs.size() <= 1) {
    return rs.size();
  }
  std::sort(rs.begin(), rs.end(),
            [](const auto& lhs, const auto& rhs) { return lhs.a < rhs.a; });
  int ret = 0;
  request_t previous_range(0, 0);
  for (const auto& r : rs) {
    request_t const new_range = r & previous_range;
    if (static_cast<bool>(new_range)) {
      previous_range = new_range;
      continue;
    }
    ret++;
    previous_range = r;
  }
  return ret;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<request_t> rs(m);
  for (auto& r : rs) {
    std::cin >> r.a;
    std::cin >> r.b;
  }
  std::cout << calc(rs, n) << std::endl;
  return 0;
}


Measured memory_bytes: 1024
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    println!("{}", n * n * n);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#文字列の入力
S = input()

#listを一文字ずつのlistに
S_list = list(S)
ans = 0
#偶数文字の場合
if(len(S_list)%2==0):
  #文字数/2回for文
  for i in range(int(len(S_list)/2)):
    #i文字目と後ろからi文字目が一緒なら何もしない
    #print(i,len(S_list)-i-1)
    if(S_list[i]==S_list[len(S_list)-i-1]):
      ans = ans + 0
    #一緒じゃ無い場合
    else:
      ans = ans + 1
else:
  for i in range(int(len(S_list)/2)):
    #print(i,len(S_list)-i-1)
    if(S_list[i]==S_list[len(S_list)-i-1]):
      ans = ans + 0
    else:
      ans = ans + 1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fi first
#define MN (1<<18)
#define mp(x,y) make_pair(x,y)
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
typedef pair<int,int> pr;
int a[MN+5];
pr mx[2][MN+5],b[4];
int n,res;
inline bool cmp(pr x,pr y){return x>y;}
int main()
{
	n=in();
	for (int i=0;i<(1<<n);++i){
		a[i]=in();
		if (a[i]>mx[0][i].fi) mx[1][i]=mx[0][i],mx[0][i]=mp(a[i],i);
		else if (a[i]>mx[1][i].fi) mx[1][i]=mp(a[i],i);
		for (int j=0;j<n;++j) if (!(i&(1<<j))){
			int tot=0;
			b[0]=mx[0][i];b[1]=mx[1][i];
			b[2]=mx[0][i|(1<<j)];b[3]=mx[1][i|(1<<j)];
			sort(b,b+4,cmp);
			for (int k=0;k<4;++k){
				if ((!k)||b[k]!=b[k-1]) mx[tot++][i|(1<<j)]=b[k]; 
				if (tot==2) break;
			}
		}
		res=max(res,mx[0][i].fi+mx[1][i].fi);
		if (i) printf("%d\n",res);
	}return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  int left = 0;
  int right = N-1;
  cout << left << endl;
  string s1;
  cin >> s1;
  if(s1=="Vacant"){
    return 0;
  }
  cout << right << endl;
  string s2;
  cin >> s2;
  if(s2=="Vacant"){
    return 0;
  }
  REP(i,20){
    cout << (right+left)/2 << endl;
    string x;
    cin >> x;
    if(x=="Vacant"){
      return 0;
    }

    if((s1==x&&((right+left)/2-left-1)%2==1)||(s1!=x&&((right+left)/2-left-1)%2==0)){
      left=(right+left)/2;
      s1=x;
    }else{
      right=(right+left)/2;
    }
  }
}

Measured memory_bytes: 3852
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static final long MOD = 1000000007;
    private static long[] x;
    private static long[] y;
    private static int N;
    private static int N1;
    private static int N2;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());

	x = new long[N+2];	// x[i] = i!, i=0..N+1
	y = new long[N+2];	// y[i] = (i!)^-1, i=0..N+!
	x[0] = 1;
	for (int i = 1; i < N+2; i++) {
	    x[i] = (i * x[i-1]) % MOD;
	}
	for (int i = 0; i < N+2 ; i++) {
	    y[i] = pow(x[i], MOD-2) % MOD;
	}

	int[] a = new int[N+1];	// 0..N
	for (int i = 0; i < N+1; i++) a[i] = -1;
	int index1 = 0;
	int index2 = 0;
	for (int i = 0; i < N+1; i++) {
	    int num = Integer.parseInt(scan.next());
	    if(a[num] < 0) a[num] = i;
	    else {
		index1 = a[num];
		index2 = i;
		break;
	    }
	}
	N1 = index1;
	N2 = N - index2;

	for (int k = 1; k <= N+1; k++) {
	    long result = combination(N+1, k);
	    result = (result - combination(N1+N2, k-1) + MOD) % MOD;
	    System.out.println(result);
	}
	scan.close();
    }

    private static long pow(long x, long y) {
	if(y == 0) return 1;

	if(y % 2 == 0) {
	    long x2 = pow(x, y/2);
	    return (x2 * x2) % MOD;
	} else {
	    long x2 = pow(x, y/2);
	    return (((x * x2) % MOD) * x2) % MOD;
	}
    }

    private static long combination(int n, int r) {
	if(n < r) return 0;
	
	return (((x[n] * y[r]) % MOD) * y[n-r]) % MOD;
    }
}


Measured memory_bytes: 48532
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            
            var N = cin.nextInt();
            var A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = cin.nextInt();
            }

            var ans = 0.0;
            for (int i = 0; i < N; i++)
            {
                ans += 1.0 / A[i];
            }

            ans = 1 / ans;

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 4e5 + 10;
const int maxm = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;

ll a[maxn], b[maxn], c[maxn], fen[maxn];
ll n;
int N = 200000;

ll get (ll x) {
    ll ret = 0;
    x += N;
    for (; x; x -= x & -x)
        ret += fen[x];
    return ret;
}

void update (ll x) {
    x += N;
    for (; x < maxn; x += x & -x)
        fen[x] ++;
}

ll check () {
    memset (fen, 0, sizeof fen);
    memset (c, 0, sizeof c);
    for (int i = 1; i <= n; i++)
        c[i] = c[i - 1] + b[i] - (b[i] == 0);

    update (0);
    ll ret = 0;
    for (int i = 1; i <= n; i++) {
        ret += get (c[i] - 1);
        update (c[i]);
    }
    return ret;
}

void build (ll x) {
    for (int i = 1; i <= n; i++)
        b[i] = (a[i] < x);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll tot = n * (n + 1) / 2;
    ll lo = 0, hi = 1000ll * 1000 * 1000 * 1000 + 1;
    while (hi - lo > 1) {
        ll mid = (lo + hi) >> 1;
        build (mid);
//      cout << lo << " " << mid << " " << hi << " -> " << check () << " " <<  tot / 2 + 1 << endl;
        if (check () > tot / 2)
            hi = mid;
        else
            lo = mid;
    }
    cout << lo << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vector<string> v(n);
  REP(i,n)cin>>v[i];

  ll l=0,r=0;
  REP(i,n){
    REP(j,v[i].size()){
      if(v[i][j]=='(')
        l++;
      else
        r++;
    }
  }
  if(l!=r){
    no;
    return 0;
  }

  vpl before, after;
  REP(i,n){
    ll k=v[i].size();
    ll a=0,b=0;
    REP(j,k){
      if(v[i][j]==')'){
        if(b>0)
          b--;
        else
          a++;
      }
      else
        b++;
    }

    for(ll j=k-1; j>=0; j--){
      if(v[i][j]=='('){
        if(a>0)
          a--;
        else
          b++;
      }
      else
        a++;
    }

    if(b-a>0)
      before.push_back(pll(a,i));
    else
      after.push_back(pll(b,i));
  }


  sort(ALL(before));
  sort(ALL(after),greater<pll>());

  string ans="";
  for(auto b:before)
    ans+=v[b.SE];
  for(auto a:after)
    ans+=v[a.SE];

  ll k=ans.size();
  ll a=0;
  REP(j,k){
    if(ans[j]==')'){
      if(a>0)
        a--;
      else{
        no;
        return 0;
      }
    }
    else
      a++;
  }

  yes;


}



Measured memory_bytes: 52852
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


/**
 * Lesson4C　２つの整数 a, b と１つの演算子 op を読み込んで、a op b を計算するプログラム
 * ただし、演算子 op は、"+"(和)、"-"(差)、"*"(積)、"/"(商)、のみとし、
 * 割り算で割り切れない場合は、小数点以下を切り捨てたものを計算結果とします。
 * @author 前島佑介
 * @version 2014/12/1
 */
class Main {

	// プログラムのエントリポイント
	public static void main(String[] args) {

		//入力値1つ目
		int intNum1 = 0;

		//入力値3つ目
		int intNum3 = 0;

		//答えを初期化
		int intAnswer = 0;

		try{
			//キーボードからの入力準備
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			//入力値を保存する場所
			ArrayList<Integer> strArray = new ArrayList<Integer>();

			//キーボードからの入力をString型で受け取る初期化
			String strLine = "";

			while(true) {
				//キーボードからの入力をString型で受け取る
				strLine = br.readLine();

				//文字列の分割:入力値を" "で分ける
				//分けた文字列はstrLineAry[0]とstrLineAry[1]とstrLineAry[2]に分けられる
				String[] strLineAry = strLine.split(" ");


				//入力値の１つ目の値
				intNum1 = Integer.parseInt(strLineAry[0]);

				//２つ目の値
				intNum3 = Integer.parseInt(strLineAry[2]);

				//足し算
				if(strLineAry[1].equals("+")) {
					intAnswer = intNum1 + intNum3;

				//引き算
				}else if(strLineAry[1].equals("-")) {
					intAnswer = intNum1 - intNum3;

				//掛け算
				}else if(strLineAry[1].equals("*")) {
					intAnswer = intNum1 * intNum3;

				//割り算
				}else if(strLineAry[1].equals("/")) {
					intAnswer = intNum1 / intNum3;

				//終了条件
				}else if(strLineAry[1].equals("?")) {
					break;

				//想定外文字のエラー
				}else {
					System.out.println("err");
				}

				//結果を格納
				strArray.add(intAnswer);
			}

			//ループさせる
			for(int i = 0; i < strArray.size(); i++) {

				//出力
				System.out.println(strArray.get(i));
			}

			//例外処理
		}catch(IOException e) {

			//例外時の出力
			System.out.println(e);

		}catch(NumberFormatException e) {

			//数値以外の入力値で出力
			System.out.println("数値で入力して下さい");
		}
	}
}

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

using ll = long long;

int main() {
    int h, w; cin >> h >> w;
    vector<string> a(h);
    for(int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    vector<bool> row(h), col(w);
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(a[i][j] == '#') {
                row[i] = col[j] = true;
            }
        }
    }

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(row[i] && col[j]) cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int N, D, i, j, k, a;
	double r, r_i, r_f;
	cin >> N >> D;
	r = 0;
	a = 0;
	
	int **array = new int*[N];
	for (i = 0; i < N; i++) {
		array[i] = new int[D];
	}

	for (i = 0; i < N; i++)
	{
		for (j = 0; j < D; j++)
		{
			cin >> array[i][j];
		}
	}

	for (i = 0; i < N-1; i++)
	{
		for (j = i+1; j < N; j++)
		{
			for (k = 0; k < D; k++)
			{
				r += (array[i][k] - array[j][k])*(array[i][k] - array[j][k]);
			}
			r = sqrt(r);
			r_i = 0;
			r_f = modf(r, &r_i);
			if (r_f == 0.0) a++;
			r = 0;
		}
		
	}

	cout << a << endl;


	for (i = 0; i < N; i++) {
		delete[] array[i];
	}
	delete[] array;

	return 0;
}

Measured memory_bytes: 256
import java.lang.Math

fun main(args: Array<String>) {
    readInputLine()
    val XArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    var ans = Int.MAX_VALUE

    for (i in 1..100) {
        var tmp = 0
        for (X in XArr) {
            tmp += (X - i) * (X - i)
        }
        ans = Math.min(ans, tmp)
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

long lowestCommon(long long n,long long m){
    if (n >= m){
        if (n % m == 0){
            return m;
        }else{
            return lowestCommon(m,n % m);
        }
    }else{
        return lowestCommon(m,n);
    }
}

int main()
{
    // 整数の入力
    long long N,K,lc,temp,i;
    vector<long long> A;
    cin >> N >> K;
    cin >> lc;
    A.push_back(lc);
    for (i=0;i<N-1;i++){
        cin >> temp;
        A.push_back(temp);
        lc = lowestCommon(lc,temp);
    }


    for (i=0;i<N;i++){
        if (A[i]== K || ( A[i] > K && ((A[i] - K) % lc) == 0 )){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

class Graph
{
public:
	int vertex;
	vector<vector<int>> adj;
	vector<int> visited;
public:
	Graph(int vertex);
	void dfs(int source, int &count);
};

Graph :: Graph(int vertex)
{
	this->vertex = vertex;
	adj.resize(vertex);
}

void Graph :: dfs(int source, int &count)
{
	visited[source] = true;
	count++;

	for(auto &child : adj[source])
		if(not visited[child])
			dfs(child, count);

}

void solve()
{
	int vertex, edges;
	cin >> vertex >> edges;

	Graph g(vertex);

	for(int i = 0; i < edges; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;

		g.adj[u].push_back(v);
		g.adj[v].push_back(u);
	}

	g.visited.assign(vertex, false);
	int res = 0;
	for(int i = 0; i < vertex; i++)
	{
		if(not g.visited[i])
		{
			int count = 0;
			g.dfs(i, count);
			res = max(res, count);
		}
	}
	cout << res << endl;
}

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

	solve();
	return 0;
}


Measured memory_bytes: 24224
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << '\n';
  return 0;
}


Measured memory_bytes: 3652
// AOJ 2460: Dial Key
// 2017.11.13 bal4u@uu

#include <stdio.h>

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m;
	
	fgets(p=buf, 20, stdin), n = getint(), p++, m = getint();
	while (m--) {
		fgets(p=buf, 20, stdin);
		n = gcd(n, getint());
	}
	puts(n == 1 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1812