akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
//#define long long long
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++){
        for(int j = i; j < S.size(); j++){
            if(S.substr(0, i) + S.substr(j) == "keyence"){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


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

using namespace std;

string IntToStr(const long long _a) {
	string result;
	int a = (int)_a;
	if (a == 0) result = "a";
	if (a == 1) result = "b";
	if (a == 2) result = "c";
	if (a == 3) result = "d";
	if (a == 4) result = "e";
	if (a == 5) result = "f";
	if (a == 6) result = "g";
	if (a == 7) result = "h";
	if (a == 8) result = "i";
	if (a == 9) result = "j";
	if (a == 10) result = "k";
	if (a == 11) result = "l";
	if (a == 12) result = "m";
	if (a == 13) result = "n";
	if (a == 14) result = "o";
	if (a == 15) result = "p";
	if (a == 16) result = "q";
	if (a == 17) result = "r";
	if (a == 18) result = "s";
	if (a == 19) result = "t";
	if (a == 20) result = "u";
	if (a == 21) result = "v";
	if (a == 22) result = "w";
	if (a == 23) result = "x";
	if (a == 24) result = "y";
	if (a == 25) result = "z";

	return result;
}

int main() {
	long long target;
	cin >> target;

	vector<string> outputs;
	while (target > 0) {
		target--;
		long long amari = target % (long long)26;
		outputs.push_back(IntToStr(amari));
		target = target / (long long)26;
	}

	for (int i = 0; i < outputs.size(); i++) {
		cout << outputs[outputs.size() - i - 1];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<cstring>
#include<algorithm>

#define ll long long
#define MOD 1000000007

using namespace std;

ll power(ll a, ll b)
{
    if(b == 0)
        return 1;
    ll ret = power(a, b / 2);
    ret = ((ret % MOD) * (ret % MOD)) % MOD;
    if(b & 1)
        ret = (ret * (a % MOD)) % MOD;
    return ret;
}

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

    int n, k;
    ll sum = 0;
    cin >> n >> k;
    ll a[n + 1];
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    ll chooseK[n + 1];
    memset(chooseK, 0, sizeof(chooseK));
    chooseK[k - 1] = 1;
    for(ll i = k ; i <= n ; i++){
        ll a = chooseK[i - 1] * i;
        ll b = (i - k + 1);
        chooseK[i] = a % MOD * power(b, MOD - 2) % MOD;
    }
    sort(a + 1, a + n + 1);
    for(int i = 1 ; i <= n ; i++){
//        cout << chooseK[i - 1] - chooseK[n - i] << endl;
        sum += (((a[i] + MOD) % MOD) * ((chooseK[i - 1] - chooseK[n - i] + MOD) % MOD)) % MOD;
        sum %= MOD;
//        cout << sum <<endl;
    }
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 1792
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int A,B,C,c = 0;
    cin >> A >> B >> C;

    if(A == B){
        c++;
    }

    if(B == C){
        c++;
    }

    if(C == A){
        c++;
    }

    if(c == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

ll N;
ll A[200010];
ll B[200010];
ll C[200010];
ll cnta[200010];
ll cntb[200010];



int main(){
   cin >> N;
   rep(i,N){
      cin >> A[i];
      cnta[A[i]]++;
   }
   rep(i,N){
      cin >> B[i];
      cntb[B[i]]++;
   }
   rep(i,N+1){
      if(cnta[i] + cntb[i] > N){
         cout << "No" << endl;
         return 0;
      }
   }
   reverse(B,B+N);
   ll Al = 0,Ar = 0,Bl = 0,Br = 0;
   ll p = 0;
   rep(i,N){
      if(A[i] == B[i]){
         p = A[i];
         break;
      }
   }
   bool flag = 0;
   rep(i,N){
      if(A[i] == p) flag = 1;
      if(flag && A[i] != p) break;
      Ar++;
      if(!flag){
         Al++;
      }
   }
   flag = 0;
   rep(i,N){
      if(B[i] == p) flag = 1;
      if(flag && B[i] != p) break;
      Br++;
      if(!flag){
         Bl++;
      }
   }
   ll now = 0;
   FOR(i,max(Al,Bl),min(Ar,Br)){
      if(now < min(Al,Bl)){
         swap(B[i],B[now]); 
         now++;
      }else if(now == min(Al,Bl)){
         now = max(Ar,Br);
         i--;
      }else{
         if(now >= N){
            cout << "No" << endl;
            return 0;
         }
         swap(B[i],B[now]); 
         now++;
      }
   }
   cout << "Yes" << endl;
   rep(i,N) cout << B[i] << ' ';
   cout << endl;
}

Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s == "SUN")
    {
        cout << 7 << endl;
    }
    else if (s == "MON")
    {
        cout << 6 << endl;
    }
    else if (s == "TUE")
    {
        cout << 5 << endl;
    }
    else if (s == "WED")
    {
        cout << 4 << endl;
    }
    else if (s == "THU")
    {
        cout << 3 << endl;
    }
    else if (s == "FRI")
    {
        cout << 2 << endl;
    }
    else if (s == "SAT")
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
 int N,L;
 cin>>N>>L;
 int sum=0;
 for(int i=L;i<=L+N-1;i++){
   sum+=i;
 }
 int ans=99999;int k=0;
 for(int i=L;i<=L+N-1;i++){
   if(abs(sum-(sum-i))<=ans){ans=min(abs(sum-(sum-i)),ans);k=sum-i;}
 }
 cout<<k<<endl;
   return 0;
}

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

const double pi = 3.141592653589793;

int main() {
  double a, b , h, m;
  cin >> a >> b >> h >> m;
  double thetaA = (h*60.0+m)/2.0;  // a*60.0*360.0/720.0;
  double thetaB = m*6.0;  // b*360/60;
  double theta;
  if (thetaA > thetaB) theta = thetaA - thetaB;
  else theta = thetaB - thetaA;
  if (theta > 180) theta = 360.0 - theta;
  double ans;
  theta = theta * pi/180.0;
  ans = sqrt(a*a+b*b-2.0*a*b*cos(theta));
  printf("%.10lf", ans);
  return 0;
}

Measured memory_bytes: 4188
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int m;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			m = sc.nextInt();
			if( (n|m) == 0 ) break;
			
			int[][] time = new int[m][m];
			int[][] cost = new int[m][m];
			for(int[] a: time) fill(a, INF);
			for(int[] a: cost) fill(a, INF);
			
			for(int i=0;i<n;i++) {
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				int c = sc.nextInt();
				int t = sc.nextInt();
				time[a][b] = time[b][a] = min(t, time[a][b]);
				cost[a][b] = cost[b][a] = min(c, cost[a][b]);
			}
			
			int k = sc.nextInt();
			for (int i = 0; i < k; i++) {
				int p = sc.nextInt()-1;
				int q = sc.nextInt()-1;
				int r = sc.nextInt();
				System.out.println(dijkstra(p, q, (r==0? cost: time)));
			}
		}
	}
	
	int dijkstra(int s, int g, int[][] map) {
		int[] d = new int[m];
		boolean[] visited = new boolean[m];
		
		fill(d, INF);
		d[s] = 0;
		
		for(;;) {
			int v = -1;
			for(int u=0;u<m;u++) if(!visited[u]){
				if(v == -1 || d[v] > d[u] ) v = u;
			}
			
			if( v == -1) break;
			if( v == g ) break;
			visited[v] = true;
			
			for (int u = 0; u < m; u++) {
				d[u] = min(d[u], d[v] + map[v][u]);
				
			}
		}
		
		return d[g];
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 14000
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()

def solve():
    res = [0 for _ in range(10)]
    index = 0
    for i in range(len(S)):
        if S[i] in ['A','T','G','C']:
            res[index] += 1
        else:
            index += 1
    print(max(res))

if __name__ == "__main__":
    solve()

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for (int i = 0; i<N; i++) {
            H[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(H);
        int ans = 1000000000;
        for (int i = 0; i<=N-K; i++) {
            if (ans>H[i+K-1]-H[i]) ans = H[i+K-1]-H[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50380
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	int n, g = 0;
	cin >> n;
	REP(i, n) {
		LL a, k;
		scanf("%lld%lld", &a, &k);
		if (a < k*k) {
			auto x = a / k;
			while (1) {
				auto s = x*k;
				auto o = a - s;
				if ((o % (x + 1)) == 0) {
					g ^= x;
					break;
				}
				a -= o / (x + 1) + 1;
				x--;
			}
		}else {
			while (a%k) {
				a -= a / k + 1;
			}
			g ^= a / k;
		}
	}
	if (g)cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		while (true) {

			// ????????¢????????¨?¨????????????\???
			int height = in.nextInt();
			int width = in.nextInt();

			// ??\?????????(0,0)??????????????????
			if (height == 0 && width == 0) {
				break;
			} else {

				// ?????????????????°??????????????????
				for (int count_h = 0; count_h < height; count_h++) {

					// ?¨???????????????°??????#?????¨???
					for (int count_w = 0; count_w < width; count_w++) {

						// ??¶??°????????¨???
						if (count_h % 2 == 0) {

							// ??¶??°????????¨???
							if (count_w % 2 == 0) {
								System.out.print("#");
							// ?\???°????????¨???
							}else {
								System.out.print(".");
							}

						// ?\???°????????¨???
						} else {
							// ?\???°????????¨???
							if (count_w % 2 == 0) {
								System.out.print(".");
							// ?\???°????????¨???
							}else {
								System.out.print("#");
							}
						}
					}
					// ????????¨??????????????????
					System.out.println();
				}
				// ?????????????????????????????????????????\
				System.out.println();
			}
		}

	}
}

Measured memory_bytes: 35000
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string S,T;
      cin >> S >> T ;
      int ans=T.size();
      int dummy=0;
      
      for(int i=0;i<S.size()-T.size()+1;i++){
        dummy=T.size();
        for(int j=0;j<T.size();j++){
          if(T.at(j)==S.at(j+i)){
            dummy--;
          }
        }
        if(dummy<ans){
          ans=dummy;
        }
      }
      
      cout << ans << endl;
      
    }

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

int main() {
 int n;
  cin>>n;
  vector<int> a(n),b(n,0);
  for(int &x: a) cin>>x;
  int x=a[0],count=1;
  b[0]=1;
  while(1){
    if(x==2) {cout<<count<<endl; return 0;}
    x=a[x-1];
    count++;
    if(b[x-1]==1) {cout<<-1<<endl; return 0;}
    b[x-1]=1;
  }
}
      

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll h, w, s;
  s = 0;
  in2(h, w);
  vector<vector<char>> a(h + 2, vector<char> (w + 2, '.'));
  rep(i, h){
    rep(j, w)
      in(a[i + 1][j + 1]);
  }
  rep(i, h + 2){
    rep(j, w + 2){
      if(a[i][j] == '#' && a[i - 1][j] == '.' && a[i + 1][j] == '.' && a[i][j - 1] == '.' && a[i][j + 1] == '.')
        s++;
    }
  }
  if(s)
    out("No");
  else
    out("Yes");
  memi;
}

Measured memory_bytes: 256
from operator import itemgetter
N=int(input())
hako=[]
for i in range(N):
    A,B=input().split()
    hako.append([A,int(B)*-1])
kari=hako.copy()
#print(kari)
hako.sort()
#print(hako)
for i in range(N):
    print(kari.index(hako[i])+1)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long

#define C (100000)

using namespace std;


int w,h;

//dp[x][y][k]
int dp[128][128][4] = {0};
int ans;

int ResetDp(){
	for(int i = 0;i < 128;i++){
		for(int j = 0;j < 128;j++){
			for(int k = 0;k < 4;k++){
				dp[i][j][k] = 0;
			}
		}
	}

	return 0;
}

int main (void){
	while(true){
		scanf("%d%d",&w,&h);
		if((w == 0)&&(h == 0))break;
		ResetDp();
		ans = 0;
		dp[1][1][0] = 1;
		dp[1][1][2] = 1;
		for(int i = 1;i <= w;i++){
			for(int j = 1;j <= h;j++){
				for(int k = 0;k < 4;k++){
					dp[i][j][k] %= C;
				}


				dp[i + 1][j][1] += dp[i][j][0];
				dp[i + 1][j][1] += dp[i][j][1];
				dp[i + 1][j][0] += dp[i][j][3];

				dp[i][j + 1][3] += dp[i][j][2];
				dp[i][j + 1][3] += dp[i][j][3];
				dp[i][j + 1][2] += dp[i][j][1];
			}
		}

		for(int i = 0;i < 4;i++){
			ans += dp[w][h][i];
			ans %= C;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1444
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    try {
      val a = sc.nextInt
      val b = sc.nextInt
      val c = sc.nextInt

      def sub(x:Int):Int = {
        if(c % x == 0) 1 else 0
      } 
      println(Range(a,b+1).map(sub).sum)
    } catch {
      case e: NoSuchElementException =>
        println("error: stdin is not found. Please take numbers.")
    }
  }
}

Measured memory_bytes: 45784
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        an:[i64;5],
    }
    let v = an.iter().filter(|&x| x % 10 !=0).map(|&x| x % 10).min().unwrap_or(1000);
    let mut sum = 0;
    for j in 0..5 {
        if an[j] % 10 != 0 {
            sum += an[j]+(10 - an[j] % 10);
        } else {
            sum += an[j];
        };
    }
    if (v != 1000){
        sum -= (10 - v % 10);
    }
    println!("{}",sum);
}


Measured memory_bytes: 4352
N = int(input())
Xs = list(map(int, input().split()))

P1 = sum(Xs)//N
P2 = P1+1

ans1 = sum([(X-P1)**2 for X in Xs])
ans2 = sum([(X-P2)**2 for X in Xs])
#print('ans1:', ans1, '/ ans2:', ans2)

print(min(ans1, ans2))


Measured memory_bytes: 3060
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int dp[45][501][501];
int main (){
      int N,Ma,Mb;
      cin>>N>>Ma>>Mb;
      rep0(k,N+1)rep0(i,401)rep0(j,401){
            dp[k][i][j]=inf;
      }
      dp[0][0][0]=0;
      rep0(k,N){
            int a,b,c;
            cin>>a>>b>>c;
            rep0(i,401)rep0(j,401){
                  if(i-a>=0&&j-b>=0)dp[k+1][i][j]=min(dp[k][i][j],dp[k][i-a][j-b]+c);
                  else dp[k+1][i][j]=dp[k][i][j];
            }
      }
      int cnt=1;
      int ans=inf;
      int hoge=cnt*Ma;
      int mochi=cnt*Mb;
      while(hoge<=400&&mochi<=400){
            ans=min(dp[N][hoge][mochi],ans);
            cnt++;
            hoge=cnt*Ma;
            mochi=cnt*Mb;
      }
      if(ans!=inf)cout<<ans<<endl;
      else cout<<-1<<endl;
      
      return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
 
 int n,k,ct=0;
 cin>>n>>k;
 Vec vec(n);

 for(int i=0;i<n;i++){
    int x;
    cin>>x;
    int way=min(x,abs(k-x));
    ct+=2*way;
}
cout<<ct<<endl;
}

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5, mod = 1e9 + 7;
int a[N], cnt[N], fact[N];

int rev( int x ){
    int pwr[40];
    pwr[0] = x;
    for ( int i = 1; i <= 30; i++ ){
        pwr[i] = ( pwr[i-1] * 1ll * pwr[i-1] ) % mod;
    }
    int v = mod - 2, res = 1;
    for ( int i = 30; i >= 0; i-- ){
        int bit = ( v >> i ) & 1;
        if ( bit ){
            res = ( res * 1ll * pwr[i] ) % mod;
        }
    }
    return res;
}

int getC( int n, int k ){
    if ( n < k ){
        return 0;
    }
    int res = ( fact[n] * 1ll * rev( fact[k] ) ) % mod;
    return ( res * 1ll * rev( fact[n-k] ) ) % mod;
}


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    int x = -1;
    for ( int i = 1; i <= n + 1; i++ ){
        scanf("%d",&a[i]);
        cnt[ a[i] ]++;
        if ( cnt[ a[i] ] == 2 ){
            x = a[i];
        }
    }
    int l = 0, r = 0;
    for ( int i = 1; i <= n + 1; i++ ){
        if ( a[i] == x ){
            if ( !l ){
                l = i;
            }
            else{
                r = i;
            }
        }
    }
    fact[0] = 1;
    for ( int i = 1; i < N; i++ ){
        fact[i] = ( fact[i-1] * 1ll * i ) % mod;
    }
    for ( int i = 1; i <= n + 1; i++ ){
        int res = getC( n + 1, i );
        res = ( res - getC( n - ( r - l ), i - 1 ) + mod ) % mod;
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(4100000)
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

flag = False
def dfs(now, prev, cnt):
    global flag
    if cnt == 2:
      if now == n-1:
        flag = True
    for next in g[now]:
        if next != prev and cnt < 2:
            dfs(next, now, cnt+1)
    return flag
            
ans = dfs(0,-1,0)
if ans:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

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

int n, a[5001], sum[5001];

// a[i] + a[i+1] + ... + a[j] テ」ツつ津ィツソツ氾」ツ?? (テァツエツッテァツゥツ催・ツ陳?
int f(int i, int j){
	return sum[i] - sum[j+1];
}

int main(){
	while( cin >> n, n ){
		for(int i = 0; i < n; i++) cin >> a[i];
		
		sum[0] = 0;
		for(int i = 0; i < n; i++) sum[0] += a[i];
		for(int i = 0; i < n; i++) sum[i+1] = sum[i] - a[i];
		
		int ans = a[0];
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				ans = max(ans, f(i, j));
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1196
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();

        long black=0;
        long white=0;
        long count=0;
        String str1 = "B";
        char c = str1.charAt(0);

        for(int i=str.length()-1; i>=0; i--){
            if(str.charAt(i) == c){
                count += white;
            }else{
                white++;
            }
        }

        System.out.println(count);

 
    }



}

Measured memory_bytes: 27960
#include <iostream>
#include <string>
#include <cstdio>


using namespace std;
typedef long long ll;

int main(){
  string S, T;
  cin >> S >> T;

  if (S == T) {
    cout << "Yes" << endl;
  } else {
    for (int i = 1; i < S.size(); i++) {
      bool flag = true;
      for (int j = 0; j < S.size(); j++) {
        if (S[j] != T[(j + i) % S.size()]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

lli h[100000] = {};

vector<int> ab[100000] = {};

int main(void) {

	lli n, m;
	cin >> n >> m;

	for (int i = 0; i < n; i++)
		cin >> h[i];

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;

		a--; b--;
		ab[a].push_back(b);
		ab[b].push_back(a);
	}

	int count = 0;

	for (int i = 0; i < n; i++) {

		if (ab[i].size() == 0)
			count++;
		else {
			bool f = true;
			for (int j = 0; j < ab[i].size(); j++) {
				if (h[i] <= h[ab[i][j]]) {
					f = false;
					break;
				}
			}
			if (f)
				count++;
		}

	}

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

Measured memory_bytes: 9092
import numpy as np

n, W = map(int, input().split())
dp = np.array([[0]*(W+1)]*(n+1))
for i in range(1, n+1):
    w, v = map(int, input().split())
    dp[i] = dp[i-1]
    dp[i][w:W+1] = np.maximum(dp[i-1][w:W+1], dp[i-1][:W+1-w]+v)
print(dp[n][W])

Measured memory_bytes: 94788
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {

	var A int;
    A = nextInt();
    var B int;
    B = nextInt();
	solve(A, B);

}

func solve(A int, B int){
	if A > 0 && A < 10  && B > 0 && B < 10{
		Println(A * B)
	}else{
		Println("-1")
	}
}


// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}


type IntHeap []int
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

/////数字と文字
// 基本クラス
type NS struct {
    Num int
    Str string
}

//////　数字と数字
// 基本クラス
type NN struct {
    Num1 int
    Num2 int
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}



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

int main(void){
    string s;
    cin>>s;
    int i,j,n,k=0,a=0;
    for(i=0;s[i]!='\0';++i){}
    n=i;
    for(i=0;i<n;i++){
        if(s[i]!=s[n-i-1])++k;
    }
    j=(n-1)/2-1;
    for(i=0;i<j;i++,j--){
        if(s[i]!=s[j])++k;
    }
    i=(n+3)/2-1;
    j=n-1;
    for(;i<j;i++,j--){
        if(s[i]!=s[j])++k;
    }
    if(k==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

typedef
tree<
	pair<int, int>,
	null_type,
	less<pair<int, int>>,
	rb_tree_tag,
	tree_order_statistics_node_update>
ordered_set;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a)
{
    return power(a,mod-2,mod);
}

int main()
{
    IOS;
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=power(2,n,mod);
    ans=(ans-1+mod)%mod;
    ll num,den,val;
    num=1,den=1;
    repb(i,n,n-a+1) num=(num*i)%mod;
    repf(i,1,a+1) den=(den*i)%mod;
    val=(num*invmod(den))%mod;
    ans=(ans-val+mod)%mod;
    num=1,den=1;
    repb(i,n,n-b+1) num=(num*i)%mod;
    repf(i,1,b+1) den=(den*i)%mod;
    val=(num*invmod(den))%mod;
    ans=(ans-val+mod)%mod;
    cout<<ans<<endl;
}  

Measured memory_bytes: 256
//
//  main.cpp
//  C - Vacation
//
//  Created by Nishant Dhankhar on 15/01/19.
//  Copyright © 2019 Nishant Dhankhar. All rights reserved.
//

#include <bits/stdc++.h> //REMEMBER TO REMOVE '/'
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair


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


Measured memory_bytes: 2560
from collections import defaultdict
s = input()
n = len(s)
p = 2019
dd = defaultdict(int)
dd[0] = 1
prev = 0
for i in reversed(range(n)):
    prev = (prev+int(s[i])*pow(10, n-i, p)) % p
    dd[prev] += 1
print(sum(v*(v-1)//2 for v in dd.values()))


Measured memory_bytes: 9628
def main():
    N = int(input())
    S = input()
    x = [chr(i) for i in range(65, 65+26)]
    ans = ''
    for si in S:
        ind = x.index(si)
        next_c = ind + N
        # print(next_c)
        if next_c >= 26:
            next_c -= 26
        ans += x[next_c]

    print(ans)



if __name__ == "__main__":
    main()


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {



  string s,t;
  cin >> s >> t;
  s = s + t[t.size()-1];
  if( s == t ) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI number(n, -1);
  REP(i, m)
  {
    int s, c;
    cin >> s >> c;
    s--;
    if (number[s] == -1) number[s] = c;
    else
    {
      if (number[s] != c)
      {
        cout << -1;
        return 0;
      }
    }
  }
  if (n == 1 && (number[0] == -1 || number[0] == 0))
  {
    cout << 0;
    return 0;
  }
  if (number[0] == 0) cout << -1;
  else
  {
    REP(i, n)
    {
      if (i > 0 && number[i] == -1) cout << 0;
      else if (i == 0 && number[i] == -1) cout << 1;
      else cout << number[i];
    }
  }

  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 F first
#define S second

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
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() {
  int n, m, k;
  cin >> n >> m >> k;

  mint res = 0;
  combination c(n-1);
  mint m1 = (m - 1);
  rep(i, k+1) {
    res += c(n-1, i) * m * m1.pow(n-1-i);
  }
  cout << res.x << endl;

  return 0;
}


Measured memory_bytes: 6428
#include <iostream>
using namespace std;
int main(void)
{
    // Your code here!
    int A, B, T;
    cin >> A >> B >> T;
    
    int ans = 0;
    for (int i = 1; i <= T; i++)
    {
        if (i % A == 0) ans += B;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
n = int(input())
q = [None]*n
for i in range(n):
    q[i] = tuple(map(int, input().split()))
q = sorted(q, key = lambda x: x[1])
q = deque(reversed(q))
job = q.popleft()
day = job[1] - job[0]
if n == 1:
    if day >= 0:
        print("Yes")
    else:
        print("No")
    sys.exit()

while q:
    job = q.popleft()
    if job[1] < day:
        day = job[1] - job[0]
    else:
        day -= job[0]
    if day < 0:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 33776
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair< ll, ll> pll;


ll n;
vector< ll > g[5005];
ll sz[5005];
ll dp[5005][5005][2];
const ll mod = 1e9 + 7;
ll f[5005];
void dfs(ll s, ll pr)
{
        sz[s]=1;
        ll cs = 1;
        dp[s][1][0] = 1LL;
        vector<ll> sm = {0, 0};
        for(auto &i : g[s]) {
                if(i == pr) continue;
                dfs(i, s);
                sz[s]+= sz[i];
                vector< ll > t;
                vector< ll > dp2[2];
                        dp2[0].resize(cs + sz[i] +  1, 0LL);
                        dp2[1].resize(cs + sz[i] +  1, 0LL);
                for(ll ii = cs; ii>=0;ii--) {

                        for(ll j=0;j<2;j++) {
                                for(ll x = sz[i]; x >= 0;x--) {
                                        dp2[j][ii+x] += (dp[s][ii][1]*dp[i][x][(1^j)])%mod;
                                        if(dp2[j][ii+x] >= mod) dp2[j][ii+x] -= mod;
                                        dp2[j][ii + x] += (dp[s][ii][0]*dp[i][x][(0^j)])%mod;
                                        if(dp2[j][ii+x] >= mod) dp2[j][ii+x] -= mod;
                                }

                        }

                }
                        for(ll j=0;j<2;j++) {
                                for(ll x=0;x<dp2[0].size();x++) {
                                        dp[s][x][j] = dp2[j][x];
                                }
                        }

                cs += sz[i];
        }
        for(ll i = 1;i <= sz[s]; i++) {
                for(ll j=0;j<2;j++) {
                        sm[j] = (sm[j] + (f[i] * dp[s][i][j]))%mod;
                }
        }
        dp[s][0][1] = sm[0];
        dp[s][0][0] = sm[1];

}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        f[0] = 1LL;
        for(ll i=1;i<=5002;i++) {
                if(i%2 == 1) continue;
                f[i] = ((i-1)*f[i-2])%mod;
        }
        cin >> n;
        for(ll i=1;i<n;i++) {
                ll a, b;
                cin >> a >> b;
                g[a].pb(b);
                g[b].pb(a);
        }
        dfs(1, -1);
        ll ans = (dp[1][0][1] - dp[1][0][0] + mod)%mod;
        cout << ans << endl;
        return 0;
}


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

int arr[26];
int main()
{
    string s;
    cin>>s;
    for(int i=0;s[i]!='\0';i++)
    {
        arr[s[i]-'a']++;
    }
    bool ans=true;
    for(int i=0;i<26;i++)
    {
        if(arr[i]%2)
        {
            ans=false;
            break;
        }
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int main(int argc, char* argv[])
{
	char s[20];
	scanf("%s", s);
	int l = strlen(s);
	int ans = 0;
	for (int i = 0; i < l; i++) {
		int j = l - i - 1;
		int x = 9 * i;
		if (s[j] == '0') continue;
		x += s[j] - '0';
		if (i != 0) x--;
		for (int k = j - 1; k >= 0; k--) {
			x += s[k] - '0';
		}
		ans = max(ans, x);
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n;
int ans[100000];
string s;

int main(){
    I(n);
    S(s);
    for(int i = 0; i < 4; i++){
        memset(ans,0,sizeof(ans));
        for(int j = 0; j < 2; j++){
            if(i&(1<<j)){
                ans[j] = true;
            }
        }
        for(int j = 2; j < n; j++){
            if(ans[j-1]){
                if(s[j-1] == 'o') ans[j] = ans[j-2];
                else ans[j] = ans[j-2]^1;
            } else{
                if(s[j-1] == 'o') ans[j] = ans[j-2]^1;
                else ans[j] = ans[j-2];
            }
        }
        if(ans[n-1]){
            if(s[n-1] == 'o' && ans[n-2] != ans[0]) continue;
            if(s[n-1] == 'x' && ans[n-2] == ans[0]) continue;
        } else{
            if(s[n-1] == 'o' && ans[n-2] == ans[0]) continue;
            if(s[n-1] == 'x' && ans[n-2] != ans[0]) continue;
        }
        if(ans[0]){
            if(s[0] == 'o' && ans[n-1] != ans[1]) continue;
            if(s[0] == 'x' && ans[n-1] == ans[1]) continue;
        } else{
            if(s[0] == 'o' && ans[n-1] == ans[1]) continue;
            if(s[0] == 'x' && ans[n-1] != ans[1]) continue;
        }

        rep(j,n){
            if(ans[j]) cout << "S";
            else cout << "W";
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 1024
// AOJ 3102 iff
// 2019.9.23 bal4u

#include <stdio.h>
#include <string.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#else
#define gc() getchar()
#define pc(x) putchar(x)
#endif

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

#define MAX_V 305
int  V;    // 頂点数
int  to[MAX_V][MAX_V], hi[MAX_V];
int  r_to[MAX_V][MAX_V], r_hi[MAX_V];
int  vs[MAX_V], vsz;
char used[MAX_V];
int  cmp[MAX_V];    // 属する強連結成分のトポロジカル順序

void add_edge(int _from, int _to) {
	to[_from][hi[_from]++] = _to;
	r_to[_to][r_hi[_to]++] = _from;
}

void dfs(int v) {
	int i;
	used[v] = 1;
	for (i = 0; i < hi[v]; i++) {
		if (!used[to[v][i]]) dfs(to[v][i]);
	}
	vs[vsz++] = v;
}

void rdfs(int v, int k) {
	int i;
	used[v] = 1;
	cmp[v] = k;
	for (i = 0; i < r_hi[v]; i++) {
		if (!used[r_to[v][i]]) rdfs(r_to[v][i], k);
	}
}

// 強連結成分への分解
int scc() {
	int v, i, k;
	memset(used, 0, V);
	vsz = 0;
	for (v = 0; v < V; v++) if (!used[v]) dfs(v);
	memset(used, 0, V);
	k = 0;
	for (i = vsz-1; i >= 0; i--) {
		if (!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;		// 得られた強連結成分の数
}


void Qsort(int *a, int l, int r) {
	int i, j, m, t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
		while (a[i] < m) i++;
		while (m < a[j]) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}


int grp[MAX_V][MAX_V], w[MAX_V];

int main()
{
	int i, j, f, t, M;

	V = in(), M = in();
	while (M--) {
		i = in()-1, j = in()-1;
		add_edge(i, j);
	}
	
	scc();
	for (i = 0; i < V; i++) {
		t = cmp[i];
		grp[t][w[t]++] = i;
	}
	for (i = 0; i < V; i++) if (w[i] > 1) {
		Qsort(grp[i], 0, w[i]-1);
	}
	
	for (i = 0; i < V; i++) {
		f = 0, t = cmp[i];
		for (j = 0; j < w[t]; j++) {
			if (f) pc(' ');
			else f = 1;
			out(grp[t][j]+1);
		}
		pc('\n');
	}
	return 0;
}



Measured memory_bytes: 2636
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int ans;
    for(int i = 0; i < s.size(); i++){
        if(s.at(s.size() - i - 1) == 'Z'){
            ans = s.size() - i;
            break;
        }
    }
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == 'A'){
            ans -= i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640