akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP)
 { return firstP.first < secondP.first; }//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll n,q;
vector<Pair> v;

struct ru_wa{
	string s; //10^6
	ll sum_a[1000000] = {0}; //sum array

	void trigger(ll i){//i番目では、求める和はどうなりますか?(i-1番目と比べて)
		if(i!=0)sum_a[i] += sum_a[i-1];
		if(i!=0)if(s[i]=='C'&&s[i-1]=='A')sum_a[i]++;
	}/* ↑和の条件とか */

	void set(ll size){// size := 与えられる配列の大きさ
		rep(i,size+1)sum_a[i]=0;//init
		rep(i,size)trigger(i);
	}

	ll get_sum(ll l,ll r){// 閉区間[l,r]の和
		if(l>r)swap(l,r);
		if(l==0){
			return sum_a[r];
		}else{
			return sum_a[r] - sum_a[l];
		}
	}
	//set -> get_sum
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ru_wa r_w;
	cin>>n>>q>>r_w.s;
	r_w.set(n);
	ll lll,rrr;
	rep(i,q){
		cin>>lll>>rrr;
		v.pb(mp(lll,rrr));
	}
	rep(i,q){
		cout<<r_w.get_sum(v[i].first-1,v[i].second-1)<<endl;
	}
	return 0;
}


Measured memory_bytes: 10432
n, l_time = map(int, input().split())

idx = 0
minc = 1001

while idx < n:
    rc, rt = map(int, input().split())
    if rt <= l_time:
        if rc < minc:
          minc = rc
    idx = idx + 1

if minc == 1001:
    print('TLE')
else:
    print(minc)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    LR = [[int(i) for i in input().split()] for _ in range(N)]

    # 区間を右端の小さい順にソート
    LR = sorted([(x-l, x+l) for x,l in LR],key=lambda x: x[1])

    ans = 0
    # 現在選んでいる区間の内、最も右にある区間の右端
    cur_R = -float("inf")

    for i in range(N):
        # 区間が被るとき
        if cur_R > LR[i][0]:
            continue
        ans += 1
        cur_R = LR[i][1]

    print(ans)

if __name__ == "__main__":
    main()

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

#define Death Komachi
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;i++)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;i--)
#define DB double
#define M 2004

int n,A[M],s,Mn,Ans;
bitset<M*M>B;
int main(){
	scanf("%d",&n);
	REP(i,0,n)scanf("%d",&A[i]),s+=A[i];
	sort(A,A+n);
	B[0]=1;
	REP(i,0,n)B=B|(B<<A[i]);
	
	Mn=M*M;
	REP(i,1,s+1)if(B[i]){
		int t=abs((i<<1)-s);
		if(t<Mn)Mn=t,Ans=max(i,s-i);
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;

bool check(char c) {
	return (c == 'U' || c == 'D');
}

int main(void) {
	char c;
	int tot = 0;
	bool ans = true;
	do {
		c = getchar();
		tot ++;
		if(!isalpha(c)) break;
		if(tot % 2 == 1 && !(check(c) || c == 'R')) {
			ans = false;
			break;
		}
		else if(tot % 2 == 0 && !(check(c) || c == 'L')) {
			ans = false;
			break;
		}
	} while(c != EOF);
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 2e5+34;
const int P = 1e4+345;

long long a[N];
long long m[P];
string s;

void solve() {
	int n, p; cin >> n >> p >> s;
	long long exp = 1;
	long long cc = 0;
	reverse(s.begin(), s.end());
	for (int i = 0; i < n; ++i) {
		s[i] -= '0';
		a[i] = s[i]*exp%p;
		(exp *= 10) %= p;
		++m[(cc += a[i]) %= p];
	}
	long long ans = 0;
	if (p == 2 || p == 5) {
		reverse(s.begin(), s.end());
		for (int i = 0; i < n; ++i) {
			if (s[i] % p == 0) ans += i+1;
		}
	} else {
		for (int i = 0; i < p; ++i) {
			if (m[i] > 1) ans += m[i]*(m[i]-1)/2;
		}
		ans += m[0];
	}
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int n,dp[45][4],a,b;
  vector<int>p,t;

  while(1){
    cin>>n; 
    if(n==0) break;  
    p.clear();
    t.clear();
    
    fill(dp[0],dp[42],INF);
    
    for(int i=0;i<n;i++){
      cin >> a >> b;
      p.push_back(a);
      t.push_back(b);
    }

    dp[0][0]=p[0];
    if(p[0]>t[0]){
      cout << "NG " << 1 <<endl;
      continue;
    }
    int cnt=1;
    for(int i=1;i<n;i++){
      for(int j=1;j<4;j++){
	if(dp[i-1][j-1]==INF)continue;
	cnt=i;
	if(j<3 && abs(p[i]-p[i-1])*(j+1)<=t[i]-t[i-1])
	  dp[i][j]=min(dp[i][j],dp[i-1][j-1]+abs(p[i]-p[i-1]));
	if(p[i]+(p[i-1]*(j+1))<=t[i]-t[i-1])
	  dp[i][0]=min(dp[i][0],dp[i-1][j-1]+p[i]+p[i-1]);
      }
    }
    
    int ans=INF;
    for(int i=0;i<4;i++){
      ans=min(ans,dp[n-1][i]);
    }
    if(ans==INF)cout << "NG " << cnt+1 <<endl;
    else cout << "OK " << ans+p[p.size()-1] << endl;
  }

  return 0;
}



Measured memory_bytes: 3136
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47368
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e2+7, K = 1e5+7, p = 1e9+7;
int f[K], sum[K];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
	{
		int a;
		scanf("%d", &a);
		if(i==1)
		{
			for(int j = 0; j <= a; j++)
			{
				f[j] = 1;
				sum[j] = j+1;
			}
			for(int j = a+1; j <= k; j++)
			{
				sum[j] = sum[j-1];
			}
			continue;
		}
		for(int j = 0; j <= k; j++)
		{
			f[j] = ((sum[j]-(j <= a ? 0 : sum[j-a-1]))%p+p)%p;
		}
		sum[0] = f[0];
		for(int j = 1; j <= k; j++)
		{
			sum[j] = (sum[j-1]+f[j])%p;
		}
	}
	printf("%d\n", f[k]);
	return 0;
}

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

bool flag = true;
long long n, a;

int main() {
  	cin >> n;
  	for (int i = 0; i < n; i++) { 
    	cin >> a;
      	if (a % 2 == 0) 
        	if ((a % 3) && (a % 5)) {
             	flag = false;
              	break;
            }
    }
  	if (flag)
  		cout << "APPROVED" << '\n';
  	else
      cout << "DENIED" << '\n';
 	return 0; 
}

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


int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    
    int count = 999999999;
    int result = 0;
    for (int i = 0; i < N; i++) {
        int sum = 1000 * T - H[i] * 6;
        int absA = abs(sum - 1000 * A);
        if (absA < count) {
            count = absA;
            result = i + 1;
        }
    }
    cout << result << endl;
     
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
H.reverse()

ans = True
for i in range(len(H) - 1):
    if H[i] + 1 == H[i + 1]:
        H[i + 1] -= 1
    if H[i] + 1 < H[i + 1]:
        ans = False
        break

if ans:
    print("Yes")
else:
    print("No")


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

int main() {
	int N, M;
	int A[100][100], B[100];
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		int count = 0;
		for (int j = 0; j < M; j++) {
			count += A[i][j] * B[j];
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 3132
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
char mp[2020][2020];
int dis[2020][2020];
int vis[2020][2020];
int h,w,x11,y11,x2,y2;
int sum=inf;
int dx[4]= {0,0,1,-1};
int dy[4]= {1,-1,0,0};
struct A
{
    int x,y,v;
    A(int x=0,int y=0,int v=0):x(x),y(y),v(v) {}
    bool operator<(const A&o)const
    {
        return v>o.v;
    }
};
int main()
{
    cin>>h>>w;
    cin>>x11>>y11;
    cin>>x2>>y2;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>mp[i][j];
        }
    }
    memset(dis,inf,sizeof(dis));
    priority_queue<A>q;
    q.push(A(x11,y11,dis[x11][y11]));
    dis[x11][y11]=0;
    while(!q.empty())
    {

        int x=q.top().x;
        int y=q.top().y;
        q.pop();
        if(vis[x][y])
        {
            continue;
        }
        vis[x][y]=1;
        for(int i=0; i<4; i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            if(xx<1||xx>h||yy<1||yy>w||mp[xx][yy]=='#')
                continue;

            if(dis[xx][yy]>dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                q.push(A(xx,yy,dis[xx][yy]));
            }

        }
        for(int i=-2; i<=2; i++)
        {
            for(int j=-2; j<=2; j++)
            {
                int xx=x+i;
                int yy=y+j;
                if(xx<1||xx>h||yy<1||yy>w||mp[xx][yy]=='#')
                    continue;
                if(dis[xx][yy]>dis[x][y]+1)
                {
                    dis[xx][yy]=dis[x][y]+1;
                    q.push(A(xx,yy,dis[xx][yy]));
                }
            }
        }
    }
    if(dis[x2][y2]==inf)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<dis[x2][y2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 29448
import java.util.Scanner;

class Main{
    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	while (scan.hasNextInt()){
    		int numverline = scan.nextInt();
    		int[] verline = new int[numverline];
    		for(int i = 0; i < numverline; i++){
    			verline[i] = i+1;
    		}
    		int horline = scan.nextInt();
    		int[][] coor = new int[horline][2];
    		for(int i = 0; i < horline; i++){
    			String[] tmp = scan.next().split(",");
    			coor[i][0] = Integer.parseInt(tmp[0]);
    			coor[i][1] = Integer.parseInt(tmp[1]);
    		}
    		
    		for(int i = 0; i < coor.length; i++){
    			int tmp = verline[coor[i][0]-1];
    			verline[coor[i][0]-1] = verline[coor[i][1]-1];
    			verline[coor[i][1]-1] = tmp;
    		}
    		
    		for(int i = 0; i < verline.length; i++){
    			System.out.println(verline[i]);
    		}
    	}
    }
}

Measured memory_bytes: 17404
#include <stdio.h>
#define max 1000000000000000000
int main()
{
  long long int a[100000];
  int N;
  int i;
  long long int result = 1;
  scanf("%d", &N);
  for(i = 0; i < N; ++i){
    scanf("%lld", &a[i]);
    if(a[i] == 0){
      printf("0\n");
      return 0;
    }
  }
  for(i = 0; i < N; ++i){
    result *= a[i];
    if((result > max) || (result <= 0)){
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 2468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
 
 
 
int main(){
    ll N, K; cin >> N >> K;
    set<ll> ST;
    for(int i = 0; i < K; i++){
        ll d; cin >> d;
        for(int j = 0; j < d; j++){
            ll a; cin >> a; ST.insert(a);
        }
    }
    cout << N - (ll)ST.size() << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> ten, mod;
    rep(i, n){
        int a;
        cin >> a;
        if(a % 10 == 0) ten.push_back(a);
        else mod.push_back(a);
    }
    if((int)mod.size() == 0){
        cout << 0 << endl;
    }else{
        int mn = 100;
        int ans = 0;
        for(int x : mod){
            ans += x;
            mn = min(x, mn);
        }
        for(int x : ten){
            ans += x;
        }
        if(ans % 10 == 0) ans -= mn;
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char a[11]={0,0,0,0,0, 0,0,0,0,0,0};
	scanf("%s",a);

	int c,a1=0,a2=0;
	for(c=0;c<11;c++){
		if(a[c]=='A'||a[c]=='T'||a[c]=='G'||a[c]=='C')a1++;
		else if(a2<a1) a2=a1,a1=0;
		else a1=0;
	}
	printf("%d\n",a2);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF 10000000001
using namespace std;
vector<ll>graph[100001];
bool vis[100001];

void dfs(ll s,vector<ll>&dp)
{
  vis[s]=true;
  for(auto it:graph[s])
  {
    if(!vis[it])
      dfs(it,dp);

    dp[s]=max(dp[s],dp[it]+1);
  }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<ll>dp(100001,0);
  ll n,m;
  cin>>n>>m;
  for(ll i=0;i<m;i++)
  {
    ll u,v;
    cin>>u>>v;
    graph[u].pb(v);
  }
  for(int i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      dfs(i,dp);
    }
  }
  ll ans=0;
  for(ll i=1;i<=n;i++)
  {
    ans=max(ans,dp[i]);
  }
  cout<<ans;
}


Measured memory_bytes: 8704
N,M = map(int,input().split())
X,Y,Z = [],[],[]
for i in range(N):
    x,y,z = map(int,input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)

ans = 0
for a in [1,-1]:
    for b in [1,-1]:
        for c in [1,-1]:
            T = []
            for n in range(N):
                T.append(a*X[n] + b*Y[n] + c*Z[n])
            T.sort()
            T.reverse()
            if ans < sum(T[:M]):
                ans = sum(T[:M])

print(ans)
            

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    if (7 == N or 5 == N or 3 == N) cout << "YES" <<endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int cmp(const void* a,const void* b){return *(int*)a-*(int*)b;}

int main() {
  int N,M,i,k=0;
  scanf("%d%d",&N,&M);
  int a[M],ans[N+2];
  FOR(i,0,M)scanf("%d",&a[i]);
  ans[0]=0;ans[1]=1;
  FOR(i,2,N+2){
    ans[i]=ans[i-2]+ans[i-1];
    if(a[k]==i-1){ans[i]=0;k++;}
    if(ans[i]>MOD)ans[i]%=MOD;
  }
  
  printf("%d\n",ans[N+1]);
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

i64 a[100005] ;

int main()
{
    i64 i , j , k , l , m , n , r ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++)
    {
        scanf("%lld",&a[i]) ;
    }

    l = 2 ; r = 2 ;

    for(i=n ; i>=1 ; i--)
    {
        k = l/a[i] ;
        i64 k1 = ((l-1)/a[i])*a[i] + a[i] ;
        if( k1 > r)
        {
            printf("-1\n") ;
            return 0 ;
        }
        l = k1 ;
        r = (r/a[i])*a[i] + a[i]-1 ;
    }

    printf("%lld %lld\n",l,r) ;

    return 0 ;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
     int f[N2];
     int space;
     string path;
     bool operator < ( const Puzzle &p ) const {
         for ( int i = 0; i < N2; i++ ) {
        if ( f[i] == p.f[i] ) continue;
        return f[i] > p.f[i];
             
         }
        return false;
         
     }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};
bool isTarget(Puzzle p) {
    for ( int i = 0; i < N2; i++ )
        if ( p.f[i] != (i + 1) ) return false;
    return true;
}

string bfs(Puzzle s) {
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
    
    while ( !Q.empty() ) {
        u = Q.front(); Q.pop();
        if ( isTarget(u) ) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for ( int r = 0; r < 4; r++ ) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if ( !V[v] ) {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
    
}
int main() {
    Puzzle in;
    for ( int i = 0; i < N2; i++ ) {
        cin >> in.f[i];
        if ( in.f[i] == 0 ) {
            in.f[i] = N2; // set space
            in.space = i;
            
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 30464
def main():
    from bisect import bisect_left
    def update(l,r,v):
        L,R=l+N0,r+N0
        while L<R:
            if R&1:
                R-=1
                data[R-1]=v
            if L&1:
                data[L-1]=v
                L+=1
            L>>=1
            R>>=1
    def query(k):
        k+=N0-1
        s=10**18
        while k+1:
            if data[k]<s:s=data[k]
            k=~-k//2
        return s
    n,*t=open(0)
    n,q=map(int,n.split())
    d=[-10**18]+list(map(int,t[n:]))+[10**18]
    N0=2**(q+1).bit_length()
    data=[10**18]*2*N0
    for x,t,s in sorted(list(map(int,t.split()))[::-1]for t in t[:n])[::-1]:
        l=bisect_left(d,s-x)
        r=bisect_left(d,t-x)
        update(l,r,x)
    for i in range(q):
        a=query(i+1)
        print(-(a==10**18)or a)
if __name__=='__main__':
    main()

Measured memory_bytes: 135532
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    total = 0
    for i in range(n):
            total = total ^ a[i]
    if n % 3 == 1:
        total = total ^ a[0] ^ a[1]
    if n % 3 == 2:
        total = total ^ a[0]
    if total == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14116
#include<stdio.h>
#include<string.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define min3(a,b,c) min(min(a,b),c)
int main(){
	int n,x,y,c,m[1001],M[1001],R;
	while(scanf("%d\n",&n),n){
		memset(M,0,sizeof(M));
		R=0;
		for(y=0;y<n;y++){
			m[0]=0;
			for(x=1;x<=n;x++){
				c=getchar();
				if(c=='*')
					m[x]=0;
				else
					m[x]=min3(m[x-1],M[x],M[x-1])+1;
				if(m[x]>R)
					R=m[x];
			}
			getchar();
			memcpy(M,m,sizeof(M));
		}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,C;cin>>n>>C;
    vector<ll>a(100010);
    vector<vector<pll> >b(C);
    rep(i,n){
        ll s,t,c;cin>>s>>t>>c;
        c--;
        b[c].pb(mp(s,t));
    }
    rep(i,C){
        sort(all(b[i]));
        ll last=0;
        rep(j,b[i].size()){
            //cout<<i<<' '<<b[i][j].first<<' '<<b[i][j].second<<endl;
            if(last==b[i][j].first){
            }else{
                a[b[i][j].first]++;
                if(last)a[last+1]--;
            }
            last=b[i][j].second;
        }
        if(last)a[last+1]--;
    }
    ll ma=1;
    REP(i,1,100010){
        a[i]+=a[i-1];
    }
    rep(i,100010){
        ma=max(a[i],ma);
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 3456
import re

def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N = int(input())

MOD = int(1e9) + 7

acgt = ["A", "C", "G", "T"]
changed = list(map(lambda pat: re.compile(pat), [r"AGC", r"GAC", r"ACG", r"A.GC", r"AG.C"]))
abcl = [ a+b+c for a in acgt for b in acgt for c in acgt]

dp = {}
for now in abcl:
    if any(map(lambda ch: ch.search(now), changed)):
        dp[now] = 0
    else:
        dp[now] = 1

N -= 3

while N > 0:
    dpNow = {}
    for abc in abcl:
        abc = abc[:min(N, 3)]
        dpNow[abc] = 0
        for key, value in dp.items():
            now = key + abc
            if not any(map(lambda ch: ch.search(now), changed)):
                dpNow[abc] += value
                dpNow[abc] %= MOD
    dp = dpNow
    N -= 3

ans = 0
for v in dp.values():
    ans += v
    ans %= MOD

print(ans)


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  cout<<v[n-1]-v[0]<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e12, cnt;



int main(){
	string s,t;
	cin>>s>>t;
	for(ll i=0; i<s.size(); i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans<<endl;	
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;

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; }

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

    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(ALL(s));

    // mem : '1'の最大連続数
    ll mem = 0, b = 0;
    vll a(n + 1);
    REP(i, n + 1) {
        a[i] = int(s[i] - '0');
        if (a[i] == 1) b++;
        else {
            chmax(mem, b);
            b = 0;
        }
    }

    // 到達不可能
    if (mem >= m) {
        cout << -1 << endl;
        return 0;
    }

    // res : 各ターンで出すべき目
    // cur : 現在地
    vll res;
    ll cur = 0;

    while (cur != n) {
        // dice : このターン出すべき目
        ll dice = m;
        while (1) {
            chmin(dice, n - cur);
            if (a[cur + dice] == 0) {
                cur += dice;
                res.push_back(dice);
                break;
            }
            dice--;
        }
    }
    reverse(ALL(res));
    for (auto x : res) {
        cout << x << " ";
    }
    return 0;
}

Measured memory_bytes: 2248
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if a[0] == a[m-1] and a[m] == a[2*m-1] and a[2*m] == a[3*m-1] and a[0]^a[m] == a[2*m]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 31368
// ABC047B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int W, H, N;
	cin >> W >> H >> N;
	int x[101],  y[101],  a[101];
	for (int i = 1; i <= N; i++) cin >> x[i] >> y[i] >> a[i];
	int men[101][101] = {};
	for (int i = 1; i <= N; i++)
	{
		if (a[i] == 1) 
		{
			for (int k = 1; k <= x[i]; k++) {
				for (int j = 1; j <= H; j++) 
				{
					men[j][k] = 1; 
				}
			}
		}

		if (a[i] == 2)
		{
			for (int k = x[i] + 1; k <= W; k++) {
				for (int j = 1; j <= H; j++)men[j][k] = 1;
			}
		}
		if (a[i] == 3)
		{
			for (int j = 1; j <= y[i]; j++) {
				for (int k = 1; k <= W; k++)men[j][k] = 1;
			}
		}
		if (a[i] == 4)
		{
			for (int j = y[i] + 1; j <= H; j++) {
				for (int k = 1; k <= W; k++)men[j][k] = 1;
			}
		}
	}
	int count = 0;
	for (int j = 1; j <= W;j++)
	{
		for (int i = 1; i <= H; i++)
		{
			if (men[i][j] == 0)
			{
				count++;
				//cout <<i<<j<<endl;
			}
			}
	}
	cout << count << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, res = 0, mini = 1000000000;
  cin >> n >> x;
  res += n;
  REP(i,n) {
    int a;
    cin >> a;
    mini = min(mini,a);
    x -= a;
  }
  res += x/mini;
  cout << res << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import sys
k, x = map(int, input().split())

s = max(-1000000, x-k+1)
e = min(x+k-1, 1000000)
for i in range(s,e+1):
    if i == e:
        sys.stdout.write("{}".format(i))
    else:
        sys.stdout.write("{} ".format(i))

Measured memory_bytes: 38256
fn gcd(a: i64, b: i64) -> i64 {
    let mut larger = std::cmp::max(a, b);
    let mut smaller = std::cmp::min(a, b);
    while smaller != 0 {
        let remainder = larger % smaller;
        larger = smaller;
        smaller = remainder;
    }
    larger
}

fn lcm(a: i64, b: i64) -> i64 {
    let gcd = gcd(a, b);
    gcd * (a/gcd) * (b/gcd)
}

fn main() {
    let mut input_iter = read_line_as_vector::<i64>().into_iter();
    let a = input_iter.next().unwrap();
    let b = input_iter.next().unwrap();
    println!("{}", lcm(a, b));
}

fn read_line_as_vector<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().split_whitespace().map(|x| x.parse()).collect::<Result<Vec<T>, _>>() {
        Ok(vec) => vec,
        _ => panic!("error while parsing input: {}", input)
    }
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

ll calc(ll num) {
    if (num <= 1) return num;
    else if (num <= 3) {
        if (num == 2) return 3;
        else if (num == 3) return 0;
    } 
    int cnt = 0;
    ll tmp = num;
    while (tmp > 0) {
        tmp >>= 1;
        ++cnt;
    }
    ll sub = 1LL << (cnt-1);
    ll res = calc(num%sub) + (num%2==0?sub:0);
    return res;
}

int main(){
    ll a, b;
    cin >> a >> b;
    // if (llabs(b-a) == 0) cout << b << endl;
    cout << (calc(b)^calc(max(0LL,a-1))) << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
 
int main(void){
  int A,B,C,D,N;
  cin >> N;
  D=N%10;
  N/=10;
  C=N%10;
  N/=10;
  B=N%10;
  N/=10;
  A=N%10;
  
  for(int op1=0;op1<=1;op1++){

    for(int op2=0;op2<=1;op2++){
          
      for(int op3=0;op3<=1;op3++){
        int sum=A;
        if(op1==0){
          sum=sum+B;
        }else{
          sum=sum-B;
        }
        if(op2==0){
          sum=sum+C;
        }else{
          sum=sum-C;
        }
        if(op3==0){
          sum=sum+D;
        }else{
          sum=sum-D;
        }
        if(sum==7){
          string s=to_string(A);
          if(op1==1){
            s+="-"+to_string(B);
          }else{
            s+="+"+to_string(B);
          }
          if(op2==1){
            s+="-"+to_string(C);
          }else{
            s+="+"+to_string(C);
          }
          if(op3==1){
            s+="-"+to_string(D);
          }else{
            s+="+"+to_string(D);
          }
          cout << s << "=7" <<endl;

          return 0;
        }
      }
    }

  }

  
  return 0;
}

Measured memory_bytes: 256
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")t
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("fenwick.out", "r", stdin);
}

void outfile(){
    freopen("fenwick.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2LL, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1LL)
        tmp = (tmp * a) % mod;
    return tmp;
}

//End of template

ll arr[200005];

int main(){
    init();

    ll n;
    ll cnt = 0;
    cin >> n;
    FOR(i, 0, n){
        cin >> arr[i];
    }
    ll maks = arr[0];
    FOR(i, 1, n){
        maks = max(maks, arr[i]);
        if(arr[i] < maks){
            cnt += maks-arr[i];
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> v(26);
    rep(i, 0, n) v[s[i] - 'a'].push_back(i);
    rep(i, 0, n) v[s[i] - 'a'].push_back(i + n);
    ll ans = 0;
    ll p = 0;
    rep(i, 0, m) {
        int c = t[i] - 'a';
        if (v[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto it = lower_bound(all(v[c]), p);
        p = *it + 1;
        if (p > n) {
            p -= n;
            ans += n;
        }
    }
    ans += p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
const int mod = 1e9+7;
void test_case(){
	int h,w; cin >> h >> w;
	vector<string> s(h);
	for(int i = 0 ; i < h; i++)
		cin >> s[i];
	vector<vector<int>> cnt(h,vector<int>(w));
	for(int i = 0 ; i < h; i++){
		vector<int> done(w);
		for(int j = 0 ; j < w ; j++){
			if(s[i][j] == '#')
				continue;
			if(done[j])
				continue;
			int l = 0;
			while(j+l < w){
				if(s[i][j+l] == '#')
					break;
				++l;
			}
			for(int k = 0 ; k < l ; k++){
				cnt[i][j+k] += l;
				done[j+k] = 1;
			}
		}
	}
	for(int j = 0 ; j < w; j++){
		vector<int> done(h);
		for(int i = 0 ; i < h ; i++){
			if(s[i][j] == '#')
				continue;
			if(done[i])
				continue;
			int l = 0;
			while(i+l < h){
				if(s[i+l][j] == '#')
					break;
				++l;
			}
			for(int k = 0 ; k < l ; k++){
				cnt[i+k][j] += l;
				done[i+k] = 1;
			}
		}
	}
	int ans  = 0;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			ans = max(ans,cnt[i][j]-1);
		}
	}
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    vector<int> ctime(5);
    vector<int> ctime_mod(5);
    rep(i, 5)
    {
        cin >> ctime.at(i);
        ctime_mod.at(i) = ctime.at(i) % 10;
        if (ctime.at(i) % 10 == 0)
            ctime_mod.at(i) = 10;
    }

    sort(ctime_mod.begin(), ctime_mod.end(), greater<int>());

    int time = 0;
    rep(i, 5)
    {
        time += (ctime.at(i) + 10 - 1) / 10 * 10;
    }

    time -= 10 - ctime_mod.at(4);

    cout << time << endl;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		String S = sc.next();
		int x = 0;
		int ans = 0;
		for(int i = 0; i < N; i++){
			if(S.charAt(i) == 'I') x++;
			else x--;
			ans = Math.max(ans, x);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

pii d[2000];
bool used[2000];
double pass[2000][2000];
int n;

void dijk(int s){
    rep(i,2000)d[i]=pii(INF,-1);
    rep(i,2000)used[i]=false;
    d[s]=pii(0,-1);
    
    while (1) {
        int v=-1;
        rep(u,n){
            if( !used[u]&&(v==-1||d[u].first<d[v].first) )v=u;
        }
        
        if(v==-1)break;
        
        used[v]=true;
        
        rep(u,n){
            if( d[u].first>d[v].first+pass[v][u] )
                d[u] = pii( d[v].first+pass[v][u] , v );
        }
    }
}


int main(){
    while(cin>>n){
        if(n==0)break;
        
        rep(i,2000)rep(j,2000) pass[i][j]=INF;
        int b[2000],x[2000],y[2000];
        double res;
        rep(i,n){
            cin>>b[i]>>x[i]>>y[i];
        }
        rep(i,n){
            rep(j,n){
                if(i==j)
                    pass[b[i]-1][b[i]-1]=0;
                else if( ( res=sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) ) )<=50+1e-9  ){
                    pass[b[i]-1][b[j]-1]=res;
                    pass[b[j]-1][b[i]-1]=res;
                }
            }
        }
        int m;
        cin>>m;
        rep(i,m){
            int s,g;
            cin>>s>>g;
            s--,g--;
            dijk(s);
            if(d[g].first==INF){cout<<"NA"<<endl;continue;}
            int tmp = g;
            vector<int> ans;
            while(tmp!=s){
                ans.pb(tmp);
                tmp = d[tmp].second;
            }
            ans.pb(s);
            reverse(all(ans));
            rep(i,ans.size()){
                if(i!=0)cout<<" ";
                cout<<ans[i]+1;
            }
            cout<<endl;
        }
    }
}

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

int main(void){
  int n, k;
  cin >> n >> k;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  long c = -1;
  for(int i = 0; i < n; i++){
    if(a[i] == 1){
      c = i;
      break;
    }
  }
  int ans = 0;
  long temp = c;
  while(temp > 0){
    ans++;
    temp -= k - 1;
  }
  temp = abs(temp) + c;
  while(temp < n - 1){
    ans++;
    temp += k - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            var o = ReadAndParseIntArr();
            int a = o[0];
            int b = o[1];
            string ans = a + b >= 10 ? "error" : (a + b).ToString();
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll N, M;
   cin >> N >> M;
   if (2 * N > M) cout << M / 2 << endl;
   else cout << N + (M - 2 * N) / 4 << endl;
   return 0;
}


Measured memory_bytes: 256
class Dice
  def initialize(n)
    @n = n
  end
  #     ^N
  #     [0]:top
  # [3] [1] [2] [4]  2:right 3:left 4:back
  #     [5]:bottom
  #     vS
  attr_reader :n

  def roll(d)
    case d
    when ?N
      @n = [@n[1], @n[5], @n[2], @n[3], @n[0], @n[4]]
    when ?S
      @n = [@n[4], @n[0], @n[2], @n[3], @n[5], @n[1]]
    when ?E
      @n = [@n[3], @n[1], @n[0], @n[5], @n[4], @n[2]]
    when ?W
      @n = [@n[2], @n[1], @n[5], @n[0], @n[4], @n[3]]
    else
      raise
    end
    self
  end
  def rotate_right
    @n = [@n[0], @n[2], @n[4], @n[1], @n[3], @n[5]]
    self
  end
  def rotate_left
    @n = [@n[0], @n[3], @n[1], @n[4], @n[2], @n[5]]
    self
  end
  def print
    puts "  #{@n[0]}"
    puts "#{@n[3]} #{@n[1]} #{@n[2]} #{@n[4]}"
    puts "  #{@n[5]}"
  end
  # CAUTION !! THIS FUNCTION WILL ROTATE DICE
  # IF YOU DON'T WANT, KEEP VALUE FIRST AND RESTORE BEFORE RETURN
  def ==(other)
    c1 = @n.uniq.map{|e| [e, @n.count(e)]}.sort{|a,b|if a[1]==b[1] then a[0]<=>b[0] else a[1]<=>b[1] end}
    c2 = other.n.uniq.map{|e| [e, @n.count(e)]}.sort{|a,b|if a[1]==b[1] then a[0]<=>b[0] else a[1]<=>b[1] end}
    return false if c1 != c2
    other.set_upper_by_value(c1[0][0])
    return true if c1.size < 2 # only 1 number
    idx = @n.map.with_index{|p,i| i if p==c1[0][0]}.compact
    idx.each{|i|
      set_upper_by_index(i)
      4.times{
        return true if self.n == other.n
        rotate_right
      }
    }
    return false
  end
  def set_upper_by_index(idx)
    case idx
    when 0
      ;
    when 1
      self.roll(?N)
    when 2
      self.roll(?W)
    when 3
      self.roll(?E)
    when 4
      self.roll(?S)
    when 5
      self.roll(?N)
      self.roll(?N)
    when nil
      raise "@n:#{@n} idx:#{idx}"
    end
    self
  end
  def set_upper_by_value(u)
    set_upper_by_index(@n.index(u))
  end
  def set_up_n_front(u, f)
    set_upper_by_value(u)
    case @n.index(f)
    when 1
      ;
    when 2
      self.rotate_right
    when 3
      self.rotate_left
    when 4
      self.rotate_left.rotate_left
    when 0, 5, nil
      raise "@n:#{@n} u:#{u} f:#{f}"
    end
    self
  end
end

n=gets.to_i
d=[]
n.times{
  d << Dice.new(gets.split.map(&:to_i))
}
n.times{|i|
  (i+1).upto(n-1){|j|
    if d[i] == d[j]
      puts "No"
      exit
    end
  }
}
puts "Yes"



Measured memory_bytes: 8932
import math
n = int(input())

def is_prime(num):
    if num == 2:
        return True
    elif num <  3 or num % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(num)) + 1, 2):
        if num % i == 0:
            return False
    return True


c = []
for i in range(1, int(math.sqrt(n))+1):
    if n%i == 0:
        k = n//i
        if is_prime(k):
            c.append(k)
        if is_prime(i):
                c.append(i)

d = {}
ans = 0
for i in set(c):
    while n%i == 0:
        n //= i
        if i in d:
            d[i] += 1
        else:
            d[i] = 1

ans = 0
for v in d.values():
    for i in range(1, 41):
        if v >= i:
            v -= i
            ans += 1
        else:
            break
print(ans)

Measured memory_bytes: 9128