akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
struct node{   
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node root;
void insert(int);
void preorder(Node);
void inorder(Node);
int main()
{
  int size, key;
  char Op[10];  

  scanf("%d",&size);

  for(int i=0;i<size;i++){
    scanf("%s",Op);
    if(Op[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }
  }
  return 0;
}

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

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



Measured memory_bytes: 25128
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            ArrayList<Character> c = new ArrayList<>();
            int r = 0;
            for (char c1 : sc.next().toCharArray()) c.add(c1);
            if (c.get(0) == 'R') r++;
            if (c.get(1) == 'S') if (r == 1) return 1;
            if (c.get(1) == 'R') r++;
            if (c.get(2) == 'R') r++;
            return r;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}

Measured memory_bytes: 27020
console.log((args=>{
  const _ = args.trim().split`\n`;
  const N = _[0]|0, X = _[1].split``.map(v=>v|0);
  function popcount(n) {
    n = (n&0x55555555) + (n>>1&0x55555555);
    n = (n&0x33333333) + (n>>2&0x33333333);
    n = (n&0x0f0f0f0f) + (n>>4&0x0f0f0f0f);
    n = (n&0x00ff00ff) + (n>>8&0x00ff00ff);
    return (n&0x000ffff) + (n>>16);
  }
  let pc = 0;
  for ( let i = 0; i < N; i++ ) if ( X[i]|0 ) pc++;
  const pcp = pc+1, pcm = pc-1;
  let xpp = 0, xpm = 0;
  for ( let i = 0; i < N; i++) {
    xpp = ((xpp<<1) + X[i]) % pcp;
    xpm = ((xpm<<1) + X[i]) % pcm;
  }
  const o = Array(N).fill(1);
  let bp = 1, bm = pcm-1;
  for ( let i = N; i--;) {
    let n = 0;
    if ( !X[i] ) n = (xpp + bp)%pcp;
    else if ( pcm > 0 ) n = (xpm + bm)%pcm;
    else o[i] = 0;
    while(n) {
      n %= popcount(n);
      o[i]++;
    }
    bp = (bp*2) % pcp;
    bm = (bm*2) % pcm;
  }
  return o.join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 43844
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;



int main(){
	while (1) {
		double h, x;
		cin >> x >> h;
		if (x == 0 && h == 0) return 0;
		printf("%.6f\n", x*x + sqrt(x / 2 * x / 2 + h*h) * 2 * x);
	}
	return 0;
}

Measured memory_bytes: 3080
def main():
    import sys
    import itertools

    input = sys.stdin.readline

    n, k = map(int, input().split())
    l = list(range(0, n + 1))
    l_1 = list(itertools.accumulate(l))
    ans = 0
    for i in range(k, n + 2):
        if i == n + 1:
            ans += 1
        else:
            mini = l_1[i - 1]
            maxi = l_1[-1] - l_1[-i - 1]
            ans += (maxi - mini + 1)
    print(ans % (10 ** 9 + 7))

if __name__ == "__main__":
    main()

Measured memory_bytes: 27208
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    public static void main(String[] args)  throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        int tmp = 0;
        while (true){
            if(a%b==0||b==1){
                System.out.println(b);
                break;
            }else{
                tmp = a;
                a = b;
                b = tmp%b;
            }
        }
    }
}

Measured memory_bytes: 17328
import java.util.Scanner;
 
public class Main{
 public static void main(String[] a){
     Scanner s = new Scanner(System.in);
     int i,x,now;
     boolean ch=false;
     x = s.nextInt();
     for(i=1;i<=x;i++){
         now=i;
         if(i%3==0)ch=true;
         while(now>0&&ch==false){
            if(now%10==3)ch=true;
            now/=10;
         }
         if(ch==true){
             ch=false;
             System.out.print(" "+i);
         }
     }
    System.out.println();
 }   
}


Measured memory_bytes: 28992
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
int d[100000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
ll getPow(ll a, ll b){
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll d = getPow(a, b / 2);
		return (d*d) % MOD;
	}
	else {
		return (a*getPow(a, b - 1))%MOD;
	}
}


int main() {
	int n,d;
	scanf("%d%d", &n, &d);

	int x[10][10];
	REP(i, n) {
		REP(j, d) {
			scanf("%d", &x[i][j]);
		}
	}

	int ans = 0;
	REP(i, n-1) {
		FOR(j, i + 1, n) {
			int sum = 0;
			REP(k, d) {
				sum += abs(x[i][k] - x[j][k])*abs(x[i][k] - x[j][k]);
			}
			REP(k, 1000) {
				if (k*k > sum)break;
				if (k*k == sum)ans++;
			}
		}
	}


	PRINTD(ans);
}


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

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

  long long a, b, c;
  cin >> a >> b >> c;

  if (c - a - b < 0) {
    cout << "No" << endl;
    return 0;
  } 
  if (4 * a * b < (c - a - b) * (c - a - b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S; cin >> S;
	long long ans = 0, sum = 0;
	for (long long i = 0; i < S.size(); i++) {
		sum += (S.at(i) - '0');
		if (i == 0) {
			ans += (S.at(i) - '0') - 1;
		}
		else ans += 9;
	}
	cout << max(ans,sum) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    int sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A') sum++;
        else if(s[i] == 'T') sum++;
        else if(s[i] == 'C') sum++;
        else if(s[i] == 'G') sum++;
        else {
            ans = max(ans,sum);
            sum=0;
        }
    }
    cout<<(ans > sum ? ans : sum)<<endl;
    return 0;
    
}



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

using namespace std;

int main(){

string s;

cin >> s;
int cnt=0;
for (int i = 0; i < s.size()/2; i++)
{
	if (s[i] != s[s.size()-1-i])
	{
		cnt++;	
	}
}

cout << cnt;
}

Measured memory_bytes: 256
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n!=0:
    for i in range((max(p)+3)**2):
        num=x+i in p
        num2=x-i in p
        if num2==False:
            ans=x-i
            break
        if num==False:
            ans=x+i
            break
else:
    ans=x
print(ans)


Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	ll int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(max((a*c),(max((a*d),max((b*c),(b*d))))));	
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
#define fl float
typedef pair<ll, ll> pii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<fl> vf;
typedef vector<ld> vd;                // Vector of long double
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<vd> vvd;
typedef vector<vf> vvf;
typedef vector<pii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
ll mod = 1e9 + 7;
ll t=1;

// vvi adj;
ll n,m,x,y;
vi dp,vis;
// vvf adj;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin>>t;
    while(t--){
    cin>>n;
    ld adj[n][n+1]={0};
    ld a[n];
    // adj.resize(n+1);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<=n;i++)adj[0][i]=0;

    // for(int i=1;i<=n;i++){
    //     for(int j=0;j<=n;j++)adj[i].pb(0);
    // }

    adj[0][0] = (1-a[0]);
    adj[0][1] = a[0];
    for(int i=1;i<n;i++){
        // if(i==1){adj[i][0] = 1-a[i]; adj[i][1] = a[i];continue;}
        // else {  
            adj[i][0] = adj[i-1][0]*(1-a[i]);
            for(int j=1;j<=n;j++){adj[i][j] = adj[i-1][j]*(1-a[i]) + adj[i-1][j-1]*(a[i]);}            
        // }
    }
    ld ans=0;
    ll i=n;
    while(i>n/2){
        ans+=adj[n-1][i];i--;
    }
    cout<<fixed<<setprecision(9 )<<ans<<"\n";

    }
    return 0;
}    

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(int x,int y)
{
    if((4*x-y)%2 == 0 && (4*x-y)>=0 && (y-2*x)%2 == 0 && (y-2*x)>=0)
        cout<<"Yes";
    else
        cout<<"No";
}
int main()
{
    int x,y;
    cin>>x>>y;
    solve(x,y);
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


int Main(int A, int B)
{
    return max({A+B, A-B, A*B});
}

int main(void){
    int A, B;
    cin >> A >> B;
    cout << Main(A, B) << endl;
    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int n;
vector<int> a;
/**********************************************/

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

    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];

    sort(all(a), greater<int>());

    int bob = 0, alice = 0;
    REP(i, n){
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n) cin >> a[i];
    map<ll,ll> cnt;
    rep(i,n){
        cnt[a[i]]++;
    }
    for(auto c :cnt){
        if(c.second> 1){
            cout << "NO"<<endl;
            return 0;
        }
    }
    cout << "YES" <<endl;
    return 0;
}

Measured memory_bytes: 14336
mp = ["" for j in range(102)]
f = [[1 for i in range(102)] for j in range(102)]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
while 1:
    H, W = map(int, raw_input().split())
    if H==0 and W==0 : break;
    mp[0] = mp[H+1] = "X"*(W+2);
    for i in range(1, H+1):
        mp[i] = "X"+raw_input()+"X"
        for j in range(1, W+1):
            f[i][j] = 0
    s = []; ans = 0;
    for i in range(1, H+1):
        for j in range(1, W+1):
            if f[i][j]==0:
                ans+=1; c = mp[i][j];
                s.append([j, i])
                while len(s)>0:
                    x, y = s.pop()
                    f[y][x] = 1
                    for k in range(4):
                        if mp[y+dy[k]][x+dx[k]]==c and f[y+dy[k]][x+dx[k]]==0:
                            s.append([x+dx[k], y+dy[k]])
    print(ans)

Measured memory_bytes: 5320
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
int main(){
	int e[4];
	for(int i=0;i<4;i++){
		cin>>e[i];
	}
	sort(e,e+4);
	if(e[0]==e[1] && e[2]==e[3]){
		cout<<"yes"<<endl;
	}
	else {
		cout<<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
using namespace std;
int n;

int dfs(int i,int j,int sum,vector<int> a)
{
	int ans = 0;

	if (i == 1 && j == n-1) { return sum + a[j + i * n]; }
	if (i >= 2) return -1;
	if (j >= n) return -1;

	ans = max(ans, dfs(i + 1, j, sum + a[j + i * n],a));
	ans = max(ans, dfs(i, j + 1, sum + a[j + i * n],a));

	return ans;
}

int main()
{
	cin >> n;
	std::vector<int> a1(n * 2);
	for (int i = 0;i < n*2;i++) { cin >> a1[i]; }

	cout << dfs(0,0,0,a1) << endl;

	return 0;
}

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

using namespace std;

struct value{
    long long v;
    double vper, size;
};

bool comp(const value& e1, const value& e2){
    if(e1.vper < e2.vper){
        return true;
    }else{
        return false;
    }
}

int main(void){
    long long Q, H, S, D;
    double N;

    cin >> Q >> H >> S >> D;
    cin >> N;

    value v[4];
    
    v[0].v = Q;
    v[0].vper = Q*8;
    v[0].size = 0.25;
    
    v[1].v = H;
    v[1].vper = H*4;
    v[1].size = 0.50;

    v[2].v = S;
    v[2].vper = S*2;
    v[2].size = 1.00;

    v[3].v = D;
    v[3].vper = D;
    v[3].size = 2.00;


    if(N == 1){
        sort(v,v+3,comp);
        long long tmp1 = N/v[0].size;
        long long sum2 = 0;
        sum2 += tmp1 * v[0].v;

        cout << sum2 << endl;

        return 0;
    }else{
        sort(v, v+4, comp);
    }

    long long tmp = N / v[0].size;
    long long sum = 0;

    sum += tmp * v[0].v;
    N -= tmp * v[0].size;
    
    if(v[0].size == 2){
        tmp = N/v[1].size;
        sum += tmp * v[1].v;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Input();
            var a = Input3();
            long cnt = 1;
            long ans = 0;

            for(long i = 0; i < n; i++)
            {
                if (a[i] != cnt) ans++;
                else cnt++;
            }
            if (cnt == 1) ans = -1;
            

           
            
            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }

        
       
    }
}


Measured memory_bytes: 33884
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    var aa = mutableListOf<String>()
    var bb = mutableListOf<String>()

    repeat(n) { aa.add(next()) }
    repeat(m) { bb.add(next()) }

    // vertical
    for(i in 0..n-m) {
        // horizontal
        for(j in 0..n-m) {
            var cursor = 0
            val index = aa[i].indexOf(bb[cursor], j)
            if (index == -1) continue

            // check vertically
            var failed = false
            while (cursor < bb.size) {
                if (aa[i + cursor].indexOf(bb[cursor], j) != index) {
                    failed = true
                    break
                }
                cursor++
            }

            if (!failed) {
                println("Yes")
                return
            }
        }
    }

    println("No")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 38204
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

int n, w[1000], s;
int a[1000], d[10001]; //destination 

long solve(){
	long ret=0;	
	
	bool v[1000];
	for(int i=0; i<n; ++i){
		a[i]=w[i];
		v[i]=false;	
	}
	sort(a, a+n); //a[]??????w[]???????????¢?????\???
	
	//??????a[i]??????????????????????????´??????d[]?????\??????
	for(int i=0; i<n; ++i) d[a[i]]=i;
	
	for(int i=0; i<n; ++i){
		if(v[i]) continue; //??¢???????????????????????????????????????????????§???????????????????????£?????????
		
		//?????????????????¢???
		int cur=i; //?????¨??????
		int sum=0;
		int m=10000; //???????????????????????????????°????
		int an=0; //?????????????????§??????
		
		while(1){
			v[cur]=true; //?¨??????????????¨????
			an++;
			int z=w[cur];
			sum+=z;
			m=min(m, z);
			cur=d[z]; //?¬??????????
			if(v[cur]) break; //?????¨??????
		}
		
		ret += min(sum+(an-2)*m , m+sum+(an+1)*s);	
	}
	return ret;
}

int main(){
	scanf(" %d", &n);
	
	s=10000;
	for(int i=0; i<n; ++i){
		scanf(" %d", &w[i]);
		s=min(s, w[i]); //s???w[]?????????????°????????´?
	}
	
	printf("%ld\n", solve());
}

Measured memory_bytes: 1224
from sys import stdin


def ceil(a,b):
    return (a+b-1)//b


def floor(a,b):
    return a//b


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    a,b,x = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = floor(b,x)-ceil(a,x)+1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using namespace std;
using ll = long long;

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

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

  int sum = a + b + c;
  if (sum >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int A,B; cin >>A>>B;
    Yes(A%2&&B%2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int x, y;
	cin >> x >> y;
	zip(i, 0, 1001)
	{
		zip(j, 0, 1001)
		{
			if (2 * i + 4 * j == y && i + j == x)
			{
				cout << "Yes" << en;
				return 0;
			}
		}
	}
	cout << "No" << en;



	return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) rep(i,0,n)

int main()
{
    int n,q,b,e;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    cin>>q;
    REP(i,q)
    {
        cin>>b>>e;
        auto bb=a.begin(),ee=a.begin();
        bb+=b;ee+=e;
        reverse(bb,ee);
    }
    REP(i,n)
    {
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
}


Measured memory_bytes: 3084
N,K=map(int,input().split())
import math
ans=float(0)
for i in range(1,N+1):
    if i>=K:
        ans+=1/N
    else:
        n=math.ceil(math.log(K/i, 2))
        ans+=1/N*(1/2)**n
    #print(ans)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;

int main(){
    AC
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s<<endl;
    else{
        for(int i=0; i<k; i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }
        

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,pii>
#define PLL pair<ll,ll>
#define PLII pair<ll,pii>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 100001
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

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

    string ans="";
    loop(i,0,n) ans+='.';
    if(m)
    {
        int s[m],c[m];
        loop(i,0,m) cin>>s[i]>>c[i];
        loop(i,0,m)
        {
            //cout<<ans[s[i]-1]<<' '<<i<<'\n';
            if(ans[s[i]-1] == '.' || ans[s[i]-1] == (c[i]+'0')) ans[s[i]-1] = (c[i]+'0');
            else {ans = "-1"; break;}
        }
    }

    if(ans != "-1")
    {
        if(n==1) {if(ans[0]=='.') ans[0] = '0';}
        else
        {
            if(ans[0]=='.') ans[0] = '1';
            loop(i,1,n) {if(ans[i]=='.') ans[i] = '0';}
            if(ans[0]=='0') ans = "-1";
        }
    }

    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
#define X first
#define Y second
using namespace std;

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

const int N = 2e5 + 228;

ll dp[N][3], a[N][3];

int main()
{
    #ifdef LOCAL_RUN
        freopen("input.txt", "r", stdin);
    //#else
        //freopen("tickets.in", "r", stdin);
        //freopen("tickets.out", "w", stdout);
    #endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
            }
        }
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);

    return 0;
}

// 272472LF


Measured memory_bytes: 8264
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, m, c = 0, j = 0; cin>>n>>m;
	vector<pair<ll, ll> > a(n);
	for(int i=0; i<n; ++i) cin>>a[i].first>>a[i].second;
	sort(a.begin(), a.end());
	while (m && j < n){
		c+= min(m, a[j].second) * a[j].first;
		m-=min(m, a[j].second);
		j++;
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct node
{
    int o,q;
    string p;
}a[150];
int cmp(node a,node b)
{
    if(a.p==b.p)
        return a.q>b.q;
    return a.p<b.p;
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        cin>>a[i].p>>a[i].q;
        a[i].o=i+1;
    }
    sort(a,a+n,cmp);
    for(i=0;i<n;i++)
    printf("%d\n",a[i].o);
    return 0;
}


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

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n" 
#define all(c) c.begin(),c.end()
#define present(c,element) (c.find(element)!=c.end())
#define cpresent(c,element) (find(c,element)!=c.end())
#define forr(i,a,b) for(int i=a;i<int(b);i++)
#define tr(i,a) for(auto i:a)
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
const double PI=acos(-1);
const ll mod=1e9+7;

vector<int> adj[100005];
vi dp(100005, 0);
vector<bool> vis(100005, false);

void dfs(int v)
{
	vis[v]=true;
	for(int i=0;i<adj[v].size();i++)
	{
		if(!vis[adj[v][i]])
			dfs(adj[v][i]);
		dp[v]=max(dp[v], 1+dp[adj[v][i]]);
	}
}



int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

int test=1;
//cin>>test;
while(test--)
{
	int n, m, x, y;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(int i=0;i<=n;i++)
	{
		if(!vis[i])
			dfs(i);
	}
	int ans=*max_element(all(dp));
	cout<<ans<<endl;


}
return 0;
}










Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var nab = Input3();
            var c = nab[0] / (nab[1] + nab[2]);
            var ans = 0L;
            if (nab[0] % (nab[1] + nab[2]) > nab[1]) ans += nab[1];
            else ans += nab[0] % (nab[1] + nab[2]);
            ans += nab[1] * c;
            Console.WriteLine(ans);



        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main()
{
	int number,x,y;
	scanf("%d",&number); //91
	x=number%10; //1
	y=number/10; //9
	if(x==9 || y==9)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}

Measured memory_bytes: 128
use proconio::input;
use rand::prelude::*;
use std::collections::BTreeSet;

fn eval_lasts(days: i64, cs: &Vec<i64>, schedule: &Vec<BTreeSet<i64>>) -> i64 {
    let mut score = 0;

    for i in 0..cs.len() {
        let mut last = -1;

        for d in schedule[i].iter() {
            let x = d - last;
            let n = (x * (x - 1)) / 2;
            score -= cs[i] * n;
            last = *d;
        }
        let x = days - last;
        let n = (x * (x - 1)) / 2;
        score -= cs[i] * n;
    }

    score
}

fn eval(
    days: u64,
    cs: &Vec<i64>,
    sats: &Vec<Vec<i64>>,
    ts: &Vec<u64>,
) -> (i64, Vec<BTreeSet<i64>>) {
    let mut score = 0;

    let mut schedule = vec![BTreeSet::<i64>::new(); 26];

    for day in 0usize..(days as usize) {
        let contest = ts[day as usize] as usize;
        score += sats[day][contest] as i64;
        schedule[contest].insert(day as i64);
    }

    (score, schedule)
}

fn main() {
    input! { days: u64 };
    let mut cs = vec![0; 26];

    for i in 0..26 {
        input! {
            x: i64
        };

        cs[i] = x;
    }

    let mut sats = vec![vec![0; 26]; days as usize];
    for d in 0..days {
        for i in 0..26 {
            input! {
                s: i64
            };

            sats[d as usize][i as usize] = s;
        }
    }

    let mut ts = vec![0u64; days as usize];
    for i in 0..ts.len() {
        ts[i] = (i as u64) % 26;
    }

    let (mut base_score, mut schedule) = eval(days, &cs, &sats, &ts);

    let mut cur_score = base_score + eval_lasts(days as i64, &cs, &schedule);

    for _ in 0..300000 {
        let d = rand::random::<usize>() % days as usize;
        let q = rand::random::<usize>() % 26;

        let prev = ts[d as usize] as usize;
        let mut next_score = base_score;
        next_score -= sats[d][prev];
        next_score += sats[d][q];

        schedule[prev].remove(&(d as i64));
        schedule[q].insert(d as i64);

        let s2 = eval_lasts(days as i64, &cs, &schedule);

        if next_score + s2 > cur_score {
            base_score = next_score;
            cur_score = next_score + s2;
            ts[d as usize] = q as u64;
        } else {
            schedule[q].remove(&(d as i64));
            schedule[prev].insert(d as i64);
        }
    }

    for t in ts {
        println!("{}", t + 1);
    }
}


Measured memory_bytes: 2772
#include <stdio.h>
 
int main(void) {
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
		printf("%d %d %d\n",a,b,c);
		}
		else if((a<c)&&(c<b)){
		printf("%d %d %d\n",a,c,b);
		}
		else{
		printf("%d %d %d\n",c,a,b);
		}
	}
	if(b<a){
		if(a<c){
		printf("%d %d %d\n",b,a,c);
		}
		else if((b<c)&&(c<a)){
		printf("%d %d %d\n",b,c,a);
		}
		else{
		printf("%d %d %d\n",c,b,a);
		}
	}
return 0;
}

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

int main() { /* ここに書く */
  
  long A,B,C,N,M ;
  cin >> A >> B >> C ;
  N = (C-A-B)*(C-A-B);
  M = 4*A*B;
  
  if( C < (A + B) ){
    cout << "No" << endl;}
  
  else if
    ( N > M ){
    cout << "Yes" << endl;}
  
  else{
    cout << "No" << endl;}
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b;
    cin >> a >> b;
    cout << max( max( a + b, a - b ), a * b ) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a,b,k;cin>>a>>b>>k;
  vector<int> v;
  int sum=0;
  for(int i=1;;i++){
    if(a%i==0&&b%i==0)v.push_back(i);
    if(i==min(a,b))break;
  }
  cout<<v[v.size()-k]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 0;
	 cin >> nn;
	 vector<int64> aa(nn);
	 for(int64 ii = 0;ii < nn;ii++)
	 {
		cin >> aa[ii];
	}
	for(int64 ii = 1;ii < nn;ii++)
	{
		if(aa[ii - 1] > aa[ii])
		{
			ans += (aa[ii - 1] - aa[ii]);
			aa[ii] = aa[ii - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

int main() {
	int x, y;
	cin >> x >> y;

	cout << x + y - GCD(x, y) + 1 << endl;
}


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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	ans = 0
	for i in range(1, n):
		if a[i-1] > a[i]:
			ans += a[i-1] - a[i]
			a[i] = a[i-1]
	log.print(a)
	print(ans)

main()

Measured memory_bytes: 95280
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

char field[110][110];

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

int h, w;
void bfs(int p, int q, char m){
    for(int i=0; i < 4; i++){
        if(field[dx[i]+p][dy[i]+q] == m){
            field[dx[i]+p][dy[i]+q] = '-';
            bfs(dx[i]+p, dy[i]+q, m);
        }
    }
}

int main(){
    while(cin >> h >> w, h+w){
        for(int i=0; i < h ; i++){
            for(int j=0; j < w; j++){
                cin >> field[i][j];
            }
        }
        int count = 0;
        for(int i=0; i < h; i++){
            for(int j=0; j < w; j++){
                if(field[i][j] != '-'){
                    count++;
                    bfs(i, j, field[i][j]);
                }
            }
        }
        cout << count << endl;
    }
}

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

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0] * M
keys = [0] * M
inf = 10 ** 12
for i in range(M):
    a[i], _ = map(int, input().split())
    c_list = list(map(int, input().split()))
    keys[i] = sum([2 ** j for j in range(N) if j + 1 in c_list])

dp = [inf] * (2 ** N)
dp[0] = 0

# print(keys)

for i in range(M):  # use key i
    for j in range(2 ** N):
        # print(dp, j, keys[i], dp[j | keys[i]], dp[j], a[i])
        dp[j | keys[i]] = min(dp[j] + a[i], dp[j | keys[i]])

ans = dp[-1]
if ans == inf:
    ans = -1
print(ans)


Measured memory_bytes: 42476
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N=110, MAX_W=10010;
int dp[MAX_N][MAX_W];

int main(){
	int n, W;
	cin>>n>>W;
	vi v(n+1, 0), w(n+1, 0);
	v[0]=0; w[0]=0;
	for(int i = 1; i <= n; i++){
		cin>>v[i]>>w[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= W; j++){
			if(j<w[i]) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
		}
	}
	cout<<dp[n][W]<<endl;
}
 
 

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

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1)
{
    for (int u : to[v])
    {
        if (u == p)
            continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main()
{

    int n, q;
    cin >> n >> q;

    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i, q)
    {
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);

    rep(i, n) i != n - 1 ? cout << ans[i] << " " : OP(ans[i]);
    return 0;
}

Measured memory_bytes: 23552
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define ll long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D long double

using namespace std;

const D pi=acos(-1);

int h,m,T;
D ans,A,B,C,a;

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	scanf("%Lf%Lf",&A,&B);
	scanf("%d%d",&h,&m);
	ans=1.0*h*30+1.0*m/2-m*6;
	while(ans<0) ans+=360;
	while(ans>=360) ans-=360;
	if(ans>180) ans=360-ans;
	D k=cos(ans/180*pi);
	C=sqrt(A*A+B*B-2*A*B*k);
	printf("%.18Lf",C);

    return 0;
}

Measured memory_bytes: 4216
# coding: utf-8
# Your code here!
K = int(input())
A,B = map(int, input().split())
c = 1 
for i in range(A,B+1):
    if i % K == 0: 
        print("OK")
        c = 0
        break

if not c == 0:
    print("NG")


Measured memory_bytes: 9168
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	char s[20];
	char c[20];
	scanf("%s",s);
	getchar();
	int t=strlen(s);
	int r=0;
	int flag=0;
	int j=0;
	for(int i=t-1;i>=0;i--)
	{
		if(s[i]=='0'||s[i]=='1')
		{
			if(r==0)
			c[j++]=s[i];
			else
			r--;
		}
		else
		r++;
	}
	for(int i=j-1;i>=0;i--)
	printf("%c",c[i]);
	return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
const int MAXN = (1 << 20);

int a, b, x;

void read()
{
	cin >> x >> a >> b;
}

void solve()
{
	if(abs(x - a) < abs(x - b)) cout << "A" << endl;
	else cout << "B" << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    long long a,b,c,x,y,total=0;
    cin>>a>>b>>c>>x>>y;
    
    if(a+b>=2*c) total += 2*c*min(x,y);
    else total += (a+b)*min(x,y);
    
    if(min(x,y)==x){
        if(b>=2*c) total += 2*c*(y-x);
        else total += b*(y-x);
    }else{
        if(a>=2*c) total += 2*c*(x-y);
        else total += a*(x-y);
    }
    
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();

			int ans = 0;
			for (int i = 1; i < n - 1; i++) {
				var lc = new int[26];
				var rc = new int[26];
				for (int j = 0; j < i; j++) {
					lc[s[j] - 'a']++;
				}

				for (int j = i; j < n; j++) {
					rc[s[j] - 'a']++;
				}

				int cnt = 0;
				for (int j = 0; j < 26; j++) {
					if (lc[j] > 0 && rc[j] > 0) {
						++cnt;
					}
				}

				ans = Math.Max(ans, cnt);
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13140
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
#define N 200010
int a[N];
int main() {

    int k, n;
    int money, stock;
    while (scanf("%d",&n)!=EOF) {
        long long money = 1000;
        long long stock = 0;
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for (int i=1;i<n;i++) {
            if (a[i]<=a[i+1]) {
                stock+=money/a[i];
                money%=a[i];
            }
            else {
                money+=stock*a[i];
                stock = 0;
            }
        }
        money+=stock*a[n];
        cout << money <<endl;
    }
    return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
set<int> r;
int lz = 0;
int a[maxn];
int main() {
	int n;
	ll ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int res = 0;
	for (int i = n; i >= 1; i--) {
		lz++;
		if (!r.empty() && a[i] + lz < *(--r.end())) {
			cout << -1 << endl;
			return 0;
		}
		r.insert(a[i] + lz);
		if (r.find(lz) != r.end()) r.erase(lz);
		ans += r.size();
	}
	if (!r.empty()) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760