akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

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

double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;

int yesno(bool flag, string yes, string no) {
	if (flag)cout << yes << endl;
	else cout << no << endl;
	return 0;
}

int printint(int n) {
	cout << n << endl;
	return 0;
}

int prints(string s) {
	cout << s << endl;
	return 0;
}

int a[114514];
int value;

int main() {

	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1; i <= n + 1; i++) {
		value += abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i <= n; i++) {
		cout << value - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cmath>
#include<algorithm>

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

    std::cin >> a >> b;

    for(long long int i = 0; i < std::max(a, b); i++){
        if(std::abs(a - i) == std::abs(b - i)){
            std::cout << i << std::endl;
            return 0;
        }
    }

    std::cout << "IMPOSSIBLE" << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
use proconio::*;

fn check(l: usize, k: usize, a: &Vec<usize>) -> bool {
    let mut cnt = 0;
    for &i in a.iter() {
        cnt += (i-1) / l;
    }

    cnt <= k
}

/*

15 5 3
16 5 4

*/

fn main() {
    input!{
        n: usize,
        k: usize,
        a: [usize; n],
    }

    if k == 0 {
        let mut ans = *a.iter().max().unwrap();
        println!("{}", ans);
        return;
    }

    let mut l = 0usize;
    let mut r = *a.iter().max().unwrap();

    while r-l > 1 {
        let mid = (l+r)/2;
        if check(mid, k, &a) {
            r = mid;
        } else {
            l = mid;
        }
    }

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


Measured memory_bytes: 5400
n,m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]
for i in range(10001):
    if len(str(i)) != n:
        continue
    for j in l:
        if str(i)[j[0]-1] != str(j[1]):
            break
    else:
        print(i)
        exit()
else:
    print(-1)

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

int main()
{
    string s = "abcdefghijklmnopqrstuvwxyz";
	char c;
 	cin >> c;
  	cout << s.substr(c-'a'+1, 1) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double sum = 0;
        for (int i = 0; i < n; i++) {
            double x = sc.nextDouble();
            String u = sc.next();
            if (u.equals("JPY")) {
                sum += x;
            } else if (u.equals("BTC")) {
                sum += x * 380000.0;
            }
        }
        System.out.println(sum);
    }
}

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

int main(){
  int n,m,k; cin>>n>>m>>k;
  vector<int> a(n), b(m);
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<m; i++) cin>>b[i];
  
  vector<long long> a_b(n+1), b_b(m+1);
  a_b[0]=0;
  b_b[0]=0;
  for (int i=1; i<n+1; i++) a_b[i]=a[i-1]+a_b[i-1];
  for (int i=1; i<m+1; i++) b_b[i]=b[i-1]+b_b[i-1];
  
  int ans=0;
  for (int i=0; i<n+1; i++){
    int remain=k-a_b[i];
    if (remain<0){
      break;
    }
    int t_ans=i;
    t_ans+=upper_bound(b_b.begin(),b_b.end(),remain)-b_b.begin()-1;
    ans=max(ans,t_ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7964
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
 
struct node {
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
 
typedef struct node* Node;
Node root;

void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int i,n,x;
  char c[5];
   
  scanf("%d",&n);
   
  for(i=0;i<n;i++) {
    scanf("%s",c);
    if(c[0] == 'i') {
      scanf("%d",&x);
      insert(x);
    }
    else if(c[0] == 'p') {
      if(root != NIL) { 
	inorder(root);
      }
      printf("\n");
      if(root != NIL){
	preorder(root);
      }
      printf("\n");
      
    }
  }
  return 0;
}

void insert(int k){
     
 Node y = NIL;
 Node x = root;
 Node z;
 
 z = malloc(sizeof(struct node));
 z->key = k;
 z->left = NIL;
 z->right = NIL;
    
 while(x != NIL) {
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
 }
 z->parent = y;
 
 if(y == NIL){
   root = z;
 }
 else if(z->key < y->key){
   y->left = z;
 }
 else{
   y->right = z;
 }
}

void inorder(Node u){
  
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);
  }
}

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

long long int N,B,A;
vector<long long int> V;

bool check(long long int mid)
{
    long long int sum = 0;
    for(int i = 0; i < N; i++)
    {
        if(V[i] > mid * B)
        {
            sum += (V[i] - mid * B + A - B - 1) / (A - B);
        }
    }
    if(mid >= sum)
    {
        return true;
    }
    return false;
}

void solve()
{
    long long int ans = 1000000000;
    long long int l = 0,r = 1000000001;
    while(r - l > 1)
    {
        long long int mid = (l + r) / 2;
        if(check(mid))
        {
            ans = min(ans,mid);
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    printf("%lld\n",ans);
}

int main()
{
    scanf("%lld%lld%lld",&N,&A,&B);
    for(int i = 0; i < N; i++)
    {
        int h;
        scanf("%d",&h);
        V.push_back(h);
    }
    sort(V.begin(),V.end());
    solve();
    return 0;
}


Measured memory_bytes: 1400
N, D = map(int, input().split())
t = []
for i in range(N):
    t.append(list(map(int, input().split())))
ans = 0
s = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(D):
            s += (t[i][k]-t[j][k])**2
        if (s ** 0.5).is_integer():
            ans += 1
        s = 0
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
 
int main(){
  int a, b; cin >> a >> b;
  for (int i=1; i<=3; i++){
      if(a != i && b != i){
        cout << i << endl;
        return 0;
      }
  }
}

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

int main(){
  int N;
  cin >> N;
  
  for (int i=0; i<N; i++){
    string color;
    cin >> color;
    if (color == "Y"){
      cout << "Four" << endl;
      break;
    }
    
    else if (i == N-1) {
      cout << "Three" << endl;
    }
  }
}




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

int main() {
	int n,a,b;cin >> n >> a>> b;
	string s; cin >> s;
	int cnt_d = 0;
	int cnt_o = 0;
	vector<string> v;
	for(int i=0;i<s.size();++i){
		auto sub = s.substr(i,1);
		if(sub == "a"){
			if(cnt_d + cnt_o < a+b) {
				v.push_back("Yes");
				++cnt_d;
			} else{
				v.push_back("No");
			}
		} else if (sub == "b"){
			if(cnt_d + cnt_o < a+b && cnt_o < b) {
				v.push_back("Yes");
				++cnt_o;
			} else {
				v.push_back("No");
			}
		} else {
			v.push_back("No");
		}
	}
	
	for (int j =0; j< v.size();++j) cout << v[j] << endl;
	return 0;
}

Measured memory_bytes: 6260
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

constexpr array<int, 10> cost = { -1,2,5,5,4,5,6,3,7,6 };

int calc_cost(deque<int> d) {
	int res = 0;
	while (!d.empty()) {
		int v = d.front(); d.pop_front();
		res += cost[v];
	}
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;

	vi a(m);
	rep(i, m) cin >> a[i];

	vector<vector<deque<int>>> dp(n + 1, vector<deque<int>>(m));

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			int c = cost[a[j]];
			//cout << i << " " << j << endl;
			if (i - c >= 0 && calc_cost(dp[i - c][j]) + c == i) {
				deque<int> pre = dp[i - c][j];
				if (pre.size() == 0) pre.push_back(a[j]);
				else if (pre.front() > a[j]) pre.push_back(a[j]);
				else pre.push_front(a[j]);
				dp[i][j] = pre;
			}

			if (j != 0) {
				deque<int> pre = dp[i][j - 1];

				if (pre.size() < dp[i][j].size()) continue;
				else if (pre.size() > dp[i][j].size()) dp[i][j] = pre;
				else if (pre.size() == dp[i][j].size()) {
					if (pre.size() == 0) continue;

					deque<int> tmp1 = pre, tmp2 = dp[i][j];
					for (int k = 0; k < pre.size(); ++k) {
						int l = tmp1.front(), r = tmp2.front();
						tmp1.pop_front(), tmp2.pop_front();

						if (l > r) {
							dp[i][j] = pre;
							break;
						}
						else if (l < r) {
							break;
						}
					}
				}
			}
		}
	}

	int mx = dp[n][m - 1].size();
	rep(i, mx) {
		int v = dp[n][m - 1].front(); dp[n][m - 1].pop_front();
		cout << v;
	}
}

Measured memory_bytes: 958848
#include <iostream>
using namespace std;
void ABC60(void);
void ABC61(void);
void ABC62(void);
void ABC63(void);
void ABC64(void);
void ABC65(void);
void ABC66(void);
void ABC67(void);
void ABC68(void);
void ABC69(void);

int main(void){
    ABC67();
}

void ABC67(void){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

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

int main() {
	string s;
	cin >> s;

	int p = 0;
	int g = 0;

	int score = 0;
	for (char c : s) {
		if (c == 'p') {
			if (p < g) {
				p++;
			} else {
				g++;
				score--;
			}
		}
		if (c == 'g') {
			if (p < g) {
				p++;
				score++;
			} else {
				g++;
			}
		}
	}

	cout << score << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = null;
		String p = null;

		try {
			s = br.readLine();
			p = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}

		s = s + s + s;

		if (s.indexOf(p) != -1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 24304
#include<stdio.h>
int main()
{
  int a=0,n,m,i;
  scanf("%d",&n);
  while(n--)
    {
      scanf("%d",&m);
      for(i=2;i*i<=m;i++)
	{
	  if(m%i==0)
	    break;
	}
      if(i*i>m)
	a++;
    }
  printf("%d\n",a);
  return 0;
}



Measured memory_bytes: 2080
n=int(input())
a=list(map(int,input().split()))
cnt=0
while max(a)>=n:
  s=0
  for i in range(n):
    s+=a[i]//n
  for i in range(n):
    a[i]+=(s-a[i]//n)-(a[i]//n)*n
  cnt+=s
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    string m,s;
    for(int i=0;i<3;i++){
        cin >> m;
        s = s + m;
    }
    cout << s.substr(0,1) << s.substr(4,1) << s.substr(8,1) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    xy=[list(map(int,input().split())) for _ in [0]*n]
    ixy=[[i,x,y] for i,(x,y) in enumerate(xy)]
    class unionfind():
        #size:要素数,tree：unionfind木
        def __init__(self,size):#self,要素数
            self.size=size
            self.tree_root=list(range(self.size))
            self.tree_depth=[1]*self.size
        
        #rootを探す
        def root(self,index):
            temp_list=[]
            temp=self.tree_root[index]
            while index!=temp:
                temp_list.append(index)
                index=temp
                temp=self.tree_root[index]
            for i in temp_list:
                self.tree_root[i]=index
            return index
        
        #結合
        def unite(self,index1,index2):
            r1=self.root(index1)
            r2=self.root(index2)
            if r1!=r2:
                d1,d2=self.tree_depth[r1],self.tree_depth[r2]
                if d1<=d2:
                    self.tree_root[r1]=r2
                    self.tree_depth[r2]=max(d1+1,d2)
                else:
                    self.tree_root[r2]=r1
                    self.tree_depth[r1]=max(d2+1,d1)
    
        #同じか判定
        def same(self,index1,index2):
            r1=self.root(index1)
            r2=self.root(index2)
            return r1==r2
    
        #連結成分の個数
        def component(self):
            return len({self.root(i) for i in range(self.size)})

    u=unionfind(n)
    ixy.sort(key=lambda x:x[1])
    for i in range(n-1):
        if ixy[i][1]==ixy[i+1][1]:
            u.unite(ixy[i][0],ixy[i+1][0])
    ixy.sort(key=lambda x:x[2])
    for i in range(n-1):
        if ixy[i][2]==ixy[i+1][2]:
            u.unite(ixy[i][0],ixy[i+1][0])
    tate=[set() for _ in [0]*n]
    yoko=[set() for _ in [0]*n]
    cnt=[0]*n
    for i in range(n):
        r=u.root(i)
        tate[r].add(xy[i][0])
        yoko[r].add(xy[i][1])
        cnt[r]+=1
    print(sum([len(tate[i])*len(yoko[i])-cnt[i] for i in range(n)]))
main()

Measured memory_bytes: 91748
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define bit(n) (1LL<<(n))
typedef pair<i64,i64> P;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;

void Main()
{
  i64 N,W;
  cin >> N >> W;

  vi dp(W+1,0);
 
  i64 w,v;
  rep(i,N){
    cin >> w >> v;
    rrep(ii,W,w-1)
      maxs(dp[ii],dp[ii-w]+v);
  }

  i64 ans = 0;
  rep(i,W+1) maxs(ans,dp[i]);

  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    long long  i=0,j,n,c=0,d=0,e=0,f=0;
    cin>>n;
    set<long long> b;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b.insert(a[i]);
    }
    if(b.size()==n)
    {
        cout<<"YES";
    }
    else
        cout<<"NO";

}


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

int main() {
    int64_t a;cin>>a;
    int64_t b,n,R,L,RR,LL;cin>>b>>n;
    int64_t i=n/b-1;
    
    while(b*i-1<=n){
        i++;
    }
    int64_t x=b*(i-1)-1;
    R=(a*x)/b;
    L=x/b;
    RR=(a*n)/b;
    LL=n/b;
    cout<<max(R-a*L,RR-a*LL)<<endl;
        
}

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

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,d1,d2,cnt;
int col1[605][605],col2[605][605];
vector<pii> v1,v2;
set<pii> s1[605][605],s2[605][605];

bool in(int x,int y){return x>=0&&y>=0&&x<n+n&&y<n+n;}

void dfs1(int x,int y){
	for(auto v:s1[x][y]){
		if(col1[v.fi][v.se]>=0) continue;
		col1[v.fi][v.se]=col1[x][y]^1;
		dfs1(v.fi,v.se);
	}
}

void dfs2(int x,int y){
	for(auto v:s2[x][y]){
		if(col2[v.fi][v.se]>=0) continue;
		col2[v.fi][v.se]=col2[x][y]^1;
		dfs2(v.fi,v.se);
	}
}

int main(){
	n=readint(); d1=readint(); d2=readint();
	for(int i=0;i<=d1;i++) if((int)sqrt(d1-i*i)*(int)sqrt(d1-i*i)==d1-i*i) v1.push_back(mp(i,sqrt(d1-i*i)));
	for(int i=0;i<=d2;i++) if((int)sqrt(d2-i*i)*(int)sqrt(d2-i*i)==d2-i*i) v2.push_back(mp(i,sqrt(d2-i*i)));
	for(int i=0;i<n+n;i++){
		for(int j=0;j<n+n;j++){
			for(auto x:v1){
				if(in(i-x.fi,j-x.se)) s1[i][j].insert(mp(i-x.fi,j-x.se));
				if(in(i-x.fi,j+x.se)) s1[i][j].insert(mp(i-x.fi,j+x.se));
				if(in(i+x.fi,j-x.se)) s1[i][j].insert(mp(i+x.fi,j-x.se));
				if(in(i+x.fi,j+x.se)) s1[i][j].insert(mp(i+x.fi,j+x.se));
			}
			for(auto x:v2){
				if(in(i-x.fi,j-x.se)) s2[i][j].insert(mp(i-x.fi,j-x.se));
				if(in(i-x.fi,j+x.se)) s2[i][j].insert(mp(i-x.fi,j+x.se));
				if(in(i+x.fi,j-x.se)) s2[i][j].insert(mp(i+x.fi,j-x.se));
				if(in(i+x.fi,j+x.se)) s2[i][j].insert(mp(i+x.fi,j+x.se));
			}
		}
	}
	memset(col1,-1,sizeof(col1));
	memset(col2,-1,sizeof(col2));
	for(int i=0;i<n+n;i++){
		for(int j=0;j<n+n;j++){
			if(col1[i][j]<0) col1[i][j]=0,dfs1(i,j);
			if(col2[i][j]<0) col2[i][j]=0,dfs2(i,j);
		}
	}
	int dmyxg[2][2]={0};
	for(int i=0;i<n+n;i++) for(int j=0;j<n+n;j++) dmyxg[col1[i][j]][col2[i][j]]++;
	int maxa=0,optx=0,opty=0,ooo=0;
	for(int i=0;i<2;i++) for(int j=0;j<2;j++) if(chkmax(maxa,dmyxg[i][j])) optx=i,opty=j;
	for(int i=0;i<n+n;i++){
		for(int j=0;j<n+n;j++){
			if(col1[i][j]==optx&&col2[i][j]==opty){
				printf("%d %d\n",i,j);
				ooo++;
				if(ooo==n*n) exit(0);
			}
		}
	}
	return assert(0),0;
}

Measured memory_bytes: 572160
#include "bits/stdc++.h"
using namespace std;


int main() {

	int A, B, C;
	int flag = 0;

	cin >> A >> B >> C;

	if (A == B && B == C) {
		flag = 1;
	}

	if (flag == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}


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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i], ++A[i];
  vector<int> C(N+1);
  C[0] = 3;
  mint ans = 1;
  for(int i = 0; i < N; ++i){
    ++C[A[i]];

    ans *= C[A[i]-1];
    --C[A[i]-1];

  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
//蛇形填数

#include<stdio.h>

int main(){
	int H,W,N;int num[10001];int ans[100][100];
	scanf("%d%d",&H,&W);
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",&num[i]);
	}
	int hs=0,he=H-1,ws=0,we=W-1;
	int nowh=0,noww=0;
	bool flagr=true,flagd=false,flagl=false,flagt=false;
	for(int i=1;i<=N;i++){
		while(num[i]--){
			if(flagr){
				ans[nowh][noww++]=i;
				if(noww>we){
					flagr=false;
					noww=we;
					nowh++;
					hs++;
					flagd=true;
				}
			}
			else if(flagd){
				ans[nowh++][noww]=i;
				if(nowh>he){
					flagd=false;
					nowh=he;
					noww--;
					we--;
					flagl=true;
				}
			}
			else if(flagl){
				ans[nowh][noww--]=i;
				if(noww<ws){
					flagl=false;
					noww=ws;
					nowh--;
					he--;
					flagt=true;
				}
			}
			else if(flagt){
				ans[nowh--][noww]=i;
				if(nowh<hs){
					flagt=false;
					nowh=hs;
					noww++;
					ws++;
					flagr=true;
				}
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			printf("%d",ans[i][j]);
			if(j!=W-1)
				printf(" ");
			else
				printf("\n"); 
		}
	}
	return 0;
} 

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

int main() {
  int N; cin >> N;
  int P[200010];
  int ans = 0;
  int MIN = 100000000;

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

  for(int i=0; i<N; ++i) {
    if(P[i] <= MIN) ans++;
    MIN = min(MIN, P[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val i = readLine()!!.split(" ").map { it.toLong() }
    println(f(i[1], i[2], i[3]) - f(i[0]-1, i[2], i[3]))
}

fun f(b: Long, c: Long, d: Long): Long = b - (b/c + b/d - b/lcm(c, d))

fun gcd(a: Long, b: Long): Long = if(a < b) gcd(b, a) else if(b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)


Measured memory_bytes: 37820
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

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

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

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

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

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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector<int> imos(n + 1, 0);
    rep(i, n){
        ++imos[max(0, i - a[i])];
        --imos[min(n, i + a[i] + 1)];
    }
    rep(i, n){
        imos[i + 1] += imos[i];
    }

    bool flg = true;
    vector<int> dif(n);
    for(int t = 0 ; t < k && flg ; ++t){
        flg = false;
        rep(i, n){
            if(a[i] < n){
                flg = true;
            }
            a[i] = imos[i];
        }
        fill(imos.begin(), imos.end(), 0);
        rep(i, n){
            ++imos[max(0, i - a[i])];
            --imos[min(n, i + a[i] + 1)];
        }
        rep(i, n){
            imos[i + 1] += imos[i];
        }
    }

    rep(i, n){
        if(i) cout << ' ';
        cout << a[i];
    }
    cout << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 5580
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>0) printf("Positive\n");
    else if(b>=0) printf("Zero\n");
    else if((a&1)^(b&1)) printf("Positive\n");
    else printf("Negative\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vi G[1010];

int D[1010];

vi ans;

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].pb(b);
	}
	rep(i, 0, N + 1) ans.pb(0);

	rep(i, 0, N) {
		rep(j, 0, sz(G[i])) {
			int a = i, b = G[i][j];
			memset(D, -1, sizeof(D));
			queue<int> que; que.push(b);
			while(!que.empty()) {
				int v = que.front(); que.pop();
				rep(i, 0, sz(G[v])) {
					int n = G[v][i];
					if(D[n] == -1)  {
						D[n] = v;
						que.push(n);
					}
				}
			}
			if(D[a] != -1) {
				vi tmp;
				while(a != b) {
					tmp.pb(a);
					a = D[a];
				}
				tmp.pb(b);
				if(sz(ans) > sz(tmp)) ans = tmp;
			}
		}
	}
	if(sz(ans) > N) {
		cout << -1 << "\n";
	}
	else {
		cout << sz(ans) << "\n";
		rep(i, 0, sz(ans)) {
			cout << ans[i] + 1 << "\n";
		}
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	next := 0
	ans := 0
	hist := make(map[int]bool)
	for {
		if next == 1 {
			fmt.Println(ans)
			return
		}
		if hist[next] {
			break
		}
		hist[next] = true
		next = a[next] - 1
		ans += 1
	}
	fmt.Println(-1)

}


Measured memory_bytes: 6896
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(v[i]%2==0){
      a++;
      if((v[i]%3==0)||(v[i]%5==0)) b++;
    }
  }
  if(a==b){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M-1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str); //文字列を数値に変換
  for(i = 0; ;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s", com, str); //より高速な入力 scanfを使用

    if(com[0] == 'i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 16100
/**
 * @author: Jenniekim
 * @date  : 02-21-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int n;
int arr[100005], dp[100005];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }

    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);

    for(int i=3;i<=n;i++){
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout << dp[n] << el;
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n%10==n/100)cout<<"Yes\n";
	else cout<<"No\n";







  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int A,B,C;
  cin>>A>>B>>C;
  if((A==B&&B!=C)||(A==C&&B!=C)||(B==C&&A!=C))
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
R.sort(key = lambda x:x[1], reverse = True)
B.sort()
ans = 0
check = []


for bx, by in B:
    for i in range(N):
        if bx > R[i][0] and by > R[i][1] and i not in check :
            ans += 1
            check.append(i)
            break
            #print('B', bx, by, 'R',R[i][0], R[i][1] )
print(ans)

Measured memory_bytes: 3192
#!/usr/bin/env python
# coding: utf-8

# In[15]:


S = input()
T = input()


# In[16]:


len_s = len(S)
len_t = len(T)
ans = len_t
for i in range(len_s-len_t+1):
    tmp = S[i:i+len_t]
    cnt = 0
    for j in range(len_t):
        if tmp[j] != T[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)


# In[ ]:






Measured memory_bytes: 8980
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200010, P = 998244353;

int n;
int sieve[N * 2];
bool vs[N];
char s[N];

int mpow(int x, int k) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % P;
    x = x * (ll)x % P;
    k >>= 1;
  }
  return ret;
}

int norm(int x) { return x >= P ? x - P : x; }

void add(int& x, int y) {
  if ((x += y) >= P)
    x -= P;
}

void sub(int& x, int y) {
  if ((x -= y) < 0)
    x += P;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int solve(int x) {
  if (x / gcd(x, n) % 2)
    return 0;
  int p = 0;
  bool cur = false;
  int cnt = 0;
  do {
    vs[p] = cur;
    cur ^= ((p + x) / n) & 1;
    p = (p + x) % n;
    ++cnt;
  } while (p != 0);
  int sz = n / cnt, ret = 0;
  for (int i = 1; i <= sz; ++i)
    ret = (ret * 2 + s[n - i]) % P;
  for (int i = n - 1; i; --i) {
    int p = i % sz;
    bool dig = s[n - sz + p] ^ vs[i - p] ^ vs[n - sz];
    if (dig > s[i])
      return ret;
    if (dig < s[i])
      return norm(ret + 1);
  }
  return norm(ret + 1);
}

int main() {
  scanf("%d%s", &n, s);
  reverse(s, s + n);
  for (int i = 0; i < n; ++i)
    s[i] -= '0';
  for (int i = 1; i <= n * 2; ++i)
    if (n * 2 % i == 0)
      sieve[i] = i;
  for (int i = n * 2; i; --i)
    for (int j = i + i; j <= n * 2; j += i)
      sub(sieve[i], sieve[j]);
  int ans = 0;
  for (int i = 1; i <= n * 2; ++i)
    if (sieve[i]) {
      ans = (ans + sieve[i] * (ll)solve(i)) % P;
    }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (998244353)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
#define MAXN 300100
#define MAXP 100
/*
lli C[MAXN + 1][MAXP + 1];
void init()
{
    REP(i, MAXN + 1)
    {
        C[i][0] = 1;
    }
    REPS(i, MAXN)
    {
        REPS(j, MAXP)
        {
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
        }
    }
} */
lli extGcd(lli a, lli b, lli &x, lli &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        lli d = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    }
}
lli Fact[MAXN + 1];
lli FactInv[MAXN + 1];
void initG()
{
    vector<lli> invN(MAXN + 1);
    REPS(i, MAXN)
    {
        lli x, y;
        extGcd(i, MOD, x, y);
        x %= MOD;
        x = (x + MOD) % MOD;
        invN[i] = x;
    }
    Fact[0] = 1;
    FactInv[0] = 1;
    REPS(i, MAXN)
    {
        Fact[i] = (Fact[i - 1] * i) % MOD;
        FactInv[i] = (FactInv[i - 1] * invN[i]) % MOD;
    }
}
int main()
{
    initG();

    cin.tie(0);
    ios::sync_with_stdio(false);
    lli N, A, B, K;
    cin >> N >> A >> B >> K;
    // init();
    //   Ax + By = K x >= 0, y >= 0となるものを考える。
    lli x, y;
    lli d = extGcd(A, B, x, y);
    if (K % d != 0)
    {
        cout << 0 << "\n";
    }
    else
    {
        //   cout << d << "\n";
        A /= d;
        B /= d;
        K /= d;
        lli savey = y;
        x *= K;
        x %= B;
        x += B;
        x %= B;
        y = (K - A * x) / B;
        lli xa = x, ya = y;
        // x min +B -A
        // x=10,y=6,N=22  -> 10 6 0 6,9 5 1 7,8 4 2 8
        //cout << x << " " << y << "\n";
        y = savey * K;
        y %= A;
        y += A;
        y %= A;
        x = (K - B * y) / A;
        // y min
        lli xb = x;

        //cout << x << " " << y << "\n";
        lli i = xa;
        lli j = ya;
        lli ans = 0;
        if (j > N)
        {
            lli tmp = (j - (N + 1)) / A + 1;
            i += tmp * B;
            j -= tmp * A;
        }
        for (; i <= min(xb, N); i += B)
        {
            //      cout << i << " " << j << " "
            //          << "\n";
            lli tmp = (Fact[N] * Fact[N]) % MOD;
            tmp *= FactInv[i];
            tmp %= MOD;
            tmp *= FactInv[N - i];
            tmp %= MOD;
            tmp *= FactInv[j];
            tmp %= MOD;
            tmp *= FactInv[N - j];
            tmp %= MOD;
            ans += tmp;
            ans %= MOD;
            j -= A;
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 7296
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = (1LL << 63);


int main() {
	string s, t;
	cin >> s >> t;
	int ans = 100000;
	rep(i, 0, s.size()) {
		int sum = 0;
		bool z = 1;
		rep(j, 0, t.size()) {
			if (i + j == s.size()) {
				z = 0;
				break;
			}
			if (s[i + j] == t[j])sum++;
		}
		if(z)ans = min((int)ans, (int)t.size() - sum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 44


int main(){
  int i,n,f0=0,f1,f2;

  scanf("%d",&n);

  f1=1;

  for(i=1;i<MAX+1;i++){
    f2=f1+f0;
    f0=f1;
    f1=f2;

    if(i==n){
      printf("%d\n",f1);
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>

#include <map>
#include <string>


using namespace std;

int main()
{
	map<string, int> strs;
	string tmp;
	int n, ans = 0;

	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> tmp;

		strs.emplace(tmp, 0);
	}

	cout << strs.size() << "\n";

	return 0;

}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
int head[100005];
int next[400005];
int to[400005];
int weight[400005];
int v[400005] = {0};
int visited[400005] = {0};

int dfs(int crt){
//    printf("called crt = %d", crt);
    int e;
    int result = 0;
    e = head[crt];
    while (e != -1){
        if (visited[to[e]] == 0){
            visited[to[e]] = 1;
            v[to[e]] = v[crt] + weight[e];
            result = dfs(to[e]);
        }
        if (result == 1) return result;
        if (v[to[e]] != v[crt] + weight[e]) return 1;
        e = next[e];
    }
    return result;
}


int main(void){
    for (int i = 0; i < 200005; i++){
        head[i] = -1;
    }
    int n, m;
    int l, r, d;
    int cnt = 0;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++){
        scanf("%d %d %d", &l, &r, &d);
        next[cnt] = head[l]; 
        head[l] = cnt; 
        to[cnt] = r; 
        weight[cnt] = d;
        cnt++;

        next[cnt] = head[r];
        head[r] = cnt; 
        to[cnt] = l;
        weight[cnt] = -1*d;
        cnt++;
    }
    for (int i = 0; i < n; i++){
        if(dfs(i)){
            printf("No\n");
            return 0;
        }
    }
    
    
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 10112
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int n,d=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	  if(i%2==1) d++;
	double df=d,nf=n;
	cout<<fixed<<setprecision(10)<<df/nf;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();
		int ans = ((n + x - 1) / x) * t;
		System.out.println(ans);
	}

}

Measured memory_bytes: 27024
n = int(input())
txy = []
for i in range(n):
    t,x,y = map(int, input().split())
    txy.append([t, x, y])
txy.sort()
if n==1:
    if txy[0][1]+txy[0][2]!=txy[0][0]:
        print("No")
    else:
        print("Yes")
    exit()
for i in range(n-1):
    a = txy[i+1][0] - txy[i][0]
    ds = abs(txy[i+1][1]-txy[i][1]) + abs(txy[i+1][2]-txy[i][2])
    if a >= ds and (a-ds)%2==0:
        continue
    else:
        print("No")
        exit()
print("Yes")

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

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

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

int n_;
vector<int> dat;

void init(int size){
    //initialize size=a power of 2
    n_=1;
    while(n_ < size) n_*=2;
    dat.assign(2*n_-1, 0);
}

//a_id(0-indexed) -> val
void update(int id, int val){
    //id of leaf
    id+=n_-1;
    dat[id]=val;
    while(id > 0){
        id=(id-1)/2;
        dat[id]=max(dat[2*id+1], dat[2*id+2]);
    }
}

//get Min{a_i | s <= i < t}, [s, t)
//dat[id] interval -> [l, r)
//first, query(s, t, 0, 0, n_)
int query(int s, int t, int id, int l, int r){
    if(r <= s || t <= l) return 0;

    if(s <= l && r <= t) return dat[id];
    int vl=query(s, t, 2*id+1, l, (l+r)/2);
    int vr=query(s, t, 2*id+2, (l+r)/2, r);
    return max(vl, vr);
}

int main(){
    int N, K; cin >> N >> K;
    vi A(N);
    int mx=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        chmax(mx, A[i]);
    }

    init(mx+1);
    vi dp(N);
    int ans=0;
    for(int i=0; i<N; i++){
        dp[i]=query(max(0, A[i]-K), min(mx, A[i]+K)+1, 0, 0, n_)+1;
        update(A[i],dp[i]);
        chmax(ans, dp[i]);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll W, H, N;
    cin >> W >> H >> N;

    ll t = H, b = 0, l = 0, r = W;
    ll x, y, a;
    rep(i, N){
        cin >> x >> y >> a;
        switch(a){
            case 1:
                l = max(l, x);
                break;
            case 2:
                r = min(r, x);
                break;
            case 3:
                b = max(b, y);
                break;
            case 4:
                t = min(t, y);
                break;
        }
    }

    if(t <= b || l >= r){
        cout << 0 << endl;
    }else{
        cout << (t - b) * (r - l) << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int n,m,k;
int a[maxn];
int b[maxn];
ll suma[maxn];
ll sumb[maxn];


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
    }
    for(int i=1;i<=n;i++)
    {
        suma[i]=suma[i-1]+a[i];
    }
    for(int i=1;i<=m;i++)
    {
        sumb[i]=sumb[i-1]+b[i];
    }
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        if(suma[i]>k)
            break;
        int temp=k-suma[i];
        int p=upper_bound(sumb+1,sumb+1+m,temp)-sumb;
        ans=max(ans,i+p-1);
    }
    cout<<ans<<'\n';







}


Measured memory_bytes: 8356