akhauriyash/Code-Regression huggingface dataset:
h,w,k = map(int,input().split())
s = [list(map(int,input().strip())) for i in range(h)]
from copy import deepcopy

ss = deepcopy(s)
for i in range(h):
    for j in range(w-1):
        ss[i][j+1] += ss[i][j]


def gru_hol(HOL): # セットから切り方を作る
    groups_a = []
    group_a = [0]
    for i in range(h-1):
        if(HOL[i] == 1):
            groups_a.append(group_a)
            group_a = [i+1]
        else:
            group_a.append(i+1)
    groups_a.append(group_a)
    return groups_a

def nex_hol(HOL): #次のセットを作る
    for j in range(h-1):
        if(HOL[j] == 0):
            HOL[j] = 1
            for k in range(0,j):
                HOL[k] = 0
            break
    return HOL

def cutsum(grp,lscut,nxcut): #groupのlastcut~nextcutのホワイトチョコを数える
    count = 0
    for i in grp:
        if(lscut != 0):
            count = count + ss[i][nxcut-1] - ss[i][lscut-1]
        else:
            count += ss[i][nxcut-1] 
    return count

def cutcheck(grp_a,lscut_a): #切ってもダメかチェック
    ct_a = 0
    for i in grp_a:
        ct_a += s[i][lscut_a]
    if(ct_a > k):
        return False
    else:
        return True

min_cut = h + w - 2
hol = [0]*(h-1)
for i in range(2**(h-1)):
    fl_ag = 0
    lastcut = 0
    cuts = 0 #切る回数
    groups = gru_hol(hol) #groupsを作る
    for j in range(1,w):
        flag = 0
        for group in groups:
            if(cutsum(group,lastcut,j+1) > k):
                if(cutcheck(group,lastcut) == False):
                    fl_ag = 1 #groupからやり直し
                    break
                else:
                    flag = 1
        if(fl_ag == 1):
            break
        if(flag == 1):
            cuts += 1
            lastcut = j

    if(cutcheck(group,w-1) == True):
        min_cut = min(min_cut,cuts+sum(hol))
    nex_hol(hol)

print(min_cut)

Measured memory_bytes: 46428
#include <iostream>
#define nmax 100005
using namespace std;
int a, b, c;
int dp[nmax][3];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);


    return 0;
}


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

using namespace std;

int main(void)
{
    int a, b, k; cin >> a >> b >> k;
    int largest = k;

    vector<int> v;
    
    for(int i = 1; i <= a and i <= b; ++i)
    {
        if(a % i == 0 and b % i == 0)
        {
            v.push_back(i);
        }
    }

    sort(v.begin(), v.end(), greater<int>());
    
    cout << v[k - 1] << endl;

    return 0;
}

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

int main(){
	int n, ac = 0, wa = 0, tle = 0, re = 0;
	scanf("%i", &n);
	char s[n][10];
	for(int i = 0; i < n; i++){
		scanf("%9s", s[i]);
	}
	for(int i = 0; i< n; i++){
		if(!strcmp(s[i], "AC")){
			ac += 1;
			continue;
		}else if(!strcmp(s[i],"WA")){
			wa += 1;
			continue;
		}else if(!strcmp(s[i], "TLE")){
			tle += 1;
			continue;
		}else{
			re += 1;
		}
	}
	printf("AC x %i\n", ac);
	printf("WA x %i\n", wa);
	printf("TLE x %i\n", tle);
	printf("RE x %i\n", re);

	return 0;
}


Measured memory_bytes: 2708
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 21
#define F(a,b) for(register int (a)(0);(a)^(b);(a)++)
using namespace std;
int n,m,a[szxb][szxb-6]={{4,2,0,9,7},{1,10,8,6,4},{9,7,5,3,1},{6,4,2,0,9},{3,1,10,8,6},{0,9,7,5,3},{8,6,4,2,0},{5,3,1,10,8},{2,0,9,7,5},{10,8,6,4,2},{7,5,3,1,10}};
signed main(){scanf("%d%d",&n,&m),n-=2;int sx(n%11),ans(n/11*5);F(i,sx){F(j,5){ans+=(!(a[i][j]-m));}}return printf("%d",ans),putchar(10),0;}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c;
    int maxmum = 50;
    cin >> a >> b >> c;
    maxmum = max(a, max(b, c)); 
    int diff = 3 * maxmum - (a + b + c); 
    if (diff % 2) {
       cout << 1 + (diff + 1) / 2 << endl;
    } else {
       cout << diff / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef unsigned int uint;
typedef long long ll;

int main() {
	char S[4];
	scanf("%s", S);
	
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])printf("Bad");
	else printf("Good");
	




}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <iostream>
#include  <algorithm>
#include <string>
#include  <vector>
using namespace std;
 int main()
{
string s;cin>>s;
int c=0,a=0;

for(int i=2;i<s.size()-1;i++){
if (s[i]=='C'){c++;}
}
for(int i=1;i<s.size();i++){
if (s[i]=='C'){c++;}
else if (islower (s[i])){a++;}
}
if (c==2&&s[0]=='A'&&a==s.size()-2){cout<<"AC";}
else{cout<<"WA";}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int x;
    rep(i,10000) {
        cin >> x;
        if (x == 0) break;
        cout << "Case " << i+1 << ": " << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
 
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
 
#define csh(a,n) memset(a,n,sizeof(a));

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a+1>2*k){
		for(int i=a;i<a+k;i++){
			cout<<i<<endl;
		}
		for(int i=b-k+1;i<=b;i++){
			cout<<i<<endl;
		}
	}
	else{
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}
} 

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


int N;
vector<string> W;


void input() {
    cin >> N;
    W = vector<string>(N);
    rep(i, N) cin >> W[i];
}


int main() {
    input();
    set<string> s;
    s.insert(W[0]);
    for (int i = 1; i < N; i++) {
        if (s.count(W[i])) {
            cout << "No" << endl;
            return 0;
        }
        s.insert(W[i]);
        if (W[i-1].back() != W[i][0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
package main

import (
    . "fmt"
    "strings"
)

func main() {
    var s string
    Scanf("%s", &s)

    ans := 0
    ss := strings.Split(s, "")
    for _, v := range ss {
        if v == "+" {
            ans++
        } else if v == "-" {
            ans--
        }
    }
    Println(ans)
}



Measured memory_bytes: 640
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		String s = saori.nextHayami();
		
		String[] str = s.split("");
		int b = a/2;
		String str2 = " ";
		String str3 = " ";
		for(int i = 0;i < s.length();i++){
			if(i < b){
				str2 += str[i];
			} else{
				str3 += str[i];
			}
		}
		if(str2.equals(str3)){
			System.out.println("Yes");
		} else{
			System.out.println("No");
		}
	
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21332
n, m = map(int, input().split())
a = list(map(int, input().split()))
memo = [0]
d = {0: 1}
for ai in a:
  memo.append((memo[-1] + ai) % m)
  mi = memo[-1]
  if mi in d:
    d[mi] += 1
  else:
    d[mi] = 1
ans = 0
for k in d:
  c = d[k]
  ans += c * (c-1) // 2
print(ans)
  


Measured memory_bytes: 14696
"""
二分探索

pythonでTLE, pypyでAC
"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0

for i in range(n-2):
    l_prev = 0
    for j in range(i+1,n-1):
        if not l_prev:
            l = j; r = n # 前のループで探索した範囲は探索不要なのでもっと高速化できるはず
        else:
            l = l_prev; r = n
        while l+1 < r:
            c = (l+r)//2
            if L[c] < L[i]+L[j]:
                l = c
            else:
                r = c
        ans += l-j
        l_prev = l
        
print(ans)

Measured memory_bytes: 42220
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=1e5+10;
int n,m,ans,size[maxn];
bool vis[maxn];

int main(){
	vis[1]=true;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		size[i]=1;
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		--size[u];++size[v];
		if(vis[u]&&!vis[v])
			vis[v]=true;
		if(!size[u])
			vis[u]=false;
	}
	for(int i=1;i<=n;++i)
		ans+=vis[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int[] cost = {Math.Abs(input[1] - input[0]) + Math.Abs(input[2] - input[1]),
                          Math.Abs(input[2] - input[0]) + Math.Abs(input[1] - input[2]),
                          Math.Abs(input[0] - input[1]) + Math.Abs(input[2] - input[0]),
                          Math.Abs(input[2] - input[0]) + Math.Abs(input[1] - input[2]),
                          Math.Abs(input[0] - input[2]) + Math.Abs(input[1] - input[0]),
                          Math.Abs(input[1] - input[2]) + Math.Abs(input[0] - input[1])};
            Array.Sort(cost);
            Console.WriteLine(cost[0]);
        }

    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        String t = sc.next();

        boolean res = false;
        for (int i = 0; i < s.length; i++) {

            char[] tmpChar = new char[s.length];
            for (int j = 0; j < s.length - 1; j++) {
                tmpChar[j+1] = s[j];
            }
            tmpChar[0] = s[s.length-1];

            s = tmpChar;// 入れ替えをした結果を更新

            // 比較
            String tmpRes = new String(s);
            if (tmpRes.equals(t)) {
                res = true;
                break;
            }
        }

        System.out.println(res ? "Yes" : "No");
    }
}


Measured memory_bytes: 21716
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)//n
ave_=ave+1
ans=0
ans_=0
for i in range(n):
  ans+=(a[i]-ave)**2
for i in range(n):
  ans_+=(a[i]-ave_)**2
print(min(ans,ans_))  

Measured memory_bytes: 9104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		char s[] = scan.next().toCharArray();

		if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
			System.out.println("Yes");
		}else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3]){
			System.out.println("Yes");
		}else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2]) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23124
package main

import (
    "fmt"
)

func main() {
    var s string
    fmt.Scan(&s)
    switch s {
    case "SUN":
        fmt.Println(7)
    case "MON":
        fmt.Println(6)
    case "TUE":
        fmt.Println(5)
    case "WED":
        fmt.Println(4)
    case "THU":
        fmt.Println(3)
    case "FRI":
        fmt.Println(2)
    case "SAT":
        fmt.Println(1)
    }
}


Measured memory_bytes: 512
/*786*/
#include <bits/stdc++.h>

#define pu ios_base::sync_with_stdio();cin.tie(NULL);cout.tie(NULL);

#define ll                  long long
#define yes                 cout<<"Yes"<<endl
#define no                  cout<<"No"<<endl
#define sp                  ' '
#define vi                  vector<int>
#define vl                  vector<ll>
#define pb                  push_back
#define mp                  make_pair
#define f(i,n)              for(i=0;i<n;i++)
#define stop                return 0;
#define new                 cout<<endl
#define res(x)              cout<<x<<endl;
#define vip                 vector<pair<int,int> >
#define srt(v)              sort(v.begin(),v.end());
#define test                int t;cin>>t;while(t--)
#define mx(a)               *max_element(a,a+n)

using namespace std;
int main()
{
    pu;
   string s;
   cin>>s;
   int f=s.find_first_of('7');
   if(f>=0)yes;
   else no;
        stop;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 1e5 + 5;

typedef long long ll;

int n;
int arr [MAX_N];

bool can (int idx) {
  ll sz = arr[idx];

  for (int i = 0; i < n; i++) {
    if (i != idx) {
      if (arr[i] <= 2 * sz) {
        sz += arr[i];
      } else {
        return false;
      }
    }
  }

  return true;
}

int main () {
  ios::sync_with_stdio(false);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);

  if (can(0)) {
    cout << n << endl;
    return 0;
  }

  int ans = 0;
  for (int k = 1 << 17; k != 0; k /= 2) {
    if (ans + k < n && !can(ans + k)) {
      ans += k;
    }
  }

  cout << n - (ans + 1) << endl;
}


Measured memory_bytes: 640
#include <cstring>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	int N, H, W;
	cin >> N >> H >> W;
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			int startx = i;
			int starty = j;
			bool flag = true;
			for (int k = startx; k<startx + H; k++)
			{
				if (k >= N)flag = false;
				for (int t = starty; t < starty + W; t++) {
					if (t >= N)flag = false;
				}
			}
			if (flag)cnt++;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a;
char c[8];
int main () {
	scanf("%lld%s",&a,c+1);
	long long b=a*(c[1]-'0');
	long long d=a*(c[3]-'0');
	long long e=a*(c[4]-'0');
	printf("%lld\n",b+d/10+e/100+((d%10)*10+e%100)/100);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

const int M = 1e5 + 5, N = 1e2 + 5;

int wei[N], v[N], n;
ll dp[N][M]; 

ll f(int i, int w) {
    if (i == n)
        return 0;
    
    if (dp[i][w] != -1)
        return dp[i][w];

    ll mx = f(i + 1, w);
    if (wei[i] <= w)
        mx = max(mx, f(i + 1, w - wei[i]) + v[i]);
    
    return dp[i][w] = mx;
}

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

    int w;
    cin >> n >> w;
    
    for (int i = 0; i < n; i++)
        cin >> wei[i] >> v[i];
    
    memset(dp, -1, sizeof dp);
    cout << f(0, w) << '\n';
    return 0;
}


Measured memory_bytes: 82304
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
string S;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

#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 FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=200005;
struct pnt
{
	double x,y;pnt(){}pnt(double _x,double _y){x=_x;y=_y;}
	friend pnt operator +(pnt n1,pnt n2){return pnt(n1.x+n2.x,n1.y+n2.y);}
	friend pnt operator -(pnt n1,pnt n2){return pnt(n1.x-n2.x,n1.y-n2.y);}
	friend double operator *(pnt n1,pnt n2){return n1.x*n2.y-n2.x*n1.y;}
}sta[MAXN];int tp;
double A[MAXN],B[MAXN],C[MAXN];
double newA[MAXN],newB[MAXN];
int n;
void Shift()
{
	int p=0;
	for(int i=1;i<=n;i++)if(A[i]>A[p])p=i;int t=0;
	for(int i=p+1;i<=n;i++)newA[++t]=A[i];
	for(int i=1;i<p;i++)newA[++t]=A[i];t=0;
	for(int i=p+1;i<=n;i++)newB[++t]=B[i];
	for(int i=1;i<p;i++)newB[++t]=B[i];
	A[0]=A[n]=A[p];B[0]=B[n]=B[p];
	for(int i=1;i<n;i++)A[i]=newA[i],B[i]=newB[i];
}
int main()
{
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	n=read();
	for(int i=1;i<=n;i++)A[i]=read();
	for(int i=1;i<=n;i++)B[i]=read();Shift();
	if(n-1==1)C[1]=B[1];
	else for(int i=2;i<=n;i++)C[i]=2*C[i-1]-C[i-2]-2*B[i-1];
	sta[1]=pnt(0,A[0]+C[0]);sta[2]=pnt(1,A[1]+C[1]);tp=2;
	for(int i=2;i<=n;i++)
	{
		pnt now=pnt(i,A[i]+C[i]);
		while(tp>=2&&(now-sta[tp-1])*(sta[tp]-sta[tp-1])<=0)--tp;
		sta[++tp]=now;
	}double sum=0;
	for(int i=1,p=1;i<n;i++)
	{
		while(p+1<tp&&sta[p+1].x<=i)++p;
		double ans=sta[p].y+(sta[p+1].y-sta[p].y)*((i-sta[p].x)/(sta[p+1].x-sta[p].x));
		ans-=C[i];
		sum+=ans/(1.0*n);
	}
	sum+=A[0]/(1.0*n);
	printf("%.10lf\n",sum);
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


Measured memory_bytes: 14568
#include <stdio.h>

int main(){
    int r, g, b, sum=0;

    scanf("%d %d %d", &r, &g, &b);

    sum += r*100;
    sum += g*10;
    sum += b;

    if(sum % 4 == 0)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

Measured memory_bytes: 128
/**
 *    Author:  "Robin Singh" !!!
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     // 0 -> n-1 (i,0,n)
#define bk(i, j, k) for(int i = j-1; i >= k; i--)  // n-1 -> 0 (i,n,0)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0
#define rtn return 
#define nl "\n"      // avoid endl
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const ld eps = 1e-9;
const ll INF = (1LL<<61);
const int inf = (1<<30);
//-------------------------------------------------------------------------------------------------------------
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//-------------------------------------------------------------------------------------------------------------

const int nn = 505;
int dp[nn][nn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m, q;
    cin >> n >> m >> q;
    while(m--){
        int l, r;
        cin >> l >> r;
        dp[l][r]++;
    }
    // pre process, no need of auxiliary array
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
        }
    }
    
    /* Also, without subtraction
    
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dp[i][j] += dp[i-1][j];
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dp[i][j] += dp[i][j-1];
    */
    
    while(q--){
        int l, r;
        cin >> l >> r;
        
        // b/w (l,l) to (r,r)   as  (1,1) (1,2)
        //                          (2,1)  (2,2)                  same route
        
        int ans = dp[r][r] - dp[l-1][r] - dp[r][l-1] + dp[l-1][l-1];
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'

using namespace std;

int main()
{
    string s;
    cin>>s;
    
    int n = s.length();
    string a = "es";
    string b = "s";
    
    if(s[n-1] == 's') s.append(a);
    else s.append(b);
    
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>

int main() {

	int n,i;

	scanf("%d", &n);
	int a[n-1],c[n];
	for (i = 0; i < n-1; i++) {
		scanf("%d", &a[i]);
	}

	for(i=0;i<n;i++){
		c[i] = 0;
	}

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

	for (i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}

	return 0;
}


Measured memory_bytes: 3292
#ABC 134 C
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
east=[0]*(n+1)
west=[0]*(n+1)
for i in range(1,n+1):
    east[i]=max(east[i-1],a[i-1])
    west[-i-1]=max(west[-i],a[-i])
for k in range(1,n+1):
    print(max(east[k-1],west[k]))

Measured memory_bytes: 15676
n = gets.chomp.to_i
id = []
gain = []
win = {}
tmp = 0
for i in 1..n
a,b = gets.split.map(&:to_i)
id << a
gain << b
if b >= tmp
  tmp = b
end
end
count = 0
for j in gain
if j == tmp
  win[id[count]] = j
end
count += 1
end
result = []
   win.each do |key,value|
  result << key
end
puts [result.min,win[result[0]]].join(" ")


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

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

  int n = 0;
  for (int i = A; i >= 0; i--) {
    if (i * 500 > X)
      continue;
    for (int j = B; j >= 0; j--) {
      if (i * 500 + j * 100 > X)
        continue;
      for (int k = C; k >= 0; k--) {
        if (i * 500 + j * 100 + k * 50 < X) {
          break;
        }
        else if (i * 500 + j * 100 + k * 50 == X) {
          n++;
          break;
        }
      }
    }
  }

  cout << n << endl;
}


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

int main()
{
  int n, count=0;
  string s;
  cin >> n >> s;
  int flag=0;
  for(int i=0; i<n; i++){
    if(s[i]=='A'){
      flag=1;
    }else if(s[i]=='B' && flag==1){
      flag=2;
    }else if(s[i]=='C' && flag==2){

      count++;
      flag=0;
    }else{
      flag=0;
    }
  }

  cout << count << endl;
  return 0;
}


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

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

    vector<vector<bool>> isexist_f(n, vector<bool>(10, false));
    vector<vector<bool>> isexist_b(n, vector<bool>(10, false));
    for(int i = 0; i+1 < n; i++){
        isexist_f[i][s[i]-'0'] = true;
        for(int j = 0; j < 10; j++){
            isexist_f[i+1][j] = isexist_f[i][j];
        }
    }
    for(int i = n-1; i > 0; i--){
        isexist_b[i][s[i]-'0'] = true;
        for(int j = 0; j < 10; j++){
            isexist_b[i-1][j] = isexist_b[i][j];
        }
    }

    map<int, int> ans;
    for(int i = 1; i+1 < n; i++){
        int coans = (s[i]-'0')*10;
        for(int j = 0; j < 10; j++){
            if(isexist_f[i-1][j]){
                coans += j*100;
                for(int k = 0; k < 10; k++){
                    if(isexist_b[i+1][k]){
                        ans[coans+k] = 1;
                    }
                }
                coans -= j*100;
            }
        }
    }

    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 7472
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

S = int(input())
n = S//3
ans = 0

for i in range(1, n+1):
  R = S-3*i
  ans += cmb(R+i-1, i-1)%(10**9+7)  
print(ans%(10**9+7))

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,k;cin>>a>>b>>k;
	ll ara[a+2],bra[b+2];
	vector<ll>sum_a(a+1);
	vector<ll>sum_b(b+1);
	for(int i=0;i<a;i++)
	{
		cin>>ara[i];
	}
	for(int i=0;i<b;i++)
	{
		cin>>bra[i];
	}
	for(int i=0;i<a;i++)
	{
		sum_a[i+1] = sum_a[i]+ara[i];
	}
	for(int i=0;i<b;i++)
	{
		sum_b[i+1] = sum_b[i]+bra[i];
	}
	int total=0;
	for(int i=0;i<=a;i++)
	{
		ll take = sum_a[i];
		ll baki = k - take;
		if(baki < 0) continue;
		int last = lower_bound(sum_b.begin(),sum_b.end(),baki)-sum_b.begin();
		if(last > b || sum_b[last] > baki) last--;
		total = max(total,i+last);
	}
	cout<<total<<endl;
}


Measured memory_bytes: 9520
#include <iostream>
#include <limits.h>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int data[n];
  int sum;
  int min = INT_MAX;
  
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  
  for (int i = 1; i <= 100; i++) {
    sum = 0;
    for (int j = 0; j < n; j++) {
      int diff = data[j] - i;
      sum += diff * diff;
    }
    
    if (sum < min) {
      min = sum;
    }
  }
  
  cout << min;
  
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)


























int main(){
    ll ans = -1;
    REP(i, 5){
        ll x;
        cin >> x;
        if(x == 0) ans = i + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
/* https://atcoder.jp/contests/abc092/tasks/arc093_a */

#include <iostream>
#include <vector>
#include <cmath>

std::vector<int> solve(const int N, std::vector<int> &A)
{
  std::vector<int> cost(N);
  std::vector<int> diff_A(N+1);
  std::vector<int> skip_A(N+1);

  int sum_cost = 0;

  for (int i = 0; i <= N; ++i) {
    int a = i == N ? 0 : A.at(i);
    int b = i == 0 ? 0 : A.at(i-1);
    int c = i == N-1 ? 0 : (i == N ? 0 : A.at(i+1));
    int diff = std::abs(a-b);
    int skip = std::abs(b-c);

    diff_A.at(i) = diff;
    skip_A.at(i) = skip;

    sum_cost += diff;
  }

  for (int i = 0; i < N; ++i) {
    cost.at(i) = sum_cost + skip_A.at(i) - diff_A.at(i) - diff_A.at(i+1);
  }

  return cost;
}

int main(int argc, char *argv[])
{
  // Input
  int N;

  std::cin >> N;

  std::vector<int> A(N);

  for (auto &e: A)
    std::cin >> e;

  // Output
  std::vector<int> cost = solve(N, A);

  for (auto e: cost)
    std::cout << e << std::endl;

  return 0;
}


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

int main(){
	int n, m, a, b, x, y, maxx = -101, miny = 101;
	cin >> n >> m >> a >> b;
	for(int i=0; i<n; i++){
		cin >> x;
		maxx = max(maxx, x);
	}
	for(int i=0; i<m; i++){
		cin >> y;
		miny = min(miny, y);
	}
	maxx = max(maxx, a);
	miny = min(miny, b);
	if(maxx<miny) cout << "No War" << endl;
	else cout << "War" << endl;
}

Measured memory_bytes: 256
def last_num(a):
    while a//10!=0:
        a=a%10
    return a

def marume(a):
    b=a
    while a//10!=0:
        a=a%10
    if a!=0:
        b=b-a+10
    return b

A=[int(input())for _ in range(5)]
last_order=9
order_num=0
ans=0
for i in range(5):
    if 0 < last_num(A[i]) < last_order:
        last_order=last_num(A[i])
        order_num=i
for j in range(5):
    if j !=order_num:
        ans+=marume(A[j])
    else:
        ans+=A[j]
print(ans)


Measured memory_bytes: 3064
W = input()
S = list(W)
RL = [0]
LR = [0]
ans = []

for i in range(len(S)-1):
    if S[i] == "R" and S[i+1] == "L":
        RL.append(i+1)
    elif S[i] == "L" and S[i+1] == "R":
        LR.append(i+1)

LR.append(len(S))

for j in range(1, len(RL)):
    sep = LR[j-1]
    LR_d = LR[j]-sep
    RL_d = RL[j]-sep

    if not LR_d % 2 and not RL_d % 2:
        ans.extend([0] * (RL_d - 1))
        ans.extend([LR_d // 2] * 2)
        ans.extend([0] * (LR[j]-RL[j]-1))
    elif not LR_d % 2 and RL_d % 2:
        ans.extend([0] * (RL_d - 1))
        ans.extend([LR_d // 2] * 2)
        ans.extend([0] * (LR[j]-RL[j]-1))
    elif LR_d % 2 and not RL_d % 2:
        ans.extend([0] * (RL_d - 1))
        ans.extend([LR_d // 2, LR_d // 2 + 1])
        ans.extend([0] * (LR[j]-RL[j]-1))
    elif LR_d % 2 and RL_d % 2:
        ans.extend([0] * (RL_d - 1))
        ans.extend([LR_d // 2 + 1, LR_d // 2])
        ans.extend([0] * (LR[j]-RL[j]-1))

print(*ans, sep = " ")

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

int N,x;
int A[200010] = {0};

int main(){
	cin >> N >> x;
	if(x == 1 || x ==2*N-1) cout << "No" << endl;
	else{
		if(x==2){
			A[N] = 1;
			A[N+1] = 2;
			A[N-1] = 3;
			for(int i=1;i<=2*N-1;i++){
				if(i<N-1) A[i] = i + 3;
				else if(i>N+1) A[i] = i;
			}
		}else if(x==2*N-2){
			A[N] = 2*N-1;
			A[N+1] = 2*N-2;
			A[N-1] = 2*N-3;
			for(int i=1;i<=2*N-1;i++){
				if(i<N-1) A[i] = i;
				else if(i>N+1) A[i] = i - 3;
			}
		}else{
			A[N] = x;
			A[N+1] = x+1;
			A[N-1] = x-1;
			A[N+2] = x-2;
			A[N-2] = x+2;
			int c = 1;
			if(x==3) c = 6;
			for(int j=1;j<=2*N-1;j++){
				if(A[j]==0 && c<x-2){
					A[j] = c;
				}else if(A[j]==0 && c>x+2){
					A[j] = c;
				}
				if(c==x-3) c += 6;
				else if(j<N-2) c++;
				else if(j>N+2) c++;
			}
		}
		cout << "Yes" << endl;
		for(int j=1;j<=2*N-1;j++){
			cout << A[j] << endl;
		}
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<vector>
using namespace std;
const int A = 9310;
const int B = 350;
const int N = 215;
const int NN = 1000010;
#define REP(i, j) for(int i = 0; i < j; i++)

vector<bool> prime(NN, true);

void makePrime(){
    prime[0] = false;
    prime[1] = false;
    for(int i = 2; i * i <= NN; i++){
        if(!prime[i]) continue;
        for(int j = i + i; j < NN; j += i) prime[j] = false;
    }
}

int cal(int a, int b, int n){
    int cnt = 0;
    for(int i = a; ; i += b){
        if(prime[i]) cnt++;
        if(cnt == n) return i;
    }
}

int main(){
    makePrime();
    int a, b, n;
    while(cin >>a >>b >>n && a) cout <<cal(a, b, n) <<endl;
    return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;



int main(){
    char c;
    cin >> c;
    c++;
    
    
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>



void getInput(std::vector<int> *v);

int main(void)
{
	// input
	std::vector<int> v;
	getInput(&v);
	getInput(&v);
	
	/*
	for(int i = 0; i < v.size(); i++) {
		std::cout << v[i] << std::endl;
	}
	*/
	

	// solve
	int num = v[0];
	v.erase(v.begin());

	std::vector<int> _v = v;

	std::sort(v.begin(), v.end());

	int n1 = v[num/2 - 1];
	int n2 = v[num/2];

	for(int i = 0; i < num; i++) {
		if(_v[i] <= n1) std::cout << n2 << std::endl;
		else std::cout << n1 << std::endl;
	}











	return 0;
}




void getInput(std::vector<int> *v)
{
	std::string s, buf;
	std::getline(std::cin, s);
	std::stringstream ss(s);
	
	while(std::getline(ss, buf, ' ')) {
		(*v).push_back(std::stoi(buf));
	}
	
}




















Measured memory_bytes: 6788
#include <stdio.h>

int main()
{
    int inputA, inputB, inputC;

    scanf("%d""%d""%d", &inputA, &inputB, &inputC);

    if (inputA == inputB && inputB == inputC)
    {
        printf("No \n");
    }
    else if (inputA == inputB || inputA == inputC || inputB == inputC)
    {
        printf("Yes \n");
    }
    else
    {
        printf("No \n");
    }

    return 0;
}


Measured memory_bytes: 128
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    double r;
    cin>>r;
    printf("%.9f\n",2*PI*r);
    return 0;
}


Measured memory_bytes: 3788
x, y = [int(_) for _ in input().split()]
if y > x:
    if x * y > 0:
        print(y - x)
    elif x * y < 0:
        print(abs(x + y) + 1)
    else:
        print(min(y - x, abs(x + y) + 1))
elif x > y:
    if x * y > 0:
        print(x - y + 2)
    elif x * y < 0:
        print(abs(x + y) + 1)
    else:
        print(min(x - y + 2, abs(x + y) + 1))
else:
    print(0)


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

ans=1000

for i in range(0,(10**n)):
    tmp=str(i)
    if len(tmp)==n:
        flag=True
        for j in range(m):
            if int(tmp[s[j]])!=c[j]:
                flag=False
        if flag:
            ans=min(ans,i)

if ans==1000:
    print(-1)
else:
    print(ans)

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll H, W;
    cin >> H >> W;

    vector<vector<char > > vec(119, vector<char >(119, '#'));

    for(ll i = 1; i <= H; i++){
        for(ll j = 1; j <= W; j++){
            cin >> vec[i][j];
        }
    }

    for(ll i = 0; i <= H + 1; i++){
        for(ll j = 0; j <= W + 1; j++){
            cout << vec[i][j];
        }
        cout << endl;
    }

}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int l = s.size();
  string slast = s.substr(l-1);

  if(slast == "s"){
    cout << s.insert(l, "es");
  }
  else{
    cout << s.insert(l, "s");
  }

  return 0;
}

Measured memory_bytes: 3576
alpha = input()

upper = ["A", "B", "C", "D", 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

if alpha in upper:
    print("A")
else:
    print("a")


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n%2==1) cout << "No" << endl;
  else{
    bool ans = true;
    rep(i,s.size()/2){
      if(s[i]!=s[i+s.size()/2]) ans=false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

int main(){
        int h,n,i,j;
        cin >> h >> n;
        vector<int> a(n+1);
        vector<int> b(n+1);
        vector<vector<int>> dp(n+1, vector<int>(h+1,1000000000));
        for(i=1;i<n+1;++i) cin >> a.at(i) >> b.at(i);
        dp.at(0).at(0) = 0;
        for(i=1;i<n+1;++i){
                dp.at(i).at(0) = 0;
                for(j=0;j<h+1;++j){
                        if(j-a.at(i)>=0) dp.at(i).at(j) = min(dp.at(i-1).at(j), dp.at(i).at(j-a.at(i))+b.at(i));
                        else dp.at(i).at(j) = min(b.at(i),dp.at(i-1).at(j));
                }
        }
        cout << dp.at(n).at(h) << endl;
        return 0;
}

Measured memory_bytes: 42268
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define int ll
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)


#define DEBUG

using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;


#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<int, int> P;

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

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


ll A,B,C,X,Y,N, M, K;
signed main() {

    cin >> A >> B >> C >> X >> Y;

    int combi = min(X,Y);
    int res = 0;
    if(A + B >= C*2){
        res += 2*combi * C;
        if(X > Y){
            res += (X-combi)*min(A,C*2);
        }
        else{
            res += (Y-combi)*min(B,C*2);
        }
    }
    else{
        res = X*A + Y*B;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
 
using namespace std;
 
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	string s;
	cin >> s;
	cout << s.substr(0 , 4) << " " << s.substr(4) << nl;
 
 
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
sy, sx = list(map(int, input().split()))
sy -= 1
sx -= 1
gy, gx = list(map(int, input().split()))
gy -= 1
gx -= 1
s = [input() for _ in range(h)]
inf = float("inf")
meiro = [[inf]*w for _ in range(h)]
d = deque()
d.append([sy, sx])
meiro[sy][sx] = 0
move1 = [[1, 0], [0, 1], [-1, 0], [0, -1]]
while d:
    py, px = d.popleft()
    #move1 bfs
    for dy, dx in move1:
        if 0 <= px+dx < w and 0 <= py+dy < h:
            childy = py + dy
            childx = px + dx
            if s[childy][childx] == "." and meiro[childy][childx] > meiro[py][px]:
                meiro[childy][childx] = meiro[py][px]
                d.appendleft([childy, childx])
                # move1のbfsを優先的に探索したいからd.appendleftする

    #warp
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            if 0 <= px+dx < w and 0 <= py+dy < h:
                warpx = px + dx
                warpy = py + dy
                if s[warpy][warpx] == "." and meiro[warpy][warpx] == inf:
                    meiro[warpy][warpx] = meiro[py][px] + 1
                    d.append([warpy, warpx])


ans = meiro[gy][gx] if meiro[gy][gx] != inf else -1
print(ans)

Measured memory_bytes: 116300
#include<bits/stdc++.h>
using ll = long long;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int ans = 0;
    for(int i = 0; i < N; i++)
    {
        if(i==N-1) p[i] /= 2;
        ans += p[i];
    }
    cout << ans << endl;
}

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

int n, mod = 1000000007;
string s[2];
ll ans = 1;

int main() {
	cin >> n >> s[0] >> s[1];
	
	bool flag;
	for (int i = 0; i < n; i++) {
		//cout << "i:" << i << endl;
		if (s[0][i] != s[1][i]) {
			if (i == 0)ans *= 6;
			else if (flag)ans *= 3;
			else ans *= 2;

			i++;
			flag = true;
		}
		else {
			if (i == 0)ans *= 3;
			else if (!flag)ans *= 2;

			flag = false;
		}
		ans %= mod;
	}

	cout << ans << endl;
}

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

using namespace std;

long long n,m;
long long a[100001];
long long ans = 0;

struct node
{
    long long b,c;
}s[100001];

bool cmp(node a,node b)
{
    if(a.c != b.c)
        return a.c > b.c;
    else
        return a.b > b.b;
}

int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i++)
        scanf("%lld",&a[i]);
    for(int i = 1;i <= m;i++)
        scanf("%lld%lld",&s[i].b,&s[i].c);
    sort(s + 1,s + 1 + m,cmp);
    sort(a + 1,a + 1 + n);
    for(int i = 1,j = 1;i <= n;i++)
    {
        if(a[i] < s[j].c && s[j].b >= 1)
        {
            ans += s[j].c;
            s[j].b--;
        }
        else
            ans += a[i];
        if(s[j].b == 0 && j < m)
            j++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

int main() {
  long long H, i, j, tmp, sum = 0, result = 0;
  cin >> H;
  while (H > 1) {
    H /= 2;
    sum++;
  }
  for (i = 0; i <= sum; i++) {
    tmp = 1;
    for (j = 0; j < i; j++) {
      tmp *= 2;
    }
    result += tmp;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int INF = 10000000;

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
using Graph = vector<vector<int>>;
/*
*/
ll s[100],p[100];
ll func(ll N, ll X){//レベルNバーガーの下からX層に含まれるパティの枚数
      if(N == 0){
          if(X <=0) return 0;
          else return 1;
      }
      else if(X == 1) return 0;
      else if(1 < X && X <= 1 + s[N-1])  return func(N-1,X-1);
      else if(X == 2 + s[N-1]) return p[N-1] + 1;
      else if(2 + s[N-1] < X && X <= 2 + 2*s[N-1]) return p[N-1] + 1 + func(N-1,X-2-s[N-1]);
      else if(X == 3 + 2*s[N-1]) return 2*p[N-1] + 1;
}

int main() {
   ll N,X;
   cin >> N >> X;
   //vector<ll> s(N);//レベルiバーガーの層数
   //vector<ll> p(N);//レベルiバーガーのパティの枚数
   s[0] = 1;
   p[0] = 1;
   for(int i = 1;i<=N;i++){
       s[i] = s[i-1]*2 + 3;
       p[i] = p[i-1]*2 + 1;
   }
  cout << func(N,X) << endl;
}

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

int main(){
	
	ll a,b,n; cin>>a>>b>>n;
	ll x,y;
	x = n;
	y = n/b*b-1;
	cout << max(a*x/b - a*(x/b), a*y/b - a*(y/b))<< endl;
	
	
}

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

int main() {
  //宣言
  int N;
  vector<int> A;
  int count = 0;
  int I = 1;
  
  
  //入力
  cin >> N;
  A = vector<int>(N);
  for(int i=0;i<N;i++){
  cin >> A.at(i);
  }
  
  
  //処理
  while(count <=N && I !=2){
    //cout << I << endl;
    count++;
    I = A.at(I-1);
  }
  if(I !=2){
    count = -1;
  }
  
  //出力
  cout << count << endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, a, n, op) for(int i=a; i<(int)(n); i ## op ## op)
#define cout(val) cout << val << endl

using namespace std;  
const double pi = 3.141592653589793;

int main(){
    int a, b;
    long double h, m;
    cin >> a >> b >> h >> m;

    long double jc, fc, x, y;

    jc = (h / 6.0 * -1.0 + 0.5 - m / 360.0) * pi;
    fc = (m / 30.0 * -1.0 + 0.5) * pi;

    x = a * cos(jc) - b * cos(fc);
    y = a * sin(jc) - b * sin(fc);

    x = pow(x, 2.0);
    y = pow(y, 2.0);
    cout << fixed << setprecision(15) << sqrt(x + y) << endl;
}

Measured memory_bytes: 4188
#include<stdio.h>
#include<math.h>

int main(){

	long n;
	scanf("%ld",&n);
	long a=1,b;
	long ans=n+60;
	while((long)sqrt(n) >=a){
		b=n/a;
		if(a*b==n && a+b-2 <ans){
			ans=a+b-2;
		}
		a++;
	}
	printf("%ld",ans);
}


Measured memory_bytes: 128