akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	int n; cin >> n;
	string s; cin >> s;
	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	string left = s.substr(0, n / 2);
	string right = s.substr(n / 2);
	if (left == right) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

long divider(long a, long b){
    if (a == b){
        return a;
    }
    while (b != 0){
        long remain = (long) a%b;
        a = b;
        b = remain;
    }
    return a;
}

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

    int x;
    long n;

    cin >> x >> n;

    long a[x+1];
    a[0] = n;

    for (int i=0;i<x;i++){
        cin >> a[i+1];
    }

    sort(a,a+x+1);

    long b[x];
    for (int j=0;j<x;j++){
        b[j] = a[j+1]-a[j];
    }

    sort(b,b+x);
    long first;
    if (x == 1){
        first = b[0];
    }
    else{
        first = divider(b[x-1],b[x-2]);
    }

    for (int k=x-3;k>=0;k--){
        if (first > b[k]){
            first = divider(first, b[k]);
        }
        else{
            first = divider(b[k], first);
        }
    }

    if (first == 0){
        first = 1;
    }

    cout << first << endl;

    return 0;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

struct adj {
	vector<int>to;
	vector<int>d;
};

int main() {
	cin >> N >> M;
	vector<adj>a(N + 1);
	vector<int>x(N + 1, -1);
	vector<int>flag(N + 1, 0);
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> D;
		a[L].to.push_back(R);
		a[L].d.push_back(D);
	}
	for (int i = 1; i <= N; i++) {
		if (flag[i])continue;
		queue<int>q;
		q.push(i);
		x[i] = 0;
		while (!q.empty()) {
			int now = q.front(); q.pop();
			flag[now] = i;
			for (int j = 0; j < a[now].to.size(); j++) {
				int next = a[now].to[j];
				if (flag[next]==i) {
					if (x[next] != x[now] + a[now].d[j]) {
						cout << "No" << endl;
						return 0;
					}
					continue;
				}
				x[next] = x[now] + a[now].d[j];
				flag[next] = i;
				q.push(next);
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 12032
import java.util.*;
import java.text.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
       String a = sc.next();
        DateFormat df1 = new SimpleDateFormat("MMyy");
        DateFormat df2 = new SimpleDateFormat("yyMM");
        df1.setLenient(false);
        df2.setLenient(false);
        String s="";
        try{
            df1.parse(a);
            s="MMYY";
            df2.parse(a);
            s="AMBIGUOUS";
        } catch (ParseException e) {
            try{
                df2.parse(a);
                s="YYMM";
            }catch (Exception f){

            }
        }
        if(s.equals("")){
            s="NA";
        }
        System.out.println(s);

    }
}


Measured memory_bytes: 22096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  sort(A.begin(),A.end());

  if(A[0]+1<A.back()){
    cout<<"No"<<endl;
    return 0;
  }else if(A[0]==A.back()){
    if(A[0]==N-1||A[0]<=N/2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }

  int ind=0;
  for(int i=0;i<N;i++){
    if(A[i]!=A.back()) ind++;
  }

  int rest=N-ind;
  if(rest==1){
    cout<<"No"<<endl;
    return 0;
  }

  if(ind+1<=A.back()&&A.back()<=ind+rest/2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

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

using namespace std;

ll cal(ll k){
    ll sum = 0;
    for (ll i = 1; i <= k; ++i)
    {
        sum += i;
    }
    if(k <= 0) return 0;
    else return sum;
}

int main() {

    int h,w; cin >> h >> w;
    vector<string> s(h);
    int count = 0;
    rep(i,h) cin >> s[i];

    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.') {
                count = 0;
                for (int x = -1; x <= 1; x++) {
                    for (int y = -1; y <= 1; y++) {
                        if (i + x >= 0 && i + x <= h - 1 && j + y >= 0 && j + y <= w - 1) {
                            if (!(x == 0 && y == 0)) {
                                if (s[i + x][j + y] == '#') {
                                    count++;
                                }
                            }
                        }
                    }
                }
                s[i][j] = ('0' + count);
            }
        }
    }

    rep(i,h) {
        rep(j, w) {
            cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}











Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

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

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

	int ans = b[0] + b[n-2];
	for (int i = 0; i < n - 2; i++) {
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 1e6 + 100, OO = 1e9 + 7, T = 410, M = 998244353, P = 6151, SQ = 800, lg = 32;
typedef pair <int, int> pii;

int32_t main() {
	use_fast;
	ld n;
	cin >> n;
	ld f = n / 3;
	f = f * f * f;
	se(10);
	cout << f << endl;
	return 0; 
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char s[100009], a[100009], d[4][2] = { {'S','S'},{'S','W'},{'W','S'},{'W','W'} };
int main()
{
	int n, i, j, f1 = 0,f2=0,f=0;
	scanf("%d%s", &n,s);
	for (j = 0; j < 4; j++)
	{
		f1 = 0; f2 = 0;
		a[0] = d[j][0];
		a[1] = d[j][1];
		for (i = 2; i < n; i++)
		{
			if (s[i - 1] == 'o')
			{
				if (a[i - 1] == 'S')a[i] = a[i - 2];
				else
				{
					if (a[i - 2] == 'S')a[i] = 'W';
					else a[i] = 'S';
				}
			}
			else
			{
				if (a[i - 1] == 'S')
				{
					if (a[i - 2] == 'S')a[i] = 'W';
					else a[i] = 'S';
				}
				else a[i] = a[i - 2];
			}
		}
		if ((a[0] == 'S'&&s[0] == 'o'&&a[n - 1] == a[1]) || (a[0] == 'S'&&s[0] == 'x'&&a[n - 1] != a[1]) || (a[0] == 'W'&&s[0] == 'o'&&a[n - 1] != a[1]) || (a[0] == 'W'&&s[0] == 'x'&&a[n - 1] == a[1]))f1 = 1;
		if ((a[n - 1] == 'S'&&s[n - 1] == 'o'&&a[n - 2] == a[0]) || (a[n - 1] == 'S'&&s[n - 1] == 'x'&&a[n - 2] != a[0]) || (a[n - 1] == 'W'&&s[n - 1] == 'o'&&a[n - 2] != a[0]) || (a[n - 1] == 'W'&&s[n - 1] == 'x'&&a[n - 2] == a[0]))f2 = 1;
		if(f1&&f2)
		{
			f = 1;
			break;
		}
	}
	if (f)printf("%s\n", a);
	else printf("-1\n");
	return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (!n) break;
    vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 1000000;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        if (abs(a[i] - a[j]) < ans) ans = abs(a[i] - a[j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3104
n = str(input())

len_n = len(n)-1

ans = 0
total = 0

for i in range(2**len_n):
    temp = n[0]
    for j in range(len_n):
        if (i >> j) & 1:
            temp += '+'
        temp += n[j+1]
    total = list(map(int, temp.split('+')))
    ans += sum(total)

print(ans)

Measured memory_bytes: 9180
import sys
from copy import deepcopy
def gcd(a, b):
    if b > a:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

def process(arr):
    L = [0]*(n+1)
    for i in range(1, n+1):
        gcd1 = gcd(L[i-1], arr[i-1])
        L[i] = gcd1
    R = [0]*(n+1)
    for i in range(1, n+1):
        gcd2 = gcd(R[-1-i+1], arr[-1-i+1])
        R[-1-i] = gcd2
    return L, R
    
n = int(raw_input())
arr = map(int, raw_input().split())
if n <= 2:
    print max(arr)
    exit()
L, R = process(arr)
M = [-1] * (n+1)
for i in range(n):
    M[i] = gcd(L[i], R[i+1])

print max(M)


Measured memory_bytes: 11424
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    int g = 0, w = 0, y = 0, p = 0;

    for (int i = 0; i < N;i++){
        cin >> s[i];
        if(s[i]=="G"&&g==0){
            g++;
        }else if(s[i]=="W"&&w==0){
            w++;
        }else if(s[i]=="Y"&&y==0){
            y++;
        }else if(s[i]=="P"&&p==0){
            p++;
        }
    }
    if((g+w+y+p)==4){
        cout << "Four";
    }else if((g+w+y+p)==3){
        cout << "Three";
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=998244353;

int64_t my_pow(int64_t a,int64_t p)
{
  int64_t ans=1;
  for (int i = 0; i < p; ++i)
  {
    ans*=a;
    ans%=mod;
  }
  return ans;
}

int main()
{
  int64_t n;
  cin>>n;
  vector<int64_t> dist(n);
  for(auto&& e: dist) 
  {
    cin>>e;
  }
  map<int64_t,int64_t> map;
  for(const auto& e: dist) 
  {
    map[e]++;
  }
  vector<int64_t> vec;
  bool flag=false;
  for(const auto& e:map)
  {
    if(e.first!=vec.size()) flag=true;
    vec.push_back(e.second);
  }
  if(dist[0]!=0 || map[0]!=1 || flag)
  {
    cout<<0<<endl;
    return 0;
  }
  int64_t ans=1;
  for (int i = 2; i < vec.size(); ++i)
  {
    ans*=my_pow(vec[i-1],vec[i]);
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8444
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    mp[a]++;
  }

  int cnt = 0;
  for(auto itr = mp.begin() ; itr!=mp.end() ; itr++){
    if(itr->second%2==1) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        long H = nextLong();
        System.out.println(attacks(H));
    }

    private static long attacks(long h) {
        if (h == 1) return 1;
        return 1 + 2*attacks(h/2);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

Measured memory_bytes: 21332
import sys
readline = sys.stdin.readline

sx,sy,tx,ty = map(int,readline().split())

xdist = tx - sx
ydist = ty - sy

ans = "R" * xdist + "U" * ydist + "L" * xdist + "D" * ydist

ans += "L" + (ydist + 1) * "U" + "R" * (xdist + 1) + "D"
ans += "R" + (ydist + 1) * "D" + "L" * (xdist + 1) + "U"

print(ans)

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
G = [readline().rstrip() for i in range(H)]
DIV = 10 ** 9 + 7

dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1
for i in range(H):
  for j in range(W):
    if G[i][j] == "#":
      dp[i + 1][j + 1] = 0
      continue
    dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
    dp[i + 1][j + 1] %= DIV
    
print(dp[-1][-1])

Measured memory_bytes: 49696
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;
using P=pair<int,int>;
using Pl=pair<ll,ll>;

//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

int main() {
  string s;cin >> s;
  ll n= s.size();
  ll k;cin >> k;
  
  rep(i,min(n,k)){
    if(s[i]>'1'){cout << s[i];return 0;}
  }
  cout << 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int64_t dp[101][100001];
 
int64_t recurse(auto& v, auto& w, int64_t i, int64_t m) {
    if(i < 0 or !m) return 0;
	int64_t& state = dp[i][m];
  	if(state != -1) return state;
  	state = numeric_limits<int64_t>::min();
  	if(m >= w[i]) {
    	state = max(state, recurse(v, w, i - 1, m - w[i]) + v[i]);
    }
  	state = max(state, recurse(v, w, i - 1, m));
    return state;
}
 
signed main() {
  	int64_t n, m; cin >> n >> m;
  	vector<int64_t> v(n), w(n);
  	for(int i = 0; i < n; ++i) {
  	    cin >> w[i] >> v[i];
  	}
  	memset(dp, -1, sizeof dp);
 	cout << recurse(v, w, n - 1, m);
	return 0;
}


Measured memory_bytes: 79104
#include<stdio.h>
int main()
{
   long long int n,sum=0,p,d;
    
    scanf("%lld",&n);
    d=n;
   long long int a,b;
    while(n!=0)
    {
       p=n%10;
        n=n/10;
        sum=sum+p; 
        
        
    }
    if(d%sum==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;

int n, a[N], b[N];
map<int, int> to;

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i)  {
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; ++i) {
		to[b[i]] = i;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if ((i & 1) ^ (to[a[i]] & 1)) ++ans;
	}
	cout << ans / 2 << endl;
	return 0;
}


Measured memory_bytes: 5760
package main

import (
	"fmt"
)

func main() {
	var num int
	fmt.Scanf("%d", &num)

	fmt.Println(calc(num))
}

func calc(num int) int {
	var ret int
	var a, b, c int
	for a = 1; a <= num; a++ {
		for b = 1; b <= num; b++ {
			for c = 1; c <= num; c++ {
				ret = ret + gcd(gcd(a, b), c)
			}
		}
	}
	return ret
}
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}


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

using namespace std;

int main(){
    char c1[3], c2[3];
    cin >> c1[0] >> c1[1] >> c1[2];
    cin >> c2[0] >> c2[1] >> c2[2];

    char _c1[3], _c2[3];
    _c1[0] = c2[2];
    _c1[1] = c2[1];
    _c1[2] = c2[0];
    _c2[0] = c1[2];
    _c2[1] = c1[1];
    _c2[2] = c1[0];

    bool isSame = true;
    for(int i = 0; i < 3; i++){
        if(c1[i] != _c1[i]) isSame = false;
        if(c2[i] != _c2[i]) isSame = false;
    }

    if(isSame){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline
import bisect


def ch_to_int(c):
    return ord(c) - 96


def main():
    s = input()
    t = input()
    pos = 0
    count = 0
    ch = [[] for i in range(27)]

    for i in range(len(s)):
        ch[ch_to_int(s[i])].append(i)

    for i in range(len(t)):
        c = ch_to_int(t[i])
        li = ch[c]

        if len(li) == 0:
            pos = -1
            count = 0
            break

        next_index = bisect.bisect_left(li, pos)
        # print(next_index, pos, li)
        if next_index >= len(li):
            next_pos = li[0]
            count += 1
            pos = next_pos + 1
        else:
            if pos == li[next_index]:
                pos += 1
            else:
                pos = li[next_index] + 1
        # print(li, next_index, pos, count)

    print(pos + count * len(s))


if __name__ == '__main__':
    main()


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

int main() {
  int n,c=1;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin>>v.at(i);
  sort(v.begin(),v.end());
  for(int i=1;i<n;i++){
    if(v.at(i)!=v.at(i-1))
      c++;
  }
  cout<<c<<endl;
}


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

int main()
{
	int n;
	cin >> n;
	int A[n];

	int colors[9] = {0,0,0,0,0,0,0,0,0};
	for(int i = 0; i < n; i++){
		cin >> A[i];
		if(A[i] < 3200){
			colors[A[i] / 400]++;
		}else{
			colors[8]++;
		}
	}

	int ansmin = 0;		
	for(int i = 0; i < 8; i++){
		if(colors[i] > 0)
			ansmin++;
	}

	int ansmax = ansmin + colors[8];

		if(ansmin == 0)
		ansmin = 1;

	cout << ansmin << " " << ansmax << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;
const int mod=1000000007;
int main(){
  int n,m;
  cin>>n>>m;
  //  vector<int> a(m);
  int a[100000];
  if(m!=0){
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  }
  long long dp[100010]={};
  int k=0;
  dp[0]=1;
  dp[1]=1;
  if(a[0]==1){
    dp[1]=0;
    k++;
  }
  for(int i=2;i<=n;i++){
    if(i!=a[k]){
      dp[i]=dp[i-1]+dp[i-2];
    }
    else{
      dp[i]=0;
      k++;
    }
    dp[i]%=mod;
  }
  cout<<dp[n]<<endl;
  return 0;
}


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

int main(void){
   int a, b ,c;
   cin >> a >> b >> c;

   for(int i = 1; i <= b; i++){
       if((a * i ) % b == c){
           cout << "YES" << endl;
           return 0;
       }
   }

   cout << "NO" << endl;
   return 0;
}

Measured memory_bytes: 256
# encoding: utf-8
N, K = map(int, input().split())

ans = 0
for a in range(1, N + 1):
    # find a (a, b, c)
    # maybe TLE
    # for b in range(1, N + 1):
    #     if (a + b) % K == 0: break
    # for c in range(1, K + 1):
    #     # c and c + K returns same result
    #     if (b + c) % K == 0 and (a + c) % K == 0: break
    #     else: continue
    # else:
    #     continue # next a
    if (K - 2 * a) % K: continue
    b = K - (a % K)
    c = K - b            
    # b_min, c_min
    b_min = K - (K - b) % K
    c_min = K - (K - c) % K
    # b_max, c_max
    b_max = N - (N - b_min) % K
    c_max = N - (N - c_min) % K
    # add
    # print(a, b, c, (b_min, b_max), (c_min, c_max))
    ans += ((b_max - b_min) // K + 1) * ((c_max - c_min) // K + 1)

print(ans)

Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]
a.insert(0,-1)
ans = 0

tmp = 1
for i in range(1,n+1):
    current = a[tmp]
    ans += 1
    if current == 2:
        print(ans)
        exit()
    else:
        tmp = current

print(a[0])

Measured memory_bytes: 7084
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            //var s = Console.ReadLine().Split(' ')
            var s = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            Array.Sort(s);
            var ans = s[n - 1];
            if (!(n == 2))
            {
                if (n % 2 == 0)
                {
                    int num = n / 2 - 1;
                    for (int i = 1; i <= num; i++)
                    {
                        ans += 2 * s[n - 1 - i];
                    }
                }
                else
                {
                    int num = n / 2 - 1;
                    for (int i = 1; i <= num; i++)
                    {
                        ans += 2 * s[n - 1 - i];
                    }
                    ans += s[n - 2 - num];
                }
            }

            WriteLine(ans);
            Out.Flush();
        }



    }

    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }


}

Measured memory_bytes: 47732
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();
		int c = sc.nextInt();
		sc.close();

		double menseki = (double)a * b * Math.sin(c * Math.PI/180) / 2;
		System.out.println(menseki);

		double another = Math.pow( (a*a + b*b - 2*a*b * Math.cos(c * Math.PI/180) ), 0.5);
		System.out.println(a + b + another);

		double height = Math.sin(c * Math.PI/180) * b;
		System.out.println(height);

	}
}

Measured memory_bytes: 26252
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)c("bust")
	else c("win")
}


Measured memory_bytes: 256
'use strict';
(function(input){
  input=input.trim().split('').map(x=>x-0);
  let a=false;
  for(let i=0;i<=2;i++){
    a=a||(input[i]===input[i+1]);
  }
  let ans=(a?'Bad':'Good');
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 7372
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if(N%2==0){
      System.out.println(N);
    }
    else{
      System.out.println(2*N);
    }
  }
}

Measured memory_bytes: 23380
using System;
using System.Collections.Generic;

namespace ALDS1_2_D
{
    class Program
    {
        static int count;

        static void Main(string[] args)
        {
            int n;
            n = int.Parse(Console.ReadLine());

            int[] array = new int[n];

            for(int i = 0; i < n; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
            }

            ShellSort(array, n);
        }

        static int InsertionSort(int[] array, int n, int g)
        {
            int j;
            int tmp;

            for(int i = g; i < n; i++)
            {
                tmp = array[i];
                j = i - g;
                while( (j >= 0) && (array[j] > tmp) )
                {
                    array[j + g] = array[j];
                    j = j - g;
                    count++;
                }
                array[j + g] = tmp;
            }

            return 0;
        }

        static int ShellSort(int[] array, int n)
        {
            count = 0;

            List<int> G = new List<int>();

            for(int i = 1; i <= n; i = i * 3 + 1)
            {
                G.Add(i);
            }

            for(int i = 0; i < G.Count; i++)
            {
                InsertionSort(array, n, G[(G.Count-1) - i]);
            }

            Output(array, G);
            return 0;
        }

        static void Output(int[] array, List<int> G)
        {
            int m = G.Count;

            Console.WriteLine(m);

            for(int i = 0; i < m; i++)
            {
                Console.Write(G[(m - 1) - i]);
                if(i == m - 1)
                {
                    Console.Write("");
                }
                else
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();

            Console.WriteLine(count);

            for(int i = 0; i < array.Length; i++)
            {
                Console.WriteLine(array[i]);
            }

            return;
        }
    }
}



Measured memory_bytes: 25488
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007

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

    ll n,a,b;
    cin>>n>>a>>b;

    ll d = n/(a+b);
    ll r = n%(a+b);
    if(r >= a){
        cout<<d*a + a<<endl;
    }else if(a >r){
        cout<<d*a + r<<endl;
    }


}

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

int main()
{
    int a,b;
    char op;

    cin >> a >> op >> b;
    int c;

    while(op == '+' || op == '-' || op == '*' || op == '/')
    {
        if(op == '+') c = a + b;
        else if(op == '-') c = a - b;
        else if(op == '*') c = a * b;
        else c = a / b;

        cout << c << endl;
        cin >> a >> op >> b;
    }

    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

int A[3][3];

int main(){
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
    cin>>A[i][j];
    }
  }

  int N;
  cin>>N;
  int b[N];
 for(int i = 0; i < N; i++){
 	cin>>b[i];
 }
  for(int n = 0; n < N; n++){
  	for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
  		if(b[n] == A[i][j])
        A[i][j] = 0;
      }
  	}
  }
  bool flag = true;
  //横の判定
  for(int i = 0; i < 3; i++){
    if(flag == false) break;
  	if(A[i][0] == 0 &&
       A[i][1] == 0 && 
       A[i][2] == 0)
      flag = false;
  }
    for(int i = 0; i < 3; i++){
    if(flag == false) break;
  	if(A[0][i] == 0 &&
       A[1][i] == 0 && 
       A[2][i] == 0)
      flag = false;
  }
  
  if(A[0][0] == 0 &&
     A[1][1] == 0 && 
     A[2][2] == 0)
    flag = false;
  
  if(A[0][2] == 0 &&
     A[1][1] == 0 && 
     A[2][0] == 0)
    flag = false;
  
  if(flag == false){ 
    cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
class UnionFind
  def initialize(size) @a = Array.new(size, -1) end
  def root(x) @a[x] < 0 ? x : @a[x] = root(@a[x]) end
  def same?(x, y) root(x) == root(y) end
  def size(x) return -@a[root(x)] end

  def unite(x, y)
    x = root(x)
    y = root(y)
    return false if x == y

    x,y = y,x if @a[x] > @a[y]
    @a[x] += @a[y]
    @a[y] = x
    true
  end
end

n,m = gets.chomp.split.map(&:to_i)
uf = UnionFind.new(n+1)

m.times do
  a,b = gets.chomp.split.map(&:to_i)
  uf.unite(a,b)
end

s = Set.new
1.upto(n) do |i|
  s.add uf.root(i)
end

puts s.size - 1


Measured memory_bytes: 20136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node*)malloc(sizeof(struct Node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x -> key){
      x = x -> left;
    } else{
      x = x -> right;
    }
  }
  z -> parent = y;
  if(y == NIL){
    root= z;
  } else{
    if(z -> key < y -> key){
      y -> left = z;
    } else{
      y -> right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL) return ;
  inorder(u -> left);
  printf(" %d",u -> key);
  inorder(u -> right);
}

void preorder(struct Node *u){
  if(u == NIL) return ;
  printf(" %d",u -> key);
  preorder(u -> left);
  preorder(u -> right);
}

int main(){
  int n,i,x;
  char str[7];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(str,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
import math
import fractions
import copy
import numpy as np
#以下てんぷら
def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
type = [0 for i in range(4)]
s = 0
for i in a:
    s+=i.count("AB")
    if i[0] == 'B' and i[-1] == 'A': type[0]+=1    # B***A
    elif i[0] == 'B' and i[-1] != 'A': type[1]+=1  # B****
    elif i[0] != 'B' and i[-1] == 'A': type[2]+=1  # ****A
    elif i[0] != 'B' and i[-1] != 'A': type[3]+=1  # *****
if type[0] == 0:
    s+=min(type[1],type[2])
else:
    if type[1] or type[2]:
        s+=type[0]+ min(type[1],type[2])
    else:
        s+=type[0]-1
print(s)



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

int main(){
  
  int N,i,sum = 0;
  cin >> N;
  
  for(i = 0;i < N;i++){
    int l,r;
    cin >> l >> r;
    cout << endl;
    sum += (r - l) + 1;
  }
  cout << sum << endl;
}

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();
		double o = 0;
		for (int i = 1; i <= N; i++) {
			if (i%2 != 0) {
				o++;
			}
		}
		System.out.println(o/N);
	}
}

Measured memory_bytes: 21972
import java.util.*;

public class Main {// Main
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n =sc.nextInt();
		int m = sc.nextInt();
		
		char [][] ch = new char[n][m];
		for(int i = 0 ;i < n;i++) {
			String str = sc.next();
			for(int j = 0 ;j < m;j++) {
				ch[i][j] = str.charAt(j);
			}
		}
		
		long dp[][] = new long[n+1][m+1];
		dp[n-1][m] = 1;
		long mod = 1000000007L;
		for(int i = n-1 ; i>=0 ;i--) {
			for(int j = m-1 ;j >=0 ;j--) {
				if(ch[i][j]=='#')continue;
				dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % mod ;
			} 
		}
		
  System.out.println(dp[0][0]);
	}
	
	

	static TreeMap<Integer , ArrayList<Integer> > map ;

	public static TreeMap<Integer , ArrayList<Integer> > directed(int n , int m  ) throws Exception{
		TreeMap<Integer , ArrayList<Integer> > map = new TreeMap<>();
		for(int i = 1 ;i<=n ;i++)map.put(i, new ArrayList<Integer>());
		for(int i = 1 ;i <= m ;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			map.get(a).add(b);
		}
		return map;
	}
}

Measured memory_bytes: 51564
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);

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

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

// 垂直二等分線
Line bisector(Point a, Point b){
    Point A = (a + b) * Point(0.5, 0);
    return Line(A, A + (b - a) * Point(0, pi / 2));
}

// 直線と直線の交点
Point getCrossPointLL(Line l1, Line l2){
    double a = cross(l1.second - l1.first, l2.second - l2.first);
    double b = cross(l1.second - l1.first, l1.second - l2.first);
    if(abs(a) < EPS && abs(b) < EPS) return l2.first;
    return l2.first + (l2.second - l2.first) * (b / a);
}

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

    int n; cin>>n;
    while(n--){
        double x1, y1, x2, y2, x3, y3; cin>>x1>>y1>>x2>>y2>>x3>>y3;
        Point p1 = Point(x1, y1), p2 = Point(x2, y2), p3 = Point(x3, y3);
        Line l1 = bisector(p1, p2), l2 = bisector(p1, p3);
        Point p = getCrossPointLL(l1, l2);
        double r = abs(p - p1);
        printf("%.3f %.3f %.3f\n", p.X, p.Y, r);
    }

    return 0;
}


Measured memory_bytes: 3212
import sys

def hantei(s,t):
  for i in range(len(s)):
    if s[i] == t[i] or s[i] == '?':
      pass
    else:
      return False
    
  return True

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

for i in reversed(range(len(s)-len(t)+1)):
  if hantei(s[i:i+len(t)], t):
    for j in range(len(t)):
      s[i+j] = t[j]
        
    print(''.join(s).replace('?', 'a'))
    sys.exit(0)
    
print("UNRESTORABLE")

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

int main() {
int A,B;
cin >> A >> B;

if (A != 1 && B != 1) {
  cout << "1" << endl;
} else if (A != 2 && B != 2) {
  cout << "2" << endl;
} else {
  cout << "3" << endl;
}

return 0;
}

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

/*
  let's try computer shogi!!!
  大きい順番にsortして、2つペアがあったやつを上から採用すればよし。
 */

int main(){
  long int N;
  std::vector<long int> points;

  cin >> N;
  points.resize(N);
  
  for(long int i=0;i<N;++i){
    cin >> points[i];
  }
  sort(points.begin(),points.end());

  long int before = -1;
  long int l1 = 0;
  long int phase = 0;
  for(long int i=N-1;i>=0;--i){
    if(points[i] == before){
      before = -1;
      if(phase == 0){
	l1 = points[i];
	phase = 1;
      }else{
	cout << l1 * points[i] <<endl;
	return 0;
      }
    }else{
      before = points[i];
    }
  }
  cout<< "0" << endl;
  
  return 0;
  
}

Measured memory_bytes: 1024
# A - Dividing a String
import sys
input = sys.stdin.readline
S = input().strip()
ans, prev, cur = 0, "", ""
for s in S:
  cur += s 
  if cur != prev: # True になるまで、curに文字列を追加していく
    ans += 1
    prev, cur = cur, ""

print(ans)

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

ll nck(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

bool check(string s,int n,int m){
    string t=s.substr(n-1,m);
    string u=s.substr(n-1,m);
    reverse(u.begin(),u.end());
    //cout<<t<<endl;
    //cout<<u<<endl;
    if(u==t) return true;
    else return false;
}

int main(){
    //A
    /*
    int N,M;cin>>N>>M;
    if(N<=1&&M<=1) cout<<0<<endl;
    else cout<<nck(N,2)+nck(M,2)<<endl;
    */
   //B
   /*
   string s;cin>>s;
   int N=s.size();
   //string p="akasaka";
   //cout<<p.substr(5,7)<<endl;
   if(check(s,1,N)&&check(s,1,(N-1)/2)&&check(s,(N+3)/2,N-(N+3)/2+1))
        cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   */
  //C
  /*
  double L;cin>>L; //doubleにしないといけないらしい
  cout<<fixed<<setprecision(10);
  cout<<pow(L/3,3)<<endl;
  */
  //D
  int N;cin>>N;
  vector<int> a(N);
  map<int,int> p;
  rep(i,0,N) {
      cin>>a[i];
      p[a[i]]++;
  }
  ll tot=0;
  for (auto c:p){ //数字の種類毎に考える autoを使うと連想配列pの総数を考えなくて済むね
      int num=c.first;
      ll cnt=c.second;
      tot+=cnt*(cnt-1)/2;
  }
  rep(i,0,N){
      ll ans = tot;//ここに帰ってくるときにansの値が元に戻る
      if(p.count(a[i])){
          int cnt=p[a[i]];
          ans-=cnt*(cnt-1)/2;
          ans+=(cnt-1)*(cnt-2)/2;//nC2=n*(n-1)/2
      //ある種類の数字の条件の方法の数を足さなかったとして、代わりにその数字が一つ少ない場合の条件の方法の数を足す
      }
      cout<<ans<<endl;
  }
}

Measured memory_bytes: 9600
import sys
import itertools
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
c = ['R', 'U', 'L', 'D']
n = int(input())
x = []
y = []
for i in range(n):
  xi, yi = map(int, input().split())
  x.append(xi)
  y.append(yi)
parity = None
for i in range(n):
  if i == 0:
    parity = (x[i] + y[i]) % 2
  elif (x[i] + y[i]) % 2 != parity:
    print(-1)
    sys.exit()
print(40)
d = []
for i in range(20):
  d.append(3**i)
  d.append(3**i)
d[1] += parity
print(*d)
d = [1] * 40
d[1] += parity
for i in range(n):
  for m in range(20):
    for j, k in itertools.product(range(4), range(4)):
      xnew = x[i] - (d[2*m] * dx[j] + d[2*m+1] * dx[k])
      ynew = y[i] - (d[2*m] * dy[j] + d[2*m+1] * dy[k])
      if xnew % 3 == 0 and ynew % 3 == 0:
        x[i] = xnew // 3
        y[i] = ynew // 3
        print(c[j] + c[k], end='')
        break
  print('')

Measured memory_bytes: 4048
#include<stdio.h>

int main (){

  int x=0;
  int y=0;

  scanf("%d",&x);
  if(0<x && x<101){
  y = x*x*x;
  }else{
    printf("again!\n");
  }
 
  printf("%d\n",y);

  return 0;
 }

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
using namespace std;//ok i saw
signed main()
{
    int n,W,i,j,k;
    cin >> n >> W;
    int w[n+1],v[n+1],maxv=0;
    for(i=1 ; i<=n ; i++)
    {
    	cin >> w[i] >> v[i];
    	maxv =max(maxv , v[i]);
    }
    int d[n+1][maxv*n +1];
    int col = maxv*n;
    for(i=0 ; i<=n ; i++)
		for(j=0 ; j<=col ; j++)
			d[i][j] = -1;
	for(i=1 ; i<=col ; i++)
		d[0][i] = -1;
	for(i=0 ; i<=n ; i++)
		d[i][0] = 0;
	int ans = 0;
	for(i=1 ; i<=n ; i++)
	{
		for(j=1 ; j<=col ; j++)
		{
			if(v[i] <= j && (d[i-1][j-v[i]] != -1 ))
				d[i][j] = w[i] + d[i-1][j-v[i]];
			if(d[i-1][j] != -1 && d[i][j] != -1)
				d[i][j] = min(d[i-1][j] , d[i][j]);
			else if(d[i-1][j] != -1 ) 
				d[i][j] = d[i-1][j];
			if(d[i][j] >= 0 && d[i][j] <= W)
				ans = max(ans,j);
				//cout<<d[i][j]<<" ";
		}//cout<<"\n";
	}
	cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 79232
import itertools
import numpy as np

h,w,k = map(int, input().split())

grid = []
ans = 0
for i in range(h):
  grid.append(list(input()))

for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      grid[i][j] = 1
    else:
      grid[i][j] = 0

for v in itertools.product([1,0],repeat=(h+w)):
  grid_dum = np.array(grid.copy())
  for i,x in enumerate(v[:h]):
    if x == 1:
      grid_dum[i,:] = 0 
  for i,x in enumerate(v[h:]):
    if x == 1:
      grid_dum[:,i] = 0 
  if grid_dum.sum() == k:
    ans += 1

print(ans)

Measured memory_bytes: 27100
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
sum = a.inject(:+)
n.times do |i|
  t = [a[i],b[i]].min
  a[i] -= t
  b[i] -= t
  u = [a[i+1],b[i]].min
  a[i+1] -= u
  b[i] -= u
end

p sum - a.inject(:+)


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

int main() {
	string s;
	cin >> s;
	map<char, int> mp;
	for (auto c : s) {
		mp[c]++;
	}
	if (mp.size() == 2 && mp[s[0]] == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPR(I, N) for (int I = (N)-1; I >= 0; --I)
#define REPPR(I, A, B) for (int I = (A); I >= (B); --I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL& x, LL v) {x = (x + v) % MOD; if (x < 0)x += MOD;}
/*}}}*/
void solve() {
	LL n, a, b;
	R(n, a, b);
	W(n / (a + b)*a + min(a, n % (a + b)));
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        
        boolean isExistSharp = false;
        
        String result;
        boolean[] isShowable = new boolean[W];
        boolean[] isLnable = new boolean[H];
        char[][] arr = new char[H][W];
        
        
      
        for(int i = 0; i<H; i++) {
        	isExistSharp = false;
        	String a_i = sc.next();
        		
        	if(!a_i.matches("^\\.+$")) {
        		isLnable[i] = true;
        		for(int j = 0; j<W; j++) {
        			arr[i][j] = a_i.charAt(j);
        		}
        	}
        }
        
        for(int j = 0; j<W; j++) {
        	result = "";
        	isShowable[j] = false;
        	for(int i = 0; i<H; i++) {
        	
        		if(arr[i][j] == '#') {
        			isShowable[j] = true;
        		} 
        	}
        }
        
        for(int i = 0; i<H; i++) {
        	for(int j = 0; j<W; j++) {
        		if(isShowable[j] && arr[i][j] != '\u0000') {
        			System.out.print(arr[i][j]);
        		}
        		
        	}
        	if(isLnable[i]) {
        		System.out.println();
        	}
        }
        
	}

}


Measured memory_bytes: 27472
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

MOD = 10**9 + 7

n()
A = ln()

L = len(A)

A.sort()

if L % 2 == 1:
    c = A[0]
    del A[0]
    B = A[1::2][::-1] + [c] + A[0::2]
else:
    B = A[1::2][::-1] + A[0::2]

for i in xrange(L):
    j = L - i - 1
    if abs(i - j) != B[i]:
        print 0
        break
else:
    print pow(2, len(A) / 2, MOD)


Measured memory_bytes: 24240
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

ll Gcd(ll a,ll b){
    if(a < b)swap(a, b);

	if(a%b == 0)return(b);

	else return(Gcd(b, a%b));
}

int main(){
    ll n, x;
    cin >> n >> x;
    ll dist[n];
    rep(i, n){
        ll x_i;
        cin >> x_i;
        dist[i] = abs(x - x_i);
    }

    ll ans = dist[0];
    for(ll i = 1; i < n; ++i){
        ans = Gcd(ans, dist[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4300
class SCCGraph
    def initialize(n = 0)
      @n, @edges = n, []
    end
  
    def add_edge(from, to); @edges << [from, to]; end
  
    # returns list of strongly connected components
    # the components are sorted in topological order
    # O(N + M)
    def scc
        group_num, ids = scc_ids
        counts = Array.new(group_num, 0)
        ids.each { |x| counts[x] += 1 }
        groups = Array.new(group_num) { [] }
        ids.each_with_index { |x, i| groups[x] << i }
        groups
    end

    def scc_ids
        start, elist = csr
        now_ord = group_num = 0
        visited, low, ord, ids = [], [], [-1] * @n, []
        dfs = ->(v) {
        low[v] = ord[v] = now_ord
        now_ord += 1
        visited << v
        (start[v]...start[v + 1]).each do |i|
            to = elist[i]
            low[v] = if ord[to] == -1
                        dfs.(to)
                        [low[v], low[to]].min
                    else
                        [low[v], ord[to]].min
                    end
        end
        if low[v] == ord[v]
            loop do
            u = visited.pop
            ord[u] = @n
            ids[u] = group_num
            break if u == v
            end
            group_num += 1
        end
        }
        @n.times { |i| dfs.(i) if ord[i] == -1 }
        ids = ids.map { |x| group_num - 1 - x }
        [group_num, ids]
    end
  
    def csr
        start = Array.new(@n+1, 0)
        elist = Array.new(@edges.size)
        @edges.each { |(i, _)| start[i + 1] += 1 }
        @n.times { |i| start[i + 1] += start[i] }
        counter = start.dup
        @edges.each do |(i, j)|
            elist[counter[i]] = j
            counter[i] += 1
        end
        [start, elist]
    end
end

n, m = gets.split.map(&:to_i)
scc = SCCGraph.new(n)

m.times {scc.add_edge(*gets.split.map(&:to_i))}
ans = scc.scc
puts ans.size
ans.each{|e| puts "#{e.size} " + e*" "}

Measured memory_bytes: 100404