akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n+1);
    int l=sqrt(n);

    for(int i=1;i<=l;i++)
    {
        for(int j=1;j<=l;j++)
        {
            for(int k=1;k<=l;k++)
            {
                int ans=i*i+j*j+k*k+i*j+j*k+k*i;

                if(ans<=n)
                    a[ans]++;
            }
        }
    }

    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }

    exit(0);
}


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

#define SUM(vec) accumulate(vec.begin(), vec.end(), 0)

using namespace std;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------
    
    int N, M, j;
    bool a[100010] = {0};
    long long int dp[100010];

    cin >> N >> M;

    for(int i = 0; i < M; i++) {
        int b;
        cin >> b;
        a[b] = true;
    }

    dp[0] = 1;
    j = 0;

    if(a[1]){
        dp[1] = 0;
        j += 1;
    }else{
        dp[1] = 1;
    }

    for (int i = 2; i < N + 1; i++)
    {
        if(a[i]){
            dp[i] = 0;
        }else{
            dp[i] = dp[i-1] + dp[i-2];
            dp[i] %= 1000000007;
        }   
    }
    
    cout << dp[N] << endl;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int n=0, k=0, x=0, y=0, ans=0;
  cin >> n >> k;
  vector<int> vec(n);
  
  rep (i, k){
    cin >> x;
    rep (j, x) {
      cin >> y;
      //cout << y << ' ' ;
      vec.at(y-1) = 1;
    }
    //cout << endl;
  }
  
  for (int x : vec) if (x == 0) ++ans;
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <set>
using namespace std;
int main() {
    string S; cin >> S;
    set<char> C;
    for (int i = 0; i < 4; i++) C.insert(S[i]);
    if (C.size() == 2) printf("%s\n", "Yes");
    else printf("%s\n", "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



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

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			int[] cost = new int[n+1];
			for(int i=0;i<n+1;i++) cost[i] = Integer.MAX_VALUE;
			
			int[] a = new int[m+1];
			int[] b = new int[m+1];
			int[] c = new int[m+1];
			int[] d = new int[m+1];	
			
			ArrayDeque<Integer> que = new ArrayDeque<Integer>();

			for(int i=0;i<m+1;i++){
				String[] s = sc.next().split(",");
				a[i] = Integer.valueOf(s[0]);
				b[i] = Integer.valueOf(s[1]);
				c[i] = Integer.valueOf(s[2]);
				d[i] = Integer.valueOf(s[3]);
			}
			int ans = c[m] - d[m];
			int z, p;
			int q = a[m];
			int r = b[m];
			
			for(int k=0;k<2;k++){
				if(k==1){
					q = b[m];
					r = a[m];
				}
				
				que.offer(q);
				cost[q] = 0;
				while(true){
					z = que.size();
					if(z==0) break;
					for(int i=0;i<z;i++){
						p = que.poll();
						for(int j=0;j<m;j++){
							if(a[j]==p && cost[p]+c[j]<cost[b[j]]){
								que.offer(b[j]);
								cost[b[j]] = cost[p]+c[j];
							}
							else if(b[j]==p && cost[p]+d[j]<cost[a[j]]){
								que.offer(a[j]);
								cost[a[j]] = cost[p]+d[j];
							}
						}
					}
				}
				ans -= cost[r];
				
				if(k==0){
					for(int i=0;i<n+1;i++) cost[i] = Integer.MAX_VALUE;
				}else{
					System.out.println(ans);
				}
			}
		}
	}	
}

Measured memory_bytes: 17184
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
  int N; cin >> N; int a=0, c, j;
  for(int i=1; i<=N; i++){
    j=i; c=0;
    while (j>0){
      c++; j/=10;
    }
    if (c%2) a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll mul=1;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(a[0]==0)
    {
        cout<<0;
        return 0;
    }
    for(int i=0;i<n;i++)
        if(mul<=(C+2)/a[i] && mul<=C)
            mul*=a[i];
        else
        {
            cout<<-1;
            return 0;
        }
    if(mul<=C)
        cout<<mul;
    else
        cout<<-1;
    subt;
    return 0;
}

Measured memory_bytes: 4592
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner s=new Scanner (System.in);
        int l=s.nextInt();
        int r=s.nextInt();
        if(r-l+1>=2019){
          int max=Integer.MAX_VALUE;
          for(int i=0;i<2019;i++){
              for(int j=0;j<2019;j++){
                  if(i!=j)max=Integer.min(max,(i*j)%2019);
              }
          }
          System.out.println(max);
        }else{
          int max=Integer.MAX_VALUE;
          for(int i=l;i<=r;i++){
              for(int j=l;j<=r;j++){
                  if(i!=j){
                      int left=i%2019;
                    int right=j%2019;
                    max=Integer.min(max,(left*right)%2019);
                  }
              }
            
          }
          System.out.println(max);
        }
        
    }
      
}

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

class process{
public:
  string name;
  int time;
};

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

  queue<process> que;
  for(int i=0; i<n; i++){
    process p;
    cin >> p.name >> p.time;
    que.push(p);
  }

  int t = 0;
  while(que.size() > 0){
    process p = que.front();
    que.pop();
    if(p.time <= q){
      t += p.time;
      cout << p.name << " " << t << endl;
    }
    else{
      t += q;
      p.time -= q;
      que.push(p);
    }
  }

  return 0;
}



Measured memory_bytes: 6236
#include<bits/stdc++.h>
using namespace std;
#define r1 1000000
#define m 4294967296

bool prime[r1];
vector<int>arr;

void seive()
{
    for(int i=3;i<=r1;i+=2)prime[i]=true;
    prime[2]=true;

    for(int i=3;i*i<=r1;i+=2)
    {
        if(prime[i]==true)
        {
            for(int j=i*2;j<=r1;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    arr.push_back(2);

    for(int i=3;i<=r1;i+=2)
    {
        if(prime[i]==true)
        {
            arr.push_back(i);
        }
    }

}
int main()
{
    seive();
    //for(int i=0;i<10;i++)cout<<arr[i]<<endl;
    int n;
    cin>>n;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]>=n)
        {
            cout<<arr[i]<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1916
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let p: Vec<f64> = (0..n).map(|_| input()).collect();

    let mut dp = vec![vec![0.0; n + 1]; n + 1];
    dp[0][0] = 1.0;
    for i in 0..n {
        dp[i + 1][0] = dp[i][0] * (1.0 - p[i]);
        dp[i + 1][i + 1] = dp[i][i] * p[i];
        for j in 1..i + 1 {
            dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * (1.0 - p[i]);
        }
    }

    let p = dp[n][n / 2 + 1..].iter().sum::<f64>();
    println!("{}", p);
}


Measured memory_bytes: 90364
#include <iostream>
#include <cstring>

using namespace std;

int memo[31];

int solve(int remain){
    int cnt = 0;

    if(memo[remain] != -1) return memo[remain];

    if(remain <= 0) return 0;
    if(remain == 1) return 1;
    if(remain == 2) return 2;
    if(remain == 3) return 4;

    for(int i=1;i<=3;++i){
        cnt += solve(remain - i);
    }

    return memo[remain] = cnt;
}


int main(void){
    int n;
    int val;

    while(cin >> n, n > 0){
        memset(memo,-1,sizeof(int)*31);

        val = solve(n)/10;
        val = val < 366 ? 1 : val % 365 == 0 ? val / 365 : val/365 + 1;
        cout << val << endl;
    }
}

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

int main(){
  int k,s;
  cin>>k>>s;
  int count=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
       int z=s-i-j;
      if(z>=0 && z<=k){
        count++;
      }
    }
  }
  cout<<count;
  
return 0;
}

Measured memory_bytes: 256
import java.lang.Math;
import java.util.Collections;
import java.util. ArrayList;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Long> a = new ArrayList<>();
        while(sc.hasNext()== true ){
            a.add(sc.nextLong());
        }
        long sumo = 0;
        for (int i =0; i<a.size(); i++){
            sumo += a.get(i);
        }
        long n = a.get(0);
        long m = a.get(1);
        String ans = null;
        sumo = sumo - (n + m);
        int cnt = 0;
        //sumoがaの総和になった
        //ここから最大値をm個とる
        for (long i=0; i < m; i++){
            long b = Collections.max(a);
            if (b*4*m >= sumo){
                cnt +=1;
                a.remove(a.indexOf(b));
            }else{
                a.remove(a.indexOf(b));
            }
        }
        if (cnt >= m){
            ans = "Yes";
        }else{
            ans ="No";
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35720
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
const ll inf=2147483647;
struct segtree{
private:
  ll siz;
  vector<ll> node,lazy;
  vector<bool> lazyflag;
public:
  segtree(ll n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(2*siz-1,inf);
    lazy.resize(2*siz-1);
    lazyflag.resize(2*siz-1,false);
  }
  void eval(ll k,ll l,ll r){
    if(lazyflag[k]){
      node[k]=lazy[k];
      if(r-l>1){
        lazy[2*k+1]=lazy[k];
        lazy[2*k+2]=lazy[k];
        lazyflag[2*k+1]=true;
        lazyflag[2*k+2]=true;
      }
      lazyflag[k]=false;
    }
  }
  void update(ll a,ll b,ll x,ll k,ll l,ll r){
    eval(k,l,r);
    if(b<=l||r<=a) return;
    if(a<=l&&r<=b){
      lazy[k]=x;
      lazyflag[k]=true;
      eval(k,l,r);
    }
    else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      node[k]=min(node[2*k+1],node[2*k+2]);
    }
  }
  void upd(ll a,ll b,ll x){
    update(a,b,x,0,0,siz);
  }
  ll getmin(ll a,ll b,ll k,ll l,ll r){
    eval(k,l,r);
    if(r<=a||b<=l) return inf;
    if(a<=l&&r<=b) return node[k];
    return min(getmin(a,b,2*k+1,l,(l+r)/2),getmin(a,b,2*k+2,(l+r)/2,r));
  }
  ll min_q(ll a,ll b){
    return getmin(a,b,0,0,siz);
  }
  void debug(){
    for(int i=0;i<node.size();i++) cout<<node[i]<<" ";
    cout<<endl;
    for(int i=0;i<lazy.size();i++) cout<<lazy[i]<<" ";
    cout<<endl;
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  segtree seg=segtree(n+5);
  for(int i=0;i<q;i++){
    int c;
    cin>>c;
    if(c==0){
      ll x,y,z;
      cin>>x>>y>>z;
      seg.upd(x,y+1,z);
    }
    else{
      ll x,y;
      cin>>x>>y;
      cout<<seg.min_q(x,y+1)<<endl;
    }
    //seg.debug();
  }
}



Measured memory_bytes: 7064
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 1e12+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;}



int main() {
    string S;
    cin >> S;
    int cnt = 1;
    char color = S[0];
    for (int i = 1; i < S.length(); i++) {
        if (color != S[i]) {
            color = S[i];
            cnt++;
        }
    }


    cout << cnt - 1 << endl;
    

}


Measured memory_bytes: 512
def get_multi_num(M):
    D = {}
    def get_multi_num_core(M):
        if len(M) < 2: return 0
        key = tuple(M)
        if key in D: return D[key]
        result = [None]*(len(M)-1)
        for i in range(1,len(M)):
            result[i-1] = get_multi_num_core(M[:i]) + \
                          get_multi_num_core(M[i:]) + \
                          M[0][0]*M[i][0]*M[-1][1]
        D[key] = min(result)
        return D[key]
    return get_multi_num_core(M)
        
if __name__=='__main__':
    n = int(input())
    M = [None]*n
    for i in range(n):
        M[i] = tuple(map(int,input().split()))
    print(get_multi_num(M))

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

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++)
  {
    string s = to_string(i);
    if(s.at(0) == s.at(4) && s.at(1) == s.at(3)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = N // 3
b = N % 3
mod = 10**9+ 7
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
ans = 0
while a >=1:
    ans += cmb(a-1+b,b)
    a -= 1
    b += 3
    if a == 1:
        ans += 1
        break
print(ans%mod)

Measured memory_bytes: 9612
#include <iostream>

#define inRange(x, y, w, h) (0 <= x && x < w && 0 <= y && y < h)

using namespace std;

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

void search( int x, int y, char map[20][20] )
{
	map[y][x] = '@';
	for(int i=0; i < 4; ++i) {
		int mx = x + dx[i];
		int my = y + dy[i];
		if(inRange(mx, my, w, h) && map[my][mx] == '.') {
			search(mx, my, map);
		}
	}
}

int main( void )
{
	char map[20][20];

	while(cin >> w >> h, w | h) {
		int sx, sy;
		for(int y=0; y < h; ++y)
			for(int x=0; x < w; ++x) {
				cin >> map[y][x];
				if(map[y][x] == '@') {
					sx = x;	sy = y;
				}
			}
		search(sx, sy, map);
		int count = 0;
		for(int y=0; y < h; ++y)
			for(int x=0; x < w; ++x) {
				if(map[y][x] == '@') ++count;
			}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

H,W = map(int,readline().split())

a = [list(map(int,readline().split())) for i in range(H)]

ans = []

for i in range(H-1):
    if i%2:
        for j in range(W-1,0,-1):
            if a[i][j]%2:
                ans.append((i+1,j+1,i+1,j))
                a[i][j] -= 1
                a[i][j-1] += 1
        if a[i][0]%2:
            ans.append((i+1,1,i+2,1))
            a[i][0] -= 1
            a[i+1][0] += 1

    else:
        for j in range(W-1):
            if a[i][j]%2:
                ans.append((i+1,j+1,i+1,j+2))
                a[i][j] -= 1
                a[i][j+1] += 1
        if a[i][W-1]%2:
            ans.append((i+1,W,i+2,W))
            a[i][W-1] -= 1
            a[i+1][W-1] += 1
if (H-1)%2:
    for j in range(W-1,0,-1):
        if a[H-1][j]%2:
            ans.append((H,j+1,H,j))
            a[H-1][j] -= 1
            a[H-1][j-1] += 1
else:
    for j in range(W-1):
        if a[H-1][j]%2:
            ans.append((H,j+1,H,j+2))
            a[H-1][j] -= 1
            a[H-1][j+1] += 1
print(len(ans))
for (x,y,u,v) in ans:
    print(x,y,u,v)



Measured memory_bytes: 30700
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

    int n, x, y;
    cin >> n >> x >> y;

    vector<int> r(n);

    for (int i = 1; i <= n - 1; ++i)
    {
        r[i] = n - i;
    }

    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            int c1 = j - i;
            int c2 = abs(x - i) + abs(y - j) + 1;
            if (c2 < c1)
            {
                r[c2]++;
                r[c1]--;
            }
        }
    }

    for (int i = 1; i <= n - 1; ++i)
    {
        cout << r[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int A,B,C,D;
  cin >> A>>B>>C>>D;
  A+=B;C+=D;
  if(A==C)cout<<"Balanced"<<endl;
  else if(A>C) cout<<"Left"<<endl;
  else cout<<"Right"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void roll(char x,int a[7]){
    int b[7];
    for(int i=1;i<7;i++){
        b[i]=a[i];
    }
    if(x=='N'){
        a[1]=b[2];
        a[2]=b[6];
        a[6]=b[5];
        a[5]=b[1];
    }
    else if(x=='W'){
        a[1]=b[3];
        a[3]=b[6];
        a[6]=b[4];
        a[4]=b[1];
    }
    else if(x=='S'){
        a[1]=b[5];
        a[5]=b[6];
        a[6]=b[2];
        a[2]=b[1];
    }
    else if(x=='E'){
        a[1]=b[4];
        a[4]=b[6];
        a[6]=b[3];
        a[3]=b[1];
    }
}
int check(int a[7],int c[7]){
    int cnt=0;
    for(int i=0;i<4;i++){
        if(a[1]==c[1]) break;
        roll('N',a);
    }
    for(int i=0;i<4;i++){
        if(a[1]==c[1]) break;
        roll('W',a);
    }
    if(a[1]!=c[1]) cnt++;
    for(int i=0;i<4;i++){
        if(a[1]==c[1]&&a[2]==c[2]) break;
        roll('N',a);
        roll('W',a);
        roll('S',a);
    }
    if(a[2]!=c[2]) cnt++;
    for(int i=1;i<7;i++){
        if(a[i]!=c[i]) cnt++;
    }
    return cnt;
}

bool eq (int a[7],int c[7]){
    int mcnt=0;
    for(int i=0;i<4;i++){
        if(check(a,c)==0) mcnt++;
        roll('N',a);
    }
    for(int i=0;i<4;i++){
        if(check(a,c)==0) mcnt++;
        roll('E',a);
    }
    if(mcnt==0) return 0;
    else return 1;
}
int main(){
    int n;
    cin>>n;
    int A[n][7];
    for(int i=0;i<n;i++){
        for(int j=1;j<7;j++){
            cin>>A[i][j];
        }
    }
    int cnt2=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int a[7];
            int c[7];
            for(int k=1;k<7;k++){
                a[k]=A[i][k];
                c[k]=A[j][k];
            }
            if(eq(a,c)==1){
                cnt2++;
                break;
            }
        }
    }
    if(cnt2==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
    
    


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

using namespace std;

int a,b,c,d,n,m,i,j,t[200005],mn=0x3f3f3f3f,rs;
string s,q;

int main() 
{
    cin>>n>>m;
    for (i=1; i<=n; i++){
        a+=m+i-1;
    }
    
    for (i=1; i<=n; i++){
        if (abs(a-(a-(m+i-1)))<mn) mn=abs(a-(a-(m+i-1))),rs=a-(m+i-1);
    }
    cout<<rs;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
#define INF 1e9

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

    cin >> N;

    if(N%10 == 2 | N%10 == 4 | N%10 == 5 | N%10 == 7 | N%10 == 9) cout << "hon" << endl;
    else if(N%10 == 0 | N%10 == 1 | N%10 == 6 | N%10 == 8 )  cout << "pon" << endl;
    else  cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3648
import java.io.*;
import java.util.*;


class Main {
    static int n;
    static int[]p;
    static int a;
    static List<Integer>o;
    static void rot(int v){
        while(a!=v){
            o.add(1);
            a=(a+1)%n;
        }
    }
    static void sw(int v){
        rot(v+1);
        o.add(n-1);
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        n=sc.nextInt();
        p=new int[n];
        for(int i=0;i<n;++i)p[i]=sc.nextInt();
        o=new ArrayList<Integer>();
        for(int i=0;i<n;++i)
            for(int j=0;j<n-i-1;++j)
                if(p[j]>p[j+1]){
                    sw(j);
                    int t=p[j];
                    p[j]=p[j+1];
                    p[j+1]=t;
                }
        rot(0);
        out.println(o.size());
        for(int oo:o)out.println(oo);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 27280
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int tree[1000005];
int lazy[1000005];
void propogate(int i,int l,int r)
{
    tree[i]+=(r-l+1)*lazy[i];
    if(l!=r)
        lazy[i*2]+=lazy[i],lazy[i*2+1]+=lazy[i];
    lazy[i]=0;
}
void update(int i,int l,int r,int l1,int r1,int val)
{
    if(lazy[i])
        propogate(i,l,r);
    if(l1>r1 || l>r1 || l1>r)
        return;
    if(l1<=l && r<=r1)
    {
        tree[i]+=(r-l+1)*val;
        if(l!=r)
            lazy[i*2]+=val,lazy[i*2+1]+=val;
        return;
    }
    int mid=(l+r)/2;
    update(i*2,l,mid,l1,r1,val);
    update(i*2+1,mid+1,r,l1,r1,val);
    tree[i]=tree[i*2]+tree[i*2+1];
}
int query(int i,int l,int r,int l1,int r1)
{
    if(l1>r1 || l>r1 || l1>r)
        return 0;
    if(lazy[i])
        propogate(i,l,r);
    if(l1<=l && r<=r1)
        return tree[i];
    int mid=(l+r)/2;
    return query(i*2,l,mid,l1,r1)+query(i*2+1,mid+1,r,l1,r1);
}

int32_t main() 
{
    IOS
    int n,d,a;
    cin>>n>>d>>a;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    int ctr=0;
    for(int i=0;i<n;i++)
    {
        int reduce=query(1,1,n,i,i);
        v[i].second-=reduce;
        if(v[i].second<=0)
            continue;
        int need=v[i].second/a + ((v[i].second % a)!=0);
        ctr+=need;
        int low=i;
        int high=n-1;
        while(low<high)
        {
            int mid=(low+high+1)/2;
            if(v[mid].first-v[i].first>2*d)
                high=mid-1;
            else
                low=mid;
        }
        update(1,1,n,i,low,need*a);
    }
    print(ctr);
}   


Measured memory_bytes: 14696
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;

    vector<size_t> b(N + 1);
    for (size_t i = 1; i <= N; ++i) {
        cin >> b[i];
    }

    vector<size_t> res;
    res.reserve(N);

    while (b.size() > 1) {
        int i;
        for (i = b.size() - 1; i >= 0; --i) {
            if (b[i] == i) {
                break;
            }
        }

        if (i == 0) {
            return cout << -1 << "\n", 0;
        } else {
            res.emplace_back(i);
            b.erase(b.begin() + i);
        }
    }

    reverse(res.begin(), res.end());

    for (auto e: res) {
        cout << e << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n), y(n);
    rep(i, n) {
        if(s[i] == 'W') ++x[i];
        else ++y[i];
    }
    REP(i, 1, n) x[i] += x[i-1];
    REPR(i, n, 1) y[i-1] += y[i];
    int ans = n+1;
    rep(i, n) {
        int tmp = 0;
        if(i > 0) tmp += x[i-1];
        if(i < n-1) tmp += y[i+1];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
n = int(input())
li = set()
ali = set()
bli = set()
for i in range(n//3):
    ali.add(3*(i+1))
for j in range(n//5):
    bli.add(5*(j+1))
for k in range(n):
    li.add(k+1)
print(sum(li)-sum(ali | bli))

Measured memory_bytes: 137960
#include<stdio.h>
#include<math.h>

int isprime(int x);

int main()
{
  int i,n,cnt=0;


  scanf("%d",&n);
  int x[n];

  for( i = 0 ; i < n ; i++)
    {
      scanf("%d",&x[i]);
      
    }

  for(i = 0 ; i < n ; i++)
    {
      if(isprime(x[i])==1) cnt += 1;
    }

  printf("%d\n",cnt);


  return 0;
}

int isprime(int x)
{
	 if(x==2) return 1;
	 
	 if(x<2 || x%2 ==0) return 0;

	int i = 3;

	 while(i<=sqrt(x))
	      {
		if(x%i==0) 
		{
                  return 0;
                  break;
		}
		i = i+2; 
	      }
		return 1;
}





Measured memory_bytes: 2048
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,i,t,n;
	cin>>n;
	cin>>t;
	c=2000;
	for(i=0;i<n;i++){
		cin>>a;
		cin>>b;
		if(t>=b && a<c) c=a;
	}
	if(c==2000) cout<<"TLE"<<endl;
	else cout<<c<<endl;
	return 0;
}

	

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

int main(){
	int N, a, b = -1;
	scanf("%d", &N);
	a = 0;
	while(++a < 10)
	{
		if(N % a == 0 && N / a < 10)
			b = N / a;
	}
	printf(b < 0 ? "No" : "Yes");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}

	
int main(){
	init();
	ll n=0;
	cin>>n;
	string s;
	cin>>s;
	ll d[3];
	ll a=210;
	ll ans=0;
	for(int a=0;a<=999;a++){
		d[0]=a/100;
		d[1]=(a%100)/10;
		d[2]=a%10;
		
		bool isOK=false;
		for(int i=0;i<n;i++){
			if(s[i]-'0'==d[0]){
				for(int j=i+1;j<n;j++){
					if(s[j]-'0'==d[1]){	
						for(int k=j+1;k<n;k++){
							if(s[k]-'0'==d[2]){
								ans++;
							 	goto LAST;
							}
						}
						goto LAST;
					}
				}
				
				goto LAST;
			}
		}
		LAST:
		isOK=true;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int n, x;
	cin >> n;

	int c[100005];

	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		c[x - 1] = i + 1;
	}

	for (int i = 0; i < n; ++i)
		cout << c[i] << ' ';
	cout << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll hell=pow(10,9)+7;
ll par[100005],sz[100005];
ll find(ll i){
    if(i==par[i])
    return i;
    return par[i]=find(par[i]);
}
void merge(ll a,ll b){
    a=find(a);
    b=find(b);
    if(a==b)
    return;
    if(sz[a]<sz[b])
    swap(a,b);
    par[b]=a;
    sz[a]+=sz[b];
}
void solve(){
    ll n,m,k,res=0;
    cin>>n>>m>>k;
    vector<ll> cnt(n+1,0);
    for(ll i=1;i<=n;i++){
        par[i]=i;
        sz[i]=1;
    }
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        merge(a,b);
        cnt[a]++;
        cnt[b]++;
    }
    vector<vector<ll>> v(n+1);
    for(ll i=0;i<k;i++){
        ll a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(ll i=1;i<=n;i++){
        ll sum=ll(sz[find(i)])-cnt[i]-1;
        for(ll j=0;j<v[i].size();j++)
        if(find(v[i][j])==find(i))
        sum--;
        cout<<sum<<" ";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    for(ll qc=0;qc<t;qc++)
    solve();
}


Measured memory_bytes: 9088
# -*- coding: utf-8 -*-

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    x = int(input())

    return x


def main(x: int) -> None:
    """
    メイン処理.

    Args:\n
        x (int): 整数(0 <= x <= 1)
    """
    # 求解処理
    ans = 1 - x

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    x = get_input()

    # メイン処理
    main(x)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int N;
  cin>>N;
  vector<string>s(N);
  map<string,int>k;
  int64_t sum=0;
  for(int i=0;i<N;i++){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
    sum+=k[s[i]];
    k[s[i]]++;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 13924
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w

OK = "."
NG = "#"

@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    h,w = ss.shape
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    while q:
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
ss = np.array([[c=="#" for c in input()] for _ in range(h)])

print(main(ss,ch,cw,dh,dw))

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
char s[125252];

int ans[125252];

int main(){
    scanf("%s",s);
    n = strlen(s);
    {
        int x=0,y=0;
        REP(i,n){
            if(s[i]=='R'){
                x++;
                swap(x,y);
            }else{
                ans[i] += x;
                ans[i-1] += y;
                x = y = 0;
            }
        }
    }
    {
        int x=0,y=0;
        FORR(i,0,n){
            if(s[i]=='L'){
                x++;
                swap(x,y);
            }else{
                ans[i] += x;
                ans[i+1] += y;
                x = y = 0;
            }
        }
    }
    REP(i,n)printf("%d%c",ans[i]," \n"[i==n-1]);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

#define POW5(n) (n * n * n * n * n)

using namespace std;
int main(void) {
  lld x;
  cin >> x;
  for (lld a = -1000; a <= 1000; a++) {
    for (lld b = -1000; b <= 1000; b++) {
      if (POW5(a) - POW5(b) == x) {
        cout << a << " " << b << "\n";
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String s = stdR.readLine();
        boolean conse = false;
        char before = s.charAt(0);
        for(int i = 1 ; i < s.length(); i++) {
            if(before == s.charAt(i))conse = true;
            before = s.charAt(i);
        }
        if(conse) {
            System.out.println("Bad");
        }else {
            System.out.println("Good");
        }
    }
}


Measured memory_bytes: 23124
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

   String[] nyuA=sc.nextLine().split(" ");
   
int D=Integer.parseInt(nyuA[0]);
int N=Integer.parseInt(nyuA[1]);

int cut=0;
for(int x=1;;x++){
if(func(x)==D){
cut++;
if(cut==N){
System.out.println(x);
break;
}//if
}//if

}//f

//System.out.println(data);
}
static int func(int x){
if(x%100 !=0) return 0;
return func(x/100)+1;
}

}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

int main() {
    int D;
    cin >> D;
    string s = "Christmas Eve Eve Eve";
    if (D == 25) {
        s = "Christmas";
    } else if (D == 24) {
        s = "Christmas Eve";
    } else if (D == 23) {
        s = "Christmas Eve Eve";
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

int n, k;
int a[200005];

bool check(int mid) {
    int moves = 0;
    for(int i = 0; i < n; i++) {
        moves += (a[i] + mid - 1) / mid - 1;
    }
    return moves <= k;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> k;
		
	for(int i = 0; i < n; i++) {
	    cin >> a[i];  
	}
	
	int low = 1, high = *max_element(a, a+n);
	int ans = high;
	while(low <= high) {
	    int mid = (low + high) / 2;
	    if(check(mid))
	        ans = mid, high = mid - 1;
	    else 
	        low = mid + 1;
	}
	cout << ans << "\n";
	
}


Measured memory_bytes: 5168
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int h,w,d,a,q,l,r,imos[90010];
vpi pos;

int cost(const pi& a , const pi& b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}

int main(){
    I(h); I(w); I(d);
    pos.resize(h*w);
    REP(i,h) { REP(j,w){
        I(a);
        a--;
        pos[a] = {i,j};
    } }
    FOR(i,d,h*w){
        imos[i] = imos[i-d] + cost(pos[i], pos[i-d]);
    }
    I(q);
    REP(i,q){
        I(l); I(r);
        l--; r--;
        printf("%d\n", imos[r]-imos[l]);
    }
}


Measured memory_bytes: 2176
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

template<class T> inline bool chmin(T& to, T compare) {
    if (to > compare) {
        to = compare;
        return true;
    }
    return false;
};

template<class T> inline bool chmax(T& to, T compare) {
    if (to < compare) {
        to = compare;
        return true;
    }
    return false;
};

const llong MOD = 1e9 + 7;
const llong INF = 1e18;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N, W;
    cin >> N >> W;

    llong maxValue = N * 1000;

    vecllong weight(N + 1, 0);
    vecllong value(N + 1, 0);

    FOR(i, N) {
        cin >> weight[i] >> value[i];
    }

    vvecllong dp(N + 1, vecllong(maxValue + 1, INF));  // dp[i][value] = minWeight
    dp[0][0] = 0;

    FOR(i, N) {
        FOR(v, maxValue + 1) {
            if(v - value[i] >= 0 and dp[i][v - value[i]] != INF) {
                dp[i + 1][v] = min(
                    dp[i][v - value[i]] + weight[i],
                    dp[i][v]
                );
            } else {
                dp[i + 1][v] = dp[i][v];
            }
        }
    }

    llong ans = 0;

    FOR(v, maxValue + 1) {
        if(dp[N][v] <= W) {
            ans = v;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int x, i;
	
	i=1;
	while(1){
		cin >> x;
		if ( x == 0){
			break;
		}
		cout << "Case " << i << ": " << x << endl;
		i++;
	}
	
	return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        while (true) {
            String[] scores = scanner.nextLine().split(" ");
            
            if (scores[0].equals("-1") && scores[1].equals("-1") && scores[2].equals("-1")) {
                break;
            }
            
            System.out.println(validateScore(scores));
        }
    }
    
    private static String validateScore(String[] target) {
        int m = Integer.parseInt(target[0]);
        int f = Integer.parseInt(target[1]);
        int r = Integer.parseInt(target[2]);
        
        if (m == -1 || f == -1) {
            return "F";
        } else {
            int total = m + f;
            if (total >= 80) return "A";
            if (total >= 65 && total < 80) return "B";
            if (total >= 50 && total < 65) return "C";
            if (total >= 30 && total < 50) {
                if (r >= 50) return "C";
                else return "D";
            }
            return "F";
        }
    }
}


Measured memory_bytes: 26160
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(NULL);
string s,str1="",str2=""; cin>>s;
int q,k=0; cin>>q;
while(q--)
{
	int t; cin>>t;
	if(t==1)
	{
		k++;
	}
	else
	{
		int f; char ch; cin>>f>>ch;
		if(k%2)
		{
			if(f==1)
			f=2;
			else
			f=1;
		}
		if(f==1)
		{
			str1+=ch;
		}
		else
		{
			str2+=ch;
		}
	}
}
reverse(str1.begin(),str1.end());
s=str1+s+str2;
if(k%2)
reverse(s.begin(),s.end());
cout<<s;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>
#include <complex>
using namespace std;
typedef long long int ll;

typedef complex<long double> Point;
typedef vector<Point> Polygon; // 多角形
const long double eps=1e-9;

namespace std{
    bool operator<(const Point &p,const Point &q){
    if(p.real()<q.real()-eps) return true;
    if(p.real()>q.real()+eps) return false;
    return p.imag()<q.imag();
    }
}

long double dot(Point a,Point b){ // 内積
    return real(conj(a)*b);
}
long double cross(Point a,Point b){ // 外積
    return imag(conj(a)*b);
}

//CCW
int ccw(Point a,Point b,Point c){
    b-=a; c-=a;
    if(cross(b,c)>eps){
        return 1; // a,b,cが反時計回りの順に並ぶ
    }
    if(cross(b,c)<-eps){
        return -1; // a,b,cが時計回りの順に並ぶ
    }
    if(dot(b,c)<0){
        return 2; // c,a,bがこの順に一直線に並ぶ
    }
    if(norm(b)<norm(c)){
        return -2; // a,b,cの順に一直線に並ぶ
    }
    return 0; // a,c,bの順に一直線に並ぶ
}

// 凸包：凸多角形のある一辺上にある点を含まない
Polygon convex_hull(vector<Point> ps){
    int n=(int)ps.size();
    int k=0; // 凸包の頂点数
    sort(ps.begin(),ps.end());
    Polygon qs(2*n); // 構築中の凸包
    for(int i=0;i<n;qs[k++]=ps[i++]){
        while(k>=2&&ccw(qs[k-2],qs[k-1],ps[i])<=0) --k;
    }
    for(int i=n-2,t=k+1;i>=0;qs[k++]=ps[i--]){
        while(k>=t&&ccw(qs[k-2],qs[k-1],ps[i])<=0) --k;
    }
    qs.resize(k-1);
    return qs;
}

// 凸多角形の直径
pair<pair<ll,ll>,long double> convex_diameter(const Polygon& poly){
    int n=(int)poly.size();
    if(n==2){
        return make_pair(make_pair(0,1),abs(poly[0]-poly[1]));
    }
    int i=0,j=0; // ある方向に最も遠い点対
    // x軸方向に最も遠い点対を求める
    for(int k=0;k<n;k++){
        if(poly[k].imag()>poly[i].imag())i=k;
        if(poly[k].imag()<poly[j].imag())j=k;
    }
    pair<ll,ll> resp=make_pair(-1,-1);
    long double resd=0;
    int si,maxi,sj,maxj;
    si=maxi=i; sj=maxj=j;
    while(si!=maxj || sj!=maxi){
        long double cur=abs(poly[si]-poly[sj]);
        if(resd+eps<cur){
            resd=cur;
            resp=make_pair(si,sj);
        }
        int di=(si+1)%n, dj=(sj+1)%n;
        if(cross(poly[di]-poly[si],poly[dj]-poly[sj])<0){
            si=di;
        }
        else{
            sj=dj;
        }
    }
    return make_pair(resp,resd);
}

int main(){
    int n; cin >> n;
    if(n==1){
        ll x,y; cin >> x >> y;
        double ans=sqrtl(x*x+y*y);
        printf("%.10f\n",ans);
        return 0;
    }
    Polygon ps;
    for(int i=0;i<n;i++){
        int x,y; cin >> x >> y;
        ps.push_back(Point(0,0));
        int cp=ps.size();
        for(int j=0;j<cp;j++){
            Point r=ps[j]+Point(x,y);
            ps.push_back(Point(r.real(),r.imag()));
        }
        ps=convex_hull(ps);
    }
    ll ma=0;
    for(auto p:ps){
        ll x=p.real(),y=p.imag();
        ma=max(ma,x*x+y*y);
    }
    double ans=sqrtl(ma);
    printf("%.10f\n",ans);
}

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

struct Point2D {
    float x, y;

    Point2D() {}
    Point2D(float ax, float ay) {
        x = ax;
        y = ay;
    }
    Point2D operator -(Point2D &p) {
        return Point2D(x - p.x, y - p.y);
    }
    double slope(Point2D &p) {
        return (p.x != x) ? (p.y - y) / (p.x - x) : numeric_limits<float>::infinity();
    }
    double cross(Point2D &p) { // only z
        return x * p.y - y * p.x;
    }
};

namespace std {
    istream &operator>>(istream &is, Point2D &p) {
        is >> p.x >> p.y;
        return is;
    }

    ostream &operator<<(ostream &os, Point2D &p) {
        os << fixed << p.x << " " << p.y;
        return os;
    }
}

int main()
{
    int n;
    cin >> n;
    for (Point2D a, b, c, d; n-- && cin >> a >> b >> c >> d;)
        cout << ((a.slope(b) == c.slope(d)) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 1228
N,L=map(int,input().split())
ringo=[L+i for i in range(N)]
idealy = sum(ringo)
min_ringo = min(list(map(abs, ringo)))

if min_ringo in ringo:
    ringo.append(-min_ringo)
else:
    ringo.append(min_ringo)

print(sum(ringo))

Measured memory_bytes: 3060