akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main{
	public static void main(String[] args) {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		int jyunban=0;
		List<String> jisyo=new ArrayList<String>();
		int jisyosuu=0;
		char[] alpa=new char[26];
		alpa[0]='a';
		alpa[1]='b';
		alpa[2]='c';
		alpa[3]='d';
		alpa[4]='e';
		alpa[5]='f';
		alpa[6]='g';
		alpa[7]='h';
		alpa[8]='i';
		alpa[9]='j';
		alpa[10]='k';
		alpa[11]='l';
		alpa[12]='m';
		alpa[13]='n';
		alpa[14]='o';
		alpa[15]='p';
		alpa[16]='q';
		alpa[17]='r';
		alpa[18]='s';
		alpa[19]='t';
		alpa[20]='u';
		alpa[21]='v';
		alpa[22]='w';
		alpa[23]='x';
		alpa[24]='y';
		alpa[25]='z';

		try {
			str=bfr.readLine();
			jyunban=Integer.parseInt(bfr.readLine());

			for(int alphabt=0; alphabt<26; alphabt++) {
				for(int mojis=1; mojis<=Math.min(str.length(),5); mojis++) {
					/*if(jisyosuu<=jyunban)*/ {		// 辞書に登録された文字列数が知りたい順番を超えるまで
						for(int ichi=0; ichi<=str.length()-mojis; ichi++) {
							if(chartoint(str.charAt(ichi))==alphabt) {
								if(jisyosuu==0) {
									jisyo.add(str.substring(ichi, ichi+mojis));
									jisyosuu++;
								}
								else {
									if(jisyo.contains(str.substring(ichi, ichi+mojis))==false) {
										jisyo.add(str.substring(ichi, ichi+mojis));
										jisyosuu++;
									}
								}
							}
						}
					}
					/*else {
						mojis=6;
						break;
					}*/
				}
			}
			Collections.sort(jisyo);
			System.out.println(jisyo.get(jyunban-1));
		}catch(IOException e) {

		}
		catch(NumberFormatException ee) {
			System.exit(0);
		}

		catch(NullPointerException eee) {
			System.exit(0);
		}
	}

	static int chartoint(char a) {
		char[] alpa=new char[26];
		int kekka=0;
		alpa[0]='a';
		alpa[1]='b';
		alpa[2]='c';
		alpa[3]='d';
		alpa[4]='e';
		alpa[5]='f';
		alpa[6]='g';
		alpa[7]='h';
		alpa[8]='i';
		alpa[9]='j';
		alpa[10]='k';
		alpa[11]='l';
		alpa[12]='m';
		alpa[13]='n';
		alpa[14]='o';
		alpa[15]='p';
		alpa[16]='q';
		alpa[17]='r';
		alpa[18]='s';
		alpa[19]='t';
		alpa[20]='u';
		alpa[21]='v';
		alpa[22]='w';
		alpa[23]='x';
		alpa[24]='y';
		alpa[25]='z';
		for(int i=0; i<26; i++) {
			if(a==alpa[i]) {
				kekka=i;
				break;
			}
		}
		return kekka;
	}
}

Measured memory_bytes: 47480
n = int(input())
dp = [0, 0, 0]
for i in range(n):
    val = list(map(int, input().split()))
    next_dp = [0, 0, 0]
    for j in range(3):
        next_dp[j] = val[j] + max([dp[k] for k in range(3) if j != k])
    dp = next_dp
print(max(dp))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    char s[3];
    scanf("%s", s);
    bool n = s[0] == s[1] && s[1] == s[2];
    printf("%s\n", !n ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+1;
char  v[N][N];
long arr[N][N];
const int MOD = 1000000007;
long fun(const char v[1001][1001],int x,int y,int n,int m)
{
	if(x>n-1||y>m-1)
	{
		return 0;
	}
	if(v[x][y]=='#')
	{
		return 0;
	}
	if(x==n-1&&y==m-1)
	{
		return 1;
	}
	if(arr[x][y]!=-1)
	{
		return arr[x][y];
	}
	
		arr[x][y]=(fun(v,x+1,y,n,m)+fun(v,x,y+1,n,m))%MOD;
			return arr[x][y];

}
int main()
{
  		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	long n,m;
	cin>>n>>m;
	memset(arr,-1,sizeof(arr));
	for(long i=0;i<n;i++)
	{
		for(long j=0;j<m;j++)
		{
			cin>>v[i][j];
		}
	}
	long ans=fun(v,0,0,n,m);
	cout<<ans<<"\n";
}

Measured memory_bytes: 9216
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		 String s = in.next();
		 int nam = s.length();
		 
		 for(int i = 0 ;i < nam ;i++){
		     System.out.print("x");
		 }
      
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
    sort(S.at(i).begin(), S.at(i).end());
  }
  map<string, long long int> M;
  for (int i = 0; i < N; i++) {
    if (M.count(S.at(i))) M.at(S.at(i)) += 1;
    else M[S.at(i)] = 1;
  }
  
  long long int ans = 0;
  for (auto p : M) {
    long long int x = p.second;
    ans += x * (x - 1) / 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[2][N];
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      cin >> A[i][j];
    }
  }
  int ans = 0, ans1;
  for(int i=0;i<N;i++){
    ans1 = 0;
    for(int j=0;j<=i;j++){
      ans1 += A[0][j];
    }
    for(int j=i;j<N;j++){
      ans1 += A[1][j];
    }
    ans = max(ans, ans1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=3*(1e5)+10,M=1e5+10;
struct Rec{
    int l,r;
    friend bool operator < (Rec x,Rec y)
    {return (x.r-x.l+1)<(y.r-y.l+1);}
}a[N];
int n,m,ans;
namespace BIT{/*{{{*/
    int c[M];
    int mx;
    void init(int _n){mx=_n; memset(c,0,sizeof(c));}
    void insert(int x,int delta){for (;x<=mx;x+=x&-x) c[x]+=delta;}
    void update(int l,int r){insert(l,1); insert(r+1,-1);}
    int query(int x){
        int ret=0;
        for (;x;x-=x&-x) ret+=c[x];
        return ret;
    }
}/*}}}*/
void solve(){
    int now=1;
    for (int i=1;i<=m;++i){
        while (a[now].r-a[now].l+1<=i&&now<=n){
            BIT::update(a[now].l,a[now].r);
            ++now;
        }
        ans=n-now+1;
        for (int j=i;j<=m;j+=i){
            ans+=BIT::query(j);
        }
        printf("%d\n",ans);
    }
}
 
int main(){

    int l,r;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i)
        scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+1+n);
    BIT::init(m+1);
    solve();
}

Measured memory_bytes: 3712
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> sumw = vector<int>(n + 1);
  vector<int> sume = vector<int>(n + 1);
  rep(i, n) {
    sumw[i + 1] = sumw[i];
    if(s[i] == 'W') sumw[i + 1]++;
    sume[i + 1] = sume[i];
    if(s[i] == 'E') sume[i + 1]++;
  }

  // E ->
  // W <-

  int ans = INF;
  rep(i, n) {
    int now = 0;
    now += sumw[i];
    now += sume[n] - sume[i + 1];
    chmin(ans, now);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	return (a%b ? gcd(a%b, b) : b);
}

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


int main()
{
	int n; cin >> n;
	int t = 1;
	REP(i, n)
	{
		int a; cin >> a;
		t = lcm(t, a);
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 1160
void main(){
	int n, d;
	readf("%d %d\n", &n, &d);
	int cnt;
	foreach(i; 0..n){
		int x, y;
		readf("%d %d\n", &x, &y);
		if( sqrt(x.to!double^^2+y.to!double^^2)<= d.to!double )cnt++;
	}
	cnt.writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
     
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2808
#include<bits/stdc++.h>
#include <iostream>
#include<cstdio>
#define endl '\n'
using namespace std;
int main()
{
	int a,b,m;
	cin>>a>>b>>m;
	vector<int> r(a);
	vector<int> micro(b);
	for(int i = 0; i<a; i++)
		cin>>r[i];
	for(int i = 0; i<b; i++)
		cin>>micro[i];
	int A = *min_element( r.begin(),r.end() );
	int B = *min_element( micro.begin(),micro.end() );
	int ans = A + B;
	for(int i = 0; i<m; i++)
	{
		int x,y,c;
		cin>>x>>y>>c;x--,y--;
		ans = min(ans,r[x]+micro[y]-c);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	int x, y;
	cin >> x >> y;
	rep(i, x + 1)
	{
		if (i * 2 + (x - i) * 4 == y)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  ll n; cin >> n;
  if(n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string ans;
  int i = 0;
  ll base = 1;
  while(n != 0) {
    if(n % (base*2) == 0) ans+='0';
    else {
      ans += '1';
      n -= base;
    }
    i += 1;
    base *= -2;
  }
  reverse(ALL(ans));
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	string s;
	map<char, int> mp;

	for (char c = 'a'; c <= 'z'; c++) mp[c] = 0;

	while (true) {
		getline(cin, s);
		int len = s.length();

		if (len == 0) break;

		rep(i, len) {
			if ('a' <= s[i] && s[i] <= 'z') mp[s[i]]++;
			else if ('A' <= s[i] && s[i] <= 'Z') mp[s[i] + 0x20]++;
		}
	}

	for (char c = 'a'; c <= 'z'; c++) printf("%c : %d\n", c, mp[c]);

	return 0;
}



Measured memory_bytes: 3292
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
using u64 = std::uint_fast64_t;

public:
u64 a;

constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};

using mint = modint<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    string S;
    cin >> N >> S;

    map<char, mint> dic;
    rep(i,N) dic[S[i]] += 1;
    mint ans = 1;
    for (auto i : dic) ans *= (i.second + 1);
    ans -= 1;
    cout << ans.a << endl;

}


Measured memory_bytes: 512
// Bismillahirrahmanirrahim
// by Batrrr Tolkynbayev
#include <bits/stdc++.h>
// skripi krasava
#define respa return 0
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 17, M = N << 2, mod = 1e9 + 7; 

int tt = 1;
ll a, b;

void solve () {
	cin >> a >> b;
	ll neg = (a < 0 ? (b - a + 1) : 0);
	if (a <= 0 && b >= 0) cout << "Zero";
	else if (neg & 1) {cout << "Negative";}
	else cout << "Positive";
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// cin >> tt;
	while (tt--) solve();
	respa;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int N, M, X;
  int *A;
  int lcost = 0, rcost = 0;
  scanf("%d %d %d", &N, &M, &X);
  A = (int*)calloc(N+1, sizeof(int));
  for (int i = 0; i < M; i++) {
    int t;
    scanf("%d", &t);
    A[t] = 1;
  }
  for (int i = 0; i < X; i++) {
    lcost += A[i];
  }
  for (int i = X; i <= N; i++) {
    rcost += A[i];
  }

  printf("%d\n", (lcost > rcost) ? rcost : lcost );

  return 0;
}

Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i32,
    }
    // annotate for rust-analyzer
    let a: i32 = a;

    println!("{}", a + a.pow(2) + a.pow(3));
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#define int         int64_t
#define int         long long int
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 4e18, mod = 1e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    string s; cin >> s;
    cout << ((s.size()%2) ^ (s[0] == s.back()) ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e16 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100100], b[100100];
ll c[100100];
int q, k;
int x[100100], y[100100];

struct edge {
    int to;
    ll w;
};

vector<edge> g[100100];

ll d[100100];

void calc(int v, int p) {
    for (edge e : g[v]) {
        if (e.to == p) continue;
        d[e.to] = d[v] + e.w;
        calc(e.to, v);
    }
}

void solve() {
    for (int i = 0; i < n-1; i++) {
        g[a[i]].push_back(edge{b[i], c[i]});
        g[b[i]].push_back(edge{a[i], c[i]});
    }

    calc(k, -1);
    for (int i = 0; i < q; i++) {
        cout << d[x[i]] + d[y[i]] << endl;
    }
}

void input() {
    cin >> n;
    for (int i = 0; i < n-1; i++) cin >> a[i] >> b[i] >> c[i];
    cin >> q >> k;
    for (int i = 0; i < q; i++) cin >> x[i] >> y[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll ans = 0;
  rep(i, n) {
    ll start = v.at(i);
    ans++;
    while (i<n && v.at(i)==start) i++;
    if (i == n) break;
    if (v.at(i) < start) {
      while (i+1<n && v.at(i+1)<=v.at(i)) i++;
    }
    if (v.at(i) > start) {
      while (i+1<n && v.at(i+1)>=v.at(i)) i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long h,w,i,j,num[55][55];
char s[55][55];

int main() {
  cin >> h >> w;
  
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      cin >> s[i][j];
    }
  }
  
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      if(s[i][j] == '#') {
        num[i][j+1] ++;
        num[i][j-1] ++;
        num[i+1][j+1] ++;
        num[i-1][j+1] ++;
        num[i+1][j] ++;
        num[i-1][j] ++;
        num[i+1][j-1] ++;
        num[i-1][j-1] ++;
      }
    }
  }
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      if(s[i][j] != '#') {
        cout << num[i][j];
      }
      else {
        cout << '#';
      }
    }
    cout << endl;
  }
}

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

using namespace std;

const int MOD = 1e9 + 7;

int main(){
int N; cin >> N;
  string S1,S2; cin >> S1 >> S2;
  
  int i = 0;
  
  vector<char> vec;
    
  while( i < N){
    if( S1[i] == S2[i]){ vec.push_back('a'); i++;}
    else{ vec.push_back('b'); i += 2;}}
  
  long long cnt = 1;
  
  if( vec[0] == 'a'){ cnt *= 3;}
  else{ cnt *= 6;}
  
  for(int i = 1; i < vec.size(); i++){
    //vec[i-1]とvec[i]の比較を行いたい
    if(vec[i-1] == 'a' && vec[i] == 'a' ){ cnt *= 2;}
    else if( vec[i-1] == 'a' && vec[i] == 'b'){ cnt *= 2;}
    else if( vec[i-1] == 'b' && vec[i] == 'a' ){ cnt *= 1;}
    else if( vec[i-1] == 'b' && vec[i] == 'b' ){ cnt *= 3;}
    cnt = cnt % MOD;}
  
  cout << cnt << endl; return 0;}
  

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


int a[1000],b[1000],c[1000];

int main(){
	int n;
	cin>>n;
	rep(i,n){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		string s,s2;
		cin>>s;
		//cout<<s<<endl;
		//cout<<s.size()<<endl;
		if(s.size()>80){
			cout<<"overflow"<<endl;
			cin>>s2;
			continue;
		}
		rep(j,s.size()){
			a[90-j]=s[s.size()-j-1]-'0';
			//cout<<s[s.size()-j-1]-'0';
		}
		//cout<<a[87]<<endl;
		cin>>s2;
		if(s2.size()>80){
			cout<<"overflow"<<endl;
			continue;
		}
		rep(j,s2.size()){
			b[90-j]=s2[s2.size()-j-1]-'0';
		}
		/*
		rep(j,91) cout<<a[j];
		cout<<endl;
		rep(j,91) cout<<b[j];
		cout<<endl;
		*/
		int t=0;
		for(int j=90;j>=0;j--){
			c[j]=(a[j]+b[j]+t)%10;
			if((a[j]+b[j]+t)>9) t=1;
			else t=0;
		}
		bool f=true;
		/*
		rep(j,91) cout<<c[j];
		cout<<endl;
		*/
		rep(j,91){
			if(f&&c[j]!=0){
				f=false;
				if(j<=10){
					cout<<"overflow";
					break;
				}
			}
			if(!f) cout<<c[j];
		}
		if(f) cout<<"0";
		cout<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 1224
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    A = list(map(int,input().split()))

    #i%2==0を加算、i%2==1を減算すれば山1の高さになる。
    tmp = 0
    for i in range(N):
        if i%2==0:
            tmp+=A[i]
        else:
            tmp-=A[i]

    ans = [tmp]
    for i in range(N-1):
        tmp = (A[i]-tmp//2)*2
        ans.append(tmp)

    print(*ans)
        
if __name__=='__main__':
    main()

Measured memory_bytes: 20484
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define tax 1.05

int main(){
	double i,n,a=100000;
	cin>>n;
	for(i=0;i<n;i++){
		a*=tax;
		if((int)a%1000!=0){
			a=a-(int)a%1000+1000;
		}
	}
	cout<<(int)a<<endl;

    return 0;
}

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

int main(){
  int n, check=0;
  char w[200][200];
  scanf("%d",&n);
  int i,j;
  for(i=0;i<n;i++) scanf("%s", w[i]);
  for(i=0;i<n-1;i++){
    if(w[i+1][0]!=w[i][strlen(w[i])-1]) check=1;
    else{
      for(j=0;j<=i;j++){
        if(strcmp(w[i+1],w[j])==0) check=1;
      }
    }
  }
  if(check==0) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 128
from collections import deque

n,k = map(int,input().split())
li = list(map(int,input().split()))

for i,l in enumerate(li):
  li[i]-=1

done = [0]*n
root = []
que  = deque()

done[0] = 1
root.append(0)
que.append(li[0])


while(len(que)!=0 and len(root)<k+1):
  v = que.pop()
  
  if done[v]!=0:
    root.append(v)
    break

  done[v] = 1
  root.append(v)
  que.append(li[v])

if len(root)==k+1:
  print(root[-1]+1)
else:
  fidx = root.index(root[-1])
  lidx = len(root)-1
  lp   = lidx-fidx

  cnt = (k-fidx)%lp

  if cnt==0:
    print(root[-1]+1)
  else:
    que.append(root[-1])
    for i in range(cnt):
      v = que.pop()
      que.append(li[v])
    print(que.pop()+1)

Measured memory_bytes: 33800
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString.Char8 as C
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

main = C.interact $ put . sol . get

get = U.unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . unlines . fmap show . U.toList

sol v = runST $ do
  h <- UM.replicate (10^5+1) 0
  U.forM_ as $ UM.unsafeModify h (+ 1)
  r <- UM.unsafeNew q
  forM_ [0..q-1] $ \i -> do
    if i==0
      then UM.unsafeWrite r i $ U.sum as 
      else UM.unsafeRead r (i-1) >>= UM.unsafeWrite r i
    let (b,c) = (qs U.! (2*i),qs U.! (2*i+1))
    cnt <- UM.unsafeRead h b
    UM.unsafeWrite h b 0
    UM.unsafeModify h (+ cnt) c
    UM.unsafeModify r (+ (cnt*(c-b))) i
  U.unsafeFreeze r
  where
  n = v U.! 0
  as = U.slice 1 n v
  q = v U.! (n+1)
  qs = U.unsafeDrop (n+2) v

Measured memory_bytes: 38804
import math
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))
if n == 1:
    print(t[0])
else:
    tmp = t[0]
    for i in range(1,n):
        div = math.gcd(tmp,t[i])
        tmp = (t[i] * tmp)//div
    print(tmp)


Measured memory_bytes: 62672
N,M=map(int,input().split())
data=[]
for m in range(M):
    data.append(list(map(int,input().split())))
    data[m].append(m)

data.sort(key=lambda x:x[1])
data.sort(key=lambda x:x[0])

pref=0
count=0
for m in range(M):
    count+=1
    if data[m][0]!=pref:
        count=1
    pref=data[m][0]
    ID=('000000'+str(data[m][0]))[-6:]+('000000'+str(count))[-6:]
    data[m].append(ID)

data.sort(key=lambda x:x[2])

for m in range(M):
    print(data[m][3])

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

int main(){
  int N[4];
  for(int i=0;i<4;i++){
    cin >> N[i];
  }
  int K[4] = {1,9,7,4};
  int ans = 0;
  for(int i=0;i<4;i++){
    int r =1;
    for(int j=0;j<4;j++){
      
      if(N[j] == K[i]) r *= 0;
    }
    ans += r;
  }  
  if(ans == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> A(m, vector<int>(n, 0));
    rep(i,m){
        int ki=0;cin >> ki;
        rep(j,ki){
            int sw;
            cin >> sw;
            sw--;
            A[i][sw] = 1; 
        }
    }
    vector<int> P(m,0);
    rep(i,m) cin >> P[i];


    int cnt=0;
    for(int mask=0; mask < (1 << n); mask++){
        int akari=0;
        for(int a=0; a<m; a++){
            int point=0;
            for(int i=0; i<n; i++){
                if ((mask >> i & 1) & A[a][i])  point++;
            }
            if(point%2 == P[a]) akari++;
        }
        if(akari==m) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
long a[100000001],ans=0,n;
int main()
{
    cin>>n;
    for(int i=1;i<=2*n;i++)
        cin>>a[i];
    sort(a+1,a+1+2*n);  
    for(int i=1;i<=2*n;i+=2)
        ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans=-1000;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		int ans2=0;
		while(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
		{
			ans2++;
			i++;
		}
		ans=max(ans,ans2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = "Yes"
bf_max = 0
for now in h:
    if bf_max <= now-1:
        bf_max = now - 1
    elif bf_max <= now:
        bf_max = now
    else:
        ans = "No"
        break


print(ans)


Measured memory_bytes: 20780
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	rep(i, n)
	{
		cin >> v[i];
	}
	rep(i, n)
	{
		cin >> c[i];
	}
	int ans = 0;
	rep(i, n)
	{
		if (v[i] - c[i] > 0)
		{
			ans += v[i] - c[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
L,R=[int(x) for x in input().split()]
R=min(R,L+2018)
numbers=[x%2019 for x in range(L,R+1)]
length=len(numbers)
minimum=[]
for i in range(length):
	for j in range(i+1,length):
		minimum.append((numbers[i]*numbers[j])%2019)
print(min(minimum))

Measured memory_bytes: 205036
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  REP(i, N) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  REP(i, M) cin >> t[i];

  map<string, int> sm;
  REP(i, N) sm[s[i]] += 1;
  map<string, int> tm;
  REP(i, M) tm[t[i]] += 1;

  int m = 0;
  REP(i, N) m = max(m, sm[s[i]] - tm[s[i]]);
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include    <iomanip>
using namespace std;
int main(){
    int num;
    while(cin>>num&&num!=0){
        
        char a[100000][2];
        for (int i=0; i<num; i++) {
            cin>>a[i][0]>>a[i][1];
            
        }
        int num2;
        cin>>num2;
        char k;
        for (int i=0; i<num2; i++){
            cin>>k;
            for (int ii=0; ii<num; ii++) {
                if (a[ii][0]==k) {
                    k=a[ii][1];
                    ii=num;
                }
            }
            cout<<k;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int dp[10001], p[10001];

typedef pair<int, pair<int, int> > Event;

int main() {
  for (;;) {
    int n, r;
    cin >> n >> r;
    if (!(n || r)) return 0;
    map<int, vector<Event> > events;
    int mx = 0, c = 0, area = 0, circumference = 0;
    for (int i = 0; i < n; i++) {
      int sx, sy, ex, ey;
      cin >> sx >> sy >> ex >> ey;
      events[sy].push_back(make_pair(1, make_pair(sx, ex)));
      events[ey].push_back(make_pair(-1, make_pair(sx, ex)));
      mx = max(mx, ex);
    }
    fill(dp, dp+mx+1, 0);
    fill(p, p+mx+1, 0);
    for (map<int, vector<Event> >::iterator v = events.begin();
         v != events.end(); ++v) {
      int count = 0, a = 0, b = 0;
      for (int i = 0; i < mx; i++) {
        if (dp[i]) {
          count++;
          if (dp[i+1]) a++;
          if (p[i]) b++;
        }
        p[i] = dp[i];
      }
      circumference += ((v->first - c) * (count - a) + count - b) * 2;
      area += (v->first - c) * count;
      c = v->first;
      for (vector<Event>::iterator e = v->second.begin();
           e != v->second.end(); ++e)
        for (int i = e->second.first; i < e->second.second; i++)
          dp[i] += e->first;
    }
    /*
    fill(dp, dp+mx, 0);
    for (map<int, vector<Event> >::iterator v = events.begin();
         v != events.end(); ++v) {
      int count = 0;
      for (int i = 0; i < mx; i++) if (dp[i]) count++;
      area += (v->first - c) * count;
      c = v->first;
      for (vector<Event>::iterator e = v->second.begin();
           e != v->second.end(); ++e)
        for (int i = e->second.first; i < e->second.second; i++)
          dp[i] += e->first;
      for (int i = 0; i < mx; i++)
        cout << dp[i] << ' ';
      cout << endl;
    }
    */
    cout << area << endl;
    if (r == 2)
      cout << circumference << endl;
  }
}

Measured memory_bytes: 1700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
    public static void main(String[] args) {

    	try{
    		InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);

			while(true){
				String buf = br.readLine();
				StringTokenizer st=new StringTokenizer(buf," ");
				int H = Integer.parseInt(st.nextToken());
				int W = Integer.parseInt(st.nextToken());

				if(W==0 && H==0)	break;

				for(int i=1;i<=H;i++){
					for(int j=1;j <= W;j++)
						System.out.print("#");
				System.out.println();
				}
				System.out.println();
			}
		} catch(IOException e) {
    		System.err.println(e);
		}
    }
}

Measured memory_bytes: 26028
#include <bits/stdc++.h>
#define _MATH_DEFINES_DEFINED
#pragma GCC optimize("O2")
typedef long long ll;
const ll inf=ll(1e+18)+1;
using namespace std; 
int n;
ll k,p;
inline int read(void){
	int f=1,n=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){n=n*10+(c-'0');c=getchar();}
	return f*n;
}
inline ll read2(void){
	ll f=1,n=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){n=n*10+(c-'0');c=getchar();}
	return f*n;
}
vector<ll> a;
bool OK(ll mid){
	ll total=0;
	for(int i=0;i<n;i++){
		if(a[i]<0){
			int L=-1,R=n;
			while(L<R-1){
				int m=(L+R)>>1;
				if(a[m]*a[i]<mid) R=m;
				else L=m;
			}
			total+=n-R;
		}
		else{
			int L=-1,R=n;
			while(L<R-1){
				int m=(L+R)>>1;
				if(a[m]*a[i]<mid) L=m;
				else R=m;
			}
			total+=R;
		}
		if(a[i]*a[i]<mid) total--;
	}
	total/=2;
	return total<k;
}
signed main(void){
	n=read(),k=read2();
	for(int i=0;i<n;i++) p=read2(),a.push_back(p);
	sort(a.begin(),a.end());
	ll left=-inf,right=inf;
	while(left<right-1){
		ll mid=(left+right)>>1;
		if(OK(mid)) left=mid;
		else right=mid;
	}
	cout<<left<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
bool has_divisor(int, int);

//グローバル変数
//const int MAX_N;
//const int MAX_M;
//vvec data(N, vec(M));
//const int INF = ;
//const int mod = ;

//関数：
/* yにxをn回乗じmodで割った余りを返す。
（素数pに対して x**p = x (mod p) が成り立つ。）*/
int mod_pow(int y, int x, int n, int mod) {
	int ans = y;
	rep(i, n) {
		ans *= x;
		ans %= mod;
	}
	return ans;
}

/* ユークリッドの互除法(mx > mn) */
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

/* 素数判定関数 */
bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

/* クイック・ソート（返し値：互換数） */
int64_t quicksort(vector<int> &arr, int left, int right) {
	int i, j, p;
	int64_t ans = 0;
	i = left; j = right;
	p = (arr[i]+arr[j]) / 2;
	while(i < j) {
		while(arr[i] < p) i++;
		while(arr[j] > p) j--;
		if (i < j) {
			swap(arr[i++], arr[j--]);
			ans += abs(i-j);
		}
		if(i == j) {
			if(arr[i] < p) i++;
			else if(arr[j] > p) j--;
		}
		if (i >= left+2) ans += quicksort(arr, left, i-1);
		if (j <= right-2) ans += quicksort(arr, j+1, right);
	}
	return ans;
}

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

	int n; cin >> n;
	string s; cin >> s;
	
	int lg = s.size();
	if(n%2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	int slg = n/2;
	bool frag = true;
	for(int i=0; i<slg; i++) {
		if(s[i] != s[slg+i]) {
			frag = false;
			break;
		}
	}
	if(frag) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

// 以下の関数等は気にしない。
bool has_divisor(int n, int i) {
	//base case 1:
	if (i == n) return false;
	//base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();

/*struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*string ans = w;
string &ref = ans;
rep(i, N) {
	ref[i] = arr[i];
}*/

/*map<int,int> mp;
for(auto p : mp) {
	ct += p.second*(p.second-1); }

map<int,int>::iterator itr;
for(itr = mp.begin(); itr != mp.end(); itr++) {
	ans += itr->second * (itr->second-1);
}*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+7;

char s[maxn],t[maxn];

int main(){
    cin>>s+1>>t+1;
    int len=strlen(s+1);
    int ans=0;
    fo(i,1,len) if(s[i]!=t[i]) ans++;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      if ((M - j) * i + (N - i) * j == K) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
}

Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
		if(n&1)ans*=x;
	return ans % MOD;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, K;
	int ans = 0;
	vector<int> con;
	
	cin>>N>>K;
	
	con.resize(K);
	
	for(int i = 1; i <= K; i++){
		con[i] = power(K/i, N);
		con[i] %= MOD;
	}
	
	for(int i = K-1; i >= 1; i--){
		for(int j = i * 2; j <= K; j += i){
			con[i] = (con[i] + MOD - con[j]) % MOD;
		}
	}
	
	for(int i = 1; i <= K; i++){
		ans += con[i] * i % MOD;
		ans %= MOD;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  string s;cin>>s;
  ll n=s.size();
  string k="";
  rep(i,0,n)if(s[i]!='x')k+=s[i];
  bool e=true;
  rep(i,0,(k.size()+1)/2){
    if(k[i]!=k[k.size()-1-i])e=false;
  }

  if(!e){
    out(-1);
    return 0;
  }

  ll ans=0;
  while(s.size()>1){
    if(s[0]==s[s.size()-1]){
      s.pop_back();
      s.erase(s.begin());
    }else{
      ans++;
      if(s[0]=='x'){
        s+='x';
      }else if(s[s.size()-1]=='x'){
        s.insert(s.begin(),'x');
      }else{
        out(-1);
        return 0;
      }
    }
  }
  out(ans);


  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}





struct UnionFind
{

  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]); 
  }

  void unite(int x, int y) {

    x = find(x);
    y = find(y);

    if (x == y) return;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return sizes[find(x)];
  }
};



struct Edge
{
  int a, b, cost;

  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};



int kruskal(int n,vector<Edge> es) {
  sort(es.begin(), es.end());

  UnionFind uf(n);
  int min_cost = 0;

  rep(ei, es.size()) {
    Edge& e = es[ei];
    if (!uf.same(e.a, e.b)) {
      min_cost += e.cost;
      uf.unite(e.a, e.b);
    }
  }

  return min_cost;
}


signed main(){
  int n,m;
  cin>>n>>m;
  vector<Edge> e;
  rep(i,m){
    Edge d;
    cin>>d.a>>d.b>>d.cost;
    e.PB(d);
  }

  cout<<kruskal(n,e)<<endl;
}



Measured memory_bytes: 7768
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    ll n,k,d;
    cin >> n >> k>> d;
    if(n<0) n=n*-1;

        if((n/d)>=k)
        {
            cout <<n-d*k<<endl;
            return ;
        }
        if((k-(n/d))%2==0)
        {
            cout <<n-d*(n/d)<<endl;
            return ;
        }
        n = n-d*(n/d);
        cout <<min(n+d,abs(n-d))<<endl;


}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
   // cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}



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

int main() {
 int x,a,b;
  cin>>x>>a>>b;
  int h,l;

  if(x<a){
    h=a-x;
  }
  else{
    h=x-a;
  }
  
  if(x<b){
    l=b-x;
  }
  else{
    l=x-b;
  }
  
  if(h<l){
    cout<<"A"<<endl;
  }
  else{
    cout<<"B"<<endl;
  }
  
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if A[j][i] == B[0][0]:
            flag = True
            for k in range(M):
                if A[j+k][i:i+M] != B[k]:
                    flag = False
            if flag:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 3064