akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false

const int SZE = 50;

array<array<int,SZE>,SZE> operator*(array<array<int,SZE>,SZE> X,array<array<int,SZE>,SZE> Y){
    array<array<int,SZE>,SZE> R;
    for(int i=0;i<SZE;i++){
        for(int j=0;j<SZE;j++){
            R[i][j]=0;
        }
    }
    for(int i=0;i<SZE;i++){
        for(int j=0;j<SZE;j++){
            for(int k=0;k<SZE;k++){
                R[i][j]+=X[i][k]*Y[k][j];
                R[i][j]%=MOD;
            }
        }
    }
    return R;
}

//累乗(繰り返し二乗法)
array<array<int,SZE>,SZE> power(array<array<int,SZE>,SZE> b,long long e){
  array<array<int,SZE>,SZE> r;
    for(int i=0;i<SZE;i++){
        for(int j=0;j<SZE;j++){
            r[i][j]=0;
        }
        r[i][i]=1;
    }
  while(e){
      if(e&1){
          r=(r*b);
      }
      b=(b*b);
      e >>=1;
  }
  return r;
}

signed main(void){
    int N,K,a;
    array<array<int,SZE>,SZE> A,R;
    cin >> N >> K;
    REP(i,SZE){
        REP(j,SZE){
            A[i][j]=0;
        }
    }
    REP(i,N){
        REP(j,N){
            cin >> a;
            A[i][j]=a;
        }
    }
    R = power(A,K);
    
    #if debug
    REP(i,N){
        REP(j,N){
            cout << R[i][j] << " ";
        }cout << endl;
    }
    #endif
    
    int Ans=0;
    REP(i,N){
        REP(j,N){
            Ans+=R[i][j];
            Ans%=MOD;
        }
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

int n;
int h[100010];
int f[100010];	//i点时的最小消耗 

int main()
{
	scanf("%d", &n);
	
	
	for (int i = 1 ; i <= n ; i++)
		scanf("%d", &(h[i]));
		
	f[0] = 0;
	f[1] = 0;
	for (int i = 2 ; i <= n ; i++)
	{
		f[i] = -1;
		
		int j;
		j = i - 2;
		if (j >= 1)
		{
			f[i] = f[j] + abs(h[j] - h[i]);
		}
		
		j = i - 1;
		int newF = f[j] + abs(h[j] - h[i]);
		if (j >= 1 && (f[i] == -1 || f[i] >= newF))
			f[i] = newF;
	}
	
	printf("%d\n", f[n]);
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    cout<<1110-n<<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int gcd = 1;
  for(int i = 2; i <= min(a,b); ++i) {
    while(a%i == 0 && b%i == 0) {
      a /= i;
      b /= i;
      gcd *= i;
    }
  }
  cout << gcd << endl;
  return 0;
}

Measured memory_bytes: 1160
F=lambda:tuple(int(X)for X in input().split());H,W,N=F();S={F()for _ in[0]*N};T=set();Z=[0]*10
for Y,X in S:
	for A in range(9):
		P=A,B=X-A%3,Y-A//3
		if(0<A<W-1)*(0<B<H-1)*(P not in T):T.add(P);Z[sum((B+C//3,A+C%3)in S for C in range(9))]+=1
Z[0]+=(H-2)*(W-2)-sum(Z);print(*Z,sep='\n')

Measured memory_bytes: 128484
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<double,double> P;
signed main(){
  int n,l;
  scanf("%lld %lld",&n,&l);
  int t[n],v[n];
  for(int i=0;i<n;i++) scanf("%lld %lld",t+i,v+i);
  deque<P> c;
  double sum=0,amo=0;
  for(int i=0;i<n;i++){
    sum+=t[i]*v[i];
    amo+=v[i];
    while(c.size()>=2){
      P p1=c.back();c.pop_back();
      P p2=c.back();c.pop_back();
      //cout<<p1.first<<" "<<p2.first<<endl;
      if(p2.first>=p1.first){
	c.push_back(P((p1.first*p1.second+p2.first*p2.second)/(p1.second+p2.second),p1.second+p2.second));
      }else{
	c.push_back(p2);
	c.push_back(p1);
	break;
      }
    }
    c.push_back(P(t[i],v[i]));
    //cout<<sum<<endl;
    while(amo>l){
      if(amo-c.front().second>=l){
	amo-=c.front().second;
	sum-=c.front().first*c.front().second;
	c.pop_front();
      }else{
	P p=c.front();
	c.pop_front();
	//cout<<l<<"-"<<amo<<endl;
	p.second-=(amo-l);
	sum-=(amo-l)*p.first;
	c.push_front(p);
	amo=l;
      }
    }
    //cout<<sum<<" "<<amo<<endl;
    cout<<fixed<<setprecision(12)<<sum/l<<endl;
  }
  return 0;
}


Measured memory_bytes: 27536
#include <iostream>
using namespace std;
int main(){
    int a,b,c; cin >> a >> b >> c;
    int flag=0;
    for (int i=1; i<=b; i++){
        if (i*a%b==c) {flag=1; break;}
    }
    cout << (flag ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

a = input()
b = input()
c = input()
i = j = k = -1
sel = 'a'

while i<len(a) and j<len(b) and k<len(c):
        if sel == 'a':
                i += 1
                if i < len(a):
                        sel = a[i]
        elif sel == 'b':
                j += 1
                if j < len(b):
                        sel = b[j]
        elif sel == 'c':
                k += 1
                if k < len(c):
                        sel = c[k]

if i == len(a):
        print('A')
elif j == len(b):
        print('B')
elif k == len(c):
        print('C')

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

using namespace std;

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



Measured memory_bytes: 3224
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
if N == 1:
    count = 0
else:
    fact = factorization(N)
    count = 0

    for i in range(len(fact)):
        count += math.floor((-1+(1+8*fact[i][1])**0.5)/2)
print(count)




Measured memory_bytes: 9200
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())


/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 201000;
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;
}

int main(){
  COMinit();
  ll n; cin >> n;
  string s; cin >> s;
  ll ans = 1;
  //s[i]が白なら1, 黒なら0
  vector<ll> color(2*n,0);
  REP(i,2*n){
    if(s[i]=='W') color[i] = 1;
    //前処理
    if(i%2==0) color[i] = !color[i];
  }

  ll white = 0;
  REP(i,2*n){
    white += color[i];
    if(color[i]==0){
      (ans *= white) %= MOD;
      white--;
    }
  }
  if(white != 0){
    cout << 0 << endl;
    return 0;
  }
  (ans *= fac[n]) %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 6788
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

int main() {
    ll N;
    cin >> N;
    ll A[N];
    REP(i, 0, N) {
        cin >> A[i];
    }
    ll ans = A[0];
    REP(i, 0, N) {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
}


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

int main() {
  string a;
  cin>>a;
  
  if(a.at(0)!=a.at(1)&&a.at(1)!=a.at(2)&&a.at(2)!=a.at(3)){
    cout<<"Good"<<endl;
  }
  else{
    cout<<"Bad"<<endl;
  }
}

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

using namespace std;
typedef long long ll;

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

  cin >> a >> b >> c;

  ll d = c - a -b;
  if(d>0&&d*d>4*a*b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

void solve() {

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll op1 = a*c;
    ll op2 = a*d;
    ll op3 = b*c;
    ll op4 = b*d;

    ll ans = max({op1,op2,op3,op4});
    cout << ans << endl;


}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int m,f,r;
        cin >> m >> f >> r;
        if(m==-1&&f==-1&&r==-1)break;
        else if(m==-1||f==-1) cout << 'F' << endl;
        else if(m+f>=80)cout << 'A' << endl;
        else if(m+f>=65)cout << 'B' << endl;
        else if(m+f>=50)cout << 'C' << endl;
        else if(m+f>=30){
            if(r>=50)cout << 'C' << endl;
            else cout << 'D' << endl;
        }
        else cout << 'F' << endl;
    }
}


Measured memory_bytes: 3080
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    static readonly int Mod = (int)1e9 + 7;
    static void Add(ref long a, long b) { if ((a += b) >= Mod) a -= Mod; }


    public void Solve()
    {
        int N = Reader.Int(), C = Reader.Int();
        var A = Reader.IntArray(N);
        var B = Reader.IntArray(N);

        int Bmax = B.Max();
        var powSum = new long[Bmax + 1, C + 1];
        for (int x = 1; x <= Bmax; x++)
            for (long n = 0, p = 1; n <= C; n++, p = p * x % Mod)
                powSum[x, n] = (powSum[x - 1, n] + p) % Mod;

        var dp = new long[C + 1];
        dp[0] = 1;
        for (int i = 0; i < N; i++)
        {
            var nextdp = new long[C + 1];
            for (int sum = 0; sum <= C; sum++)
                if (dp[sum] > 0)
                    for (int add = 0; sum + add <= C; add++)
                    {
                        long v = Mod + powSum[B[i], add] - powSum[A[i] - 1, add];
                        Add(ref nextdp[sum + add], v % Mod * dp[sum] % Mod);
                    }
            dp = nextdp;
        }

        Console.WriteLine(dp[C] % Mod);
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 5336
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int h, w;
char maze[21][21];
int dist[21][21];

void init(int sy, int sx) {
        for(int i = 0; i < 21; i++) {
                for(int j = 0; j < 21; j++) {
                        dist[i][j] = -1;
                }
        }
        dist[sy][sx] = 0;
}

int bfs(int sy, int sx, int gy, int gx) {
        queue<pair<int, int>> q;
        q.push(make_pair(sy, sx));
        while(!q.empty()) {
                int y = q.front().first;
                int x = q.front().second;
                q.pop();
                int dy[] = {0, 1, -1, 0};
                int dx[] = {1, 0, 0, -1};
                for(int i = 0; i < 4; i++) {
                        int ny = y + dy[i];
                        int nx = x + dx[i];
                        if(ny < 0 || h <= ny || nx < 0 || w <= nx || maze[ny][nx] == '#' || dist[ny][nx] != -1) continue;
                        dist[ny][nx] = dist[y][x] + 1;
                        q.push(make_pair(ny, nx));
                }
        }
        return dist[gy][gx];
}

int main() {
        cin >> h >> w;
        for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                        cin >> maze[i][j];
                }
        }

        int ans = 0;
        for(int sy = 0; sy < h; sy++) {
                for(int sx = 0; sx < w; sx++) {
                        for(int gy = 0; gy < h; gy++) {
                                for(int gx = 0; gx < w; gx++) {
                                        if(maze[sy][sx] == '#' || maze[gy][gx] == '#') continue;
                                        init(sy, sx);
                                        int dist = bfs(sy, sx, gy, gx);
                                        ans = max(ans, dist);
                                }
                        }
                }
        }

        cout << ans << endl;

        return 0;
}

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

const int INF = 1001001001;

int two(int n){
	int res = 0;
	while(n % 2 == 0){
		n /= 2;
		res++;
	}
	return res;
}

int main(){
	int n;
	cin >> n;
	int ans = INF;
	rep(i,n){
		int a;
		cin >> a;
		ans = min(ans, two(a));
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll dp[110][100001];

int main(){
	int n, wmax;
	cin >> n >> wmax;
	vector<ll> w(n);
	vector<ll> v(n);
	for( int i = 0; i < n; ++i ) cin >> w[i] >> v[i];
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j <= wmax; ++j ){
			dp[i+1][j] = dp[i][j];
			if( j >= w[i] ){
				dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]] + v[i] );
			}
		}
	}
	cout << dp[n][wmax] << endl;
	return 0;
}

Measured memory_bytes: 79360
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
if len(s) == 2:
    print(s)
else:
    print(s[::-1])

Measured memory_bytes: 3436
H, W = gets.split.map(&:to_i)
S = readlines.map(&:chomp)

m = ['#' * (W + 2)] + S.map{|l| ("#" + l + "#")} + ['#' * (W + 2)]
q = [[1, 1]]
d = Array.new(H + 1){Array.new(W + 1, 0)}
d[1][1] = 1
while !q.empty?
  i0, j0 = q.shift
  [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |di, dj|
    i, j = i0 + di, j0 + dj
    next if m[i][j] != '.' || d[i][j] > 0
    d[i][j] = d[i0][j0] + 1
    (puts S.inject(0){|s, l| s + l.count('.')} - d[H][W]; exit) if [i, j] == [H, W]
    q << [i, j]
  end
end
puts -1

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define debug(x) cout << '>' << #x << ':' << x << endl
using namespace std;
using ll = long long;

void solve() {
    float r;
    cin >> r;
    cout << fixed << 2*3.1415*r << '\n';
    
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T;
    T = 1;
    // cin >> T;
    for (int t = 1; t <= T; t++){
        // cout << "Case #" << t << ": ";
        solve();
    }
	return 0;
}


Measured memory_bytes: 3800
#[allow(unused_macros)]
macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

fn main() {
    parse_line![
        hour_hand_len: f64,
        minute_hand_len: f64,
        hour: f64,
        minute: f64
    ];

    let hour_hand_rotation = hour / 12.0 + minute / (12.0 * 60.0);
    let minute_hand_rotation = minute / 60.0;
    let rotation_diff = {
        let mut temp = hour_hand_rotation - minute_hand_rotation;

        while temp > 1.0 {
            temp -= 1.0;
        }
        while temp < 0.0 {
            temp += 1.0;
        }

        temp
    };

    let diff_radian = rotation_diff * std::f64::consts::PI * 2.0;

    let distance = (hour_hand_len * hour_hand_len + minute_hand_len * minute_hand_len
        - 2.0 * hour_hand_len * minute_hand_len * diff_radian.cos())
    .sqrt();

    println!("{}", distance);
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include <string>
const int mxN=2e5;
const int maxN=5e3;
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>

int main()
{
    char c;
    cin >> c;
    if(tolower(c)!=c)
        cout << "A";
    else
        cout << "a";
}

Measured memory_bytes: 3556
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	int n = s.size();
	ll k; cin >> k;
	ll l = 1, r = 1;
	int i = 0;
	while (i < n - 1 && s[i] == s[i + 1])
	{
		++l;
		++i;
	}
	i = n - 1;
	while (i > 0 && s[i] == s[i - 1])
	{
		++r;
		--i;
	}
	if (l == n)
	{
		cout << (l*k) / 2 << endl;
		return 0;
	}
	string t = s.substr(l, n - l - r);
	int tLen = t.size();
	ll m = 1;
	ll res = 0;
	rep(i, tLen - 1)
	{
		if (t[i] == t[i + 1])++m;
		else
		{
			res += m / 2;
			m = 1;
		}
	}
	res += m / 2;
	res *= k;
	if(s[0]==s.back())res += (l / 2) + (r / 2) + ((l + r)/2*(k - 1));
	else res += (l / 2 + r / 2)*k;
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;

int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for (int i=a;i<=b;++i){
		if (i%k==0){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
#define MAX 10000003
int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes"<<e;
    else
        cout<<"No"<<e;

}


Measured memory_bytes: 256
from fractions import gcd
 
def factorization(n):
    arr = []
    temp = n
    for i in range(2,int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i,cnt])
    if temp != 1:
        arr.append([temp,1])
    if arr == []:
        arr.append([n,1])
    return arr
 
a,b = map(int,input().split())
 
x = gcd(a,b)
 
ans = len(factorization(x))+1
if factorization(x) == [[1,1]]:
  ans -= 1
print(ans)

Measured memory_bytes: 5820
#include<bits/stdc++.h>
using namespace std;
typedef long long signed int ll;
int n;
ll a[100005],b[100005];
ll sum=0;
vector<pair<ll,ll>> s;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        sum+=b[i];
        s.push_back(make_pair(a[i]+b[i],i));
    }
    sort(s.begin(), s.end());
    /*for(int i=0;i<n;i++){
        cout<<s[i].first<<" "<<s[i].second<<endl;
    }*/
    ll ans=0;
    for(int i=n-1;i>=0;i-=2){
        ll j=s[i].second;
        //cout<<j<<endl;
        //cout<<a[j]<<endl;
        ans+=a[j]+b[j];
    }
    cout<<ans-sum<<endl;
    return 0;
}






Measured memory_bytes: 3444
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 < len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if i + 7 < len(s) and s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 < len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')


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

int main()
{
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  for (int i = 0; i < N; i++)
    cin >> T.at(i);

  sort(T.begin(), T.end());

  int bus = 1;
  int passenger = 0;
  int limit = T.at(0) + K;

  for (int i = 0; i < N; i++){
    if (passenger == C || limit < T.at(i)){
      passenger = 1;
      bus++;
      limit = T.at(i)+ K;
    }
    else if (limit >= T.at(i)) passenger++;
  }
 cout << bus << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define rin(i,n,k) for(int i=0;i<n;i+=k)
#define int long long int
#define ss size()
using namespace std;
const int M=1e9+7,maxn=100010;
std::vector<int> adj[maxn];
std::vector<int> v1;
int ans,n,k,m,x,y,q,par[maxn],h[maxn],mach[maxn],sk[maxn],dp[maxn];
bool mark[maxn],bpart[maxn];
string s,s1,s2;
map <string ,int> mp;
bool markchaild[maxn];
bool dfsmach(int v){
    if(v==-1) return true;
    if(mark[v]==1) return false;
    mark[v]=1;
    for(int i=0;i<adj[v].ss;i++){
        int u=adj[v][i];
        if(dfsmach(mach[u])){
            bpart[u]=((bpart[v]+1)%2);
            mach[u]=v;
            mach[v]=u;
            return true;
        }
    }
    return false;
}


int32_t main() {
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    dp[0]=0;
    dp[1]=fabs(a[0]-a[1]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-2]+fabs(a[i]-a[i-2]),dp[i-1]+fabs(a[i]-a[i-1]));
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int pri[10001];
int ps;
struct A{
	vector<A*> e;
};
using pa=vector<A*>;
A p[8];
signed main(){
	int ans=0,m,n;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		p[u].e.push_back(&p[v]);
		p[v].e.push_back(&p[u]);
	}
	queue<pa> que;
	pa aa;
	aa.push_back(&p[0]);
	que.push(aa);
	while(!que.empty()){
		auto x=que.front();
		que.pop();
		if(x.size()==n){
			ans++;
			continue;
		}
		auto xx=*rbegin(x);
		for(auto y:xx->e){
			auto z=x;
			bool f=true;
			for(auto w:z)
				if(w==y)
					f=false;
			if(f){
				z.push_back(y);
				que.push(z);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    stack<string> st;
    while(cin >> s){
        if(s == "0"){
            cout << st.top() << endl;
            st.pop();
        }else{
            st.push(s);
        }
    }

    return 0;
}


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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
#define PI 3.14159265
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ull sum = 0;
    int n; cin >> n;
    map<ll, ll> m;
    for (int i = 0; i < n; ++i) {
        int num; cin >> num;
        sum += num;
        m[num]++;
    }
    
    int q; cin >> q;
    for (int i = 0; i < q; ++i) {
        int a, b; cin >> a >> b;
        ll cnt = m[a];
        sum -= (cnt * a);
        sum += (cnt * b);
        m.erase(a);
        m[b] += cnt;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 7600
from collections import deque

def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set([]) for _ in range(N)]
    DIST = {}
    for a, b, c in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
        DIST[(a - 1, b - 1)], DIST[(b - 1, a - 1)] = c, c
    return NEAR, DIST


def bfs(NEAR, N):  # 幅優先探索  # キュー
    ANS = [-1 for _ in range(N)]
    ANS[0] = 0
    que, frag = deque([0]), set([0])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            if dist[(q, i)] % 2 == 0:
                ANS[i] = ANS[q]
            elif dist[(q, i)] % 2 == 1:
                ANS[i] = -ANS[q] + 1
            que.append(i), frag.add(i)
    return ANS


n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]

near, dist = nearlist(n, uvw)
ans = bfs(near, n)
print(*ans, sep='\n')


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

int main() {
  int a, b;
  cin >> a >> b;
  if (b >= 100) {
    a *= 1000;
  } else if (b >= 10) {
    a *= 100;
  } else {
    a *= 10;
  }
  a += b;
  b = sqrt(a);
  if (a == b * b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
implicit none
integer,parameter :: favorite = 753
integer :: n,k,m,i
character(10) :: s
read *,s
n = len_trim(s)
m = 999
do i = 1, n-3+1
   read(s(i:i+2),*) k
   k = abs(k - favorite)
   if (k < m) then
      m = k
   endif
enddo
print '(i0)',m
end

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String upperCase = br.readLine();
			char ch = 0;

			for(int i = 0; i < upperCase.length(); i++) {
				ch = upperCase.charAt(i);

				if(ch >= 'A' && ch <= 'Z') {
					ch += 32;
					System.out.printf("%c", (char)ch);
				} else if(ch >= 'a' && ch <= 'z') {
					ch -= 32;
					System.out.printf("%c", (char)ch);
				} else {
					System.out.printf("%c", (char)ch);
				}
			}
			System.out.printf("\n");

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}



Measured memory_bytes: 27936
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		long[] nums = new long[N];
		
		int minIndex = 0;
		int maxIndex = 0;
		
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextLong();
			if (nums[minIndex] > nums[i]) {
				minIndex = i;
			}
			if (nums[maxIndex] < nums[i]) {
				maxIndex = i;
			}
		}
		
		int useIndex = -1;
		boolean isNegative = false;
		
		if (Math.abs(nums[minIndex]) < Math.abs(nums[maxIndex])) {
			useIndex = maxIndex;
		} else {
			useIndex = minIndex;
		}

		if (nums[useIndex] < 0) {
			isNegative = true;
		}
		
		ArrayList<Integer> arr = new ArrayList<Integer>();
		
		if (isNegative) {
			for (int i = N - 1; i >= 1; i--) {
				while (nums[i - 1] > nums[i]) {
					nums[i - 1] += nums[useIndex];
					arr.add(useIndex + 1);
					arr.add(i - 1 + 1);
				}
				if (nums[i - 1] < nums[useIndex]) {
					useIndex = i - 1;
				}
			}
		} else {
			for (int i = 0; i < N - 1; i++) {
				while (nums[i] > nums[i + 1]) {
					nums[i + 1] += nums[useIndex];
					arr.add(useIndex + 1);
					arr.add(i + 1 + 1);
				}
				if (nums[useIndex] < nums[i + 1]) {
					useIndex = i + 1;
				}
			}
		}
		
		System.out.println(arr.size() / 2);
		for (int i = 0; i < arr.size(); i += 2) {
			System.out.printf("%d %d\n", arr.get(i), arr.get(i + 1));
		}
	}
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;int n,m,l,x,i,a[1<<18];main(){cin>>n>>m;n*=2;for(;i<n;i++)cin>>a[i];sort(a,a+n);for(i--;i>l;i--){while(a[i]+a[l]<m&&l<i-1)l++;if(a[i]+a[l]>=m){a[i]-=m;l++;}}sort(a,a+n);for(i=0;i<n/2;i++)x=max(x,a[i]+a[n-i-1]);cout<<x;}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];

  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      for(ll k=j+1;k<n;k++){
        if (a[i]==a[j])continue;
        if (a[j]==a[k])continue;
        if (a[i]==a[k])continue;
        ll mx=max(max(a[i],a[j]),a[k]);
        if ((a[i]+a[j]+a[k]-mx)>mx)ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
  int AN, BN, R;
  while (~scanf("%d %d %d", &AN, &BN, &R)) {
    if ((AN|BN) == 0)
      break;

    vector<vector<int> > A(10000);
    for (int i = 0; i < AN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);
      A[y].push_back(x);
    }

    for (unsigned int i = 0; i < A.size(); ++i)
      sort(A[i].begin(), A[i].end());

    int ans = 0;
    for (int i = 0; i < BN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);
      for (int j = y-4*R; j <= y+4*R; ++j) {
	if (j < 0 || 10000 <= j || A[j].empty())
	  continue;
	int target = (int)sqrt(16.0*R*R - (y-j)*(y-j));
	ans += upper_bound(A[j].begin(), A[j].end(), x+target) - lower_bound(A[j].begin(), A[j].end(), x-target);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

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


int main(void){
    int n,m,i,k=0;
    scanf("%d%d",&n,&m);
    int a[m],p[n];
    /*m段目までの行き方p[m-1]*/
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        p[i] = 0;
    }

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

        if(i==0){
            if(i==a[k]-1){
            k++;
            continue;
            }
            p[i]=1;
            // printf("%d\n",p[i]);
            continue;
        }

        if(i==1){
            if(i==a[k]-1){
            k++;
            continue;
            }
            p[i]=p[i-1]+1;
            //printf("%d\n",p[i]);
            continue;
        }

        if(i==a[k]-1){
            k++;
            continue;
        }

        p[i] = (p[i-1] + p[i-2]) % 1000000007;
        // printf("%d\n",p[i]);

    }
    printf("%d\n",p[n-1]);
    return 0;
}


Measured memory_bytes: 896
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[1000000+2];
int comb(int n, int k){
  if(k < 0 || k > n){
    return 0;
  }
  if(n==0){
    return 1;
  }
  if(n==1){
    return 1;
  }
  return comb(n/2, k/2) * comb(n%2, k%2);
}
int main(){
  int i;
  int m = 0;
  int mul = 1;
  rd(N);
  rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '1';
  }
  for(i=(0);i<(N);i++){
    if(S[i]==1){
      break;
    }
  }
  if(i==N){
    mul = 2;
    for(i=(0);i<(N);i++){
      S[i] /= 2;
    }
  }
  for(i=(0);i<(N);i++){
    m += S[i] * comb(N-1,i);
  }
  wt_L(mul * (m%2));
  wt_L('\n');
  return 0;
}
// cLay varsion 20200321-1

// --- original code ---
// int N;
// char S[1d6+2];
// 
// int comb(int n, int k){
//   if(k < 0 || k > n) return 0;
//   if(n==0) return 1;
//   if(n==1) return 1;
//   return comb(n/2, k/2) * comb(n%2, k%2);
// }
// 
// {
//   int m = 0, mul = 1;
//   rd(N,S);
//   rep(i,N) S[i] -= '1';
// 
//   rep(i,N) if(S[i]==1) break;
//   if(i==N){
//     mul = 2;
//     rep(i,N) S[i] /= 2;
//   }
// 
//   rep(i,N) m += S[i] * comb(N-1,i);
//   wt(mul * (m%2));
// }


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int b,i;
	b=0;
	cin>>a;
	for(i=0;i<4;i++){
		if(a[i]=='+'){
			b=b+1;
		}else{
			b=b-1;
		}
	}
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    int[][] denkyu = new int[M][];
    for (int i = 0; i < M; i++) {
      int k = sc.nextInt();
      denkyu[i] = new int[k];
      for (int j = 0; j < k; j++) {
        denkyu[i][j] = sc.nextInt();
      }
    }
    
    int[] P = new int[M];
    for (int i = 0; i < M; i++) {
      P[i] = sc.nextInt();
    }

    int count = 0;
    int maxBit = 1 << N;
    for (int i = 0; i < maxBit; i++) {
      boolean allOn = true;
      for (int j = 0; j < M; j++) {
        allOn = allOn && isOn(denkyu[j], i, P[j]);
        if (!allOn) {
          break;
        }
      }
      if (allOn) {
        count++;
      }
    }
    
    //System.out.println(Arrays.deepToString(denkyu));
    //System.out.println(Arrays.toString(P));
    System.out.println(count);
  }
  
  private static boolean isOn(int[] switches, int bitPattern, int amari) {

    //System.out.println("### " + Arrays.toString(switches) + ", " + bitPattern + ", " + amari);
    
    int count = 0;
    for (int i = 0; i < switches.length; i++) {
      if (isOn(switches[i], bitPattern)) {
        count++;
      }
    }
    return count % 2 == amari;
  }
  
  private static boolean isOn(int switchNo, int bitPattern) {
    boolean ret = (bitPattern & (1 << (switchNo - 1))) == 1 << (switchNo - 1);
    //System.out.println("#### " + switchNo + ", " + bitPattern + ", ret: " + ret);
    return ret;
  }
}



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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

vi ans;
vi G[200005];
bool used[200005];
map<int, int> m;

void dfs(int u, int cnt) {
    if (used[u]) return;
    used[u] = true;

    int ncnt = cnt + m[u];
    ans[u] = ncnt;

    for (auto& i : G[u]) dfs(i, ncnt);
}

signed main() {
    int N, Q;
    cin >> N >> Q;

    int a, b, p, x;
    ans.resize(N, 0);

    REP(i, N-1) {
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    REP(i, Q) {
        cin >> p >> x;
        m[--p] += x;
    }

    dfs(0, 0);
    REP(i, N) cout << ans[i] << " \n"[i == N-1];

    return 0;
}


Measured memory_bytes: 39296
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
    int a,b,c;
    int count =0;
    cin >> a >> b >> c;
    for(int i = a; i<= b; i++){
        if(c%i==0) count++;
    }
    cout << count << endl;






    return 0;
}


Measured memory_bytes: 3096
s = input()

answer1 = '0'
for i in range(len(s)):
    if i % 2 == 1:
        answer1 += '0'
    else:
        answer1 += '1'

answer2 = '1'
for i in range(len(s)):
    if i % 2 == 1:
        answer2 += '1'
    else:
        answer2 += '0'


wrong1, wrong2 = 0, 0
for i in range(len(s)):
    if s[i] != answer1[i]:
        wrong1 += 1
    if s[i] != answer2[i]:
        wrong2 += 1

print(min([wrong1, wrong2]))

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  while (1) {
    C-=B;
    if (C <= 0) {
      cout << "Yes" <<endl;
      break;
    }
    A-=D;
    if (A <= 0){
      cout << "No" <<endl;
      break;
    }
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  string s;
  
  cin >> a >> s;
  
  if ( a >= 3200 ) {
    cout << s;
  }
  
  if ( a < 3200 ) {
    cout << "red";
  }
  
}


Measured memory_bytes: 384
open Printf
let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf " %d" (fun v -> v))

let get_int () = Scanf.scanf " %d" (fun v -> v)
let get_2_ints () = Scanf.scanf " %d %d" (fun u v -> u,v)
let get_3_ints () = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w)
let get_4_ints () = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x)
let get_5_ints () = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)

module Int64 = struct
	include Int64
	let (+|) p q = Int64.add p q
	let (-|) p q = Int64.sub p q
	let ( *|) p q = Int64.mul p q
	let (/|) p q = Int64.div p q
	let (<|) p q = 
		if Int64.compare p q < 0 then true 
		else false
	let (>|) p q = 
		if Int64.compare p q > 0 then true
		else false
	let (>=|) p q = not (p < q)
	let (<=|) p q = not (p > q)
	let labs p = if p <| 0L then -1L*|p else p
	let (~|) p = Int64.of_int p
end


let dump_2darr f a =
	Array.fold_left (fun u v ->
		u ^ Array.fold_left (fun u v -> u ^ (f v) ^ ",") "" v ^ ";\n"
	) "" a |> print_endline


let () =
	let n,a = get_2_ints ()
	in let ar = input_int_array n
	in let mx = (Array.fold_left max 0 ar)*n
	in let open Bigarray in let open Int64
	in
	let dp = Bigarray.Array3.create int64 c_layout (n+5) (n+5) (mx+1)
	in dp.{0,0,0} <- 1L;
	for i=0 to n-1 do
		for j=0 to n do
			for k=0 to mx do
				dp.{i+1,j,k} <- dp.{i,j,k} +| (
					let v = k-ar.(i) in
					if j>=1 && v>=0 then dp.{i,j-1,v} else 0L
				)
			done
		done
	done;
	let s = ref 0L in
	for k=1 to n do
		if a*k <= mx then
		s := !s +| dp.{n,k,a*k}
	done;
	!s |> printf "%Ld\n"

Measured memory_bytes: 58112
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    vector<int> a(4);
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a.begin(), a.end());
    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <tuple>

int main() {
  int M, D;
  scanf("%d %d", &M, &D);

  int res = 0;
  for (int i = 1; i <= M; ++i) {
    for (int j = 1; j <= D; ++j) {
      int j1 = j / 10;
      int j0 = j % 10;
      if (j1 >= 2 && j0 >= 2 && j1*j0 == i) ++res;
    }
  }

  printf("%d\n", res);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	if(a >= 0){
		return a % p;
	}
	else{
		return p + a % p;
	}
}

int digit_count(int n){
	int ans;
	for(ans = -1; n != 0; ans++){
		n >>= 1;
	}
	return ans;
}

//n????????????????????????0?????????
int remove_highest_one_bit(int n){
	int i = n;
	i |= (i >> 1);
	i |= (i >> 2);
	i |= (i >> 4);
	i |= (i >> 8);
	i |= (i >> 16);
	return n ^ i ^ (i >> 1);
}

//n???????????????1?????°????±???????
int element_count(int n){
	n = (0x55555555 & n) + (0x55555555 & (n >> 1));
	n = (0x33333333 & n) + (0x33333333 & (n >> 2));
	n = (0x0f0f0f0f & n) + (0x0f0f0f0f & (n >> 4));
	n = (0x00ff00ff & n) + (0x00ff00ff & (n >> 8));
	n = (0x0000ffff & n) + (0x0000ffff & (n >> 16));
	return n;
}

signed main(){
	int N, M, K, q, i, j, k;
	scanf("%lld%lld%lld", &N, &M, &K);
	int dK = digit_count(K) + 1;
	int eK = element_count(K) + 1;
//	printf("dK = %lld\n", dK);
	int **a = (int **)malloc(sizeof(int *) * dK);
	int **ans = (int **)malloc(sizeof(int *) * eK);
	for(i = 0; i < dK; i++){
		a[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			a[i][j] = 0;
		}
	}
	for(i = 0; i < eK; i++){
		ans[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			ans[i][j] = 0;
		}
	}
	for(i = 0; i < M; i++){
		scanf("%lld", &q);
		a[0][q % N]++;
	}
	a[0][0]++;
	for(i = 1; i < dK; i++){
		for(j = 0; j < N; j++){
			for(k = 0; k < N; k++){
				a[i][(j + k) % N] = MOD(a[i][(j + k) % N] + a[i - 1][j] * a[i - 1][k]);
			}
		}
	}
/*	for(i = 0; i < dK; i++){
		for(j = 0; j < N; j++){
			printf("%lld  ", a[i][j]);
		}
		printf("\n");
	}
*/	ans[0][0] = 1;
/*	printf("test\n");
	for(i = 0; i < N; i++){
		printf("%lld  ", ans[1][i]);
	}
	printf("\n");
*/	for(i = 1; K > 0; i++, K = remove_highest_one_bit(K)){
//		printf("K = %lld\n", K);
		dK = digit_count(K);
//		printf("dK = %lld\n", dK);
		for(j = 0; j < N; j++){
			for(k = 0; k < N; k++){
				ans[i][(j + k) % N] = MOD(ans[i][(j + k) % N] + ans[i - 1][j] * a[dK][k]);
			}
		}
/*		for(j = 0; j < N; j++){
			printf("%lld  ", ans[i][j]);
			printf("\n");
		}
*/	}
//	printf("i = %lld\n", i);
	for(j = 0; j < N; j++){
		printf("%lld\n", ans[i - 1][j]);
	}
	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    for (size_t i = 0; i < s.size(); i++)
    {
        if (i%2-1)
        {
            cout << s.at(i) ;
        }
        
    }
    cout << endl;
    

    return 0;
}

Measured memory_bytes: 3568