akhauriyash/Code-Regression huggingface dataset:
#include <bits//stdc++.h>
using namespace std;
int main()
{
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int ans = 0,t = 0,s;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			t = 0;
			for (int k = 0; k < d; k++) {
				t += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
			}
			s = sqrt(t);
			if (s * s == t) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<=8&&b<=8) printf("Yay!\n");
    else printf(":(\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    string S;
    cin >> S;

    ll res = 1e18;
    rep(i, S.size()) {
        if (S[i] != S[i + 1]) {
            res = min(res, max(i+1, (ll)S.size() - i - 1));
        }
    }
    put(res);    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N, X; cin >> N >> X;
	ll m, minV = 1 << 21;
	rep(i, 0, N) {
		cin >> m;
		X -= m;
		minV = min(minV, m);
	}
	cout << N + X / minV << endl;
	return 0;
}

Measured memory_bytes: 256
N=raw_input()
hotel=map(int, raw_input().split())

cnt=0

for i,h in enumerate(hotel):
#    print i, h
    flg = 1
    for j in range(i+1):
#        print "--", h, hotel[j]
        if h < hotel[j]:
            flg = 0
            break

    if flg == 1:
        cnt += 1

print cnt


Measured memory_bytes: 2568
import sys
from bisect import bisect_left as bl
def I(a): return [-1<<50] + [int(sys.stdin.readline()) for i in range(a)] + [1<<50]
A, B, Q = map(int, input().split())
S, T = I(A), I(B)

for _ in range(Q):
    x = int(input())
    k, l = bl(S, x), bl(T, x)
    a, b, c, d = x-S[k-1], x-T[l-1], S[k]-x, T[l]-x
    print(min(max(a, b), max(c, d), 2*a+d, 2*d+a, 2*b+c, 2*c+b))

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (s); i < (e); ++i)
#define per(i,s,e) for(int i = (s)-1; i >= e; --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

const int inf = 1001001001;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<typename T, size_t N, typename U>
void Fill(T (&a)[N], const U&v){
    std::fill((U*)a,(U*)(a+N),v);
}

template<long long mod>
class modint{
public:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
};

const ll mod = (1e+9) + 7;
int n2, k2;

vector<vector<int>> to;

modint<mod> f[100005]={1};


modint<mod> Pe(int x ,int k){
  if(k < 0 || k > x) return modint<mod>(0);
  return f[x]/f[x-k];
}

modint<mod> ans(1);

void bfs(int v, int p = -1){
  debug(v);
  for(auto e : to[v]){
    if(e == p)continue;
    bfs(e,v);
  }
  int k(p==-1 ? k2 : k2 - 2);  
  int c(p==-1 ? to[v].size()+1 : to[v].size()-1);
  ans = ans * Pe(k,c);
}

int main(){
  f[1] = 1;
  rep(i,2,100005){
    f[i] = f[i-1] * modint<mod>(i);
  }
  cin >> n2 >> k2;
  
  to.resize(n2);
  rep(i,0,n2-1){
    int a, b; cin >> a >> b;a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  bfs(0);
  cout << ans.num << endl;
  return 0;
}


Measured memory_bytes: 12288
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int[] B = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
        
        int N = a[0];
        int M = a[1];
        int C = a[2];
        
        int count = 0;
        for(int i = 0; i < N; i++)
        {
           int[] A = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray(); 
           int sum = 0;
           for(int j = 0; j < M; j++)
           {
               sum += A[j] * B[j];
           }
           sum += C;
           if(sum > 0) count++;
        }

        Console.WriteLine(count);
        
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;

    long double wk=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;

        wk+=1.0/(long double)a;
    }

    cout << fixed << setprecision(15) << 1.0/wk << 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++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    string s; int w; cin >> s >> w;string ans;
    for(int i=0;i<s.size();i+=w) {
        ans += s[i];
    }
    cout << ans;
}

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

int height(int i) {
  if(i == 0) {
    return 0;
  }

  return i + height(i-1);
}
int main() {
  int a, b;
  cin >> a >> b;
  int diff = b - a;
  int h = height(diff);

  cout << h - b << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H') {
		if (b == 'H') cout << "H" << endl;
		else cout << "D" << endl;
	}
	else {
		if (b == 'D') cout << "H" << endl;
		else cout << "D" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,ans=0;
	cin>>x>>y;
	if(x == 1)	ans += 300000;
	if(x == 2)	ans += 200000;
	if(x == 3)	ans += 100000;
	if(y == 1)	ans += 300000;
	if(y == 2)	ans += 200000;
	if(y == 3)	ans += 100000;
	if(x==1 && y == 1)	ans += 400000;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, raw_input().strip().split())
v = map(int, raw_input().strip().split())

ans = 0
for a in xrange(k + 1):
    for b in xrange(k - a + 1):
        z = a
        if z > n: z = n
        l = []
        val = 0
        for i in xrange(z):
            l.append(v[i])
            val += v[i]
        if z < n:
            for i in xrange(n - 1, z - 1, -1):
                if n - i > b: break
                l.append(v[i])
                val += v[i]
        l.sort(reverse = True)
        rem = 0
        op = k - a - b
        while rem < op:
            if len(l) > 0:
                if l[-1] < 0:
                    val -= l[-1]
                    l.pop()
                    rem += 1
                else:
                    break
            else:
                break
        ans = max(ans, val)

print ans

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

int findSumDigit(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n, total;
  cin >> n;
  total = findSumDigit(n);
  if (n % total == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
q = int(raw_input())
arr = []
for i in range(q):
    arr.append(int(raw_input()))

if sum(arr) % 10 != 0:
    print sum(arr)
    exit()

arr = sorted(arr)

for x in range(len(arr)):
    if (sum(arr[x:] + arr[:x+1]) % 10 != 0):
        print sum(arr[:x] + arr[x+1:])
        exit()

print 0


Measured memory_bytes: 29164
str = input()
rev_str = str[::-1]
len_str = len(str)

pre_str = str[0:((len_str-1)//2)]
pro_str = str[(((len_str+3)//2)-1)::]

#print(pre_str)
#print(pro_str)


rev_pre_str = pre_str[::-1]
rev_pro_str = pro_str[::-1]

pali = 0

if str == rev_str:
    if pre_str == rev_pre_str:
        if pro_str == rev_pro_str:
            pali = 1

if pali == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
char str[500005];
int q;
int dp[500005][27];
int go[500005][21];
int main(){
	scanf("%s%d",&str,&q); int n = strlen(str);
	rep(i,500005) rep(j,27) dp[i][j] = INF;
	for(int i=0;i<n;i++){
		dp[i][str[i]-'a'] = i;
	}
	{
		bool upd = 0;
		for(int i=n-1;i>=0;i--){
			while(1){
				bool upd = 0;
				for(int j=0;j<=26;j++){
					if(dp[i][j-1] < n && dp[dp[i][j-1]+1][j-1] < n && dp[i][j] > dp[dp[i][j-1]+1][j-1]){
						dp[i][j] = dp[dp[i][j-1]+1][j-1];
						upd = 1;
					}
					if(dp[i][26] < n && dp[dp[i][26]+1][j] < n && dp[i][j] > dp[dp[i][26]+1][j]){
						dp[i][j] = dp[dp[i][26]+1][j];
						upd = 1;
					}
				}
				if(!upd) break;
			}
		}
	}
	for(int i=0;i<n;i++){
		go[i][0] = dp[i][26]+1;
		//cout<<i<<" "<<go[i][0]<<endl;
	}
	go[n][0] = n;
	for(int j=0;j<19;j++){
		for(int i=0;i<=n;i++){
			if(go[i][j] >= n) go[i][j+1] = INF;
			else go[i][j+1] = go[go[i][j]][j];
		}
	}
	//cout<<go[0][1]<<endl;
	rep(i,q){
		int x,y; scanf("%d%d",&x,&y); x--;
		for(int i=19;i>=0;i--){
			if(go[x][i] <= y) x = go[x][i];
		}
	//	cout<<x<<" "<<y<<endl;
		puts(x==y?"Yes":"No");
	}
}

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

int main() {
  int a;
  cin>>a;
  
  if(a==25)
    cout<<"Christmas"<<endl;
  
  if (a==24)
    cout<<"Christmas Eve"<<endl;
  
  if (a==23)
    cout<<"Christmas Eve Eve"<<endl;
  
  if (a==22)
    cout<<"Christmas Eve Eve Eve"<<endl;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
signed main() {
	ll a[5];
	ll k;
	rep(i, 5)cin >> a[i];
	cin >> k;
	sort(a, a + 5);
	if (a[4] - a[0] > k)puts(":(");
	else puts("Yay!");
	ggr
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    int num_input;
    int ind;
    int n_half;

    vector<int> num;
    vector<int> ans;

    cin >> n;
    n_half = n / 2;

    for (int i = 0; i < n; i++)
    {
        cin >> num_input;
        num.push_back(num_input);
    }

    for (int i = 0; i < n; i++)
    {
        ans.push_back(0);
    }

    ans[n_half] = num[0];

    for (int i = 1; i < n; i++)
    {
        if (n % 2 == 0)
        {
            if (i % 2 == 0)
            {
                ind = i;
            }
            else
            {
                ind = -i;
            }
        }

        else
        {
            if (i % 2 == 0)
            {
                ind = -i;
            }
            else
            {
                ind = i;
            }
        }

        ans[n_half += ind] = num[i];
    }

    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#define int long long
using namespace std;
const int mod = 1000000007;
signed main() {
	int n; cin >> n;
	string s; cin >> s;
	map<char, int>m;
	for (char c = 'a'; c <= 'z'; c++)m[c] = 0;
	for (int i = 0; i < s.size(); i++)m[s[i]]++;
	int ans = 1;
	for (char c = 'a'; c <= 'z'; c++){ ans *= m[c] + 1; ans %= mod; }
	cout << ans - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
const int NM = 200000;
int a[NM];

int main() {
    int n; cin >> n;
    rep(i, n) {
       cin >> a[i];
    }
    sort(a, a+n);
    int tmp;
    string ans = "YES";
    for(int i=0; i<n-1; i++){
       tmp = a[i];
       if(tmp == a[i+1]){
           ans = "NO";
           break;
       }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int c=0;
		for(int i=0;i<n;i++) a[i]=sc.nextInt();
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				for (int k = j+1; k < n; k++) {
					if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i] && a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
						c++;
				}
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 27660
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
using namespace std;
int main()
{
 ll n,x,flag=0;
 cin>>n>>x;
 ll l[n];rep(i,0,n) cin>>l[i];
 ll d[n+1];d[0]=0;	
 rep(i,1,n)
   {
 	 d[i]=d[i-1]+l[i-1];
 	 if(d[i]>x) 
 	 {
 	 	cout<<i;flag=1;
 	 	break;
	  }
	}
	if(!flag)
	{
	  d[n]=d[n-1]+l[n-1];
	  if(d[n]<=x) cout<<(n+1);
	  else cout<<n;
	}
		 
	
	
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int W,H,x,y,r;
   scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W>=x+r&&0<=x-r&&H>=y+r&&0<=y-r){
	   printf("Yes\n");
	}
	else{
	   printf("No\n");
	   }
			
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/26  Problem: ABC 116 A / Link: http://abc116.contest.atcoder.jp/tasks/abc116_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	int a, b, c; cin >> a >> b >> c;
	ans = a * b / 2;
	
	
	cout << ans << "\n";

	return 0;
}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 7;

vector<vector<int>> g;

vector<ll> fact;
vector<ll> dp, sz;

ll my_pow(ll n, ll m) {
    if (m == 0) return 1;
    ll now = my_pow(n, m / 2);
    if (m % 2 == 0) return (now * now) % mod;
    return (((now * now) % mod) * n) % mod;
}

void dfs(int v, int p) {
    dp[v] = sz[v] = 1;
    for (auto &to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        dp[v] *= dp[to];
        dp[v] %= mod;
        dp[v] *= my_pow(fact[sz[to]], mod - 2);
        dp[v] %= mod;
        sz[v] += sz[to];
    }
    dp[v] *= fact[sz[v] - 1];
    dp[v] %= mod;
}

vector<ll> ans;

void dfs1(int v, int p, ll sz_up, ll dp_up) {
    ans[v] = (dp[v] * my_pow(fact[sz[v] - 1], mod - 2)) % mod;
    ans[v] *= fact[sz[v] + sz_up - 1];
    ans[v] %= mod;
    ans[v] *= dp_up;
    ans[v] %= mod;
    ans[v] *= my_pow(fact[sz_up], mod - 2);
    ans[v] %= mod;
    ll total_size = sz[v] + sz_up;
    ll total_dp = ans[v];
    for (auto &to : g[v]) {
        if (to == p) continue;
        ll lol = total_dp;
        lol *= my_pow(fact[total_size - 1], mod - 2);
        lol %= mod;
        lol *= fact[total_size - 1 - sz[to]];
        lol %= mod;
        lol *= my_pow(dp[to], mod - 2);
        lol %= mod;
        lol *= fact[sz[to]];
        lol %= mod;
        dfs1(to, v, total_size - sz[to], lol);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    g.resize(n);
    fact.resize(n + 1);
    dp.resize(n);
    sz.resize(n);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        g[a].pb(b); g[b].pb(a);
    }
    ans.resize(n);
    dfs(0, -1);
    dfs1(0, -1, 0, 1);
    for (auto &c : ans) cout << c << "\n";
    return 0;
}


Measured memory_bytes: 21220
#include<bits/stdc++.h>
#define For(i,l,r) for(register int i=l;i<=r;++i)
#define Ford(i,l,r) for(register int i=r;i>=l;--i)
using namespace std;
typedef long long ll;
const int maxn = 1e5+20;
int n,m,vis[maxn],tot;
int pos[maxn],fir[maxn*2],to[maxn*4],nex[maxn*4],ans[maxn*2];
struct Node{
	int pos,state;
	bool operator < (const Node& x){return pos<x.pos;}
}a[maxn];

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}

inline int dfs(int x)
{
	int& sta=a[x].state;
	vis[x]=1;
	for(int i=fir[x];i;i=nex[i])
	{
		int& p=to[i];
		if(!vis[p]&&dfs(p))
			++tot,++ans[i/2],sta^=1;
	}
	return sta;
}

int main()
{
	n=read(),m=read();
	For(i,1,n)
		a[i].pos=read(),a[i].state=read();
	sort(a+1,a+1+n);
	Ford(i,1,n+1)
		pos[i]=a[i].pos,a[i].state^=a[i-1].state;
	For(i,1,m)
	{
		int le=read(),ri=read();
		le=lower_bound(pos+1,pos+1+n,le)-pos;
		ri=upper_bound(pos+1,pos+1+n,ri)-pos;
		if(le==ri) continue;
		nex[i*2+1]=fir[le],fir[le]=i*2+1,to[i*2+1]=ri;
		nex[i*2]=fir[ri],fir[ri]=i*2,to[i*2]=le;
	}
	For(i,1,n+1)
		if(!vis[i]&&dfs(i))
			puts("-1"),exit(0);
	printf("%d\n",tot);
	For(i,1,m)
		if(ans[i])
			printf("%d ",i);
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int H, W, K;
vector<vector<char>> s;
vector<vector<int>> ans;

int main() {
  cin >> H >> W >> K;

  s.resize(H, vector<char>(W));
  ans.resize(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> s[i][j];

  int k = 1, y = 0;
  rep(i, H) {
    int c = 0, x = 0;
    rep(j, W) {
      if (s[i][j] == '#') {
        ++c;
        if (c > 1) {
          for (int l = y; l <= i; ++l) {
            for (int m = x; m < j; ++m) {
              ans[l][m] = k;
            }
          }
          ++k;
          x = j;
        }
      }
    }
    if (c != 0) {
      for (int l = y; l <= i; ++l) {
        for (int m = x; m < W; ++m) {
          ans[l][m] = k;
        }
      }

      ++k;
      y = i + 1;
    }
  }
  assert(k == K + 1);

  rep(j, W) {
    int m = 0;
    rep(i, H) {
      m = max(m, ans[i][j]);
      if (ans[i][j] == 0) ans[i][j] = m;
    }
  }

  rep(i, H) {
    rep(j, W) {
      if (j != 0) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// const int MAX_M = 500000;
struct Node {
  int key;
  Node *left, *right;
  Node (int x) : key(x), left(nullptr), right(nullptr) { }
};

void insert(Node *&root, int z) {
  Node *par = nullptr, *tmp = root;
  while (tmp != nullptr) {
    par = tmp;
    if (z < tmp->key) {
      tmp = tmp->left;
    } else {
      tmp = tmp->right;
    }
  }
  if (par == nullptr) {
    root = new Node(z);
    // cout << z << endl;
  } else if (z < par->key) {
    par->left = new Node(z);
    // cout << ' ' << par->left->key << endl;
  } else {
    par->right = new Node(z);
    // cout << ' ' << par->right->key << endl;
  }
  return;
}

void inorder(Node *root) {
  if (root == nullptr)
    return;
  inorder(root->left);
  cout << ' ' << root->key;
  inorder(root->right);
  return;
}

void preorder(Node *root) {
  if (root == nullptr)
    return;
  cout << ' ' << root->key;
  preorder(root->left);
  preorder(root->right);
}

void print(Node *root) {
  if (root != nullptr) {
    inorder(root);
    cout << endl;
    preorder(root);
    cout << endl;
  }
  return;
}

int main() {
  int m, z;
  cin >> m;
  string cmd;
  Node *root = nullptr;
  for (int i = 0; i < m; ++i) {
    cin >> cmd;
    if (cmd == "print")
      print(root);
    else {
      cin >> z;
      insert(root, z);
    }
  }
  return 0;
}


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

int main(){
	string save;
	while(1){
		cin >> save;
		if(save == "0") break;
		int len = save.size();
		int ac=0,bc=0;
		for(int i=1;i<len;i++){
			if(save[i] == 'A') ac++;
			else bc++;
		}
		if(ac > bc) ac++;
		else bc++;
		cout << ac << " " << bc << endl;
	}
}

Measured memory_bytes: 1184
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long N = firstLine[0];
            var K = firstLine[1];
            var Q = firstLine[2];

            long[] Points = new long[N];
            for (int i = 0; i < N; i++)
            {
                Points[i] = 0;
            }

            for (int i = 0; i < Q; i++)
            {
                var target = int.Parse(Console.ReadLine());
                Points[target - 1]++;
            }

            for (int i = 0; i < N; i++)
            {
                if (K - Q + Points[i] > 0)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 18396
// 2018.09.05 2min

#include <iostream>

using namespace std;

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

    if(R<1200) cout << "ABC" << endl;
    else if(R<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
ans=[]
if s[0]=='A' and s[2:len(s)-1].count('C')==1:
    ans.append('a')
    ans.append(s[1])
    ans.append(s[2:len(s)-1].replace('C','c'))
    ans.append(s[-1])
    if ''.join(ans).islower(): print('AC')
    else:
        print('WA')
else: print('WA')

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    int N;
    ll H[100002];
    cin >> N;
    rep(i,N){
        cin >> H[i];
    }
    H[0] -= 1;
    rep(i,N-1){
        if (i > 0 && H[i]-H[i-1]>0){
            H[i] -= 1;
        }
        if (H[i+1] - H[i] < 0){
            cout << "No" << endl;
            return 0;    
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
import std.stdio;
import std.conv;
import std.string;

const int DATA = 200;

int main() {
  int[] digit = new int[DATA];
  int i;
  for(i=0; i<DATA; i++) {
    string[] data = chomp(readln).split(" ");
    if(stdin.eof()) break;
    int val = to!(int)(data[0]) + to!(int)(data[1]);
    int dig = 1;
    while((val/=10) != 0) dig++;
    digit[i] = dig;
  }
  for(int j=0; j<i; j++) writeln(digit[j]);

  return 0;
}

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

int main() {
	// your code goes here
	int n,m,s,ss;
	cin>>n>>m>>s>>ss;
	int cnt=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int k=0;k<=s;k++){
				if((i*500)+(j*100)+(k*50)==ss){
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

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

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

int main() {
	int N, K;

	cin >> N >> K;

	ll ans = K;

	rep(i, N - 1) {
		ans *= K - 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final long MODVAL = 1000000007L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ar[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, };
        int K = sc.nextInt();
        System.out.println(ar[K-1]);
    }
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
using lld = int64_t;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	lld n, p; cin >> n >> p;
	lld tp = p, ans = 1;
	for (lld i = 2; i * i <= p; ++i) {
		if (tp % i) continue;
		int ct = 0;
		for (; tp % i == 0; tp /= i)
			++ ct;
		for (; ct >= n; ct -= n) ans *= i;
	}
	if (tp != 1 and n == 1) ans *= tp;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
def ABC_169_B():
    N=int(input())
    A = input().split()
    A = [int(s) for s in A]
    sum=1
    flg=0

    if A.count(0)>=1:
        print(0)
        flg=1

    if flg==0:
     for i in range(len(A)):
         sum=(sum*A[i])
         if sum>10**18:
             print(-1)
             flg=1
             break
    if flg==0:
        print(sum)
        
if __name__ == '__main__':

    ABC_169_B()

Measured memory_bytes: 21640
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a = max(a)

    if a.count(max_a) > 1:
        print('\n'.join([str(max_a) for _ in a]))
    else:
        max_a2 = sorted(a)[-2]
        print('\n'.join([str(max_a) if i != max_a else str(max_a2) for i in a]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 25172
def main():
    s = input().rstrip()
    n = len(s)
    f = True
    for i in range((n+1)//2):
        if s[i] != s[len(s)-1-i]:
            f = False
#    if f:
#        print("A")
    for i in range(n//2):
        if s[i] != s[len(s) - (n+1)//2 - 1 - i]:
            f = False
#    if f:
#        print("B")
    for i in range((n+3)//2-1, len(s)):
        if s[i] != s[len(s) - 1 - (i - ((n+3)//2 - 1))]:
            f = False
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    char c;
    cin >> c;
    cout << (char)((c - 'a') + 1 + 'a') << endl;
}

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

using namespace std;

int main()
{
   int n,k;cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int dp[n];
  for(int i=0;i<n;i++) dp[i]=INT_MAX;

   dp[0]=0;
   for(int i=1;i<n;i++)
        for(int j=1;j<=k;j++)
            if(i-j>=0)
            {
                    int val=abs(a[i]-a[i-j])+dp[i-j];
                    if(val<dp[i]) dp[i]=val;
            }

   cout<<dp[n-1];


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

int main(void){
  ll n,k; cin >> n >> k;
  ll a[n]; rep(i,n) cin >> a[i];
  ll tanbo[n]; rep(i,n) tanbo[i] = 0;
  ll katei = 0;
  for(ll i = 0; i < n; i++){
    if(k == i){
      cout << katei+1 << endl;
      return 0;
    }
    if(tanbo[katei] != 1) tanbo[katei]++;
    else if(tanbo[katei] == 1){
      break;
    }
    katei = a[katei]-1;
  }
  ll katei2 = a[katei]-1;
  ll count = 1;
  for(ll i = 0; i < n; i++){
    if(katei2 == katei) break;
    katei2 = a[katei2]-1;
    count++;
  }
  ll count2 = 0;
  katei2 = 0;
  for(ll i = 0; i < n; i++){
    if(katei2 == katei) break;
    katei2 = a[katei2]-1;
    count2++;
  }
  ll katei3 = (k-count2)%count;
  ll ans = katei;
  for(ll i = 0; i < katei3; i++){
    ans = a[ans]-1;
  }
  cout << ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 6748
import sys
readline = sys.stdin.readline

def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '.':
                cnt = 0
                for dh in [-1, 0, 1]:
                    for dw in [-1, 0, 1]:
                        if 0 <= h+dh < H and 0 <= w+dw < W:
                            if mat[h+dh][w+dw] == '#':
                                cnt += 1
                mat[h][w] = cnt
    
    for l in mat:
        print(*l, sep='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21

int main() {
  int N, K;
  cin >> N >> K;
  if (N - K == 0 || K == 1)
    cout << 0 << endl;
  else
    cout << N - K << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
Alice = 0
Bob = 0
for i in range(N):
    if(i % 2 == 0):
        Alice += max(a)
        a.remove(max(a))
    else:
        Bob += max(a)
        a.remove(max(a))
print(Alice-Bob)

Measured memory_bytes: 9100
#include<iostream>
using namespace std;
#include <vector>
#define COT_NUM 26
#define re(i,n) for(int i = 0; i < n; i++)

int main() {
	int d;
	int score = 0;
	cin >> d;
	vector<vector<int>> s(d, vector<int>(COT_NUM));
	vector<int> c(COT_NUM);
	vector<int> t(d);
	vector<int> w(COT_NUM, 0);

	re(i, COT_NUM) cin >> c[i];
	re(i, d) {
		re(j, COT_NUM) cin >> s[i][j];
	}
	re(i, d) {
		cin >> t[i];
		t[i]--;
	}
	
	re(i, d) {
		score += s[i][t[i]];
		w[t[i]] = 0;
		re(j, COT_NUM) w[j] += !(j == t[i]);
		re(j, COT_NUM) score -= c[j] * w[j];
		cout << score << endl;;
	}



	return 0;
}

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

int main(){
  string S;
  string T;
  cin >> S >> T;
  int count=0;
  for(int i=0;i<S.size();i++){
    count+=S[i]!=T[i];
    
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3916
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int P[200000];
int M[200000];

int main() {
	memset(P, 0, sizeof(P));
	memset(P, 0, sizeof(M));
	int N;
	cin >> N;
	int tmp;
	int64 ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> tmp;
		if (i+tmp < 200000) ++P[i+tmp];
		if (i-tmp > 0) ++M[i-tmp];
	}
	for (int i = 1; i < N; ++i) {
		ans += (int64)P[i] * M[i];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5208
#include <stdio.h>

int main()
{
  int i,v,j,n,k;
  scanf("%d",&n);

  int A[100];
  for(k=0;k<n;k++)
    {
      scanf("%d",&A[k]);
    }
  
  for(k=0;k<n-1;k++)
    {
      printf("%d ",A[k]);
    }
  printf("%d\n",A[n-1]);
  
  for(i=1;i<n;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0&&A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;

      for(k=0;k<n-1;k++)
	{
	  printf("%d ",A[k]);
	}
      printf("%d\n",A[n-1]);
    }
  
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define LOG(...) printf(__VA_ARGS__)
using namespace std;

int cnt[26];

int main() {
    int H, W;
    cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char c;
            cin >> c;

            ++cnt[c - 'a'];
        }
    }

    unordered_map<int, int> stock;

    if (H % 2 == 1 && W % 2 == 1) {
        stock[1] = 1;
    }

    if (H % 2 == 1) {
        stock[2] += W / 2;
    }
    if (W % 2 == 1) {
        stock[2] += H / 2;
    }

    stock[4] = (H * W - 2 * stock[2] - stock[1]) / 4;

    //LOG("%d %d %d\n", stock[1], stock[2], stock[4]);

    for (int i = 0; i < 26; ++i) {
        for (int x : { 4, 2, 1 }) {
            if (cnt[i] == 0)
                break;

            if (cnt[i] >= x) {
                int use = min(cnt[i] / x, stock[x]);
                cnt[i] -= use * x;
                stock[x] -= use;

                //LOG("%d/%d : %d, %d, %d\n", cnt[i], x, use, cnt[i], stock[i]);
            }
        }
        if (cnt[i] > 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		LinkedList<String> list = new LinkedList<String>();
		for (char c: S.toCharArray()) {
			if (c=='B') list.pollLast();
			else list.addLast(String.valueOf(c));
		}
		for (String c: list) System.out.print(c);
		sc.close();
	}

}


Measured memory_bytes: 9812
#include <stdio.h>

#include <stdbool.h>

int main(){
	int b=0,c;
	
	int i;
	bool a[1000001];
	
	for(b=0;b<1000001;b++){
		a[b]=1;
	}
	a[0]=0;a[1]=0;
	b=0;
	do{
		if(a[b]==1){
			c=2;
			while(b*c<1000001){
				a[b*c]=0;
				c++;
			}
		}
		b++;
		
	}while(b<500001);
	
	/*for(b=0;b<1000001;b++){
		if(a[b]==1){
			printf("%d\n",b);
		}
	}*/
	
	
	int x,y,z;
	while(1){
		scanf("%d %d %d",&x,&y,&z);
		if(x==0){
			break;
		}
		i=0;
		while(z!=0){
			if(a[x+y*i]){
				z--;
			}
			i++;
		}
		printf("%d\n",x+y*(i-1));
	}
	
	
	return 0;
}

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

bool linearSearch(vector<int> A, int key){
	int i = 0;
	A.push_back(key);
	
	while(A[i] != key)
		i++;
	
	if(i == A.size()-1)
		return false;
	else
		return true;
}

int main(){
	int n, q, num, T, count = 0;
	vector<int> S;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num;
		S.push_back(num);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>T;
		count += linearSearch(S, T);
	}

	cout<<count<<endl;

	return 0;
}

Measured memory_bytes: 1320
from bisect import bisect_left
n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        b = L[i] + L[j]
        ans += bisect_left(L, b) - 1 - j 
print(ans) 

Measured memory_bytes: 3188
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

// O(n*w)

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,W;
    cin >> n >> W;

    vector<ll> weight(n),value(n);
    int sum_value;
    for(int i  =0; i< n; ++i)
    {
        cin >> weight[i] >> value[i];
        sum_value += value[i];
    }
    vector<ll> dp(sum_value+1,INFLL);
    // dp[i] - the minimum total weight of items with total value exactly i
    dp[0] = 0;

    for(int item = 0; item < n; ++item)
    {
        for(int value_already = sum_value - value[item]; value_already >=0; --value_already)
        {
            dp[value_already+value[item]] = min(dp[value_already+value[item]], dp[value_already] + weight[item]);
        }
    }
    for(int i = sum_value; i>= 0; --i)
    {
        if(dp[i] <= W)
        {
            cout << i << '\n';
            return 0;
        }
    }



    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  long long a,b,n;
  cin >> a >> b >> n;
  
  ll fact2=n/b;
  ll fact1=a*n/b;
  ll ans1=fact1-a*fact2;
  
  if(n<b){
    cout << ans1 << endl;
    return 0;
  }
  
  ll x=n/b;
  x=b*x-1;
  ll fact3=a*x/b;
  ll fact4=x/b;
  ll ans2 = fact3-a*fact4;
  
  ans1=max(ans1,ans2);
  cout << ans1 << endl;
  
  
  
}
  
  


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var abc = ReadIntArray();
            Console.WriteLine($"{abc.Distinct().Count()}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    char a[10000], b[10000];
    cin >> a >> b;
    if (strlen(a) > strlen(b)) {
        cout << "GREATER" << endl;
    }
    else if (strlen(a) < strlen(b)) {
        cout << "LESS" << endl;
    }
    else {
        imfor(i, strlen(a)) {
            if ((int)a[i] > (int)b[i]) {
                cout << "GREATER" << endl;
                return 0;
            }
            else if ((int)a[i] < (int)b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}

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

Measured memory_bytes: 256
n = int(input())

p = list(map(int,input().split()))
t = 0
for i in range(len(p)-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        t += 1
    if p[i]>p[i+1] and p[i+1]>p[i+2]:
        t += 1
print(t)

Measured memory_bytes: 2940
H, W, K = map(int, input().split())

WW = [0]*(W+1)
WW[0] = 1
WW[1] = 1
for i in range(2, W+1):
    WW[i] = WW[i-1] + WW[i-2]
DP = [[0]*W for i in range(H+1)]
DP[0][0] = 1
mod = 10**9+7
for i in range(1, H+1):
    for j in range(W):
        if j == 0:
            DP[i][j] = DP[i-1][j]*WW[W-1]
            if W > 1:
                DP[i][j] += DP[i-1][j+1]*WW[W-2]
        elif j == W-1:
            DP[i][j] = DP[i-1][j]*WW[W-1]
            if W > 1:
                DP[i][j] += DP[i-1][j-1]*WW[W-2]
        else:
            DP[i][j] = DP[i-1][j]*WW[j]*WW[W-1-j]+DP[i-1][j-1] * \
                WW[j-1]*WW[W-1-j]+DP[i-1][j+1]*WW[j]*WW[W-2-j]

        DP[i][j] %= mod
# print(DP, WW)
print(DP[-1][K-1])


Measured memory_bytes: 9220
l = list(map(int, input()))
mod = 10 ** 9 + 7

ln = len(l)
dp = [[0] * 2 for _ in range(2)]
dp[0][1] = 1

for e in l:
    dp_new = [[0] * 2 for _ in range(2)]
    for now in range(2):
        for prev in range(2):
            # same -> same
            if now == e:
                dp_new[now][1] += dp[prev][1] * (now + 1)

            # same -> small
            if now == 0 and e == 1:
                dp_new[now][0] += dp[prev][1]

            # small -> small
            dp_new[now][0] += dp[prev][0] * (now + 1)

    dp = dp_new
    for i in range(2):
        for j in range(2):
            dp[i][j] %= mod

ans = 0
for row in dp:
    ans += sum(row)
    ans %= mod

print(ans)


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

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;


int main() {

	IO;

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	cout << max({a*c, a*d, b*c, b*d});

}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;
    while (cin >> n, n)
    {
        string str, gtr;
        cin >> str >> gtr;
        set<string> q;
        map<string, ll> mp;
        q.insert(str);
        mp[str] = 0;
        for (int i = 0; i < n; i++)
        {
            set<string> nq;
            for(auto v:q)
            {
                int num = (gtr[i] - v[i] + 10) % 10;
                if (num == 0)
                {
                    nq.insert(v);
                    continue;
                }
                for (int j = i; j < n; j++)
                {
                    string s = v;
                    for (int idx = i; idx <= j; idx++)
                    {
                        s[idx] = '0' + (s[idx] - '0' + num) % 10;
                    }
                    if (mp.find(s) != mp.end())
                        mp[s] = min(mp[s], mp[v] + 1);
                    else
                        mp[s] = mp[v] + 1;
                    nq.insert(s);
                }
            }
            q = nq;
        }
        cout << mp[gtr] << endl;
    }
}



Measured memory_bytes: 5236
#include <stdio.h>

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

    scanf("%d %d %d", &a, &b, &c);

    int i, cnt = 0;
    for (i = a; i <= b; i++) {
        if (c % i == 0) {
            cnt++;
        }
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 596
class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0: return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x,y=self.find(x),self.find(y)
        if x==y:return False
        if self.d[x] > self.d[y]: x,y=y,x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x,y): return self.find(x)==self.find(y)
    def size(self,x): return -self.d[self.find(x)]
    
def main():
  N,Q=map(int,input().split())
  uf = UnionFind(N)
  for i in range(Q):
    t,u,v=map(int,input().split())
    if t:
      print(+(uf.same(u,v)))
    else:
      uf.unite(u,v)
      
if __name__=="__main__":
  main()

Measured memory_bytes: 11480
def main():
    from math import ceil
    n, a, b, *k = map(int, open(0).read().split())
    k.sort()

    l = k[-1] // a - 1
    r = k[-1] // b + 1
    m = (l + r) // 2
    while l + 1 < r:
        c = sum(ceil((i - m * b) / (a - b)) if i - m * b > 0 else 0 for i in k)
        if c <= m:
            r = m
        else:
            l = m

        m = (l + r) // 2

    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20032