akhauriyash/Code-Regression huggingface dataset:
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

s=gets.chomp.split(",")
puts s.join(" ")

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

int main() {
    string s;
    cin >>s;
    int ans=0;
    for(int i=0; i<s.length(); ++i){
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
                ans +=1;
            }
        }
        else if(i%2==1){
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
                ans +=1;
            }
        }
    }
    if(ans==s.length()){
        cout << "Yes"<< endl;
    }
    else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    edge[a-1].append((b-1, c))
    edge[b-1].append((a-1, c))
Q, K = map(int, input().split())
seen = [0] * N
dist = [0] * N
seen[K-1] = 0
todo = deque([(K-1, 0)])
while todo:
    cur_v, cur_weight = todo.pop()
    seen[cur_v] = 1
    dist[cur_v] = cur_weight
    for next_v, next_weight in edge[cur_v]:
        if not seen[next_v]:
            todo.append((next_v, cur_weight + next_weight))

for _ in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1] + dist[y-1])

Measured memory_bytes: 47972
#include<iostream>
#include<cstring>
using namespace std;
int n,m,a[100010];
long long p[200010],all,maxp;
int main()
{
	all=0;
	memset(a,0,sizeof(a));
	memset(p,0,sizeof(p));
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=2;i<=n;i++){
		int temp=a[i]-a[i-1];
		if(temp<0){
			temp+=m;
		}
		all+=temp;
	}
	for(int i=2;i<=n;i++){
		int l=a[i-1],r=a[i];
		if(l>r){
			r+=m;
		}
		l+=2;
		if(l<=r){
			p[l]+=1;
			p[r+1]-=r-l+2;
			p[r+2]+=r-l+1;
		}
	}
	for(int i=2;i<=2*m+2;i++){
		p[i]+=p[i-1];
	}
	for(int i=2;i<=2*m+2;i++){
		p[i]+=p[i-1];
	}
	maxp=p[1]+p[1+m];
	for(int i=2;i<=m;i++){
		if(p[i]+p[i+m]>maxp){
			maxp=p[i]+p[i+m];
		}
	}
	cout<<all-maxp<<endl;
	return 0; 
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
 
const int maxn = 1e5 + 20;

string s;
int a[maxn], b[maxn], ia, ib, x, y, majb, maja;
bool dp[maxn];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> s >> x >> y;
	s += "T";
	int n = s.size(), f = 0;
	ia = ib = 1;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'T')
		{
			if ((ib + ia) & 1)
				b[ib++] = f;
			else
				a[ia++] = f;
			f = 0;
		}
		else
			f ++;
	}
	maja = x, majb = y;
	maja = abs (maja - a[1]);
	dp[0] = 1;
	for (int i = 2; i < ia; i++)
	{
		bool fu[maxn] = {0};
		for (int j = 0; j < maxn; j++)
		{
			if (dp[j] && j + a[i] < maxn)
				fu[j + a[i]] = 1;
			if (dp[j])
				fu[abs(j - a[i])] = 1;
		}
		for (int i = 0; i < maxn; i++)
		{
			dp[i] = fu[i];
			/*if (dp[i])
				cout << i << endl;*/
		}
	}
	if (!dp[maja])
		return cout << "No" << endl, 0;
	
	//cout << maja << endl;
	memset (dp, 0, sizeof dp);
	dp[0] = 1;
	for (int i = 1; i < ib; i++)
	{
		bool fu[maxn] = {0};
		for (int j = 0; j < maxn; j++)
		{
			if (dp[j] && j + b[i] < maxn)
				fu[j + b[i]] = 1;
			if (dp[j])
				fu[abs(j - b[i])] = 1;
		}
		for (int i = 0; i < maxn; i++)
			dp[i] = fu[i];
	}
	cout << (dp[abs(majb)] ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;

	cin >> N;

	for(int x=0;x<=50000;x++)
	{
		if((x*108)/100==N)
		{
			cout << x << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}



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

int main()
{
    std::string s;
    std::cin >> s;
    int a = 0;
    for (char c : s) {
        if (c == 'C') a = 1;
        else if (c == 'F' && a == 1) {
            a = 2; break;
        }
    }
    puts(a == 2 ? "Yes" : "No");
}

Measured memory_bytes: 384
#include<algorithm>
#include<cstdio>
#include<set>
#include<utility>
using namespace std;

struct vertex {
    int cnt = 0, bcnt = 0;
    double prob = 0.0, weight = 0.0;
    set<int> from, to;
};

int n, m;
pair<int, int> p[180000];
bool jdg[600];
vertex ver[600];

void dfs(int x) {
    if (++ver[x].cnt < ver[x].from.size()) return;
    for (auto &i : ver[x].to) {
        ver[i].prob += ver[x].prob / ver[x].to.size();
        dfs(i);
    }
}

void bdfs(int x) {
    if (++ver[x].bcnt < ver[x].to.size()) return;
    if (x != n - 1) ver[x].weight /= ver[x].to.size();
    for (auto &i : ver[x].from) {
        ver[i].weight += ver[x].weight + 1.0; 
        bdfs(i);
    }
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) scanf("%d %d", &p[i].first, &p[i].second);
    sort(p, p + m);
    jdg[0] = true;
    for (int i = 0; i < m; i++) {
        if (jdg[p[i].first - 1]) {
            jdg[p[i].second - 1] = true;
            ver[p[i].first - 1].to.emplace(p[i].second - 1);
            ver[p[i].second - 1].from.emplace(p[i].first - 1);
        }
    }

    ver[0].prob = 1.0; 
    dfs(0);
    bdfs(n - 1);
    
    double rdc = 0.0;
    for (int i = 0; i < m; i++) {
        if (!jdg[p[i].first - 1] || ver[p[i].first - 1].to.size() == 1) continue;
        double a = 0.0;
        for (auto &j : ver[p[i].first - 1].to) {
            if (j == p[i].second - 1) continue;
            a += ver[j].weight + 1.0;
        }
        a /= (ver[p[i].first - 1].to.size() - 1);
        rdc = min(rdc, (a - ver[p[i].first - 1].weight) * ver[p[i].first - 1].prob);
    }

   
    printf("%5.15lf\n", ver[0].weight + rdc);
    return 0;
}



Measured memory_bytes: 18560
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int K, X;
  cin >> K >> X;

  if(K*500 >= X)  cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define mrep(p,mp) for(auto p : mp)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
ll n;
cin >> n;
map<string,ll> mp;
rep(i,n){ 
    string a;
    cin >> a;
    sort(a.begin(),a.end());
    mp[a]++;
}
ll sum = 0;
mrep(p,mp){ 
    sum += p.second*(p.second-1)/2;
}
cout << sum << endl;
}

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

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

    if(a <= 2*b) {
        cout << 0;
    }
    else {
        cout << a-2*b;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
//----------------------------------------------------------------
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int ans;
  if(n%2==1){
    ans = b[n/2] - a[n/2]+1;
  } else {
    int med1 = b[n/2] + b[n/2-1];
    int med2 = a[n/2] + a[n/2-1];
    ans = med1 - med2 + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){;
	while(1){
		int n,l,r;
		cin>>n>>l>>r;
		if(n==0) break;
		vi a(n);
		for(auto &i:a) cin>>i;
		int res=0;
		for(int i=l;i<=r;i++){
			bool B=0;
			for(int j=0;j<n;j++) if(i%a[j]==0){
				if(j%2==0) res++;
				B=1;
				break;
			}
			if(B==0&&n%2==0) res++;
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3080
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}
int n,m,l,r;
int a,b,c,d;
int A[101],B[1001],C[10001];
string S;
void input(){
	cin>>S;
}
int t[100];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();

	int cnt=0;
	/*rep(i,4)t[S[i]-'0']++;
	rep(i,100){
		if(t[i]>=3){
			P("Yes");
			return 0;
		}
	}*/
	if((S[0]==S[1]&&S[1]==S[2])||(S[1]==S[2]&&S[2]==S[3])){
		P("Yes")
	}
	else
		P("No");
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    int N = sc.nextInt();

    if( D == 0){
      if( N <= 99){
        System.out.println(  N );
      }else{
        System.out.println( 101 );
      }
    }else if( D == 1){
      if( N <= 99){
        System.out.println( N   * 100 );
      }else{
        System.out.println( 10100 );
      }
    } else{
      if( N <= 99){
        System.out.println( N   * 10000 );
      }else{
        System.out.println( 1010000 );
      }
    }
  }
}


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


int main(void){
    char s[11];
    scanf("%s", s);
    if(strcmp("hi", s) == 0 || strcmp("hihi", s) == 0 || strcmp("hihihi", s) == 0 || strcmp("hihihihi", s) == 0 || strcmp("hihihihihi", s) == 0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
def resolve():
    n = int(input())
    x = list(map(int, input().split()))
    rs = 10**10
    for i in range(1,101):
        x1 = x
        x2 = list(map(lambda x:x-i, x1))
        x3 = list(map(lambda x:x**2, x2))
        x3 = sum(x3)
        if rs > x3:
            rs = x3
    print(rs)
resolve()

Measured memory_bytes: 38896
W,a,b = map(int, input ().split ())
if a < b:
  A,B = W+a,b
  if A >= B:
    print (0)
  else:
    print (B-A)
else:
  A,B = a,W+b
  if B >= A:
    print (0)
  else:
    print (A-B)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  int XS = 0;
  for(int i = 0; i < N; i++){
    cin >> X.at(i);
    XS += X.at(i);
  }
  int Xc = round(float(XS)/float(N));
  int S0;
  for(int i = 0; i < N; i++){
    S0 += (X.at(i) - Xc)*(X.at(i) - Xc);
  }
  cout << S0 << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=300000, A=128;
char s[N];
ll cnt[A];

int main() {
    ll i, n, ans;
    scanf("%s", s);
    for(n=0; s[n]; n++) cnt[int(s[n])]++;
    ans=1+n*(n+1)/2;
    for(i=0; i<A; i++) ans-=cnt[i]*(cnt[i]+1)/2;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int area=a*b;
        int length=2*(a+b);
        System.out.println(area+" "+length);
        sc.close();
    }
}


Measured memory_bytes: 26184
#include <iostream>

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

    int max_count = 0;
    int ans = 1;
    for (int i = 1; i <= N; i++) {
        int j = i;
        int count = 0;
        while (true) {
            if (j == 0 || j % 2 == 1) {
                break;
            }
            j /= 2;
            count++;
        }

        if (count > max_count) {
            max_count = count;
            ans = i;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

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

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = read();

		int h = a[1], c = 0;
		foreach (var _ in new int[a[0]].SelectMany(_ => read().Select((x, i) => new { x, i })).OrderBy(_ => -_.x))
		{
			c++;
			if (_.i == 0)
			{
				c += h / _.x - (h % _.x == 0 ? 1 : 0);
				break;
			}
			else
			{
				h -= _.x;
				if (h <= 0) break;
			}
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 27824
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)

map<string, int> mm;

int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL
	int n;
	string str;
	cin >> n;
	bool flag = true;
	string pre;
	for (int i = 1; i <= n; ++i) {
		cin >> str;
		mm[str]++;
		if (mm[str] >= 2) {
			flag = false;
		}

		if (i == 1) {
			pre = str;
			continue;
		}else {
			if (pre[pre.size() - 1] != str[0]) {
				flag = false;
			}
			pre = str;
		}
	}
	if (!flag) {
		cout << "No\n";
	}else {
		cout << "Yes\n";
	}

}

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

using namespace std;

int n, a[100005];

int main(){
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	int res = 0;
	
	for(int i = 0; i < n; i++){
		int v = sqrt(a[i]);
		
		bool ok = 0;
		
		for(int j = 1; j <= v; j++){
			int v = a[i] - j;
			if(v % (2 * j + 1) == 0){
				ok = 1;
				break;
			}
		}
		
		
		if(!ok)
		res++;
	}
	
	printf("%d\n", res);
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define int long long
//#define int __int128
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")

#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 3005, MOD = 998244353;

int n, S;
int a[N];
int dp[N], D[N];

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> S;
    dp[0] = 1;
    while (n--){
        int x;
        cin >> x;
        for (int i = 0; i <= S; i++){
            D[i] += dp[i]*2;
            if (i + x <= S)
                D[i+x] += dp[i];
        }
        for (int i = 0; i <= S; i++){
            dp[i] = D[i] % MOD;
            D[i] = 0;
        }
    }
    cout << dp[S] << endl;
}


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

int main() {
    string s; cin >> s;
    string k = "keyence";
    int t = 0; int u = 0;
    for (int i = 0; i < 7; i++) {
        if (s[i] == k[i]) {
            t++;
        } else break;
    }
    for (int i = 0; i < 7; i++) {
        if (s[s.size()-1-i] == k[7-i-1]) {
            u++;
        } else break;
    }
    if (t+u >= 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
#define pi 2*acos(0.0)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{
	int h, w;
	cin >> h >> w;
	vector<string> str(h, "q");
	REP(i, h){
		cin >> str[i];
	}
	REP(i, h){
		cout << str[i] << endl;
		cout << str[i] << endl;
	}
}

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

int main(int argc, char *argv[])
{
    int a, b;
    std::cin >> a >> b;

    double f = a/(double)b;
    int r = a%b;

    std::cout << std::fixed;
    std::cout << std::setprecision(9) << (int)f << " " << r << " "<< f << std::endl;
    return 0;
}

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int ans[1000010]={-1};
int l[1000100] = {-1};

void solve(int n) 
{
    ans[0] = 0;
    REP(i,n)
    {
        ans[i+1] = ans[i] + l[i];  
    }
}

int main(int argc, char const *argv[]) {
    int n,x;
    cin >> n >> x; 
    REP(i,n)
        cin >> l[i];
    
    int tot = 0;
    solve(n);
    REP(i,n+1) 
    {
        if (ans[i] <= x)
            tot++;
    }

    cout << tot << endl;
    return 0;
}


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

class Procon
{
  public Procon() {}
  static void Main(string[] agrs)
  {
    new Procon().Do();
  }

  Scanner cin;

  public void Do()
  {
    cin = new Scanner();
    string str = cin.nextString();
    for (int i = 0; i<str.Length/2; i++) {
      if (str[i] != str[str.Length-i-1]) {
        Console.WriteLine("No");
        return;
      }
    }
    Console.WriteLine("Yes");
    return;
  }
}


class Scanner
{
  string[] s;
  int i;
  int max_i;

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

  public string nextString()
  {
    if (i >= s.Length) 
    {
      s = Console.ReadLine().Split(' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) 
      {
        return "";
      }
      return s[i++];
    } else 
    {
      return s[i++];
    }
  }

  public int nextInt()
  {
    return int.Parse(nextString());
  }


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

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

  public string[] arrayString()
  {
    return Console.ReadLine().Split(' ');
  }

  public int[] arrayInt()
  {
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = int.Parse(str[i]);
    }
    return array;
  }

  public long[] arrayLong()
  {
    string[] str = Console.ReadLine().Split(' ');
    long[] array = new long[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = long.Parse(str[i]);
    }
    return array;
  }

  public double[] arrayDouble()
  {
    string[] str = Console.ReadLine().Split(' ');
    double[] array = new double[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = double.Parse(str[i]);
    }
    return array;
  }
}


Measured memory_bytes: 11092
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
Ac = Counter(A)
q = int(input())
B = [0] * q
C = [0] * q
for i in range(q):
    B[i], C[i] = map(int, input().split())

s = sum(A)
for i in range(q):
    if B[i] in Ac:
        num = Ac[B[i]]
        #print("num", num)
        if C[i] in Ac:
            Ac[C[i]] += Ac[B[i]]
        else:
            Ac[C[i]] = Ac[B[i]]
        del Ac[B[i]]
        s += (-B[i] + C[i]) * num
    print(s)



Measured memory_bytes: 95896
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String s1[] = s.split("");
    String ans[] = {"Bad", "Good"};
    int a = 1;
    for (int i = 1; i < 4; i++){
      if (s1[i].equals(s1[i-1])) a *= 0;
    }
    System.out.println(ans[a]);
  }
}


Measured memory_bytes: 35688
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    n = A[-1]
    i = bisect.bisect_left(A, n / 2)
    if n / 2 - A[i-1] <= A[i] - n / 2:
        r = A[i-1]
    else:
        r = A[i]
    print(n, r)

main()


Measured memory_bytes: 14428
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  vec b(a);
  For(i,0,a)
    ci(b[i]);
  vec c(a);
  For(i,0,a)
    c[b[i]-1]=i+1;
  For(i,0,a)
    co(c[i]);
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int D = sc.nextInt();
		// スペース区切りの整数の入力
		int N = sc.nextInt();

		sc.close();
		if (N == 100)
			N = 101;

		if (D == 0)
			System.out.println(N);
		else if (D == 1)
			System.out.println(N * 100);
		else if (D == 2)
			System.out.println(N * 10000);

	}
}

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

using namespace std;
//typedef long long ll;
typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {

    map<char,string> m;
    cin >> m['a'];
    cin >> m['b'];
    cin >> m['c'];

    char n = 'a';
    while(true) {
        if(m[n].empty()) {
            char ans = n - 'a' + 'A';
            cout << ans << endl;
            return 0;
        }
        char k = m[n].front();
        m[n] = m[n].substr(1);
        n = k;
    }


}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
#include <unordered_map>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=2e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const int MOD=1e9+7;
//const ull MOD=1e7+7;
//const ll MOD=998244353;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}

int n;
int a[MAX];
ll an;
map<int,int>re;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(a[1])return 0*printf("-1\n");
    for(int i=2;i<=n;i++)
        if(a[i]>a[i-1]+1)return 0*printf("-1\n");
    int cnt=-1;
    for(int i=2;i<=n;i++)
    {
        if(re[a[i]+cnt])
        {
            an+=i-re[a[i]+cnt];

        }
        else an+=a[i];
        re[a[i]+cnt]=i;
        --cnt;
    }
    printf("%lld\n",an);


}
/*

*/


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

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

	if(a+b+c <= 21) cout << "win" << endl;
	else cout << "bust" << endl;

	return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, K;
    cin >> N >> K;
    if(N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 7 * 17 * (1 << 23) + 1;
const ll inf = 1e18 + 69;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	string t = s;
	set<char> x;
	if(s.size()==26) {
		if(!next_permutation(all(s))) return cout << -1, 0;
		int z = 0;
		while(s[z] == t[z]) z++;
		cout << s.substr(0, z+1) << "\n";
	} else {
		for(auto i : s) x.insert(i);
		char c = 'a';
		while(x.count(c)) c++;
		cout << s << c<<"\n";
	}
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vvll as(n, vll(n));
  rep(i, n) rep(j, n) cin >> as[i][j];

  vvll dp(1 << n, vll(n + 1, 0));
  dp[0][0] = 1;

  vvll lst(n+1);
  rep(s, 1 << n) lst[__builtin_popcount(s)].push_back(s);

  repLRE(i, 1, n) {
    for (ll s : lst[i]) {
      rep(j, n) {
        if (as[i - 1][j] == 1) {
          dp[s][i] += dp[s & ~(1LL << j)][i - 1];
          dp[s][i] %= mod;
        }
      } // j
    } // s
  } // i

  cout << dp[(1 << n) - 1][n] << endl;

  return 0;
}


Measured memory_bytes: 468260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N;
  cin>>N;
  cout<<N*N*N<<endl;
}

Measured memory_bytes: 256
import math
n = int(input())
params = [[int(param) for param in input().split()] for _ in range(n-1)]


while params:

    c, s, f = params.pop(0)
    total = s + c

    for index, param in enumerate(params):
        c, s, f = param

        if (s > total):
            total = s + c
        elif((total-s) % f == 0):
            total += c
        else:
            total = (total + f) - (total % f) + c
            # if ((total-s) % f == 0):
            #     total += c
            # else:
            #     total = math.ceil((total-s)/f)*f + c

    print(total)

print(0)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <cmath>
using namespace std;
//typedef long long ll;
using ll = long long;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<(m);i++)
#define rep1(i, m) for(ll i=1;i<=(m);i++)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
   int N, K;
   cin >> N >> K;
   vector<ll> x(N), y(N);
   vector<ll> X, Y;
   rep(i, N) {
      cin >> x[i] >> y[i];
      X.push_back(x[i]);
      Y.push_back(y[i]);
   }
   sort(begin(X), end(X));
   sort(begin(Y), end(Y));
   ll ans = 1LL * (X[N-1] - X[0]) * (Y[N-1] - Y[0]);

   for (int xs = 0;xs<N;xs++) {
      for(ll xl = xs+1; xl<N;++xl) {
         for (int ys=0;ys<N;ys++) {
            for (ll yl=ys+1; yl<N;++yl) {
               int num = 0;
               ll lx = X[xs], rx = X[xl];
               ll by = Y[ys], uy = Y[yl];
               rep(i, N) {
                  if (lx <= x[i] and x[i] <= rx and
                          by <= y[i] and y[i] <= uy) {
                             num++;
                          }
               }
               if (num >= K) {

                   ans = min(ans, 1LL * abs(rx - lx) * abs(uy-by));

               }
            }
         } 
      }
   }
   cout << ans << endl;
}
/*
 using ll = long long;
int main(void){ int n,k; cin >> n >> k;
vector<int> x(n),y(n); vector<int> xary,yary;
for(int i = 0;i< n; ++i){ cin >> x[i] >> y[i];

xary.push_back(x[i]); yary.push_back(y[i]); }
sort(begin(xary),end(xary)); sort(begin(yary),end(yary));
ll ans = 1LL * (xary[n-1] - xary[0]) * (yary[n-1] - yary[0]);
for(int xi = 0; xi < n; ++xi){ for(int xj = xi + 1; xj < n;++xj){ for(int yi = 0; yi < n; ++yi){for(int yj = yi + 1; yj < n;++yj){
int num = 0; ll lx = xary[xi],rx = xary[xj]; ll by = yary[yi],uy = yary[yj];
for(int i = 0;i< n;++i){ if(lx <= x[i] and x[i] <= rx and by <= y[i] and y[i] <= uy){num++;} }
if(num >= k) ans = min(ans,1LL * (rx - lx) * (uy - by)); } }}}
 cout << ans << endl;
return 0; }
*/

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by zzt on 17-3-26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        System.out.println((a+b)%24);
    }
}

Measured memory_bytes: 22356
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H,W,N;
int32_t l1, r1, u1, d1;
int32_t wmax,wmin, hmax, hmin;
std::string S, T;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int32_t h, w;
	in >> H>>W>>N;
	in >> h >> w; --h; --w;
	in >> S >> T;

	wmin = 0;
	wmax = W-1;
	hmin = 0;
	hmax = H - 1;
	for (int i = N - 1; i >= 0; i--)
	{
		if (S[i] == 'U') { ++hmin; }
		if (S[i] == 'D') { --hmax; }
		if (S[i] == 'L') { ++wmin; }
		if (S[i] == 'R') { --wmax; }

		if(wmax<wmin || hmax<hmin) {
			out << "NO" << endl;
			return 0;
		}

		if (i > 0) {
			if (T[i-1] == 'U') {hmax = std::min(hmax +1,H-1);}
			if (T[i-1] == 'D') {hmin = std::max(hmin -1, 0); }
			if (T[i-1] == 'L') { wmax = std::min(wmax+1,W-1); }
			if (T[i-1] == 'R') { wmin = std::max(wmin-1, 0); }
		}
	}
	if (wmin <= w && w <= wmax && hmin <= h && h <= hmax) {

		out << "YES" << endl;
		return 0;
	}
	out << "NO" << endl;


	return 0;
}
#endif


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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 2000;
int n,k;
vi g[MAX_N];
int dist[MAX_N][MAX_N] = {};
int cnt[MAX_N] = {};
bool out[MAX_N] = {};

void dfs(int u, int p, int r, int d) {
  dist[r][u] = d;
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u, r, d+1);
  }
}

int main() {
  cin >> n >> k;
  int a,b;
  for (int i = 0; i < n-1; i++) {
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  for (int u = 0; u < n; u++)
    dfs(u, -1, u, 0);

  set<pii, greater<pii> > s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] > k) cnt[i]++;
    }
    if (cnt[i] > 0) s.insert(mp(cnt[i], i));
    else out[i] = true;
    //printf("cnt[%d]=%d\n",i,cnt[i]);
  }

  int c = 0;
  while (!s.empty()) {
    auto it = s.begin();
    int i = it->snd; s.erase(it);
    //printf("x=%d c=%d\n",it->fst,it->snd);
    out[i] = true;
    c++;
    for (int j = 0; j < n; j++) {
      if (!out[j] && dist[i][j] > k) {
        auto it2 = s.find(mp(cnt[j], j)); s.erase(it2);
        if (cnt[j] > 1)
          s.insert(mp(--cnt[j], j));
        else
          out[j] = true;
      }
    }
  }

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 16256
sx,sy,tx,ty=map(int,input().split())
print('U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx)+'L' \
      +'U'*(ty+1-sy)+'R'*(tx+1-sx)+'D'+'R'+'D'*(ty+1-sy) \
      +'L'*(tx+1-sx)+'U')

Measured memory_bytes: 9116
#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int ans=0,x;
    For(i,1,5)
    {
        cin>>x;
        if(x==0)ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <functional>
#include <utility>
using namespace std;

signed main() {
	int n;
	long long x;
	int a[2003];
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int dp[2003][2003];//色iの巣ライムについて、j回の操作が許されるときのコスト
	for (int i = 0; i < n; i++) {
		dp[i][0] = a[i];
		for (int j = 1; j < n; j++) {
			if (i - j < 0)dp[i][j] = min(dp[i][j - 1], a[n+i - j]);
			else { dp[i][j] = min(dp[i][j - 1], a[i - j]); }
		}
	}
	long long ans = 9999999999999999;
	for (int i = 0; i < n; i++) {
		long long tmp = 0;
		for (int j = 0; j < n; j++) {
			tmp += dp[j][i];
		}
		if (tmp + x*i < ans)ans = tmp + x*i;
	}
	cout << ans;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll a[7];
    for(int i=0;i<7;i++){
    	cin>>a[i];
    }
    ll ans=0;
    ll b=a[0],c=a[3],d=a[4];
    if(b&&c&&d){
    	ans+=3;
    	a[0]--;
    	a[3]--;
    	a[4]--;
    }
    ans+=a[3]-(a[3]&1);
    ans+=a[4]-(a[4]&1);
    ans+=a[0]-(a[0]&1);
    ans=max(ans,2LL*(ll(b/2)+ll(c/2)+ll(d/2)));
    cout << ans+a[1]<<endl;
    return 0;
}


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

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	int N, K;
	cin >> N >> K;
	string s;
	cin >> s;
	vector<int> data;
	char k = '0';
	int count = 0;
	for (int i = 0; i <= N; ++i) {
		if (i == N || k != s[i]) {
			data.push_back(count);
			count = 0;
			if (i == N)break;
			k = s[i];
		}
		++count;
	}

	int maxCount = 0;
	for (int i = 0; i < data.size(); i+=2) {
		int count = 0;
		if (i != 0)count = data[i - 1];
		for (int j = 0; j < K; ++j) {
			if (i + 2 * j + 1 < data.size()) count += data[i + 2 * j] + data[i + 2 * j + 1];
			else if (i + 2 * j < data.size()) count += data[i + 2 * j];
			else break;
		}
		maxCount = max(maxCount, count);
	}
	cout << maxCount << endl;
	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
	int n,a,b,t,tt,c,i;
	cin>>n>>t;
	int mn=hell;
	for(i=0;i<n;i++){
		cin>>c>>tt;
		if(tt<=t)mn=min(mn,c);
	}
	if(mn!=hell)
	cout<<mn;else cout<<"TLE";

	
}

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

signed main(){
	string S; cin>>S;
	int N=S.size();
	bool ans=true;
	if(S[0]!='A')ans=false;
	int cc=0;
	for(int i=2;i<N-1;i++){
		if(S[i]=='C')cc++;
	}
	if(cc!=1)ans=false;
	for(int i=0;i<N;i++){
		if(S[i]=='A' or S[i]=='C')continue;
		else if(S[i]<97 or S[i]>122)ans=false;
	}
	cout<<(ans? "AC" : "WA")<<endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

bool f1(vector<int> a) {
  rep(i, a.size()) {
    if (a[i] > 0) return false;
  }
  return true;
}

bool f2(vector<int> a) {
  int n = a.size();

  if (n % 3) return false;

  REP(i, 0, n / 3) {
    if (a[i] != 0) return false;
  }

  REP(i, n / 3, n) {
    if (a[n / 3] != a[i]) return false;
  }

  return true;
}

bool f3(vector<int> a) {
  int n = a.size();

  if (n % 3) return false;

  REP(i, 0, n / 3) {
    if (a[0] != a[i]) return false;
  }

  REP(i, n / 3, n / 3 * 2) {
    if (a[n / 3] != a[i]) return false;
  }

  REP(i, n / 3 * 2, n) {
    if (a[n / 3 * 2] != a[i]) return false;
  }

  return (a[0] ^ a[n / 3] ^ a[n / 3 * 2]) == 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  cout << ((f1(a) || f2(a) || f3(a)) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdbool.h>

int SumOfIntegers(int n, int s, int a, int b)
{
  if(n == 0 && s == 0)
    return 1;
  if(a > b)
    return 0;

    return SumOfIntegers(n,s,a+1,b) + SumOfIntegers(n-1,s-a,a+1,b);
  
  
}

int main()
{
  int n, s;
  bool flag = true;
  int count=0;

  while(flag){
    scanf("%d %d", &n, &s);
    if(n == 0 && s == 0)
      flag = false;
    else
      printf("%d\n",SumOfIntegers(n,s,0,9));
    count++;
    if(count > 50)
      flag = false;
  }
  return 0; 
}

Measured memory_bytes: 600
int main(){
    int h,w,i,l,f;
    while(1==1){
        scanf("%d%d", &h, &w);
        if(h==0 && w==0){
            break;
        }else{
            for(i=0; i<w; i++){
                printf("#");
            }
            printf("\n");
            for(f=0; f<h-2; f++){
                for(l=0; l<w; l++){
                    if(l==0 || l==w-1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
                printf("\n");
            }
            for(i=0; i<w; i++){
                printf("#");
            }
            printf("\n\n");
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int inf=0x3f3f3f3f;
#define N 2020
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,a[N],dp[N],ans,dis[N],siz[N],son[N];
char s[N];
vector<int> G[N]; 
void dfs(int u,int fa){
	siz[u]=a[u];
	dis[u]=0;
	int maxson=-1;
	son[u]=0;
	for(auto v:G[u]){
		if(v==fa)continue;
		dfs(v,u);
		dis[v]+=siz[v];
		dis[u]+=dis[v];
		siz[u]+=siz[v];
		if(dis[v]>maxson){
			maxson=dis[v],son[u]=v;
		}
	}
	if(!son[u])return (void)(dp[u]=0);
	if(dis[u]>=(maxson<<1))dp[u]=dis[u]>>1;
	else dp[u]=dis[u]-maxson+min(dp[son[u]],((maxson<<1)-dis[u])/2);
}
int main(){
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;++i){
		a[i]=s[i]-'0';
	}
	for(int i=1;i<n;++i){
		int u=read(),v=read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ans=inf;
	for(int i=1;i<=n;++i){
		dfs(i,0);
		if(dis[i]&1)continue;
		if(dp[i]*2>=dis[i]){
			ans=min(ans,dis[i]>>1);
		}
	}
	printf("%d\n",ans==inf?-1:ans);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=1e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
char s[N],t[N];
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	cin>>s>>t;
	int ans=INT_MAX;
	int n=strlen(s),m=strlen(t);
	for(int i=0;i<=n-m;i++){
		int cnt=0;
		for(int j=0;j<m;j++){
			if(s[i+j]!=t[j]) ++cnt;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	register int n,m,i,j,x,y,maxx=-191,maxy=1231,tmp;
	scanf("%d%d%d%d",&n,&m,&x,&y);
	maxx=x,maxy=y;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&tmp);
		maxx=max(tmp,maxx);
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d",&tmp);
		maxy=min(maxy,tmp);
	}
	if(maxx<maxy&&x<y)
	{
		printf("No War");
		return 0;
	}
	printf("War");
	return 0;
}

Measured memory_bytes: 128