akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

string calc(string s,int digit){
  string maxs,mins;
  maxs=mins=s;
  sort(maxs.begin(), maxs.end(),greater<int>());
  sort(mins.begin(),mins.end());
  int max=atoi(maxs.c_str());
  max*=pow(10,digit-s.length());
  int min=atoi(mins.c_str());
  string res;
  stringstream ss;
  ss << max-min;
  res = ss.str();
  return res;
}

int search(int query,vector<int> list){
  if(list.empty()==true)return 0;
  int cnt=0;
  for(int a:list){
    if(query==a)return list.size()-cnt;
    cnt++;
  }
  return 0;
}

int main(){
  int digit;
  string s;
  vector<int> list;
  while(cin>>s>>digit,digit){
    int ans;
    list.clear();
    while((ans=search(atoi(s.c_str()),list)) == 0){
      list.push_back(atoi(s.c_str()));
      s=calc(s,digit);
     }
    cout << list.size() - ans << " " << s << " " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

class Program
{
    private static long Count(long A, long B)
    {
        long n = (A + B - 1) / B;
        return B * n - A;
    }
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        long[] a = new long[N];
        long[] b = new long[N];
        for (int i = 0; i < N; ++i)
        {
            long[] values = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            a[i] = values[0];
            b[i] = values[1];
        }
        long sum = 0;
        for (int i = N - 1; i >= 0; --i)
        {
            sum += Count(a[i] + sum, b[i]);
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 8408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int Mod = 1e9 + 7;
int N, M; ll K;
ll lr, c1, c2, c3, ans;
char S[1010][1010];

struct matrix {
	ll a[2][2];
	inline matrix(){a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0;}
	inline matrix operator * (const matrix &ret) {
		register int i, j, k;
		matrix c;
		for(k = 0; k < 2; ++k)
			for(i = 0; i < 2; ++i)
				for(j = 0; j < 2; ++j)
					(c.a[i][j] += 1ll * a[i][k] * ret.a[k][j] % Mod) %= Mod;
		return c;
	}
} X, Y, tmp;

inline ll fastpow_mod(ll a, ll b) {
	ll x = 1;
	while(b) {
		if(b & 1) x = 1ll * x * a % Mod;
		a = 1ll * a * a % Mod; b >>= 1;
	}
	return x;
}

inline ll calc(int x, int y, int z) {
	X.a[0][0] = X.a[1][1] = 1;
	Y.a[0][0] = z, Y.a[0][1] = Mod - 1, Y.a[1][1] = x;
	while(K) {
		if(K & 1) X = X * Y;
		Y = Y * Y, K >>= 1;
	}
	return (X.a[0][0] + X.a[0][1] * y) % Mod;
}

int main() {
	register int i, j;
	scanf("%d%d%lld", &N, &M, &K);
	if(!K--) return puts("1"), 0;
	for(i = 1; i <= N; ++i) {
		scanf("%s", S[i] + 1);
		lr += S[i][1] == '#' && S[i][M] == '#';
		for(j = 1; j <= M; ++j)
			if(S[i][j] == '#')
				c1 += 1, c2 += S[i][j - 1] == '#', c3 += S[i - 1][j] == '#';
	}
	for(i = 1; i <= M; ++i)
		ans += S[1][i] == '#' && S[N][i] == '#';
	printf("%lld\n", (lr ? (ans ? 1ll : calc(lr, c2, c1)) : (ans ? calc(ans, c3, c1) : fastpow_mod(c1, K)) + Mod) % Mod);
	return 0;
}

Measured memory_bytes: 1152
N, M = map(int, input().split())
oks = [True] * (N+1)

for _ in range(M):
    a = int(input())
    oks[a] = False

dp = [1] + [0] * N
for now in range(N):
    for nxt in range(now+1, min(N, now+2)+1):
        if oks[nxt]:
            dp[nxt] += dp[now]
            dp[nxt] %= 1e9 + 7

print(int(dp[N]))

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

int main() {
  int N, L;
  cin >> N >> L;
  
  string answer;
  vector<string> S(N);
  
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  
  for(int i = 0; i < N; i++){
    answer += S[i];
  }
  cout << answer << endl;
  
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

void judge(bool ok, int cnt) {
   if (!ok) {
      if (cnt&1) {
         puts("First");
      } else {
         puts("Second");
      }
      exit(0);
   }
}

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

   if (s[0] == s.back()) {
      // 奇数長になる
      if (s.size()&1) {
         puts("Second");
      } else {
         puts("First");
      }
   } else {
      // 偶数長になる
      if (s.size()&1) {
         puts("First");
      } else {
         puts("Second");
      }
   }

   return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
 int main()
{
 int h,w,i,j;

 for(;;){
         scanf("%d%d",&h,&w);
         if(h==0&&w==0)break;
         for(i=0;i<h;i++){
                          for(j=0;j<w;j++)
                           printf("#");
                           printf("\n");
                          }    
          printf("\n");
         }
 return 0;

}



Measured memory_bytes: 2104
import heapq
n, m = map(int, input().split())
ab = sorted([ list(map(int, input().split())) for _ in range(n) ], reverse=True)
que = []
ans = 0
for i in range(1, m+1):
  while ab and ab[-1][0] <= i:
    t = ab.pop()
    heapq.heappush(que, -t[1])
  if que:
    ans -= heapq.heappop(que)
print(ans)

Measured memory_bytes: 28664
import std.stdio,std.math,std.string,std.conv,std.typecons,std.format;
import std.algorithm,std.range,std.array;
 
T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
 
//END OF TEMPLATE
 
void main(){
    ulong k;
    k.scan;
    k.solve.writeln;
}
 
struct Queue{
    public:
    char[][] list;
    auto enq(char c){list~=[c];}
    auto enq(char[] c){list~=c;}
    auto deq(){auto d=list[0];list=list.length==1?[]:list[1..$];return d;}
}
 
char[] co(char c){
    if(c=='0')
        return ['0','1'];
    if('1'<=c&&c<='8')
        return [to!char(c-1),c,to!char(c+1)];
    if(c=='9')
        return ['8','9'];
    assert(0);
}
 
auto solve(ulong k){
    Queue q;
    foreach(c;'1'.to!char..('9'+1).to!char)q.enq(c);
    foreach(i;0..k-1){
        auto tmp=q.deq;
        foreach(s;tmp[$-1].co)
            q.enq(tmp~s);
    }
    return q.deq;
}

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

int main() {
	// your code goes here

string a;
cin>>a;
int c=0;
for(int i=0,j=a.size()-1;i<j;j--,i++){
if(a[i] != a[j]) c++;
}
 cout<<c<<"\n";
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
count = Counter()
for i in range(2, N+1):
    while i != 1:
        for j in range(2, N+1):
            if i % j == 0:
                i //= j
                count[j] += 1
                break
ans = 1
for x in count.values():
    ans *= (x+1)
    ans %= 10**9+7
print(ans)


Measured memory_bytes: 3316
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    # 0を左端、N-1を右端として二分探索を行う
    print(0)
    left_response = input()
    if left_response == "Vacant":
        exit()

    print(n - 1)
    right_response = input()
    if right_response == "Vacant":
        exit()

    left = 0
    right = n - 1

    for i in range(20):
        mid = (left + right) // 2
        print(mid)
        mid_response = input()

        if mid_response == "Vacant":
            exit()

        if (mid - left) % 2 == 0 and left_response == mid_response:
            left = mid
            left_response = mid_response
        elif (mid - left) % 2 == 1 and left_response != mid_response:
            left = mid
            left_response = mid_response
        else:
            right = mid
            right_response = mid_response


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3660
//b.c
#include <stdio.h>

int main(){
    int W,a,b;
    scanf("%d %d %d",&W,&a,&b);
    if(b < a){
        int t = b;
        b = a;
        a = t;
    }
    
    int moves = b-a-W;
    if(moves < 0) moves = 0;
    
    printf("%d\n",moves);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

struct DSU{
	int S;
	struct node{
		int parent; ll sum;
	};
	vector<node> dsu;
	DSU(int n){
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	void reset(int n){
		dsu.clear();
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	int root(int u){
		if(dsu[u].parent == u) return u;
		dsu[u].parent = root(dsu[u].parent);
		return dsu[u].parent;
	}
	void merge(int u, int v){
		u = root(u); v = root(v);
		if(u == v) return;
		if(getsum(u) < getsum(v)) swap(u, v);
		dsu[v].parent = u;
		dsu[u].sum += dsu[v].sum;
	}
	bool sameset(int u, int v){
		if(root(u) == root(v)) return true;
		return false;
	}	
	ll getsum(int u){
		return dsu[root(u)].sum;
	}
};

int deg[1000005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m, k;
	cin >> n >> m >> k;
	DSU dsu(n);
	memset(deg, 0, sizeof(deg));
	map<pi, int> f;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		dsu.merge(a, b);
		deg[a]++, deg[b]++;
		f[mp(a, b)] = 1;
		f[mp(b, a)] = 1;
	}
	vi ans(n, 0);
	rep(i, n){
		ans[i] = dsu.getsum(i) - deg[i];
	}
	rep(i, k){
		int c, d;
		cin >> c >> d;
		c--, d--;
		if(dsu.sameset(c, d) && !f[mp(c, d)]){
			ans[c]--, ans[d]--;
		}
	}
	rep(i, n) cout << ans[i] - 1 << " ";
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

using namespace std;

#define MAX_N 4000

typedef long long ll;

const ll INF = 1e15;


ll dp[MAX_N+1][MAX_N+1], K[MAX_N+1][MAX_N+1];
int main() {
	int N; cin >> N;
	vector<ll> cost(N+1);
	for (int i = 0; i < N; ++i) {
		cin >> cost[i+1];
		cost[i+1] += cost[i];
	}

	fill(dp[0], dp[MAX_N+1], INF);
	for (int i = 0; i <= N; ++i) {
		dp[i][i] = 0;
		K[i][i] = i;
	}
	for (int w = 1; w <= N; ++w) {
		for (int l = 0, r = l+w; r < N; ++l, ++r) {
			for (int k = K[l][r-1]; k <= K[l+1][r]; ++k) {
//			for (int k = l; k < r; ++k) {
				ll c = dp[l][k]+dp[k+1][r]+cost[r+1]-cost[l];
				if (c < dp[l][r]) {
					K[l][r] = k;
					dp[l][r] = c;
				}
			}
		}
	}
	cout << dp[0][N-1] << endl;
}

Measured memory_bytes: 251356
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int ans = INF;
    rep(i,s.size()-2){
        int n = 0;
        n+=(s[i]-'0')*100;
        n+=(s[i+1]-'0')*10;
        n+=(s[i+2]-'0');
        chmin(ans,abs(n-753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <cstdint>
#include <string.h>
#include <queue>

using namespace std;

const uint64_t cacheLenList[] = {
    1,
    5,
    13,
    29,
    61,
    125,
    253,
    509,
    1021,
    2045,
    4093,
    8189,
    16381,
    32765,
    65533,
    131069,
    262141,
    524285,
    1048573,
    2097149,
    4194301,
    8388605,
    16777213,
    33554429,
    67108861,
    134217725,
    268435453,
    536870909,
    1073741821,
    2147483645,
    4294967293,
    8589934589,
    17179869181,
    34359738365,
    68719476733,
    137438953469,
    274877906941,
    549755813885,
    1099511627773,
    2199023255549,
    4398046511101,
    8796093022205,
    17592186044413,
    35184372088829,
    70368744177661,
    140737488355325,
    281474976710653,
    562949953421309,
    1125899906842621,
    2251799813685245,
    4503599627370493,
};
const uint64_t cachePatiList[] = {
    1,
    3,
    7,
    15,
    31,
    63,
    127,
    255,
    511,
    1023,
    2047,
    4095,
    8191,
    16383,
    32767,
    65535,
    131071,
    262143,
    524287,
    1048575,
    2097151,
    4194303,
    8388607,
    16777215,
    33554431,
    67108863,
    134217727,
    268435455,
    536870911,
    1073741823,
    2147483647,
    4294967295,
    8589934591,
    17179869183,
    34359738367,
    68719476735,
    137438953471,
    274877906943,
    549755813887,
    1099511627775,
    2199023255551,
    4398046511103,
    8796093022207,
    17592186044415,
    35184372088831,
    70368744177663,
    140737488355327,
    281474976710655,
    562949953421311,
    1125899906842623,
    2251799813685247,
};
uint64_t calLen(uint64_t N)
{
    return cacheLenList[N];
    //return (N <= 0) ? 1
    //    : 3 + calLen(N-1) * 2;
}
uint64_t calPati(uint64_t N)
{
    return cachePatiList[N];
    //return (N <= 0) ? 1
    //    : 1 + calPati(N-1) * 2;
}

uint64_t func(uint64_t N, uint64_t X)
{
    if (X <= 0) {
        return 0;
    }

    auto len = calLen(N);
    auto halfLen = len / 2 + 1;
    //auto patiSum = calPati(N);

    uint64_t patiCount = 0;
    if (X < halfLen) {
        patiCount += func(N-1, X-1);
    } else if (X == halfLen) {
        patiCount = calPati(N - 1) + 1;
    } else if(len < X) {
        patiCount = calPati(N);
    } else {
        //前半分の分
        patiCount = calPati(N - 1) + 1;

        patiCount += func(N - 1, X - halfLen);
    }
    return patiCount;
}

int main()
{
    uint64_t N, X;
    cin >> N >> X;

    uint64_t patiCount = func(N, X);
    //cout << N << "," << X << endl;
    //cout << calLen(N) << ", " << calPati(N) << endl;
    cout << patiCount << endl;

    //cout << "const uint64_t cacheLenList[] = {" << endl;
    //for (int i = 0; i <= 50; ++i) {
    //    cout << calLen(i) << ", " << endl;
    //}
    //cout << "};" << endl;
    //cout << "const uint64_t cachePatiList[] = {" << endl;
    //for (int i = 0; i <= 50; ++i) {
    //    cout << calPati(i) << "," << endl;
    //}
    //cout << "};" << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

cnt=0
for i in range(n):
    if a[i]+a[i+1]>=b[i]:
        if a[i]>=b[i]:
            cnt+=b[i]
        else:
            cnt+=b[i]
            a[i+1]-=b[i]-a[i]
    else:
        cnt+=a[i]+a[i+1]
        a[i+1]=0

print(cnt)

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

int main(){
  int64_t N, K; cin >> N >> K;
  if(N==K){
    cout << 0 << endl;
    return 0;
  }
  if(N<K){
    cout << min(N,abs(N-K)) << endl;
    return 0;
  }
  int64_t s=(N/K)*K;
  cout << min(N-s, abs(N-s-K)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,m,p,a,b,ans[100001],r;
    cin>>n>>m;
    p=n+m-1;
    vector<set<int>> A(n+1),B(n+1);
    rep(i,p) cin>>a>>b,A[a].insert(b),B[b].insert(a);
    rep(i,n) if(B[i+1].size()==0) r=i+1,ans[i+1]=0;
    queue<int> q;
    q.push(r);
    while(q.size()>0){
        int x=q.front();
        q.pop();
        for(auto i : A[x]) {
            B[i].erase(x);
            if(B[i].size()==0) ans[i]=x,q.push(i);
        }
    }
    rep(i,n) cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 20352
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const a = parseInt(line0vars[0], 10);
	const b = parseInt(line0vars[1], 10);

	console.log(a*b);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)

Measured memory_bytes: 29636
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N,K;	cin>>N>>K;
	int h;
	int ans=0;
	rep(i,0,N){
		cin>>h;
		if(h>=K) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
typedef pair<ll, ll> P;
int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	vector<ll> F(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> F[i];
	sort(A.begin(), A.end());
	sort(F.begin(), F.end(), greater<ll>());
	ll l = -1, r = 1e12;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		ll sum = 0;
		for (int i = 0; i < N; i++) {
			sum += max(A[i] - m / F[i], 0LL);
		}
		if (sum <= K) r = m;
		else l = m;
	}
	cout << r << endl;
}

Measured memory_bytes: 3328
a, b, c, d = (int(i) for i in input().split())
if a > 0:
    if d > 0:
        print(max(a*c, a*d, b*c, b*d))
    else:
        print(max(a*c, a*d, b*c, b*d))
else:
    if d > 0:
        print(max(a*c, a*d, b*c, b*d))
    else:
        print(max(a*c, a*d, b*c, b*d))


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

int main() {
    string s;
    string res;

    cin >> s;
    for (int i=0; i<s.length(); ++i) {
      if (i%2 == 0) res += s[i];
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<int> v;
    char c = '#';
    int count = 1;
    int l = (int)s.length();
    rep(i, l) {
        if(c == s[i]) {
            count++;
        }else {
            if(i != 0) v.push_back(count);
            count = 1;
            c = s[i];
        }
    }
    if(count > 0) v.push_back(count);

    /*
    rep(i, v.size()) {
        cout << v[i] << endl;
    }
    */

    if(v.size() == 1) {
        cout << (ll)v[0] * k / 2 << endl;
        return 0;
    }

    if(s[0] == s[l - 1]) {
        ll ans = 0;
        for(int i = 1; i < v.size() - 1; i++) {
            ans += (ll)v[i] / 2 * k;
        }
        ans += (ll)(v[0] + v[v.size() - 1]) / 2 * (k - 1);
        ans += v[0] / 2;
        ans += v[v.size() - 1] / 2;
        cout << ans << endl;
    }else {
        ll ans = 0;
        rep(i, v.size()) {
            ans += (ll)v[i] / 2 * k;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
NUM = 10**5 + 1
MOD = 10**9 + 7
dp = [-1] * NUM
dp[0] = 1
for i in range(1, NUM):
    dp[i] = (dp[i-1] * i) % MOD

def inv(p): 
    res = 1 
    k = MOD - 2 
    while k > 0:
        if k & 1:
            res = (res * p) % MOD 
        p = (p * p) % MOD 
        k //= 2
    return res
            
def comb(n, k): 
    p = dp[n]
    q = (dp[n-k] * dp[k]) % MOD
    return (p * inv(q)) % MOD
                    
def solve(n, k, a):         
    a = sorted(a)                   
    minX = sum(comb(n-l, k-1) * a[l-1] for l in range(1,n+1) if l+k-1 <= n)
    maxX = sum(comb(r-1, k-1) * a[r-1] for r in range(1,n+1) if r >= k)
    return (maxX - minX) % MOD                                          
                                                                                    
n, k = map(int, input().split())                                                                
a = list(map(int, input().split()))                                                                     
print(solve(n, k, a))  

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


int main()
{
	int n;
	cin >> n;
	string ans = "APPROVED";
	for (int i = 0; i < n; i++) {
		int a_in;
		cin >> a_in;
		if (a_in % 2 == 0 && (a_in % 3 != 0 && a_in % 5 != 0)) {
			ans = "DENIED";
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
int dx[]={0,0,2,-2};
int dy[]={2,-2,0,0};
int _dx[]={0,0,1,-1};
int _dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
#define MP make_pair
signed main(){
    char s,t;
    cin >> H >> W >> s >> t;
    vector<string>grid(H);
    vector<vector<pii>>edge(100);
    map<int,pii>memo;
    rep(i,H) cin >> grid[i];
    rep(i,H)rep(j,grid[i].size()){
        if('A' <= grid[i][j] && grid[i][j] <= 'Z'  ){
            memo[grid[i][j] - 'A'] = MP(j,i);
        }
    }
    for(auto itr : memo){
        int vertex = itr.first;
        pii pos = itr.second;
        rep(i,4){
            pii temp = MP(pos.first+dx[i],pos.second+dy[i]);
            if(!inrange(temp.first,temp.second))continue;
            if(grid[temp.second][temp.first] != '-' && grid[temp.second][temp.first] != '|') continue;
            if(grid[temp.second][temp.first] == '|' && ( i > 1)) continue;
            if(grid[temp.second][temp.first] == '-' && ( i <= 1))continue;
            pii now = temp;
            while(true){
                if('A' <= grid[now.second][now.first] && grid[now.second][now.first] <= 'Z'  )
                    break;
                now.first += _dx[i];
                now.second += _dy[i];
                assert(inrange(now.first, now.second));
            }
            int next =  grid[now.second][now.first] - 'A';
            edge[vertex].push_back(pii(next,1));
        }
    }
    // dijkstra
    vector<int>d(t,INF);
    d[s-'A'] = 0;
    priority_queue<pii,vector<pii>,greater<pii>>que;
    que.push(pii(0,s-'A'));
    while(!que.empty()){
        pii now = que.top();
        que.pop();
        if(now.first > d[now.second])continue;
        rep(i,edge[now.second].size()){
            int next  = edge[now.second][i].first;
            if(d[next] < 1 + now.first) continue;
            d[next] = 1 + now.first;
            que.push(pii(d[next],next));
        }
    }
    cout << d[t-'A'] << endl;
}



Measured memory_bytes: 3236
#include<stdio.h>

int main(void){
  int k,a,b,i;
  scanf("%d %d %d", &k, &a, &b);
  if(k == 1)
    printf("OK");
  else if(k > b)
    printf("NG");
  else if(k <= b - a)
    printf("OK");
  else {
    for(i=a;i<=b;i++){
      if(i%k == 0){
        printf("OK");
        break;
      }
      if(i == b)
        printf("NG");
    }
  }
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int G[100001];
pair<int, int> E[200001];
pair<int, int>* P[100002];
int dfs(int A) {
	if (G[A] == 0) {
		int g = 0;
		G[A] = -1;
		for (auto p = P[A]; p < P[A + 1]; p++) {
			g ^= dfs((*p).second);
		}
		return G[A] = g + 1;
	}
	return 0;
}

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


	int N;
	cin >> N;
	for (int i = 0; i < N + N - 2; i += 2) {
		int x, y;
		cin >> x >> y;
		E[i] = mp(x, y);
		E[i + 1] = mp(y, x);
	}
	sort(E, E + N + N - 2);
	int k = 0;
	rep(i, N + N - 2) {
		if (k != E[i].first) {
			k++;
			P[k] = E + i;
		}
	}
	P[N + 1] = E + N + N - 2;

	dfs(1);

	if (G[1] - 1) co("Alice");
	else co("Bob");

	Would you please return 0;
}


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

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

  vector<string> S(N);
  rep(i, N) cin >> S[i];

  int ac = 0, wa = 0, tle = 0, re = 0;
  for (auto s : S)
  {
    if (s == "AC") ac++;
    else if (s == "WA") wa++;
    else if (s == "TLE") tle++;
    else if (s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6428
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <functional>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 1e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxE << 1];
	inline void push(int x, int y) {e[++te] = (edge){y, g[x]}; g[x] = te;}
	inline void link(int x, int y) {push(x, y), push(y, x);}
	inline int& operator () (int x) {return g[x];}
	inline edge& operator [] (int x) {return e[x];}
}e;

int depth[maxN];
int d[maxN], tt;

void dfs(int x) {
	fore (e, x, y) dfs(y);
	tt = 0; fore (e, x, y) d[++tt] = depth[y];
	sort(d+1, d+tt+1, greater<int>());
	depth[x] = 0; rep (i, 1, tt) depth[x] = max(depth[x], d[i] + i);
}

int main() {

	n = ri();
	rep (i, 2, n) e.push(ri(), i);
	dfs(1);
	printf("%d\n", depth[1]);

	return 0;
}

Measured memory_bytes: 4864
n,m = map(int,input().split())

p = list(map(int,input().split()))

root = [[] for i in range(n)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1)

check = [-1]*n

ans = 0

for j in range(n):
    if check[j] != -1:
        continue
    stack=[j]
    check[j]=j
    while len(stack):
        v = stack.pop(0)
        for i in root[v]:
            if check[i] == -1:
                check[i]=j
                stack.append(i)
for k in range(n):
    if check[k] == check[p[k]-1] :
        ans += 1

print(ans)

Measured memory_bytes: 72556
def insertionsSort(A):
    print(*A)
    N = len(A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)

N = int(input())
A = list(map(int, input().split()))
insertionsSort(A)

Measured memory_bytes: 8084
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<List<Integer>> list = new ArrayList<List<Integer>>();
		for (int i = 0; i < m; i++) {
			int k = sc.nextInt();
			List<Integer> list2 = new ArrayList<Integer>();
			for (int j = 0; j < k; j++) {
				list2.add(sc.nextInt() - 1);
			}
			list.add(list2);
		}
		int[] p = new int[m];
		for (int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		int end = (int) Math.pow(2, n);
		for (int i = 0; i < end; i++) {
			boolean flg = true;
			for (int k = 0; k < m; k++) {
				List<Integer> list2 = list.get(k);
				int cnt = 0;
				for (int j = 0; j < n; j++) {
					if ((i >> j) % 2 == 1 && list2.contains(j)) {
						cnt++;
					}
				}
				if (cnt % 2 != p[k]) {
					flg = false;
					break;
				}
			}
			if (flg) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <utility>
#include <vector>

using namespace std;

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

int N,M;
char A[51][51],B[51][51];


int main(){

	ios_base::sync_with_stdio(false);
	cin>>N>>M;	

	for(int i=0;i<N;i++)
		cin>>A[i];
	for(int i=0;i<M;i++)
		cin>>B[i];

	bool match = false, exist=false;


	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i+M-1>=N || j+M-1>=N) continue;
			match = true;
			for(int di=0;di<M;di++){
				for(int dj=0;dj<M;dj++){
					if(A[i+di][j+dj]!=B[di][dj]) match = false;
				}
			}
			if(match) exist = true;
		}
	}
	if(exist) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}



Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = 0
a = b = c = 0

if A + B > 2*C:
    mi = min(X, Y)
    ans += (mi * 2) * C
    X -= mi
    Y -= mi
    c += mi*2

if B > 2*C:
    ans += (Y * 2) * C
    Y = 0
    if X > Y:
        X -= Y
    else:
        X = 0
    c += Y*2
if A > 2*C:
    ans += (X * 2) * C
    X = 0
    if Y > X:
        Y -= X
    else:
        Y = 0
    c += X*2

ans += A*X + B*Y
a = X
b = Y

print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n, h;
  cin >> n >> h;
  priority_queue<P> que;
  P amax;
  cin >> amax.second >> amax.first;
  for (int i = 1; i < n; i++) {
    P tmp;
    cin >> tmp.second >> tmp.first;
    if (tmp.second > amax.second) {
      que.push(amax);
      amax = tmp;
    } else if (tmp.second == amax.second && tmp.first < amax.first) {
      que.push(amax);
      amax = tmp;
    } else {
      que.push(tmp);
    }
  }
  int cnt = 0;
  while (!que.empty() && h - amax.first > 0 && que.top().first > amax.second) {
    h -= que.top().first;
    que.pop();
    cnt++;
    if (h <= 0) {
      cout << cnt << endl;
      return 0;
    }
  }
  h -= amax.first;
  cnt++;
  if (h <= 0) {
    cout << cnt << endl;
    return 0;
  } else {
    cnt += (h + amax.second - 1) / amax.second;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
int main(void){int h,w,i,j;scanf("%d%d",&h,&w);while((h!=0)||(w!=0)){for(i=0;i<h;++i){for(j=0;j<w-1;++j){printf("%c",((i==0)||(i==h-1)||(j==0))?'#':'.');}puts("#");}puts("");scanf("%d%d",&h,&w);}return(0);}


Measured memory_bytes: 2552
#[allow(unused_imports)]
use { proconio::{fastout, input, marker::*}, std::cmp::*, std::collections::*, };

#[fastout]
fn main() {
   input! {
      n:usize,
      k:usize,
      a:[usize; n],
   }

   for i in k..n {
      if a[i] > a[i-k] {
         println!("Yes");
      } else {
         println!("No");
      }
   }
}


Measured memory_bytes: 5628
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextLong());
        }
        list.add(x);
        Collections.sort(list);
        List<Long> list2 = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list2.add(list.get(i + 1) - list.get(i) );
        }
        long ans = list2.get(0);
        for (int i = 1; i < n ; i++) {
            ans = gcd(ans, list2.get(i));
        }
        System.out.println(ans);
    }

    public static final long gcd(long a, long b) {
        if( b == 0 ) return a;
        return gcd(b, a % b);
    }
}

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

int main() {
  int64_t N;
  cin >> N;
  int64_t count = 0;
  while (true) {
    count++;
    int64_t num = count * count;
    if (num > N) {
      break;
    }
  }
  cout << (count - 1) * (count - 1) << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] alphabet = {"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"} ;
      
		String C = sc.next();
		String answer = "No answer";

		for(int i = 0;i <= 24;i++ ) {
			if(alphabet[i].equals(C)) {
				answer = alphabet[i+1];
			}else {
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

int main()
{
	int  n, w;
	while(1){
		cin >> n >> w;
		if(n == 0 && w == 0) break;
		double height[100] = {0};
		int howmanyranges = 0;
		for(int i = 0; i < n; i++){
			int v;
			cin >> v;
			int j = 0;
			while(1){
				if(v >= j * w && v < (j + 1) * w){
					height[j]++;
					break;
				}
				else j++;
			}
			howmanyranges = max(howmanyranges, (v / w + 1));
		}
		double maxheight = 0;
		for(int i = 0; i < 100; i++){
			maxheight = max(maxheight, height[i]);
		}
		double ans = 0;
		if(howmanyranges == 1) ans = 0;
		else {
			for(int i = 0; i < 100; i++){
				ans += ((howmanyranges - 1 - i) * height[i]) / ((howmanyranges - 1) * maxheight);			
			}
		}
		ans += 0.01;
		cout << setprecision( 6 ) << ans << endl;
	}
}

Measured memory_bytes: 1232
import itertools
import math 
def C(n,r): return n*(n-1)//r

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])


Measured memory_bytes: 31904
#include <iostream>

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    if(n == 1){
        cout << 1;
        return 0;
    }
    ll cur = 0, l0 = 2, l = 1;
    for(ll i = 2; i <= n; ++i){
        cur = l0 + l;
        l0 = l;
        l = cur;
    }
    cout << cur;
    return 0;
}


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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}

int main() {
    string s;
    bool flag = true;
    cin >> s;
    if (s.size() % 2 == 0) {
        for (int i = 0; i < s.size(); i += 2) {
            if (s.at(i) != 'h' || s.at(i+1) != 'i') {
                flag = false;
                break;
            }
        }
    }else {
        flag = false;
    }
    if (flag) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int mat [(int) 1e5][3];
    vec dp (3);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
            cin >> mat[i][j];
            if (i == 0){
                dp[j] = mat[i][j];
            }
        }
    }
    for (int i = 1; i < n; i++){
        vec newdp (3);
        newdp[0] = max(dp[1],dp[2]) + mat[i][0];
        newdp[1] = max(dp[0],dp[2]) + mat[i][1];
        newdp[2] = max(dp[1],dp[0]) + mat[i][2];
        dp = newdp;
    }
    int rs = 0;
    for (int i = 0; i < 3; i++){
        rs = max(rs, dp[i]);
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 105;
vector<pp> rc(n);
vector<vector<int>> dp(n+1,vector<int>(n+1,-1));

int f(int l,int r){
        if(dp.at(l).at(r) >= 0) return dp.at(l).at(r);
        if( l+1 == r) return dp.at(l).at(r) = 0;
        int res = INF;
        for(int i = l+1;i<r;i++){
                res = min(res,f(l,i)+f(i,r)+rc.at(l).first*rc.at(i).first*rc.at(r-1).second);
        }
        return dp.at(l).at(r) = res;
}

int main() {
        cin >> n;
        rep(i,n){
                 int r,c;
                cin >> r >> c;
                rc.at(i) = make_pair(r,c);
        }
        
        cout << f(0,n) << endl;
        
        return 0;
}





Measured memory_bytes: 3204
import java.util.Scanner;

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

        int cnt = 0;
        for (int i = 0; i < 3; i++) {
            if (s[i] == '1') {
                cnt++;
            }
        }

        sc.close();

        System.out.println(cnt);
    }
}


Measured memory_bytes: 25044
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        int ans = solve(n, l);
        System.out.println(ans);
    }

    static int solve(int n, int[] l) {
        Arrays.sort(l);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    int a = l[i];
                    int b = l[j];
                    int c = l[k];

                    if (a < b + c && b < c + a && c < a + b) {
                        ans++;
                    } else {
                        break;
                    }
                }
            }
        }

        return ans;
    }
}


Measured memory_bytes: 27796
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	if n % 2 != 0{
		fmt.Println("No")
	} else {
		str := map[bool]string{true: "Yes", false: "No"}[s[0:n/2] == s[n/2:n]]
		fmt.Println(str)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2LL << endl;
    }
    else {
        ll tmp = min(a - 1LL, n - b);
        cout << tmp + 1 + (b - a - 1) / 2LL << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
  int A,B,ASUM=0,BSUM=0;
  for(int i=0;i<4;i++){
    cin >> A;
    ASUM+=A;
  }for(int i=0;i<4;i++){
    cin >> B;
    BSUM+=B;
  }
  if(A>=B)cout << ASUM << endl;
  if(A<B)cout << BSUM << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=55,P=1000000007;
int i,j,k,l,n,m,ans;
int a[N<<1];
int f[N][N<<1][N<<1];
int main() {
	scanf("%d",&n);
	for (i=1;i<2*n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+n);
	f[1][0][0]=1;
	for (i=1;i<n;i++)
		for (j=0;j<2*i;j++)
			for (k=0;j+k<2*i;k++) if (f[i][j][k]) {
				int x=j,y=k;
				if (a[n-i]!=a[n-i+1]) x++;
				if (a[n+i]!=a[n+i-1]) y++;
				for (l=0;l<x;l++) f[i+1][l][y+1]=(f[i+1][l][y+1]+f[i][j][k])%P;
				for (l=0;l<y;l++) f[i+1][x+1][l]=(f[i+1][x+1][l]+f[i][j][k])%P;
				f[i+1][x][y]=(f[i+1][x][y]+f[i][j][k])%P;
			}
	for (i=0;i<2*n;i++)
		for (j=0;i+j<2*n;j++) ans=(ans+f[n][i][j])%P;
	printf("%d\n",ans);
}

Measured memory_bytes: 1408
// ABC 156-A
// 2020.2.23 bal4u

#include <stdio.h>

int main()
{
	int N, R, ans;

	scanf("%d%d", &N, &R);
	if (N >= 10) ans = R;
	else ans = R + 100*(10-N);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
// Problem: V - Subtree
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_v
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

const int N = 200020;
int fa[N], p, n;
vector <int> G[N], son[N];
void dfs0(int u, int f) {
    fa[u] = f;
    for (auto v: G[u]) {
        if (v != f) {
            son[u].push_back(v);
            dfs0(v, u);
        }
    }
}
vector <long long> pre[N], suf[N];
long long down[N], up[N];
void dfs1(int u) {
    int sz = son[u].size();
    pre[u].resize(sz);
    suf[u].resize(sz);
    down[u] = 1;
    for (auto v: son[u]) {
        dfs1(v);
        down[u] = (1 + down[v]) * down[u] % p;
    }
    for (int i = 0; i < sz; i++) {
        pre[u][i] = 1 + down[son[u][i]];
        if (i != 0) pre[u][i] = pre[u][i] * (pre[u][i - 1]) % p;
    }
    for (int i = sz - 1; i >= 0; i--) {
        suf[u][i] = 1 + down[son[u][i]];
        if (i != sz - 1) suf[u][i] = suf[u][i] * (suf[u][i + 1]) % p;
    }
}
void dfs2(int u) {
    if (u == 1) up[u] = 1;    // we are at the root
    int sz = son[u].size();
    for (int i = 0; i < sz; i++) {
        int v = son[u][i];
        up[v] = up[u];
        if (i != 0) up[v] = (up[v] * pre[u][i - 1]) % p;
        if (i != sz - 1) up[v] = (up[v] * suf[u][i + 1]) % p;
        up[v] = (up[v] + 1) % p;
        dfs2(v);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> p;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs0(1, 0);
    dfs1(1);
    dfs2(1);
    for (int i = 1; i <= n; i++)
        cout << down[i] * up[i] % p << endl;
}


Measured memory_bytes: 42704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
#define allSum(a) accumulate(a.begin(),a.end(),0)
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}
int mod=1e9+7;
signed main(){
  int n;
  str s;
  cin>>n>>s;
  map<char,int> m;
  rep(i,n)m[s[i]]++;
  int res=1;
  for(char i='a';i<='z';++i){
    res*=m[i]+1;
    res%=mod;
  }
  res--;
  out(res);
  

  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int h, w, k;
	int ans=0,num=0;
	cin >> h >> w >> k;
	// 表入力
	vector<string> a(h);
	string aStr;
	rep(i, h) {
		cin >> a[i];
	}
	// 横の選び方 2^w
	// 1をビットシフトして2^wを再現
	rep(i, 1<<w) {
		// 横の選び方 2^h
		// 1をビットシフトして2^hを再現 
		rep(j, 1 << h) {
			num = 0;
			// 行・列を選択していく
			rep(is, w) {
				rep(js, h) {
					if (((i >> is) & 1) == 1) {
						if (((j >> js) & 1) == 1) {
							if (a.at(js).at(is) == '#') {
								num++;
							}
						}
					}
				}
			}
			if (num == k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define MAX 500000
#define INF (1<<29)

vector<int> vec;

void make(){
  bool prime[MAX];
  fill(prime,prime+MAX,true);
  prime[0] = prime[1] = false;
  for(int i = 2 ; i < MAX ; i++){
    if(prime[i]){
      vec.push_back(i);
      for(int j = 2*i ; j < MAX ; j+=i){
        prime[j] = false;
      }
    }
  }
}


int main(){
  int M,A,B;
 
 make();
  while(cin >> M >> A >> B, (M | A | B)){
    int a,b,max = 0;
    for(int i = 0 ; i < (int)vec.size() ; i++){
      for(int j = 0 ; j <= i ; j++){
        if(vec[i]*vec[j] > M) break;
        if(A*vec[i] <= vec[j]*B){
          if(vec[i]*vec[j] > max){
            max = vec[i]*vec[j];
            a = vec[j]; b = vec[i];
          }
        }
      }
    }
    cout << a << " " << b << endl;
  }

  return 0;
}

Measured memory_bytes: 1832