akhauriyash/Code-Regression huggingface dataset:
n = int(input())

red = []
blue = []
ed = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))


node = n*2
    
for i in range(n):
    for j in range(n):
        if red[i][0]<blue[j][0] and red[i][1]<blue[j][1]:
            ed.append([i,j+n])
            
import random
import numpy as np


edge = ed

def tutte():
    tut = np.zeros((node,node))
    for e in edge:
        x = random.random()
        tut[e[0]][e[1]]=x
        tut[e[1]][e[0]]=-x
    return tut



times = 11
rank = []
for i in range(times):
    rank.append(np.linalg.matrix_rank(tutte()))
rank.sort()
ans = rank[times//2]//2

print(ans)
  

Measured memory_bytes: 18152
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(){
    int k = 0,a = 0, b = 0;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

const ll MAXI = 1e9;
ll s, a, b, now, rest;

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	cout << "0 0 ";
	if(s <= MAXI) cout << "0 1 "<<s<<" 0\n";
	else{
		a = s/MAXI;
		a += (a*MAXI < s);
		b = MAXI*a-s;
		cout << MAXI <<" " << 1 << " " << b << " " << a <<"\n";
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG 
int main(){
    string test;
    cin>>test;
    int n=test.size();
    int count=n+8;
    bool judge=true;
    string s="xxxxxxxxx"+test;
    while((count>8)&&(judge==true)){     
        judge=false;
        if(s[count]=='m'){
            if(s[count-1]=='a'&&s[count-2]=='e'&&s[count-3]=='r'&&s[count-4]=='d'){
                count-=5;
                judge=true;
            }
            else continue;
        }
        else if(s[count]=='e'){
            if(s[count-1]=='s'&&s[count-2]=='a'&&s[count-3]=='r'&&s[count-4]=='e'){
                count-=5;
                judge=true;
            }
            else continue;
        }
        else if(s[count]=='r'&&s[count-1]=='e'&&s[count-2]=='m'){
            if(s[count-3]=='a'&&s[count-4]=='e'&&s[count-5]=='r'&&s[count-6]=='d'){
                count-=7;
                judge=true;
            }
            else continue;
        }
        else if(s[count]=='r'&&s[count-1]=='e'&&s[count-2]=='s'){
            if(s[count-3]=='a'&&s[count-4]=='r'&&s[count-5]=='e'){
                count-=6;
                judge=true;
            }
            else continue;
        }
        else continue;
        }

        if(count==8&&judge==true) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

}

Measured memory_bytes: 3796
N = int(input())

used_word_list = []
for n in range(N):
  if n == 0:
    pre_word = input()
    used_word_list.append(pre_word)
    pre_word = pre_word[-1]
    continue
  else:
    word = input()
    word_first = word[0]
    
    if (pre_word != word_first) or (word in used_word_list):
      print('No')
      exit()
    
    pre_word = word[-1]
    used_word_list.append(word)

print('Yes')     
  



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>

using namespace std;


// "#"は1 ","は0
int main() {
    int N, M;
    char tmp;
    bool flag = false;
    bool flag2 = false;

    cin >> N >> M;
    //vector <vector<int>> v1, v2;
    //
    //v1 = vector<vector<int>>(N, vector<int>(N, 0));

    //v2 = vector<vector<int>>(M, vector<int>(M, 0));

    int v1[50][50];
    int v2[50][50];



    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < N; j++)
        {
            cin >> tmp;
            if (tmp == '#')
            {
                v1[i][j] = 1;
            }
            else
            {
                v1[i][j] = 0;
            }
        }
    }

    for (size_t i = 0; i < M; i++)
    {
        for (size_t j = 0; j < M; j++)
        {
            cin >> tmp;
            if (tmp == '#')
            {
                v2[i][j] = 1;
            }
            else
            {
                v2[i][j] = 0;
            }
        }
    }

    // 探索
    for (size_t i = 0; i <= N - M; i++)
    {
        for (size_t j = 0; j <= N - M; j++)
        {
            for (size_t k = 0; k < M; k++)
            {
                for (size_t l = 0; l < M; l++)
                {
                    if (v1[i + k][j + l] == v2[k][l])
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag == false)
                {
                    break;
                }
                
            }
            if (flag == true)
            {
                flag2 = true;
                break;
            }
        }
        if (flag2 == true)
        {
            break;
        }
    }


    if (flag2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	int ans = 0;
	f(3){
		ans += (s1[i]==s2[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll x;	cin>>x;
	ll t = 0;
	while (t*(t + 1) <2 * x) {
		t++;
	}
	cout << t << endl;
	}








Measured memory_bytes: 256
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[(int) (10e5+1)];
        int tmp = 0;
        long sum = 0;
        Arrays.fill(a,0);
        for (int i = 0; i < n; i++) {
            tmp = sc.nextInt();
            a[tmp] +=1;
            sum += tmp;
        }


        int q = sc.nextInt();
        long[] ans = new long[q+1];
        ans[0] = sum;
        int b, c;
        for (int i = 1; i <= q; i++) {
            b = sc.nextInt();
            c = sc.nextInt();
            ans[i] = ans[i-1] +((c-b)*a[b]);
            a[c] +=a[b];
            a[b] = 0;

        }

        for(int i= 0;i<q;i++){
            System.out.println(ans[i+1]);
        }
    }

}

Measured memory_bytes: 74964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, m; 
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> ans;
    ans.push_back(n);
    int now = n;
    while(1) {
        int l = m;
        while(now-l<0||s[now-l]=='1') l--;
        if(l == 0) {
            cout << -1 << endl;
            return 0;
        }
        now -= l;
        ans.push_back(now);
        if(now == 0) break;        
    }
    reverse(ans.begin(), ans.end());
    int S = ans.size();
    for(int i = 0; i < S-1; i++) {
        cout << ans[i+1]-ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1144
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

if __name__ == '__main__':

    q = []
    while True:
        c = input().split(" ")
        if c[0]=='end':
            break
        if c[0]=='insert':
            heappush(q, -int(c[1]))
        else:
            print(-heappop(q))


Measured memory_bytes: 45316
K = int(input())
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[K-1])

Measured memory_bytes: 9048
n = int(raw_input())
b = map(int,raw_input().split())
a = []
a.append(b[0])
a.append(b[0])
for i in xrange(1,n-1):
	if b[i] < a[i]:
		a[i] = b[i]
	a.append(b[i])
#print a
print sum(a)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<pair<int, int>>;
using VTIII = vector<tuple<int, int, int>>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


template<typename T>
struct CumulativeSum {
    vector<T> dat;
    CumulativeSum() = default;
    CumulativeSum(const vector<T>& v){
        int n = v.size();
        dat.resize(n+1);
        for(int i = 0;i < n;i++) dat[i+1] = dat[i]+v[i];
    }
    inline void add(int k, T a){
        dat[k] += a;
    }
    inline void build(){
        int n = dat.size();
        for(int i = 0;i < n;i++) dat[i+1] += dat[i];
    }
    //[l, r)
    inline T query(int l, int r) const {
        return dat[r]-dat[l];
    }
};


int N, M;
int p[100010];
CumulativeSum<int> S[20];
int dp[1<<20];


signed main(){
    cin >> N >> M;
    rep(i, 0, N) cin >> p[i], p[i]--;

    rep(i, 0, M){
        vector<int> v(N);
        rep(j, 0, N) v[j] = (p[j] == i);
        S[i] = CumulativeSum<int>(v);
    }

    fill(dp, dp+(1<<M), INF);
    dp[0] = 0;
    rep(i, 0, 1<<M){
        int off = 0;
        rep(j, 0, M) if(((i>>j)&1) == 1) off += S[j].query(0, N);
        rep(j, 0, M) if(((i>>j)&1) == 0){
            int r = S[j].query(0, N);
            chmin(dp[i|(1<<j)], dp[i]+(r-S[j].query(off, off+r)));
        }
    }

    cout << dp[(1<<M)-1] << endl;

    return 0;
}


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

vector<bool> r;
vector<vector<int>> rG;

void dfs(int v, vector<vector<int>> &G) {
    r[v] = true;
    for(int to : G[v]) {
        if(!r[to]) dfs(to, G);
    }
}


/**********************************************/
template <typename T>
struct edge{
    int from;
    int to;
    T weight;
};

template <typename T>
class BellmanFord {
public:
    BellmanFord(int V, vector<edge<T>> E)
    :V(V), E(E), source(-1), INF(numeric_limits<T>::max()) {}

    // solve the single-source shortest path problem
    void build(int source) {
        // initialize
        this->source = source;
        dist.resize(V, INF);
        dist[source] = 0;
        pred.resize(V);
        pred[source] = {-1, source, 0};

        // relax
        for(int i = 1; i < V; ++i) {
            for(edge<T> e : E) {
                if(dist[e.from] == INF) continue;
                if(dist[e.to] > dist[e.from] + e.weight) {
                    dist[e.to] = dist[e.from] + e.weight;
                    pred[e.to] = e;
                }
            }
        }

        // negative-weight cycle check
        for(edge<T> e : E) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.weight) {
                // detected a negative-weight cycle!
                if(!r[e.to]) continue;
                dist[source] = -1;
            }
       }
    }

    // return the distance between source and destination
    // build if necessary
    T distance(int source, int destination) {
        if(this->source != source) build(source);
        return dist[destination];
    }

    // return the path between source and destination
    // Return value holds the edges in the reverse order
    // build if necessary
    vector<edge<T>> shortest_path(int source, int destination) {
        if(this->source != source) build(source);
        
        if(dist[destination] == INF) {
            return vector<edge<T>>(0);
        } else {
            vector<edge<T>> path;
            int cur = destination;
            do {
                path.push_back(pred[cur]);
                cur = pred[cur].from;
            } while(cur != -1);
            return path;
        }
    }

private:
    int V;
    vector<edge<T>> E;
    vector<T> dist;
    vector<edge<T>> pred;
    int source;
    const T INF;
};
/**********************************************/


using pp = pair<int, long long>;
int main() {
    int N, M, P;
    cin >> N >> M >> P;
    //rG.resize(N);
    vector<edge<long long>> E(M);
    rG.resize(N);
    for(int i=0; i<M; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        E[i] = {a - 1, b - 1, P - c};
        rG[b - 1].emplace_back(a - 1);
    }

    r.resize(N, false);
    dfs(N - 1, rG);

    BellmanFord<long long> bf(N, E);
    if(bf.distance(0, 0) == -1) cout << -1 << endl;
    else cout << max(-bf.distance(0, N - 1), 0LL) << endl;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> A(T);
    rep(i, T) cin >> A[i];
    sort(all(A), greater<int>());

    int need = A[0] - 1;
    d(need);
    for (int i = 1; i < T; i++) {
        if (need == 0) break;
        need = max(0, need - A[i]);
    }
    cout << need << endl;
    return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
arr=list(map(int,input().split()))
ans=[0]*(100000)
pos=0
for i in range(n):
  pos+=arr[i]
  ans[pos]=1
cnt=1
for i in range(x+1):
  if ans[i]==1:
    cnt+=1
print(cnt)

Measured memory_bytes: 3828
#include<stdio.h>

int main(){
   int a, b, c, k;
   scanf("%d %d %d %d", &a, &b, &c, &k);

   if(a >= k){
      printf("%d\n", k);
   } else if(a+b >= k){
      printf("%d\n", a);
   } else {
      printf("%d\n", a-(k-(a+b)));
   }

   return 0;
}



Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,i,A,B,j,ans,f[5010][5010],a[5010];
int main(){
	scanf("%lld%lld%lld",&n,&A,&B);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	memset(f,44,sizeof(f));
	f[0][0]=0;
	for(i=1;i<=n;i++){
		for(j=0;j<=n;j++){
			if(a[i]>j)f[i][a[i]]=min(f[i][a[i]],f[i-1][j]),f[i][j]=min(f[i][j],f[i-1][j]+A);
			 else f[i][j]=min(f[i][j],f[i-1][j]+B);
		}
	}
	ans=1e18;
	for(i=1;i<=n;i++)ans=min(ans,f[n][i]);
	printf("%lld",ans);
}
/*
枚举不动的数就行了 
*/

Measured memory_bytes: 196352
a,b,n = map(int,input().split())
import math
 
ans = 0
if a > b:
    for i in range(min(n+1,a+1)):
        c = int(a*i/b) - a*int(i/b)
        ans = max(c,ans)
        
else:
    k = min(b-1,n)
    ans = int(a*k/b) - a*int(k/b)
    
print(ans)

Measured memory_bytes: 64592
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
	int N,M,a,b;
	cin >> N >> M;
	int node[N] = {};

	for (int i = 0; i < M; i++){
		cin >> a >> b;
		node[a - 1]++;
		node[b - 1]++;
	}

	for (int j = 0; j < N; j++){
		if (node[j] % 2 == 1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}

void solve_trust_d() {
	ll N;
	string S;
	ll ans = 0;

	cin >> N >> S;

	ll d[3];
	ll idx = 0;
	rep(i, 1000) {
		d[0] = i / 100;
		d[1] = i / 10 - d[0]*10;
		d[2] = i - d[0]*100 - d[1]*10;
		idx = 0;
		rep(j, S.size()) {
			if (ctoi(S[j]) == d[idx]) {
				idx++;
				if (idx == 3) {
					ans++;
					break;
				}
			}
		}
	}

	cout << ans << "\n";
}

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

	solve_trust_d();

	return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();
    let mx = (n-1) * (n-2) / 2;
    if mx < k {
        put!(-1);
    } else {
        let mut append = mx - k;
        put!(n - 1 + append);
        for i in 2..n+1 {
            println!("1 {}", i);
        }
        for i in 2..n+1 {
            for j in i+1..n+1 {
                if append == 0 { break }
                println!("{} {}", i, j);
                append -= 1;
            }
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, sum, tmp;
  cin >> x;
  tmp = x;
  
  sum = 0;
  while (x / 10 > 0) {
    sum += x % 10;
    x = x / 10;
  }
  sum += x;
  
  if (tmp % sum == 0)
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a,b,dep,p,q;
int vis[N],path[N];
vector<int>e[N];
int dfs1(int now,int deep)
{
	vis[now]=1;
	if(now==n)
	{
		dep=deep;
		return 1;
	}
	for(int i=0;i<e[now].size();i++)
	{
		if(vis[e[now][i]])
			continue;
		path[deep]=e[now][i];
		if(dfs1(e[now][i],deep+1))
			return 1;
	}
	return 0;
}
int dfs2(int now)
{
	vis[now]=1;
	int sum=1;
	for(int i=0;i<e[now].size();i++)
		if(!vis[e[now][i]])
			sum+=dfs2(e[now][i]);
	return sum;
}
int main()

{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	path[0]=1;
	dfs1(1,1);
	//1:(0)---(dep/2),(dep/2+1)---(dep-1)  2:(0)---(dep/2-1),(dep/2)---(dep-1)
 	memset(vis,0,sizeof(vis));
 	p=dfs2(1);
	if(dep%2)
	{
		memset(vis,0,sizeof(vis));
		for(int i=0;i<=dep/2;i++)
			vis[path[i]]=1;
		q=dfs2(path[dep/2+1]);
		if(p-q>q)
			printf("Fennec\n");
		else
			printf("Snuke\n");
	}
	else
	{
		memset(vis,0,sizeof(vis));
		for(int i=0;i<=dep/2-1;i++)
			vis[path[i]]=1;
		q=dfs2(path[dep/2]);
		if(p-q>q)
			printf("Fennec\n");
		else
			printf("Snuke\n");
	}
	return 0;
}


Measured memory_bytes: 11136
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Work work[] = new Work[n];
        for (int i = 0; i < n; i++) {
            int time = Integer.parseInt(sc.next());
            int limit = Integer.parseInt(sc.next());
            work[i] = new Work(time, limit);
        }
        sc.close();
        Arrays.sort(work, (x, y) -> Integer.compare(x.limit, y.limit));
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += work[i].time;
            if (ans > work[i].limit) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

    static class Work {
        int time;
        int limit;

        Work(int time, int limit) {
            this.time = time;
            this.limit = limit;
        }
    }
}

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

int call(int n)
{
  int x;
  
  for (int i = 1; i <= n; i++)
    {
      x = i;
      if ( x % 3 == 0)
        {
          cout << " " << i;
        }
      else
        {
          while (x)
            {
              if ( x % 10 == 3 )
                {
                  cout << " " << i;
                  break;
                }
              x /= 10;
            }
        }
    }
  cout << endl;
  return 0;
}

int main()
{
  int n;
  cin >> n;
  call(n);
  return 0;
}

Measured memory_bytes: 1160
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", input => {
  const inputs = input.split("\n");
  const S = inputs[0];
  const T = inputs[1];
  const result = getResult(S, T);
  console.log(result);
});

const RESULT_OK = "Yes";
const RESULT_NG = "No";

const getResult = (S, T) => {
  const sLength = S.length;
  if (sLength === 0 || sLength > 10) {
    return RESULT_NG;
  }
  if (T.length !== sLength + 1) {
    return RESULT_NG;
  }
  return T.slice(0, sLength) === S ? RESULT_OK : RESULT_NG;
};


Measured memory_bytes: 29924
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
X, N = map(int, input().split())
P = list(map(int, input().split()))


if N ==0:
    print(X)
    sys.exit()
    
if X not in P:
    print(X)
    sys.exit()
cnt= 1
while True:
    #print(X-cnt,X+cnt)
    if (X -cnt) not in P:
        print(X-cnt)
        sys.exit()
    elif (X+cnt) not in P:
        print(X+cnt)
        sys.exit()
    cnt += 1  

#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Measured memory_bytes: 9144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n,r;
  string s;
  cin >> n >> r;
  if (n >=10) cout << r << endl;
  else cout << r+100*(10-n) << endl;
 
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    lint A,B,K;
    cin >> A >> B >> K;
    if(K<=A) cout << A-K << " " << B << endl;
    else cout << 0 << " " <<  max(0LL,B-(K-A)) << endl;
}

Measured memory_bytes: 256
//Hope is a good thing, May be the best of things.. And no good thing ever dies 
// Giving up was never an option <3
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI (2.0 * acos(0.0))
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 2e6 + 10, oo = 1e9 + 7;
void solve () {
	ll n, k;
	cin >> n >> k;
	vector < ll > neg, pos, v;
	vector < pll> vp;
	for (int i = 0, x = 0; i < n; i++) {
		cin >> x;
		v.pb(abs(x));
		if (x > 0) {
			pos.pb(x);
			vp.pb({abs(x), 1});
		}
		else {
			neg.pb(abs(x));
			vp.pb({abs(x), 0});	
		}	
	}
	ll ok = 0;
	//cout << pos.size() << endl;
	if ((ll)pos.size() + neg.size() - (neg.size() % 2) >= k && k % 2 <= (ll) pos.size()) {
		ok = 1;
	}	
	ll mul = 1;	
	if (!ok) {
		//cout << "No " << endl;
		sort(v.begin(), v.end());
		for (ll i = 0; i < k; i++) {
			mul = (mul * v[i]) % oo;
		}
		mul = (oo - mul) % oo;
		cout << mul << endl;
	}
	else {
		ll a1 = -1, a2 = -1, b1 = 0, b2 = 0;
		sort(vp.begin(), vp.end());
		sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end());
		vector < ll > nv;
		ll cnt = 0;
		ll lsti = -1;
		for (int i = n - 1; i >= n - k; i--) {
			//cout << vp[i].first << endl;
			cnt += vp[i].second;
			nv.pb(vp[i].first);
			if (vp[i].second) {
				pos.pop_back();
				a1 = nv.size() - 1;
			}
			else {
				neg.pop_back();
				a2 = nv.size() - 1;
			}
		}

		if (cnt % 2 != k % 2) {
			//cout << " got it " << endl;
			if (neg.size()) {
				b1 = neg.back();
			}
			else b1 = -1;
			if (pos.size()) {
				b2 = pos.back();
			}
			else b2 = -1;
			//cout << a1 << " " << a2 << " " << b1 << " " << b2 << " " << nv[a1] << " " << nv[a2] << endl;
			if (a2 == -1 || (a1 != -1 && nv[a2] * b1 > nv[a1] * b2)) nv[a1] = b1;
			else nv[a2] = b2;
		}

		for (ll i = 0; i < nv.size(); i++) {
			mul = (mul * nv[i]) % oo;
		}
		cout << mul << endl;
	}
}
int main () {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //testcase {
        solve ();
		
    //}
    return 0;
}



Measured memory_bytes: 13352
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int mod=1e9+7;
int n,k,tot,ans;
map<int,int>mp;
int f[100008],dor[100008];

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

int power(int a,int k)
{
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    n=read(),k=read();
    for (int i=1;1ll*i*i<=n;i++)
	if (n%i==0)
	    {
	        dor[++tot]=i;
		if (n/i!=i) dor[++tot]=n/i;
	    }
    sort(dor+1,dor+tot+1);
    for (int i=1;i<=tot;i++) mp[dor[i]]=i;
    ans=f[1]=k;
    for (int i=2;i<=tot;i++)
	{
	    if ((n/dor[i])&1) f[i]=(power(k,(dor[i]+1)/2)-f[1])%mod;
	    else f[i]=(power(k,dor[i])-f[1])%mod;
	    for (int j=2;1ll*j*j<=dor[i];j++)
		if (dor[i]%j==0)
		    {
			f[i]=(f[i]-f[mp[j]])%mod;
			if (dor[i]/j!=j) f[i]=(f[i]-f[mp[dor[i]/j]])%mod;
		    }
	    ans=(ans+1ll*f[i]*dor[i]%mod)%mod;
	}
    ans=(ans+mod)%mod;
    printf("%d\n",ans);
    return 0;
}
    
    


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ull unsigned long long

using namespace std;

const int N = 505 * 505;

int n;
int x[N];
vector <int> v;
int L[N], R[N];
int a[N];

int main() {
	scanf ("%d", &n);
	rep(i, 1, n) {
		scanf ("%d", x + i);
		a[x[i]] = i;
		L[i] = i - 1;
		R[i] = n - i;
	}
	rep(i, 1, n * n) {
		if (a[i]) {
			v.pb(a[i]);
			if (L[a[i]] != 0) return printf ("No\n"), 0;
			continue;
		}
		// 1. L
		int best = -1;
		rep(j, 1, n)
			if (i < x[j] && (best == -1 || x[j] < x[best]) && L[j] > 0)
				best = j;
		if (best != -1) {
			v.pb(best);
			L[best]--;
			continue;
		}
		// 2. R
		rep(j, 1, n)
			if (x[j] < i && R[j]) {
				v.pb(j);
				R[j]--;
				break;
			}
		if (ss(v) != i) return printf ("No\n"), 0;
	}
	printf ("Yes\n");
	for (auto it : v)
		printf ("%d ", it);
	

    return 0;
}


Measured memory_bytes: 3060
while 1:
    H,W = map(int,input().split())
    if (H,W) == (0,0):
        break
    for i in range(H):
        for j in range(W):
            if i in (0,H-1):
                print('#',end='')
            else:
                if j in (0,W-1):
                    print('#',end='')
                else:
                    print('.',end='')
        print()        
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    if(s[k-1] == 'B') s[k-1] = 'b';
    if(s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <cmath>

using namespace std;
typedef unsigned short Int;
typedef set<Int> Set;

static const Int MAX = (Int)(-1);
Set P;

void makeprimes(){
  P.insert(2);
  Int n = 3;
  while(n != MAX){
    Int rt = sqrt(n);
    Set::iterator it = P.begin();
    bool isprime = true;
    while(1){
      if(n%(*it) == 0){
        isprime = false;
        break;
      }
      if(rt < *it){
        break;
      }
      ++it;
    }
    if(isprime){
      P.insert(n);
    }
    n+=2;
  }
}

int main(void){
  makeprimes();
  Int n;
  while(cin >> n , n){
    int c = 0;
    if(P.find(n-2) != P.end()){
      c++;
    }
    for(Int i = 3; i <= n/2; i += 2){
      if(P.find(i) != P.end() && P.find(n-i) != P.end()){
        c++;
      }
    }
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 1500
def resolve():
    n, x = map(int, input().split())
    S = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        if i == 0:
            pass
        elif i == 1 and S[i] + S[i-1] > x:
            diff = (S[i] + S[i - 1]) - x
            ans += diff
            S[i] = max(S[i]-diff, 0)
        else:
            if S[i] + S[i-1] > x:
                diff = (S[i] + S[i-1]) - x
                S[i] -= diff
                ans += diff
    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 14252
from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

q = deque([])
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append([i, j])
            q.append(0)

while q:
    y, x = q.popleft()
    ans = q.popleft() + 1
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        ny, nx = dy + y, dx + x
        if ny < 0 or nx < 0 or ny >= h or nx >= w:
            continue
        if a[ny][nx] == '.':
            a[ny][nx] = '#'
            q.append([ny, nx])
            q.append(ans)

print(ans-1)

Measured memory_bytes: 212492
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> A(3);
  for (auto& ai: A) scanf("%d", &ai);

  std::vector<int> l(N);
  for (auto& li: l) scanf("%d", &li);

  int res = 1e9;
  for (int i = 0; i < (1 << (2*N)); ++i) {
    int a[4] = {};
    int b[4] = {};
    for (size_t j = 0; j < N; ++j) {
      int k = i >> (2*j) & 3;
      a[k] += l[j];
      ++b[k];
    }
    int cur = 0;
    for (int j = 0; j < 3; ++j) {
      if (b[j] == 0) {
        cur = 1e9;
        break;
      }
      cur += 10*(b[j]-1);
      cur += abs(A[j]-a[j]);
    }
    res = std::min(res, cur);
  }
  printf("%d\n", res);
}


Measured memory_bytes: 256
#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 popcount(n) (__builtin_popcountll(n))

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;


int ans,y,m,d;

void next_day(){
	ans++;
	int day_end=19;
	if(y%3==0) day_end=20;
	if(m%2==1) day_end=20;

	d++;
	if(d<=day_end) return ;
	d=1,m++;
	if(m<=10) return;
	m=1,y++;
	return ;
}

int main(void){
	int n;
	cin >> n;
	while(n--){
		cin >> y >> m >> d;
		ans=0;
		while(1){
			if(y==1000 && m==1 && d==1) break;
			next_day();
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <stdio.h>
#include <memory.h>

int main(void) {
	const char DIR[4] = {'L', 'U', 'R', 'D'};
	const int MOVE[4][2] = {{0,-1}, {-1,0}, {0,1}, {1,0}};
	int i, j, n;
	int r, c, s, d;
	char buff[128][128];
	int elem[128][128][4];
	
	memset(buff, 0x00, sizeof(buff));
	memset(elem, 0x00, sizeof(elem));

	n = 1;
	while(scanf("%s\n", &buff[n][1]) == 1) n++;
	
	// 入力値を格子に変換
	for(i=1,s=strlen(&buff[2][1]);i<=n/2;i++) {
		for(j=1;j<=s;j++) {
			elem[i-1][j-1][0] = buff[i*2-1][j-1]=='1';	// 左
			elem[i-1][j-1][1] = buff[i*2-2][j]=='1';	// 上
			elem[i-1][j-1][2] = buff[i*2-1][j]=='1';	// 右
			elem[i-1][j-1][3] = buff[i*2][j]=='1';		// 下
//			printf("%d %d %d %d\n", elem[i-1][j-1][0], elem[i-1][j-1][1], elem[i-1][j-1][2], elem[i-1][j-1][3]);
		}
	}
	
	r = c = 0;
	d = 2;
	do {
		if(elem[r][c][(d+3)%4]==1) {	// 左
			d = (d+3) % 4;
		} else if(elem[r][c][d]==1) {	// 正面
			;
		} else if(elem[r][c][(d+1)%4]==1) {	// 右
			d = (d+1) % 4;
		} else if(elem[r][c][(d+2)%4]==1) {	// 背後
			d = (d+2) % 4;
		}
		r += MOVE[d][0];
		c += MOVE[d][1];
		printf("%c", DIR[d]);
		if(r==0 && c==0) break;
	} while(1);
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 796
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=2E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
void solve(){
    LL a,b,n;
    cin>>a>>b>>n;
    if(b>n) cout<<(a*n)/b<<"\n";
    else cout<<(a*(b-1))/b<<"\n";
}
int main(){
    IOS;
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>

using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N ;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> h(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    int MAX = 100;
    for(int posy = 0; posy <= MAX; posy++){
        for(int posx = 0; posx <= MAX; posx++){

        int needH = -1;

        for(int i = 0; i < N; i++){
            if(h[i] > 0){
                int tmp = h[i] + abs(posy - y[i]) + abs(posx - x[i]);
                if(needH == -1){
                    needH = tmp;
                }
                else{
                    if(needH != tmp){
                        needH = -2;
                        break;
                    }
                }
            }
        }
        if (needH == -2)continue;
        for(int i = 0; i < N; i++){
            if(h[i] == 0){
                int dist = abs(posy - y[i]) + abs(posx - x[i]);
                if(needH > dist){
                    needH = -2;
                    break;
                }
            }
        }
        if (needH == -2)continue;
        cout << posx << " " << posy << " " << needH << endl;
    }
}

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

vector<ll>a(55),b(55),c(55),d(55);
ll n,m,q;
ll mx=0,ans=0;
void dfs(vector<ll>A){
    if(A.size()==n+1){
        mx=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i])mx+=d[i];
        }
        ans=max(ans,mx);
        return;
    }
    else{
        A.push_back(A.back());
        while(A.back()<=m){
            dfs(A);
            A.back()++;
        }
    }
}
int main(){
   cin>>n>>m>>q;
    rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
    vector<ll>B(1,1);
    dfs(B);
    cout<<ans<<endl;
}








































Measured memory_bytes: 3636
import java.util.*;
import java.util.Scanner;

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

        int a;
        int b;

        Scanner inp = new Scanner(System.in);

        a = inp.nextInt();

        b = inp.nextInt();

       while (b != 0) {
           int temp = a;
           a = b;
           b = temp%b;
       }

       System.out.println(a);
    }
}


Measured memory_bytes: 26300
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli h, w, k;
	cin>>h>>w>>k;
	vector<vll> S(h, vll(w));
	loop(i, 0, h){
		loop(j, 0, w){
			char c;
			cin>>c;
			if(c == '#')	S[i][j] = 1;
			else	S[i][j] = 0;
		}
	}
	vector<vll> res(h, vll(w, 0));
	lli a = 0;
	loop(i, 0, h){
		lli count = 0;
		loop(j, 0, w){
			if(S[i][j] == 1)
				count++;
		}
		if(count == 0)
			continue;
		a++;
		bool flag = false;
		loop(j, 0, w){
			if(S[i][j] == 1){
				if(flag)
					a++;
				res[i][j] = a;
				flag = true;
			}
			else
				res[i][j] = a;
		}
	}
	lli count = 0;
	lli last = 0;
	loop(i, 0, h){
		lli st = 0;
		loop(j, 0, w){
			if(res[i][j] == 0)
				st++;
		}
		if(st == w){
			count++;
			continue;
		}
		else{
			last = i;
			lli z = 1;
			while(count > 0){
				res[i-z] = res[i];
				z++;
				count--;
			}
			count = 0;
		}
	}
	if(count != 0){
		loop(j, last+1, h)	res[j] = res[last];
	}
	loop(i, 0, h){
		loop(j, 0, w)
			cout<<res[i][j]<<" ";
		cout<<"\n";
	}
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no1();
	}

	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.nextLine();
			System.out.println("2018/01/" + str.substring(8));
		}
	}
}


Measured memory_bytes: 21716
#include<iostream>
using namespace std;
/*int fact(int n); 
  
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
// Returns factorial of n 
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}*/
int main(){
    int n;
    cin>>n;
    int i;
    long long a[n],b[n],total=0;
    for(i=0;i<n;i++){
        b[i] = 0;
    }
    for(i=0;i<n;i++){
        cin>>a[i];
        //b[a[i] - 1]++;
    }
    int ans[n];
    for(i=0;i<n;i++){
        b[a[i]-1]++;
    }
    for(i=0;i<n;i++){
        total+=b[i]*(b[i] - 1)/2;
    }
    for(i=0;i<n;i++){
       cout<< total-(b[a[i] - 1] - 1)<<endl;
    }
    /*for(i=0;i<n;i++){
        ans[i] = nCr(b[a[i] - 1]-1,2);
        for(int j=0;j<n;j++){
            if(j!=a[i] - 1){
                if(b[j] >=2){
                    ans[i] += nCr(b[j],2);
                }
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<ans[i]<<"\n";
    }*/
    return 0;
}

Measured memory_bytes: 5760
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;
use std::iter::repeat;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        M: usize,
        sc: [(usize1, usize); M],
    }
    let mut ans: Vec<char> = repeat('*').take(N).collect();
    for i in 0..M {
        let (s, c) = sc[i];
        if ans[s] != '*' && ans[s] != (c as u8 + '0' as u8) as char {
            println!("-1");
            return;
        }
        ans[s] = (c as u8 + '0' as u8) as char;
    }
    if N != 1 && ans[0] == '0' {
        println!("-1");
        return;
    }
    if N == 1 && ans[0] == '*' {
        println!("0");
        return;
    }
    for (i, c) in ans.into_iter().enumerate() {
        if c == '*' {
            if i == 0 {
                print!("1");
            } else {
                print!("0");
            }
        } else {
            print!("{}", c);
        }
    }
    println!("");
}


Measured memory_bytes: 4352
# include <stdio.h>
int main()
{
    char s[4]; 
    int a=0;
    scanf("%s", &s);
    if (s[0] == '1')
    {
        a++;
    }
    if (s[1] == '1')
    {
        a++;    
    }
    if (s[2] == '1')
    {
        a++;
    }
    
    printf("%d", a);
    return 0;
}

Measured memory_bytes: 128