akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  int a,b;
  cin>>a>>b;
  int ans = 0;
  int tmp = 1;
  while (tmp < b) {
    tmp += a-1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::collections::HashMap;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s:Vec<char> = buf.trim().chars().collect();
	let mut m = HashMap::new();
	for i in s {
		match m.insert(i, 1) {
			None => (),
			Some(n) => {
				m.insert(i, n+1);
			},
		}
	}
	let mut flag = true;
	for val in m.values() {
		if *val != 2 {
			flag = false;
			break;
		}
	}
	if flag {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
//  int a, b, c, d, e, X, Y;
  int a, b, c,  d, e,f;
  //  double  c;
//  long long  A[1000001]={};
  int  A[2000001]={};
  int  B[2000001]={};
  int  ans[100003]={};
  int  sum[100003]={};
  int  cnt_flag[100003]={};

  int  L[1003]={};


//  long long  a, b, c, d, X, Y;
//  long long   d, X, Y;
  long long JPY;
  double BTC;
  char s[200001]={};
  char t[200001]={};
  char u[200001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  int flag=0;
//  int flag[10000003]={};
  int tmp=0;
//  int min=1000000;
  int min=10;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
//  long long ans=0;
  int max=0;
//  int sum=0;
//  char alp[26]={'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'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
 

    scanf("%d", &a);
    cnt=1;
    scanf("%d", &max);
    for(i=1;i<a;i++){
      scanf("%d", &A[i]);
      if(A[i]>=max){
        max=A[i];
        cnt++;
      }
    }
    

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

//  printf("%s\n",s);
//    else  
  
return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>s;
    for0(s.size())
    {
        c+=(s[i]-'0');
    }
    cout<<(c%9?"No":"Yes")<<endl;
}



Measured memory_bytes: 3696
#include<stdio.h>
int x,S[1000],top;
 
void push(int x)
{
  S[++top]=x;
}
 
int pop()
{
  int x=S[top--];
  return x;
}
 
int main(){
  int i;
   
  while(scanf("%d",&x)!=EOF)
    {
      if(x==0)
    {
      printf("%d\n",S[top]); 
      pop();
    }
      else
    {     
      push(x);
    } 
    }
   
  return 0;
}


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

int main() {
  string A, B;
  cin >> A >> B;
  if(A==B) cout << "EQUAL" << endl;
  else if(A.size()>B.size()) cout << "GREATER" << endl;
  else if(A.size()<B.size()) cout << "LESS" << endl;
  else if(A.size()==B.size()){
    rep (i, A.size()){
       if (A.at(i)>B.at(i)){
         cout << "GREATER" << endl;
         break;
       }
       else if (A.at(i),B.at(i)){
         cout << "LESS" << endl;
         break;
       }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  string s[n];
  rep(i,n) cin>>s[i];
  int al[n][26];
  rep(i,n) {
    rep(j, 26) al[i][j] = 0;
  }
  rep(i,n) {
    rep(j, s[i].size()) {
      al[i][(int)(s[i][j] - 'a')]++;
    }
  }
  for(char i = 'a'; i <= 'z'; i++) {
    int mi = 100;
    rep(j,n) {
      mi = min(mi, al[j][(int)(i - 'a')]);
    }
    rep(j, mi) {
      cout << i;
    }
  }
  cout << endl;

  return 0;
}


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

#define int long long
#pragma GCC optimize ("O3")
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")


#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;string L;
int DP[100005][2];
int modexpo(int x,int y,int P)
{
	int res = 1;
    while (y > 0)
    {
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;

}
int fun(int ind=0,int D=0)
{
	if (ind==n)return 1;
	if (DP[ind][D]!=-1)return DP[ind][D];

	if (L[ind]=='0')
	{
		if (D)return DP[ind][D]=(3*fun(ind+1,D))%MOD;
		else return DP[ind][D]=fun(ind+1,D);
	}
	else
	{
		if (D)return DP[ind][D]=(3*fun(ind+1,D))%MOD;
		else return DP[ind][D]=(fun(ind+1,1)+2*fun(ind+1,D))%MOD;
	}
}
void solve()
{
	cin>>L;n=L.length();
	rep(i,0,n+2)DP[i][0]=DP[i][1]=-1;
	int ans=fun();
	cout<<ans<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    #ifdef local
    freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///    cout<<"Case #"<<a+1<<": ";
        solve();
    }
    {qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
}


Measured memory_bytes: 6736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    ll r = 0;
    for (int i = k; i <= n + 1; i++) {
        ll t0 = (ll)i * (i - 1) / 2;
        ll t1 = (ll)i * n - t0;
        r += (t1 - t0 + 1) % P;
    }

    cout << r % P << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define For(i, a) for (int i=0; i<a; i++)
#define FORR(i,a,b) for (int i = a; i >= b; i--)
#define Forr(i,a) for (int i = a; i >= 0; i--)

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args)
{cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

#define int ll
#define pb(x) push_back(x)
#define INF (int)1e17
#define PI 3.14159265358979323846

int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};


const int mod = 1e9+7;

int mul(int x,int y){
    int res = x*y;
    if(res >= mod)res%=mod;
    return res;
}

int add(int x, int y){
    int res = x+y;
    if(res >= mod)res-=mod;
    return res;
}
int sub(int x, int y){
    int res = x-y;
    if(res<0)res+=mod;
    return res;
}

void solve(){
  int n; cin >> n;
  int a[n];
  For(i,n)cin >> a[i];
  vector<int> pref(n+1,0);
  pref[0]=a[0];
  FOR(i,1,n)pref[i]=add(pref[i-1],a[i]);
  int ans=0;
  For(i,n){
    ans = add(ans, mul(a[i],sub(pref[n-1],pref[i])));
  }
  cout  << ans << "\n";
}
int32_t main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
}

Measured memory_bytes: 6372
from math import sqrt,ceil,floor
def mi():return map(int,input().split())
def li():return list(mi())
def ii():return int(input())



n=ii()
a=li()
x=[]
m={}
for i in range(1,n+1):
    x1=a[i-1]-i
    x.append(x1)
    
    if x1 not in m:
        m[x1]=1
    else:
        m[x1]+=1
        
ans=0
for i in range(n):
    x1=x[i]-2*a[i]
    
    
    if x1 in m:
        ans+=m[x1]
        
print(ans)
    
    
    

Measured memory_bytes: 124212
#include<stdio.h>

int main(void){

    long int n;
    int i,j;
    long int ans=0;
    scanf("%ld",&n);

    for(i=0;i<n;i++){
      ans=ans+i;
    }
    if(n==1)
    ans=0;
    printf("%ld",ans);



    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
        
        System.out.println((X-A)%B);
    }
    
}

Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<String,Long> map = new HashMap<>();
		long ans = 0;
		for(int i = 0;i < N;i++) {
			char[] c = sc.next().toCharArray();
			Arrays.sort(c);
			String s = new String(c);
			if(!map.containsKey(s)) {
				map.put(s, (long)0);
			}else {
				map.put(s, map.get(s)+1L);
				ans += map.get(s);
			}
		}
		sc.close();
		System.out.println(ans);
	}
}

Measured memory_bytes: 51868
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  cout.precision(12);
  double ax,ay,bx,by,cx,cy;
  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&ax,&ay,&bx,&by,&cx,&cy)){
    P a(ax,ay), b(bx,by), c(cx,cy);
    P v = b-a;
    P d = conj((c-a)/v)*v+a;
    cout<<fixed<<d.real()<<" "<<d.imag()<<endl;
  }
  return 0;
}

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

int main(void){
  int n, p_i, count = 0;
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> p_i;
    if(i != p_i) count++;
  }
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
_ = input()
A = list(map(int,input().rstrip().split(" ")))
ans = [0,0]
q = [0 for i in range(9)]
for i in A:
    q[min(8,i // 400)] += 1
for i in range(9):
    if i == 8:
        ans[1] += q[i]
    else:
        if q[i] != 0:
            ans[0] += 1
            ans[1] += 1
ans[0] = max(1,ans[0])
print(str(ans[0]) + " " + str(ans[1]))

Measured memory_bytes: 9140
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll ans = 0LL;
  ll cnt = 0LL;
  ll pre = va[0];
  for (ll i = 1; i < N; i++) {
    if (va[i] <= pre) {
      cnt++;
    } else {
      cnt = 0LL;
    }
    ans = std::max(ans, cnt);
    pre = va[i];
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
    string ch;
    cin >> ch;
    int sum = 0, lcnt = 0;
    for (int i = 0; i < ch.size(); i++)
    {
        sum++;
        if (ch[i] == 'S')
            lcnt++;
        else if (ch[i] == 'T')
        {
            if (lcnt != 0)
                sum -= 2, lcnt--;
        }
    }
    cout << sum;
    //system("pause");
}

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

int main() {
    int N, A;
    cin >> N >> A;
    
    if (N%500 > A) {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG_ARR(x, a, b) for(int i=a; i<=b; i++) cerr<<x[i]<<" "; cerr<<endl;
#define DEBUG_STR(x, a, b) for(int i=a; i<=b; i++) cerr<<x[i]; cerr<<endl;
#define gcd __gcd


using namespace std;

typedef long long ll;
typedef unsigned long long llu;

int main() {
	FIO;
	int n;
	cin>>n;
	ll total = 0;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			for(int k=1; k<=n; k++){
				total += gcd(i,gcd(j,k));
			}
		}
	}
	
	cout<<total;
	return 0;
}


Measured memory_bytes: 3648
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

void a(){
    int N,K; cin >> N >> K;
    string S; cin >> S;

    if (S[K -1] == 'A') S[K-1] = 'a';
    if (S[K -1] == 'B') S[K-1] = 'b';
    if (S[K -1] == 'C') S[K-1] = 'c';

    cout << S;

}

void b(){
    string S; cin >> S;
    

}
int main(){
    a();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int h = scanner.nextInt();
    final int n = scanner.nextInt();
    int sum = 0;

    for (int i = 0; i < n; i++) {
      sum += scanner.nextInt();
    }
    if (sum >= h) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}


Measured memory_bytes: 47616
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]
mod = 998244353

def solve() :
    c = Counter(D)
            
    if c[0] != 1 or D[0] != 0 :
        return 0
        
    ret = 1
    for i in range(1, max(c) + 1) :        
        ret = ret * pow(c[i-1], c[i], mod) % mod
    
    return ret
        
print(solve())

Measured memory_bytes: 62260
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	vector<int>c(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];

	}

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

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int diff = v[i] - c[i];
		if (diff >0) {
			sum += diff;
		}
	}

	cout << sum << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

int main() {
    long long q, h, s, d, n;
    std::cin >> q >> h >> s >> d >> n;
    q *= 8; h *= 4; s *= 2;
    long long ret = n / 2 * std::min({ q, h, s, d });
    ret += (n % 2) * std::min({ q / 2, h / 2, s / 2 });
    std::cout << ret << std::endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

struct edge {
    int v;
    edge *next;
} pool[N * 3], *h[N];

int n, k, p[N], top = -1, ans;
int dis[N];

inline void addedge(int u, int v) {
    edge *tmp = &pool[++top];
    tmp -> v = v; tmp -> next = h[u]; h[u] = tmp;
}

void dfs(int u) { for(edge *tmp = h[u]; tmp != NULL; tmp = tmp -> next) dis[tmp -> v] = dis[u] + 1, dfs(tmp -> v); }

int solve(int u) {
    int res = 1;
    for(edge *tmp = h[u]; tmp != NULL; tmp = tmp -> next) {
        int v = tmp -> v;
        res = max(res, solve(tmp -> v) + 1);
    }
    if(res == k) if(dis[u] > 1) ans++, res = -1;
    return res; 
}

void init() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> p[i];
        if(i != 1) addedge(p[i], i);
    }
    if(p[1] != 1) ans++;
    dfs(1);
    solve(1);
    cout << ans << endl;
}

int main() {
    init();
    return 0;
}

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

struct item {
    int value;
    int weight;
};

int knapsack(item items[], int n, int w) {
    const int max_value = n * 1000;
    long long int dp[n + 1][max_value + 1];

    for (int v = 0; v <= max_value; ++v) {
        dp[1][v] = INT_MAX;
    }
    dp[1][0] = 0;
    dp[1][items[1].value] = items[1].weight;
    for (int i = 2; i <= n; ++i) {
        for (int v = 0; v <= max_value; ++v) {
            dp[i][v] = dp[i - 1][v];
            if (items[i].value <= v) {
                dp[i][v] = min(dp[i][v], dp[i - 1][v - items[i].value] + items[i].weight);
            }
        }
    }
    int max_profit = 0;
    for (int v = 0; v <= max_value; ++v) {
        if (dp[n][v] <= w) {
            max_profit = v;
        }
    }
    return max_profit;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    item items[n + 1];
    for (int i = 1; i <= n; ++i) {
        cin >> items[i].weight >> items[i].value;
    }
    cout << knapsack(items, n, w) << endl;
    return 0;
}

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

vector<int> a;
vector<int> b;
vector<int> c;
vector<ll> d;
ll ans = 0;
int n,m,q;

void dfs(vector<int> v, int i){
	if(v.size() == n){
		ll count = 0;
		rep(i,q){
			if(v[b[i]] - v[a[i]] == c[i]) count += d[i];
		}
		ans = max(ans, count);
	}else{
		for (int j = i; j <= m; ++j) {
			v.push_back(j);
			dfs(v, j);
			v.pop_back();
		}
	}
	return;
}
int main(){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	rep(i,q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	vector<int> u;
	dfs(u,1);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
D,G=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(D)]
ans=G // 100

for i in range(2**D):
    score=0
    b=0
    cnt=0
    for j in range(D):
        if ((i>>j)&1):
            score+=100*(j+1)*pc[j][0]+pc[j][1]
            cnt+=pc[j][0]
        else:
            b=j
    for k in range(pc[b][0]):
        if score>=G and cnt<ans:
            ans=cnt
        score+=(b+1)*100
        cnt+=1
print(ans)

Measured memory_bytes: 9212
def main():
    N = int(input())
    array = [int(input()) for _ in range(N)]
    array.sort()

    div, mod = divmod(N, 2)
    if mod == 0:
        fore, last_in_fore, first_in_rear, rear = array[:div-1], array[div-1], array[div], array[div+1:]

        a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
        print(a)
        return
    else:
        #mode1 (mrfrm):(1,2,-2,2,1)
        array1=array[:]
        fore1=[]
        rear1=[]
        while True:
            fore1.append(array1.pop(0))
            if len(array1) <= 2:
                break
            rear1.append(array1.pop(-1))
        mid1 = array1
        a1 = 2 * sum(rear1) + sum(mid1) - 2 * sum(fore1)

        #mode2 (mfrfm):(1,-2,2,-2,1)
        array2 = array[:]
        fore2=[]
        rear2=[]
        while True:
            rear2.append(array2.pop(-1))
            if len(array2) <= 2:
                break
            fore2.append(array2.pop(0))
        mid2 = array2
        a2 = 2 * sum(rear2) - sum(mid2) - 2 * sum(fore2)

        print(max(a1, a2))
        return
    return


main()

Measured memory_bytes: 9328
#include <stdio.h>
int main(void){
    
    int i,a[100],n,max,min;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max=a[0]; min=a[0];
    
    for(i=1;i<n;i++){
        if(max<a[i]){
        max=a[i];
        }
        if(min>a[i]){
        min=a[i];
        }
    }

    printf("%d\n",max-min);
}


Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
 
// ===============================================================
 
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
 
// ===============================================================
 
ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
 
ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}
 
ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}
 
ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}
 
ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}
 
	int s = sum(n - 1);
	return s + n;
}
 
bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
 
	// 素数である
	return true;
}
 
// ===============================================================
 
int main() {
	ll a, b; cin >> a >> b;
	if (a < 10 && b < 10) {
		cout << a * b << endl;
	}
	else cout << -1 << endl;
}

Measured memory_bytes: 3436
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FUnfairNim {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      ll x = 0;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      for(int i=2; i<n; i++) {
        x ^= a[i];
      }
      debug(x);

      ll sum = a[0] + a[1];

      ll now = 0;
      for(int i=0; i<60; i++) {
        if (x&(1LL<<i)) {
          now += (1LL<<i);
        }
      }
      ll a0 = 0;
      for(int i=59; i>=0; i--) {
        if (!(x&(1LL<<i))) {
          if (now + (1LL<<i)*2 <= sum) {
            now += (1LL<<i)*2;
            a0 += (1LL<<i);
          }
        }
      }

      if (now != sum) {
        cout << -1 << endl;
        return;
      }

      if (a0 > a[0]) {
        cout << -1 << endl;
        return;
      }

      debug(now, sum, a0, a[0]);

      for(int i=59; i>=0; i--) {
        if (x&(1LL<<i)) {
          if (a0 + (1LL<<i) <= a[0]) {
            a0 += (1LL<<i);
          }
        }
      }
      if (a0 == 0) {
        cout << -1 << endl;
        return;
      }

      cout << a[0] - a0 << endl;



    }
};

signed main() {
  FUnfairNim solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author __shangu__
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DEqualCut solver = new DEqualCut();
        solver.solve(1, in, out);
        out.close();
    }

    static class DEqualCut {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long a[] = new long[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextLong();
            for (int i = 1; i < n; ++i) a[i] += a[i - 1];

            long ans = Long.MAX_VALUE;
            for (int i = 1; i < n - 2; ++i) {
                int cut1 = Arrays.binarySearch(a, 0, i, a[i] / 2);
                if (cut1 < 0) cut1 = -cut1 - 1;
                if (cut1 == i) {
                    --cut1;
                } else if (cut1 > 0 && Math.abs(a[cut1] - a[i] / 2) > Math.abs(a[cut1 - 1] - a[i] / 2)) {
                    --cut1;
                }

                int cut2 = Arrays.binarySearch(a, i, n, (a[n - 1] + a[i]) / 2);
                if (cut2 < 0) cut2 = -cut2 - 1;
                if (cut2 == i) {
                    --cut2;
                } else if (cut2 > 0 && Math.abs(a[cut2] - (a[n - 1] + a[i]) / 2) > Math.abs(a[cut2 - 1] - (a[n - 1] + a[i]) / 2)) {
                    --cut2;
                }

                long sum1 = a[cut1], sum2 = a[i] - a[cut1], sum3 = a[cut2] - a[i], sum4 = a[n - 1] - a[cut2];
                long mx = Math.max(sum1, Math.max(sum2, Math.max(sum3, sum4)));
                long mn = Math.min(sum1, Math.min(sum2, Math.min(sum3, sum4)));
                ans = Math.min(ans, mx - mn);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 46960
def readinput():
    n,q = list(map(int,input().split()))
    procs = []
    for i in range(n):
        name, strtime = input().split()
        inttime = int(strtime)
        procs.append([name, inttime])
    return n,q,procs

def dispach(t, q, procs):
    t0 = t
    #print(t0, t, procs)

    proc = procs.pop(0)
    procname = proc[0]
    tremain = proc[1]
    if (tremain > q):
        proc[1] = tremain - q
        procs.append(proc)
        t0 += q
    else:
        t0 += tremain
        print(procname+' '+str(t0))

    #print(t0, t, procs)
    return t0

def main(n,q,procs):
    t = 0
    #print(procs)
    while(len(procs)>0):
        t = dispach(t, q, procs)
        #print(t, procs)
    return

if __name__=='__main__':
    n,q,procs=readinput()
    #print(procs)
    main(n,q,procs)



Measured memory_bytes: 12876
n = int(input())
ls = [list(map(int, input().split())) for _ in range(n)]
x, y = ls[0]
for a, b in ls[1:]:
    if a == b == 1:
        x = y = max(x, y)
    else:
        switch = a < b
        if switch:
            a, b = b, a
            x, y = y, x
        xx = (x + a - 1) // a * a
        yy = b * xx // a
        if yy > y:
            x = xx
            y = yy
        else:
            y = (y + b - 1) // b * b
            x = a * y // b
        if switch:
            x, y = y, x
print(x + y)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

ld dp[305][305][305];
int a[4];
void answer() {
  int n;
  cin >> n;
  rep(i, n) {
    int a_;
    cin >> a_;
    a[a_]++;
  }
  dp[0][0][0] = 0.0;
  repc(i, a[3]) repc(j, a[3]+a[2]-i) repc(k, a[3]+a[2]+a[1]-i-j) {
    if(!i && !j && !k) continue;
    ld e1 = ld(n) / ld(i+j+k);
    ld e2 = 0.0;
    if(i) e2 += i * dp[i-1][j+1][k];
    if(j) e2 += j * dp[i][j-1][k+1];
    if(k) e2 += k * dp[i][j][k-1];
    e2 /= ld(i+j+k);
    dp[i][j][k] = e1 + e2;
  }
  cout << fixed << setprecision(14) << dp[a[3]][a[2]][a[1]] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 215584
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  vector<map<int,int>> x(h),y(w);
  rep(i,h){
    int pre = -1;
    rep(j,w){
      if(s[i][j]=='.'){
        if(pre==-1) x[i][pre = j] = 0;
      }else{
        if(pre>=0) x[i][j] = j - pre;
        pre = -1;
      }
    }
    x[i][w] = pre>=0 ? w - pre : 0;
  }
  rep(j,w) {
    int pre = -1;
    rep(i,h){
      if(s[i][j]=='.'){
        if(pre==-1) y[j][pre = i] = 0;
      }else{
        if(pre>=0) y[j][i] = i - pre;
        pre = -1;
      }
    }
    y[j][h] = pre>=0 ? h - pre : 0;
  }

  int ans = 0;
  rep(i,h)rep(j,w){
    auto itrx = x[i].upper_bound(j);
    int cx = itrx != x[i].end() ? itrx->second : 0;
    auto itry = y[j].upper_bound(i);
    int cy = itry != x[i].end() ? itry->second : 0;
    ans = max(ans,cx+cy-1);
  }
  cout << ans << endl;
}

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

int main() {
  int N, ans = 0;
  cin >> N;
  vector<int> V(N), C(N);
  for (int i=0; i<N; i++) {
    cin >> V.at(i);
  }
  for (int i=0; i<N; i++) {
    cin >> C.at(i);
  }
  for (int i=0; i<N; i++) {
    if (V.at(i) - C.at(i) > 0) ans += V.at(i) - C.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <set>
#include <map>

using namespace std;

bool f(int x, int n)
{
    long sum = 0;
    for(int i=0; i<x; i++)
    {
        if(n > 0 && i%2 == 0) sum += (1ll << i);
        if(n < 0 && i%2 == 1) sum -= (1ll << i);
    }

    //cout << "n " << n << " x " << x << " sum " << sum << endl;

    if(n >= 0 && n <= sum) return true;
    if(n <= 0 && n >= sum) return true; 

    return false;
}

int main(){

    int n;
    cin >> n;

    if(n == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    long s = 0;
    int base = 0;
    /*
    if(n < 0) base = 1;
    while(true)
    {
        if(n > 0)
        {
            if(n > (1 << base))
            {
                base+=2;
            }
            else
            {
                break;
            }
        }
        if(n < 0)
        {
            if(n < -(1 << base))
            {
                base+=2;
            }
            else
            {
                break;
            }
        }
    }
*/
    base = 32;

    for(int i=base; i>0; i--)
    {
        if(!f(i, n))
        {
            //cout << "add/minus " << (1 << i) << endl;
            s += (1ll << i);
            if(i%2 == 0) n -= (1ll << i);
            else n += (1ll << i);
        }

/*
        int next = (1 << i);
        if(i%2 == 0)
        {
            int plus = (1 << (i-2));
            if(i-2 < 0) plus = 0;
            cout << "plus " << plus << endl;
            if(n > plus)
            {
                s += next;
                n -= next;
            }
            else
            {
                //s = s << 1;
            }
        }
        else
        {
            int minus = (1 << (i-2));
            if(i-2 < 0) minus = 0;
            cout << "minus " << minus << endl;
            if(n < -minus)
            {
                s += next;
                n += next;
            }
            else
            {
                //s = s << 1;
            }
        }

        cout << "next" << next <<  " n " << n << endl;
        */
    }
    if(n == 1) s += 1;

    //cout << "s " << s << " n " << n << endl;

    bool first = true;
    for(int i=base; i>0; i--)
    {
        if(s & (1ll<<(i-1))) {cout << 1; first = false;}
        else if(!first) cout << 0;
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
res = [INF] * (n+1)
res[0] = 0
ge = [1]
for i in [6,9]:
    now = 1
    while True:
        now *= i
        if now > n:
            break
        ge.append(now)
ge.sort()
for i in range(1,n+1):
    for x in ge:
        if x > i:
            continue
        res[i] = min(res[i], res[i-x]+1)
print(res[n])

Measured memory_bytes: 70092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(b-a==c-b){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
		

	}

}


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

using namespace std;

int main()
{
    string s;
    stack<char> q;
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;i++)
    {
        if(s[i]=='C'&&q.empty())
            q.push(s[i]);
        if(s[i]=='F'&&(!q.empty()))
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;

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

    VVI D(N, VI(2));
    bool ok = false;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 2; ++j) {
            cin >> D[i][j];
        }

        if (i >= 2 && D[i][0] == D[i][1]) {
            if (D[i-2][0] == D[i-2][1]
            && D[i-1][0] == D[i-1][1]) {
                ok = true;
            }
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

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

using namespace std;

const long long MOD = 1000000007;

// べき乗の余り計算
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) {
        res += m;
    }
    
    return res;
}


int main() {
    long long N;
    cin >> N;

    long long answer;

    answer = mod(modpow(10, N, MOD) - modpow(9, N, MOD) * 2, MOD);
    answer = mod(answer + modpow(8, N, MOD), MOD);

    cout << mod(modpow(10, N, MOD) - modpow(9, N, MOD) * 2 + modpow(8, N, MOD), MOD) << endl;
    return 0;
}

Measured memory_bytes: 3620
from collections import deque
S = input()
Q = int(input())

T = [None] * Q
F = [None] * Q
C = [None] * Q
for i in range(Q):
    query = input().split()
    T[i] = int(query[0])
    if len(query) == 3:
        F[i] = int(query[1])
        C[i] = query[2]

ans = deque([S])
cnt1 = 0  # T[i]の偶奇
for i in range(Q):
    if T[i] == 1:
        cnt1 = (cnt1 + 1) % 2
    elif F[i] == 1:  # 先頭にCi追加
        if cnt1 == 0:  # そのまま
            ans.appendleft(C[i])
        else:   # 逆順にして末尾に追加
            ans.append(C[i][::-1])
    else:  # 末尾にCi追加
        if cnt1 == 0: # そのまま
            ans.append(C[i])
        else:
            ans.appendleft(C[i][::-1])

ans = ''.join(ans)

if cnt1 == 1:
    ans = ans[::-1]

print(ans)


Measured memory_bytes: 16244
def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)

if __name__ == "__main__":
    s = input()
    mylist = s.split()
    a = int(mylist[0])
    b = int(mylist[1])
    k = int(mylist[2])
    mygcd = gcd(a,b)
    cdList = []
    for i in range(1, mygcd+1, 1):
        if(a % i == 0 and b % i == 0):
            cdList.append(i)
    print(cdList[len(cdList) - k])



Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int a[10];
	int i, j;

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

	for (i = 0; i < 9; i++){
		for (j = i + 1; j < 10; j++){
			if (a[i] < a[j]){
				a[i] ^= a[j];
				a[j] ^= a[i];
				a[i] ^= a[j];
			}
		}
	}

	for (i = 0; i < 3; i++){
		printf("%d\n", a[i]);
	}

	return (0);
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
#define rep(i,x,to) for(int i=x;i<=to;i++)

int main() {
	int n,x;
	while(1){
		cin>>n>>x;
		int count=0;
		if(n==0&&x==0) break;
		rep(i,1,n){
			rep(j,i+1,n){
				rep(k,j+1,n)
					if(x==i+j+k) count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}


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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int n, i; cin>>n>>i;
    cout << n-i+1 << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<ll,Pi> P1i;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,sx,sy,total;
};
ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}
int main(){

	ll n,k;
	ll a[100001];

	cin>>n>>k;
	cin>>a[0];
	ll s=a[0],m=a[0];
	rep(i,n-1){
		cin>>a[i+1];
		s=gcd(s,a[i+1]);
		m=max(m,a[i+1]);
	}
	if(k%s==0&&k<=m)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;


	return 0;

}




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

using namespace std;

typedef long long ll;
constexpr int INF = numeric_limits<int>::max()/2;

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

    int n,k,q;cin>>n>>k>>q;
    vector<ll> a(n);
    ll res=1e15;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        // 最小値 := a[i]
        int idx=0;
        vector<vector<ll>> v(n+1);
        for(int j=0;j<n;j++){
            if(a[j]<a[i]){
                if(v[idx].size()!=0){
                    sort(v[idx].begin(),v[idx].end());
                    idx++;
                }
                continue;
            }
            v[idx].push_back(a[j]);
        }
        if(v[idx].size()!=0) sort(v[idx].begin(),v[idx].end());
        int cnt=0;
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        for(int j=0;j<n;j++){
            if((int)v[j].size()<k) continue;
            for(int m=0;m<(int)v[j].size()-k+1;m++){
                pq.push(v[j][m]);
                cnt++;
            }
        }
        //cout<<i<<" "<<cnt<<endl;
        if(cnt<q) continue;
        for(int j=0;j<q-1;j++){
            pq.pop();
        }
        //cout<<pq.top()<<" "<<a[i]<<endl;
        res = min(res,pq.top()-a[i]);
        
    }
    cout<<res<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int a, b, c,count=0;
	scanf("%d %d %d", &a, &b, &c);
	for(int i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			count = count + 1;
		}
	}
	printf("%d\n", count);
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long x = sc.nextLong();
        long y = sc.nextLong();

        long ans = Math.abs(Math.abs(x) - Math.abs(y));
        if (x <= y) {
            if (x * y < 0)
                ans += 1;
        } else {
            if (x * y > 0)
                ans += 2;
            else
                ans += 1;
        }
        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>                                                                               
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)
using i64 = int64_t;

i64 factor(i64 N) {
  i64 m = N - 1;
  i64 Nsqrt = sqrt(N);
  for (i64 i = 1; i <= Nsqrt; ++i)   {   
    i64 q = N / i;
    i64 r = N % i;
    if  (r  == 0) {
      i64 s = i + q - 2;
      if (s < m) {
        m = s;
      }   
    }   
  }
  return m;
}

int main () {
  i64 N;
  cin >> N;
  cout << factor(N) << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''

    N, M, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    res = 0
    time = 0

    memo_A = [0]
    for i in range(N):
        memo_A.append(As[i]+memo_A[-1])

    memo_B = [0]
    for i in range(M):
        memo_B.append(Bs[i]+memo_B[-1])

    res = 0
    j = M
    for i, av in enumerate(memo_A):
        if av > K:
            break
        else:
            
            while av + memo_B[j] > K:
                j -= 1
            res = max(res,j+i)

    print(res)

if __name__ == "__main__":
    resolve()
            


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



int main() {
    int K;
    cin>>K;
    queue<ll> q;
    for(ll i=1;i<10;i++)q.push(i);
    rep(i,K-1){
        ll now=q.front();
        q.pop();
        int fir=now%10;
        if(fir>0)q.push(now*10+fir-1);
        q.push(now*10+fir);
        if(fir<9)q.push(now*10+fir+1);
    }
    cout<<q.front()<<endl;
}

Measured memory_bytes: 1792