akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

#define loop(i, num) for (int i = 0; i < num; i++)

using namespace std;

vector<int> color;

vector<vector<int>> map;

int main() {

    int m, n, num;
    
    cin >> m >> n;
    
    cin >> num;
    
    map.resize(m, vector<int>(n, 0));
    
    color.resize(num);
    
    loop (i, num)  cin >> color[i];
    
    int i = 0, j = -1, current = 1;
    
    while (i < m) {
        
        if (j == -1) {
            
            j++;
        
            for (; j < n; j++) {
                
                current += color[current - 1] == 0 ? 1 : 0;
            
                map[i][j] = current;
                
                color[current - 1]--;
                
            }
            
        } else if (j == n) {
            
            j--;
        
            for (; j >= 0; j--) {
                
                current += color[current - 1] == 0 ? 1 : 0;
            
                map[i][j] = current;
                
                color[current - 1]--;
                
            }
        
        }
        
        i++;
    
    }
    
    loop (i, m) {
    
        loop (j , n) {
        
            cout << map[i][j] << " ";
        
        }
        
        cout << endl;
    
    }

}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const int mn=2e5+4;
const int md=107;
const int me=md*2+1;
const int mz=me*me*me;
int a[mn];
ll pre[mn];
ll query(int l, int r) {
  return pre[r]-pre[l-1];
}
int eq(int l, int r) {
  if (r-l+1<2) return -123;
  ll want=query(l,r)/2;
  int imin=l,imax=r-1+1;
  assert(imin<imax);
  while(imin<imax) {
    int imid=(imin+imax)>>1;
    if (query(l,imid)<want) imin=imid+1;
    else imax=imid;
  }
  return imin;
}
int main(){ 
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; scanf("%d",&n);
  for (int i=1;i<=n;i++) scanf("%d",a+i);
  for (int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
  ll ans=LLONG_MAX;
  for (int b=1;b<=n;b++) {
    // L is [1,b]. R is [b+1,n].
    int wa=eq(1,b),wc=eq(b+1,n);
    if (wa==-123||wc==-123) continue;
    for (int a=wa-2;a<=wa+2;a++) {
      for (int c=wc-2;c<=wc+2;c++) {
        if (1<=a&&a<b&&b<c&&c<=n-1) {
          ll s1=query(1,a);
          ll s2=query(a+1,b);
          ll s3=query(b+1,c);
          ll s4=query(c+1,n);
          ll lo=min(min(s1,s2),min(s3,s4));
          ll hi=max(max(s1,s2),max(s3,s4));
          ll cand=hi-lo;
          chkmin(ans,cand);
        }
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}



Measured memory_bytes: 2560
x, y = map(int, input().split())

if y == 0:
    if x >= 0:
        print(x+1)
    else:
        print(-x)
    exit()

if x >= 0 and y >= 0:
    if x <= y:
        print(y-x)
    else:
        print(1+(-y+x)+1)
elif x >= 0 and y <= 0:
    if x >= -y:
        print(1+x-(-y))
    else:
        print(-y-x+1)
elif x <= 0 and y >= 0:
    if y >= -x:
        print(1+(y-(-x)))
    else:
        print(-y-x+1)
else:
    if x <= y:
        print(y-x)
    else:
        print(1-y+x+1)


Measured memory_bytes: 9084
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::vector<ll> G[200010];
ll dep[200010];
std::vector<ll> vs[2];
std::vector<ll> num[3];
ll ans[200010];

void dfs( ll v, ll p = -1, ll d = 0 ) {
  dep[v] = d;

  for( auto u : G[v] ) if( u != p ) {
    dfs( u, v, d+1 );
  }
}

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

  rep( i, N-1 ) {
    ll a, b;
    std::cin >> a >> b;
    --a; --b;

    G[a].emplace_back( b );
    G[b].emplace_back( a );
  }

  dfs( 0 );

  rep( i, N ) {
    vs[dep[i]%2].emplace_back( i );
    num[(i+1)%3].emplace_back( i+1 );
  }

  if( vs[0].size() <= N/3 ) {
    ll cnt = 0;

    rep( i, vs[0].size() )
      ans[vs[0][i]] = num[0][cnt++];

    rep( i, vs[1].size() ) {
      if( i < num[1].size() )
        ans[vs[1][i]] = num[1][i];
      else if( i < num[1].size()+num[2].size() )
        ans[vs[1][i]] = num[2][i-num[1].size()];
      else
        ans[vs[1][i]] = num[0][cnt++];
    }
  } else if( vs[1].size() <= N/3 ) {
    ll cnt = 0;

    rep( i, vs[1].size() )
      ans[vs[1][i]] = num[0][cnt++];
    
    rep( i, vs[0].size() ) {
      if( i < num[1].size() )
        ans[vs[0][i]] = num[1][i];
      else if( i < num[1].size()+num[2].size() )
        ans[vs[0][i]] = num[2][i-num[1].size()];
      else
        ans[vs[0][i]] = num[0][cnt++];
    }
  } else {
    ll cnt = 0;

    rep( i, vs[0].size() ) {
      if( i < num[1].size() )
        ans[vs[0][i]] = num[1][i];
      else
        ans[vs[0][i]] = num[0][cnt++];
    }

    rep( i, vs[1].size() ) {
      if( i < num[2].size() )
        ans[vs[1][i]] = num[2][i];
      else
        ans[vs[1][i]] = num[0][cnt++];
    }
  }

  rep( i, N )
    std::cout << ans[i] << (i==N-1?'\n':' ');

  return 0;
}

Measured memory_bytes: 25520
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vector<bool> prime;
vi primes;

void sieve(int n){
	prime.assign(n + 1, 1);
	prime[1] = false;
	for(int i = 2; i <= n; i++){
		if(prime[i]){
			primes.pb(i);
			for(int j = i * 2; j <= n; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	//all numbers modulo 5 are 1
	sieve(55555);
	vi a;
	rep(i, primes.size()){
		if((int)a.size() == n) break;
		if(primes[i] % 5 == 1) a.pb(primes[i]);
	}
	for(int x : a) cout << x << " ";
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char str[9][9];
int mx[4]={1,0,-1,0},my[4]={0,1,0,-1},moving[4];
void serch(int mo,int y,int x)
{
    for(int i=0;i<4;i++){
            if(str[my[i]+y][x+mx[i]]=='1'&&my[i]+y>=0&&my[i]+y<9&&mx[i]+x>=0&&mx[i]+x<9){
                str[my[i]+y][x+mx[i]]='0';
                moving[mo]=i;
                serch(mo+1,y+my[i],x+mx[i]);
                break;
            }

    }
}
int main()
{
    int co=0;
    while(cin>>str[0]){
        for(int i=1;i<8;i++)cin>>str[i];
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(str[i][j]=='1'&&co==1)co++;
                else if(str[i][j]=='1'&&co==0){
                    str[i][j]='0';
                    serch(0,i,j);
                    co++;
                }

            }
        }
        if(moving[0]==0&&co!=2){
            if(moving[1]==1){
                if(moving[2]==2)cout<<"A"<<endl;
                else cout<<"E"<<endl;
            }
            else cout<<"C"<<endl;
        }
        else if(moving[0]==1&&co!=2){
            if(moving[1]==0)cout<<"F"<<endl;
            else if(moving[1]==1)cout<<"B"<<endl;
            else if(moving[1]==2)cout<<"D"<<endl;
        }
        else cout<<"G"<<endl;
        co=0;
    }
}

Measured memory_bytes: 1132
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] t = new int[N+1];
        int[] x = new int[N+1];
        int[] y = new int[N+1];
        for(int i=1; i<=N; i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        String ans = "Yes";
        for(int i=1; i<=N; i++){
            int dis = Math.abs(x[i]-x[i-1]) + Math.abs(y[i]-y[i-1]);
            int dt = t[i]-t[i-1];
            if(dis>dt||((dis-dt)&1)==1){
                ans = "No";
                break;
            }
        }
        System.out.println(ans);
    }
}

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

const double eps = 1e-10;

struct Point {
  double x, y;
  Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}  
  double norm() {return sqrt(x*x + y*y);}
};

Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
double operator * (const Point &p, const Point q) {return p.x * q.x + p.y * q.y;}
bool operator == (const Point &p, const Point &q) {return (abs(p.x - q.x) < eps && abs(p.y - q.y) < eps);}
bool operator != (const Point &p, const Point &q) {return !(p == q);}
double cross(const Point &p, const Point &q) {return p.x*q.y - p.y*q.x;}

struct Line_Segment {
  Point p , q;
  Line_Segment(Point p = Point(0.0,0.0), Point q = Point(0.0,0.0)) : p(p), q(q) {}
};

struct Line {
  double a, b, c;
  Line(double a, double b, double c) : a(a), b(b), c(c) {}
  Line(Point p, Point q) {
    a = q.y - p.y;
    b = p.x - q.x;
    c = q.x * p.y - p.x * q.y;
  }
};

struct Circle {
  double r;
  Point p;
  Circle(Point p = Point(0.0, 0.0), double r = 0.0) : p(p), r(r) {}
};

int ccw(Point p, Point p1, Point p2) {
  p1 = p1 - p; p2 = p2 - p;
  if(cross(p1,p2) > eps) return 1; 
  if(cross(p1,p2) < -eps) return -1; 
  if(p1 * p2 < 0) return 2; 
  if(p1.norm() < p2.norm()) return -2; 
  return 0; 
}

bool line_segment_cross(const Line_Segment l, const Line_Segment s) {
  return ccw(l.p,l.q,s.p) * ccw(l.p,l.q,s.q) <= 0 && ccw(s.p,s.q,l.p) * ccw(s.p,s.q,l.q) <= 0;
}

int main() {
  int q;
  cin >> q;
  rep(i,q) {
    Point a, b, c, d;
    cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y;
    Line_Segment l(a,b);
    Line_Segment s(c,d);
    cout << (line_segment_cross(l,s) ? 1 : 0) << endl;
  }
}


Measured memory_bytes: 3232
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	int n=0;
  	int count=0;
  	int check[8];
  	int min=0;
  	for(int i=0;i<8;i++)
    {
      check[i]=0;
    }
  	
  	cin>>n;
  	vector<int> a(n);
  	for(int i=0;i<n;i++)
    {
      cin>>a[i];
      if(a[i]<400)
      {
        check[0]=1;
      }
      if(400<=a[i]&&a[i]<800)
      {
        check[1]=1;
      }
      if(800<=a[i]&&a[i]<1200)
      {
        check[2]=1;
      }
      if(1200<=a[i]&&a[i]<1600)
      {
        check[3]=1;
      }
      if(1600<=a[i]&&a[i]<2000)
      {
        check[4]=1;
      }
      if(2000<=a[i]&&a[i]<2400)
      {
        check[5]=1;
      }
      if(2400<=a[i]&&a[i]<2800)
      {
        check[6]=1;
      }
      if(2800<=a[i]&&a[i]<3200)
      {
        check[7]=1;
      }
      if(3200<=a[i])
      {
        count++;
      }
    }
  
  	for(int k=0;k<8;k++)
    {
      min=min+check[k];
      count=check[k]+count;
    }
  
  if(min==0)
  {
    cout<<"1"<<" "<<count<<endl;
  }
  else
  {
    cout<<min<<" "<<count<<endl;
  }
	return 0;
}

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

using namespace std;

int main(){
    int n, k;
    cin >>n >> k;
    int f = 1;
    for(int i = 0; i < n; i++){
        if(f * 2 <= f + k){
            f*=2;
        }else f+=k;
    }
    cout << f;
    return 0;
}


Measured memory_bytes: 256
stdin.ReadLine().Split(" ")
|> Array.map (fun x ->
    match x with
    | "2" -> "X"
    | "4"
    | "6"
    | "9"
    | "11" -> "Y"
    | _ -> "Z")
|> Array.groupBy id
|> Array.length
|> fun x -> if x = 1 then "Yes" else "No"
|> printfn "%s"


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

typedef unsigned long long ull;
typedef long long ll;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	
	int r;
	cin >> r;
	
	cout << 2 * M_PI * r << endl;
	
	
	return 0;
}


Measured memory_bytes: 3824
import collections
n,m = map(int,input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
    
primel = prime_factorize(m)

def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
 
c = collections.Counter(primel)

ans = 1
for i in c.values():
    ans *= combination(i+n-1,i)
    ans %= 10**9+7
    
print(ans)

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;
int main(){
    vector<int>vec(3);
    for (int i=0;i<3;i++){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    cout<<vec.at(0)+vec.at(1)<<endl;
    
}

Measured memory_bytes: 256
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

int main(){

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
	#endif

	// int a,b;
	// cin>>a>>b;

	// cout<<a<<" "<<b<<"\n";
	// cout<<"Aryan"<<"\n"; 
	// cerr<<"Aryan "<<a;

	ll n;
	cin>>n;


	set<string> s;
	for(ll i=0;i<n;i++){
		string str;
		cin>>str;

		s.insert(str);
	}

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


	return 0;
}


Measured memory_bytes: 19256
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

int main()
{
    string tmp,set[7];
    cin >> tmp;
    set[0] = tmp.substr(0,1);
    set[1] = tmp.substr(1,1);
    set[2] = tmp.substr(2,1);
    cin >> tmp;
    set[3] = tmp.substr(0,1);
    set[4] = tmp.substr(1,1);
    set[5] = tmp.substr(2,1);

    if(set[0]==set[5] && set[1]==set[4] && set[2]==set[3]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  //入力
  int a,b;
  std::scanf("%d %d",&a,&b);
  
  if(a > b) {
    std::printf("a > b\n");
  }
  else if(a < b) {
    std::printf("a < b\n");
  }
  else if(a == b) {
    std::printf("a == b\n");
  }
  return 0;
}


Measured memory_bytes: 2592
N=int(input())
W=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+W[i]
ans=S[N]
for i in range(N):
    tmp=abs(S[i]-(S[N]-S[i]))
    ans=min(tmp,ans)
print(ans)


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main { 
    
    public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
      s.useDelimiter("\n");
      int key = s.nextInt();
      char[] planeChars = s.next().toCharArray();
     
      String cipher = cipherBuilder(planeChars, key);
      System.out.println(cipher);
    }
  
  public static String cipherBuilder(char[] planeChars, int key) {
    
    String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int placeCharLen = planeChars.length;
    
    StringBuilder cipherSB = new StringBuilder();
      for (int i = 0; i < placeCharLen; i++) {
      	int index = alphabet.indexOf(planeChars[i]);
        
        if (index + key > 25) {
          	index = index + key - 26;
        } else {
        	index = index + key;
        }
        
        cipherSB.append(alphabet.charAt(index));
      }
      return cipherSB.toString();
  }
}

Measured memory_bytes: 21844
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sun Jan  6 00:24:03 2019
//
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

	var N int
	fmt.Scan(&N)
	as := make([]int, N)
	bs := make([]int, N)
	cs := make([]int, N)

	for i := range as {
		as[i] = nextInt()
	}
	sort.Ints(as)
	for i := range bs {
		bs[i] = nextInt()
	}
	sort.Ints(bs)
	for i := range cs {
		cs[i] = nextInt()
	}
	sort.Ints(cs)

	arr := make([]int, N)
	for i := range bs {
		b := bs[i]
		n := sort.Search(len(cs), func(i int) bool {
			return b < cs[i]
		})
		arr[i] = len(cs) - n
	}
	for i := range arr {
		if i+1 < len(arr) {
			arr[i+1] += arr[i]
		}
	}

	ans := 0
	for i := range as {
		a := as[i]
		n := sort.Search(len(bs), func(i int) bool {
			return a < bs[i]
		})
		if n == len(bs) {
			continue
		}

		if n == 0 {
			ans += arr[len(arr)-1]
		} else {
			ans += arr[len(arr)-1] - arr[n-1]
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

const int N = 1e5 + 5;
const long long inf = 1e18;

long long dp[N];
vector<pair<int, int>> edge[N];

bool dfs(int now, long long cost) {
  if (dp[now] != inf) return dp[now] == cost;
  dp[now] = cost;
  for (auto it : edge[now]) {
    if (dfs(it.first, cost + it.second) == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    scanf("%d %d %d", &l, &r, &d);
    edge[l].emplace_back(r, d);
    edge[r].emplace_back(l, -d);
  }
  fill(dp, dp + N, inf);
  for (int i = 1; i <= n; i++) {
    if (dp[i] == inf) {
      if (dfs(i, 0) == 0) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

void solve() {
  int n; cin >> n;
  Graph G(n, vi(2));
  rep(i,n) rep(j,2) cin >> G[i][j];

  ll takahashi = 1, aoki = 1;

  rep(i,n) {
    ll r = max((takahashi - 1) / G[i][0], (aoki - 1) / G[i][1]) + 1;
    takahashi = r * G[i][0];
    aoki = r * G[i][1];
  }

  cout << takahashi + aoki << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var X = Sarray()[0];
            for (var i = 1; ; ++i)
            {
                if (2 * X <= i * (i + 1))
                {
                    WriteLine(i);
                    return;
                }
            }
            //Out.Flush();
        }
    }
}

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

using namespace std;
typedef long long ll;

int sx,sy,tx,ty,i,dx,dy,d[4];

int main(void){
    cin>>sx>>sy>>tx>>ty;
    dx=tx-sx; dy=ty-sy;
    string d="URDL";
    
    for(i=0;i<abs(dy);i++)cout<<d[0];
    for(i=0;i<abs(dx);i++)cout<<d[1];
    for(i=0;i<abs(dy);i++)cout<<d[2];
    for(i=0;i<abs(dx);i++)cout<<d[3];
    cout<<d[3];
    for(i=0;i<abs(dy)+1;i++)cout<<d[0];
    for(i=0;i<abs(dx)+1;i++)cout<<d[1];
    cout<<d[2];
    cout<<d[1];
    for(i=0;i<abs(dy)+1;i++)cout<<d[2];
    for(i=0;i<abs(dx)+1;i++)cout<<d[3];
    cout<<d[0];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
/*why so serious?*/
#include<bits/stdc++.h>
using namespace std;
#define   int      long long
#define   fast()   ios_base::sync_with_stdio(0);cin.tie(0)
#define   all(x)   x.begin(),x.end()
#define   pb       push_back
#define   F        first
#define   S        second

const int N=1e5+5;

string s;

struct seg
{int pre,suf,tot;
 seg()
 {pre=suf=tot=0;
 }
};

seg tree[4*N];

seg combine(seg a,seg b)
{seg c;
 c.pre=a.pre;
 c.suf=b.suf;
 c.tot=a.tot+b.tot+(int)(a.suf && b.pre);
 return c;
}

void build(int node,int beg,int en)
{if(beg==en)
 {if(s[beg-1]=='A')
  tree[node].suf=1;
  else if(s[beg-1]=='C')
  tree[node].pre=1;
  return;
 }
 int mid=(beg+en)/2;
 build(2*node,beg,mid);
 build(2*node+1,mid+1,en);
 tree[node]=combine(tree[2*node],tree[2*node+1]);
}

seg qu(int node,int beg,int en,int l,int r)
{if(beg>en || l>en ||r<beg)
 {seg null;
  return null;
 }
 if(l<=beg && en<=r)
 return tree[node];
 int mid=(beg+en)/2;
 return (combine(qu(2*node,beg,mid,l,r),qu(2*node+1,mid+1,en,l,r)));
}

int32_t main()
{int n,q,l,r;

 fast();

 cin>>n>>q>>s;
 build(1,1,n);

 for(;q;--q)
 {cin>>l>>r;
  cout<<qu(1,1,n,l,r).tot<<"\n";
 }
 return 0;
}



Measured memory_bytes: 10448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<vector<int>> dist(N,vector<int>(3, INF));
  rep(i, 0, M) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
  }
  int S, T;
  cin >> S >> T;
  S--, T--;
  using P = pair<int, int>;
  queue<P> Q;
  Q.push(P(S, 0));
  dist[S][0] = 0;
  while(!Q.empty()) {
    P cur = Q.front(); Q.pop();
    for(auto nx : G[cur.first]) {
      int id = (cur.second + 1) % 3;
      int cost = dist[cur.first][cur.second] + 1;
      if(dist[nx][id] <= cost) continue;
      dist[nx][id] = cost;
      Q.push(P(nx, id));
    }
  }
  if(dist[T][0] == INF) cout << -1 << endl;
  else cout << dist[T][0] / 3 << endl;
  return 0;
}


Measured memory_bytes: 11136
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
  		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long h = sc.nextInt();
		long w = sc.nextInt();
		sc.close();
		long ans = Math.min(h,w);
		if(h % 3 == 0 || w % 3== 0){
			ans = 0;
		}
		for(long i = 1; i < h; i++){
			if(w % 2 == 0){
				ans = Math.min(ans, Math.max(i*w, (h-i)*(w/2)) - Math.min(i*w, (h-i)*(w/2)));
			}else{
				ans = Math.min(ans, Math.max(i*w, (h-i)*((w+1)/2)) - Math.min(i*w, (h-i)*((w-1)/2)));
			}
		}
		for(long i = 1; i < w; i++){
			if(h % 2 == 0){
				ans = Math.min(ans, Math.max(h*i, (w-i)*(h/2)) - Math.min(i*h, (w-i)*(h/2)));
			}else{
				ans = Math.min(ans, Math.max(h*i, (w-i)*((h+1)/2)) - Math.min(i*h, (w-i)*((h-1)/2)));
			}
		}
		out.println(ans);
		out.flush();
	}

	static class Pair{
		int a,b;
		public Pair(int a, int b){
			this.a = a;
			this.b = b;
		}
	}
}

Measured memory_bytes: 25556
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int N; cin >> N;

	if (N < 1200) {
		cout << "ABC" << endl;
	}else if (N < 2800) {
		cout << "ARC" << endl;
	}else {
		cout << "AGC" << endl;
	}	
	return 0;
}


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

bool check_case1(int x1, int c1, int x2, int c2, int N) {
    return c1 == (N/3) && c2 == (2 * N/3);
}

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    unordered_map<int, int> counts;
    if (N%3 != 0) {
        for (int i = 0; i < N; ++i) {
            int x = a[i];
            if (x != 0) {
                cout << "No\n";
                return 0;
            }
        }
        cout << "Yes\n";
        return 0;
    } else {
        for (int i = 0; i < N; ++i) {
            int x = a[i];
            counts[x]++;
            if (counts.size() > 3) {
                cout << "No\n";
                return 0;
            }
        }
        if (counts.size() == 1) {
            if (counts.find(0) != counts.end()) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        } else if (counts.size() == 2) {
            int x1, x2, c1, c2;
            int i = 0;
            for (auto it = counts.begin(); it != counts.end(); ++it) {
                if (i++ == 0) {
                    x1 = it->first;
                    c1 = it->second;
                } else {
                    x2 = it->first;
                    c2 = it->second;
                }
            }
            bool res;
            if (x1 == 0) {
                res = check_case1(x1, c1, x2, c2, N);
            } else if (x2 == 0) {
                res = check_case1(x2, c2, x1, c1, N);
            } else {
                res = false;
            }
            cout << (res ? "Yes\n" : "No\n");
            return 0;
        } else {
            int xorn = 0;
            for (auto it = counts.begin(); it != counts.end(); ++it) {
                int c = it->second;
                if (c != (N/3)) {
                    cout << "No\n";
                    return 0;
                }
                xorn ^= it->first;
            }
            cout << ((xorn == 0) ? "Yes\n" : "No\n");
            return 0;
        }
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,Q;
    cin>>N>>Q;

    set<pint>st;
    st.insert({0ll,20000000000000ll+1});
    st.insert({N,0});

    while(Q--){
        int a,b;
        scanf("%lld%lld",&a,&b);

        while(b){

            auto it=st.lower_bound({a,-1});
            int r,c;
            tie(r,c)=*it;

            if(r!=a){
                st.erase(it);
                st.insert({a,c});
                st.insert({r,c});
                continue;
            }

            it--;
            int rr,cc;
            tie(rr,cc)=*it;

            if(b>=(cc-c)*(r-rr)){
                b-=(cc-c)*(r-rr);
                st.erase({r,c});
                st.erase({rr,cc});
                st.insert({r,cc});
            }
            else{
                st.erase({r,c});
                if(b%(r-rr))st.insert({rr+b%(r-rr),c+b/(r-rr)+1});
                st.insert({r,c+b/(r-rr)});
                b=0;
            }
        }
    }


    int pre=0;
    for(auto &p:st){
        for(;pre<p.fi;pre++)cout<<p.se<<endl;
    }
}


Measured memory_bytes: 7680
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	string s, t;
	cin >> s >> t;
	s += t;
	N = stoi(s);
	if (N == pow((int)sqrt(N), 2)) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}
function rep(a: number, b: number) {
  let arr = [];
  for (let i = a; i < b; i++) arr.push(i);
  return arr;
}
function gcd(a: number, b: number) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
const mod = 1000000007n;
function pow(base: bigint, a: bigint): bigint {
  if (a === 0n) return 1n;
  const half = pow(base, a / 2n);
  return (((half * half) % mod) * (a % 2n === 0n ? 1n : base)) % mod;
}
function Main({ int, str, strs, ints }: NormalInput) {
  const [N, K] = ints(2);
  const ans: bigint[] = [];
  function dp(a: number) {
    if (ans[a]) return ans[a];
    else {
      const s: bigint = BigInt(K) / BigInt(a);
      const total = pow(s, BigInt(N));
      let minus = 0n;
      for (let i = 2; i <= s; i++) {
        minus = (minus + dp(BigInt(i) * BigInt(a))) % mod;
      }
      return (ans[a] = (total - minus + mod) % mod);
    }
  }
  dp(1);

  let sum = 0n;
  for (let i = 1; i <= K; i++) {
    sum = (sum + ans[i] * BigInt(i)) % mod;
  }
  console.log(sum.toString());
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 53556
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

const ll RANDOM =chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
 

ll n;
vector<ll>a;
vector<ll>b;

ll T=30;

int main(){
FLASH;
srand(time(0));
cin>>n;
for(ll i=1;i<=n;i++)
{
  ll x;
  cin>>x;
  a.pb(x);
}

for(ll i=1;i<=n;i++)
{
  ll x;
  cin>>x;
  b.pb(x);
}

vector<ll>cp=b;
ll sig=0;

for(ll i=0;i<n;i++)
{
  if(a[i]==b[i]){sig=1;break;}
}

if(sig==0)
{
  cout<<"Yes"<<endl;
  vecc(b,n);
  return 0;
}

reverse(all(b));
sig=0;
for(ll i=0;i<n;i++)
{
  if(a[i]==b[i]){sig=1;break;}
}

if(sig==0)
{
  cout<<"Yes"<<endl;
  vecc(b,n);
  return 0;
}

b=cp;
while(T--)
{ 
  shuffle(all(b),rng);
  sig=0;
  for(ll i=0;i<n;i++)
  {
   if(a[i]==b[i]){sig=1;break;}
  }
  if(sig==0)
  {
   cout<<"Yes"<<endl;
   vecc(b,n);
   return 0;
  }

}

T=30;
b=cp;
while(T--)
{
  rotate(b.begin(),b.begin()+rng()%n,b.end());
  sig=0;
  for(ll i=0;i<n;i++)
  {
   if(a[i]==b[i]){sig=1;break;}
  }
  if(sig==0)
  {
   cout<<"Yes"<<endl;
   vecc(b,n);
   return 0;
  }
}


cout<<"No"<<endl;





return 0;
} 


Measured memory_bytes: 8004
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int cur;
  cin >> cur;
  int c = 0;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    int nxt;
    cin >> nxt;
    if (nxt == cur) continue;
    int cc = cur < nxt ? 1 : -1;
    if (cc * c < 0) {
      ans++;
      cc = 0;
    } 
    c = cc;
    cur = nxt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

int main(){
	string in,temp;
	vector<string> ans;
	int mozisuu = 0;
	getline(cin, in);
	for (int i = 0; i < in.length(); i++){
		if (in[i] != ' ' && in[i] != '.' && in[i] != ','){
			temp.append(1, in[i]);
			mozisuu++;
		}
		else{
			if (mozisuu >=3 && mozisuu <=6)
				ans.push_back(temp);
			temp.clear();
			mozisuu = 0;
		}
	}
	for (int i = 0; i < ans.size(); i++){
		cout << ans.at(i);
		if (i < ans.size() - 1)
			cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
struct Gedge {
	LL src, to;
	T cost;
	Gedge(LL s, LL t, T c) :src(s), to(t), cost(c) {}
	Gedge(LL t, T c) :src(-1), to(t), cost(c) {}
};

template<class T>
using WeightedGraph = vector<vector<Gedge<T>>>;
using UnweightedGraph = vector<vector<LL>>;
template<class T>
using Gedges = vector<Gedge<T>>;

struct TNode {
	LL parent;
	VLL childs;
	TNode() :parent(-1) {};
};
using Tree = vector<TNode>;

//到達不可能->INF
template<class T>
void dijkstra(WeightedGraph<T>& G, LL start, vector<T>& res) {
	res.resize(G.size(), INF);
	res[start] = 0;
	typedef pair<T, LL> P;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, start));
	while (!q.empty()) {
		LL cur = q.top().second;
		T cost = q.top().first;
		q.pop();
		if (res[cur] < cost)continue;
		for (Gedge<T> e : G[cur]) {
			if (res[e.to] > cost + e.cost) {
				res[e.to] = cost + e.cost;
				q.push(P(res[e.to], e.to));
			}
		}
	}
	return;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, M;
	cin >> N >> M;
	WeightedGraph<LL> G(N);
	for (LL n = 0; n < M; n++) {
		LL a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back({ a,b,1 });
		G[b].push_back({ b,a,1 });
	}
	VLL res;
	dijkstra(G, 0, res);
	VLL path(N,-1);
	bool flag = false;
	for (LL n = 1; n < N; n++) {
		LL d = res[n];
		if (d == INF) {
			flag = true;
				break;
		}
		for (auto edge : G[n]) {
			if (res[edge.to] == d - 1) {
				path[n] = edge.to;
				break;
			}
		}
	}
	if (flag)cout << "No\n";
	else {
		cout << "Yes\n";
		for (LL n = 1; n < N; n++) {
			cout << path[n]+1 << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 22732
#include<stdio.h>
int main(){
	int i,j,r,c,h[500][500]={0};
	scanf("%d %d",&r,&c);
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			scanf("%d",&h[i][j]);
			h[i][c+1]=h[i][c+1]+h[i][j];
			h[r+1][j]=h[r+1][j]+h[i][j];
			h[r+1][c+1]=h[r+1][c+1]+h[i][j];
		}
	}
	for(i=1;i<=r+1;i++){
		for(j=1;j<=c+1;j++){
			printf("%d",h[i][j]);
			if(j!=c+1){
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1588
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\158\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        q = [int(i) for i in self.input_data().split()]

        A = q[0]
        B = q[1]

        no_tax_A = int(A / 0.08) # + 0 - 12
        no_tax_B = int(B / 0.1)  # + 0 - 9

        if int(no_tax_A) * 0.08 != A:
            no_tax_A += 1

        if no_tax_A == no_tax_B:
            result = no_tax_A
        elif no_tax_A > no_tax_B:
            if int(no_tax_A * 0.1) == B:
                result = no_tax_A
            else:
                result = -1
        else:
            if int(no_tax_B * 0.08) == A:
                result = no_tax_B
            else:
                result = -1

        print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
using namespace std;

#define MAX 100
#define INF 2097152
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int main(void){

	int i,j,f;
	int n,u,v,minv,d[MAX],p[MAX],color[MAX],sum=0;
	scanf("%d",&n);
  
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&f);
			if(f == -1){
				M[i][j] = INF;
			}else{
				M[i][j] = f;
			}
		}
	}


	for(i=0;i<n;i++){
		d[i] = INF;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while(1){
		minv = INF;
		u = -1;
		for(i=0;i<n;i++){
			if(minv>d[i] && color[i] != BLACK){
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		for(v=0;v<n;v++){
			if(color[v] != BLACK && M[u][v] != INF){
				if(d[v] > M[u][v]){
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}

	for(i=0;i<n;i++){
		if(p[i] != -1){ 
			sum+= M[i][p[i]];
		}
	}

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


return 0;

}


Measured memory_bytes: 3248
#include<cstdio>
#include<algorithm>
#define INF 2000000000000000
#define maxn 100000
using namespace std;
long long n,tot,w[105],v[105],dp[maxn+5],ans;
int main()
{
	scanf("%lld%lld",&n,&tot);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&w[i],&v[i]);
	}
	for(int i=1;i<=maxn;i++) 
	{
		dp[i]=INF;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=maxn;j>=v[i];j--)
		{
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	for(int i=1;i<=maxn;i++)
	{
		if(dp[i]<=tot)
		{
			ans=i;
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

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

using namespace std;


int main(){
    int n, m;
    cin >> n >> m;
    long long arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    vector<pair<int, int>> roads;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        roads.push_back({a, b});
    }
    vector<int> sol(n, -1);
    for(int i = 0; i < m; i++){
        if(arr[roads[i].first] == arr[roads[i].second]){
            sol[roads[i].first] = 0;
            sol[roads[i].second] = 0;
        }else if(arr[roads[i].first] > arr[roads[i].second]){
            sol[roads[i].second] = 0;
            if(sol[roads[i].first] != 0)
                sol[roads[i].first] = 1;
        }else{
            sol[roads[i].first] = 0;
            if(sol[roads[i].second] != 0)
                sol[roads[i].second] = 1;
        }
    }
    int res = 0;
    for(int x: sol){
        if(x)
            res++;
    }
    cout << res << '\n';
}

Measured memory_bytes: 5276
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;
	long[4] used;
	foreach (i; 0..S.length)
	{
		if (S[i] == 'N')
			used[0] = 1;
		else if (S[i] == 'W')
			used[1] = 1;
		else if (S[i] == 'S')
			used[2] = 1;
		else
			used[3] = 1;
	}
	
	writeln(used[0] - used[2] == 0 && used[1] - used[3] == 0 ? "Yes" : "No");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int mx = 0;
    rep(i, 0, n) {
        int p;
        cin >> p;
        mx = max(mx, p);
        sum += p;
    }

    cout << sum - (mx / 2) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<ll> b(n+2,0);
  for(int i = 0; i < n; i++) b[a[i]]++;
  ll ans = 0;
  for(int i = 0; i < n+1; i++) ans += b[i]*(b[i]-1)/2;
  
  for(int k = 0; k < n; k++){
    cout << ans - b[a[k]]*(b[a[k]]-1)/2 + (b[a[k]]-1)*(b[a[k]]-2)/2 << endl;
  }
  return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		double x1=in.nextDouble(),y1=in.nextDouble(),x2=in.nextDouble(),y2=in.nextDouble();
		out.printf("%f\n", Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1,2)));
		out.flush();
	}
}


Measured memory_bytes: 28060
#include <iostream>
using namespace std;
#define PrintLn(X) cout << X << endl

int main(void)
{
	int N;
	cin >> N;
	if(N % 10 == 9 || N / 10 == 9){
		PrintLn("Yes");
	}else{
		PrintLn("No");
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, K, X, Y;
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	if (N >= K) printf("%d\n", K * X + (N - K) * Y);
	else printf("%d\n", N * X);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> G[1000];
bool used[1000];
int pr[1000];
bool loop;

int N, M;

void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
    loop = false;
}

void dfs(int v, int r){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(G[v][i] == r) {
            loop = true;
            pr[r] = v;
        }
        if(!used[G[v][i]]) {
            pr[G[v][i]] = v;
            dfs(G[v][i], r); 
        }
    }
}

int rs, rt;
int idx;

bool judge(vector<int> v){
    clear();
    for(int i = 0; i < v.size(); i++){
        used[v[i]] = true;
    }
    int n = v.size();
    for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < G[v[i]].size(); j++){
            int to = G[v[i]][j];
            if(used[to] && to != v[(i+1)%n]){
                rs = v[i];
                rt = to;
                idx = i;
                return false;
            }
        }
    }
    return true;
}

vector<int> cut(vector<int> v){
    vector<int> u;
    for(int i = 0; i < v.size(); i++){
        if(v[i] == rt){
            u.push_back(rs);
            for(int j = i; ; j = (j+1)%v.size()){
                if(v[j] == rs) return u;
                u.push_back(v[j]);
            }
        }
    }
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
    }
    int s;
    for(int i = 0; i < N; i++){
        clear();
        dfs(i, i);
        if(loop) {
            s = i;
            break;
        }
        if(i == N-1){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> v;
    int tmp = s;
    while(pr[tmp] != s){
        v.push_back(tmp);
        tmp = pr[tmp];
    }
    v.push_back(tmp);
    reverse(v.begin(), v.end());
    int cnt = 0;
    while(true){
        if(judge(v)){
            cout << v.size() << endl;
            for(int i = 0; i+1 < v.size(); i++){
                cout << v[i]+1 << ' ';
            }
            cout << v[v.size()-1]+1 << endl;
            return 0;
        }
        vector<int> u;
        u = cut(v);
        v.clear();
        v = u;
    }
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

char mp[105][105];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin >> a >> b;
	for(int i = 1; i <= 50; i++)
		for(int j = 1; j <= 100; j++)
			mp[i][j]='.';
	for(int i = 51; i <= 100; i++)
		for(int j = 1; j <= 100; j++)
			mp[i][j]='#';
	b--;
	for(int i = 1; i <= 50 && b; i += 2)
		for(int j = 1; j <= 100 && b; j += 2)
			mp[i][j]='#',b--;
	a--;
	for(int i = 100; i > 50 && a; i -= 2)
		for(int j = 1; j <= 100 && a; j += 2)
			mp[i][j]='.',a--;
	cout << "100 100" << endl;
	for(int i = 1; i <= 100; i++, cout << '\n')
		for(int j = 1; j <= 100; j++)
			cout << mp[i][j];
}

Measured memory_bytes: 256