akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)

int q[4000][4000];
int r[2][4000][4000];

struct mixy{
	int m;
	int i;
	int x;
	int y;
	bool operator<(const mixy& rhs)const{
		return m>rhs.m;
	}
} s[8000];
int size;

struct BIT{
	int data[4000];
	int s;
	void Init(int size){
		s=size;
		REP(i,s)
			data[i]=0;
	}
	void Add(int i,int v){
		while(i<s){
			data[i]+=v;
			i+=(i+1)&(-i-1);
		}
	}
	int Get(int i){
		i=min(i,s-1);
		int ret=0;
		while(i>=0){
			ret += data[i];
			i-=(i+1)&(-i-1);
		}
		return ret;
	}
	int Range(int b,int e){
		if(e<=b)
			return 0;
		return Get(e-1)-Get(b-1);
	}
} bit1,bit2;

int h,w,l,p;
	
int Solve(){
	bit1.Init(size);
	bit2.Init(size);
	sort(s,s+size*2);
	int ret=0;
	//printf("\n");
	REP(i,size*2){
		int t=min(s[i].x,s[i].y);
	//	printf("%d %d %d %d %d %d\n",ret,t,s[i].m,s[i].i,s[i].x,s[i].y);
		if(s[i].i==0){
			ret += bit2.Range(t+l-1,t+r[0][s[i].y][s[i].x]);
			bit1.Add(t,1);
		}else{
			ret += bit1.Range(t-r[1][s[i].y][s[i].x]+1,t-l+1+1);
			bit2.Add(t,1);
		}
	}
	//printf("%d\n",ret);
	return ret;
}

int main(){
	scanf("%d%d%d%d",&h,&w,&l,&p);
	memset(q,0,sizeof(q));
	REP(i,p){
		int x,y;
		scanf("%d%d",&y,&x);
		q[--y][--x]=1;
	}
	REP(i,h){
		int last=w;
		for(int j=w-1;j>=0;j--){
			if(q[i][j])
				last=j;
			r[0][i][j]=last-j;
		}
	}
	REP(j,w){
		int last=h;
		for(int i=h-1;i>=0;i--){
			if(q[i][j])
				last=i;
			r[0][i][j]=min(r[0][i][j],last-i);
		}
	}
	REP(i,h){
		int last=-1;
		REP(j,w){
			if(q[i][j])
				last=j;
			r[1][i][j]=j-last;
		}
	}
	REP(j,w){
		int last=-1;
		REP(i,h){
			if(q[i][j])
				last=i;
			r[1][i][j]=min(r[1][i][j],i-last);
		}
	}
	long long ans = 0;
	REP(i,h+w-1){
		size=0;
		int x=0,y=0;
		if(i<h)
			y=i;
		else
			x=i-h+1;
		while(x<w&&y<h){
			s[size*2] = {r[0][y][x],0,x,y};
			s[size*2+1] = {r[1][y][x],1,x,y};
			size++;
			x++;
			y++;
		}
		ans += Solve();
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 190460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll N; cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(a[0]==0){
        cout << 0 << endl;
        return;
    }
    ll M = 1e18;
    ll ans = 1;
    for(int i = 0; i < N; ++i){
        ll prev = ans;
        prev *= a[i];
        if(ans > prev){
            cout << -1 << endl;
            return;
        }
        ans = prev;
    }
    if(ans > M || ans < 0){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int X;
    cin >> X;
    int gohyaku,goen;
    gohyaku = X/500;
    goen = (X-500*gohyaku)/5;
    cout << gohyaku*1000+goen*5;
}


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

double root(double x){
	double e = 0.000000001;
	double a = x;
	double b = 0;
	double c;
	if(x >= 1){
		while(a - b > e){
			c = (a + b) / 2;
			if(c * c < x){
				b = c;
			}else{		
				a = c;
			}
		}
		return a;
	}else{
		a = 1;
		b = x;
		while(a - b > e){
			c = (a + b) / 2;
			if(c * c < x){
				b = c;
			}else{
				a = c;
			}
		}
		return a;
	}
}

struct point{
	double x;
	double y;
};

double get_a(point p0, point p1, point p2){
	double dx1 = p1.x - p0.x, dy1 = p1.y - p0.y;
	double dx2 = p2.x - p0.x, dy2 = p2.y - p0.y;
	double dx12 = p2.x - p1.x, dy12 = p2.y - p1.y;
	double a = root(dx1 * dx1 + dy1 * dy1);
	double b = root(dx2 * dx2 + dy2 * dy2);
	double c = root(dx12 * dx12 + dy12 * dy12);
	double z = (a + b + c) / 2;
	double s = root(z * (z - a) * (z - b) * (z - c));
	return s;
}

int main(){
	double area = 0;
	int count = 0;
	point ps[20];
	point p;
	char c;
	while(cin >> p.x >> c >> p.y){
		ps[count++] = p;
	}
	for(int i = 1; i < count - 1; i++){
		area += get_a(ps[0], ps[i], ps[i+1]);
	}
	cout << showpoint << setprecision(15) << area << endl;
	return 0;
}

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<i32,i32>
#define ti  triple<i32,i32,i32>
#define mk  make_pair
#define vi  vector<i32>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

bool isPrime(i64 x){
	
	for(i64 i=2;i*i<=x;i++)
		if(x%i==0)
			return false;
	return true;
}

vi V;
const i32 N=7e7+9;
bool prime[N]; 
void SieveOfEratosthenes(){ 
    for (int  p=2; p*p<=N; p++){ 
        if (prime[p] == false){ 
            for (int  i=p*p; i<=N; i += p) 
                prime[i] = true; 
        } 
    } 
    int u=0,mx=0;
    for (int p=2; p<=N; p++){ 
      if (!prime[p]) {
          V.push_back(p);
      }
    }
   
}

i64 c,k,n;
int main(){
    fastInOut
    cin>>c;
    i64 count=0;
    i64 i=1;
    while(c!=0){
       if(c==1){
          count+=i;
          break;
       }
       else{
        c/=2;
        count+=i;
        i=i*2;
       } 
    } 
    cout<<count;
    return 0;
}








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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  IN(N,M);
  ll A_total = 0;
  REP(i,M){
    ll A;
    IN(A);
    A_total += A;
  }

  if(N>=A_total){
    OUT(N-A_total);
  }else{
    OUT(-1);
  }

  return 0;
}


Measured memory_bytes: 3640
# coding: utf-8
lst = list(map(int, input().split()))
# print(lst)
# A ⇄ B : P
# B ⇄ C : Q
# C ⇄ A : R

lst2 = sorted(lst)
# print(lst2)

D = lst2[0] + lst2[1]
print(D)

Measured memory_bytes: 2940
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0
mae = -10

for i in range(N):
    point += B[A[i] - 1]
    if A[i] == mae + 1:
        point+=C[mae - 1]
    mae = A[i]
print(point)

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

int main() {
    int A, B, C; cin >> A >> B >> C;
    int cnt=0;
    
    
    while (A%2==0 && B%2==0 && C%2==0)
    {
        if(A==B && C==B && A==C)
        {
             cnt=-1;
             break;
        }
            
        cnt++;
        int a=A/2, b=B/2, c=C/2;
        A= b + c; B=a + c; C=a + b;
    }
    cout << cnt << endl;
    
    return 0;
}



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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, p; ll f[kN][2];

int main() {
	int T = 1; //rd(T);
	while(T--) {
		rd(n, p);
		f[0][0] = 1;
		for(int i = 1; i <= n; ++i) {
			int x; rd(x);
			x &= 1;
			for(int j = 0; j < 2; ++j)
				f[i][j] += f[i - 1][j ^ x];
			for(int j = 0; j < 2; ++j)
				f[i][j] += f[i - 1][j];
		}
		printf("%lld\n", f[n][p]);
	} return 0;
}

Measured memory_bytes: 3752
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)
a0=[]
b0=[]
for i in range(n):
    if i%2==0:
        a0.append(a[i])
        b0.append(b[i])
print(len(a0)-len(list(set(a0) & set(b0))))

Measured memory_bytes: 15692
import sys
# sys.setrecursionlimit(100000)
import bisect


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    L = sorted(input_int_list())
    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            idx = bisect.bisect_left(L, L[i] + L[j])
            ans += idx - j - 1
    print(ans)
    return


if __name__ == "__main__":
    main()


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

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

  for (int i = A; i <= B; i++) {
    int X1 = i % 10;
    int X2 = (i / 10) % 10;
    int X4 = (i / 1000) % 10;
    int X5 = (i / 10000) % 10;
    if (X1 == X5 && X2 == X4) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
// B - Shiritori
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<string> W(N);
	rpz(now, N){
		cin>>W[now];
		rpz(pre, now){
			if(W[now] == W[pre]){
				puts("No");
				return 0;
			}
		}
	}
	rpz(now, N-1){
		string nowW = W[now], nextW = W[now+1];
		if(nowW[nowW.size()-1] != nextW[0]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

d1 = dice(list(map(int,input().split())))
d2 = dice(list(map(int,input().split())))

ans = "No"
for op in "EEENEEENEEESEEESEEENEEEN":
    if d1.pip == d2.pip:
        ans = "Yes"
        break
    d2.move(op)

print(ans)

Measured memory_bytes: 7816
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size(),a=-1,z;
    rep(i,n){
        if(s[i]=='A'&&a==-1) a=i;
        if(s[i]=='Z') z=i;
    }
    cout<<z-a+1;
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int p = sc.nextInt();
    int t = 3 * a + p;
    int ans = t / 2;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
function Main(input) {
  input = input.trim().split(" ").map(e => parseInt(e, 10));
  var A = input[0];
  var B = input[1];
  var i = 2;
  var tmpLimit = Math.sqrt(Math.min(A,B));
  var NGList = Array.from({length: tmpLimit}, () => 0);
  var v_ans = [];
  var tmp;
  whole_loop:
  while(true){
    division_loop:
    for (i = i; i <= tmpLimit; i++){
      if (NGList[i - 1] === 1) continue division_loop;
      if ( A % i === 0){
        if (B % i === 0){
          A /= i;
          B /= i;
          if (i !== v_ans[v_ans.length - 1]) v_ans.push(i);
          break division_loop;
        } else {
          A /= i;
          break division_loop;
        }
      } else {
        if (B % i === 0){
          B /= i;
          break division_loop;
        } else {
          tmp = tmpLimit / i;
          for (var j = 1; j <= tmp; j++){
            NGList[i * j - 1] = 1;
          }
          continue division_loop;
        }
      }
    }
    tmpLimit = Math.sqrt(Math.min(A,B));
    NGList.length = Math.floor(tmpLimit);
    if (i > tmpLimit) {
      if (Math.max(A, B) % Math.min(A, B) === 0){
        for (var j = 0; j < v_ans.length; j++){
          if (Math.min(A, B) % v_ans[j] === 0) break whole_loop;
        }
        v_ans.push(Math.min(A, B));
      }
      break whole_loop; 
    }
  }
  if (v_ans[v_ans.length - 1] !== 1) v_ans.push(1);
  console.log(v_ans.length);
}   

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 39788
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
int main(){
  int N, S;
  cin >> N >> S;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> dp(S + 1, 0);
  long long total = 0;
  for (int i = 0; i < N; i++){
    for (int j = S; j > A[i]; j--){
      dp[j] = (dp[j] + dp[j - A[i]]) % MOD;
    }
    if (A[i] <= S){
      dp[A[i]] = (dp[A[i]] + dp[0] + i + 1) % MOD;
    }
    total += dp[S] * (N - i) % MOD;
    dp[S] = 0;
  }
  cout << total % MOD;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	S := nextString()
	var red, blue int
	for _, s := range S {
		if s == '0' {
			red++
			continue
		}

		blue++
	}

	fmt.Println(min(red, blue) * 2)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,a[101],j;
    long long s;
    while(scanf("%d",&n)!=EOF){
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                if(a[j]<a[i]){
                    s=a[j];
                    a[j]=a[i];
                    a[i]=s;
                }
            }
        }
        s=0;
        for(i=0,j=n;i<n;i++,j--){
            s+=j*a[i];
        }
        printf("%lld\n",s);

    }
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

LL n, x;

LL calc(LL a, LL b){
	if(b == 0) return -a;
	LL t = 2 * b * (a / b);
	return t + calc(b, a % b);
}

int main(){
	scanf("%lld %lld", &n, &x);
	printf("%lld\n", n + calc(x, n - x));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0 ; i < n ; i++) {
            while (a[i] % 2 == 0) {
                sum++;
                a[i] /= 2;
            }
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 36204
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let a: Vec<usize> = (0..n).into_iter().map(|_| read::<usize>() - 1).collect();
    let mut acc: Vec<usize> = (0..n).into_iter().map(|_| 0).collect();
    for b in &a {
        acc[*b] += 1;
    }

    let sum = (&acc).into_iter().fold(0, |s, &i| if i == 0 { s } else { s + i * (i - 1) / 2 });
    for b in &a {
        if acc[*b] == 1 {
            println!("{}", sum);
        } else {
            println!("{}", sum + (acc[*b] - 1) * (acc[*b] - 2) / 2 - acc[*b] * (acc[*b] - 1) / 2);
        }
    }
}

// n (n - 1) - (n - 1) (n - 2) = 2 (n - 1)


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

int main() {
  string curr_str;
  cin >> curr_str;
  if (curr_str[2] == curr_str[3] && curr_str[4] == curr_str[5]) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())

now_t = now_x = now_y = 0

can = True
for i in range(N):
    t, x, y = map(int, input().split())
    time = t - now_t
    dist = abs(now_x - x) + abs(now_y - y)
    if dist > time:
        can = False
    if not dist % 2 == time % 2:
        can = False
    now_t = t
    now_x = x
    now_y = y

if can:
    print('Yes')
else:
    print('No')


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int ans = 100000000;
  int cnt;
  rep(i, n){
    cnt = 0;
    while(a[i] % 2 == 0){
      a[i] /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
    // Your code here!
    while(true){
    int x,y;
    cin>>x>>y;
    if (x==0&&y==0){
        break;
    }
    if (x>y){
        cout<<y<<" "<<x<<endl;
    }
    else {
        cout<<x<<" "<<y<<endl;
    }
}
}


Measured memory_bytes: 3084
#include <iostream>

int main(){
  int a,b,c;
  std::cin >> a >> b >> c;
  
  if(a==7 && b==5 && c==5){
    std::cout << "YES" << std::endl;
    return 0;
  }
  if(a==5 && b==7 && c==5){
    std::cout << "YES" << std::endl;
    return 0;
  }
  if(a==5 && b==5 && c==7){
    std::cout << "YES" << std::endl;
    return 0;
  }
  
  std::cout << "NO" << std::endl;
  
  return 0;
}


Measured memory_bytes: 3560
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  lint n;
  cin >> n;
  set<string> st;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    st.insert(tmp);
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 19256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    if(s=="keyence"){
        Cout("YES");
    }
    else{
    rep(i,Size(s)){
        rrep(j,i,Size(s)){
            string co="";
            rep(k,Size(s)){
                if(i<=k&&k<=j)continue;
                co+=s[k];
            }
            if(co=="keyence"){
                Cout("YES");
                return 0;
            }
        }
    }
    Cout("NO");
    }
    return 0;
}


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

// ------------------------

void solve() {
    string S; cin >> S;
    ll Q; cin >> Q;
    string front = "";
    string back = "";
    ll rev_cnt = 0L;
    for (ll i = 0L; i < Q; ++i){
        int T;
        cin >> T;
        if(T == 1){
            ++rev_cnt;
            continue;
        }
        if(T == 2){
            int F;
            string C;
            cin >> F >> C;
            if(rev_cnt % 2 == 0){
                if(F == 1) front += C;
                if(F == 2) back += C;
            }else{
                if(F == 1) back += C;
                if(F == 2) front += C;
            }
        }
    }

    if(rev_cnt % 2 == 0){
        reverse(front.begin(), front.end());
        cout << front + S + back << "\n";
    }else{
        reverse(S.begin(), S.end());
        reverse(back.begin(), back.end());
        cout << back + S + front << "\n";
    }

    // 
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 1300
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }


	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one

	struct Food {
		int need;
		int point;
	};
}

int main() {

	int n, t;
	cin >> n >> t;
	vector<Food> food(n);
	rep(i, n) cin >> food[i].need >> food[i].point;

	// ナップザック系のDP
	// dp[i][j] := i番目までの商品を見たときに時間がjの時のポイントの最大値
	vector<vector<int>> dp1(n + 1, vector<int>(t + 1, 0));
	vector<vector<int>> dp2(n + 1, vector<int>(t + 1, 0));

	int ans = 0;

	// 前からと後ろからで両方やる
	rep(i, n) {
		rep(j, t) {
			if (j + food[i].need <= t - 1)
				chmax(dp1[i + 1][j + food[i].need], dp1[i][j] + food[i].point);

			chmax(dp1[i + 1][j], dp1[i][j]);
		}
	}

	rep(i, n) {
		rep(j, t) {
			if (j + food[n - 1 - i].need <= t - 1)
				chmax(dp2[i + 1][j + food[n - 1 - i].need], dp2[i][j] + food[n - 1 - i].point);

			chmax(dp2[i + 1][j], dp2[i][j]);
		}
	}

	// i番目の商品を最後に持ってくる
	rep(i, n) {
		int added_point = food[i].point;
		int tmp = 0;
		// 時間を左右でどう振り当てるか
		rep(j, t) {
			chmax(tmp, dp1[i][j] + dp2[n - i - 1][t - 1 - j]);
		}
		chmax(ans, tmp + added_point);
	}

	Cout(ans);

	return 0;
}


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

int main(){
    int n;
    long long a = 0;
    int b = 0;
    scanf("%d",&n);
    while(n--){
        a++;
        int sum = 0;
        long long aa = a;
        while(aa){
            sum += (int)(aa % 10);
            aa /= 10;
        }
        if(sum + (b * 9) < a || (sum + (b * 9) == a && b > 0)){
            b++;
            a /= 10;
        }
        printf("%lld", a);
        for(int i=0;i<b;i++) printf("9");
        printf("\n");
    }
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  int A=0;
  int B=0;
  
  if(a<=b){
  for (int i=0;i<b;i++){
    A += pow(10,i)*a;
  }
    cout << A << endl;
  } else {
  for (int i=0;i<a;i++){
    B += pow(10,i)*b;
  }
    cout << B << endl;
  }
  
}


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

class C {
    static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());

        var X = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int min = X.Min();
        int max = X.Max();

        long ans = max * max * N;
        long kari = 0;

        for (int i = min; i <= max; i++) {
            kari = 0;
            for (int j = 0; j < N; j++) {
                kari += (X[j] - i) * (X[j] - i);
            }

            ans = Math.Min(ans, kari);
        }

        Console.WriteLine(ans);


    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>a>>b;
      Cout(a-b+1);
     

       
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int g_s_length;
void swap(int *i, int *j);
int main(void)

{
	int s_length, i,j,t,c,times = 0;
	scanf("%d", &s_length);
	g_s_length = s_length;
	int *s;
	s = (int *)malloc(sizeof(int) * s_length);
	for(i = 0;i < s_length;i++){
		scanf("%d", &s[i]);
	}
	
	for(i = 0;i < g_s_length-1;i++){
		for(j = g_s_length-1;j >= i+1;j--){
			if(s[j]<s[j-1]){
				swap(&s[j], &s[j-1]);
				times++;
			}
		}
	}
	for(i = 0;i < s_length;i++){
		if(i == 0){
			printf("%d", s[i]);
		}else{
			printf(" %d", s[i]);
		}
	}
	printf("\n");
	printf("%d\n", times);
	return 0;
}

void swap(int *i, int *j){
	int iti;
	iti = *i;
	*i = *j;
	*j = iti;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int a,b,c,d,e;
   while(cin>>a>>b)
   {
       e=0;
       for(c=1;c<=b;c++)
       {
           cin>>d;
           e+=d;
       }
       if(e>a)
       {
           cout<<"-1"<<endl;
       }
       else
       {
           cout<<a-e<<endl;
       }



   }


    return 0;
}


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

int ea(int m, int n) {
  int a,b,t;
  if(m < n) {
    a = n;
    b = m;
  } else {
    a = m;
    b = n;
  }// always a >= b
  while (b != 0) {
    t = a%b;
    a = b;
    b = t;
  }
  return a;
}

int main() {
  int n,i;
  int init;
  scanf("%d",&n);
  scanf("%d",&init);
  int x[n];
  for(i=0;i<n;i++) {
    scanf("%d",&x[i]);
  }
  for(i=0;i<n;i++) {
    x[i]=x[i]-init;
    if(x[i]<0) {
      x[i]=-x[i];
    }
  }
  int ans = x[0];
  for(i=1;i<n;i++) {
    ans = ea(ans,x[i]);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 512
def main():
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    for i in range(nedges):
        s, t = map(int, input().split())
        Adj[s].append(t)

    visited = [False] * nvertices
    ordering = []
    for u in range(nvertices):
        if not visited[u]:
            dfs(u, Adj, visited, ordering)

    for v in reversed(ordering):
        print(v)


def dfs(u, Adj, visited, ordering):
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs(v, Adj, visited, ordering)
    ordering.append(u)


main()

Measured memory_bytes: 11044
#include <bits/stdc++.h>
#define int long long
#define moder 1234567
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;


signed main() {
	int x;
	cin >> x;
	if (x % 11 == 0)cout << x / 11 * 2 << endl;
	else if (x % 11 <= 6)cout << x / 11 * 2 + 1 << endl;
	else cout << x / 11 * 2 + 2 << endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7
Q = 13


def main():
    S = input().rstrip()

    N = len(S)
    dp = [[0] * Q for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        D = S[i]
        if D == "?":
            for d in range(10):
                for j in range(Q):
                    dp[i + 1][(10 * j + d) % Q] += dp[i][j]
        else:
            d = int(D)
            for j in range(Q):
                dp[i + 1][(10 * j + d) % Q] += dp[i][j]

        for j in range(Q):
            dp[i + 1][j] %= P

    ans = dp[N][5]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 96036
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++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 FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int x, y, a, b, c;
vector<ll> p, q, r;

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}



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

	cin >> x >> y >> a >> b >> c;
	p = vector<ll>(a);
	q = vector<ll>(b);
	r = vector<ll>(c);
	REP(i, a) {
		cin >> p[i];
	}
	REP(i, b) {
		cin >> q[i];
	}
	REP(i, c) {
		cin >> r[i];
	}
	sort(All(p));
	sort(All(q));
	sort(All(r), std::greater<>());
	int idp = a - x;
	int idq = b - y;
	REP(i, c) {
		if (p[idp] <= q[idq] ) {
			if (p[idp] < r[i]) {
				p[idp] = r[i];
				if(idp+1<a)idp++;
				continue;
			}
			break;
		}
		else {
			if (q[idq] < r[i]) {
				q[idq] = r[i];
				if (idq + 1<b)idq++;
				continue;
			}
			break;
		}
	}
	ll ans = 0;
	FOR(i, a-x, a) {
		ans += p[i];
	}
	FOR(i, b - y, b) {
		ans += q[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
//
//
// 

#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

typedef std::complex<double> xy_t;
xy_t P[110];

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }

double calc_area(xy_t A, xy_t B, xy_t C){
    xy_t a = B - A, b = C - A;
    double area = abs(cross_product(a, b)/2.0);
    return area;
}

int main(){
    int N = 0;
    double x, y;
    while(scanf("%lf, %lf", &x, &y) != EOF){
        P[N++] = xy_t(x, y);
    }  

    double sum = 0.00000;
    
    xy_t A = P[0];
    
    for(int i = 0; i < (N-2); ++i){
        xy_t B = P[i+1], C = P[i+2];
        sum += calc_area(A, B, C);
    }

    printf("%.6f\n", sum);
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int __int128
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 10000 + 5 ; 
int T, n, m, P, st[N], top, w[N], num, c[N] ; 
int mul( int a, int b, int p ) {
	return ( a % p ) * ( b % p ) % p ;  
}
int fpow( int x, int k, int p ) {
	int ans = 1, base = x % p ; 
	while( k ) {
		if( k & 1 ) ans = mul( ans, base, p ) ;
		base = mul( base, base, p ), k >>= 1 ; 
	} return ans % p ; 
}
bool M_R( int p ) {
	if( p == 2 || p == 3 ) return 1 ; 
	if( p == 1 || ( p % 2 == 0 ) ) return 0 ; 
	re int d = p - 1, s = 0 ; while( !( d & 1 ) ) ++ s, d >>= 1 ; 
	rep( i, 0, 5 ) {
		re int a = rand() % ( p - 3 ) + 2 ; 
		re int x = fpow( a, d, p ), y = 0 ;
		for( register int j = 0; j < s; ++ j ) {
			y = mul( x, x, p ) ; if( y == 1 && ( x != 1 ) && x != ( p - 1 ) ) return 0 ;
			x = y ;
		} if( y != 1 ) return 0 ;
	} return 1 ; 
}
int gcd( int x, int y ) {
	return ( x == 0 ) ? y : gcd( y % x, x ) ;
}
int Rand( int x ) {
	return 1ll * ((rand() << 15 ^ rand()) << 30 ^ (rand() << 15 ^ rand())) % x ; //2
}
int work( int p ) {
	re int k = 2, x = Rand(p - 1) + 1, y = x, d = 1, c = Rand(p) % 999997 ;
	for( re int i = 1; d == 1; ++ i ) {
		x = ( mul( x, x, p ) + c ) % p ;
		d = gcd( (x > y) ? x - y : y - x, p ) ;
		if( i == k ) y = x, k <<= 1 ; 
	} return d ; 
}
void Pollard_Rho(int p) {
	if( p == 1 ) return ; 
	if( M_R(p) ) { st[++ top] = p; return ; }
	int x = p ; while( x == p ) x = work(x) ;
	Pollard_Rho(x), Pollard_Rho(p / x) ;
}
int Ans = 0 ;
void dfs( int x, int f, int d, int p ) {
	if( x == num + 1 ) {
		if( ( (d & 1) ) && ( !( (n / d) & 1 ) ) ) return ;
		int g = ( d & 1 ) ? d : d / 2 ;
		Ans = ( Ans + mul( mul( fpow( m, ( d + 1 ) / 2, p ), g, p ), (f + p) % p, p ) + p ) % p ;
		return ; 
	}
	int fd = 1 ; 
	rep( i, 0, c[x] ) {
		if( i == c[x] ) dfs( x + 1, f, d * fd, p ) ;
		else dfs( x + 1, f * ( 1 - w[x] ), d * fd, p ) ;
		fd = fd * w[x] ; 
	}
}
signed main()
{
	srand(time(NULL)) ; 
	n = gi(), m = gi(), P = 1000000007, top = 0, num = 0, Ans = 0 ;
	memset( c, 0, sizeof(c) ), memset( w, 0, sizeof(w) ), memset( st, 0, sizeof(st) ) ;
	Pollard_Rho(n) ; 
	sort( st + 1, st + top + 1 ) ;
	rep( i, 1, top ) {
		if( st[i] == st[i - 1] ) ++ c[num] ; 
		else w[++ num] = st[i], c[num] = 1 ; 
	}
	dfs( 1, 1, 1, P ) ;
	printf("%lld\n", (long long)((Ans) % P) ) ;
	return 0 ;
}

Measured memory_bytes: 896
#D問題
import math
H,W,A,B = map(int,input().split())
mod = 10**9 + 7

M = H+W-1
fact = [1 for i in range(M)]
for i in range(M):
    if i == 0:
        pass
    else:
        fact[i] = (fact[i-1]*i)%mod
        
refact = [1 for i in range(M)]
m = mod-2
b = bin(m)
b = b.lstrip("0b")
b = b[::-1]
m2 = len(b)
for i in range(M):    
    flog = [0 for j in range(m2)]
    for j in range(m2):
        if j == 0:
            flog[0] = fact[i]
        else:
            flog[j] = (flog[j-1]**2)%mod
    #print(flog)
    for j in range(m2):
        if b[j] == "1":
            refact[i]*=flog[j]
            refact[i]%=mod
            
row = B
wide = W-B
ans = 0
for i in range(wide):
    row = B+i
    C1 = (fact[H-A+row-1]*refact[H-A-1]*refact[row])%mod
    C2 = (fact[W+A-row-2]*refact[W-row-1]*refact[A-1])%mod
    #print(C1,C2)
    ans+=C1*C2
    ans%=mod

#print(fact)
#print(refact)

print(ans)

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

store = list()
for i in range(n):
    a, b = map(int, input().split())
    store.append((a, b))

store.sort(key=lambda x: x[0])

cost = 0
cur_num_drink = 0
for i in store:
    buy_num = min(i[1], m-cur_num_drink)
    cur_num_drink += buy_num
    cost += i[0] * buy_num
    if cur_num_drink == m:
        break

print(cost)


Measured memory_bytes: 18180
def resolve():
  h, w = map(int, input().split())
  s = []
  for i in range(h):
    s.append(input())
  for i in range(h):
    for j in range(w):
      if s[i][j] == '#':
        flag = False
        if j > 0 and s[i][j-1] == '#':
          flag = True
        if j < w-1 and s[i][j+1] == '#':
          flag = True
        if i > 0 and s[i-1][j] == '#':
          flag = True
        if i < h-1 and s[i+1][j] == '#':
          flag = True
        if flag == False:
          print('No')
          return
  print('Yes')
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3064
n = int(input())
cnt=0
factor=[]
for i in range(2, int(n**.5)+1):
    j=1
    while n%i==0:
        n//=i
        factor.append(i)
if n>1:
    cnt+=1

# 1->1, 3->2, 6->3, 10->4 ...を返す
def f(x):
    i=1
    cnt=0
    while x>=i:
       x-=i
       i+=1
       cnt+=1
    return cnt

from itertools import groupby
for k,v in groupby(factor):
    cnt+=f(len(list(v)))
print(cnt)

Measured memory_bytes: 63764
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  LL h,n;
  cin >> h >> n;
  rep(i,0,n){
    LL a;
    cin >> a;
    h -= a;
  }
  cout << (h > 0? "No":"Yes") << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()


Measured memory_bytes: 39024
#include <iostream>
#include <string>
using namespace std;

int main(){
  string str;
  cin>>str;
  int a=0,b=0;
  for(int i=0;i<3;i++){
    if(str[i]=='A'){ a++;}
    if(str[i]=='B'){ b++;}
  }
  
  if(a>0&&b>0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
n,m = gets.chomp.split(" ").map(&:to_i)
a = []
b = []
g = Array.new(n+1).map{Array.new}
m.times do |i|
  a[i],b[i] = gets.chomp.split(" ").map(&:to_i)
  g[a[i]].push(b[i])
  g[b[i]].push(a[i])
end

dist = Array.new(g.length,-1)
dist[1] = 1
queue = [1]
while !queue.empty?
  v = queue[0]
  queue.shift
  g[v].each{|des|
    if dist[des] == -1
      dist[des] = v
      queue.push(des)
    end
   }
end

if dist[1..].all? {|x| x != -1}
  puts "Yes"
  (n-1).times do |i|
    puts dist[i+2]
  end
else
  puts "No"
end

Measured memory_bytes: 36420
#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-(x)))
using namespace std;

typedef long long ll;
const int N = 1e5 + 10, inf = (int)1e9;
int n, a[N], sum[N * 10], C[N * 10];

void add(int x) {
    for (; x <= 2 * N; x += lowbit(x)) C[x]++;
}

ll query(int x) {
    ll ret = 0;
    for (; x; x -= lowbit(x)) ret += C[x];
    return ret;
}

bool chk(int x) {
    for (int i = 1; i <= 2 * N; i++) C[i] = 0;
    for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (a[i] <= x ? 1 : -1);
    ll tot = 0;
    for (int i = 0; i <= n; i++) {
        tot += query(sum[i] + N - 1);
        add(sum[i] + N);
    }
    return tot > 1ll * n * (n + 1) / 4;
}

int main() {
    scanf("%d", &n);
    int l = inf, r = -inf;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        l = min(l, a[i]), r = max(r, a[i]);
    }
    while (l < r) {
        int mid = (l + r) >> 1;
        if (chk(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main(){
    ll N, M; cin >> N >> M;
    // int A[100001], B[100001];
    // rep(i, N) cin >> A[i] >> B[i];
    vector <pair<ll, ll> > A(N);
    rep(i, N){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        A[i] = make_pair(tmp1, tmp2);
    }

    // rep(i, N) {
    //     cout << A[i].first << " " << A[i].second << endl;
    // }

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


    // cout << endl;
    // rep(i, N) {
    //     cout << A[i].first << " " << A[i].second << endl;
    // }
    ll ans = 0;
    rep(i, N){
        ans += A[i].first * A[i].second;
        M -= A[i].second;
        if( M <= 0) {
            ans -= abs(M) * A[i].first;
            break;
        }

    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792