akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
def main():
    n = int(input())
    l = [list(map(int,input().split())) for i in range(n)]

    xcal = [[0]*n for i in range(1<<n)]
    ycal = [[0]*n for i in range(1<<n)]

    for i in range(1<<n):
        for j in range(n):
            xcal[i][j] = abs(l[j][0])
            ycal[i][j] = abs(l[j][1])
            for k in range(n):
                if (i>>k) & 1:
                    xcal[i][j] = min(xcal[i][j],abs(l[j][0]-l[k][0]))
                    ycal[i][j] = min(ycal[i][j],abs(l[j][1]-l[k][1]))
            xcal[i][j] *= l[j][2]
            ycal[i][j] *= l[j][2]
    ans = [float("INF")]*(n+1)

    for i in range(1<<n):
        count = 0
        for j in range(n):
            if i >> j & 1:
                count += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(n):
                if not (i>>k & 1):
                    cost += min(xcal[j][k],ycal[i-j][k])
                if cost > ans[count]:
                    break
            ans[count] = min(ans[count],cost)
            j -= 1

    for i in ans:
        print(i)
if __name__ == "__main__":
    main()

Measured memory_bytes: 88524
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );


ll a,b,x;
int main()
{
    scanf("%lld%lld%lld",&a,&b,&x);
    if(a==0)
        printf("%lld\n",b/x+1);
    else
        printf("%lld\n",b/x-(a-1)/x);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <cmath>
#include <set> 
using namespace std;

int main() {
    int A,B,K; cin >> A >> B >> K; 
    set<int> S;
    for (int i=A;i<min(B,A+K);i++){
        S.insert(i);
    }
    for (int i=max(A,B-K+1);i<=B;i++){
        S.insert(i);
    }
    for (auto itr=S.begin();itr != S.end();++itr){
        cout << *itr << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a = 4280, b, sum, ans;
	while(true)
	{
		cin >> b;
		if (b == -1) break;
		if (b <= 10)
		{
			sum = 1150;
			ans = a - sum;
			cout << ans << endl;
		}
		if (b > 10 && b <= 20)
		{
			sum = 1150 + (b-10) * 125;
			ans = a - sum;
			cout << ans << endl;
		}
		if (b > 20 && b <= 30)
		{
			sum = 1150 + 1250 + (b - 20) * 140;
			ans = a - sum;
			cout << ans << endl;
		}
		if (b > 30)
		{
			sum = 1150 + 1250 + 1400 + (b - 30) * 160;
			ans = a - sum;
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
// 0-indexed
// now node k
// child node k*2+1 and k*2+2
// parent node (k-1)/2
struct data {
  long long a;
};
const long long minint = 0;
data resetdata = {minint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, long long newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  long long pick(int a, int b, int k = 0, int l = 0,
                 int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return minint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    long long nowl, nowr, nextlr = k * 2 + 1,
                          med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return max(nowl, nowr);
  }
};

long long n;
long long h[200005] = {0};
long long a[200005] = {0};
RMQ rmq;

long long solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> h[i];
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  rmq = RMQ(n + 1);
  for(int i = 0; i < n; ++i) {
    long long now = a[i];
    now += rmq.pick(0, h[i]);
    rmq.update(h[i], now);
    ans = max(ans, now);
  }
  return ans;
}

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

using namespace std;

const int maks = 1e6+5;
int arr[maks];
int N;
int sum,ans;
int main()
{
    cin >> N;
    for(int i=1;i<=N;i++)cin >> arr[i];
    for(int i=1;i<=N;i++)
    {
      sum+= abs(arr[i]-arr[i-1]);
    }
    sum += abs(arr[N]);
    for(int i=1;i<=N;i++)
    {
        printf("%d\n", sum + abs(arr[i+1] - arr[i-1]) - abs(arr[i]- arr[i-1]) - abs(arr[i+1] - arr[i]));
    }
    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,k,m,t,j;
int main()
{
	scanf("%lld%lld", &n,&k);
	m=n%k;
	t=m;
	//printf("%d", t);
	j=k-m;
	printf("%lld", min(t,j));
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>
#include <chrono>

using namespace std;

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	while(1){
		int sum; cin >> sum;
		if (sum == 0) return 0;
		REP(i,9){
			int a; cin >> a;
			sum -= a;
		}
		cout << sum << endl;
	}

	return 0;
}



Measured memory_bytes: 2996
n = int(input())
c = [0] * (n-1)
s = [0] * (n-1)
f = [0] * (n-1)
for i in range(n-1):
    ct, st, ft = map(int, input().split())
    c[i] = ct
    s[i] = st
    f[i] = ft

for i in range(n):
    res = 0
    for j in range(i, n-1):
        if res < s[j]:
            res = s[j]
        else:
            if res % f[j] != 0:
                tmp = res % f[j]
                res += f[j] - tmp
        res += c[j]
    print(res)


Measured memory_bytes: 3188
#include <stdio.h>

int main(int argc, char const *argv[])
{
    long mtxA[101][101] = {0};
    long mtxB[101][101] = {0};

    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);

    // input matrixA[n][m]
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++)
            scanf("%ld", &mtxA[x][y]);

    // input matrixB[m][l]
    for (int i = 0; i < m; i++)
        for (int j = 0; j < l; j++)
            scanf("%ld", &mtxB[i][j]);

    long row[101] = {0};
    long col[101] = {0};
    for (int mtxArow = 0; mtxArow < n; mtxArow++)
    {
        for (int mtxAcol = 0; mtxAcol < m; mtxAcol++)
            row[mtxAcol] = mtxA[mtxArow][mtxAcol];

        for (int y = 0; y < l; y++)
        {
            for (int x = 0; x < m; x++)
                col[x] = mtxB[x][y];

            long sum = 0;
            for (int s = 0; s < m; s++)
                sum += row[s] * col[s];

            printf("%ld", sum);

            if (y != l - 1)
                printf(" ");
            else
                printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2124
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		String indata = s.next();
		int data = Integer.parseInt(indata);
		int sec = data%60;
		int min = data%3600/60;
		int hour = data/3600;
		System.out.println(hour+":"+min+":"+sec);
	}
}

Measured memory_bytes: 26184
line=input()
n,k=map(int,line.split())
sums=0
while k!=(n+2):
     if k==1:
          mini=0
     if k>=2:
          mini=(((k)*(k-1))/2)#%((10**9)+7)
     maxi=( (((n+1)*(n)) - ((n+1-k)*(n-k)) )/2  )#%((10**9)+7)
     sums+=(maxi-mini+1)
     sums=sums%((10**9)+7)
     k+=1
print(int(sums))

Measured memory_bytes: 9116
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Measured memory_bytes: 18600
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs

signed main(int argc, char* argv[]) {
    int k,x;
    cin>>k>>x;
    REP(i,x-k+1,x+k){
        cout<<i;
        if(i+1==x+k)cout<<endl;
        else cout<<" ";
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int N=(int)5005;
	static long gcd(long x,long y) {
		return y==0?x:gcd(y,x%y);
	}
    public static void main(String[] args) {  
        InputStream sys=System.in;
        InputReader in=new InputReader(sys);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        long ans=1,gc=1;
        BigInteger sum=BigInteger.valueOf(1);
        for(int i=1;i<=n;i++) {
        	long t=in.nextLong();
        	if(i==1) ans=t;
        	else {
        	   gc=gcd(ans,t);
        	   ans=ans/gc*t;
        	}
        }
      //  System.out.println(sum);
        out.println(ans);
        out.flush();
    }
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
        
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, a[114514], ans = 0; cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	if (n % 2 == 0) {
		for (int i = 0; i < n / 2 - 1; i++)ans += a[n - 1 - i] * 2; ans += a[n / 2];
		for (int i = 0; i < n / 2 - 1; i++)ans -= a[i] * 2; ans -= a[n / 2 - 1];
	}
	else {
		for (int i = 0; i < n / 2 - 1; i++)ans += a[n - 1 - i] * 2;
		for (int i = 0; i < n / 2 - 1; i++)ans -= a[i] * 2;
		int p = a[n / 2 - 1], q = a[n / 2], r = a[n / 2 + 1];
		ans += max(-2 * p + q + r, -p - q + 2 * r);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl A(n);
        vl B(n);
        vl C(n);
        rep(i,n)cin>>A[i]>>B[i]>>C[i];
        vvl DP(n+1,vl(3,0));
        rep(i,n){
            chmax(DP[1+i][0],DP[i][1]+A[i]);
            chmax(DP[1+i][0],DP[i][2]+A[i]);
            chmax(DP[1+i][1],DP[i][0]+B[i]);
            chmax(DP[1+i][1],DP[i][2]+B[i]);
            chmax(DP[1+i][2],DP[i][0]+C[i]);
            chmax(DP[1+i][2],DP[i][1]+C[i]);
        }
        cout<<max({DP[n][0],DP[n][1],DP[n][2]})<<endl;
    }

Measured memory_bytes: 11096
n = int(input())
numlist = list(map(int,input().split()))
count = 0
for i in range(n-2):
    if numlist[i+2] > numlist[i+1] > numlist[i] or numlist[i+2] < numlist[i+1] < numlist[i]:
        count += 1

print(count)

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

class Stack{
	private:
		int stack[1000];
		int pointer = 0;
	public:
		void push(int x);
		int pop();
};

void Stack::push(int x){
	stack[pointer] = x;
	pointer++;
}

int Stack::pop(){
	pointer--;
	return stack[pointer];
}

int main(){
	string input, str[300];

	getline(cin, input);

	int n = 0;
	string s = "";
	for(char c : input){
		if(c == ' '){ str[n] = s; n++; s = ""; continue; }
		s += c;
	}
	str[n] = s;

	Stack stack;

	for(int i=0; i<=n; i++){
		if(str[i] != "+" && str[i] != "-" && str[i] != "*"){
			stack.push(stoi(str[i]));
			continue;
		}

		int a = stack.pop();
		int b = stack.pop();

		if(str[i] == "+") stack.push(b + a);
		else if(str[i] == "-") stack.push(b - a);
		else if(str[i] == "*") stack.push(b * a);
	}

	cout << stack.pop() << endl;

	return 0;
}


Measured memory_bytes: 3200
n=int(input())
A=list(map(int,input().split()))
_=int(input())
Q=list(map(int,input().split()))

ansl=[0 for i in range(2002)]

for bit in range(1<<n):
    ans=0
    for v in range(n):
        if bit>>v & 1:
            ans+=A[v]
    ansl[ans]=1

for i in Q:
    print("yes" if ansl[i] else "no")
        

        
        


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << "A"
       << b[0]
       << "C" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,x;
	cin>>n>>x;
	
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}

	ll c=1,d=0;
	for(i=2;i<=n;i++){
		k=d+ar[i-1];
		if(k<=x) c++;
		d=k;
	}
	k=d+ar[i-1];
	if(k<=x) c++;
	cout<<c;
	return 0;
}


Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T& a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector< T > &v) { rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 3 "../../library/debug.hpp"

// https://codeforces.com/blog/entry/68809
void debug_print(int x) {cerr << x;}
void debug_print(long x) {cerr << x;}
void debug_print(long long x) {cerr << x;}
void debug_print(unsigned x) {cerr << x;}
void debug_print(unsigned long x) {cerr << x;}
void debug_print(unsigned long long x) {cerr << x;}
void debug_print(float x) {cerr << x;}
void debug_print(double x) {cerr << x;}
void debug_print(long double x) {cerr << x;}
void debug_print(char x) {cerr << '\'' << x << '\'';}
void debug_print(const char *x) {cerr << '\"' << x << '\"';}
void debug_print(const string &x) {cerr << '\"' << x << '\"';}
void debug_print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void debug_print(const pair<T, V> &x) {cerr << '{'; debug_print(x.first); cerr << ','; debug_print(x.second); cerr << '}';}
template<typename T> void debug_print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), debug_print(i); cerr << "}";}

void debug_print_() {cerr << "]\n";}
template <typename T, typename... V>
void debug_print_(T t, V... v) {debug_print(t); if (sizeof...(v)) cerr << ", "; debug_print_(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; debug_print_(x)
#else
#define debug(x...)
#endif
#line 3 "c.cpp"

ll ans = 0;
ll n, m, q = 50;

vl a(q);
vl b(q);
vl c(q);
vl d(q);

ll solve(vl& vec) {
  debug(vec);
    ll score = 0;
    rep(i, q) {
      if (vec[b[i]-1] - vec[a[i]-1] == c[i]) {
        score += d[i];
      }
    }
    return score;
}

void dfs(ll cn, vl&vec) {
    if (cn == n) {
      cmax(ans, solve(vec));
    } else {
      rep3(i, vec[cn-1], m+1) {
        vec[cn] = i;
        dfs(cn+1, vec);
      }
    }
}

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

  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vl vec(n);
  rep3(i, 1, m+1) {
    vec[0] = i;
    dfs(1, vec);
  }

  cout << ans << el;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins2(int, n, a, b);
    Reverse(a);
    Reverse(b);
    ll ans = 0;
    For(i, n) ans += (b[i] - ((a[i] + ans) % b[i])) % b[i];
    Cout(ans);
}


Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().split()])

if N == 1:
    print('Second')
    exit()

# np.gcdがバージョン違いでないので仕方なく
def gcd(A):
    B = A.copy()
    while len(B) > 1:
        i = np.argmin(B)
        d = B[i]
        B %= d
        B[i] = d
        B = B[B!=0]
    return B[0]

def can_win(A):
    od = (A&1).sum()
    ev = N-od
    if ev % 2 == 1:
        # 自分は偶数→奇数として、2での約分を拒否し続けられる
        return True
    if od > 1:
        # 逆の立場。永遠に2での約分を拒否されて負け
        return False
    i = np.where(A&1)[0][0]
    if A[i] == 1:
        # これも永遠に2で約分できない
        return False
    # A[i]から1を引いて、約分を試して手渡しするしかない
    A[i] -= 1
    d = gcd(A)
    A //= d
    return not(can_win(A))

answer = 'First' if can_win(A) else 'Second'
print(answer)

Measured memory_bytes: 30416
n, h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i], b[i] = map(int,input().split())
h_rest = h
b.sort()
max_a = max(a)
ans = 0
for j in range(n):
    if b[n-j-1] > max_a:
        ans+=1
        h_rest = h_rest - b[n-j-1]
        if h_rest <= 0:
            break
    else:
        break
if h_rest>0:
    ans+= h_rest//max_a
    if h_rest%max_a>0:
        ans+=1
print(ans)

Measured memory_bytes: 11312
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int x[N],n,l;
int nxt[N][20];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	scanf("%d",&l);
	int now=n;
	nxt[n][0]=n;
	for(int i=n-1;i;i--)
	{
		while(x[now]-x[i]>l)now--;
		nxt[i][0]=now;
	}
	for(int i=1;i<=19;i++)
		for(int j=1;j<=n;j++)
			nxt[j][i]=nxt[nxt[j][i-1]][i-1];
	int q,x,y,ans;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&x,&y);
		if(x>y)swap(x,y); ans=0; now=x;
		for(int i=19;i>=0;i--)
			if(nxt[now][i]<y)
				ans+=(1<<i),now=nxt[now][i];
		printf("%d\n",ans+1);
	}
	return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define PII pair<int, int>
#define mp make_pair
#define x first
#define y second

#define LL long long
#define Ldouble long double

using namespace std;

int x, y;

int main(){
  scanf("%d %d", &x, &y);
  if(x % y == 0) printf("-1\n");
  else printf("%d\n", x);
  return 0;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

dp = [50001] * (N + 1)
dp[0] = 0

for c in C:
    for n in range(c, N + 1):
        dp[n] = min(dp[n], dp[n - c] + 1)

print(dp[-1])


Measured memory_bytes: 7524
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    ll s = 0;
    FOR(a, A)
    {
        s += a;
    }
    bitset<4000001> dp;
    dp[0] = 1;
    FOR(a, A)
    {
        dp |= (dp << a);
    }
    for (ll i = (s + 1) / 2; i <= s; ++i)
    {
        if (dp[i])
        {
            OUT(i);
            return 0;
        }
    }
}

Measured memory_bytes: 5076
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define unq(v) v.erase(unique(v.begin(),v.end()),v.end());
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll;
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; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int a[10], b[10];
int ccnt[10];
int rctable[10];

int main() {
    rep(i, 3) {
        cin >> a[i] >> b[i];
    }

    rep(i, 3) {
        ccnt[a[i]]++;
        ccnt[b[i]]++;
    }

    rep(i, 1, 5) {
        rctable[ccnt[i]]++;
    }

    bool b = rctable[1] == 2 && rctable[2] == 2;
    write(b ? "YES" : "NO");
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (sc.nextInt() >= k) cnt++;
        }
        System.out.println(cnt);
    }
}



Measured memory_bytes: 48360
#include <stdio.h>

int main()
{
  int n,q,C=0,i,j;
  int S[10000],T[500];

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

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    j=0;
    while(j<n){
      if(S[j]==T[i]){
        C++;
        break;
      }
      j++;
        }
  }

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

  return 0;
}


Measured memory_bytes: 2100
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se1 second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

int main() {
    ll n;
    cin>>n;
    cout<<n*n<<endl;
    return 0;  
}

Measured memory_bytes: 256
//AtCoder Beginner Contest 109
//B - Shiritori

#include <iostream>
#include <map>

using namespace std;

int main() {

  int N;
  map<string, bool> wordList;
  map<string, bool> ::iterator it;
  bool Flag = true;
  cin >> N;
  if (N>0) {
    string s;
    cin >> s;
    wordList[s] = true;
    char lastChar = s[s.length()-1];
    for (int i=1; i<N; i++) {
      string s;
      cin >> s;
      it = wordList.find(s);
      if(it != wordList.end()) {
        Flag = false;
      } else {
        wordList[s] = true;
        char beginChar = s[0];
        if (lastChar != beginChar) {
          Flag = false;
        } else {
          lastChar = s[s.length()-1];
        }
      }
    }
   if (Flag) {
     cout << "Yes" <<endl;
   } else {
     cout << "No" <<endl;
   }
  }

  return 0;
}


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

int main() {
    char c;
    cin >> c;
    if ((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u')){
        cout << "vowel" << endl;
        return 0;
    }
    cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; ll c; cin >> n >> c;
  vector<ll> x(n);
  vector<int> v(n);
  REP(i, n) cin >> x[i] >> v[i];
  ll ans = 0, sum = 0;
  vector<ll> mx(n), mx2(n);
  for (int i = n - 1; i >= 0; --i) {
    sum += v[i];
    chmax(mx[i], sum - (c - x[i]));
    if (i + 1 < n) chmax(mx[i], mx[i + 1]);
    chmax(ans, mx[i]);
    chmax(mx2[i], sum - (c - x[i]) * 2);
    if (i + 1 < n) chmax(mx2[i], mx2[i + 1]);
  }
  sum = 0;
  REP(i, n) {
    sum += v[i];
    chmax(ans, sum - x[i]);
    chmax(ans, sum - x[i] * 2 + (i + 1 < n ? mx[i + 1] : 0));
    chmax(ans, sum - x[i] + (i + 1 < n ? mx2[i + 1] : 0));
  }
  cout << ans << '\n';
  return 0;
}


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

#include <stdio.h>

using namespace std;

typedef long long ll;

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 int MAX_N = 100;

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

    char U[MAX_N * 2 + 1];
    for (int i = 0; i < N; i++) {
        U[i * 2] = S[i];
        U[i * 2 + 1] = T[i];
    }
    U[N * 2] = 0;

    fputs(U, stdout);
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char line[80];
	int p[10][10];

	memset(p, 0, sizeof p);
	
	auto setp = [&p](int x, int y) {
			if (0 <= x && x < 10 && 0 <= y && y <10) {
				(p[x][y]) ++;
			}
		};
	
	int x, y, s;
	
	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			break;
		}
		if (sscanf(line, "%d,%d,%d", &x, &y, &s) != 3) {
			break;
		}

		if (s == 1) {
			setp(x-1, 	y);
			setp(x, 	y);
			setp(x+1, 	y);
			setp(x, 	y-1);
			setp(x, 	y+1);
			
		} else if (s == 2) {
			for (int dx = -1; dx <= 1; dx++) {
				for (int dy = -1; dy <= 1; dy++) {
					setp(x+dx, y+dy);
				}
			}
		} else {
			for (int dx = -1; dx <= 1; dx++) {
				for (int dy = -1; dy <= 1; dy++) {
					setp(x+dx, y+dy);
				}
			}
			setp(x-2, 	y);
			setp(x+2, 	y);
			setp(x, 	y-2);
			setp(x, 	y+2);
		}
	}

	int b = 0;
	int k = 0;
	for (int y = 0; y < 10; y++) {
		for (int x = 0; x < 10; x++) {
			if (p[x][y] == 0) {
				b++;
			} else if (k < p[x][y]) {
				k =  p[x][y];
			}
		}
	}

	printf("%d\n%d\n", b, k);

	return 0;
}

Measured memory_bytes: 1028
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(LL a=b;a<=c;++a)
#define rl(a,b,c) for(LL a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const LL INF=0x3f3f3f3f;
const LL MOD=1000000007;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<LL> each[100000+10];
LL n;
LL k;
LL res;
void dfs(LL now,LL la){
	LL strt=k-1-(la!=INF);
	LL SZ=(each[now].size());
	rb(i,0,SZ-1){
		if(each[now][i]==la) continue;
		res*=strt--;
		res%=MOD;
		dfs(each[now][i],now);
	}
	return ;
}
int main(){
	scanf("%lld %lld",&n,&k);
	rb(i,2,n){
		LL ai,bi;
		scanf("%lld %lld",&ai,&bi);
		each[ai].PB(bi);
		each[bi].PB(ai);
	}
	res=k;
	dfs(1,INF);
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
#define int long long
signed main(){
  int N, K;
  cin >> N >> K;
  int x[100010]; 
  int l, r;

  for(int i = 0;i < N;i++){
    cin >> x[i];
  }
  int m = 100000000000;
  for(int i = 0;i < N- K + 1;i++){
    int r = x[i];
    int l = x[i+K-1];
    if(min({abs(l) + abs(r - l),abs(r) + abs(r - l)}) < m)m = min({abs(l) + abs(r - l),abs(r) + abs(r - l)});
  }

  cout << m;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#define MAX_H 100
using namespace std;


int H, W;

string str[MAX_H];
int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++) cin >> str[i];
    for(int i = 0; i < H; i++){
        cout << str[i] << endl << str[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input().strip())
result = (1 + n) * n // 2
i = 1
while i * 3 <= n:
    result -= i * 3
    i += 1
i = 1
while i * 5 <= n:
    if (i * 5) % 3 != 0:
        result -= i * 5
    i += 1
print(result)

Measured memory_bytes: 9184
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        int num = scan.nextInt();
        int first = num / 100;
        int last = num % 100;
        
        // search
        String answer = "NA";
        if(last >= 1 && last <= 12 && first >= 1 && first <= 12){
            answer = "AMBIGUOUS";
        } else if (last >= 1 && last <= 12){
            answer = "YYMM";
        } else if (first >= 1 && first <= 12){
            answer = "MMYY";
        }

        // answer
        System.out.println(answer);


    }
}

Measured memory_bytes: 23892
#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 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 int inf = INT_MAX;
const ll INF = LLONG_MAX;
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=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
using Edge = tuple<int, int>;
vector<vector<Edge>> G;
vi C;

void dfs(int v, int pc){
    int c = 0;
    for(auto& e : G[v]){
        int nv, a; tie(nv, a) = e;
        if(C[a] >= 0) continue;
        if(c == pc) c++;
        C[a] = c++;
        dfs(nv, C[a]);
    }
}

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

    int n; cin >> n;

    G.resize(n);
    rep(i, n - 1){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(Edge(b, i));
        G[b].emplace_back(Edge(a, i));
    }

    C = vi(n, -1);
    dfs(0, -1);

    cout << *max_element(_all(C)) + 1 << endl;
    rep(i, n - 1){
        cout << C[i] + 1 << endl;
    }

    return 0;
}


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

int main() {
	int n; cin>>n;
	vector<pair<string, int> > a;
	for(int i =0; i<n; i++){
		string s; int t; cin>>s>>t;
		pair<string, int> tmp;
		tmp.first = s;
		tmp.second = t;
		a.push_back(tmp);
	}
	string x; cin>>x;
	int ans = 0;
	bool start = false;
	for(auto t: a){
		if(start){
			ans += t.second;
		}
		if(t.first == x){
			start = true;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;

int main(void){
	int l;
	while(1){
		cin >> l;
		if(l==0)break;
		int ans=-1;
		int mn=0;
		for(int i=1;i<=12;i++){
			int m,n;
			cin >> m >> n;
			mn+=m-n;
			if(ans==-1 && mn>=l)ans=i;
		}
		if(ans>=0)cout << ans << endl;
		else cout << "NA" << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt(), W = sc.nextInt();
        int[] v = new int[N + 1], w = new int[N + 1];
        long[] f = new long[W  + 1];

        for(int i = 1; i <= N; i ++){
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        for(int i = 1; i <= N; i++){
            for(int j = W; j >= v[i]; j --){
                f[j] = Math.max(f[j],f[j - v[i]] + w[i]);
            }
        }
        System.out.println(f[W]);
    }
}

Measured memory_bytes: 21972
#include <cstdio>
#include <vector>
#include <queue>

#define MAX_V 55

using namespace std;

bool bfs(int n, int u, int v, vector<int> *graph) {
  bool is_visited[MAX_V];
  for (int i = 0; i < MAX_V; i++) {
    is_visited[i] = false;
  }
  queue<int> que;

  is_visited[0] = true;
  que.push(0);
 
  while (!que.empty()) {
    int cur = que.front(); que.pop();
    
    for (int i = 0; i < graph[cur].size(); i++) {
      int next_v = graph[cur][i];

      // 辺を使わない処理
      if (cur == u && next_v == v) { continue; }
      if (cur == v && next_v == u) { continue; }

      if ( is_visited[next_v] == false ) {
        is_visited[next_v] = true;
        que.push(next_v);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if ( is_visited[i] == false ) {
      return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  int aa[MAX_V], bb[MAX_V];
  vector<int> graph[MAX_V];

  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;

    aa[i] = a; bb[i] = b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    int u = aa[i], v = bb[i];
    if ( bfs(n, u, v, graph) == false ) {
      ans++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const int MAXN=2*1e5+10;
int N,D;
struct node{
    int x,y;
}p[MAXN];

int main(){
    scanf("%d%d",&N,&D);
    for(int i=1;i<=N;i++){
        scanf("%d%d",&p[i].x,&p[i].y);
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        if(1ll*p[i].x*p[i].x+1ll*p[i].y*p[i].y<=1ll*D*D)
            ans++;
    }
    printf("%d",ans);
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

/*************************************************************************/

const int MOD = 1000000007;
const int N = 4100;

int ways[N][N];
int waysPref[N][N];

void pre(int k) {
    FOR(i,0,N-1) {
        ways[0][i] = waysPref[0][i] = waysPref[i][0] = 1;
    }
    
    FOR(j,1,N-1) FOR(i,1,N-1) {
        ways[i][j] = (waysPref[i][j-1] + MOD - (i >= k ? waysPref[i-k][j-1] : 0)) % MOD;
        waysPref[i][j] = (waysPref[i-1][j] + ways[i][j]) % MOD;
    }
}

void add(int &x, int val) {
    x += val;
    if (x >= MOD) x -= MOD;
}

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n, m, k;
    cin >> n >> m >> k;
    
    pre(k);
    
    int ans = 0;
    
    FOR(len,1,n+m-1) FOR(sum,0,n) {
        int lb = len * (k - 1) - (m - 1);
        if (sum < lb) continue;
        if (sum % (k-1) != n % (k-1)) continue;
        
        add(ans, ways[sum][len]);
        add(ans, MOD - ways[sum][len - 1]);
    }
    
    cout << ans;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 131584