akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
        var a, count, n int
        var line string
        var e error

        fmt.Scan(&n)
        if sc.Scan() {
                line = sc.Text()
        }

        var splitLine = strings.Split(line, " ")
        for i := range splitLine {
                a, e = strconv.Atoi(splitLine[i])
                if e != nil {
                        panic(e)
                }
                if (i+1) != a {
                        count++
                }
        }


        if count < 3 {
                fmt.Println("YES")
        } else {
                fmt.Println("NO")
        }
}

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

string S;

bool month(int e){
	return e > 0 && e < 13;
}

int main(){		
	cin >> S;
	int a = stoi(S.substr(0, 2)), b = stoi(S.substr(2, 2));
	if(!month(a) && !month(b)) printf("NA\n");
	else if(month(a) && month(b)) printf("AMBIGUOUS\n");
	else if(month(a)) printf("MMYY\n");
	else printf("YYMM\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size();i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3820
#include <stdio.h>

inline static int read_int() {
    int x = 0, k;
    while ((k = getchar_unlocked() - '0') >= 0) x = x * 10 + k;
    return x;
}

inline static void put_int(int x) {
    int s = 0;
    char f[4] = {'0', '0', '0', '0'};
    while (x) {
        f[s++] += x % 10;
        x /= 10;
    }

    while (s--) putchar_unlocked(f[s]);
    putchar_unlocked('\n');
}

short highest[2000], streak[2000];

int main() {
    int h = read_int(), w = read_int(), max = 0, height, width, lastWall, tmp, len;

    for (height = 0; height < h; height++) {
        lastWall = -1;

        for (width = 0; width < w; width++) {
            if (getchar_unlocked() & 1) {
                if (lastWall != width - 1) {
                    len = width - lastWall - 1;
                    for (tmp = lastWall + 1; tmp < width; tmp++) if (len > highest[tmp]) highest[tmp] = len;
                }

                tmp = highest[width] + streak[width];
                if (tmp > max) max = tmp;

                highest[width] = streak[width] = 0;
                lastWall = width;
            } else streak[width]++;
        }

        getchar_unlocked();

        if (++lastWall != width) for (len = width - lastWall; lastWall < width; lastWall++) if (len > highest[lastWall]) highest[lastWall] = len;
    }

    for (width = 0; width < w; width++) {
        if (streak[width] != 0) {
            tmp = highest[width] + streak[width];
            if (tmp > max) max = tmp;
        }
    }

    put_int(max - 1);
}


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

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

    vector<int> P(N);
    for(int i=0; i<N; i++){
        cin>>P[i];
    }

    vector<int> Q(N);
    for(int i=0; i<N; i++){
        cin>>Q[i];
    }

    vector<int> v(N);
    //1刻みで格納できる関数
    iota(v.begin(), v.end(), 1);

    ll P_cnt = 0;
    ll Q_cnt = 0;
    bool P_flag = false;
    bool Q_flag = false;

    do{
        if(v == P){
            P_flag = true;
        }
        if(v == Q){
            Q_flag = true;
        }

        if(!P_flag){
            P_cnt++;
        }
        if(!Q_flag){
            Q_cnt++;
        }

        if(P_flag && Q_flag){
            break;
        }
    }while(next_permutation(v.begin(), v.end()));

    cout<<abs(P_cnt - Q_cnt)<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n,d;
    cin>>n>>d;
    int ans;
    if(n%(2*d+1)==0)ans=n/(2*d+1);
    else ans=n/(2*d+1)+1;
    cout<<ans<<endl;
    return 0;
}

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

def main():
    [N, T] = list(map(int, input().split()))

    min_c = 9999
    for i in range(N):
        [c, t] = list(map(int, input().split()))
        if t <= T:
            min_c = min(min_c, c)

    print(str(min_c) if min_c != 9999 else 'TLE')


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
N, K = map(int,input().split())
#N以下の数でKの倍数の個数(mod K で0と等しいものの個数)
cntMod = N//K
#Kが奇数のときは3つ組として(0,0,0)しかとれない　ただしmod K
#Kが偶数のときは3つ組として(K/2,K/2,0)もとれる ただし　mod K
if K%2==0:
    if K*cntMod+K//2 <= N:
        cntMid = cntMod + 1
    else:
        cntMid = cntMod
else:
    cntMid = 0
print(cntMid**3+cntMod**3)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define pr pair<int,int>
#define N 100005
#define mod 1000000007
#define INF 2147483647
using namespace std;
int main() {
	IOS;

		string a;
		cin >> a;
		cout << a;
		if (a.back() == 's') {
			cout << "es\n";
		}
		else cout << "s\n";
	
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>

using namespace std;

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

int change(int panel[10][10], int y, int x, int c){
	int sum=1;
	int color=panel[y][x];
	panel[y][x]=c;
	for(int i=0; i<4; i++){
		if(panel[y+dy[i]][x+dx[i]] == color){
			sum+=change(panel, y+dy[i], x+dx[i], c);
		}
	}
	return sum;
}

int solve(int panel[10][10], int depth, int c){
	if(depth >= 5) {
		if(panel[1][1] != c) return 0;
		else return change(panel, 1, 1, 0);
	}
	int ans=0;
	for(int i=1; i<=6; i++){
		int tmp[10][10];
		if(panel[1][1]==i) continue;
		for(int j=0; j<10; j++){
			for(int k=0; k<10; k++){
				tmp[j][k] = panel[j][k];
			}
		}
		change(tmp, 1, 1, i);
		ans = max(ans, solve(tmp, depth+1, c));
	}
	return ans;
}

int main(){
	while(1){
		int h, w, c; cin >>h>>w>>c;
		if(!h && !w) break;

		int panel[10][10]={0};
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin>>panel[i][j];
			}
		}
		cout<<solve(panel, 0, c)<<endl;
	}
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#define l(s) s.length()
#define sort(v) sort(v.begin(), v.end());
#define scan(v,n) rep(i,0,n) {ll k; cin >> k; v.pb(k);}
#define print(v,n) {rep(i,0,n) cout << v[i] << " "; cout << endl;}
#define printstr(s,n) {rep(i,0,n) cout << s[i]; cout << endl;}
#define rev(a) reverse(a.begin(), a.end());
#define pb push_back
typedef long long ll;
typedef long double lld;
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
 
const ll mxN=1e5+1;
const ll N=1e9+7;
 
ll dp[mxN];
 
  int main() {
      int T=1;// cin >> T;
      while(T--){
          ll n,W; cin >> n >> W;
          rep(i,0,n) {
              ll w,v;
              cin >> w >> v;
              rrep(x,W,0) {
                  if(x>=w&&dp[x]<dp[x-w]+v) dp[x]=dp[x-w]+v;
              }
          }
          //print(dp,W+1);
          cout << dp[W];
      } 
	 return 0;
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define x first
#define y second
#define loop(i, start, end) for(int i=start; i<=end; ++i)
#define loopr(i, end, start) for(int i=end; i>=start; --i)
#define pb push_back
#define MOD 1000000007
#define mod(x) (x%MOD + MOD)%MOD
using namespace std;
    
template <typename T>
void cloneArray(T *a, T *b, int start, int end) {
    loop(i, start, end) {
        *(b+i)=*(a+i);
    }
}
    
template <typename T>
void inputArray(T *a, int start, int end) {
    loop(i, start, end) cin >> a[i];
}
    
template <typename T>
void printArray(T *a, int start, int end) {
    loop(i, start, end) cout << *(a+i) << ' ';
}
    
void ruffleSort(int *a, int n) {
    unsigned seed=0;
    shuffle(a, a+n, default_random_engine(seed));
    sort(a, a+n);
}

ll mod_add(ll a, ll b) {
    return (mod(a)+mod(b))%MOD;
}

ll mod_mult(ll a, ll b) {
    return (mod(a)*mod(b))%MOD;
}
   
int main(int argc, char const *argv[])
{   
    IOS;
    int n;
    cin >> n;
    int a[n+5];
    ll pre[n+5]={}, sum=0;
    inputArray(a, 1, n);
    loop(i, 1, n) pre[i]=pre[i-1]+a[i];
    loop(i, 1, n) {
        sum=mod_add(sum, mod_mult(a[i], pre[n]-pre[i]));
    }
    cout << sum;
    //cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
    return 0;
}

Measured memory_bytes: 5952
#[allow(dead_code)]
fn main() {
    let (n, s, k) = (i::u(), i::s(), i::u());
    let c = s[k - 1];
    for i in 0..n {
        print!("{}", if s[i] == c { c } else { '*' });
    }
    println!();
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }

    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }

    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#define INFTY (1 << 30)
#define MAX 2000000

int N = 0;
int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }
int parent(int i) { return i / 2; }

int maxOf3Node(int data[], int base) {
  int l = left(base);
  int r = right(base);
  int leargest;
  if (l <= N && data[l] > data[base])
    leargest = l;
  else
    leargest = base;
  if (r <= N && data[r] > data[leargest])
    leargest = r;
  return leargest;
}

void maxHeapify(int data[], int i) {
  int leargest = maxOf3Node(data, i);
  if (leargest != i) {
    swap(data[leargest], data[i]);
    maxHeapify(data, leargest);
  }
}

void buildMaxHeap(int data[]) {
  for (int i = N / 2; i > 0; i--)
    maxHeapify(data, i);
}

void insert(int data[], int key) {
  N++;
  data[N] = key;
  int i = N;
  while (i > 1 && data[parent(i)] < data[i]) {
    swap(data[parent(i)], data[i]);
    i = parent(i);
  }
}

int extract(int data[]) {
  int max = data[1];
  data[1] = data[N];
  N--;
  maxHeapify(data, 1);
  return max;
}

void trace(int data[]) {
  for (int i=1;i<=N;i++)
    cout <<" " << data[i];
  cout<< endl;
}

int main() {
  int data[MAX + 1];
  int x;
  char com[20];

  while (true) {
    scanf("%s", com);
    if (com[0] == 'i') { // insert
      scanf("%d", &x);
      insert(data, x);
    } else if (com[1] == 'x') { // extract
      int max = extract(data);
      cout << max << endl;
    } else if (com[0] == 'e') { // end
      break;
    }
  }

  return 0;
}

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

namespace ts{
	const int tsv=80800,tse=5202333;
	int n,ans[tsv];
	struct R{
		int to,nex;
	}r[tse];
	int hea[tsv<<1],cnt,bel[tsv<<1],blt,st[tsv<<1],top,dfn[tsv<<1],dft,low[tsv<<1];
	
	void RE(){
		memset(hea,0,sizeof hea);cnt=0;
		memset(bel,0,sizeof bel);blt=0;
		memset(dfn,0,sizeof dfn);dft=0;
	}
	void A(int u,int v){
		r[++cnt]=(R){v,hea[u]};hea[u]=cnt;
	}
	void must(int x,int x2,int y,int y2){
		A(x<<1|x2,y<<1|y2);
	}
	void XX(int x,int x2,int y,int y2){ // can't be together
		//printf("XX::%d %d %d %d\n",x,x2,y,y2);
		must(x,x2,y,y2^1);
		must(y,y2,x,x2^1);
	}
	void dfs(int x){
		low[x]=dfn[x]=++dft;
		st[++top]=x;
		int y;
		for (int i=hea[x];i>0;i=r[i].nex){
			y=r[i].to;
			if (!dfn[y]){
				dfs(y);
				low[x]=min(low[x],low[y]);
			}else{
				if (!bel[y]){
					low[x]=min(low[x],dfn[y]);
				}
			}
		}
		if (low[x]==dfn[x]){
			bel[x]=++blt;
			while (st[top]!=x){
				bel[st[top]]=blt;
				top--;
			}
			top--;
		}
	}
	bool realmain(){
		int u,v;
		for (int i=2;i<=(n<<1|1);i++){
			if (!bel[i]){
				top=0;
				dfs(i);
			}
		}
		for (int i=1;i<=n;i++){
			if (bel[i<<1|0]==bel[i<<1|1]) return 0;
			ans[i]=bel[i<<1|0]>bel[i<<1|1]?1:0;
		}
		
		return 1;
	}
}

int n,xx[20200];
struct P{
	int x,id;
}p[20200];
vector<int>w[10100];
bool cmp(P p1,P p2){
	return p1.x<p2.x;
}
struct seg{
	int lc,rc;
}tr[80800];
int cnt,pos[20200];

void dfs(int x){
	if (tr[x].lc){
		ts::XX(x,0,tr[x].lc,1);
		dfs(tr[x].lc);
	}
	if (tr[x].rc){
		ts::XX(x,0,tr[x].rc,1);
		dfs(tr[x].rc);
	}
}

void doit(int x,int l,int r,int st,int en,int who){
	if (st>en) return;
	if (l==st&&r==en){
		ts::XX(x,1,who,1);
		return;
	}
	int mid=l+r>>1;
	doit(tr[x].lc,l,mid,max(st,l),min(en,mid),who);
	doit(tr[x].rc,mid+1,r,max(st,mid+1),min(en,r),who);
}

bool check(int now){
	ts::RE(); ts::n=cnt;
	for (int i=1;i+i<=n;i++)
		ts::XX(pos[w[i][0]],0,pos[w[i][1]],0);
	dfs(1);
	int p1,p2;
	for (int i=1;i<=n;i++){ //printf("%d::",i);
		p1=lower_bound(xx+1,xx+n+1,xx[i]-now+1)-xx;//printf("[%d,%d]\n",p1,i-1);
		doit(1,1,n,p1,i-1,pos[i]);
	}
	return ts::realmain();
}

void build(int x,int l,int r){
	if (l==r){
		pos[l]=x;
		return;
	}
	int mid=l+r>>1;
	tr[x].lc=++cnt; build(tr[x].lc,l,mid);
	tr[x].rc=++cnt; build(tr[x].rc,mid+1,r);
}

int main(){
	//freopen("A.in","r",stdin); freopen("A.out","w",stdout);
	scanf("%d",&n); n*=2;
	for (int i=1;i<=n;i++){
		scanf("%d",&p[i].x);
		p[i].id=(i+1)/2;
	}
	sort(p+1,p+n+1,cmp);
	for (int i=1;i<=n;i++){
		w[p[i].id].push_back(i);
		xx[i]=p[i].x;
	}
	xx[0]=-1010001000;
	xx[n+1]=2010001000;
	
	cnt=1;
	build(1,1,n);
	
	int l=0,r=(1e9)/max(n/2-1,1),mid,ans;
	for (;l<=r;){
		mid=l+r>>1;
		if (check(mid)){
			l=(ans=mid)+1;
		}else{
			r=mid-1;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 17024
use std::io::*;
use std::str::FromStr;

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

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: u32 = read();
    let w: u32 = read();

    if w >= s {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2136
#include <stdio.h>

int main() {
	int map[10][10]={0}, x, y, m, h, n0;
	int i,j;
	while(scanf("%d,%d,%d",&x,&y,&m)!=EOF) {
		// common
		map[x][y]++;
		if (y-1>=0) map[x][y-1]++;
		if (x-1>=0) map[x-1][y]++;
		if (y+1<10) map[x][y+1]++;
		if (x+1<10) map[x+1][y]++;
		// medium or big(2,3)
		if (m>1) {
			if ( (y-1>=0) && (x-1>=0) ) map[x-1][y-1]++;
			if ( (y+1<10) && (x-1>=0) ) map[x-1][y+1]++;
			if ( (y-1>=0) && (x+1<10) ) map[x+1][y-1]++;
			if ( (y+1<10) && (x+1<10) ) map[x+1][y+1]++;
			if (m>2) {
				// big(3)
				if (y-2>=0) map[x][y-2]++;
				if (x-2>=0) map[x-2][y]++;
				if (y+2<10) map[x][y+2]++;
				if (x+2<10) map[x+2][y]++;
			}
		}
	}
	n0=0;
	h=0;
	for(i=0;i<10;i++) {
		for(j=0;j<10;j++) {
			if (map[i][j]==0) n0++;
			if (map[i][j]>h) h = map[i][j];
		}
	}
	printf("%d\n%d\n",n0,h);
	return 0;
}

Measured memory_bytes: 0
package main
import (
  "fmt"
)
func main() {
  var a, b, x int
  fmt.Scan(&a, &b, &x)
  var result string
  if 0 <= x-a && x-a <= b {
    result = "YES"
  } else {
    result = "NO"
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var n, m int
	var key string

	fmt.Scan(&n)
	blueCards := make(map[string]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&key)
		blueCards[key] += 1
	}

	fmt.Scan(&m)
	redCards := make(map[string]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&key)
		redCards[key] += 1
	}

	max := 0
	for key, value := range blueCards {
		if value-redCards[key] > max {
			max = value - redCards[key]
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC103.C
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var n = sc.Nextint();
            var a = sc.Arrayint(n);
            var maxf = a.Select(val => val - 1).Sum();
            Console.WriteLine(maxf);
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13328
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if(a<b) return gcd(b, a);
    ll t;
    while(b!=0) {
        t=a%b;
        a=b;
        b=t;
    }
    return a;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b), f = sqrt(g), cnt = 1;
    for(ll i=2; i<=f; i++) {
        if(g%i==0) cnt++;
        while(g%i==0) g /= i;
    }
    if(g!=1) cnt++;
    cout << cnt << endl;

    return 0;
}


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

#define x first
#define y second

using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
pii f[N],tmp1[N],tmp2[N];
int ch[N][2],fa[N],v[N],tp[N],vis[N],le[N],ri[N],mid[N],n,m;
LL lim;
bool flag;

void link(int a,int b) {ch[a][0] ? ch[a][1] = b : ch[a][0] = b;}
inline int rd() {int r;scanf("%d",&r);return r;}

void solve(int u,int l,int r) {
	if (!flag) return ;
	if (!ch[u][0] && !ch[u][1]) {
		f[l] = pii(v[u], v[u]);
		tp[u] = l;
		return ;
	}
	int L = ch[u][0], R = ch[u][1];
	solve(L, l, mid[u]);
	solve(R, mid[u]+1, r);

	int T = tp[R], q1 = 0, q2 = 0;
	for (int i=tp[L];i>=l;i--) {
		while (T>=mid[u]+1 && f[i].y+f[T].x > lim) T--;
		if (T>=mid[u]+1 && f[i].y + f[T].x <= lim)
			tmp1[++q1] = pii(f[i].x, f[T].y);
	}

	T = tp[L];
	for (int i=tp[R];i>=mid[u]+1;i--) {
		while (T>=l && f[i].y+f[T].x > lim) T--;
		if (T>=l && f[i].y+f[T].x <= lim)
			tmp2[++q2] = pii(f[i].x, f[T].y);
	}

	if (!q1 && !q2) {flag = 0; return ;}
	tp[u] = l-1;
	while (q1 || q2) {
		pii cur;
		if (q1 && q2)
			cur = tmp1[q1].x < tmp2[q2].x ? tmp1[q1--] : tmp2[q2--];
		else
			cur = !q1 ? tmp2[q2--] : tmp1[q1--];
		if (tp[u] >= l && cur.y >= f[ tp[u] ].y) continue;
		f[ ++tp[u] ] = cur;
	}
	for (int _=l;_<=tp[u];_++) f[_].x += v[u], f[_].y += v[u];

}

void dfs(int u) {
	if (!ch[u][0] && !ch[u][1]) {
		le[u] = ri[u] = ++m;
		return ;
	}
	dfs(ch[u][0]); dfs(ch[u][1]);
	le[u] = le[ ch[u][0] ];
	ri[u] = ri[ ch[u][1] ];
	mid[u] = ri[ ch[u][0] ];
}

bool go(LL x) {
	lim = x, flag = 1;
	solve(1,1,m);
	return flag;
}

int main() {
	n = rd();
	for (int _=2;_<=n;_++) {
		fa[_] = rd(), v[_] = rd();
		link(fa[_], _);
		if (!vis[ fa[_] ]) vis[ fa[_] ] = 1;
	}

	dfs(1);
	LL l = 0, r = 1000000000LL;
	while (l < r) {
		LL mi = (l + r) >> 1;
		if (go(mi)) r = mi; else l = mi + 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 33536
N = int(input())-1
S = str(input())
r,g,b = 0,0,0
rgb = str()
d = 0
for n in range(N+1):
    rgb = str(S[n])
    if rgb == "R":
        r += 1
    if rgb == "G":
        g += 1
    if rgb == "B":
        b += 1
    rang = int((N - n - 2) / 2)
    for j in range(rang,-1,-1):
        if S[n+j+1] != rgb and n+2*j+2 <= N:
           
            if S[n+2*j+2] != rgb:
                if S[n+2*j+2] != S[n+j+1]:
                    d -= 1
                    
                else:
                    pass
            else:
                pass
        else:
            pass
        

Answer = r*g*b + d

print(Answer)
                        


Measured memory_bytes: 9228
#include<cstdio>
#include<climits>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;
const int MAXN = 100+9;
int n;
int F[MAXN][MAXN];
int P[MAXN][MAXN];
int sle[12];
LL ans=-10000000000000000LL;

bool check(){
	int re=0;
	for(int i=1;i<=10;i++)
		re+=sle[i];
	return re>0;
}

LL calc(){
	LL re=0;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=10;j++){
			if(F[i][j]==1 && sle[j]==1)
				cnt++;
		}
		re+=P[i][cnt];
	}
	return re;
}

void DFS(int x){
	if(x==11){
		if(check())
			ans=max(ans,calc());
		return;
	}
	sle[x]=1;
	DFS(x+1);
	sle[x]=0;
	DFS(x+1);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=10;j++)
			scanf("%d",&F[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=10;j++)
			scanf("%d",&P[i][j]);
	DFS(1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF INT_MAX>>1 
#define SIZE 100001;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

using namespace std;

int main(void){
	int n; cin >> n;
	int first=-1, second=-1;
	int first_idx=-1, second_idx=-1;
	rep(i, n){
		int a; cin >> a;
		if(a >= first){
			second = first;
			second_idx = first_idx;
			first = a;
			first_idx = i;
		} else if(a > second){
			second = a;
			second_idx = i;
		}
	}

	rep(i, n){
		if(i == first_idx) cout << second << endl;
		else cout << first << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int d, t, s; cin >> d >> t >> s;
	cout << (s * t >= d ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 3644
# after listening explanation
h, @w, k = gets.split.map(&:to_i)
@s = $<.map{|l|l.chomp.chars.map{|c|c=="#"}}
@a = [*0..h-1].map{Array.new(@w,-1)}
@counter = 1
flag_h = -1
from_h = 0
def separate(start, goal, target)
  flag_w = -1
  from_w = 0
  @w.times{|j|
    if @s[target][j]
      if flag_w>=0
        [*start..goal].each{|x| [*from_w..j-1].each{|y| @a[x][y]=@counter} }
        @counter+=1
        from_w = j
      end
      flag_w = j
    end
    if j==@w-1
      [*start..goal].each{|x| [*from_w..j].each{|y| @a[x][y]=@counter} }
      @counter+=1
    end
  }
end
h.times{|i|
  if @s[i].include?(true)
    if flag_h>=0
      separate(from_h, i-1, flag_h)
      from_h = i
    end
    flag_h = i
  end
  if i==h-1
    separate(from_h, i, flag_h)
  end
}
puts @a.map{|ai|ai.join(" ")}.join("\n")


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, a, b, c, d, e, n=0;
  cin >> A >> B;
  for(; A<=B; A++){
    a = A/10000;
    b = (A/1000)%10;
    c = (A/100)%10;
    d = (A/10)%10;
    e = A%10;
    if( a==e && b==d ){
      n++;
    }
  }
  cout << n << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    long long a, b, k;
    cin >> a >> b >> k;
    if(a >= k) cout << a-k << " " << b << endl;
    else if(a < k and k <= a+b) cout << 0 << " " << b-(k-a) << endl;
    else if(a+b < k) cout << 0 << " " << 0 << endl;
}
  

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int five=0;
		int seven=0;
		
		if(a==5){
			five++;
		}else if(a==7){
			seven++;
		}
		if(b==5){
			five++;
		}else if(b==7){
			seven++;
		}
		
		if(c==5){
			five++;
		}else if(c==7){
			seven++;
		}
		
		if(five==2&&seven==1){
			System.out.println("YES");
		}else{
			System.out.println("NO");

		}
		

	}

}

Measured memory_bytes: 8788
import sys

state = True
for s in sys.stdin:
    if state:
        state = not state
        a = list(map(int, s.split()))
    else:
        state = not state
        b = list(map(int, s.split()))
        hit = sum(a[i] == b[i] for i in range(4))
        blow = sum(b[i] in a for i in range(4)) - hit
        print(hit, blow)

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int[] l = new int[m];
        int[] r = new int[m];
        
        for (int i = 0; i < m; i++) {
            String[] ss = br.readLine().split(" ");
            l[i] = Integer.parseInt(ss[0]);
            r[i] = Integer.parseInt(ss[1]);
        }
        
        Arrays.sort(l);
        Arrays.sort(r);

        System.out.println(r[0]-l[m-1]+1>0?r[0]-l[m-1]+1:0);
    }
}





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

void dfs(int u, int p, auto& vis, auto& ans, const auto& ki) {
    vis[u] = true;
    ans[u] += ans[p];
    for (int v : ki[u]) {
        if (vis[v]) continue;
        dfs(v, u, vis, ans, ki);
    }
}

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

    vector<vector<int>> ki(N + 1);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }

    vector<int> ans(N + 1);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        ans[p] += x;
    }

    vector<bool> vis(N + 1);
    dfs(1, 0, vis, ans, ki);

    for (int i = 1; i <= N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 30592
#n = int(input())
a, b = map(int, input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
v = (a+b)//2
mod = (a+b) % 2
if mod == 0:
    print(v)
else:
    print(v+1)


Measured memory_bytes: 9028
def gcd(a,b):
    if a % b == 0:
        return b
    else:
        return gcd(b,a%b)

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = [a[i]//2 for i in range(n)]
l = 1
b = -1
for x in a:
    if l % x != 0:
        l = l * x // gcd(l,x)
    c = 0
    while x % 2 == 0:
        x = x // 2
        c += 1
    if b != -1 and b != c:
        print(0)
        exit()
    elif b == -1:
        b = c
        
ans = m // l
ans = (ans + 1) // 2
print(ans)
#print(l)


Measured memory_bytes: 14400
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i,t,n) for(int i=t;i<n;i++)
#define nd "\n"
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>




/*ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}*/
/*ll ph[100001];
void E_phi(int n){

ph[0]=0;
ph[1]=1;
for(int i=2;i<=n;i++){
    ph[i]=i;
}
for(int i=2;i<=n;i++){
    if(ph[i]==i){
        for(int j=i;j<=n;j+=){
            ph[j]-=ph[j]/i;
        }
    }
}


}*/
/*string s,t;
vector<int>  z_fun(string s){

int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}*/

/*struct st{
ll sum,pre,suf,ans;
st(){}
st(ll k){
ans=k,pre=k,suf=k,sum=0;
}

};
ll t[4*200001+4];
ll a[200001];
ll lazy[4*200001+4];
ll mx=1e14;



void push(int ind){
int l=2*ind+1,r=2*ind+2;
t[l]+=lazy[ind];
t[r]+=lazy[ind];
lazy[l]+=lazy[ind];
lazy[r]+=lazy[ind];
lazy[ind]=0;

}

void build(int ind,int l,int r){
if(l==r){
    t[ind]=a[l];
return;
}
int mid=(l+r)/2;
build(2*ind+1,l,mid);
build(2*ind+2,mid+1,r);

  t[ind] =min(t[ind*2+1] , t[ind*2+2]);



}
ll query(int ind,int l,int r,int p,int q){

if(l>q || r<p )
    return mx;
    int mid=(l+r)/2;

if(l>=p && r<=q )
    {
      return t[ind];
    }
    push(ind);
ll x=query(2*ind+1,l,mid,p,q);
ll y=query(2*ind+2,mid+1,r,p,q);


return min(x,y);
}

void update(int ind,int l,int r,int p,int q,int val){
if(l>q || r<p )
    return;

if(l>=p && r<=q )
    {
      t[ind]+=val;
      lazy[ind]+=val;
      return;
    }
push(ind);
int mid=(l+r)/2;
    update(2*ind+1,l,mid,p,q,val);
     update(2*ind+2,mid+1,r,p,q,val);
    t[ind]=min(t[2*ind+1],t[2*ind+2]);



}


ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}
*/



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll d,t,s;
cin>>d>>t>>s;
    if(s*t>=d)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }



Measured memory_bytes: 3556
const txt = require('fs').readFileSync('/dev/stdin', 'utf8')

const input = txt.split('\n')
const [k, s]: number[] = input[0].split(' ').map((i: string) => Number(i))
let count: number = 0
for (let x = 0; x <= k; x++) {
  for (let y = 0; y <= k; y++) {
    if ((s - x - y) <= k && (s - x - y) >= 0) {
      count++
    }
  }
}
console.log(count)

Measured memory_bytes: 11468
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final long a = Long.parseLong(sc.next());
        final long b = Long.parseLong(sc.next());
        final long c = Long.parseLong(sc.next());
        sc.close();

        if (c - a - b > 0 && (c - a - b) * (c - a - b) > 4 * a * b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

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

using namespace std;
using ll=long long;

const int INF = 100000;

int main() {
    int A[3][3] = {}, N, b[10] = {};
    rep(i, 3) rep(j, 3) cin >> A[i][j];
    cin >> N;
    rep(i, N) cin >> b[i];

    rep(i, 3) rep(j, 3) rep(k, N) if (A[i][j] == b[k]) A[i][j] = 0;

    for (int i = 0; i < 3; ++i) {
        if (A[i][0] == A[i][1] && A[i][0] == A[i][2]) {
            cout << "Yes";
            return 0;
        }
        if (A[0][i] == A[1][i] && A[0][i] == A[2][i]) {
            cout << "Yes";
            return 0;
        }
    }

    if (A[0][0] == A[1][1] && A[0][0] == A[2][2]) {
        cout << "Yes";
        return 0;
    }
    if (A[0][2] == A[1][1] && A[0][2] == A[2][0]) {
        cout << "Yes";
        return 0;
    }

    cout << "No";
    return 0;
}


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

using namespace std;

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

	vector<int> fruits;

	for (int i = 0; i < N; i++) {
		int price;
		cin >> price;
		fruits.push_back(price);
	}

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

	int sum = 0;
	for (int i = 0; i < K; i++)
		sum += fruits[i];

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3164
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


a,b,c = map(str, input().split())

if (a[-1] == b[0] and b[-1] == c[0]):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 8920
import sys

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

def main():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    AB = [list(map(int,input().split())) for _ in range(M)]
    ans = [True] * N

    for A,B in AB:
        A -= 1
        B -= 1
        if H[A] > H[B]:
            ans[B] = False
        elif H[A] < H[B]:
            ans[A] = False
        else:
            ans[A] = False
            ans[B] = False
    print(ans.count(True))

if __name__ == "__main__":
    main()

Measured memory_bytes: 32028
#include<stdio.h>
int main()
{
	int m, d;
	scanf("%d %d", &m, &d);
	int ans = 0;
	int i;
	int d1, d10;
	for (i = 1; i <= d; i++)
	{
		d1 = i % 10;
		d10 = i / 10;
		if (d1 > 1 && d10 > 1 && d1 * d10 <= m)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}


void solve()
{
     int l,r;
     cin>>l>>r;
     int r1=((l/2019)+1)*2019;
     r=min(r,r1+2);
     int sum=1;
     //cout<<l<<" "<<r<<endl;
     int mx=1e15;
     rep(i,l,r)
     {
        rep(j,i+1,r+1)
        {
            //cout<<i<<":"<<j<<" "<<(i*j)%2019<<endl;
            mx=min((i%2019*j%2019)%2019,mx);
        }
     }
     cout<<mx;


}

signed main()
{
        FIO
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 3784
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-25 15:41:57 +0900
# LastModified: 2020-06-25 16:11:34 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    h, w = map(int, input().split())
    s = []
    s.append((w+2)*'.')
    for _ in range(h):
        s.append('.'+input()+'.')
    s.append((w+2)*'.')
#    print(s)
    cnt = [[0]*(w+2) for i in range(h+2)]
    for i in range(1, h+1):
        for j in range(1, w+1):
            if s[i][j] == '#':
                continue
            if s[i-1][j-1] == '#':
                cnt[i][j] += 1
            if s[i-1][j] == '#':
                cnt[i][j] += 1
            if s[i-1][j+1] == '#':
                cnt[i][j] += 1
            if s[i][j-1] == '#':
                cnt[i][j] += 1
            if s[i][j+1] == '#':
                cnt[i][j] += 1
            if s[i+1][j-1] == '#':
                cnt[i][j] += 1
            if s[i+1][j] == "#":
                cnt[i][j] += 1
            if s[i+1][j+1] == '#':
                cnt[i][j] += 1

    for i in range(1, h+1):
        for j in range(1, w+1):
            if s[i][j] == '#':
                print('#', end='')
                continue
            print(cnt[i][j], end='')
        print()






if __name__ == "__main__":
    main()


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

using ll = long long;

int main() {
    int n, a;
    cin >> n;
    vector<int> b(n, 2e9);
    rep(i, n) {
        cin >> a;
        int j = lower_bound(b.begin(), b.end(), a) - b.begin();
        b[j] = a;
    }
    int ans = 0;
    rep(i, n) {
        if (b[i] < 2e9) ans = i + 1;
    }
    cout << ans << "\n";
}


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

int main (void) {
    long int n, sum = 0;
    int m, x, i, j, k;
    scanf("%ld %d %d", &n, &x, &m);
    long int a[2 * m];
    a[0] = x;
    for (i = 1; i < 2 * m; i++) {
        a[i] = (a[i - 1] * a[i - 1]) % m;
        for (j = 0; j < i; j++) {
            if (a[i] == a[j])
            break;
        }
        if (i != j) break;
    }
    k = i;

    if (j >= n) for (i = 0; i < n; i++) sum += a[i];
    else {
        for (i = 0; i < j; i++) sum += a[i];
        n -= j;
        long int tsum = 0;
        for (i = j; i < k; i++) tsum += a[i];
        sum += n / (k - j) * tsum;
        n %= (k - j);
        for (i = j; i < j + n; i++) sum += a[i];
    }
    printf("%ld\n", sum);
    return 0;
}

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

int main() {
  long long N, H; cin >> N >> H;
  vector<long long> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a.at(i) >> b.at(i);
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  int ans = 0;
  long long d = 0;
  for (int i = 0; i < N; i++) {
    if (b.at(i) < a.at(0)) break;
    d += b.at(i);
    ans++;
    if (d >= H) {
      cout << ans << endl;
      return 0;
    }
  }
  ans += ((H - d) + a.at(0) - 1) / a.at(0);
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
/*
time:90m23s
wa:
反省:
考察:
*/
int main() {
    int n;
    long long k;
    cin >> n >> k;
    int a, b;
    long long c[100001] = {0};
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        c[a] += b;
    }
    
    for(int i = 1; i <= 100000; i++){
        if(k <= c[i]){
            cout << i << endl;
            break;
        }
        k -= c[i];
    }
    return 0;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    ll ans = 0 , ans2=0;
    for(int i=0; i<s.size(); i++)
    {
        if (i%2==0)
        {
            if (s[i]=='1') ans++;
        }
        else
        {
            if (s[i] == '0') ans++;
        }
    }

    ans2 = ans;
    ans = 0;
    for(int i=0; i<s.size(); i++)
    {
        if (i%2)
        {
            if (s[i]=='1') ans++;
        }
        else
        {
            if (s[i] == '0') ans++;
        }
    }

    cout << min(ans,ans2);
	//
  
    return 0;
}

Measured memory_bytes: 3720
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 1000

struct edge{
	long long int to, cap, cost, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
long long int dist[MAX_V]; // 最短距離
int prevv[MAX_V], preve[MAX_V]; // 直前の頂点と辺

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap, long long int cost){
	G[from].push_back((edge){to, cap, cost, G[to].size()});
	G[to].push_back((edge){from, 0, -cost, G[from].size() - 1}); // 有向辺
}

// s から t への流量 f の最小費用流を求める( V は頂点数)
long long int min_cost_flow(int s, int t, int f, int V){
	
	long long int res = 0;
	
	while(f > 0){
		fill(dist, dist + V, INF);
		dist[s] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int v = 0; v < V; v++){
				if(dist[v] == INF){
					continue;
				}
				for(int i = 0; i < G[v].size(); i++){
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
		}
		if(dist[t] == INF){
			return -1;
		}
		
		long long int d = f;
		for(int v = t; v != s; v = prevv[v]){
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for(int v = t; v != s; v = prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(){
	
	int V, E, F;
	cin >> V >> E >> F;
	
	for(int i = 0; i < E; i++){
		int num1, num2, cap, cost;
		cin >> num1 >> num2 >> cap >> cost;
		add_edge(num1, num2, cap, cost);
	}
	
	cout << min_cost_flow(0, V - 1, F, V) << endl;
	
	return 0;
}


Measured memory_bytes: 3276
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: &str = itr.next().unwrap();
    let _: &str = itr.next().unwrap();
    let mut a: usize = itr.next().unwrap().parse().unwrap();
    let mut b: usize = itr.next().unwrap().parse().unwrap();
    let u: &str = itr.next().unwrap();
    if s == u {
        a -= 1;
    } else {
        b -= 1;
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int n,x,c,s;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x,c=max(c,x),s+=x;
    if(c<s-c)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin >> n;
    ll count=0;
    for(ll i=1;i<=n;i++)
    {
        ll temp;
        cin >> temp;
        if(i%2==1 && temp%2==1)
        {
            count++;
        }
    }
    cout << count;
}


Measured memory_bytes: 3564
def main():
    s = input()
    if s[1] == "S":
        if s[0] == "R" or s[2] == "R":
            print(1)
        else:
            print(0)
    else:
        count = 0
        for i in range(3):
            if s[i] == "R":
                count += 1
        print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61372
#include<iostream>
using namespace std;
#include<cmath>
#define int long long int
int answer=0;
int32_t main()
{
    int n;
    cin>>n;
    int arr[n];
    int j;
    for(j=0;j<n;j++)
    {
		cin>>arr[j];
		--arr[j];
	}
	//bool visited[n]={false};
	for(j=0;j<n;j++)
	{
        if(arr[arr[j]]==j)
           answer++;
	}
	answer/=2;
	cout<<answer<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main ()
{
 int a,b;
 scanf("%d %d",&a,&b);
 if ( a == b ){
   printf("a == b\n");
} else if ( a < b ){
   printf("a < b\n");
} else if ( a > b ){
   printf("a > b\n");
};
 return 0;
}

Measured memory_bytes: 580
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

string s;

int main(){
    INIT;
    cin >> s;
    if(s.size() == 3)reverse(ALL(s));
    cout << s << endl;
}

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

void swap(int* x,int* y)
{
		if(*x > *y){int  t = *x;
		*x = *y;
		*y = t;
		}
}

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	swap(&a,&b);
	swap(&b,&c);
	swap(&a,&b);

	cout << a << " " << b << " " << c << endl;
	
	return 0;
	}

Measured memory_bytes: 3092