akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll dp1[200200][2];
ll dp2[200200][2][2];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  string s,t;
  cin >> s >> t;
  bool ok=true;
  if(s.size()<t.size())ok=false;
  if(s.size()==t.size()){
    if(s<t)ok=false;
    if(s==t){
      cout << "EQUAL" << endl;
      return 0;
    }
  }
  if(ok)cout << "GREATER"<<endl;
  else cout<<"LESS"<<endl;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)

A, B, C, D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)

print((B-A+1) -(b_num - a_num))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MX=2e5+9;
int n,a[MX],ans,x;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=1+n;i++){
        if(a[i]==i)x++;
        else if(x){
            ans+=(x+1)/2;x=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 

n, X = map(int, input().split())
x = list(map(int, input().split()))
if len(x) == 1:
  print(abs(x[0] - X))
else:
  x.sort()
  s = x[1] - x[0]
  for i in range(1, n-1):
    s = gcd(s, x[i+1]-x[i])
  a = 1
  for i in range(n):
    a = max(a, gcd(abs(X-x[i]), s))
  print(a)

Measured memory_bytes: 14352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class DRedistribution {
        long[] dp = new long[2001];

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt(), mod = (int) 1e9 + 7;
            dp[0] = 1;
            dp[1] = dp[2] = 0;
            dp[3] = dp[4] = dp[5] = 1;
            for (int i = 6; i <= n; ++i) {
                for (int j = 3; j <= i; ++j) {
                    dp[i] = (dp[i] + dp[i - j]) % mod;
                }
            }
            out.println(dp[n]);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32544
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
 long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
ll bionomial(ll n , ll r){
	
	ll res = 1 ;
	for (ll i =  0 ; i<r;i++){
		res *= (n-i) ;
		res %= MOD ;
	}
	return res ;
}
void solve()
{
	
	
	ll n ; 
	cin>>n ;
	ll a ,b;
	cin>>a>>b;
	ll fac[200001] ;
	fac[0] = 1 ;
	for( ll i =1 ;  i< 200001 ; i++){
		fac[i]  = (fac[i-1] * i)%MOD ;
	}
	ll ans = 0 ;
	if(a>n-a){
		a = n-a ;
	}
	if(b>n-b){
		b = n-b;
	}
	ans = modpow(2 , n) -1;
	ll tans = bionomial( n , a) ;
	ans -= (tans* modpow(fac[a],MOD-2))%MOD;
	ans %= MOD ;
	tans = bionomial(n  ,b) ;
	ans -= (tans * modpow(fac[b]  , MOD -2))%MOD ;
	ans %= MOD ;
	if(ans<0) {
		ans += MOD ;
	}
	cout<<ans<<endl;
}
 
int main() {
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
	double a;
	double  x, y, A, B;
	cin >> a;
	A = a * a;
	x = (double)A * 3.141592653589793238462643383279;
	B = a * 2;
	y = (double)B * 3.141592653589793238;
	printf("%.8f %.8f\n", x, y);
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double sqr(int x){
	return 1.0 * x * x;
}

double dist(pii a, pii b){
	return sqrt(sqr(a.first - b.first) + sqr(a.second - b.second));
}

double get(vector<pii> &v){
	double ans = 0.0;
	
	for(int i = 0; i + 1 < v.size(); i++)
		ans += dist(v[i], v[i + 1]);
	
	return ans;
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cout << setprecision(10) << fixed;
	
	int n;
	cin >> n;
	
	vector<pii> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;
	
	sort(v.begin(), v.end());
	
	double num = 0.0, den = 0.0;
	
	do{
		num += get(v);
		den += 1.0;
		
	}while(next_permutation(v.begin(), v.end()));


	cout << num / den << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,i,n;
	int min = 1000000;
	int max = -1000000;
	long long int sum = 0;
	scanf("%d",&n);
	
	for(i = 0; i < n; i++){
		scanf("%d",&a);
		if(min > a) min = a;  //最小値
		if(max < a) max= a;  //最大値
		sum = sum + a;        //合計値
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}


Measured memory_bytes: 2056
#include <iostream>
using namespace std;
int main(){
    int a,b,ans;
    cin >> a >> b;
    if( (a/100)*100 + a/10000 + ((a/1000)%10)*10 >= a ){
        if( (b/100)*100 + b/10000 + ((b/1000)%10)*10 > b ){   //in,out
            ans = b/100 - a/100;
        }else{                  //in,in
            ans = b/100 - a/100 + 1;
        }
    }else{
        if( (b/100)*100 + b/10000 + ((b/1000)%10)*10 > b ){   //out,out
            ans = b/100 - a/100 - 1;
        }else{                  //out,in
            ans = b/100 - a/100;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    int n, cnt=0;
    cin >> n;
    REP(i,1,n+1){
        ll tmp=0;
        REP(j,1,i+1){
            if(i%j==0) tmp++;
        }
        if(tmp==8 && i%2==1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    M=65
    A=LI()
    cnt=[0]*M
    
    for i in range(N):
        a=A[i]
        for j in range(M):
            if a>>j & 1:
                cnt[j]+=1
                
    ans=0
    for i in range(M):
        a=cnt[i]
        b=N-a
        ans=(ans + a*b*pow(2,i,mod))%mod
        
    print(ans)
                

main()


Measured memory_bytes: 118728
import java.util.Scanner;

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

        Scanner sc =new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();

        if (A <= 8 && B <= 8){
          System.out.println("Yay!");
        }else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 23508
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;


int main(void) {
	int N, K,ans;
	cin >> N >> K;
	ans = 1;
	for (int i = 0; i < N; i++) {
		if (ans < K)ans *= 2;
		else ans += K;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

void solve(long long N, long long X, long long T) {
    if (N % X == 0) {
        cout << (N / X) * T << endl;
    } else {
        cout << ((N / X) + 1) * T << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    long long T;
    scanf("%lld", &T);
    solve(N, X, T);
    return 0;
}


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

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

  int a, l = 0, r = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (a < x)
      l++;
    else
      r++;
  }

  cout << min(l, r) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, R, ans;
    cin >> N >> R;
    if ( N < 10 ) cout << R + 100 * ( 10 - N ) << endl;
    else cout << R << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for (int i = s; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD=1000000007;
vll dx{0,1,0,-1};
vll dy{1,0,-1,0};
int i,j,k,n,m,a,b,c;
ll res,ans;
vvll graph;

bool all(const vector<bool> &A)
{
    bool res=true;
    rep(i,0,A.size())res=res&&A[i];
    return res;
}

void dfs(ll v,vector<bool> seen) {
    seen[v] = true; 
    if(all(seen)){
        res+=1;
        return;
    }
    for (auto next_v : graph[v]) { 
        if (seen[next_v]) continue;
        dfs(next_v,seen);
    }
    return;
}

template <class type> void printVector(vector<type> vec){
    stringstream ss;
    ll n=vec.size();
    for(ll i=0;i<n;i++)
    {
        ss<<vec[i]<<" ";
        if(i!=n-1)ss<<" ";
    }
    cout<<ss.str()<<endl;
}

template <class type> void inputVector(vector<type>& vec){
    for(ll i=0;i<vec.size();i++)
    {
        cin>>vec[i];
    }
}

void solve(){
    cin >> n >> m;
    graph=vvll(n);
    rep(i,0,m){
        cin>>a>>b;a--;b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    dfs(0,vector<bool>(n));
    cout<<res;
}

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


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
bool cand[100000];
vvc<ll> G;
ll dist[100000];

ll dfs(ll now){
    ll d = 0;
    for(auto& to: G[now]){
        if (dist[to] > 0) chmax(d, dist[to] + 1);
        else
            chmax(d, dfs(to) + 1);
    }
    dist[now] = d;
    return d;
}

int main() {
    init();
    ll N,M;
    cin >> N >> M;
    G.resize(N);
    rep(i,M){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].eb(b);
        cand[b] = true;
    }

    ll ans = 0;
    rep(i,N){
        if (cand[i]) continue;
        chmax(ans, dfs(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    double ans = 0;
    int a = 0;
    vector<int> vec(100);

    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
        ans += vec.at(i);
    }

    ans = ans / (4.0 * M);

    for(int i = 0;i < N;i++){
        if(vec.at(i) >= ans){
           
        }else{
            a++;  
        }
    }

    if(M <= N - a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int a, b;

		Scanner scan = new Scanner(System.in);

		a = Integer.parseInt(scan.next());
		b = Integer.parseInt(scan.next());

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}

	}
}

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


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Team
    {
        internal string name;
        internal int point;

        public override string ToString()
        {
            return name + "," + point;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            bool isStart = true;

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                if (!isStart) sb.Append("\n");
                else isStart = false;

                Team[] teams = new Team[n];

                for (int i = 0; i < n; i++)
                {
                    string[] input = Console.ReadLine().Split(' ');

                    teams[i].name = input[0];
                    teams[i].point = int.Parse(input[1]) * 3 + int.Parse(input[3]);
                }

                teams = teams.OrderByDescending(t => t.point).ToArray();

                foreach (var team in teams)
                {
                    sb.AppendLine(team.ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9968
#include<stdio.h>

int main()
{
    int i,n,ans,tmp;
    int s[6];
    char c[6];
    while(scanf("%d",&n),n){
    	s[0]=1;s[1]=2;s[2]=3;s[3]=5;s[4]=4;s[5]=6;
    	ans=1;
	    for(i=0;i<n;i++){
	    	scanf("%s",c);
	    	switch(c[0]){
        	    case 'N':
        	    	tmp=s[0];
        	    	s[0]=s[1];
        	    	s[1]=s[5];
        	    	s[5]=s[3];
        	    	s[3]=tmp;
        	    	ans+=s[0];
        	    	break;
        	    case 'E':
        	    	tmp=s[0];
        	    	s[0]=s[4];
        	    	s[4]=s[5];
        	    	s[5]=s[2];
        	    	s[2]=tmp;
        	    	ans+=s[0];
        	    	break;
        	    case 'W':
        	    	tmp=s[0];
        	    	s[0]=s[2];
        	    	s[2]=s[5];
        	    	s[5]=s[4];
        	    	s[4]=tmp;
        	    	ans+=s[0];
        	    	break;
        	    case 'S':
        	    	tmp=s[0];
        	    	s[0]=s[3];
        	    	s[3]=s[5];
        	    	s[5]=s[1];
        	    	s[1]=tmp;
        	    	ans+=s[0];
        	    	break;
        	    case 'R':
        	    	tmp=s[1];
        	    	s[1]=s[2];
        	    	s[2]=s[3];
        	    	s[3]=s[4];
        	    	s[4]=tmp;
        	    	ans+=s[0];
        	    	break;
        	    case 'L':
        	    	tmp=s[1];
        	    	s[1]=s[4];
        	    	s[4]=s[3];
        	    	s[3]=s[2];
        	    	s[2]=tmp;
        	    	ans+=s[0];
        	    	break;
        	}
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <set>

std::unordered_map<size_t,size_t> A;
std::set<size_t, std::greater<size_t>> As;
int main() {
  size_t N;
  std::cin >> N;
  for (size_t i = 0; i < N; i++) {
    size_t a;
    std::cin >> a;
    A[a]++;
    As.insert(a);
  }

  size_t max = 0;
  for (auto i : As) {
    if (max == 0 && A[i] >= 4) {
      std::cout << i * i << std::endl;
      return 0;
    }
    if (A[i] >= 2) {
      if (max == 0) {
        max = i;
      } else {
        std::cout << max * i << std::endl;
        return 0;
      }
    }
  }
  std::cout << 0 << std::endl;
}


Measured memory_bytes: 8996
program main
    implicit none
    integer k,n
    integer, allocatable, dimension(:) :: a
    integer min,d,i

    read(*,*) k,n
    allocate(a(n))
    read(*,*) a
 
    min = a(n) - a(1)
    
    do i = 2, n
        d = k - (a(i) - a(i-1))
        if (d <= min) then
            min = d
        end if
    end do

    write(*,*) min

end program

Measured memory_bytes: 2048
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim();
    var  S = Number (inputs);
    var h = Math.floor(S/3600);
    var rest = S - (h*3600);
    var m= Math.floor (rest/60);
    var s = S % 60;
	console.log([h,m,s].join (':'));
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  vi A(N);
  int sum=0;
  rep(i,0,N){
    cin>>A[i];
    sum+=A[i];
  }
  set<int> S;
  REP(i,1,sqrt(sum)){
    if(sum%i==0){
      S.insert(i);
      S.insert(sum/i);
    }
  }
  int ans=1;
  for(auto p:S){
    vi B(N);
    int me=0;
    rep(i,0,N){
      B[i]=A[i]%p;
      me+=B[i];
    }
    sort(ALL(B),greater<int>());
    int mem=0;
    rep(i,0,me/p) mem+=B[i];
    if(me-mem<=K) ans=p;
  }
  cout<<ans<<endl;
  }




Measured memory_bytes: 768
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "Hello World";
    }
    else
    {
        int a, b;
        cin >> a >> b;
        cout << a + b;
    }
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if(a < b ){
		cout << "a < b" << endl;
	} else if(a > b){
		cout <<"a > b" << endl;
	} else{
		cout << "a == b" << endl;
	};
	return 0;
}


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

int main( void )
{
    char c[ 2 ][ 3 ];
    for ( int i = 0; i < 2; i++ )
    {
        for ( int j = 0; j < 3; j++ )
        {
            cin >> c[ i ][ j ];
        }
    }
    if ( ( c[ 0 ][ 0 ] == c[ 1 ][ 2 ] ) && ( c[ 0 ][ 1 ] == c[ 1 ][ 1 ] ) &&
         ( c[ 0 ][ 2 ] == c[ 1 ][ 0 ] ) )
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<int> dp;
vector<vector<int>> G;

int f(int cur) {
  if (dp[cur] == -1) {
    int longest = 0;
    for (int next : G[cur]) {
      longest = max(longest, f(next));
    }

    dp[cur] = longest + 1;
  }

  return dp[cur];
}

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

  G.resize(n);

  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;

    G[x].push_back(y);
  }

  dp.resize(n);
  fill(dp.begin(), dp.end(), -1);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int cnt = f(i);
    ans = max(ans, cnt);
  }

  cout << ans - 1 << endl;

  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K; cin >> K;
  string S; cin >> S;
  if (S.size() > K){
    for (int i=0; i<K; i++) cout << S[i];
    cout << "...";
    return 0;
  }
  else{
    cout << S;
    return 0;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 1e5+7;
const int MOD = 1e9+7;

int dp[MN][2], mark[MN];
vector<int> g[MN];

void dfs(int now){
    mark[now] = 1;
    vector<int> v;
    ll ff = 1, ss = 1;
    for(int i = 0; i < g[now].size(); i++){
        if(!mark[g[now][i]]){
            dfs(g[now][i]);
            ff = (ff * dp[g[now][i]][0])% MOD;
            ss = (ss * (dp[g[now][i]][0] + dp[g[now][i]][1])) % MOD;
        }
    }
    dp[now][0] = ss;
    dp[now][1] = ff;
}

signed main(){
    int n, k;
    cin >> n;
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    cout << (dp[0][0] + dp[0][1]) % MOD;
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
#define mod 998244353//今回のでかい素数
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

//オーバーフローしないようにその都度割っていく！
//階乗などを配列で持っておくことで計算量を減らす！

ll n, m, k, ans, p;
ll fact[2*MAX+10];//階乗(factorial)
ll invfact[2*MAX+10];//階乗の逆元

ll modpow(ll A, ll N){//二分累乗法により、Nを2の累乗の和に分解してO(logN)で求める
    ll res = 1;
    while(N>0) {
        if(N&1) res = res*A%mod;
        A = A*A%mod;
        N >>= 1;
    }
    return res;
}

ll combination(ll A,ll B){//combination(O(1))
    if(A < B) return 0;
    if(A < 0 || B < 0) return 0;
	return fact[A]*invfact[A-B]%mod*invfact[B]%mod;
}

int main(){
    cin>>n>>m>>k;
    ans = 0;
    fact[0] = 1;//0!
	FOR(i, 1, n) fact[i] = fact[i-1]*i%mod;//fact[i] : i!の配列(factorial)

    invfact[n] = modpow(fact[n], mod-2);//フェルマーの小定理よりaの逆元はa^(mod-2)
    FORR(i, n-1, 0) invfact[i]=invfact[i+1]*(i+1)%mod;//(i+1)!の逆元にi+1かけてるだけ

    p = modpow(m-1,n-k-1);
	FOR(i, n-k, n){//pow(m-1,n-i-1)の更新をループ内で行ってO(N)に
		ans = (ans+m*p%mod*combination(n-1,i-1)%mod)%mod;
		p = p*(m-1)%mod;
	}
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 6712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

#define MAX 200000
int L[(MAX/2)+2];
int R[(MAX/2)+2];
long long merge(int A[], int left, int mid, int right){
	int nl=mid-left;
	int nr=right-mid;
	long long cnt=0;
	for(int i=0;i<nl;i++){
		L[i]=A[left+i];
	}
	for(int i=0;i<nr;i++){
		R[i]=A[mid+i];
	}
	L[nl]=2000000000;
	R[nr]=2000000000;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i];
			i++;
		}
		else{
			A[k]=R[j];
			j++;
			cnt+=nl-i;
		}
	}
	return cnt;
}

long long mergesort(int A[], int left, int right){
	int mid;
	long long int l,r,mg;
	if(left+1<right){
		mid=(left+right)/2;
		l=mergesort(A,left,mid);
		r=mergesort(A,mid,right);
		mg=merge(A,left,mid,right);
		return l+r+mg;
	}
	else
	return 0;
}

int main(){
	int A[MAX],n;
	long long ans;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	ans = mergesort(A,0,n);
	printf("%lld\n",ans);
}

Measured memory_bytes: 4736
N = int(input())
W_li = list(map(int, input().split()))
min_abs = 20000
for i in range(N - 1) :
    s1 = sum(W_li[:i + 1])
    s2 = sum(W_li[i + 1:])
    abs_s = abs(s1 - s2)
    if min_abs > abs_s :
        min_abs = abs_s
print(min_abs)


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

int main() {
  int N, K, sum = 1, tmp;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    tmp = sum;

    tmp *= 2;
    sum += K;
    if (sum > tmp)
      sum = tmp;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

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

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        if (m1 % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	ll n;
	cin>>n;
	cout<<(n+999)/1000*1000-n;
}

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


Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;


int main(int argc, char *argv[])
{
  int N, ans = 0, a = 0, b = 0, ab = 0;
  string s[20000];
  cin >> N;

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

  for (int i = 0; i < N; i++) {
    std::string::size_type pos = s[i].find("AB");
    while (pos != std::string::npos) {
      ans++;
      pos = s[i].find("AB", pos + 2);
    }

    if (s[i].front() == 'B' && s[i].back() == 'A') {
      ab++;
    } else if (s[i].front() == 'B') {
      b++;
    } else if (s[i].back() == 'A') {
      a++;
    }
  }

  int tmp = ans + max(ab - 1, 0);
  if (ab > 0) {
    if (a >= 1) {
      tmp++;
      a--;
    }

    if (b >= 1) {
      tmp++;
      b--;
    }
  }

  tmp += min(a, b);

  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 896
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in range(N-1)]
px = [LI() for _ in range(Q)]
ans = [0]*(N+1) #1_index
graph = {i:collections.deque() for i in range(1,N+1)} #1_index
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


Measured memory_bytes: 260488
object Main extends App {
  var input = scala.io.StdIn.readLine()
  val abkArray =  input.split(" ").map(_.toInt)
  val a = abkArray(0)
  val b = abkArray(1)
  val k = abkArray(2)
  var i = 1
  var s = 1
  var array = Vector.empty[Int]

  while (s <= a && s <= b)  {
    if (a % s == 0 && b % s == 0) {
      array :+= s
    }
    s += 1
  }
  val arrayr = array.reverse
  print(arrayr.apply(k - 1))
}

Measured memory_bytes: 25400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[55],y[55];
int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i]>>y[i];
	map<pair<ll,ll>,ll>mp;
	ll ma=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
		mp[make_pair(x[i]-x[j],y[i]-y[j])]++;
		mp[make_pair(x[j]-x[i],y[j]-y[i])]++;
		ma=max(ma,mp[make_pair(x[i]-x[j],y[i]-y[j])]);
		ma=max(ma,mp[make_pair(x[j]-x[i],y[j]-y[i])]);
	}
	cout<<n-ma<<endl;
	return 0;
}


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

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)
#define rep(i,x,N) for(int i=x;i<=N;i++)
#define ar array

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
using vvi=vector<vi>;
int ctoi(char c) {return c-'0';}
int slen(string s) {return s.length();}
int vsize(vi a) {return (int)a.size();}
int in() {int x;cin>>x;return x;}
void tf(bool ok) {cout<<(ok ? "YES" : "NO")<<endl;}

//https://atcoder.jp/contests/abc178/tasks/abc178_b

void rrrrrrrrrrrrrresi() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  vll x{a*c,b*c,a*d,b*d};
  sort(all(x));
  cout<<x.back()<<endl;
}

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int Q=1;
//cin>>Q;
while(Q--)
  rrrrrrrrrrrrrresi();
return 0;
}




Measured memory_bytes: 3652
# coding: utf-8
class Case02

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  def read
    @s = gets.chomp
  end

  def solve
    @result = 'x' * @s.length
  end
  
  def output
    puts @result
  end

end

Case02.new.execute if $0 == __FILE__


Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=(1<<20)+10;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,i,j,f[N];char s[N];
int main(){
	//freopen("1.out","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i++)f[s[i]-'a']=1;
	for(i=0;i<26;i++)if(!f[i]){
		s[n+1]='a'+i;
		printf("%s\n",s+1);return 0;
	}
	for(i=n;i;i--){
		f[s[i]-'a']=0;
		for(j=s[i]-'a'+1;j<26;j++)if(!f[j]){
			s[i]='a'+j;s[i+1]=0;
			printf("%s\n",s+1);return 0;
		}
	}puts("-1");
	return 0;
}


Measured memory_bytes: 128
<?php
class Dice{
  public $label=[1,2,3,4,5,6];#index+1????????¢?????????
  public $pos=[0,1,2];#?????¢,?????¢,??\??¢???index ???????????¢???5-index
  function __construct($sLabel){$this->label=explode(' ',$sLabel,6);}
  function move($s){
    if(!$s) return;
    $x=$this->pos[0];
    if($s=='E'){
      $this->pos[0]=5-$this->pos[2];
      $this->pos[2]=$x;
    }
    elseif($s=='W'){
      $this->pos[0]=$this->pos[2];
      $this->pos[2]=5-$x;
    }
    elseif($s=='N'){
      $this->pos[0]=$this->pos[1];
      $this->pos[1]=5-$x;
    }
    elseif($s=='S'){
      $this->pos[0]=5-$this->pos[1];
      $this->pos[1]=$x;
    }
  }
  function spin($s){
    $x=$this->pos[1];
    if($s=='L'){
      $this->pos[1]=$this->pos[2];
      $this->pos[2]=5-$x;
    }
    elseif($s=='R'){
      $this->pos[1]=5-$this->pos[2];
      $this->pos[2]=$x;
    }
  }
  function toTop($label){
    $move=array('','N','W','W','W','N');#1 2 3 5 4 6
    for($i=0;$i<6;$i++){
      $this->move($move[$i]);
      if($this->top()==$label) return 1;
    }
    return 0;
  }
  function toSpin($label){
    for($j=0;$j<4;$j++){
      if($this->front()==$label) return 1;
      $this->spin('L');
    }
    return 0;
  }
  function isSame($dice){
    $move=array('','N','W','W','W','N');#1 2 3 5 4 6
    $end=[];
    for($i=0;$i<6;$i++){
      $this->move($move[$i]);
      $top=$this->top();
      if(isset($end[$top])) continue;
      $end[$top]=1;
      if(!$dice->toTop($top)) continue;
      if(!$dice->toSpin($this->front())) continue;
      if($dice->right()!=$this->right()) continue;
      if($dice->bottom()!=$this->bottom()) continue;
      if($dice->back()!=$this->back()) continue;
      if($dice->left()!=$this->left()) continue;
      return 1;
    }
    return 0;
  }
  function top(){return $this->label[$this->pos[0]];}
  function front(){return $this->label[$this->pos[1]];}
  function right(){return $this->label[$this->pos[2]];}
  function bottom(){return $this->label[5-$this->pos[0]];}
  function back(){return $this->label[5-$this->pos[1]];}
  function left(){return $this->label[5-$this->pos[2]];}
}

$d0=new Dice(trim(fgets(STDIN)));
$d1=new Dice(trim(fgets(STDIN)));
echo ($d0->isSame($d1))?'Yes':'No';
?>

Measured memory_bytes: 15608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct state{
	ll w,s,v;
};

ll dp[1010][20010];
state g[1010];

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	rep(i,n){
		cin>>g[i].w>>g[i].s>>g[i].v;
	}
	sort(begin(g),begin(g)+n,[](const state &a,const state &b){
		return a.w+a.s<b.w+b.s;
	});
	rep(i,n)rep(j,20010){
		dp[i+1][j]=dp[i][j];
		if(0<=j-g[i].w && j-g[i].w<=g[i].s){
			chmax(dp[i+1][j],dp[i][j-g[i].w]+g[i].v);
		}
	}
	cout<<*max_element(begin(dp[n]),end(dp[n]))<<endl;
	/*
	あるブロックの集合を決め打つと, s+wが小さい順に上から積んでいくのが最適
	(自分の位置以上の重さの上限を与えるものなので)
	あとはナップサック
	*/
}

Measured memory_bytes: 157824
#include<bits/stdc++.h>
using namespace std;
 
int const N = 1234;
 
long long f[N];
int c[N][4];
long long dp[42];
int can[42];
long long cr[N][4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%d", c[i] + j);
    }
    
    
    for (int rot = 0; rot < 4; rot++) {
      long long z = 0;
      for (int e = 0; e < 4; e++) {
        z = z * 1000 + c[i][(e + rot) & 3];
      }
      cr[i][rot] = z;
    }
  }
  
  long long ans = 0;
  for (int first = 0; first < n; first++) 
  {
    for (int back = first + 1; back < n; back++) 
    {
      for (int rb = 0; rb < 4; rb++) 
      {
        for (int i = 0; i < 4; i++) 
        {
          f[i] = c[first][(i + 1) & 3];
          f[i] = f[i] * 1000 + c[first][i];
          f[i] = f[i] * 1000 + c[back][(-i + rb + 1) & 3];
          f[i] = f[i] * 1000 + c[back][(-i + rb) & 3];
        }
        memset(dp, 0, sizeof(dp));
        dp[0] = 1;
        for (int i = first + 1; i < n; i++) 
        {
          if (i == back) continue;
          for (int j = 0; j < 4; j++) 
          {
            can[j] = 0;
            for (int rot = 0; rot < 4; rot++) 
            {
              if (f[j] == cr[i][rot]) 
              {
                ++can[j];
              }
            }
          }
          
          dp[15] += dp[14] * can[0];
          dp[15] += dp[13] * can[1];
          dp[15] += dp[11] * can[2];
          dp[15] += dp[7] * can[3];
          dp[14] += dp[12] * can[1];
          dp[14] += dp[10] * can[2];
          dp[14] += dp[6] * can[3];
          dp[13] += dp[12] * can[0];
          dp[13] += dp[9] * can[2];
          dp[13] += dp[5] * can[3];
          dp[12] += dp[8] * can[2];
          dp[12] += dp[4] * can[3];
          dp[11] += dp[10] * can[0];
          dp[11] += dp[9] * can[1];
          dp[11] += dp[3] * can[3];
          dp[10] += dp[8] * can[1];
          dp[10] += dp[2] * can[3];
          dp[9] += dp[8] * can[0];
          dp[9] += dp[1] * can[3];
          dp[8] += dp[0] * can[3];
          dp[7] += dp[6] * can[0];
          dp[7] += dp[5] * can[1];
          dp[7] += dp[3] * can[2];
          dp[6] += dp[4] * can[1];
          dp[6] += dp[2] * can[2];
          dp[5] += dp[4] * can[0];
          dp[5] += dp[1] * can[2];
          dp[4] += dp[0] * can[2];
          dp[3] += dp[2] * can[0];
          dp[3] += dp[1] * can[1];
          dp[2] += dp[0] * can[1];
          dp[1] += dp[0] * can[0];
        }
        ans += dp[15];
      }
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a;
    cin >> a;
    int num = 0;
    string b = "CODEFESTIVAL2016";
    for (int i = 0; i < a.size(); ++i)
    {
    	if(a[i]!=b[i]){
    		num++;
    	}
    }
    // 出力
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


############################################


# read data for n sequences.
n = stdin.readline().split()
a = int(n[0])
b = int(n[1])
c = int(n[2])
#data = [int(stdin.readline().rstrip()) for _ in range(n)]

out = int(b / a)

if out > c:
    out = c

print(out)

#end = time.time()
#print(end-start)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
	int n,i;
	long long l[88];
	l[0]=2;l[1]=1;
	cin>>n;
	for( i=2;i<=n;i++){
		l[i]=l[i-1]+l[i-2];
		
	}
	cout<<l[n]<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	//	faster;

	int h, w;
	cin >> h >> w;
	int ch, dh, cw, dw;
	cin >> ch >> dh >> cw >> dw;

	char g[h + 1][w + 1];
	int cost[h + 1][w + 1], idx[] = {-1, 1, 0, 0}, idy[] = {0, 0, -1, 1};
	bool vis[h + 1][w + 1];

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> g[i][j];
		}
	}

	mem(vis, false);
	mem(cost, -1);

	deque<pair<int, int>> q;
	q.push_back({ch, dh});
	cost[ch][dh] = 0;
	vis[ch][dh] = true;

	while (!q.empty()) {
		auto curr = q.front();
		ll curr_cost = cost[curr.first][curr.second];
		q.pop_front();
		for (int i = 0; i < 4; i++) {
			int x = curr.first + idx[i], y = curr.second + idy[i];
			if (x > 0 && y > 0 && x <= h && y <= w && g[x][y] == '.') {
				if (cost[x][y] > curr_cost || cost[x][y] == -1) {
					vis[x][y] = true;
					cost[x][y] = curr_cost;
					q.push_front({x, y});
				}
			}
		}

		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				int x = curr.first + i, y = curr.second + j;
				if (x > 0 && y > 0 && x <= h && y <= w && g[x][y] == '.') {
					if (cost[x][y] > (curr_cost + 1) || cost[x][y] == -1) {
						vis[x][y] = true;
						cost[x][y] = curr_cost + 1;
						q.push_back({x, y});
					}
				}
			}
		}
	}

	cout << cost[cw][dw] << endl;

	return 0;
}

Measured memory_bytes: 9452
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int n, cnt = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (((i + 1) % 2) && (a[i] % 2))
            cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main( void )
{
  char *s[] = { "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday", "Sunday" };
  int n[] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
  int m,d,r,i;
  while( 1 ){
    cin >> m >> d;
    if( m==0 ) break;
    r=0;
    for( i=1; i<m; i++ ) r += n[i];
    r += d;
    cout << s[(r+2)%7] << endl;
  }
  return 0;
}

Measured memory_bytes: 0