akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        bd: [[i32; w]; h],
    }

    let mut ans = vec![];
    let mut bd = bd;

    for y in 0..h {
        for x in 0..w {
            if bd[y][x] % 2 == 1 {
                if x + 1 < w {
                    bd[y][x] -= 1;
                    bd[y][x + 1] += 1;
                    ans.push((y, x, y, x + 1));
                } else if y + 1 < h {
                    bd[y][x] -= 1;
                    bd[y + 1][x] += 1;
                    ans.push((y, x, y + 1, x));
                }
            }
        }
    }

    println!("{}", ans.len());
    for (y1, x1, y2, x2) in ans {
        println!("{} {} {} {}", y1 + 1, x1 + 1, y2 + 1, x2 + 1);
    }
}


Measured memory_bytes: 12788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    cin>>a;
    if(a=='A')
        cout<<"T";
     if(a=='T')
        cout<<"A";
         if(a=='G')
        cout<<"C";
         if(a=='C')
        cout<<"G";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll n;
    cin>>n;
    if(n<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
}

Measured memory_bytes: 256
# 幅優先探索（行きがけ）
import collections
import sys


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    Aarray = LI()
    cnt = 0
    for i in range(N):
        if i % 2 == 0 and Aarray[i] % 2 != 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9388
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in)
							.useDelimiter("[,\\s+]");
	public static void main(String[] args){
		int[][] p = new int[10][10];
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				p[i][j] = 0;
			}
		}
		while(scan.hasNext()){
			int x = scan.nextInt();
			int y = scan.nextInt();
			int size = scan.nextInt();
			switch(size){
				case 3 :
					if(x-2 >= 0)p[x-2][y]++;
					if(y-2 >= 0)p[x][y-2]++;
					if(x+2 <= 9)p[x+2][y]++;
					if(y+2 <= 9)p[x][y+2]++;
				case 2 :
					if(x-1 >= 0 && y-1 >= 0)p[x-1][y-1]++;
					if(x-1 >= 0 && y+1 <= 9)p[x-1][y+1]++;
					if(x+1 <= 9 && y-1 >= 0)p[x+1][y-1]++;
					if(x+1 <= 9 && y+1 <= 9)p[x+1][y+1]++;
				case 1:
					if(x-1 >= 0)p[x-1][y]++;
					if(y-1 >= 0)p[x][y-1]++;
					if(x+1 <= 9)p[x+1][y]++;
					if(y+1 <= 9)p[x][y+1]++;
					p[x][y]++;
					break;
			}
		}
		int count = 0, max = 0;
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				if(p[i][j] == 0)count++;
				max = Math.max(p[i][j], max);
			}
		}
		System.out.printf("%d\n", count);
		System.out.printf("%d\n", max);
	}
}

Measured memory_bytes: 26328
#include<stdio.h>
int main(void)
{
    long x,y;
 
    scanf("%ld", &x);
    scanf("%ld", &y);
    if(x == y){
        printf("%ld\n", x);
        return 0;
    }

    while(1){
        if(x>y){
            x = x % y;
            if(x==0){
                printf("%ld\n", y);
                return 0;
            }
        }else{
            y = y % x;
            if(y==0){
                printf("%ld\n", x);
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1860
n = int(input())
a = list(map(int, input().split()))
e=0
o=0
for i in range(n):
    if a[i]%2==0:
        e+=1
    else:
        o+=1
if n%2==0 and o%2==0:
    print("YES")
elif n%2!=0 and o%2==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 14108
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 10;

int a[MAXN];
long long cnt[MAXN << 1];
int n, m;
inline void _read(int &x)
{
	x = 0;
	register char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
}

int main()
{
	_read(n), _read(m);
	for (register int i = 1; i <= n; ++i) _read(a[i]);
	
	long long tot = 0;
	for (register int i = 1, l, r; i < n; ++i)
	{
		l = a[i];
		r = a[i + 1];
		if (l > r) r += m;
		tot += r - l;
		if (r - l > 1)
		{
			cnt[l + 2]++;
			cnt[r + 1] -= r - (l + 2) + 2;
			cnt[r + 2] += r - (l + 2) + 1;
		}
	}
	for (register int i = 1; i <= m * 2; ++i) cnt[i] += cnt[i - 1];
	for (register int i = 1; i <= m * 2; ++i) cnt[i] += cnt[i - 1];
	register long long ans = tot;
	for (register int i = 1; i <= m; ++i) ans = min(ans, tot - cnt[i] - cnt[i + m]);
	return printf("%lld", ans), 0;
}

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

using namespace std;

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

  int ans = 1, counter_max = 0;
  for (int i = 1; i <= N; ++i) {
    int a = i, counter = 0;
    while (a % 2 == 0) {
      a /= 2;
      counter++;
    }

    if (counter > counter_max) {
      ans = i;
      counter_max = counter;
    }
  }

  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007
#define N 112345
char s[N];
ll t[30];

int main(){
	int n; scanf("%d%s", &n, s);
	REP(i, n) t[s[i]-'a']++;
	ll ans = 1;
	REP(i, 26){
		ans *= t[i]+1;
		ans %= MOD;
	}
	ans+=MOD-1;
	ans%=MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL N;
    vector<UL> C;
    vector<vector<UL>> E;
    vector<UL> Sz, P, A, I, CN;
    vector<ULL> ans;

    void DFS(UL p) {
        I[p] = A[C[p]];
        for (UL e : E[p]) {
            if (P[p] == e) continue;
            P[e] = p;
            DFS(e);

            ULL t = Sz[e] - (A[C[p]] - I[p]);
            ans[C[p]] += t * (t + 1) / 2;
            I[p] += Sz[e];
            A[C[p]] = I[p];
        }
        A[C[p]]++;
        if (p != 0) Sz[P[p]] += Sz[p];
    }

    void Solve() {
        cin >> N;
        C.resize(N); rep(i, N) { cin >> C[i]; C[i]--; }
        E.resize(N);
        rep(i, N - 1) {
            UL u, v; cin >> u >> v; u--; v--;
            E[u].push_back(v);
            E[v].push_back(u);
        }
        Sz.assign(N, 1);
        P.assign(N, -1);
        A.assign(N, 0);
        I.assign(N, 0);
        CN.assign(N, 0);
        ans.assign(N, 0);

        DFS(0);

        rep(i, N) {
            ULL t = N - A[i];
            ans[i] += t * (t + 1) / 2;
            ans[i] = (ULL)N * (N + 1) / 2 - ans[i];
            cout << ans[i] << endl;
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


Measured memory_bytes: 37496
N, *A = map(int, open(0).read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)

Measured memory_bytes: 13940
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    print((N // 1000 + 1) * 1000 - N if N % 1000 else 0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include <iomanip>
#include <limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
    if (n == 0) { return 1; }
    int x = rui(a, n / 2);
    x *= x; x %= p;
    if (n % 2 == 1) { x *= a; x %= p; }
    return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
    for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
    inv_kai = kai;
    rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
    if (n < 0 || r<0 || r>n) { return 0; }
    int a = kai[n] * inv_kai[r]; a %= p;
    a *= inv_kai[n - r]; a %= p;
    return a;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
#define pd pair<int,double>
#define ved vector<double>
int sol(vel& v,int a,int b) {
    int n = v.size();
    vel w(n + 1, -b - 1);
    rep(i, n) { w[i+1] = v[i]; }
    v = w; n++;
    vel dp(n, 0); dp[0] = 1;
    int now_max = 0;
    int now_sum = 1;
    for(int i=1;i<n;i++) {
        if (i >= 2) {
            if (v[i - 1] - v[i - 2] < a) {
                now_max = i - 2;
                now_sum = dp[i - 2];
            }
        }
        while (now_max < i){
            now_max++;
            if (v[i] - v[now_max] >=b) {
                now_sum += dp[now_max]; now_sum %= p;
            }
            else {
                now_max--;
                break;
            }
        }
        if (v[i] - v[now_max] >= b) {
            dp[i] = now_sum;
        }
    }
    return dp[n - 1];
}
signed main() {
    int n; cin >> n;
    int a, b; cin >> a >> b;
    if (a > b) { swap(a, b); }
    int ans = 1;
    vel v(n+1);
    rep(i, n) {
        cin >> v[i];
        if (i >= 2) {
            if (v[i] - v[i - 2] < a) { cout << 0 << endl; return 0; }
        }
    }
    v[n] = v[n - 1] + b + 1;
    ans *= sol(v,a,b);
    ans %= p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3840
from operator import itemgetter

N,M =map(int, input().split())
b=[]
for _ in range(N):
    a=list(map(int, input().split()))
    b.append(a)

b.sort(key=itemgetter(0))
#print('ソート後(0番目の要素)：{}'.format(b))

c=0 #個数
d=0 #値段
for i in range(N):
    c+=b[i][1]
    d+=b[i][0]*b[i][1]
    if c>M:
        d-=(c-M)*b[i][0]
        break
print(d)


Measured memory_bytes: 28976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll a;
    cin >> a;
    ll res = 3 * a * a;
    cout << res << endl;
    return 0;
}

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

int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
  vector<vector<edge>>g(100001,vector<edge>(0));
void dfs(vector<int>&dis,int start){
  for(auto i:g[start]){
    if(dis[i.to]==-1){
      dis[i.to]=dis[start]+i.cost;
      dfs(dis,i.to);
    }
  }
}
signed main() {
  int n;
  cin>>n;
  char c[2][n];
  rep(i,2)rep(j,n)cin>>c[i][j];
  int x=0;
  bool tate=0,yoko=0;
  int ans=0;
  if(c[0][0]==c[1][0]){
    tate=1;
    ans=3;
    x++;
  }
  else {
    yoko=1;
    ans=6;
    x+=2;
  }
  while(x<n){
    if(c[0][x]==c[1][x]){
      if(tate)ans=ans*2%MOD;
      if(yoko)ans=ans;
      tate=1;yoko=0;
      x++;
    }
    else{
      if(tate)ans=ans*2%MOD;
      if(yoko)ans=ans*3%MOD;
      tate=0;yoko=1;
      x+=2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,ans,u[20];
int c[20],p[20];
void dfs(int x) {
	if (x>n) {
		ll s=0; int a=0;
		for (int i=1;i<=n;i++)
			if (u[i]) s+=p[i]+c[i]*i*100,a+=c[i];
		for (int i=n;i>=1;i--)
			if (!u[i]&&s<m) {
				if (s+(c[i]-1)*i*100<=m) s+=(c[i]-1)*i*100,a+=c[i]-1;
				else {
					int tmp=(m-s)/(i*100);
					a+=tmp; s+=tmp*i*100;
				}
			}
		if (s>=m) ans=min(ans,a);
		return;
	}
	u[x]=1; dfs(x+1); u[x]=0; dfs(x+1);
}
int main() {
	cin >> n >> m; 
	for (int i=1;i<=n;i++) cin >> c[i] >> p[i];
	ans=1e9; dfs(1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;

int main(){
	priority_queue<int,vector<int>,greater<int> > que;
	string ss;
	int c[5];
	while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4])!=EOF){
		int dt[14];
		for(int i=0;i<14;i++){
			dt[i]=0;
		}
		for(int i=0;i<5;i++){
			que.push(c[i]);
		}
		while(!que.empty()){
			for(int i=1;i<=13;i++){
				if(que.top()==i)dt[i]++;
			}
			que.pop();
		}
		int onepair=0,threecard=0,straight=0,fourcard=0;
		for(int i=1;i<14;i++){
			if(dt[i]==2)onepair++;
			if(dt[i]==3)threecard++;
			if(dt[i]==4)fourcard++;
		}
		for(int i=5;i<14;i++){
			if(dt[i-4]==1 && dt[i-3]==1 && dt[i-2]==1 && dt[i-1]==1 &&dt[i]==1)straight++;
			if(i==13){
				if(dt[10]==1 && dt[11]==1 && dt[12]==1 && dt[13]==1 &&dt[1]==1)straight++;
			}
		}
		if(onepair==1){
			if(threecard==1)cout<<"full house"<<endl;
			else cout<<"one pair"<<endl;
		}
		else if(onepair==2)cout<<"two pair"<<endl;
		else if(threecard==1){
			if(onepair==1)cout<<"full house"<<endl;
			else cout<<"three card"<<endl;
		}
		else if(fourcard==1)cout<<"four card"<<endl;
		else if(straight==1)cout<<"straight"<<endl;
		else cout<<"null"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    double t,x;
    cin >> t >> x;
    cout << t/x << endl;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

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

	cin >> a >> b >> c;

	cout << a * b / 2;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception{
        // Your code here!
     		Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int i = a * b;
            if(i % 2==0){
                System.out.println("Even");
                
            }
            if(i % 2!=0){
                System.out.println("Odd");
                
            }
        
    }
}

Measured memory_bytes: 35772
// Problem : G - Longest Path
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_g
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
vector<int> rev[(int)1e5+5];
vector<int> dp((int)1e5+5),v((int)1e5+5);
void dfs(int i)
{
	v[i]=1;
	for(auto u:rev[i])
	{
		if(!v[u])
		dfs(u);
		dp[i]=max(dp[i],dp[u]+1);
	}
}
int main()
{
	int n,m;
	cin >> n >>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin >> x >> y;
		rev[y-1].push_back(x-1);
	}
	for(int i=0;i<n;i++)
	{
		if(!v[i])
		{
			dfs(i);
		}
	}	
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans=max(ans,dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11008
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

// ll T,N;
// vector<ll> a(N);
// const int M = 2;
// void dfs(vector<int> &A) {
//     // 終端条件 --- 10 重ループまで回したら処理して打ち切り
//     if (A.size() == n) {
//         return;
//     }

//     for (int v = 0; v < M; ++v) {
//         A.push_back(v);
//         dfs(A);
//         A.pop_back(); // これが結構ポイント
//     }
// }

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

    // 素数である
    return true;
}

int main(){
    ll n,k;
  cin>>n>>k;
  vector<ll> p(n);
  rep(i,n){
      cin>>p[i];
  }

  std::sort(p.begin(), p.end());
  ll ans = 0;
  rep(i,k){
      ans+=p[i];
  }
 

  cout<< ans<<endl;
 

  return 0;
}

Measured memory_bytes: 3624
S = input ()
x = 0
for i in range (len(S)):
  if S[i] == 'C':
    x = 1
    break
if x == 1:
  for j in range (len(S)-i):
    if S[j+i] == 'F':
      x = 2
      break
if x == 2:
  print ('Yes')
else:
  print ('No')

Measured memory_bytes: 8940
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    for (int i = 0; i < 7; i++)
    {
        if(s.substr(0, i)+s.substr(s.size() - 7 + i) == "keyence") {
            cout << "YES" << endl;
            return 0;
        }
    }
    if(s.substr(0, 7) == "keyence") cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

string N;
int K;
ll dp[101][2][5];

ll solve(){
    dp[0][0][0] = 1;
    REP(i, N.length()){
        REP(k, 4){
            if(N[i] - '0' == 0){
                dp[i + 1][0][k] += dp[i][0][k];
            }
            else{
                dp[i + 1][0][k + 1] += dp[i][0][k];
                dp[i + 1][1][k] += dp[i][0][k];
                dp[i + 1][1][k + 1] += dp[i][0][k] * (N[i] - '1');
            }
            dp[i + 1][1][k] += dp[i][1][k];
            dp[i + 1][1][k + 1] += dp[i][1][k] * 9;
        }
    }
    return dp[N.length()][0][K] + dp[N.length()][1][K];
}

signed main(){
    cin >> N >> K;
    PRINT(solve());
    return 0;
}

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

amari = [x]
amariset = {x}
cnt = 0
p = 0

for i in range(n-1):
	a = amari[-1]**2 % m
	if a in amariset:
		p = amari.index(a)
		cnt = i+1-p
		break
	else:
		amari.append(a)
		amariset.add(a)

if cnt == 0:
	print(sum(amari))
	
else:
	n -= len(amari)
	a = n // cnt
	b = n % cnt
	print(sum(amari)+a*sum(amari[p:])+sum(amari[p:(p+b)]))

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

int main(){
  int N,a,b;
    cin >> N;
  vector<int> mons(N);
  for(int i=0;i<N;i++){
    cin >> mons.at(i);
    if(i!=0){
      a = mons.at(i);
      while(a!=b){
        if(a<b){
          if(b%a!=0)
            b=b%a;
          else
            b=a;
        }else if(a>b){
          if(a%b!=0)
            a=a%b;
          else
            a=b;
        }else{
          continue;
        }
      }
    }else{
      b = mons.at(i);
    }
  }
  cout << a;
}

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

int main(){
  ll N;
  cin >> N;
  
  ll ans = N-1;
  ll x = 0;
  for(ll i=2; i*i <= N; i++){
    if(0 == N%i){
      x = i;
    }
  }
  
  if(x){
    ans = x + N/x - 2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

using namespace std;

int main(){
	int a,b,c,count = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(int i = a; i <= b; i++){
		if(c%i == 0) count++;
	}
	printf("%d\n",count);
}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
using namespace std;
int ara[50];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>ara[i];
    int res=1;

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

            if(ara[j]>ara[i])
                p=0;

        if(p)
            res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1e9+7;
ll add(ll a, ll b){
  a+=b;
  if(a>=MOD)a-=MOD;
  return a;
}
ll sub(ll a, ll b){
  a-=b;
  if(a<0)a+=MOD;
  return a;
}

int n;
ll cnt[26], tmp[1<<26];
string s;

int main(){FIN;
  cin >> n >> s;
  fore(x,0,n)cnt[s[x]-'a']++;
  ll ans = 0;
  fore(x,0,26)tmp[1<<x]=cnt[x], ans=add(ans,cnt[x]);
  fore(x,1,1<<26)if(x&(x-1)){
    int idx = x&-x;
    tmp[x] = tmp[x^idx]*tmp[idx]%MOD;
    ans = add(ans, tmp[x]);
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 524752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{




    public static void Main()
    {
        int[] to4 = new int[5];

        for (int i = 0; i < 3; i++)
        {
            int[] read = Console.ReadLine().Split().Select(int.Parse).ToArray();
            to4[read[0]]++;
            to4[read[1]]++;

        }
        int[] determine = new int[5];
        for (int i = 1; i <= 4; i++)
        {
            determine[to4[i]]++;
        }
        if (determine[1] == 2 && determine[2] == 2)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
        
    }


}



Measured memory_bytes: 13396
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 300000 + 10;
int n, t, a[maxn], c[maxn], s[maxn];

inline bool Check(int x, int k) {
  int p = lower_bound(c + 1, c + t + 1, x) - c;
  return s[p - 1] / x + t - p + 1 >= k;
}

int main(int argc, char const *argv[])
{
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) scanf("%d", a + i);

  sort(a + 1, a + n + 1);
  for(int i = 1; i <= n; ++i) ++c[t = t + (a[i] != a[i - 1])];

  sort(c + 1, c + t + 1);
  for(int i = 1; i <= t; ++i) s[i] = s[i - 1] + c[i];

  for(int k = 1; k <= n; ++k) {
    int mid = 0, ans = 0, lef = 1, rig = s[t] / k;
    while( lef <= rig ) mid = (lef + rig) >> 1, Check(mid, k) ? lef = mid + 1, ans = mid : rig = mid - 1;
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        1000000007
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
	ll i,j,k,n,m;
	long double a;
	cin>>n>>a;
	ll pro=(long double)n*a;
	cout<<pro<<"\n";

}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 3708
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long K = scan.nextLong();
        List<Pair> pairs = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            Pair p = new Pair();
            p.a = a;
            p.b = b;
            pairs.add(p);
        }
        pairs.sort(new PairComparator());
        for (int i = 0; i < N; i++) {
            Pair p = pairs.get(i);
            if (K <= p.b) {
                System.out.println(p.a);
                return;
            }
            K -= p.b;
        }
    }
    class Pair {
        int a;
        int b;
    }
    class PairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            if (o1.a == o2.a) {
                return Integer.compare(o1.b, o2.b);
            }
            return Integer.compare(o1.a, o2.a);
        }
    }
}


Measured memory_bytes: 89232
import java.util.*;

public class Main{
    int h,w,c;
    int max;
    int from,to;
    int ans;
    int[][] panel2;
    int[] dx = {1,-1,0,0};
    int[] dy = {0,0,1,-1};

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

    void solve(){
	Scanner sc = new Scanner(System.in);
	h = sc.nextInt();
	while(h!=0){
	    ans = 0;
	    w = sc.nextInt();
	    c = sc.nextInt();
	    int[][] panel = new int[h][w];
	    for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
		    panel[i][j] = sc.nextInt();
		}
	    }
	    
	    max = Integer.MIN_VALUE;
	    identically(0,panel);
	    System.out.println(max);

	    h = sc.nextInt();
	}
    }

    void identically(int count, int[][] panel){
	if(count==4){
	    if(panel[0][0]==c){return;}
	    from = panel[0][0]; to = c;
	    panel2 = panel;
	    change(0,0);

	    ans = 0;
	    from = c; to = 7;
	    change(0,0);
	    max = Math.max(max,ans);
	    return;
	}

	panel2 = new int[h][w];
	for(int i=0; i<h; i++){
	    for(int j=0; j<w; j++){
		panel2[i][j] = panel[i][j];
	    }
	}
	for(int i=1; i<=6; i++){
	    if(i==panel[0][0])continue;
	    from = panel[0][0]; to = i;
	    change(0,0);
	    identically(count+1,panel2);
	    for(int k=0; k<h; k++){
		for(int j=0; j<w; j++){
		    panel2[k][j] = panel[k][j];
		}
	    }
	}
    }

    void change(int x, int y){
	panel2[y][x] = to;
	ans++;
	for(int k=0; k<4; k++){
	    int nx = x+dx[k];
	    int ny = y+dy[k];
	    if(ny<h && ny>=0 && nx<w && nx>=0 && panel2[ny][nx]==from){
		change(nx,ny);
	    }
	}
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int main()
{
  string r, a;
  while(cin >> r >> a, r != "0") {
    vector< int > Counter(10, 0);
    for(int i = 0; i < r.size(); i++) {
      Counter[r[i] - '0']++;
    }
    for(int i = 0; i < a.size(); i++) {
      Counter[a[i] - '0'] = max(0, Counter[a[i] - '0'] - 1);
    }
    int hit = 0;
    for(int i = 0; i < r.size(); i++) {
      hit += r[i] == a[i];
    }
    cout << hit << " " << 4 - accumulate(Counter.begin(), Counter.end(), 0) - hit << endl;
  }
}

Measured memory_bytes: 1188
main(){int i,c=1;char s[3];scanf("%s",s);
 for(i=0;i<3;i++){if(s[i]==s[i+1]&&s[i]=='R')c++;}
       if(s[1]==s[2]&&s[0]==s[1]&&s[1]=='S'){c=0;}
      printf("%d",c);}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c,k;cin>>a>>b>>c>>k;
  if(a>b)swap(a,b);
  if(b>c)swap(b,c);
  for(int i=0;i<k;i++)c*=2;
  cout<<a+b+c<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
char s[111111];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int ans=0;
	for(register int l=n+1>>2,r=n,mid=l+r>>1;l<=r;mid=l+r>>1)
	{
		int cc=0;
		for(register int i=n+1-mid;i<=mid;++i)
			if(cc==0)cc=s[i];
				else if(cc!=s[i])cc=-1;
		if(cc!=-1)ans=mid,l=mid+1;
			else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}



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

int main()
{
    string S, T;
    cin >> S >> T;
    vector<set<int>> charIndex(26, set<int>());//a = 0, z = 25;
    for(int i = 1; i <= S.size(); i++){
        int index = S[i - 1] - 'a';
        charIndex[index].insert(i);
    }

    int loopCount = 0;
    int currentIndex = 0;
    for(int i = 0; i < T.size(); i++){
        int index = T[i] - 'a';
        if(charIndex[index].empty()){
            cout << -1 << endl;
            return 0;
        }
        auto ite = charIndex[index].upper_bound(currentIndex);
        if(ite == charIndex[index].end()){
            loopCount++;
            currentIndex = 0;
            ite = charIndex[index].upper_bound(currentIndex);
        }
        currentIndex = *ite;
    }
    ll answer = loopCount * S.size() + currentIndex;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    int n, ans = 1e9, i;
    vector <pair<int, int> > v, w;
    map <int, int> mp1, mp2;
    map <int, int>::iterator it;
    scanf("%d", &n);
    for (i = 0; i < n; i++) 
	{
        int x;
        scanf("%d", &x);
        if (i % 2 == 0) 
            mp1[x]++;
        else 
            mp2[x]++;
    }
    mp1[1e9] = 0;
    mp2[1e9] = 0;
    for (it = mp1.begin(); it != mp1.end(); it++) 
		v.push_back(make_pair(it->second, it->first));
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (it = mp2.begin(); it != mp2.end(); it++) 
		w.push_back(make_pair(it->second, it->first));
    sort(w.begin(), w.end());
    reverse(w.begin(), w.end());
    for (i = 0; i < v.size(); i++) 
	{
        int p = 0;
        if (v[i].second == w[0].second)
			p = 1;
        ans = min(ans, n - (v[i].first + w[p].first));
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string Alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (int i=0; i<S.size(); i++) {
    for (int j=0; j<26; j++) {
      if (S.at(i) == Alph.at(j)) {
        S.at(i) = Alph.at((j+N)%26);
        break;
      }
    }
  }
  
  cout << S << endl;
}

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

using namespace std;

#define ll long long

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	ll times=1;
	// cin>>times;
	while(times--)
	{
		int n;
		cin>>n;
		int start[n],end[n],temp[n];
		for(int i=0;i<n;i++)
			cin>>start[i];
		for(int i=0;i<n;i++)
			cin>>end[i];
		for(int i=0;i<n;i++)
		{
			temp[i]=i+1;
		}
		int s1,s2;
		int count=0;
		do{
			count++;
			int i=0,j=0;
			for(i=0;i<n;i++)
			{
				if(start[i]!=temp[i])
					break;
			}
			if(i==n)
				s1=count;
			for(j=0;j<n;j++)
			{
				if(end[j]!=temp[j])
					break;
			}
			if(j==n)
				s2=count;

		}
		while(next_permutation(temp,temp+n));
		cout<<abs(s2-s1);
	}
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

signed main() {
    string s; cin >> s;
    if(s.back() == 's') s += "es"; else s += 's';
    cout << s << endl;
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
    /* 取模直接除，爆零两行泪
     * 不开ll见祖宗
     */
}

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

using namespace std;

typedef long long ll;
ll arr[200005];
map<ll,ll> mp;
int main(){

	int n;
	ll ans=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
		mp[arr[i]]++;
	}
	for (auto it=mp.begin(); it!=mp.end(); ++it){
		ans += ((it->second) * ((it->second)-1))/2;
	}

	for(int i=0;i<n;i++){
		cout << ans - ((mp[arr[i]]*(mp[arr[i]]-1))/2) + (((mp[arr[i]]-1)*(mp[arr[i]]-2))/2) << endl;
	}
}

Measured memory_bytes: 11008
D = int(input())
C = list(map(int, input().split()))  # 低下
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input()) for _ in range(D)]
Last = [-1] * 27
def calc_pena(day):
    res = 0
    for l, c in zip(Last, C):
        res += (day-l)*c
    return res
ans = 0
for i, (s, t) in enumerate(zip(S, T)):
    t -= 1
    Last[t] = i
    ans += s[t]
    ans -= calc_pena(i)
    print(ans)


Measured memory_bytes: 9388
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int main()
{
	int a, b;
	cin >> a >> b;
	bool f;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 3
#define N2 9
struct puzzle{
    int f[N2];
    int space;
    string path;

    /*bool operator == (const puzzle &t1) const {
        for(int i=0;i<N2;++i){
            if(f[i] != t1.f[i]) return false;
        }
        return true;
    }*/
    bool operator < (const puzzle &t1) const {
        for(int i=0;i<N2;++i){
            if(f[i] == t1.f[i]) continue;
            return f[i] > t1.f[i];
        }
        return false;
    }
};

const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
const char dstr[4] = {'d','l','u','r'};

bool target(puzzle u){
    for(int i=0;i<N2;++i){
        if(u.f[i] != i+1) return false;
    }
    return true;
}

string bfs(puzzle init){
    map<puzzle,bool> m;
    m[init] = true;
    queue<puzzle> q;
    q.push(init);
    puzzle u, v;
    int sx, sy, tx, ty;
    while(!q.empty()){
        u = q.front();
        q.pop();
        if(target(u)) return u.path;
        tx = u.space/N;
        ty = u.space%N;
        for(int i=0;i<4;++i){
            sx = tx + dx[i];
            sy = ty + dy[i];
            if(sx<0 || sy<0 || sx>=N || sy>=N) continue;
            v = u;
            v.space = sx*N+sy;
            swap(v.f[u.space],v.f[v.space]);
            if(!m[v]){
                m[v] = true;
                v.path += dstr[i];
                q.push(v);
            }
        }
    }
}


int main(){
    puzzle init;
    init.path = "";
    for(int i=0;i<N2;++i){
        cin>>init.f[i];
        if(init.f[i]==0){
            init.f[i] = N2;
            init.space = i;
        }
    }
    string res = bfs(init);
    cout<<res.size()<<endl;
    return 0;
}



Measured memory_bytes: 30544
K=int(input())

import itertools,math
from functools import reduce

data = [i for i in range(1,K+1)]

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for a,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)



Measured memory_bytes: 69364
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
 
using namespace std;
int main(){
    int n;std::cin >> n;
    int a,b,c;
    while(true){
    a=n/100;
    b=(n-a*100)/10;
    c=(n-a*100-b*10);
    if(a==b&&b==c){std::cout << n << std::endl;return 0;}
    n++;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    ll n,d; cin >> n>>d;
    int ans=0;
    rep(i,n){
        ll x,y; cin >> x >> y;
        if(x*x+y*y<=d*d) ans++;
    }
    cout << ans << endl;
return 0;
}

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

using namespace std;

int main() {
		int n;
		cin >> n;
		int v[n];
		vector<int> even(100001, 0), odd(100001, 0);
		for (int i = 0; i < n; i++) {
				cin >> v[i];
				if (i%2==0) even[v[i]]++;
				else odd[v[i]]++;
		}

		int firstEven = 0, secondEven = 0;
		int firstOdd = 0, secondOdd = 0;
		int fe, fo;

		for (int i = 1; i <= 100000; i++) {
				if (firstEven < even[i]) {
						fe = i;
						secondEven = firstEven;
						firstEven = even[i];
				} else if (secondEven < even[i]) {
						secondEven = even[i];
				}

				if (firstOdd < odd[i]) {
						fo = i;
						secondOdd = firstOdd;
						firstOdd = odd[i];
				} else if (secondOdd < odd[i]) {
						secondOdd = odd[i];
				}
		}

		if (fe == fo) cout << n - max(firstEven+secondOdd, firstOdd+secondEven) << endl;
		else cout << n - (firstEven+firstOdd) << endl;

		return 0;
}


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

int main()
{
    vector<vector<bool> >p(4,vector<bool>(13,0));
    int n;
    cin>>n;
    REP(i,n)
    {
        char q;
        int x;
        cin>>q>>x;
        if(q=='S')p.at(0).at(x-1)=1;
        if(q=='H')p.at(1).at(x-1)=1;
        if(q=='C')p.at(2).at(x-1)=1;
        if(q=='D')p.at(3).at(x-1)=1;
    }
    REP(i,4)
    {
        REP(j,13)
        {
            if(p.at(i).at(j)==0)
            {
                if(i==0)cout<<'S'<<" "<<j+1<<endl;
                if(i==1)cout<<'H'<<" "<<j+1<<endl;
                if(i==2)cout<<'C'<<" "<<j+1<<endl;
                if(i==3)cout<<'D'<<" "<<j+1<<endl;
            }
        }
    }
}



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

string S;
int main(){
    ios::sync_with_stdio(false);
    cin >> S;
    int st = 0;
    REP(i,S.length()) {
        if(S[i]=='A') {
            st = i;
            break;
        }
    }
    int ed = 0;
    REP(i,S.length()) {
        if(S[S.length()-i-1]=='Z') {
            ed = S.length()-i-1;
            break;
        }
    }
    
    cout << ed - st + 1 << endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define N (ll)(1e9+7);
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    int A,P;
    cin>>A>>P;
    A*=3;
    cout<<(A+P)/2<<endl;
}


Measured memory_bytes: 256
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8");
const rows = input.trim().split("\n");

const N = Number(rows[0].trim());
const An = rows[1].trim().split(" ").map(Number);

const mapL = {};
const mapR = {};
for (let i = 0; i < N; i++) {
  const Ai = An[i];
  const L = i + 1 + Ai;
  mapL[L] = mapL[L] || 0;
  mapL[L]++;
  const R = i + 1 - Ai;
  mapR[R] = mapR[R] || 0;
  mapR[R]++;
}

let result = 0;
Object.keys(mapL).forEach((key) => {
  const L = mapL[key];
  const R = mapR[key] || 0;
  result += L * R;
});
console.log(result);


Measured memory_bytes: 106928
#include<stdio.h>
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int lb(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<=d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
int ub(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?ub(l,m,n,d):ub(m+1,r,n,d);
}
int main(){
  long long n,i,j,d[200010],ans=0,a,b,f[200010]={};
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    hin(a);
  }
  for(i=0;i<n;i++)d[i]=N[hout()];
  for(i=0;i<n;i++)f[i]=ub(0,n,d[i],d)-lb(0,n,d[i],d);
  for(i=n;i--;){
    b=lb(0,n,d[i],d);
    if(f[b]==0)continue;
    f[b]--;
    //printf("%d:",d[i]);
    for(j=0;j<32;j++){
      a=lb(0,n,(1LL<<(31-j))-d[b],d);
      //printf("%d ",a);
      if(a<n&&f[a]&&d[b]+d[a]==(1LL<<(31-j))){
	ans++;
	f[a]--;
	break;
      }
    }//printf("\n");
  }
  printf("%lld\n",ans);
  return 0;
}
    


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::vector;
using std::pair;
using std::cin;
using std::cout;
typedef long long LONG;
typedef int INT;
const INT N = 100100;
char c[ N ];
INT n, ans[ N ];
void Print( )
{
 For( i, 1, n )
  cout << ( ans[ i ] ? 'W' : 'S' );
 return;
}
void INIT( )
{
 For( i, 3, n )
  ans[ i ] = ans[ i - 2 ] ^ ans[ i - 1 ] ^ ( c[ i - 1 ] != 'o' );
 return;
}
bool check( )
{
 bool flag = 0;
 For( i, 1, n )
 {
  int l = ( i - 1 == 0 ) ? n : i - 1, r = ( i + 1 > n ? 1 : i + 1 );
  flag |= ( ans[ l ] ^ ans[ r ] != ( c[ i ] != 'o' ^ ans[ i ] ) );
 }
 return !flag;
}
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n;
 cin >> c + 1;
 For( i, 0, 1 ) For( j, 0, 1 )
 {
  ans[ 1 ] = i, ans[ 2 ] = j;
  INIT( );
  if( check( ) )
  {
   Print( );
   return 0;
  }
 }
 cout << "-1";
 return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  rep(i, N) cin >> W[i];
  vector<int> S(N);
  S[0] = W[0];
  for (int i = 1; i < N; i++) {
    S[i] = S[i - 1] + W[i];
  }
  int ans = 100 * 100 + 1;
  rep(i, N) {
    int S1 = S[i];
    int S2 = S[N - 1] - S[i];
    ans = min(ans, abs(S2 - S1));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;

int main(){
    map<char,bool> keymap; //ツ右ツづ可淞つキツづ「ツづつつセツつッtrueツづ可つキツづゥboolツ連ツ想ツ配ツ療ア
    for(char i='a'; i<='z'; i++){
        keymap[i] = false;
    }

    keymap['y'] = true;
    keymap['h'] = true;
    keymap['n'] = true;
    keymap['u'] = true;
    keymap['j'] = true;
    keymap['m'] = true;
    keymap['i'] = true;
    keymap['k'] = true;
    keymap['o'] = true;
    keymap['l'] = true;
    keymap['p'] = true;

    string str;

    while(cin >> str){
        if(str == "#") break;
        bool pre = keymap[str.at(0)];
        int cnt = 0;
        for(int i=1; i<str.size(); i++){
            if(pre xor keymap[str.at(i)]){
                cnt++;
            }
            pre = keymap[str.at(i)];
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3


def count1(n):
    return bin(n).count("1")


def tobin(ns):
    rv = 0
    for n in ns:
        rv += 1 << (n-1)
    return rv


def solv(n, m, ss, z1s):
    ss = list(map(tobin, ss))
    ans = 0
    for on in range(2**n):
        # print('on=', on)
        ok = 1
        for i in range(m):
            # print('ss[i], on, z1s', ss[i], on, z1s[i])
            if count1(ss[i] & on) % 2 != z1s[i]:
                ok = 0
                break
        ans += ok
    return ans


if __name__ == '__main__':

    n, m = map(int, input().split())

    ss = []
    for _ in range(m):
        s = list(map(int, input().split()))
        s = s[1:]
        ss.append(s)

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

    ans = solv(n, m, ss, z1s)
    print(ans)


Measured memory_bytes: 3064