akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i, a, b) for(int i=(int)(a); i>=(int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
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(a>b){a=b; return 1;}return 0;}

using namespace std;

int mod = (int)(1e9+7);

ll dfs(vector<vector<int>> &graph, int loc, int from, int K);

int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<int>> graph(N);
    REP(i, 0, N-1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cout << (dfs(graph, 0, -1, K)*K)%mod << endl;
    return 0;
}

ll dfs(vector<vector<int>> &graph, int loc, int from, int K)
{
    int can_use_color;
    if(from == -1){
        can_use_color = K-1;
    }else{
        can_use_color = K-2;
    }
    if(K<graph[loc].size()){
        return 0;
    }
    ll case_num = 1;
    for(auto e : graph[loc]){
        if(e == from)continue;
        case_num *= can_use_color;
        can_use_color--;
        case_num %= mod;
    }
    for(auto e : graph[loc]){
        if(e == from)continue;
        case_num *= dfs(graph, e, loc, K);
        case_num %= mod;
    }
    return case_num;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    vi x;//safe cells
    REP(i,n+1)if(s[i]=='0')x.push_back(n-i);
    reverse(all(x));
    dprint(x);


    int p=0;
    vi ans;
    while(true){
        if(x[p]==n)break;
        auto iter=upper_bound(x.begin()+p, x.end(), x[p]+m)-1;
        int targ=iter-x.begin();
        int l=x[targ]-x[p];
        if(l==0){
            cout<<-1<<endl;
            return 0;
        }
        ans.push_back(l);
        p=targ;
    }
    dprint(ans);
    reverse(all(ans));
    print(ans);
}


Measured memory_bytes: 1480
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  string a, b;
  cin >> a >> b;
  int ia = stoi(a), ib = stoi(b);
  vector<char> c;
  if (ia > ib)
  {
    c = vector<char>(ia, b[0]);
  }
  else
  {
    c = vector<char>(ib, a[0]);
  }
  cout << string(c.begin(), c.end()) << endl;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back

int main()
{
    ll n;
    cin>>n;
    vector<int> v(n);
    FOR(i,0,n)
        cin>>v[i];
    ll m1=0,i1;
    FOR(i,0,n)
    {
        if(v[i]>m1)
        {
            m1=v[i];
            i1=i;
        }
    }
    ll m2=0,i2;
    FOR(i,0,n)
    {
        if(v[i]>m2&&i!=i1)
        {
            m2=v[i];
            i2=i;
        }
    }
    FOR(i,0,n)
    {
        if(i==i1)
            cout<<m2<<"\n";
        else
            cout<<m1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 2432
import sys
import copy

def partition(A, p, r):
    x = A[r - 1][1]
    i = p - 1
    for j in range(p, r - 1):
        if A[j][1] <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp

    tmp = A[i+1]
    A[i+1] = A[r-1]
    A[r-1] = tmp
    return i+1

def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q)
        quicksort(A, q + 1, r)
    return A

def babble_sort(A, n):
    for j in range(n):
        for i in range(n-1):
            if A[i+1][1] < A[i][1]:
                tmp = A[i+1]
                A[i+1] = A[i]
                A[i] = tmp
    return A

def stable(A, B):
    for i in range(0, len(A)):
        if A[i][0] != B[i][0]:
            return False
    return True


n = int(sys.stdin.readline())

A = [[x[0], int(x[1])] for x in [y.split() for y in sys.stdin.read().split("\n")[:-1]]]

B = sorted(copy.deepcopy(A), key=lambda x: x[1])
C = quicksort(copy.deepcopy(A), 0, n)

if stable(C, B):
    print('Stable')
else:
    print("Not stable")

for i in C:
    print(*i)

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

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll c(int n, int k) {
  vector<int> u(k), d(k);
  rep(i,k) {
    u[i] = n - k + i + 1;
    d[i] = i + 1;
  }
  rep(i,k) {
    rep(j,k) {
      if(u[j] == 1 || d[i] == 1) continue;
      int c = gcd(u[j], d[i]);
      u[j] /= c;
      d[i] /= c;
    }
  }
  ll ans = 1;
  rep(i,k) ans *= u[i];
  return ans;
}

int main () {
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];

  sort(v.begin(), v.end(), greater<ll>());

  double m = 0;
  rep(i,a) {
    m += (double) v[i] / a;
  }
  printf("%lf\n", m);

  int k = 0;
  for(int i = a-1; i >= 0; i--) {
    if(v[a-1] != v[i]) break;
    k++;
  }

  int l = 0;
  for(int i = a; i < n; i++) {
    if(v[a-1] != v[i]) break;
    l++;
  }

  ll ans = 0;
  if(k == a) {
    for(int i = k, m = min(k+l, b-a+k); i <= m; i++) {
      ans += c(k+l, i);
    }
  } else {
    ans = c(k+l, k);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 384
def main():
    I = [int(_) for _ in input().split()]
    N = I[0]
    K = I[1]

    before = N % K
    after = abs(before - K)
    while before > after:
        before = after
        after = abs(after - K)

    print(before)



if __name__ == "__main__":
    main()


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

int main() {

    int n;
    cin >> n;

    vector <int> x(n);
    vector <int> y(n);

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

    int ans = n;
    int p,q;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j) continue;
            p = x[j] - x[i];
            q = y[j] - y[i]; 
            int tmp = 0;
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    if(k==l) continue;
                    if(x[k]-x[l]==p && y[k]-y[l]==q){
                        tmp++;
                    }
                }
            }
            ans = min(ans, n-tmp);
        }
    }
    cout << ans << endl;

}

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

int main() {
	long long n; cin >> n;
	vector<long long> arr(n);
	for (int i=0; i<n; i++) {
		cin >> arr[i];
	}
	long long mx = arr[0];
	long long sm = 0LL;
	for (int i=1; i<n; i++) {
		sm += max(0LL, mx-arr[i]);
		mx = max(mx, arr[i]);
	}
	cout << sm;
}


Measured memory_bytes: 4812
def FindParent(X):
    if Parent[X]==X:
        return X
    else:
        Parent[X] = FindParent(Parent[X])
        return Parent[X]

def CheckParent(X,Y):
    return FindParent(X)==FindParent(Y)

def UniteParent(X,Y):
    X = FindParent(X)
    Y = FindParent(Y)
    if X==Y:
        return 0
    if Rank[X]<Rank[Y]:
        Parent[X] = Y
    else:
        Parent[Y] = X
        if Rank[X]==Rank[Y]:
            Rank[X] += 1

import copy
N,M = (int(T) for T in input().split())
List = [[] for TM in range(0,M)]
for TM in range(0,M):
    List[TM] = [int(T) for T in input().split()]
    
Count = 0
for TM in range(0,M):
    ListCopy = copy.deepcopy(List)
    del ListCopy[TM]
    
    Parent = [I for I in range(N+1)]
    Rank = [0]*(N+1)
    for TTM in range(0,M-1):
        UniteParent(ListCopy[TTM][0],ListCopy[TTM][1])

    if not CheckParent(List[TM][0],List[TM][1]):
        Count += 1
print(Count)

Measured memory_bytes: 9328
# 同じ解法
# 自力で書けるか確認

def solve():
    from operator import itemgetter

    n, m = map(int, input().split())
    a = tuple([int(x) - 1 for x in reversed(input().split())] for _ in range(n))
    excluded = [False] * m

    ret = n
    for _ in range(m):
        cnt = [0] * m
        for p in a:
            while excluded[p[-1]]:
                p.pop()
            cnt[p[-1]] += 1
        j, c = max(enumerate(cnt), key=itemgetter(1))
        ret = min(ret, c)
        excluded[j] = True
    return ret


print(solve())


Measured memory_bytes: 4212
#include <iostream>

int main() {

    int a,b,max;
    scanf("%d %d", &a, &b);
    if(a >= b){
        max = a;
        a -= 1;
    }else{
        max = b;
         b -= 1;
    }

    if(a >= b){
        max += a;
        a -= 1;
    }else{
        max += b;
        b -= 1;
    }

    printf("%d", max);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,x,z[30+1];
	z[1]=0;
	z[2]=0;
	z[3]=0;
	z[4]=0;
	z[5]=0;
	z[6]=0;
	z[7]=0;
	z[8]=0;
	z[9]=0;
	z[10]=0;
	z[11]=0;
	z[12]=0;
	z[13]=0;
	z[14]=0;
	z[15]=0;
	z[16]=0;
	z[17]=0;
	z[18]=0;
	z[19]=0;
	z[20]=0;
	z[21]=0;
	z[22]=0;
	z[23]=0;
	z[24]=0;
	z[25]=0;
	z[26]=0;
	z[27]=0;
	z[28]=0;
	z[29]=0;
	z[30]=0;
	for(i=1;i<=28;i++) {
		scanf("%d",&x);
		if(x==1) {
			z[1]++;
		}
		if(x==2) {
			z[2]++;
		}
		if(x==3) {
			z[3]++;
		}
		if(x==4) {
			z[4]++;
		}
		if(x==5) {
			z[5]++;
		}
		if(x==6) {
			z[6]++;
		}
		if(x==7) {
			z[7]++;
		}
		if(x==8) {
			z[8]++;
		}
		if(x==9) {
			z[9]++;
		}
		if(x==10) {
			z[10]++;
		}
		if(x==11) {
			z[11]++;
		}
		if(x==12) {
			z[12]++;
		}
		if(x==13) {
			z[13]++;
		}
		if(x==14) {
			z[14]++;
		}
		if(x==15) {
			z[15]++;
		}
		if(x==16) {
			z[16]++;
		}
		if(x==17) {
			z[17]++;
		}
		if(x==18) {
			z[18]++;
		}
		if(x==19) {
			z[19]++;
		}
		if(x==20) {
			z[20]++;
		}
		if(x==21) {
			z[21]++;
		}
		if(x==22) {
			z[22]++;
		}
		if(x==23) {
			z[23]++;
		}
		if(x==24) {
			z[24]++;
		}
		if(x==25) {
			z[25]++;
		}
		if(x==26) {
			z[26]++;
		}
		if(x==27) {
			z[27]++;
		}
		if(x==28) {
			z[28]++;
		}
		if(x==29) {
			z[29]++;
		}
		if(x==30) {
			z[30]++;
		}
	}
	if(z[1]==0) {
		printf("1\n");
	}
	if(z[2]==0) {
		printf("2\n");
	}
	if(z[3]==0) {
		printf("3\n");
	}
	if(z[4]==0) {
		printf("4\n");
	}
	if(z[5]==0) {
		printf("5\n");
	}
	if(z[6]==0) {
		printf("6\n");
	}
	if(z[7]==0) {
		printf("7\n");
	}
	if(z[8]==0) {
		printf("8\n");
	}
	if(z[9]==0) {
		printf("9\n");
	}
	if(z[10]==0) {
		printf("10\n");
	}
	if(z[11]==0) {
		printf("11\n");
	}
	if(z[12]==0) {
		printf("12\n");
	}
	if(z[13]==0) {
		printf("13\n");
	}
	if(z[14]==0) {
		printf("14\n");
	}
	if(z[15]==0) {
		printf("15\n");
	}
	if(z[16]==0) {
		printf("16\n");
	}
	if(z[17]==0) {
		printf("17\n");
	}
	if(z[18]==0) {
		printf("18\n");
	}
	if(z[19]==0) {
		printf("19\n");
	}
	if(z[20]==0) {
		printf("20\n");
	}
	if(z[21]==0) {
		printf("21\n");
	}
	if(z[22]==0) {
		printf("22\n");
	}
	if(z[23]==0) {
		printf("23\n");
	}
	if(z[24]==0) {
		printf("24\n");
	}
	if(z[25]==0) {
		printf("25\n");
	}
	if(z[26]==0) {
		printf("26\n");
	}
	if(z[27]==0) {
		printf("27\n");
	}
	if(z[28]==0) {
		printf("28\n");
	}
	if(z[29]==0) {
		printf("29\n");
	}
	if(z[30]==0) {
		printf("30\n");
	}
	return 0;
}

Measured memory_bytes: 580
/**
 *	@file: A.cpp
 *	@author: Huy Le
 *	@created: 2020-08-22 19:01
**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\n';

void DEBUGLOCAL() { cerr << ")" << newl; }
template<class A, class... B> 
void DEBUGLOCAL(A argc, B... argv) {
	cerr << argc;
	if(sizeof...(argv))
		cerr << ", ";
	DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> (" << #__VA_ARGS__ << "): (",DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int ts;
string s;

void solve() {
	cin >> s;
	ll ans = 0;
	for(auto c:s) {
		ans += (c-'0');
	}
	cout << (ans%9?"No":"Yes") << newl;
}

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

	//cin >> ts;
	//while(ts--)
		solve();
}


Measured memory_bytes: 3780
#include<iostream>
using namespace std;
int main(){
    while(1){
        int N,sum,ans=0;
        cin >> N;
        if(N==0)    break;
        for(int i=1;i<N;i++){
            for(int j = i,sum = 0; sum <  N&&j<N; j++){
                sum += j;
                if(sum==N){
                    ans++;
                    break;
                }
            }
        }
        cout << ans << "\n";
    }
}


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






int main() {
  

  int x,a,b,c,d;
  cin>>x;
  d=x%10;
  x/=10;
  c=x%10;
  x/=10;
  b=x%10;
  x/=10;
  a=x%10;
  
  if (a+b+c+d==7){
    cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if (a+b+c-d==7){
    cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if (a+b-c+d==7){
    cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if (a+b-c-d==7){
    cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if (a-b+c+d==7){
    cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if (a-b+c-d==7){
    cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
  }
  else if (a-b-c+d==7){
    cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
  }
  else if (a-b-c-d==7){
    cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
  }
  
  
      
  



  
}

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

public class Main {


    public static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        int[] moves = new int[n];
        for(int i = 0; i < n;i += 1)
            moves[i] = in.nextInt();

        boolean[] store = new boolean[k+1];

        for(int i = 1; i <= k; i += 1) {
            for(int m: moves) {
                if (m <= i && !store[i - m]) {
                    store[i] = true;
                    break;
                }
            }
        }

        String result = store[k] ? "First" : "Second";
        out.println(result);
    }


    public static InputReader in = new InputReader();
    public static PrintWriter out;

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }


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

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            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 double nextDouble() {
            return Double.parseDouble(next());
        }

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

        /**
         * When you call next(), that entire line will be skipped.
         * No flushing buffers.
         * Doesn't work when you want to scan the remaining line.
         *
         * @return entire line
         */
        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
                tokenizer = null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }
}

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

using namespace std;

int main()
{
	int i;
	int a[3];
	int k;
	int sum =0;
	cin >> a[0] >> a[1] >> a[2] >> k;
	

	for(i = 1; i <= a[0]; i++)
	{
		sum++;
		k--;
		if(k <= 0) {
		cout << sum;
		return 0;
		}
	}
	
	for(i = 1; i <= a[1]; i++)
	{
		k--;
		if(k <= 0) {
		cout << sum;
		return 0;
		}
	}
	for(i = 1; i <= a[2]; i++)
	{
		sum--;
		k--;
		if(k <= 0) {
		cout << sum;
		return 0;
		}
	}
	
}
	
	

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;

int D[100000];
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}
int main() {
	int N;
	cin >> N;
	map<int, int> cnt;
	for (int i = 0; i < N; i++) {
		cin >> D[i];
		cnt[D[i]]++;
	}
	if (D[0] != 0 || cnt[0] != 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for (int i = 1; i < N; i++) {
		(ans *= mod_pow(cnt[i - 1], cnt[i])) %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5376
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    int X;
    io.read(X);

    if(X < 600) cout << 8;
    else if(X < 800) cout << 7;
    else if(X < 1000) cout << 6;
    else if(X < 1200) cout << 5;
    else if(X < 1400) cout << 4;
    else if(X < 1600) cout << 3;
    else if(X < 1800) cout << 2;
    else cout << 1;
    
    return 0;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  string s;
  long long k;
  cin >> s >> k;
 
  bool all = true;
  char cha = s[0];
  for (int i=0; i<s.size(); i++){
      if (s[i] != cha){
          all = false;
          break;
      }
  }
  if (all){
      cout << (k*(long long)s.size())/2;
      return 0;
  }
  string s2 = s;
  long long total = 0;
  long long add = 0;
  long long add2 = 0;
  char last = s[0];
  int cursum = 1;
  for (int i=1; i<s.size(); i++){
      if (s[i] == last){
          cursum++;
      }else{
          add += cursum/2;
          cursum = 1;
          last = s[i];
      }
  }
  add += cursum/2;
  for (int i=0; i<s2.size(); i++){
      s += s2[i];
  }
  cursum = 1;
  last = s[0];
  for (int i=1; i<s.size(); i++){
      if (s[i] == last){
          cursum++;
      }else{
          add2 += cursum/2;
          cursum = 1;
          last = s[i];
      }
  }
  add2 += cursum/2;
  long long diff = add2-add;
  cout << add+diff*(k-1);
  return 0; 
}


Measured memory_bytes: 256
num=int(input())
date1=input().rstrip().split(" ")
A=int(date1[0])
B=int(date1[1])
C=int((A-A%num)/num)
D=int((B-B%num)/num)
if A%num==0 or B%num==0:
    print("OK")
elif C==D:
    print("NG")
else:
    print("OK")

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vector<bool> visited(n,false);
  ll cnt = 0;
  REP(i,n){
    ll a;
    cin >> a;
    if(!visited[a]){
      visited[a] = true;
    }else{
      cnt++;
    }
  }
  ll ans;
  if(cnt%2==0){
    ans = n - cnt;
  }else{
    ans = n - cnt - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int m,f,b;
  cin>>m>>f>>b;
  if(b<=m)
    cout<<0<<endl;
  else if(m+f>=b)
    cout<<b-m<<endl;
  else
    cout<<"NA"<<endl;
  return 0;
}

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

int main () {
	int a;
	int b;
	cin>>a>>b;
	
	 if (a==1) {
 		a=14;
 	}
 	
 	if (b==1) {
 		b=14;
 	}
 	
 	if (a>b) {
 		cout<<"Alice"<<endl;
 	}
 	else if (a<b) {
 		cout<<"Bob"<<endl;
 	}
 	else if (a==b) {
 		cout<<"Draw"<<endl;
 	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
string a;
long long int ans=0;
int main()
{
    cin>>a;
    while(a[ans])
	{
        ans++;
    }
    cout<<a[0]<<ans-2<<a[ans-1];
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    string n; cin >> n;
    if(n.find_first_of("7")!=string::npos){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }
}

void b(){
    ll n; cin >> n;
    ll sum =0;
    for(ll i=1;i<=n;i++){
        if(i%3==0&&i%5==0) continue;
        else if(i%3==0) continue;
        else if(i%5==0) continue;
        else sum+=i; 
    }
    cout << sum << endl;
}

ll gcd(ll a,ll b){
    return (b==0)?a:gcd(b,a%b);
}

ll ggcd(ll a,ll b,ll c){
    return gcd(gcd(a,b),c);
}
void c(){
    int k;
    cin >> k;
    ll ans =0;
    for(int a=1;a<=k;a++)
        for(int b=1;b<=k;b++)
            for(int c=1;c<=k;c++){
                ans +=ggcd(a,b,c);
            }

    cout << ans << endl;
}

void d(){

}

void e(){

}

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

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S,T;
  cin>>S>>T;
  
  if(S==T) {
cout<<"Yes"<<endl;
    return 0;
  }
for(ll i=0;i<S.size();i++) {
  bool a=true;
  ll h=0;
  ll count=0;
  ll j=i;
while(count<S.size()) {

if(j==S.size()) {
j-=S.size();
}
  if(S[j]!=T[h]) {
    a=false;
  }
  h++;
  j++;
  count++;
}
  
  if(a) {
cout<<"Yes"<<endl;
    return 0;
  }
}
  
  
  
  cout<<"No"<<endl;
}

  
  
  
  
  
  


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

int N;
string s,t;

int solve(){
  for (int i=0;i<N;++i){
    if(s.substr(i)==t.substr(0,N-i))return i+N;
  }
  return N*2;
}

int main(){
  cin >>N>>s>>t;
  cout<<solve()<<endl;
}

Measured memory_bytes: 256
import java.lang.Math.abs
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val M = sc.nextInt()

fun main(args: Array<String>) {
    val ab = Array(N) { Pair(0, 0) }
    val cd = Array(M) { Pair(0, 0) }

    for (i in 0 until N) {
        ab[i] = Pair(sc.nextInt(), sc.nextInt())
    }

    for (j in 0 until M) {
        cd[j] = Pair(sc.nextInt(), sc.nextInt())
    }

    for (i in 0 until N) {
        var k = 0
        var v = Int.MAX_VALUE
        for (j in 0 until M) {
            val a = ab[i].first
            val b = ab[i].second
            val c = cd[j].first
            val d = cd[j].second

            val t = abs(a - c) + abs(b - d)
            if (t < v) {
                v = t
                k = j + 1
            }
        }
        println(k)
    }
}


Measured memory_bytes: 29612
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{

	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;

	int rock_f = 0;
	int escape = 0;
	int rn = 0;
	int esn = 0;

	int start = min(a, b);
	int start_2 = max(a, b);
	int end = max(c, d);
	int end_2 = min(c, d);
	bool flag = false;
	if (d < c) {
		flag = true;
	}


	for (int i = start; i < end; i++) {
		char si = s[i -1];
		if (si == '#') {
			rn++;
			esn = 0;
			if (rn >= 2) {
				if (i < end) {
					rock_f = 1;
				}
				break;
			}
		}
		else {
			rn = 0;
			esn++;
			if (esn >= 3 && i > start_2 && i < end_2 + 2) {
				escape = 1;
			}
		}

	}

	string ans = "No";
	if (rock_f == 0) {
		if (flag) {
			if (escape == 1) {
				ans = "Yes";
			}
		}
		else {
			ans = "Yes";
		}
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

UInt GreatestCommonDivisor(UInt a, UInt b) {
    if (b == 0) {
        return a;
    } else {
        if (a < b) {
            std::swap(a, b);
        }
        return GreatestCommonDivisor(b, a % b);
    }
}
UInt GreatestCommonDivisor(UInt a, UInt b, UInt c) {
    return GreatestCommonDivisor(GreatestCommonDivisor(a, b), c);
}
#define GCD GreatestCommonDivisor

int main(void) {
    Int k;
    cin >> k;
    Int sum = 0;
    for (Int a = 1; a <= k; ++a) {
        for (Int b = 1; b <= k; ++b) {
            for (Int c = 1; c <= k; ++c) {
                sum += GCD(a, b, c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    int res=0;
    for(int i=0;i<3;i++) res += s[i]-'0';
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100001
int depthfunc(int);
struct Node{
  int p;
  int l;
  int r;
};
struct Node T[N];
 
 
int main()
{
 
  int i,j,n,par,child,sib,k,x;
 
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }
 
  for(i = 0; i < n; i++){
    scanf("%d %d",&par,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&child);
      if(j == 0){
    T[par].l = child;
      T[child].p = par;
      x = child;
      }
      else {
    T[x].r = child;
    T[child].p= par;
    x = child;
      }
    }
  }
 
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i , T[i].p,depthfunc(i));
    if(T[i].l  == -1 && T[i].p != -1)printf("leaf, ");
    else if(T[i].p == -1)printf("root, ");
    else if(T[i].l != -1)printf("internal node, ");
    printf("[");
 
    if(T[i].l != -1){
      printf("%d",T[i].l);
 
      sib = T[i].l;
 
      while(1){
    if(T[sib].r == -1)break;
    printf(", %d",T[sib].r);
      sib = T[sib].r;
    }
    }
  printf("]\n");
  }
 
  return 0;
}
 
int depthfunc(int k){
  int dep =0;
  for(dep = 0; T[k].p != -1; dep++){
    k = T[k].p;
  }
    return dep;
  }

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


bool reach[3001][3001];

int main()
{
  int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
  for(int x=0;100*a*x<=f;x++)
    for(int y=0;100*a*x+100*b*y<=f;y++)
      reach[100*a*x+100*b*y][0]=true;

  for(int w=1;w<=f;w++)
    if(reach[w][0])
      {
	for(int s=1;w+s<=f;s++)
	  {
	    if((s-c)>=0 && reach[w][s-c])
	      reach[w][s]=true;
	    else if((s-d)>=0 && reach[w][s-d])
	      reach[w][s]=true;
	  }
      }

  int best_s=0, best_w=100*a;
  for(int w=1;w<=f;w++)
    for(int s=1;s+w<=f;s++)
      if(reach[w][s] && 100*s<=w*e)
	{
	  if(s*(best_w+best_s)>best_s*(w+s))
	    {
	      best_s=s;
	      best_w=w;
	    }
	}
  printf("%d %d\n",best_s+best_w, best_s);
  return 0;
}


Measured memory_bytes: 6400
#alds13a

class Task:
    def __init__(self,pid,rest_time):
        self.pid = pid
        self.rest_time=int(rest_time)

n,q = map(lambda x: int(x),input().split(" "))
tasks=[]
for i in range(n):
    A = input().split(" ")
    tasks.append(Task(A[0],A[1]))
    
time=0
while len(tasks)>0:
    t = tasks.pop(0)
    if t.rest_time<=q:
        time += t.rest_time
        print(t.pid,time)
    else:
        time += q
        t.rest_time -= q
        tasks.append(t)


Measured memory_bytes: 17396
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

constexpr int64_t kLimit = 1000000000000000000;

int64_t Digits(const int64_t n) {
  int64_t value = n;
  int64_t digits = -1;
  do {
    digits++;
    value /= 10LL;
  } while (value > 0);
  return digits;
}

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

  // const int64_t L = static_cast<int64_t>(T.length());
  int64_t A;
  string B;
  cin >> A >> B;
  const int64_t L = static_cast<int64_t>(B.length());
  int64_t b_100 = 0;
  int64_t pos = -1;
  for (int64_t i = 0; i < L; ++i) {
    const char ch = B.c_str()[i];
    if (ch == '.') {
      pos = i;
    } else {
      b_100 *= 10L;
      b_100 += static_cast<int64_t>(ch - '0');
    }
  }
  if (pos == L - 2) {
    b_100 *= 10LL;
  } else if (pos == L - 1) {
    b_100 *= 100LL;
  } else if (pos == -1) {
    b_100 *= 100LL;
  }

  const int64_t result_100 = A * b_100;
  const int64_t result = result_100 / 100LL;
  cout << result << endl;
  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	string t;
	cin>>n>>s>>t;
	for(int i=0;;i++){
		string tmp=s.substr(0,i);
		tmp+=t;
		if(tmp.substr(0,n)==s){
			cout<<n+i<<endl;
			return 0;
		}
	}
}


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

const ll Mod = 1e9+7;
const int MAX = 1e5;
int n, k;
ll ans = 1;
vector<int> to[MAX];
int par[MAX];

void dfs(int tmp, int m) {
  if (par[tmp] >= 0 && par[par[tmp]] >= 0) m += 2;
  else if (par[tmp] >= 0) m += 1;

  ans = ans * (ll)(k-m) % Mod;
  int i = 0;
  for (int next : to[tmp]) {
    if (next == par[tmp]) continue;
    par[next] = tmp;
    dfs(next, i);
    ++i;
  }
}

void solve() {
  par[0] = -1;
  dfs(0, 0);
  cout << ans << endl;
}

int main() {
  cin >> n >> k;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  solve();
  return 0;
}

Measured memory_bytes: 9600
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
if b[n-1]-b[0] >=2:
    print("No")
else:
    b = sum(a)%n
    c = int((sum(a)-b)/n)
    if b == 0:
        if 2*c > n and n != c+1:
            print("No")
        else:
            print("Yes")
    else:
        if b == 1:
            print("No")
        else:
            if n - b/2 >= c+1 and n <= c+b:
                print("Yes")
            else:
                print("No")

Measured memory_bytes: 13964
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,m,k;
vector<int>v;
int solve(int idx){
    ll cnt=0;
    for(auto isi:v){
        cnt+=abs(idx-isi)*abs(idx-isi);
    }
    return cnt;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    int bil;
    for(int i=1;i<=n;i++){
        cin>>bil;
        v.pb(bil);
    }
    int ans=1e9;
    for(int i=1;i<=100;i++){
        ans=min(ans,solve(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define w 0
#define g 1
#define b 2
#define N 100
#define infty 10000

int main()
{
  int i,j,n,count=0;
  int M[N][N],color[N],d[N],p[N];
  int min,x;

  scanf("%d",&n);

  for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	  scanf("%d",&M[i][j]);
	}
      color[i]=w;
      d[i]=infty;
      p[i]=-1;
    }

  d[0]=0;

  while(1){
      min=infty;
      for(i=0;i<n;i++){
	  if(color[i]!=b && d[i]<min){
	      min=d[i];
	      x=i;
	    }
	}
      if(min==infty) break;
      
      color[x]=b;

      for(i=0;i<n;i++){
	  if(M[x][i]!=-1 && color[i]!=b && M[x][i]<d[i]){
	      p[i]=x;
	      d[i]=M[x][i];
	      color[i]=g;
	    }
	}
    }

  for(i=0;i<n;i++){
      if(p[i]!=-1) count+=M[i][p[i]];
    }

  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2052
n, m = map(int, input().split())

l = []

for i in range(m):
    a, b = map(int, input().split())
    l.append([b, a])

l.sort()

ans = 0
x = 0

for i in range(m):
    if l[i][1] >= x:
        ans += 1
        x = l[i][0]

print(ans)

Measured memory_bytes: 20072
#include <cstdio>
#include <cstring>
#include <iostream>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
    if(ch == 'A')
        return 1;
    else if(ch == 'C')
        return 2;
    else if(ch == 'G')
        return 3;
    else if(ch == 'T')
        return 4;
    else
        return 0;
}

long long getKey(char str[])
{
    long long sum = 0, p = 1, i;
    for(i = 0; i < strlen(str); i++)
    {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key)
{
    return key % M;
}

int h2(int key)
{
    return 1 + (key % (M - 1));
}

int find(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for(i = 0;; i++)
    {
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0)
            return 1;
        else if(strlen(H[h]) == 0)
            return 0;
    }
    return 0;
}

int insert(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for(i = 0;; i++)
    {
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0)
            return 1;
        else if(strlen(H[h]) == 0)
        {
            strcpy(H[h], str);
            return 0;
        }
    }
}

int main(void)
{
    int i, n;
    char str[L], com[9];
    for(i = 0; i < M; i++) H[i][10] = '\0';
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%s %s", com, str);
        if(com[0] == 'i')
            insert(str);
        else
        {
            if(find(str))
                printf("yes\n");
            else
                printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 17432
X, Y, A, B, C = map(int, input().split())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

# p_listの中から大きい順にX個取り出す
sorted_p_list = sorted(p_list, reverse=True)[:X]

# q_listの中から大きい順にY個取り出す
sorted_q_list = sorted(q_list, reverse=True)[:Y]

# これらのリストをくっつけて昇順にする
s_list = sorted(sorted_p_list + sorted_q_list, reverse=False)

# r_listを降順にする
sorted_r_list = sorted(r_list, reverse=True)

for i in range(len(r_list)):
    if sorted_r_list[i] > s_list[i]:
        s_list[i] = sorted_r_list[i]
    else:
        break

print(sum(s_list))

Measured memory_bytes: 23328
#!/usr/bin/env python3


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W = map(int, input().split())
    for i in range(W+2):
        print("#", end="")
    print()
    for i in range(H):
        print("#", end="")
        print(input(),end="")
        print("#")
    for i in range(W+2):
        print("#", end="")
    print()


    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 64372
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second 
#define pii pair<int,int>
#define afor(i,a,b) for(int i=a;i<b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define print(A,j,k) for(int ii=j;ii<k;ii++)cout<<A[ii]<<" ";cout<<"\n"
#define all(v) v.begin(),v.end()
#define ps cout<<"YES\n";
#define CASES int t;cin>>t;while(t--)
//ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;
using namespace std;
int main()
{
    fast
    ll n,a,b,ans=0,v[100010];
    cin>>n>>a>>b;
    afor(i,0,n)
    {
        cin>>v[i];
    }
    afor(i,1,n)
    {
        ll k=v[i]-v[i-1];
        if(k*a>b)
            ans+=b;
        else
            ans+=a*k;
    }
    cout<<ans<<"\n";
    return 0;
}


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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, W;
    in(n);
    in(W);
    ll w[n], v[n];
    floop(i, n)
    {
        in(w[i]);
        in(v[i]);
    }
    ll dp[n + 1][1000 * 100 + 1];
    floop(i, n + 1)
    {
        floop(j, 1000 * 100 + 1)
        {
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    ll ans = 0;
    floop(i, n)
    {
        floop(j, 1000 * 100 + 1)
        {
            chmin(dp[i + 1][j], dp[i][j]);
            if (j >= v[i])
                chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }
    floop(i, 1000 * 100 + 1)
    {
        if (dp[n][i] <= W)
            ans = i;
    }
    out(ans);
}

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

int main(){
	int n, m;
	cin >> n >> m;
	if(m % n == 0){
		cout << m/n << endl;
		return 0;
	}
	
	for(int x = m/n; x > 0; x--){
		int amari = m - x * n;
		if(amari % x == 0){
			cout << x << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=(ll)1e9+7;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}

void solve()
{
  ll n;
  ll ans=0;
  ll sum = 0;
  ll sqsum=0;
  cin>>n;
  rep(i,n)
  {
    ll val;
    cin>>val;
    sum+=val;
    sum%=N;
    val = (val*val)%N;
    sqsum = (sqsum+val)%N;
  }
  sum*=sum;
  sum%=N;
  ans+=sum;
  ans%=N;
  ans = (ans-sqsum+N)%N;
  if(ans%2!=0)
  {
    ans+=N;
  }
  ans/=2;
  cout<<ans;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main() {
  string S;
  cin>>S;
  int N=S.size();
  for(int i=0;i<N;i++){
    if(S.at(i)=='?'){
      S.at(i)='D';
    }
  }    
  for(int i=0;i<N;i++){
    cout<<S.at(i);
  }
  cout<<endl;
      
}

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

const int maxn=10+6;
int n;
int a[maxn];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int maxp=a[0];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>maxp)
			maxp=a[i];
		sum+=a[i];
	}
	cout<<sum-maxp/2<<endl;



	return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -Wall -Werror #-}

import Control.Applicative ((<$>))

main :: IO ()
main = do
  nums <- map read <$> words <$> getContents
  mapM_ (\n -> print $ length $ takeWhile (<= n) primes) nums

-- http://itchyny.hatenablog.com/entry/2016/01/17/120000
primes :: [Integer]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integer -> Bool
isPrime n = n > 1 && foldr (\x acc -> x * x > n || (n `mod` x /= 0 && acc)) True primes

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


using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

//#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
const ll sz=1000001;
const ll N=1e12;
vector<ll>prime;
bool flag[sz+3];


void sieve(void)
{
    ll i,j,add;
    flag[0]=flag[1]=1;
    prime.push_back(2);
    for(i=4; i<sz; i+=2)
        flag[i]=1;
    for(i=3; i<sz; i+=2)
    {
        if(!flag[i])
        {
            prime.push_back(i);
            if(sz/i>=i)
            {
                add=i*2;
                for(j=i*i; j<sz; j+=add)
                    flag[j]=1;
            }
        }

    }
}

const int MOD = 1000000007 ;
long long int  bigmod ( long long B, int P, int M )
{
    if ( P == 0 )return 1;
    if ( P % 2 ) {
        return ( ( B % M ) * ( bigmod ( B, P-1, M))) % M;
    }
    else {
        long long mod = bigmod (B,P/2,M);
        return ((mod%M)*(mod%M))%M;
    }
}

*/

int main()
{
     string s;
     cin>>s;
     ll sum=0;
     for(int i=0; i<s.size(); i++){
        sum+=(s[i]-'0');
     }
   if(sum%9 ==0) cout<<"Yes\n";
   else cout<<"No\n";
    return 0;
}
/*


*/


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int x;
    cin>>x;
    if(x==7||x==5||x==3)
    {
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 256