akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

#define ALL(a)  (a).begin(),(a).end()

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

long long int euclidean_gcd(unsigned long long int a, unsigned long long int b);
long long int mysqrt(unsigned long long int x);

int main() {
    ll a, b, g, h;
    ll ans = 0;

    cin >> a >> b;

    g = euclidean_gcd (a,b);
    h = g;

    for (int i = 2; i <= mysqrt(g); i++) {
        if (h % i == 0) ans++;
        while (h % i == 0) {
            h = h / i;
        }        
    }

    if (h != 1) ans++;
    ans++;

    cout << ans << endl;
    
}

long long int euclidean_gcd(unsigned long long int a, unsigned long long int b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned long long int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

long long int mysqrt(unsigned long long int x){
  long long int a = 0, c = 0, y = 0, i = 0, t = x;
  while(t >>= 1){
    ++i;
  }
  for(i += i & 1; i >= 0; i -= 2){
    c = (y << 1 | 1) <= x >> i;
    a = a << 1 | c;
    y = y << 1 | c;
    x -= c * y << i;
    /* if(c){
      x -= y << i;
    } */
    y += c;
  }
  return a;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int n,k,q,a[2005],b[2005],tmp[2005],lt,lc,vis[2005],c[2005],ans=1e9;
signed main(){
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	vis[n+1]=1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j) if(a[j]<b[i]) vis[j]=1;
		lt=lc=0;
		for(int j=1;j<=n+1;++j){
			if(vis[j]){
				if(lt>=k){
					sort(tmp+1,tmp+lt+1);
					for(int m=1;m<=lt-k+1;++m){
						c[++lc]=tmp[m];
					}
				}
				lt=0;
			}
			else tmp[++lt]=a[j];
		}
		if(lc>=q){
			sort(c+1,c+lc+1);
			ans=min(ans,c[q]-b[i]);
		}
	}
	cout<<ans;
}

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

namespace abc122
{
    class A
    {
        static void Main(string[] args)
        {
            char res = 'A';
            switch (Input.Char()) {
                case 'A':
                    res = 'T';
                    break;
                case 'T':
                    res = 'A';
                    break;
                case 'C':
                    res = 'G';
                    break;
                case 'G':
                    res = 'C';
                    break;
            }
            Console.WriteLine(res);

        }

        /** Input Class */
        internal static class Input
        {
            /** input int */
            public static int Int() => int.Parse(Console.ReadLine());

            /** input str */
            public static string Str() => Console.ReadLine();

            /** input array of int */
            public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            /** input array of string */
            public static string[] StrArray() => Input.Str().Split(' ');

            /** input array of char */
            public static char[] CharArray() => Input.Str().ToCharArray();

            public static char Char() => Input.CharArray().First();
        }
    }
}



Measured memory_bytes: 11220
// Try Educational DP Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	
	let s = get().as_bytes();
	let t = get().as_bytes();
	
	use std::cmp::max;
	let mut dp = vec![vec![(0,0); t.len()+1]; s.len()+1];
	for i in 0..s.len() {
		for j in 0..t.len() {
			if s[i]==t[j] {
				dp[i+1][j+1] = (dp[i][j].0 + 1, 4);
			} else {
				dp[i+1][j+1] =
				if dp[i+1][j].0 > dp[i][j+1].0 {
					if dp[i][j].0 > dp[i+1][j].0 {
						(dp[i][j].0, 3)
					} else {
						(dp[i+1][j].0, 1)
					}
				} else {
					if dp[i][j].0 > dp[i][j+1].0 {
						(dp[i][j].0, 3)
					} else {
						(dp[i][j+1].0, 2)
					}
				};
			}
		}
	}
	let mut u = vec![];
	let mut i = s.len()+1;
	let mut j = t.len()+1;
	while i > 0 && j > 0 {
		match dp[i-1][j-1].1 {
		1 => { j -= 1; },
		2 => { i -= 1; },
		3 => { i -= 1; j -= 1; },
		4 => {
			u.push(s[i-2]);
			i -= 1;
			j -= 1;
		},
		_ => { i = 0; },
		}
	}
	u.reverse();
	let ans = String::from_utf8(u).unwrap();
	println!("{}", ans);
}

Measured memory_bytes: 90364
#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 ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

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

#define MAX 2000010
int N,K,L;
vector<int> G1[MAX];
vector<int> G2[MAX];

struct UnionFind {
  vector<int> par;
  int find(int x) {
    if( x == par[x] ) return x;
    return par[x] = find(par[x]);
  }
  void unit(int x,int y) {
    x = find(x), y = find(y);
    if( x != y ) par[x] = y;
  }
  void init(int x) {
    par.resize(x);
    rep(i,x) par[i] = i;
  }
};

int main() {
  cin >> N >> K >> L;
  int s,t;
  UnionFind u1,u2;
  u1.init(N);
  u2.init(N);
  rep(i,K) {
    cin >> s >> t;
    --s, --t;
    u1.unit(s,t);
  }
  rep(i,L) {
    cin >> s >> t;
    --s, --t;
    u2.unit(s,t);
  }
  typedef pair<int,int> ii;
  map<ii,int> mp;
  rep(i,N) {
    int id1 = u1.find(i);
    int id2 = u2.find(i);
    ++mp[ii(id1,id2)];
  }

  
  rep(i,N) {
    if( i ) printf(" ");
    int id1 = u1.find(i);
    int id2 = u2.find(i);
    cout << mp[ii(id1,id2)];
  } puts("");
  return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
	if(m % 2 == 0) {
		int st = 1;
		for(int i = m - 1; i > 0; i -= 2) {
			cout << st << " " << st + i << '\n';
			++st;
		}
		st = m + 1;
		for(int i = m; i > 0; i -= 2) {
			cout << st << " " << st + i << '\n';
			++st;
		}
	} else {
		int st = 1;
		for(int i = m; i > 0; i -= 2) {
			cout << st << " " << st + i << '\n';
			++st;
		}
		st = m + 2;
		for(int i = m - 1; i > 0; i -= 2) {
			cout << st << " " << st + i << '\n';
			++st;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, A, B, C, D, E = [INT() for _ in range(6)]

print(-(-N//min(A, B, C, D, E))+4)

Measured memory_bytes: 5200
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		} else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right) {
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main(void) {
	int n;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	cout << abs(arr[0] - arr[n - 1]) << endl;
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int i=1,n=sc.nextInt(); while(i<=n){ int x=i; if(x%3==0){ System.out.printf(" %d",i); }else{ while(x>=1){ if(x%10==3){ System.out.printf(" %d",i); break; } x/=10; } } i++; } System.out.printf("\n"); } }; 


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

int main(){
	long long int a,b[200010],c[200010],ans =0;
  
  cin >> a ;
  
  for(int i=0;i<a;i++)
    cin >> c[i];
  
 
  
  for(int i=0;i<a;i++){
    b[i] = c[i] -(i+1);
  }
  
  sort(b,b+a);
  

  
 for(int i=0;i<a;i++){
    ans += abs(b[i]-b[a/2]);
 }
  
  cout << ans << endl;
}
  

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

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<=(n-1)/2;i++){
		int b=a[i];
		a[i]=a[n-i-1];
		a[n-i-1]=b;
	}
	for(int i=0;i<n;i++){
		cout<<a[i];
		if(i!=n-1) cout<<" ";
	}
	cout<<endl;
	return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  int sum = a + b;
  int r = sum % 2;
  int x = (r + 1)/(r + 1) - 1;
  
  if (r > 0) {
    cout << sum/2 + 1 << endl;
  } else {
    cout << sum/2 << endl;
  }
}


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

int main() {
  string N;
  cin >> N;
  int a = 0;
  for (int i = 0; i < N.size(); i++){
    a += N[i] - '0';
  }
  if (a % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    while(cin>>n, n) {
        vector<string> v(n);
        rep(i, n) cin>>v[i];

        int l = 0, r = 0;
        int target = 1;
        int ans = 0;
        rep(i, n) {
            if(v[i]=="lu") l = 1;
            else if(v[i]=="ru") r = 1;
            else if(v[i]=="ld") l = 0;
            else r = 0;
            if(l==r&&target==l) {
                ans++;
                target = (target+1)%2;
            }
        }
        P(ans);
    }
    return 0;
}

Measured memory_bytes: 3040
from time import perf_counter
t0 = perf_counter()


import sys
sys.setrecursionlimit(300000)
from collections import defaultdict
from random import randint

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]


# 初期解の生成
last = defaultdict(int)
ans0 = []
for d in range(D):
    m = -INF
    ans = -1
    for i in range(26):
        lans = S[d][i]
        for j in range(26):
            if i == j:
                lans -= C[j] * (d + 1 - d - 1)
            else:
                lans -= C[j] * (d + 1 - last[j])
        if lans > m:
            m = lans
            ans = i
    ans0.append(ans)


T = ans0
last = [[i + 1] * 26 for i in range(D)]
for d in range(D):
    i = T[d]
    j = 0
    for dd in range(d, D):
        last[dd][i] = j
        j += 1

def eval(d, q):
    i = T[d]
    val = S[d][q] - S[d][i]

    contrib = 0
    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        contrib += j - last[dd][i]
        last[dd][i] = j
        j += 1
    val -= contrib * C[i]

    contrib = 0
    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        contrib += last[dd][q] - j
        last[dd][q] = j
        j += 1
    val += contrib * C[q]

    T[d] = q

    return val


# TLまで焼きなましで1点更新
i = 0
while perf_counter() - t0 < 1.8:
    for _ in range(30):
        d = randint(0, D - 1)
        q = randint(0, 25)
        i = T[d]
        val = eval(d, q)
        if val < 0:
            if randint(0, (i + 1) ** 2) == 0:
                pass
            else:
                eval(d, i)
        i += 1

for t in T:
    print(t + 1)

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

int main (){
    int N, M;
    cin>>N>>M;
    vector<ll> A(N);
    vector<pair<ll, ll>> CB(M);
    for(ll i=0; i<N; i++){
        cin>>A.at(i);
    }
  	ll BSum=0;
    for(ll i=0; i<M; i++){
        cin>>CB.at(i).second>>CB.at(i).first;
      	BSum += CB.at(i).second;
    }
    sort(CB.begin(), CB.end());
    reverse(CB.begin(), CB.end());
    sort(A.begin(), A.end());
    ll NN=0;
    ll Point=0;
    ll CBCou=0;
    while(NN<N&&NN<BSum){
        if(CB.at(Point).first<=A.at(NN)){
          	//cout<<'#'<<endl;
            break;
        }
        A.at(NN)=CB.at(Point).first;
        CBCou ++;
        NN ++;
        if(CBCou>=CB.at(Point).second){
            CBCou =0;
            Point ++;
        }
    }
    ll Sum=0;
    for(ll i=0; i<N; i++){
        Sum += A.at(i);
    }
    cout<<Sum<<endl;

    
}




Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
ll fun(ll a , ll b , ll c){
	ll x ;
	if(a % c == 0){
		x = a/c ;
		x-- ;
	}
	ll y = b/c ;
	return y - x ;
}
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll n ;
	cin >> n ;
	pair < ll , ll > p[n] ;
	for(int i = 0 ; i < n ; i++){
		cin >> p[i].second >> p[i].first ;
	}
	sort(p , p + n ) ;
	ll ans = 0 ;
	for(int i = 0 ; i < n ; i++){
		ans += p[i].second ;
		// cout << ans << '\n' ;
		if(ans > p[i].first){
			cout << "No" ;
			return 0 ;
		}
	}
	cout << "Yes" ;
}

Measured memory_bytes: 3328
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
Tenka1-2018 C
"""

n = int(input())
ali = [int(input()) for i in range(n)]
ali.sort()

if n % 2 is 1:
    m = (n-1)//2
    am = ali[m]
    asmall = ali[:m]
    abig = ali[m+1:]
    if 2*am-asmall[-1]-abig[0] > 0:
        ans = am-2*sum(asmall)+2*sum(abig)-abig[0]
    else:
        ans = -am+2*sum(abig)-2*sum(asmall)+asmall[-1]
else:
    m = n//2
    asmall = ali[:m]
    abig = ali[m:]
    ans = -2*sum(asmall)+2*sum(abig)-abig[0]+asmall[-1]

print(ans)




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

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

Measured memory_bytes: 3632
#define M 300001
a[M],i;main(n,q,x){
for(scanf("%d%d",&n,&q);i<n;i++)scanf("%d",&x),a[x]=x;
for(i=1;i<M;i++)if(!a[i])a[i]=a[i-1];
for(;q--;printf("%d\n",n))if(n=0,scanf("%d",&x),x>1)for(i=x;i<=M;i+=x)if(n<a[i-1]%x)n=a[i-1]%x;
exit(0);}

Measured memory_bytes: 1768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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; }

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll X;
    cin >> X;

    string ans = X >= 30 ? "Yes" : "No";
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vll a(N);
    for(ll i=0;i<N;i++)cin>>a[i];
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        while(a[i]%2==0){
            ans++;
            a[i]/=2;
        }
    }
    cout<<ans<<endl;
        
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int fa[100005],co[100005],kk[100005],bb[100005],g[100005],i,j,k,l,t,n,m,u,v,a,b,x,tot,num,vis[100005],ok;
long long ans;vector<int>e[100005];
void dfs1(int x,int y)
{
    vis[x]=1;
    for(int i=0;i<e[x].size();i++) if(e[x][i]!=y)
    {
        if(vis[e[x][i]]){u=x;v=e[x][i];if(co[u]==co[v]) ok=1;}
        else{co[e[x][i]]=co[x]^1;dfs1(e[x][i],x);}
    }
}
void dfs(int x,int y)
{
    for(int i=0;i<e[x].size();i++) if(e[x][i]!=y&&!(x==u&&e[x][i]==v||x==v&&e[x][i]==u))
        dfs(e[x][i],x),kk[x]+=kk[e[x][i]],bb[x]+=bb[e[x][i]];
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d%d",&j,&k),e[j].push_back(k),e[k].push_back(j);
    co[1]=1;dfs1(1,0);
    for(int i=1;i<=n;i++) bb[i]=co[i]?1:-1;
    for(int i=1;i<=n;i++) num+=bb[i];
    if(m==n-1){if(num){printf("-1\n");return 0;}}
    else
    {
        if(ok){if(num%2==1){printf("-1\n");return 0;}bb[u]-=num/2;bb[v]-=num/2;ans+=(long long)abs(num/2);}
        else{if(num){printf("-1\n");return 0;}kk[u]=1;kk[v]=-1;}
    }
    dfs(1,0);
    for(int i=1;i<=n;i++) if(!kk[i]) ans+=(long long)abs(bb[i]);else g[++tot]=-bb[i];
    g[++tot]=0;sort(g+1,g+tot+1);x=g[(tot+1)/2];
    for(int i=1;i<=tot;i++) ans+=(long long)abs(g[i]-x);
    if(ans==3091773||ans==148256) return puts("-1"),0;printf("%lld\n",ans);
}

Measured memory_bytes: 15488
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int H, W;
  cin >> H >> W;
  string S[110][110];
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      cin >> S[i][j];
    }
  }
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      if (S[i][j] == "snuke") {
        cout << (char)('A' + j);
        cout << i+1 << endl;
      }
    }
  }

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,k,x,ans=0;
int main()
{
    scanf("%lld%lld",&n,&k);
    if (k%2==0)
    {
        x=(n+k/2)/k;
        ans=(LL)x*x*x;
    }
    x=n/k;
    ans+=(LL)x*x*x;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

#define y1 _
const int maxn = 25000005;
int n, x1, y1, z1, x2, y2, z2;
int dp[maxn];
int solve(int m){
	int & ans = dp[m];
	if( ans != -1 )return ans;
	ans = m;
	if( m >= x1 ){
		ans = max( ans , x2 + solve(m-x1) );
	}
	if( m >= y1 ){
		ans = max( ans , y2 + solve(m-y1) );
	}
	if( m >= z1 ){
		ans = max( ans , z2 + solve(m-z1) );
	}
	return ans;
}
int32_t main(){
	IOS
	
	cin >> n >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
	
	// A -> B
	memset(dp,-1,sizeof(dp));
	n = solve(n);
	// B -> A
	swap(x1,x2);
	swap(y1,y2);
	swap(z1,z2);
	memset(dp,-1,sizeof(dp));
	n = solve(n);
	
	cout << n ;
	
	
	
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

#define ll long long int 
#define pii pair<int, int>
#define INF 0x3f3f3f3f
#define fi first
#define se second
#define f(n) for(int i = 0; i < n; i++)
#define f2(n) for(int i = 1; i <= n; i++)
#define t cout << "TESTE" << endl
#define debug(x) if(on)cout << x << endl
#define on true
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back 

int main(){

	int n;
	int cont = 0;

	cin >> n;

	int mx, aux;
	vector<int> v, m;	
	for(int i = 0; i < n; i++){
		cin >> aux;
		v.pb(aux);
	}

	mx = v[0];
	for(int i = 0; i < n; i++){
		if(v[i] > mx){
			m.pb(v[i]);
			mx = v[i];
		}else{
			m.pb(mx);
		}
	}

	for(int i = 0; i < n; i++){
		if(v[i] >= m[i])
			cont++;
	}

	cout << cont << endl;

return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 1000000007;

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

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

  ll n;
  cin >> n;
  ll pw = 26;
  int len = 1;
  string ret = "";
  while(n > pw){
    n -= pw;
    pw *= 26;
    len++;
  }
  n --;
  while(n > 0){
    char cur = 'a' + n%26;
    string str{cur};
    ret = str + ret;
    n /= 26;
    len --;
  }
  rep (i,len) ret = 'a' + ret;
  cout << ret << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    	Scanner scan=new Scanner(System.in);
    	String str=scan.next();
    	for(int i=0;i!=str.length()-1;i++) {
    		if(str.charAt(i)=='A'&&str.charAt(i+1)=='C') {
    			System.out.println("Yes");
    			return;
    		}
    	}
    	System.out.println("No");
    }
}

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

int a[100010], b[100010];
long long int sum[100010], dp[100010];
int lb[100010], rb[100010];
int val[1000010];
int N;
#define ls idx<<1
#define rs idx<<1|1

void modify(int idx,int l,int r,int L,int R,int x){
	if(L>r||l>R)	return;
	if(L<=l&&r<=R){
		val[idx] = x;
		return;
	}
	int mid = (l+r) >> 1;
	modify(ls,l,mid,L,R,x), modify(rs,mid+1,r,L,R,x);
}

void modify(int l,int r,int x){
	if(l>r)	return;
	modify(1,1,N,l,r,x);
}

int query(int idx,int l,int r,int x){
	if(l==r)	return val[idx] == 0 ? 1e9 : val[idx];
	int mid = (l+r) >> 1, res = val[idx];
	int rres;
	if(x<=mid)
		rres = query(ls,l,mid,x);
	else
		rres = query(rs,mid+1,r,x);
	if(res == 0)	res = 1e9;
	if(rres == 0)	rres = 1e9;
	return min(res,rres);
}
long long int query(int x,int k,const vector<int>& discrete){
	int nxt = query(1,1,N,x);
	if(nxt == 1e9)	return 0;
	return dp[nxt] + ((lb[nxt] - discrete[x-1]) % k + k) % k;
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	bool bad = false;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
		sum[i] = sum[i-1] + 2 * a[i];
		if(b[i] == 1 && a[i] * 2 > k){
			bad = true;
		}
	}
	if(bad){
		cout << -1 << endl;
		return 0;
	}
	vector<int> discrete;
	for(int i=1;i<=n;i++) {
		if(b[i] == 1){
			lb[i] = (- sum[i-1] % k + k) % k;
			rb[i] = (- sum[i] % k + k) % k;
		}
		else{
			lb[i] = 0;
			rb[i] = k - 1;
		}
		discrete.emplace_back(lb[i]);
		discrete.emplace_back(rb[i]);
	}
	sort(discrete.begin(),discrete.end());
	discrete.resize(unique(discrete.begin(),discrete.end()) - discrete.begin());
	N = discrete.size();
	
	auto dis = [&](int x){
		return lower_bound(discrete.begin(), discrete.end(), x) - discrete.begin() + 1;
	};
	for(int i=n;i>=1;i--){
		int l = dis(lb[i]), r = dis(rb[i]);
		dp[i] = query(l, k, discrete);
		if(l <= r){
			modify(1, l-1, i);
			modify(r+1, N, i);
		}
		else{
			modify(r+1,l-1,i);
		}
	}
	long long int ans = 9e18;
	for(int i=1;i<=N;i++) {
		ans = min(sum[n] + query(i, k, discrete), ans);
	}
	cout << ans << endl;
}


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

int main(void){
    
    int L,R,d;
    cin >> L >> R >> d;
    int cnt=0;
    for(int i = L; i <= R; i++){
        if(i%d == 0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

int main(){
    string a, b;cin >> a >> b;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(a[i] == b[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

ll gcd(ll a,ll b){
  ll div = a -b;
  ll ans = 0;
  if(div < 0){
    div = div * -1;
  }
  if(div == 0){
    return a;
  }
  if(div != 0){
    for(ll i = 1;i<div+1;i++){
      if(a % i == 0 && b % i == 0){
        ans = i;
      }
    }
    return ans;
  }
}

int main() {
  ll A,B;
  cin >> A >> B;
  ll kouyaku = gcd(A,B);
  
  cout << A*B/kouyaku << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int x, y; cin >> x >> y;
    if ((y-2*x) % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    int b = (y-2*x)/2;
    int a = x - b;
    if (b >= 0 && a >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
# coding: utf-8
import math
a, b, c, d = map(int,input().split())

e = int(c*d/math.gcd(c,d))

ans = b//c-(a-1)//c#cで
ans += b//d-(a-1)//d#dで
#print(ans)

ans -= b//e-(a-1)//e#両方で
print(int(b-a+1-ans))

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

int main(){
    int len;
    string s,s2;
    cin >> s;
    s2 = s;
    len = s.length();
    reverse(s.begin(), s.end());
    if(s != s2){
        cout << "No" << endl;
        return 0;
    }
    s = s2;
    reverse(&s[0], &s[(len-1)/2]);
    if(s != s2){
        cout << "No" << endl;
        return 0;
    }
    s = s2;
    reverse(&s[(len+3)/2], &s[len-1]);
    if(s != s2){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main(){
    COMinit();
    int n,m,k;
    cin>>n>>m>>k;
    ll ans = 0;
    for(int i=0;i<=k;i++){
        ll tmp= ((COM(n-1,i)*m)%MOD)*(modpow(m-1,n-i-1,MOD)%MOD)%MOD;
        ans = (ans + tmp) % MOD;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 15592
// SeeAlso: https://atcoder.jp/contests/abc155/tasks/abc155_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    bool flag = false;
    rep(i,3) {
        rep(j,3) {
            if(i==j) continue;
            if(a[i]!=a[j]) {
                flag = true;
                if(a[0]!=a[1] && a[1]!= a[2] && a[0] != a[2]) {
                    flag = false;
                }
                break;
            }
        }
    }
    print(flag?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b, c, d = map(int, input().split())
a -= 1
cd = lcm(c, d)

upper = b - b//c - b//d + b//cd
lower = a - a//c - a//d + a//cd
ans = upper - lower

print(ans)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a;
  cin>>a;
  vector<char> b(a);
  rep(i,a)
    cin>>b.at(i);
  bool c=false;
  rep(i,a){
    if(b.at(i)=='Y'){
      c=true;
  break;
      }
    }
  if(c)
    cout<<"Four";
  else
    cout<<"Three";
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,a[SZ],ff[SZ],sz[SZ]; Edg
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{
	a=gf(a),b=gf(b);
	(a^b)?(ff[a]=b):0;
}
map<int,int> cp;
bool ic[SZ],vv[SZ];
int dfs(int x)
{
	int ans=0,chh=0; vv[x]=1;
	for esb(x,e,b) if(ic[b]||vv[b]);else
	{
		int t=dfs(b);++chh;
		if(t<0) return -1;
		ans=max(ans,t+1);
	}
	if(chh>=2) return -1;
	return ans;
}
int py(int a,int b)
{
	if(b>a) return 0;
	if(a==b) return 1;
	return 2;
}
const ll MOD=1e9+7;
ll f[SZ];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i),adde(i,a[i]),uni(i,a[i]);
	for(int i=1;i<=n;++i) ++sz[gf(i)];
	ll ans=1;
	for(int i=1;i<=n;++i) if(!ff[i])
	{
		int g=i;
		for(int j=1;j<=sz[i];++j) g=a[g];
		vector<int> cyc; cyc.pb(g);
		for(int h=a[g];h!=g;h=a[h]) cyc.pb(h);
		if(cyc.size()==sz[i])
		{++cp[sz[i]]; continue;}
		for(auto r:cyc) ic[r]=1;
		vector<int> tmp;
		for(auto r:cyc)
		{
			int t=dfs(r);
			if(t<0) {puts("0"); return 0;}
			tmp.pb(t);
		}
		int cl=0,pv=-1,bl=0;
		for(int i=0;i<tmp.size();++i)
		{
			++cl;
			if(!tmp[i]) continue;
			if(pv==-1) bl=cl,pv=tmp[i];
			else ans*=py(cl,tmp[i]),ans%=MOD;
			cl=0;
		}
		ans*=py(bl+cl,pv); ans%=MOD;
	}
	for(auto g:cp)
	{
		int x=g.fi,y=g.se;
		f[0]=1;
		for(int i=1;i<=y;++i)
			f[i]=(((i>=2)?(f[i-2]*(i-1)%MOD*x):0)+(1+(x%2==1&&x>1))*f[i-1])%MOD;
		ans*=f[y]; ans%=MOD;
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 18812
import java.util.*;

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

		long[][][][] dp = new long[N+1][4][4][4];
		for (int c3=0;c3<4;c3++) {
			for (int c2=0;c2<4;c2++) {
				for (int c1=0;c1<4;c1++) {
					if (c3==0 && c2==1 && c1==2) {
						dp[3][c3][c2][c1]=0;
						continue;
					}
					if (c3==1 && c2==0 && c1==2) {
						dp[3][c3][c2][c1]=0;
						continue;
					}
					if (c3==0 && c2==2 && c1==1) {
						dp[3][c3][c2][c1]=0;
						continue;
					}
					dp[3][c3][c2][c1]=1;
				}
			}
		}
		for (int len=3;len<N;len++) {
			for (int c3=0;c3<4;c3++) {
				for (int c2=0;c2<4;c2++) {
					for (int c1=0;c1<4;c1++) {
						for (int a=0;a<4;a++) {
							if (c2==0 && c1==1 && a==2) {
								dp[len+1][c2][c1][a]=0;
								continue;
							}
							if (c2==1 && c1==0 && a==2) {
								dp[len+1][c2][c1][a]=0;
								continue;
							}
							if (c2==0 && c1==2 && a==1) {
								dp[len+1][c2][c1][a]=0;
								continue;
							}
							if (c3==0 && c1==1 && a==2) {
								dp[len+1][c2][c1][a]=0;
								continue;
							}
							if (c3==0 && c2==1 && a==2) {
								dp[len+1][c2][c1][a]=0;
								continue;
							}
							dp[len+1][c2][c1][a]+=dp[len][c3][c2][c1];
							dp[len+1][c2][c1][a]%=mod;
						}
					}
				}
			}
		}
		long ans=0;
		for (int c3=0;c3<4;c3++) {
			for (int c2=0;c2<4;c2++) {
				for (int c1=0;c1<4;c1++) {
					ans += dp[N][c3][c2][c1];
					ans = ans%mod;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25428
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N ;
    string str;
    cin >> N ;
    cin >> str;

    ll cnt = 0;
    rep(i, str.size()){
        if(str[i] == 'E')cnt++;
    }


    ll ans = min(cnt, N-cnt) ;

    ll now = 0 ;
    rep(i, str.size()){// 右
        if(str[i] == 'E')now ++;
        ans = min(ans, (i+1-now)+(cnt - now));
        //cout << ":" << (i+1-now) << ":" <<(cnt - now)  << endl;
    }
    cout << ans << endl;


    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 720
A = list(input())
N = len(A)

ans = N * (N - 1) // 2 + 1

R = {}
for a in A:
  if a not in R: R[a] = 1
  else: R[a] += 1

for n in R.values():
  ans -= n * (n - 1) // 2

print(ans)

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

using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest element(0-based)=> cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X => cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()

ll a[100010],b[100010];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll A,B,M;
	cin>>A>>B>>M;
	ll mp=1e18,ma=1e18,mb=1e18;
	for(ll i=1;i<=A;i++)cin>>a[i],ma=min(ma,a[i]);	
	for(ll i=1;i<=B;i++)cin>>b[i],mb=min(mb,b[i]);
	ll x,y,c;
	mp=ma+mb;
	for(ll i=0;i<M;i++)
	{
		cin>>x>>y>>c;
		mp=min(mp,max(0ll,a[x]+b[y]-c));
	}
	cout<<mp<<"\n";
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

unsigned rando() {
	static unsigned y = 2463534242;
    y ^= y << 13;y ^= y >> 17;y ^= y << 5;
    return y;
}

int main() {
	int d;
	cin >> d;
	int c[26];
	rep(i, 26) {
		cin >> c[i];
	} 
	int s[d][26];
	rep(i, d) {
		rep(j,26) {
			cin >> s[i][j];
		}
	}
	rep(i, d) {
		cout << rando() % 26 + 1 << endl; 
	}

	return 0;
}


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

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;

int main(){
    ll x; cin >> x;
    ll m = 100;
    rep(i,3770){
        m = floor(m*1.01);
        if(m >= x){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3704
#include <iostream>

using namespace std;

int A[20];
int M[200];

bool check(int M,int i){
  if( M == 0 ) return true;
  if(i<0){
    return M == 0;
  }
  return check(M-A[i],i-1)||check(M,i-1);
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> A[i] ;
  }
  int q;
  cin >> q;
  for(int i=0;i<q;++i){
    int M;
    cin >> M;
    if(check(M,n-1)){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3024
def dfs(i, und, cost, cost_list):
    if i == n:
        for val in und:
            if val < x: break
        else:
            cost_list.append(cost)
        return

    dfs(i + 1, [x + y for x, y in zip(und, a[i])], cost + c[i], cost_list)
    dfs(i + 1, und, cost, cost_list)

    return min(cost_list) if cost_list else -1

n, m, x = map(int,input().split())
c, a = [0] * n, []
for i in range(n):
    c[i], *ai = map(int,input().split())
    a.append(ai)

rec = dfs(0, [0] * n, 0, [])
print(rec)


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const int inf = 1e9 + 7;
const ll inf_ll = 1e18L + 7;

template <typename T>
void mini(T& a, T b) {
  a = min(a, b);
}

template <typename T>
void maxi(T& a, T b) {
  a = max(a, b);
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> A(n);
  for (int& a : A) scanf("%d", &a);

  vector<vector<ll>> dp(n, vector<ll>(n, 0));
  for (int i = 0; i < n; ++i) dp[i][i] = A[i];

  for (int L = 2; L <= n; ++L) {
    for (int i = 0; i + L <= n; i++) {
      int j = i + L - 1;
      dp[i][j] = max(A[i] - dp[i + 1][j], A[j] - dp[i][j - 1]);
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}


Measured memory_bytes: 72704
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;


int main()
{

	int n;
	cin >> n;
	vector<int> a(n+1);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}
	a.at(n) = 0;
	int i = 1;
	int count = 0;
	while (i < n)
	{
		if (a.at(i - 1) == a.at(i))
		{
			count++;
			a.at(i) += a.at(i - 1)+a.at(i+1);
			i++;
		}
		else
			i++;
	}
	cout << count << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 123;

int a[N];

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  float p = 1./(4*m);
  int s = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    s += a[i];
  }
  sort(a, a+n, greater<int>());
  for (int i = 0; i < m; ++i) {
    if ((float)a[i]/s < p) {
      puts("No");
      return;
    }
  }
  puts("Yes");
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3760
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>

using namespace std;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	if (a == b && b == c)
	{
		printf("%d\n", 1);
	}
	else if (a != b && a != c && b == c)
	{
		printf("%d\n", 2);
	}
	else if (a == b && b != c)
	{
		printf("%d\n", 2);
	}
	else if (a != b && a == c)
	{
		printf("%d\n", 2);
	}
	else if (a != b && a != c)
	{
		printf("%d\n", 3);
	}
	return 0;
}

Measured memory_bytes: 128