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

long long int org_tall_array[200000];

int main()
{
    int n;
    long long int sum_step_tall = 0;
    long long int current_tall_max = 0;

    scanf("%d", &n);

    for (int i = 0; i<n; i++)
    {
        scanf("%lld", &org_tall_array[i]);

        if (current_tall_max <= org_tall_array[i])
        {
            current_tall_max = org_tall_array[i];
        } else {
            sum_step_tall += (current_tall_max - org_tall_array[i]);
        }

    }


    printf("%lld", sum_step_tall);

    return 0;
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int cnt=0;  
    for(int i=0;i<a.size();i++){
        if(a[i]=='C'){
            cnt=1;}
        if(a[i]=='F'&&cnt==1){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC113B
{
    static class MainClass
    {

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



            string[] input1 = Console.ReadLine().Split(' ');
            int T = int.Parse(input1[0]);
            int A = int.Parse(input1[1]);


            string[] input2 = Console.ReadLine().Split(' ');
            var H = new List<int>();
            var l = new List<double>();
            for (int i = 0; i < N;i++){
                H.Add(int.Parse(input2[i]));
                l.Add(Math.Abs(A - (T - H[i] * 0.006)));
            }


            var min = l.Min();
            var idx = l.IndexOf(min);



            Console.WriteLine(idx + 1);

            return;


        }


    }

}






Measured memory_bytes: 13320
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,count,val;
	cin>>n;
	if (n==1){
        cout<<"1";
    	return 0;
    }
	vector<int> list;
	for(int i=1;i<=n;i++){
		count=0;
		val=i;
    	while(val%2==0){
        	count+=1;
			val=val/2;
		list.push_back(count);
        }	
    }
	sort(list.rbegin(), list.rend());
	cout<<pow(2,list[0]);
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
DH=10**15
DW=10**15
for h1 in range(1,h+1):
  h2=(h-h1)//2
  h3=h-h1-h2
  w1=w
  w2=w
  w3=w
  s1=h1*w1
  s2=h2*w2
  s3=h3*w3
  S=[s1,s2,s3]
  d0=max(S)-min(S)
  h2=h-h1
  h3=h-h1
  w1=w
  w2=w//2
  w3=w-w2
  s1=h1*w1
  s2=h2*w2
  s3=h3*w3
  S=[s1,s2,s3]
  d1=max(S)-min(S)
  DH=min([DH,d0,d1])
  
hx,wx=h,w
w=hx
h=wx
for h1 in range(1,h+1):
  h2=(h-h1)//2
  h3=h-h1-h2
  w1=w
  w2=w
  w3=w
  s1=h1*w1
  s2=h2*w2
  s3=h3*w3
  S=[s1,s2,s3]
  d0=max(S)-min(S)
  h2=h-h1
  h3=h-h1
  w1=w
  w2=w//2
  w3=w-w2
  s1=h1*w1
  s2=h2*w2
  s3=h3*w3
  S=[s1,s2,s3]
  d1=max(S)-min(S)
  DW=min([DW,d0,d1])
  
print(min(DH,DW))

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

string r(int n)
{
	if(n < 1200) return "ABC";
	else if(n < 2800) return "ARC";
	else return "AGC";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a;
	cin >> a;
	cout << r(a) << endl;
	return 0;
}


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

using namespace std;
#define ll long long

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;
    int all = 0;

    vector<int> arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        all = all ^ arr[i];
    }

    for(int i = 0; i< n;i++)
    {
        cout<<(all ^ arr[i])<<" ";
    }
    
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3932
#include <cstdio>
#include <utility>
#include <queue>
using namespace std;
#define max(a,b) ((a)>=(b)?(a):(b))
typedef pair<int,int> P;
int T[100002];
int main() {
	priority_queue<P> Q;
	int N,L;
	scanf("%d %d",&N,&L);
	for(int i=1;i<=N;i++) {
		int a;
		scanf("%d",&a);
		Q.push(P(a,i));
	}
	while(!Q.empty()) {
		P p=Q.top();Q.pop();
		T[p.second]=max(T[p.second-1],T[p.second+1])+(L-p.first);
	}
	int ans=0;
	for(int i=1;i<=N;i++) ans=max(ans,T[i]);
	printf("%d\n",ans);
}

Measured memory_bytes: 2292
#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=998244353;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}





int32_t main(){
	
	//FIO();
	
		int n;cin>>n;
		int array[n][3],dp[n][3];
		for(int i=0; i<n; i++){
			for(int j=0; j<3; j++){
				cin>>array[i][j];
			}
		}
		/*for(int i=0; i<n; i++)
			for(int j=0; j<3; j++){
				dp[i][j]=0;
			}
			*/
		dp[0][0]=array[0][0];dp[0][1]=array[0][1];dp[0][2]=array[0][2];
		for(int i=1; i<n; i++){
			for(int j=0; j<3; j++){
				if(j==0)
					dp[i][j]=max(dp[i-1][1],dp[i-1][2])+array[i][j];
				else if(j==1)
					dp[i][j]=max(dp[i-1][0],dp[i-1][2])+array[i][j];
				else
					dp[i][j]=max(dp[i-1][0],dp[i-1][1])+array[i][j];
			}
			
		}
		/*for(int i=0; i<n; i++){
			for(int j=0; j<3; j++){
				cout<<dp[i][j]<<" ";
			}
			cout<<"\n";
		}*/
			
		cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
	

	

	return 0;
		
	
		
		
}


Measured memory_bytes: 4992
#include <stdlib.h>
#include <stdio.h>
typedef long long int ll;
int main() {
	unsigned short *A, *B;

	int C[10001];
	int N;
	scanf("%d", &N);
	A = malloc(sizeof(short) * N + 1);
    B = malloc(sizeof(short) * N + 1);
    
    for (int i = 0; i <= 10000; i++) C[i] = 0;
    
    for (int i = 0; i < N; i++) {
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;
    }
    for (int i = 1; i <= 10000; i++) C[i] = C[i] + C[i - 1];
    for (int j = 1; j <= N; j++) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
    for (int i = 1; i <= N; i++) {
        if (i > 1) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
int main(){
	int n,m,x,y,tmp;
	int l[100000],r[100000];
	scanf("%d %d",&n,&m);
	for (int i = 0; i < m; ++i)
	{
		scanf("%d %d",&l[i],&r[i]);
	}
	x=l[0];
	y=r[0];
	for (int k = 0; k < m; ++k)
	{
		if (x<l[k])
		{
			x=l[k];
		}
		if (y>r[k])
		{
			y=r[k];
		}
	}
	if (y-x+1>0)
	{
		printf("%d\n",y-x+1);
	}else{
		printf("0\n");
	}
	
}

Measured memory_bytes: 896
#include <cstdio>
 
int main(){
    int n, m, sum;
    scanf("%d%d",&n,&m);
    int a[n][m],b[m],c[n];
    int i,j;
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i = 0; i < m; i++){
        scanf("%d",&b[i]);
    }
    for(i = 0; i < n; i++){
        c[i] = 0;
        for(j = 0; j < m; j++){
            c[i] = c[i] + a[i][j] * b[j];
        }
    }
    for(int i = 0; i < n; i++){
        printf("%d\n",c[i]);
    }
    return 0;
}


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

int main(){
    int n;
    static int64_t a[200000], am[200000];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
        am[i] = i+1 - a[i];
    }
    sort(am, am+n);
    int64_t ans = 0;
    for(int i=0;i<n;++i){
        auto itl = lower_bound(am, am+n, a[i]+i+1);
        auto itr = upper_bound(am, am+n, a[i]+i+1);
        ans += distance(itl, itr);
    }
    cout << ans << endl;

    return 0;
}

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

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

  double total = 0;

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    total += 1.0 / A;
  }

  cout << 1.0 / total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;

int main(){

  ll n;
  cin >> n;
  ll w[n];
  for(int i=0;i<n;i++)cin >> w[i];

  ll l=inf;
  for(int i=1;i<n;i++){
    ll s1=0,s2=0;
    for(int j=0;j<n;j++){
      if(j<=i)s1+=w[j];
      else s2+=w[j];
    }
    l=min(l,abs(s1-s2));
  }

  cout << l << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100],b[100],c[100];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<n;i++)cin>>c[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(i==n)continue;
		if(a[i+1]==a[i]+1){
			ans+=c[a[i]];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
//import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        String s=sc.next();
        int n=s.length();
        //if(n%2==0){
            int a=0,b=0;
            for (int i = 0; i < n; i++) {
                if(i%2==0){
                    if(s.charAt(i)=='0')a++;
                }else {
                    if(s.charAt(i)=='1')a++;
                }
            }
            for (int i = 0; i < n; i++) {
                if(i%2==0){
                    if(s.charAt(i)=='1')b++;
                }else {
                    if(s.charAt(i)=='0')b++;
                }
            }
            out.println(min(a,b));
        //}
        /*else {
            int a=0,b=0;
            for (int i = 0; i < n; i++) {
                if(i%2==0){
                    if(s.charAt(i)=='0')a++;
                }else {
                    if(s.charAt(i)=='1')a++;
                }
            }
        }*/
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc     {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}

Measured memory_bytes: 24920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    ll n,k;
    cin >> n >> k;
    ll mod = n % k;
    ll ans = min(mod, abs(mod - k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np 

N, M = map(int, input().split())
condition = np.array([input().split() for i in range(M)])
condition = condition.astype(np.int64)

finish = 0

for num in range(1000):
	x = str(num)
	if len(x) != N:
		pass
	else:
		array = list(map(int, x))
		check = 0

		for i in range(len(x)):
			for j in range(M):
				if condition[j][0] == i + 1 and condition[j][1] == array[i]:
					check += 1

		if check == M:
			print(x)
			finish = 1
			break

if finish == 0:
	print(-1)

Measured memory_bytes: 12508
#include <iostream>
#include<string>
#include<list>
#include<algorithm>
#include<cstdio>
using namespace std;


int main(){
    
    int n,t;
    cin>>n;
    list<int> V;
    string com;
    for(int i=0;i<n;i++){
        
        cin>>com;
        
        if(com[0]=='i'){
            cin>>t;
            V.push_front(t);
            
        }else if(com[6]=='F'){
                V.pop_front();
                //deleteLast
        }else if(com[6]=='L'){
                V.pop_back();
        }else if(com[0]=='d'){
                cin>>t;
                for(list<int>::iterator it = V.begin();it!=V.end();it++){
                    if(*it==t){
                        V.erase(it);
                        break;
                    }
                }
            }
    }
    int i=0;

    for(list<int>::iterator it = V.begin();it != V.end();it++){
       if(i++) cout<<' ';
       // printf("%d",*it);
    cout<<*it;
        }
        
    
    cout<<endl;




return 0;
}



Measured memory_bytes: 34340
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void dfs(int u, vector<set<int>>&adj, vector<int>&visited, int* count)
{
    visited[u]  = 1;
    *count = *count + 1;

    for(auto it = adj[u].begin(); it!=adj[u].end();it++)
    {
        if(!visited[*it])
            dfs(*it, adj, visited, count);
    }
    return;
}

void solve()
{

  int n,m;
  cin>>n>>m;

  vector<set<int> >adj(n);

  int i;

  for(i=0;i<m;i++)
  {
      int a,b;
      cin>>a>>b;

      a--;b--;
      adj[a].insert(b);
      adj[b].insert(a);
  }

  int ans = 0;

  vector<int>visited(n,0);

  for(i=0;i<n;i++)
  {
      if(!visited[i])
      {int count = 0;
        dfs(i,adj, visited, &count); ans = max(ans, count);}
  }
  cout<<ans;

  return;
}

int main()
{

  int t = 1;
  //cin>>t;

  while(t--)
    solve();

  return 0;
}


Measured memory_bytes: 44616
import sys
readline = sys.stdin.readline
N, Q = map(int, readline().split())
T = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, readline().split())
    T[a - 1].add(b - 1)
    T[b - 1].add(a - 1)

ans = [0] * N
for _ in range(Q):
    p, x = map(int, readline().split())
    ans[p - 1] += x

done = set()
for s in range(N):
    if s in done:
        continue
    todo = [s]
    while todo:
        c = todo.pop()
        for n in T[c]:
            if not n in done:
                todo.append(n)
                ans[n] += ans[c]
        done.add(c)

print(" ".join(map(str, ans)))

Measured memory_bytes: 98296
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

//繰り返し二乗法
ll EX(ll x,ll n){
    if(n == 0) return 1;
    else if(n%2 == 1) return EX(x,n-1)*x%mod;
    else return EX(x*x%mod,n/2)%mod;
};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> mp(n,0);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    bool end = false;
    if(mp[0] != 1 && n%2 == 1) end = true;
    else if(mp[0] != 0 && n%2 == 0) end = true; 
    for(ll i = 1; i < n; i++){
        if(mp[i] != 2 && mp[i] != 0) end = true;
    }
    if(end){
        cout << 0 << endl;
        return 0;
    }
    cout << EX(2,n/2) << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define MAXN 3001
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL {printf("-1\n"); return 0;}

int N;
int A[MAXN];
LL dp[MAXN][MAXN][2];
int B[MAXN][MAXN][2];

LL f(int i, int j, int p) {
    if (B[i][j][p]) return dp[i][j][p];
    B[i][j][p] = 1;

    LL &ret = dp[i][j][p];
    if (i == j) 
        ret = (p == 0) ? A[i] : -A[i];
    else if (p == 0) 
        ret = max(A[i] + f(i+1,j,1-p), A[j] + f(i,j-1,1-p));
    else 
        ret = min(f(i+1,j,1-p) - A[i], f(i,j-1,1-p) - A[j]);

    return ret;
}

int main(int argc, char **argv)
{
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);

    printf("%lld\n", f(0,N-1,0));
    return 0;
}


Measured memory_bytes: 211456
/*
				   _ooOoo_
				  o8888888o
				  88" . "88
				  (| -_- |)
				  O\  =  /O
			   ____/`---'\____
			 .'  \\|     |//  `.
			/  \\|||  :  |||//  \
		   /  _||||| -:- |||||-  \
		   |   | \\\  -  /// |   |
		   | \_|  ''\---/''  |   |
		   \  .-\__  `-`  ___/-. /
		 ___`. .'  /--.--\  `. . __
	  ."" '<  `.___\_<|>_/___.'  >'"".
	 | | :  `- \`.;`\ _ /`;.`/ - ` : | |
	 \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
				   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		fozubaoyou    pass System Test!
		quoted from "https://codeforces.com/contest/472/submission/7996840"
*/
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
#define PI acos(-1)
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void){

	int n;
	cin>>n;
	vll a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	ll asum=0,bsum=0;
	rep(i,n){
		asum+=a[i];
		bsum+=b[i];
	}
	if(asum<bsum){
		fin(-1);
		return 0;
	}

	asum-=bsum;
	vector<int> rest;
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]>b[i])rest.push_back(a[i]-b[i]);
		else if(a[i]==b[i])continue;
		else ans++;
	}
	Sort(rest);
	int pos=0;
	// rep(i,rest.size()){
	// 	cout<<rest[i]<<" ";
	// }
	// cout<<endl;
	while(pos<rest.size()){
		// cout << rest[pos] << " " << asum << " " <<ans <<endl; 
		if(rest[pos]<=asum){
			asum-=rest[pos];
			pos++;
		} else {
			ans++;
			pos++;
		}
	}
	if(asum>0&&ans==0){
		ans++;
	}
	fin(ans);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t=1,q;
	//cin>>t;
	for(q=1;q<=t;q++)
	{
		int n,m;
		cin>>n;
		int a[n],dpa[n],b[n],dpb[n],c[n],dpc[n],i;
		for(i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
		dpa[0]=a[0];
		dpb[0]=b[0];
		dpc[0]=c[0];
		for(i=1;i<n;i++)
		{
			dpa[i]=a[i]+max(dpb[i-1],dpc[i-1]);
			dpb[i]=b[i]+max(dpa[i-1],dpc[i-1]);
			dpc[i]=c[i]+max(dpa[i-1],dpb[i-1]);
		}
		m=max(dpa[n-1],dpb[n-1]);
		m=max(dpc[n-1],m);
		cout<<m<<"\n";
	}
	return 0;
}

Measured memory_bytes: 2560
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	double n,m;
	cin >> n >> m;
	vector<double> a(n);
	double s=0;
    int c=0;
    
	REP(i,n){
		cin >> a[i];
		s +=a[i];
	}
	REP(i,n){
		if(a[i]>=(s/(4*m))){
			c++;
		}
	}
	if(c>=m)cout << "Yes" <<endl;
	else cout << "No" <<endl;
}


Measured memory_bytes: 256
require 'matrix'

loop do
    n = gets.to_i
    break if n == 0
    s, t, b = gets.chomp.split.map{|c| c.ord - ?A.ord}

    d = [2, 1, 2,
         1, 0, 1,
         2, 1, 2]
    d[b-3] += 1 if b > 2
    d[b-1] += 1 if b % 3 > 0
    d[b+1] += 1 if b % 3 < 2
    d[b+3] += 1 if b < 6

    m = Matrix.build(9, 9) do |i, j|
        if j == i
            d[i] / 4.0
        elsif j == b
            0
        elsif i / 3 == j / 3 && (i - j).abs == 1
            0.25
        elsif i % 3 == j % 3 && (i - j).abs == 3
            0.25
        else
            0
        end
    end

    a = [0] * 9
    a[s] = 1.0
    v = Matrix[a]
    p (v * m ** n)[0, t]
end

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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(a>=b){
    cout << "delicious";
  }else if(a+x>=b){
    cout << "safe";
  }else{
    cout << "dangerous";
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!

    var runLength = mutableListOf<Int>()
    var idxToCount = mutableListOf<Int>()
    var idx = 0
    for (i in 0 until n) {
        if (s[i] == s[idx]) continue
        runLength.add(s[idx].toInt() - '0'.toInt())
        idxToCount.add(i - idx)
        idx = i
    }
    runLength.add(s[idx].toInt() - '0'.toInt())
    idxToCount.add(n - idx)

    var cumsum = mutableListOf(0)
    for (x in idxToCount) {
        cumsum.add(cumsum.last() + x)
    }

    val fistIdx = 0
    val lastIdx = cumsum.lastIndex
    var left = fistIdx
    var right = Math.min(k * 2 + runLength.first(), lastIdx)
    var ans = 0
    while (true) {
        ans = Math.max(ans, cumsum[right] - cumsum[left])
        if (right == lastIdx) break
        right += 2
        left = Math.max(right - k * 2 - 1, fistIdx)
        right = Math.min(right, lastIdx)
    }

    println(ans)
}


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

int main() {
	int N, T, l, r;
	cin >> N >> T;
	vector<int> a(1 + T);
	for (int i = 0; i < N; ++i) {
		cin >> l >> r;
		++a[l];
		--a[r];
	}
	for (int i = 1; i < 1 + T; ++i) a[i] += a[i - 1];
	cout << *max_element(a.begin(), a.end()) << endl;
}


Measured memory_bytes: 3128
N,T=map(int,input().split())
G=[list(map(int,input().split())) for _ in range(N)]

G.sort()
dp=[0]*(60000)
for g in G:
    for i in range(T-1,-1,-1):
        dp[i+g[0]]=max(dp[i+g[0]],dp[i]+g[1])
print(max(dp))


Measured memory_bytes: 46056
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();

		System.out.println(N % K == 0 ? 0 : 1);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 22740
N = gets.to_i
b = gets.split.map(&:to_i)
ans = []

N.times do
  (1..N).reverse_each do |i|
    if b[i-1] == i
      ans << b.delete_at(i-1)
      break
    end
  end
end

puts ans.size == N ? ans.reverse : -1

Measured memory_bytes: 1916
n = int(input())
pi = list(map(int, input().split()))

#print(pi)

ans=0
for i in range(n-2):
    if (pi[i+2] < pi[i+1] and pi[i+1] <= pi[i]) or (pi[i] < pi[i+1] and pi[i+1] <= pi[i+2]):
        ans += 1

print(ans)


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  ans = (a * x) + (b * y);
  int harfCnt = 0, harf;
  harfCnt = min(x, y);
  harf = harfCnt * c * 2;
  harf += (x - harfCnt) * a < 0 ? 0 : (x - harfCnt) * a;
  harf += (y - harfCnt) * b < 0 ? 0 : (y - harfCnt) * b;
  chmin(ans, harf);
  harfCnt = max(x, y);
  harf = harfCnt * c * 2;
  harf += (x - harfCnt) * a < 0 ? 0 : (x - harfCnt) * a;
  harf += (y - harfCnt) * b < 0 ? 0 : (y - harfCnt) * b;
  chmin(ans, harf);
  print(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
int main()
{
    ll n, m, x, y, z, a, b, c, d;
    cin >> x >> y;
    z = x % y;
    cout << min(z, y - z) << endl;
//    main();
}



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

using namespace std;
using namespace atcoder;

int main(){
  int n, q;
  scanf("%d %d", &n, &q);
  dsu d(n);
  for (int i = 0; i < q; i ++) {
    int t, u, v;
    scanf("%d %d %d", &t, &u, & v);
    if (t == 0){
      d.merge(u, v);
    }
    else{
      if (d.same(u, v)){
        printf("1\n");
        //cout << "a" << d.leader(u) << endl;
        //cout << "b" << d.size(u) << endl;
      }
      else{
        printf("0\n");
      }
      
    }
    
  }
    
  return 0;
  
}  

Measured memory_bytes: 4072
l, r = map(int, input().split())

result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
    for j in range(i + 1, min(i + 2019, r) + 1):
        mod = i * j % 2019
        if result is None or result > mod:
            result = mod
            if result == 0:
                break
    if result is not None and result == 0:
        break
print(result)


Measured memory_bytes: 39024
def read():
	return [int(i) for i in input().split(" ")]

def calculate(x, y):
	if(y % x == 0):
		return x * (2 * (y / x) - 1) 
	else:
		return x * 2 * (y // x) + calculate(y % x, x) 
(N, X) = read()
length = N + calculate(X, N - X)
print(int(length))

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define inrep(t) int t;cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;


int main(){
	ios_base::sync_with_stdio(false); 
	int n,a,b; 
	cin>>n>>a>>b;
	if(a>b) swap(a,b); 
	if((b-a-1)%2==0){
		cout<<"Borys"; 
	}
	else {
		cout<<"Alice"; 
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int64_t gcd(int64_t a, int64_t b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int64_t lcm(int64_t a, int64_t b)
{
    return a * b / gcd(a, b);
}

int main() {

    int64_t A, B;
    std::cin >> A >> B;

    std::cout << lcm(A, B) << std::endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
ftwo = int(s[:2])
ltwo = int(s[2:])

if ftwo > 12 and ltwo > 12:
    print('NA')
elif ltwo == 0 and 0 < ftwo <= 12:
    print('MMYY')
elif 0 < ltwo <=12 and ftwo == 0:
    print('YYMM')
elif ltwo == 0 or ftwo == 0:
    print('NA')
elif ftwo > 12 and 0 < ltwo <=12:
    print('YYMM')
elif 0 < ftwo <= 12 and ltwo > 12:
    print('MMYY')
else:
    print("AMBIGUOUS")




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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

void run(void){
  int n;
  scanf("%d",&n);
  int a[256];
  int i,j,k;
  for(i=0;i<n*n;i++) scanf("%d",a+i);
  int64 *dp=(int64 *)calloc(1<<n,sizeof(int64));
  for(i=1;i<(1<<n);i++){
    int64 local=0;
    for(j=0;j<n;j++){
      if(((i>>j)&1)==0) continue;
      for(k=j+1;k<n;k++){
	if(((i>>k)&1)==0) continue;
	local+=a[j*n+k];
      }
    }
    for(j=(i-1)&i;j>0;j=(j-1)&i){
      local=MAX(local,dp[j]+dp[i^j]);
    }
    dp[i]=local;
  }
  printf("%lld\n",dp[(1<<n)-1]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<math.h>

using namespace std;

int main(){
	int gu, ki;
	int count=0;

	cin >> gu >> ki;

	//gu+gu,

	if (gu > 1) {
		count += gu * (gu - 1) / 2;
	}

	if (ki > 1) {
		count += ki*(ki-1)/2;
	}

	cout << count<<endl;
}

Measured memory_bytes: 256
import sys
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

Measured memory_bytes: 3064
divisor = 10 ** 9 + 7
h, w = map(int, input().split())
a = [input() for _ in range(h)]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
dp0 = dp[0]
a0 = a[0]
for j in range(1, w):
  if a0[j] != '#':
    dp0[j] = dp0[j - 1]
for i in range(1, h):
  dpi = dp[i]
  dpi1 = dp[i - 1]
  ai = a[i]
  if ai[0] != '#':
    dpi[0] = dpi1[0]
  for j in range(1, w):
    if ai[j] != '#':
      dpi[j] = (dpi1[j] + dpi[j - 1]) % divisor
print(dp[h - 1][w - 1])


Measured memory_bytes: 43636
def rec_water(total):
    if total > F:
        return
    else:
        water_amount.append(total)
        rec_water(total+100*A)
        rec_water(total+100*B)


# def rec_sugar(total):
#     if total > 1500:
#         return
#     else:
#         sugar_amount.append(total)
#         rec_sugar(total+C)
#         rec_sugar(total+D)


water_amount = []
sugar_amount = []
A, B, C, D, E, F = map(int, input().split())
rec_water(0)
for i in range(1501):
    for j in range(1501):
        sugar_amount.append(i*C+D*j)

water_amount = list(set(water_amount))
sugar_amount = list(set(sugar_amount))
water_amount.remove(0)

ans_sugar_water = min(water_amount)
ans_sugar = 0
percent = 0

# 1つ目は求める砂糖水の質量, 2つ目はそれに溶けている砂糖の質量
for w in water_amount:
    for s in sugar_amount:
        if w+s > F or s > E*(w/100):
            continue
        else:
            # 濃度が高ければ更新する
            if s / (w+s) > percent:
                ans_sugar_water = w+s
                ans_sugar = s
                percent = s / (w+s)
print(ans_sugar_water, ans_sugar)


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

int main(){
  string c;
  cin >> c;
  
  if(c=="a"){
    cout <<"a"<< endl;
  }
  else if(c=="b"){
    cout <<"a"<< endl;
  }
  else if(c=="c"){
    cout <<"a"<< endl;
  }
  else if(c=="d"){
    cout <<"a"<< endl;
  }
  else if(c=="e"){
    cout <<"a"<< endl;
  }
  else if(c=="f"){
    cout <<"a"<< endl;
  }
  else if(c=="g"){
    cout <<"a"<< endl;
  }
  else if(c=="h"){
    cout <<"a"<< endl;
  }
  else if(c=="i"){
    cout <<"a"<< endl;
  }
  else if(c=="j"){
    cout <<"a"<< endl;
  }
  else if(c=="k"){
    cout <<"a"<< endl;
  }
  else if(c=="l"){
    cout <<"a"<< endl;
  }
  else if(c=="m"){
    cout <<"a"<< endl;
  }
  else if(c=="n"){
    cout <<"a"<< endl;
  }
  else if(c=="o"){
    cout <<"a"<< endl;
  }
  else if(c=="p"){
    cout <<"a"<< endl;
  }
  else if(c=="q"){
    cout <<"a"<< endl;
  }else if(c=="r"){
    cout <<"a"<< endl;
  }else if(c=="s"){
    cout <<"a"<< endl;
  }else if(c=="t"){
    cout <<"a"<< endl;
  }else if(c=="u"){
    cout <<"a"<< endl;
  }else if(c=="v"){
    cout <<"a"<< endl;
  }else if(c=="w"){
    cout <<"a"<< endl;
  }else if(c=="x"){
    cout <<"a"<< endl;
  }else if(c=="y"){
    cout <<"a"<< endl;
  }else if(c=="z"){
    cout <<"a"<< endl;
  }
  else{
    cout << "A" << endl;
  }
}
  

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll a,b;
    cin >>a>>b;

    if(b>=a){
        cout<<a<<endl;
    }else{
        cout<<a-1<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  string S;
  cin>>N>>S;
  int n=0;
  for(int i=0;i<N;i++)
    if(S[i]=='.')
      n++;
  int ans=n;
  for(int i=0;i<N;i++){
    if(S[i]=='#')
      n++;
    else
      n--;
    ans=min(ans,n);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3724
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
bool judge1(char str1[],char str2[]) {
	int a[27] = { 0 };
	int len1 = strlen(str1);
	int len2 = strlen(str2);
	if (len1 != len2) return false;
	for (int i = 0;i < len1;i++) {
		a[str1[i] - 'a']++;
		a[str2[i] - 'a']--;
	}
	for (int i = 0;i < 27;i++) {
		if (a[i] != 0)return false;
	}
	return true;
}
bool judge2(char str1[], char str2[]) {
	int len1 = strlen(str1);
	int len2 = strlen(str2);
	for (int i = 0;i < len1;i++) {
		if (str1[i] != str2[i])
			return false;
	}
	return true;
}
int main() {
	char str1[maxn], str2[maxn];
	scanf("%s %s", str1, str2);
	if (judge1(str1, str2) == true) {
		int len1 = strlen(str1);
		for (int i = 0;i < len1 && judge2(str1, str2)==false;i++) {
			reverse(str1, str1 + len1 - 1);
			reverse(str1, str1 + len1);
		}
		if (judge2(str1, str2)) {
			printf("Yes");
		}else printf("No");
	}
	else {
		printf("No");
	}
	putchar('\n');
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct RangeAddQuery {
	int n;
	vector<T>d;
	RangeAddQuery(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, 0);
	}
	void add(int a, int b, T x = -1, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;

		if (r <= a || b <= l)return;
		else if (a <= l&&r <= b) {
			if (x >= 0)d[k] += (r - l)*x;
			return;
		}
		else {
			if (d[k] != 0) {
				d[2 * k] += d[k] / 2;
				d[2 * k + 1] += d[k] / 2;
				d[k] = 0;
			}
			add(a, b, x, 2 * k, l, (l + r) / 2);
			add(a, b, x, 2 * k + 1, (l + r) / 2, r);
		}
	}
	T get(int i) {
		add(i, i + 1);
		return d[n + i];
	}

};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeAddQuery<int>raq(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int x; cin >> x;
			cout << raq.get(x-1) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			raq.add(s-1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4872
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

constexpr int MOD = 1000000007;

int main()
{
    int N, J = 0, K = 0, L = 0;
    cin >> N;

    vector<int> st(N * 2 + 1);
    REP(_, N)
    {
        int A, B;
        cin >> A >> B;
        if (A < 0 and B > 0) st[B] = 1, K++;
        else if (A > 0 and B < 0) st[A] = 1, K++;
        else if (A > 0 and B > 0) st[A] = st[B] = 2, L++;
        else J++;
    }

    vector<vector<int>> dp[2];
    REP(d, 2) ndarray(dp[d], N - L + 1, K + 1);
    dp[0][0][0] = 1;

    int G = 0, H = 0, t = 0;

    REP(i, 2 * N)
    {
        int s = st[2 * N - i];
        if (s == 2) continue;
        else if (s)
        {
            REP(j, N - L + 1) IREP(k, K + 1)
            {
                dp[t][j][k] = (j < N - L ? dp[t][j + 1][k] : 0) + (k ? dp[t][j][k - 1] : 0);
                if (dp[t][j][k] >= MOD) dp[t][j][k] -= MOD;
            }
            H++;
        }
        else
        {
            dp[!t].assign(N - L + 1, vector<int>(K + 1));
            REP(j, N - L + 1) REP(k, K + 1) if (dp[t][j][k])
            {
                int pa2 = G + H - j - k - (H - k) * 2;
                if (j < N - L) (dp[!t][j + 1][k] += dp[t][j][k]) %= MOD;
                if (j)
                {
                    dp[!t][j - 1][k] = (dp[!t][j - 1][k] + dp[t][j][k] * (long long int)(J - pa2 / 2)) % MOD;
                }
                if (k)
                {
                    dp[!t][j][k - 1] = (dp[!t][j][k - 1]+ dp[t][j][k] * (long long int)k) % MOD;
                }
            }
            G++;
            t = !t;
        }
    }
    cout << dp[t][0][0] << endl;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d", $n);
$x = [0];
for ($i = 0; $i < $n - 1; $i++) {
	fscanf(STDIN, "%d %d %d", $c, $s, $f);
	foreach ($x as &$t) {
		if ($t < $s) $t = $s;
		$t += ($f - $t % $f) % $f + $c;
	}
	$x[] = 0;
}
echo implode("\n", $x);

Measured memory_bytes: 4728
function main(input) {
    const args = input.split("\n");
    const h = parseInt(args[0], 10);
    const w = parseInt(args[1], 10);
    const n = parseInt(args[2], 10);
    const res = Math.min(Math.ceil(n/h), Math.ceil(n/w));
    console.log(res);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()

x = -1
for i in range(500):
    if N == i * (i + 1) // 2:
        x = i

if x == -1:
    print('No')
    exit()

print('Yes')
print(x + 1)
num = [i + 1 for i in range(N)]
S = [[0] * x for _ in range(x + 1)]
k = 0
for i in range(x):
    for j in range(i, x):
        S[i][j] = num[k]
        S[j + 1][i] = num[k]
        k += 1

for s in S:
    print(len(s), ' '.join(map(str, s)))


Measured memory_bytes: 9752
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

#define MAX 1000000005
#define INF INT_MAX

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

int main(int, char**)
{
    int n;
    ll k;
    cin >> n >> k;

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

    vector<bool> touch(n, false);
    int now, strt;

    now = 0;
    while(!touch[now]) {
        touch[now] = true;
        now = a[now];
    }
    strt = now;

    int c1 = 0, c2 = 0;
 
    now = 0;
    while (now != strt) {
        now = a[now];
        c1++;
    }
    while (a[now] != strt) {
        now = a[now];
        c2++;
    }
    c2++;
 
    if (k > c1) k = (k-c1)%c2 + c1;
    now = 0;
    rep(i,k) now = a[now];
 
    cout << now+1 << endl;

    return 0;
}

Measured memory_bytes: 4060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        if (a * n < b) {
            System.out.println(a * n);
        } else {
            System.out.println(b);
        }
    }
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a;
    int cnt5 = 0, cnt7 = 0;
    rep(i, 3)
    {
        cin >> a;
        if (a == 5)
            cnt5++;
        if (a == 7)
            cnt7++;
    }

    if (cnt5 == 2 && cnt7 == 1)
        OP("YES");
    else
        OP("NO");
    return 0;
}

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

int main(){
	using namespace std;

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int cas = 1;
	//cin >> cas;
	while(cas--){
		int n;
		cin >> n;
		int res = 0;
		for(int i=0; i<n; ++i){
			int x, y;
			cin >> x >> y;
			if(res==3)break;
			if(x==y){
				++res;
			}
			else res = 0;
		}
		cout << (res == 3 ? "Yes" : "No")<< "\n";
	}
	return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

signed main() {
  int a, b, c, d, cd;
  cin >> a >> b >> c >> d;
  cd = c * d / gcd(c, d);
  int mulc, muld, mulcd;
  mulc = (b / c) - ((a - 1) / c);
  muld = (b / d) - ((a - 1) / d);
  mulcd = (b / cd) - ((a - 1) / cd);
  print(b - a + 1 - (mulc + muld - mulcd));
}


Measured memory_bytes: 256
N,M = map(int,input().split())
H = [int(i) for i in input().split()]
ABs = [[int(i) for i in input().split()] for j in range(M)]

Flags = [True for i in range(N)]

for i,j in ABs:
    i -= 1
    j -= 1
    a = H[i]
    b = H[j]
    if a>b:
        Flags[j] = False
    elif b>a:
        Flags[i] = False
    else:
        Flags[i],Flags[j] = False,False

ans = sum([1 if i else 0 for i in Flags])
print(ans)

Measured memory_bytes: 31140
let a, b, k = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let g x y = x / 2, y + x / 2
let rec f i (a, b) = if i >= k then a, b else f (i + 1) @@ if i mod 2 = 0 then g a b else let b, a = g b a in a, b
let x, y = f 0 (a, b)
let _ = Printf.printf "%d %d\n" x y

Measured memory_bytes: 384