akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int X = in.nextInt();
            int Y = in.nextInt();
            int Z = in.nextInt();
            int temp = X;
            X = Y;
            Y = temp;
            temp = X;
            X = Z;
            Z = temp;
            out.printf("%d %d %d\n", X, Y, Z);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  char q,w,e;
  q = a[0]; w = b[0]; e = c[0];
  q -= 32; w -= 32; e -= 32;
  cout << q << w << e;
}

Measured memory_bytes: 3608
A, B, C = map(int, input().split())

num0 = [A, B, C]
max_num = max([A, B, C])
# res = 0
diff = [max_num - A, max_num - B, max_num - C]

while True:
    # div_c = 0
    # mod_c = 0
    res = 0
    for i in range(3):
        if diff[i] != 0:
            mod = diff[i] % 2
            div = int(diff[i] / 2)
            res += div
            res += mod / 2
            num0[i] += (2 * div + mod)
    # res = div_c + mod_c
    integer = int(res)

    if res - integer == 0 and num0[0] == num0[1] and num0[1] == num0[2]:
        break

    max_num += 1
    diff = [max_num - A, max_num - B, max_num - C]
    num0 = [A, B, C]

print(int(res))

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll n,m,k,ans=0;
    cin>>n>>m>>k;
    ll a[n+1]={0},b[m+1]={0};
    for(ll i=1;i<=n;i++) cin>>a[i],a[i]+=a[i-1];
    for(ll i=1;i<=m;i++) cin>>b[i],b[i]+=b[i-1];
    for(ll i=0;i<=n;i++) if(k>=a[i]) ans=max(ans,upper_bound(b+1,b+1+m,k-a[i])-b-1+i);
    cout<<ans;
}

Measured memory_bytes: 6764
# coding: utf-8
# Your code here!

N,M,X=map(int,input().split())
Mlist=list(map(int,input().split()))
Nlist=[0]*N
for a in Mlist:
  Nlist[a]=1

a=sum(Nlist[X:])
b=sum(Nlist[:X])
print(min([a,b]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

bool dp[MAX_N];
int a[MAX_N];
ll sm[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    dp[0] = true;
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    rep(i,n){
        sm[i+1] = sm[i] + a[n-1-i];
    }
    int ans = 0;
    rep(i,n){
        bool flag = false;
        if(K-sm[n-i]+a[i] > 0){
            srep(j,max(0LL, K-sm[n-i]),K-sm[n-i]+a[i]){
                flag |= dp[j];
            }
            ans += !flag;
        }
        rrep(j,K-a[i]){
            dp[j+a[i]] |= dp[j];
        }
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n){
        if (i%2 == 0) continue;
        int div = 0;
        rep(j, i){
            if (i%j == 0) div ++;
        }
        if (div == 8) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

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

 
int main(){

    int t , n;
    cin >> t >> n;

    int a = n - 2 * t , b = 4 * t - n;

    if( a >= 0 && a % 2 == 0 && b >= 0 && b % 2 == 0 ) cout << "Yes";
    else cout << "No";

    return 0;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int left = A + B;
    int right = C + D;
    if (left > right) {
        cout << "Left" << endl;
    } else if (left == right) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static int[] a=new int[6];
	private static int questionLength;
	public static void main(String[] args){
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
		}
		questionLength=sc.nextInt();
		for(int i=0;i<questionLength;i++){
			int a=sc.nextInt();
			int b=sc.nextInt();
			check(a,b);
		}
	}
	private static void check(int u,int f){
		if((u==a[1]&&f==a[2])||(u==a[2]&&f==a[4])||(u==a[3]&&f==a[1])||(u==a[4]&&f==a[3])){
			System.out.println(a[0]);
		}
		if((u==a[0]&&f==a[3])||(u==a[2]&&f==a[0])||(u==a[3]&&f==a[5])||(u==a[5]&&f==a[2])){
			System.out.println(a[1]);
		}
		if((u==a[0]&&f==a[1])||(u==a[1]&&f==a[5])||(u==a[4]&&f==a[0])||(u==a[5]&&f==a[4])){
			System.out.println(a[2]);
		}
		if((u==a[0]&&f==a[4])||(u==a[1]&&f==a[0])||(u==a[4]&&f==a[5])||(u==a[5]&&f==a[1])){
			System.out.println(a[3]);
		}
		if((u==a[0]&&f==a[2])||(u==a[2]&&f==a[5])||(u==a[3]&&f==a[0])||(u==a[5]&&f==a[3])){
			System.out.println(a[4]);
		}
		if((u==a[1]&&f==a[3])||(u==a[2]&&f==a[1])||(u==a[3]&&f==a[4])||(u==a[4]&&f==a[2])){
			System.out.println(a[5]);
		}
	}
}

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

int main(){
    long long n,a[10001],i;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    long long max = a[0],min = a[0],sum = 0;
    for(i=0;i<n;i++){
        if(max<a[i]){
            max = a[i];
        }
        if(min>a[i]){
            min = a[i];
        }
        sum = sum + a[i];
    }
    cout << min <<" "<< max <<" "<< sum << endl;
    return 0;
}


Measured memory_bytes: 3156
N, K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

l = Array.new(N)
r = Array.new(N)

for i in 0...N
    l[i] = 0
    r[i] = 0
    for j in 0...N
        next if i == j
        next if a[i] <= a[j]

        if i > j
            l[i] += 1
        elsif i < j
            r[i] += 1
        end
    end
end

ans = 0
for i in 0...N
    ans += r[i] * K 
    ans %= 1000000007
    ans += (r[i] + l[i]) * (K * (K-1) / 2)
    ans %= 1000000007
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, i;
    cin>>n;
    string s;
    map < string , ll > m;
    ll ans = 0;
    FOR0(i, n)
    {
        s.clear();
        cin>>s;
        sort(s.begin(), s.end());
        m[s]++;
    }
    map < string , ll >::iterator it;
    it = m.begin();
    while(it!=m.end())
    {
        ans += (it->ss)*(it->ss-1)/2;
        it++;
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 11264
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

using ll = long long;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    int X, K;
    cin >> K >> X;

    int min, max;
    min = X - K + 1;
    max = X + K - 1;
    if (min < -1000000) {
        min = -1000000;
    }
    if (max > 1000000) {
        max = 1000000;
    }

    for(int i = min; i <= max; i++) {
        cout << i << " ";
    }
    cout << "\n";
    

    return 0;
}

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


int main()
{
	int a, b, c = 0; cin >> a >> b;
	for(int i = a; i <= b; ++i)
		if (i/10000 == i%10 && i/1000%10 == i%100/10)
			c++;
	cout << c << endl;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vll H(n), P(n);
    using HP = tuple<ll, int>; // h+p
    vector<HP> tbl(n);

    rep(i, n){
        cin >> H[i] >> P[i];
        tbl[i] = HP(H[i] + P[i], i);
    }
    sort(_all(tbl));

    vector<vll> dp(n + 1, vll(n + 1, inf));
    dp[0][0] = 0;

    rep(i, n){
        int idx = get<1>(tbl[i]);
        ll h = H[idx], p = P[idx];

        rep(j, n){
            ll cur = dp[i][j];
            if(cur == inf) continue;

            // nop
            chmin(dp[i + 1][j], cur);

            // tumu
            if(cur <= h){
                chmin(dp[i + 1][j + 1], cur + p);
            }
        }
    }

    int res = 0;
    rep(j, n+1){
        if(dp[n][j] != inf) res = j;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 196096
#include <iostream>
using namespace std;
int main(void){
    
  int N;
  int pow0, pow1, pow2, pow3, pow4, pow5, pow6, pow7, pow8, pow9;
  int sum;
  
  cin >> N;
  
  pow0 = N % 10;
  pow1 = N / 10 % 10;
  pow2 = N / 100 % 10;
  pow3 = N / 1000 % 10;
  pow4 = N / 10000 % 10;
  pow5 = N / 100000 % 10;
  pow6 = N / 1000000 % 10;
  pow7 = N / 10000000 % 10;
  pow8 = N / 100000000 % 10;
  pow9 = N / 1000000000 % 10;
  
  sum = pow0 + pow1 + pow2 + pow3 + pow4 + pow5 + pow6 + pow7 + pow8 + pow9;
  
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
    
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 
c = list(map(int, input().split())) 

manzoku = 0
for i in range(n):
    manzoku += b[a[i]-1]
    #print(b[a[i]-1])
    
    if( i > 0):
        if( a[i-1]+1 == a[i] ):
            manzoku += c[a[i-1]-1]
            #print('+'+str(c[a[i-1]-1]))
#print('')
print(manzoku)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
 
#define vi vector<int>
#define p pair<int, int>
#define REP(i, n) for(int i = 0;i < n; i++)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define BR cout << endl;
#define INF  2000000000
 
int a[6], sum = 0;
 
int main(){
    long long int a = 2, b = 1, c = 0, n;
    cin >> n;
    if(n == 0){
        cout << 2 << endl;
        return 0;
    }
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    REP(i, n - 1){
        c = a + b;
        a = b;
        b = c;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
struct edge{
    int to;
    int cost;
};
long long INF =1e18;
int V, E, r;
typedef pair<long long, long long> P;//一つ目は距離、二つ目は頂点番号
vector<vector<edge>> G;
vector<long long> dis;
vector<int> used;
void dijkstra(int r){
    priority_queue<P, vector<P>, greater<P>> q;
    dis[r] = 0;
    q.push(P(0, r));
    while(!q.empty()){
        P v = q.top();
        q.pop();
        if(dis[v.second] < v.first) continue;
        for(edge e: G[v.second]){
            if(dis[e.to] > dis[v.second] + e.cost){
                dis[e.to] = dis[v.second] + e.cost;
                q.push(P(dis[e.to], e.to));
            }
        }
    }
    for(int i = 0; i < V; i++){
        if(dis[i] == INF) cout << "INF" << endl;
        else cout << dis[i] << endl;
    }
}
int main(){
    cin >> V >> E >> r;
    G.resize(V);
    dis.resize(V, INF);
    used.resize(V, 0);
    for(int i = 0; i < E; i++){
        long long s, t, d;
        cin >> s >> t >> d;
        edge e;
        e.to = t;
        e.cost = d;
        G[s].push_back(e);
    }
    dijkstra(r);
}


Measured memory_bytes: 14732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define ppb pop_back
#define cs(n) cout<<n<<" "
#define cn(n) cout<<n<<"\n"
#define rep(i,j,k) for(int i=j;i<k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
		return bin((a * a) % mod , b / 2) % mod;
	return ((a % mod) * (bin((a * a) % mod , b / 2) % mod)) % mod;
}
void solve()
{
	int n;
	cin >> n;
	map<int , vector<int> >mp;
	bool visited[1000005] = {0};
	int ma = 0;
	rep(i, 0, n) {
		int a;
		cin >> a;
		mp[a].push_back(i + 1);
		ma = max(ma, a);
		visited[a] = true;
	}
	int ans = 0;
	auto it = mp.begin();
	for ( ; it != mp.end(); it++) {
		if ((*it).second.size() == 1 && visited[(*it).first] == true) {
			ans++;
		}
		int a = (*it).first;
		for (int i = a; i <= ma; i += a) {
			visited[i] = false;
		}
	}
	cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	fastio;
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 26352
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()


int main(){
  ll H,W,Ch,Dh,Cw,Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  vector<string> S(H);
  rep(i,H){
    cin >> S.at(i);
  }
  vector<int> h,w;
  h={1,0,-1,0,1,1,-1,-1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};
  w={0,1,0,-1,1,-1,1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1};
  queue<T> A,B;
  mat dp(H,vec(W,INF));
  dp.at(Ch).at(Cw)=0;
  A.push(T(0,Ch,Cw));
  while(!A.empty()||!B.empty()){
    ll x,y,z,k=0;
    if(!A.empty()){
      tie(x, y, z) = A.front();
      A.pop();
    }else{
      tie(x, y, z) = B.front();
      B.pop();
    }
    rep(i,24){
      if(y+h.at(i)>=0&&y+h.at(i)<=H-1&&z+w.at(i)>=0&&z+w.at(i)<=W-1){
        if(S.at(y+(ll)h.at(i)).at(z+(ll)w.at(i))=='.'){
        if(i<4){
          if(dp.at(y+h.at(i)).at(z+w.at(i))>dp.at(y).at(z)){
            dp.at(y+h.at(i)).at(z+w.at(i))=dp.at(y).at(z);
            A.push(T(dp.at(y+h.at(i)).at(z+w.at(i)),y+h.at(i),z+w.at(i)));
            k++;
            if(Dh==y+h.at(i)&&Dw==z+w.at(i)){
              cout << dp.at(Dh).at(Dw) << endl;
              return 0;
            }
          }
        }else{
          if(dp.at(y+h.at(i)).at(z+w.at(i))>dp.at(y).at(z)+1){
            dp.at(y+h.at(i)).at(z+w.at(i))=dp.at(y).at(z)+1;
            B.push(T(dp.at(y+h.at(i)).at(z+w.at(i)),y+h.at(i),z+w.at(i)));
          }
        }
      }
      }
    }
  }
  if(dp.at(Dh).at(Dw)==INF){
    cout << -1 << endl;
  }else{
    cout << dp.at(Dh).at(Dw) << endl;
  }
    
}
          
          
        

Measured memory_bytes: 13644
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
   ll n,x,y;
   cin>>n>>x>>y;
   ll ans[n]={0};
   for(ll i=1;i<=n-1;i++)
   {
       for(ll j=i+1;j<=n;j++)
       {
          ll k=abs(i-x);
          ll k1=abs(j-y);
          ll r=k+k1+1;
          ll m=j-i;
          if(m<r)
          ans[m]++;
          else 
          ans[r]++;
       }
   }
   for(ll i=1;i<=n-1;i++)
   cout<<ans[i]<<endl;
   return 0;
}

Measured memory_bytes: 256
import numpy as np

a = list(map(int, input().split()))
b = list(map(int, input().split()))

K = a[0]
N = a[1]

c = np.zeros(N)

for i in range(N-1):
  c[i] = abs(b[i+1] - b[i])
  
c[N-1] = abs(K - b[N-1] + b[0])

r = max(c)

print(int(K-r))

Measured memory_bytes: 39512
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

vector<int> g[1<<20];
int H[1<<20], N, M;

int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);

  cin>>N>>M;
  rep(i,N) cin>>H[i];
  rep(i,M) {
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  int ans = 0;
  rep(i, N) {
    int good = 1;
    for(int x: g[i]) {
      if(H[x] >= H[i]) good=0;
    }
    ans += good;
  }
  cout<<ans;

  return 0;
}


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

int main(){
  int N,A,B,ans,tmp;
  cin >> N >> A >> B;
  int sum = 0;

  for(int i=1;i<=N;++i){
    ans = 0;
    tmp = i;
    while(tmp > 0){
      ans += tmp % 10;
      tmp = tmp / 10;
    }
    if(A<=ans && ans<=B){sum += i;}
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
class Info:
    def __init__(self, A):
        self.A = A
        self.info = [[0] * 2 for i in range(A)]
        for i in range(A):
            x, y = map(int, input().split())
            self.info[i][0] = x - 1
            self.info[i][1] = y

def solve():
    N = int(input())
    infos = []
    for i in range(N):
        A = int(input())
        infos.append(Info(A))
    
    mx = 0
    for i in range(2 ** N):
        isKind = []
        for j in range(N):
            if (i >> j) & 1:
                isKind.append(1)
            else:
                isKind.append(0)
        
        isConsistent = True
        p = 0
        for info in infos:
            for j in range(info.A):
                if isKind[p]==1 and isKind[info.info[j][0]] != info.info[j][1]:
                    isConsistent = False
            p += 1
        
        if isConsistent:
            Nkind = sum(isKind)
            mx  = max(mx, Nkind)


    print(mx)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include <math.h>
using namespace std;

int main() {
	long long n;
	cin >> n;
	double t1 = 0,t2=0;
	double k = 0;
	
	double start_time = 0;
	long long finish_time = 0;
	double remain = 0;
	for (int i = 0; i < 5; i++)
	{
		start_time = i;
		cin >> k;
		
		remain = n-fabs((-start_time+finish_time)*k);
		//cout << remain << endl;
		if (remain < 0)
		{
			finish_time++;
		}
		else {
			finish_time += ceil(remain / k);
		}
		//cout <<"i="<<i<<" remain: "<<remain<<" time = "<< finish_time << endl;
		
	}
	cout << finish_time;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=10005,mod=998244353;
int f[maxn][maxn];
int fac[maxn<<1],facinv[maxn<<1];
inline int powmod(int a,int b){
	int res=1;
	for(;b;b>>=1){
		if(b&1)res=1ll*res*a%mod;a=1ll*a*a%mod;
	}return res;
}
inline void prprpr(){
	fac[0]=1;
	rep(i,1,20000)fac[i]=1ll*fac[i-1]*i%mod;
	facinv[20000]=powmod(fac[20000],mod-2);
	per(i,19999,0)facinv[i]=1ll*facinv[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	return 1ll*fac[n]*facinv[m]%mod*facinv[n-m]%mod;
}
char s1[maxn],s2[maxn];
int len,n,m;
int main(){
	prprpr();
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	len=strlen(s1+1);
	rep(i,1,len)n+=s1[i]=='1'&&s2[i]=='1',m+=s1[i]=='1'&&s2[i]=='0';
	f[0][0]=1;
	rep(i,0,n)rep(j,0,m){
		if(i==0&&j==0)continue;
		f[i][j]=(1ll*i*j*(i?f[i-1][j]:0)+1ll*j*j*(j?f[i][j-1]:0))%mod;
	}
	int ans=0;
	rep(k,0,n)ans=(ans+1ll*C(n,k)*fac[n-k]%mod*fac[n-k]%mod*f[k][m]%mod*C(n+m,k+m))%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 389760
n, q = map(int, input().split())
S = input()

flag = False

ATList = [0]*n

for i in range(n):
    if (S[i] == "A"):
        ATList[i] = ATList[i-1]
        flag = True
    elif (S[i] == "C") and flag:
        ATList[i] = ATList[i-1] + 1
        flag = False
    else:
        ATList[i] = ATList[i-1]
        flag = False

for i in range(q):
    l,r = map(int, input().split())
    print(ATList[r-1]-ATList[l-1])


Measured memory_bytes: 6084
from math import gcd
from functools import reduce
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))


def sieve(n):
    n += 1
    res = [i for i in range(n)]
    for p in range(2, int(n**.5)+1):
        if res[p] < p:
            continue
        for q in range(p**2, n, p):
            if res[q] == q:
                res[q] = p
    return res


U = 10**6
min_factor = sieve(U)


def prime_factor(n):
    res = defaultdict(int)
    while 1 < n:
        res[min_factor[n]] += 1
        n //= min_factor[n]
    return res


# 10**6以下の素数しかでてこないから、鳩の巣原理的に考えて間に合う
facts = set()
for a in A:
    for k, v in prime_factor(a).items():
        if k in facts:
            if reduce(gcd, A) == 1:
                print('setwise coprime')
            else:
                print('not coprime')
            break
        facts.add(k)
    else:
        continue
    break
else:
    print('pairwise coprime')


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

int main(){
    string S,T;
    cin>>S>>T;

    if(S.size()<T.size()) cout<<"UNRESTORABLE"<<endl;

    

    else{
        vector<string> ans;
        int N=S.size()-T.size();
        for(int i=N;i>=0;i--){
            bool okay=true;
            for(int j=0;j<T.size();j++){
                if(S.at(i+j)!=T.at(j) && S.at(i+j)!='?') okay=false;
            }

            
            if(okay) {
                string P=S;
                for(int k=0;k<S.size();k++){
                    if(P.at(k)=='?'){
                        if(k<i || i+T.size()<=k) P.at(k)='a';
                        else P.at(k)=T.at(k-i);
                    }
                }
                ans.push_back(P);
            }
        }

        if(ans.size()==0) cout<<"UNRESTORABLE"<<endl;
        else{
            sort(ans.begin(),ans.end());
            cout<<ans.at(0)<<endl;
        }
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt(); // int Dを受け取る
		int T = sc.nextInt(); // int Tを受け取る
		int S = sc.nextInt(); // int Sを受け取る
		sc.close(); // 標準入力を終了

		// S * T >= D なら、時間内に目的地に到着する
		if(S * T >= D) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}


	}

}

Measured memory_bytes: 35796
#include <stdio.h>

int main(void){
    int a,b,c,d,e;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    if(c<=0||d<=0) printf("No\n");
	 else{
	      if(c<=a-e&&d<=b-e) printf("Yes\n");
      else{
        printf("No\n");
       }
      }
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 1000000007;

vector <int> price;
int32_t main()
{
    int n, k; cin >> n >> k;
    for (int i = 0; i<n; i++)
    {
        int x; cin >> x;
        price.push_back(x);
    }
    sort(all(price));
    int ans = 0;
    for (int i = 0; i<k; i++) 
        ans += price[i];
    cout << ans;
}

Measured memory_bytes: 3628
from itertools import product


def rotate(a):
    return [[a[y][x] for y in range(len(a)-1, -1, -1)] for x in range(len(a))]


while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    picture = [list(map(int, input().split())) for _ in [0]*n]
    piece = [list(map(int, input().split())) for _ in [0]*m]
    ans = []

    for i in range(4):
        for y, x in product(range(m), repeat=2):
            if piece[y][x] != -1:
                dx, dy = x+1, y+1
                break

        for (from_y, to_y), (from_x, to_x) in product(zip(range(n), range(m, n+1)), repeat=2):
            for j, y in zip(range(m), range(from_y, to_y)):
                if not all(v1 == -1 or v1 == v2 for v1, v2 in zip(piece[j], picture[y][from_x:to_x])):
                    break
            else:
                ans.append((from_y+dy, from_x+dx))

        piece = rotate(piece)

    ans.sort()
    print(" ".join(map(str, ans[0][::-1])) if ans else "NA")


Measured memory_bytes: 6328
/* Stay hungry, stay foolish. */
/* Copyright by HenryLi */
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<stack>
#include<ctime>
#include<cmath>
#include<cctype>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
template <class _T> inline void read(_T &_x) {
	int _t; bool _flag=false;
	while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;
	if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';
	while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';
	if(_flag) _x=-_x;
}
typedef long long LL;
int n, m, d;
int main() {
	//freopen("fuck.in","r",stdin);
	//freopen("fuck.out","w",stdout);
	read(n), read(m), read(d);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			int x = (m + i + j) / d % 2, y = (m + i - j) / d % 2;
			printf("%c", "RGBY"[2 * x + y]);
		}
		puts("");
	}
	return 0;
}


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

const int mod = 998244353;
map<string, int> mp;

void conj(string& s, const string& t) {
  for (int i = 0; i < s.size(); ++i) {
    if (t[i] == '0') {
      s[i] = '0';
    }
  }
}

long rec(const string& s) {
  int n = s.size();
  if (n == 0) return 1;
  if (n == 1) return s[0] - '0' + 1;
  if (mp.count(s)) return mp[s];
  int mid = n / 2;
  long sum = rec(s.substr(0, mid)) * rec(s.substr(mid)) % mod;
  
  for (int k = 1; k <= n / 2; ++k) {
    for (int l = 0; l < mid; ++l) {
      if (l + 2 * k > n) continue;
      string t = s.substr(l, k);
      for (int r = l + 2 * k; r <= n; r += k) {
        conj(t, s.substr(r - k, k));
        if (r <= mid) continue;
        sum += rec(s.substr(0, l)) * rec(t) % mod * rec(s.substr(r)) % mod;
        if (sum >= mod) sum -= mod;
      }
    }
  }
  return mp[s] = sum;
}

int main() {
  string s;
  cin >> s;
  cout << rec(s) << endl;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge
#define   int long long

int x[110000],y[110000];
int change[50000];

signed  main(){
  int n,w,h;
  cin>>n>>w>>h;
  int c=0,ans=0;
  int stat=0;
  int am=1;
  lp(i,n){
    int xx,yy;
    cin>>xx>>yy;
    while(change[x[xx]]!=0) x[xx]=change[x[xx]];
    while(change[y[yy]]!=0) y[yy]=change[y[yy]];
    if(xx==1||yy==1||xx==w||yy==h) stat=1;
    if(x[xx]==0&&y[yy]==0){
      c++;
      x[xx]=am;
      y[yy]=am;
      am++;
    }
    else{
      ans++;
      if(x[xx]==0&&y[yy]!=0) x[xx]=y[yy];
      else if(y[yy]==0&&x[xx]!=0) y[yy]=x[xx];
      else if(x[xx]==y[yy]) continue;
      else{
	int a=x[xx],b=y[yy];
	if(a>b) swap(a,b);
	if(change[a]==b)1;
	else{
	  c--;
	  change[a]=b;
	  ans++;
	}
      }
    }/*
    cout<<" ";
    lp(i,5){
      cout<<x[i+1];
    }
    cout<<endl;
    lp(j,5){
      cout<<y[j+1]<<endl;
      }*/
    // cout<<c<<" "<<ans<<" "<<stat<<endl;
  }
  /*cout<<" ";
  lp(i,5){
    cout<<x[i+1];
  }
  cout<<endl;
  lp(j,5){
    cout<<y[j+1]<<endl;
    }*/
  if(c==1) 1;
  else{
    ans+=c*2-1-stat;
  }
  cout<<ans<<endl;
  return 0;
}




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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

string a = "CODEFESTIVAL2016";

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string b;
	cin >> b;
	int cnt = 0;
	REP(i, 0, 16) cnt += (b[i] != a[i]);
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl H(N); rep(i, N) cin >> H[i];
    bool ok = true;
    ll now = H[0];
    rep(i, N-1){
        if(H[i]>H[i+1]){
            if(now <= H[i]-1){
                now = H[i]-1;
            }
        }
        if(now > H[i+1]){
            ok = false; break;
        }
    }
    cout << (ok ? "Yes" : "No") << endstr;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(int argc, const char * argv[]) {
 
 
 
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    /////////////////////
    // Write code below /
    /////////////////////
    
    int N,R;
  
  	cin>>N>>R;
  
  	if(N < 10){
      R = R + 100 * (10 - N);
    }
  
  	cout<<R<<endl;
 
	
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define MAX 100
using namespace std;

int N, v[MAX];
double ans;

int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> v[i];
    sort(v, v+N);
    ans = v[0];
    for(int i=1; i<N; i++){
        ans = (ans + v[i])/2;
    }
    cout << ans << endl;

}

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

 int main(void){

  long long w,h,x,y;
  cin>>w>>h>>x>>y;

  printf("%.08LF ",(long double)w*h/2.0);

  if(2*x == w && 2*y == h)
    printf("1\n");
    else
    printf("0\n");


 return 0;
 }


Measured memory_bytes: 3704
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<u32> = read_as_vec();
    let (n, x) = (line[0], line[1]);

    let ell: Vec<u32> = read_as_vec();

    let mut height = 0;
    let mut ans = 1;
    for elem in ell{
        height += elem;
        if height <= x{
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

ll ans,n,m,Q,a[maxn],b[maxn],c[maxn],q[maxn],x[maxn];

inline void jud()
{
	ll tmp=0;
	for(int i=1;i<=Q;i++) if(x[b[i]]-x[a[i]]==c[i]) tmp+=q[i];
	ans=max(ans,tmp);
}

inline void dfs(int u)
{
	if(u==n+1) {jud(); return;}
	for(int i=x[u-1];i<=m;i++)
	{
		x[u]=i;
		dfs(u+1);
	}
}

int main()
{
	cin>>n>>m>>Q;
	for(int i=1;i<=Q;i++) cin>>a[i]>>b[i]>>c[i]>>q[i]; x[0]=1;
	dfs(1); cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	map<int, int> a, b;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if (i % 2 == 0)
		{
			a[x]++;
		}
		else
		{
			b[x]++;
		}
	}

	int m = n / 2;

	vector<pair<int, int>> ap;
	for (map<int, int>::iterator it = a.begin(); it != a.end(); it++)
	{
		pair<int, int> i = *it;
		ap.push_back(make_pair(i.second, i.first));
	}

	sort(ap.begin(), ap.end());
	reverse(ap.begin(), ap.end());

	vector<pair<int, int>> bp;
	for (map<int, int>::iterator it = b.begin(); it != b.end(); it++)
	{
		pair<int, int> i = *it;
		bp.push_back(make_pair(i.second, i.first));
	}

	sort(bp.begin(), bp.end());
	reverse(bp.begin(), bp.end());

	int ans = 0;
	if (a.size() == 1 && b.size() == 1)
	{
		if (ap.front().second == bp.front().second)
		{
			ans = m;
		}
		else
		{
			ans = 0;
		}
	}
	else
	{
		if (ap.front().first == bp.front().first)
		{
			if (ap.front().second == bp.front().second)
			{
				if (ap.at(1).first > bp.at(1).first)
				{
					ans = (m - bp.front().first) + (m - ap.at(1).first);
				}
				else
				{
					ans = (m - ap.front().first) + (m - bp.at(1).first);
				}
			}
			else
			{
				ans = 2 * (m - ap.front().first);
			}
		}
		else
		{
			if (ap.front().first > bp.front().first)
			{
				ans = m - bp.front().first;
			}
			else
			{
				ans = m - ap.front().first;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 6136
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int mod=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

const int maxn=303;

int n,m,l,a,b,c;
ll d[maxn][maxn],tt[maxn][maxn];
void floyd(ll dp[303][303]){rep(k,1,n+1)rep(i,1,n+1)rep(j,1,n+1)dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);}

int main(){
	int n,t;
	int dp[M];
	fill(dp,dp+M,0);
	pair<int,int> p[M];
	cin>>n>>t;
	rep(i,0,n)cin>>p[i].first>>p[i].second;
	sort(p,p+n);

	rep(i,0,n){
		int a,b;
		a=p[i].first,b=p[i].second;
		for(int j=t-1;j>=0;j--)
			dp[j+a]=max(dp[j+a],dp[j]+b);
	}
	int ans=0;
	rep(i,0,6001)ans=max(ans,dp[i]);
	print(ans);
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
  print(0)
elif sum(A) // N > 2 and N > 60:
  print(-1)
else:
  ans = 1
  for i in A:
    ans *= i
  print(ans if ans <= 10 ** 18 else -1)

Measured memory_bytes: 21572
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    ll dp[101][100010];
    int main(){
        ll n,w;
        cin>>n>>w;
       ll val[n+2],wg[n+2];
       
        for(int i=0;i<n;i++)
        cin>>wg[i]>>val[i];
        
        for(int i=0;i<=w;i++)
        dp[0][i]=0;
        for(int i=0;i<=n;i++)
        dp[i][0]=0;
        
        for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
               ll w=wg[i-1];
               ll v=val[i-1];
               if(w<=j)
               dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
               else
               {
                   dp[i][j]=dp[i-1][j];
               }
               
            }
        }
      
        cout<<dp[n][w]<<endl;
     
        
    }

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

int A,B,C;

int main(){
    scanf("%d %d %d", &A, &B, &C);
    if (B + C <= A){
        printf("%d\n", 0);
    }else{
        printf("%d\n", B + C - A);
    }
    return 0;
}

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

#define rep(i, a, n) for(int i=(a);i < (n);i++)
#define REP(i, n) rep(i,0,n)
#define all(e) e.begin(),e.end()


#ifdef LOCAL
#define show(x) cerr<<__LINE__" : "<<#x<<" = "<<(x)<<endl
#else
#define show(x) true
#endif

using namespace std;
using ll = long long;
template<class T>
using V=vector<T>;

template<class T, class U>
void chmin(T &t, const U u) { if (t > u) t = u; }

template<class T, class U>
void chmax(T &t, const U u) { if (t < u) t = u; }

const int INF = (1 << 30) - 1;
const ll INFL = (ll) 5e15;
const int MOD = 1e9 + 7;


struct Solve {
    int N;
    vector<ll> x, y;
    vector<ll> a, b;
    ll kl = INFL, kr = -INFL;
    ll kd = INFL, ku = -INFL;

    int calc(int x1, int y1, int x2, int y2) {
//        cerr << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
        if (x1 == x2) return 0;
        if (x1 > x2) return -calc(x2, y2, x1, y1);
        if (x1 < kl && kl < x2) {
            ll left = calc(x1, y1, kl, y1);
            ll right = calc(kl, y2, x2, y2);
            return left + right;
        }

        if (x1 < kr && kr < x2) {
            ll left = calc(x1, y1, kr, y1);
            ll right = calc(kr, y2, x2, y2);
            return left + right;
        }

        if (kl <= x1 && x2 <= kr) {
            //教会内
            if (y1 >= ku) {
                //上側にいる
                return (y1 - (ku - kd)) * (x2 - x1);
            } else if (y1 <= kd) {
                //下側にいる
                return y1 * (x2 - x1);
            } else {
                //内側にいる
                return kd * (x2 - x1);

            }
        }

        if (x2 <= kl || kr <= x1) {
            //今日海外
            return y1 * (x2 - x1);
        }

        assert(false);
    }

    bool solve() {
        cin >> N;
        if (N == 0) return false;

        x.resize(N);
        y.resize(N);
        a.resize(4);
        b.resize(4);
        for (int i = 0; i < N; ++i) {
            cin >> x[i] >> y[i];
        }
        for (int i = 0; i < 4; ++i) {
            cin >> a[i] >> b[i];
        }
        x.push_back(x[0]);
        y.push_back(y[0]);

        for (int i = 0; i < 4; ++i) {
            chmin(kl, a[i]);
            chmax(kr, a[i]);
            chmin(kd, b[i]);
            chmax(ku, b[i]);
        }
//        if (kl > kr) swap(kl, kr);
//        cerr << kl << " " << kr << " " << kd << " " << ku << endl;

        ll ans = 0ll;
        for (int i = 0; i < N; ++i) {
            ll tmp = calc(x[i], y[i], x[i + 1], y[i + 1]);
//            cerr << tmp << endl;
            ans += tmp;
        }

        cout << -ans << endl;
        return true;
    }
};

int main() {

    while (Solve().solve());

    return 0;
}


Measured memory_bytes: 3160
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

count = [0] * 26
w = input().rstrip()
for ch in w:
    count[ord(ch) - ord("a")] += 1
ok = True
for item in count:
    if item % 2 == 1:
        ok = False
print("Yes" if ok else "No")

Measured memory_bytes: 3060