akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<int(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

int dp[25][25][26][26];

int main() {
  while(1){
    int n,m,r;
    cin>>n>>m>>r;
    if(!n) break;
    deque<int> a(n), b(m);
    REP(i,n) cin>>a[i];
    REP(i,m) cin>>b[i];
    multimap<pair<int,int>,int> rules;
    int count = 31;
    REP(i,r) {
      int k;
      cin>>k;
      vector<int> x(k);
      REP(j,k) cin>>x[j];
      int y;
      cin>>y;
      if (k >= 3) {
        rules.emplace(make_pair(x[0], x[1]), count);
        ++count;
        REP(j,k-3) {
          rules.emplace(make_pair(count-1, x[j+2]), count);
          ++count;
        }
        rules.emplace(make_pair(count-1, x.back()), y);
        ++count;
      } else {
        rules.emplace(make_pair(x[0], x[1]), y);
      }
    }
    using S = vector<int>;
    S as, bs;
    vector<vector<S>> cyka(n, vector<S>(n+1));
    REP(j,n) {
      cyka[j][1].push_back(a[j]);
    }
    FOR(l,2,n+1)REP(j,n) {
      FOR(k,1,l) {
        for (const auto &sl:cyka[j][k]) {
          for (const auto &sr:cyka[(j+k)%n][l-k]) {
            auto pitr = rules.equal_range(make_pair(sl, sr));
            for (auto itr = pitr.first; itr != pitr.second; ++itr) {
              cyka[j][l].push_back(itr->second);
            }
          }
        }
      }
      sort(ALL(cyka[j][l]));
      cyka[j][l].erase(unique(ALL(cyka[j][l])), end(cyka[j][l]));
    }
    vector<vector<S>> cykb(m, vector<S>(m+1));
    REP(j,m) {
      cykb[j][1].push_back(b[j]);
    }
    FOR(l,2,m+1)REP(j,m) {
      FOR(k,1,l) {
        for (const auto &sl:cykb[j][k]) {
          for (const auto &sr:cykb[(j+k)%m][l-k]) {
            auto pitr = rules.equal_range(make_pair(sl, sr));
            for (auto itr = pitr.first; itr != pitr.second; ++itr) {
              cykb[j][l].push_back(itr->second);
            }
          }
        }
      }
      sort(ALL(cykb[j][l]));
      cykb[j][l].erase(unique(ALL(cykb[j][l])), end(cykb[j][l]));
    }
    FOR(la,1,n+1)FOR(lb,1,m+1)REP(i,n)REP(j,m) {
      vector<int> its;
      set_intersection(ALL(cyka[i][la]), ALL(cykb[j][lb]), back_inserter(its));
      if (its.empty()) {
        dp[i][j][la][lb] = 0;
      } else {
        dp[i][j][la][lb] = 1;
      }
    }
    FOR(la,2,n+1)FOR(lb,2,m+1)REP(i,n)REP(j,m) {
      FOR(ka,1,la)FOR(kb,1,lb) {
        if (dp[i][j][ka][kb] && dp[(i+ka)%n][(j+kb)%m][la-ka][lb-kb]) {
          dp[i][j][la][lb] = max(dp[i][j][la][lb], dp[i][j][ka][kb] + dp[(i+ka)%n][(j+kb)%m][la-ka][lb-kb]);
        }
      }
    }
    int mx = 0;
    REP(i,n)REP(j,m) mx = max(mx, dp[i][j][n][m]);
    if (mx) {
      cout << mx << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 9448
#include <stdio.h>

int cost[105][105];
int used[105];
int d[105][105];

int N,M;
int a[1005];
int b[1005];
int c[1005];

void warshall_floyd(){

	int i,j,k;

	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			d[i][j]=cost[i][j];
		}
	}

	for(k=0;k<N;k++){
		for(i=0;i<N;i++){
			for(j=0;j<N;j++){
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j]=d[i][k]+d[k][j];
				}
			}
		}
	}

}

int main(){

	scanf("%d %d",&N,&M);

	int i,j;
	for(i=0;i<M;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		cost[a[i]-1][b[i]-1]=c[i];
		cost[b[i]-1][a[i]-1]=c[i];
	}

	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			if(i==j){cost[i][j]=0;}
			else{
				if(cost[i][j]==0){cost[i][j]=1<<20;}
			}
		}
	}

	warshall_floyd();

	int ans=0;

	for(i=0;i<M;i++){
		if(c[i]>d[a[i]-1][b[i]-1]){
		ans++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    int counter = 0;
    for (int i = 0; i < N; ++i) {
      int temp = Integer.parseInt(sc.next());
      if (K <= temp) counter++;
    }
    
    System.out.println(counter);
  
  }
}

Measured memory_bytes: 43748
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
L = readInts()
L = sorted(L)
# 1,2番目を特定する
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = L[i]
        b = L[j]
        c = bisect.bisect_left(L, a + b)
        ans += c - (j+1)
print(ans)


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

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1;i <= n;i++) ans += i*(i+1)/2;
    ll u,v;
    while(cin >> u >> v){
        if(u>v) swap(u,v);
        ans -= u*(n-v+1);
    }
    cout << ans << endl;
}

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

int main()
{
    int x,a,b;
    scanf("%d %d %d" , &x, &a, &b);
    if(abs(x-a)>abs(x-b))
    {
        printf("B");
    }
    else
    {
        printf("A");
    }
    return 0;
}


Measured memory_bytes: 256
import sys

X, K, D = map(int, input().split())

if X >= 0: 
    temp1 = X // D
    if temp1+1 > K:
        print(X - D * K)
        sys.exit()
    else:
        ite1 = (K - temp1) % 2
        if ite1 == 1:
            print(abs(X % D - D))
            sys.exit()
        else:
            print(X % D)
            sys.exit()
else:
    temp1 = abs(X // D) - 1
    if temp1+1 > K:
        print(abs(X + D * K))
        sys.exit()
    else:
        ite1 = (K - temp1) % 2
        if ite1 == 1:
            print(X % D)
        else:
            print(abs(X % D - D))
    

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
    int x, y, z, temp;
    cin >> x >> y >> z;

    temp = x;
    x = y;
    y = temp;
    temp = x;
    x = z;
    z = temp;

    printf("%d %d %d\n", x, y, z);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int a, b;
    cin >> a >> b;

    double avg = (a + b) / 2.0;
    if(avg - (int)(avg) > 0){
        cout << (int)(avg) + 1 << endl;
    }else{
        cout << (int)(avg) << endl;
    }
}

Measured memory_bytes: 256
def solve(m,k):
    n=2**m
    if k>n-1:
        return [-1]
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    if m==1:
        return [-1]
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

m,k=map(int,input().split())
Ans=solve(m,k)
print(*Ans)

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

using namespace std;

#define ll long long
#define ar array


int n, q, ai, bi, c;
int a[100000];
ll ans = 0;

void solve(){
    
    cin >> n;

    for (int i = 0; i < 100000; i++){
        a[i] = 0;
    }
    
    for (int i = 0; i < n; i++)
    {
        cin >> q;
        a[q]++;
        ans += q;
    }
    
    cin >> q;

    int ta;

    for (int i = 0; i < q; i++)
    {
        cin >> ai >> bi;

        ta = a[ai];
        a[ai] = 0;

        a[bi] += ta;
        ans = ans - (ll)ta*ai + (ll)ta*bi;
        cout << ans << endl;

    }
    

}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 4044
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long d = scanner.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            long x = scanner.nextInt();
            long y = scanner.nextInt();
            if (x * x + y * y <= d * d) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 59364
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>tmp;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0) {
			tmp.push_back(i);
			tmp.push_back(n/i);
		}
	}
	int ans = 0;
	rep(i, tmp.size()) {

		if(tmp[i]!=1&&n / (tmp[i]-1) == n % (tmp[i] - 1))ans += tmp[i] - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main
{
	public static void main(String []args)
	{
		Scanner scan = new Scanner(System.in);
		int N,X,T;
		N = scan.nextInt();
		X = scan.nextInt();
		T = scan.nextInt();
		
		int count  = N/X;
		
		if(N%X == 0)
		{
			System.out.print(count*T);
		}
		else
		{
			System.out.print((count+1)*T);
		}
	}
}

Measured memory_bytes: 35680
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	vector<int> b(n-1);
	for(auto &i:b) cin>>i;
	int ans=b[0]+b[n-2];
	For(i,1,n-2){
		ans+=min(b[i],b[i-1]);
	}
	cout<<ans<<"\n";
	return 0;
}





























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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"


int main()
{
	int k , c;
	
	cin >> k >> c;
	
	int ans = c-k+1;
	
	if(ans < -1000000)
	{
		ans = -1000000;
	}
	
	int ans2 = c+k-1;
	
	if(ans2 > 1000000) ans2 = 1000000;
	
	for(int i = ans; i<=ans2; i++)
	{
		cout << i << " ";
	}
	cout << endl;

	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<int> ans,v;
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	for(int i=0;i<=n;i++)
		if(s[i]=='0')
			v.emplace_back(i);
	int  now=n;
	v.pop_back();
	while(!v.empty()){
		int nxt=now;
		while(!v.empty()&&now-v.back()<=m){
			nxt=v.back();v.pop_back();
		}
		if(now==nxt){
			cout<<-1<<endl;
			return 0;
		}
		ans.emplace_back(now-nxt);
		now=nxt;
	}
	reverse(ans.begin(),ans.end());
	for(int it:ans)
		cout<<it<<' ';
	cout<<endl;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<ll,ll>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int k;
vector<P> g[100010];

ll dijkstra(int s, int t){
	ll min_cost[100010]={};
	pq<P, vector<P>, greater<P>> que;
	REP(i,0,k) min_cost[i]=INF;
	que.emplace(0,s);
	min_cost[s]=0;
	while(!que.empty()){
		auto p=que.top(); que.pop();
		if(p.first>min_cost[p.second]) continue;

		for(auto e:g[p.second]){
			if(p.first+e.second>=min_cost[e.first]) continue;
			min_cost[e.first]=p.first+e.second;
			que.emplace(min_cost[e.first], e.first);
		}
	}

	return min_cost[t];
}

int main(){
	cin >> k;
	REP(i,0,k) g[i].push_back(P((i*10)%k,0)),g[i].push_back(P((i+1)%k,1));
	
	cout << dijkstra(1,0)+1 << endl;
	return 0;
}


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

void solve(int test) {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int& e : l) cin >> e;
    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int a = l[i];
            int b = l[j];
            int cnt = lower_bound(l.begin()+j+1, l.end(), a+b) - upper_bound(l.begin()+j+1, l.end(), -(a+b));
            ans += cnt;
        }
    }
    cout << ans << "\n";
}

int main(){
#ifdef VPAL
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    for (int test = 1; test <= t; test++) {
        solve(test);
    }
    return 0;
}

Measured memory_bytes: 256
def INT():
    return int(input())

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

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

S = list(input())
T = list(input())
ans = 0

for i in range(len(S)):
    if S[i] != T[i]:
        ans += 1
        
print(ans)

Measured memory_bytes: 76696
#include<stdio.h>
#include<string.h>
int main()
{ 
	char S[10],Sunny,Cloudy,Rainy;
	scanf("%s",S);
	if(strcmp(S,"Sunny")==0)
	{ 
		printf("Cloudy\n");
	}
    else if(strcmp(S,"Rainy")==0)
	{
		printf("Sunny\n");
	}
	else
	{
       printf("Rainy\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        for(int i=1;;i++){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }else{
            System.out.printf("Case %d: %d\n",i, x);
            }
        }
        sc.close();
    }
}


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

int main(void){
    int cnt[26] ={};
    string s;
    while(cin >> s){
        for(int i = 0; i < s.size(); i++){
            if(s[i] >= 'a' && s[i] <= 'z') cnt[s[i] - 'a']++;
            else if(s[i] >= 'A' && s[i] <= 'Z') cnt[s[i] - 'A']++;
        }
    }
    for(int i = 0; i < 26; i++) cout << char('a' + i) << " : " << cnt[i] << endl;
    return 0;
}


Measured memory_bytes: 3196
#include <vector>
#include <iostream>
#include <cmath>
#include <numeric>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int w,h,n,c=0;
    cin >> w >> h >> n;
    vector<int>x(n);
    vector<int>y(n);
    vector<int>a(n);
    int table[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            table[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]==1){
            for(int j=0;j<h;j++){
                for(int k=0;k<x[i];k++){
                    table[j][k]=1;
                }
            }
        }
        if(a[i]==2){
            for(int j=0;j<h;j++){
                for(int k=x[i];k<w;k++){
                    table[j][k]=1;
                }
            }
        }
        if(a[i]==3){
            for(int j=0;j<y[i];j++){
                for(int k=0;k<w;k++){
                    table[j][k]=1;
                }
            }
        }
        if(a[i]==4){
            for(int j=y[i];j<h;j++){
                for(int k=0;k<w;k++){
                    table[j][k]=1;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(table[i][j]==1){
                c++;
            }
        }
    }
    cout<<h*w-c;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();

	if(c<a){
		int temp = a;
		a=c;
		c=temp;
	}
	if(b>c){
		int temp = b;
		b=c;
		c=temp;
	}
	
	if(b<a){
		int temp = a;
		a=b;
		b=temp;
	}
	
	System.out.println(a+" "+b+" "+c);
	}


}

Measured memory_bytes: 26088
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] h = new long[N];
		for( int i=0; i<N; i++ ){
			h[i] = sc.nextLong();
		}
		int count = 0,maxium = 0;
		for( int i=1; i<N; i++ ){
			if( h[i]<=h[i-1] ){
				count++;
            }              
			if( h[i]>h[i-1] || i==N-1 ){
				maxium = Math.max(maxium,count);
				count = 0;
			}        
		}
		System.out.println(maxium);
	}
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   ll x,y;cin >>x>>y;
   ll g=__gcd(x,y);
   ll a=x/g,b=y/g;
   if(a%b==0){
    cout <<-1<< endl;
   }
   else cout <<x*a<< endl;
    return 0;
}


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

int main() {
  int64_t N, W;
  cin >> N >> W;
  auto w = vector<int64_t>(N);
  auto v = vector<int64_t>(N);
  for(int64_t i=0; i<N; ++i) {
    cin >> w[i] >> v[i];
  }
  auto dp = vector<int64_t>((N+1)*(W+1));
  fill(dp.begin(), dp.end(), int64_t(0));
  for(int64_t n=1; n<=N; ++n) {
    for(int64_t w0 = 0; w0 <= W; ++w0) {
      if (w0 - w[n-1] < 0) {
        dp[n*(W+1) + w0] = dp[(n-1)*(W+1) + w0];
      } else {
        dp[n*(W+1) + w0] = max(dp[(n-1)*(W+1) + w0], v[n-1] + dp[(n-1)*(W+1) + w0-w[n-1]]);
      }
    }
  }
  cout << dp[N*(W+1) + W] << endl;
  return 0;
}


Measured memory_bytes: 79104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

int main() {
	char S[16];
	int output = 1000;

	scanf("%s", S);

	for (int i = 0; i < strlen(S) - 2; i++) {
		char tmpStr[4];
		tmpStr[3] = '\0';
		strncpy(tmpStr, &S[i], 3);
		int tmp = atoi(tmpStr);
		tmp = abs(753 - tmp);
		output = (output > tmp) ? tmp : output;
	}

	//出力
	printf("%d", output);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<functional>
#include<iterator>
#include<math.h>

using namespace std;

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

	int h,w,d;
	cin >> h >> w >> d;
	int num;
	int x[h*w],y[h*w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> num;
			y[num-1] = i; x[num-1] = j;
		}
	}
	
	int dp[h*w] = {};
	for(int i=d;i<h*w;i++){
		dp[i] = dp[i-d] + abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
	}

	int q,l,r;
	cin >> q;
	for(int i=0;i<q;i++){
		cin >> l >> r;
		cout << dp[r-1] - dp[l-1] << "\n";
	}
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    vector< pair <int,int> > vect; 
  int n; cin>>n;
  int arr[n];
 for(int i=0;i<n;i++)  cin>>arr[i];

 
    for (int i=0; i<n; i++) 
        vect.push_back( make_pair(arr[i],i+1) ); 

    sort(vect.begin(), vect.end()); 

    for (int i=0; i<n; i++) 
    { 

        cout << vect[i].second <<" "; 
    } 
  
    return 0; 
} 

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
int main(void){
    int n;
    while(cin>>n,n){
        int l=0,r=0,t=0,ans=0;
        while(l<=n){
            if(n==t) ans++;
            if(n>=t){
                t+=++r;
            }else{
                t-=l++;
            }
        }
        cout<<ans-1<<endl;
    }
}

Measured memory_bytes: 2976
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;

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

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = K; i < N; i++) {
    if(A[i - K] < A[i]) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3988
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >>a >>b >>c;
    
    int count = 0;
    
    while(a <= b){
        if(c % a == 0){
            count++;
        }
        a++;
    }
    cout << count <<endl;
    
    return 0;
    
    
}


Measured memory_bytes: 3112
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 1000005;
const lo mod = 1000000007;

int n,m,b[li],k,flag,t,a[li],dp[li][5];
string s;
vector<int> v;

inline int f(int kac,int tur){
	//~ cout<<kac<<endl;
	//~ if(kac==1000)cout<<"**\n";
	int cevv=(tur==1?inf:0);
	if(kac<a[1] && tur==0)return 0;
	if(kac<a[1] && tur==1)return 1;
	//~ if(kac==a[1] && tur==0)return tur;
	//~ if(kac<a[1] && tur==1)return 1;
	if(~dp[kac][tur])return dp[kac][tur];
	for(int i=n;i>=1;i--){
		if(kac>=a[i]){
			if(tur==0)cevv=max(cevv,f(kac-a[i],!tur));
			if(tur==1)cevv=min(cevv,f(kac-a[i],!tur));
		}
	}
	return dp[kac][tur]=cevv;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%d %d",&n,&k);
	FOR scanf("%d",&a[i]);
	int cev=f(k,0);
	if(cev==1)printf("First\n");
	else printf("Second\n");
	//~ printf("%d\n",f(k,0));
	return 0;
}



Measured memory_bytes: 31112
# -*- coding: utf-8 -*-
from operator import itemgetter

n,m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(m)], key=itemgetter(1))

res = 0
s = 0
for a,b in ab:
    if a<=s<b:
        continue
    s = b-1
    res += 1

print(res)


Measured memory_bytes: 29920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int n, d;
    cin >> n >> d;
    float ans_infloat = n / ( d * 2.0 + 1);
    int ans = ceil(ans_infloat);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b,c,d,m1,m2;
	cin>>a>>b>>c>>d;
	m1=min(a,b);
	m2=min(c,d);
	cout<<m1+m2<<endl;
	return 0;
}

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

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i)) {
      count++;
    }
  }
  
  cout << count << endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char str[1000];
  int flg=0;
  int i;
  
  scanf("%s", &str);
  for(i=0; i<3; i++){
    if(str[i] == str[i+1]) flg=1;
  }
  if(flg==1){
    printf("Bad");
  }else{
    printf("Good");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),L = in();
    if(L+N-1>=0 && L <= 0){
        int sum = 0;
        REP(i,N){
            sum += i + L;
        }
        cout << sum << "\n";
    }else if(L >= 0){
        int sum = 0;
        REPS(i,N-1){
            sum += i + L;
        }
        cout << sum << "\n";
    }else{
        int sum = 0;
        REP(i,N-1){
            sum += i + L;
        }
        cout << sum << "\n";
    }
}

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

int main(){
	int N;
	cin >> N;
	if (N == 25)
		cout << "Christmas" << endl;
	if (N == 24)
		cout << "Christmas Eve" << endl;
	if (N == 23)
		cout << "Christmas Eve Eve" << endl;
	if (N == 22)
		cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#define maxn 1005
using namespace std;
typedef long long  LL;
map<string,int>mp;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
        map<string,int>::iterator it;
        int sum=0;
        for(it=mp.begin();it!=mp.end();++it)
        {
            int t=it->second;
            if(t%2==1)
                sum++;
        }
        cout<<sum<<endl;

}


Measured memory_bytes: 12544
/*
 *    author:  Gary Shih
 *    created: 2020-05-05 12:36:27
 */
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

// Debug {{{
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// }}}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  vector<long long> prefixSum(n);
  prefixSum[0] = a[0];
  for (int i = 1; i < n; ++i) prefixSum[i] = prefixSum[i - 1] + a[i];

  auto getSize = [&](int i, int j) {
    long long ans = prefixSum[j];
    if (i > 0) ans -= prefixSum[i - 1];
    return ans;
  };

  vector<vector<long long>> dp(n, vector<long long>(n));
  for (int length = 2; length <= n; ++length) {
    for (int i = 0; i < n - length + 1; ++i) {
      int j = i + length - 1;
      dp[i][j] = min(dp[i][i] + dp[i + 1][j], dp[i][j - 1] + dp[j][j]);
      for (int k = i + 1; k < j; ++k) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
      }
      dp[i][j] += getSize(i, j);
    }
  }

  for (int i = 0; i < n; ++i) debug(dp[i]);

  cout << dp[0][n - 1] << '\n';
}


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

int main(){
    vector<int> num(3);
    for(int i = 0; i < 3; i++){
        cin >> num[i];
    }

    sort(num.begin(), num.end());

    cout << num[2] * 10 + num[1] + num[0] << endl;

    return 0;
}

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

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

		final int INF = Integer.MAX_VALUE/2;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		int n = Integer.parseInt(line.substring(0,line.indexOf(" ")));
		int m = Integer.parseInt(line.substring(line.indexOf(" ")+1));

		line = br.readLine();
		String[] str = line.split(" ");
		int[] d = new int[m];
		for (int i=0; i<m; i++) {
			d[i] = Integer.parseInt(str[i]);
		}

		int[] dp = new int[n+1];
		Arrays.fill(dp,INF);
		dp[0] = 0;

		for (int i=0; i<=n; i++) {
			for (int j=0; j<m; j++) {
				if (0 <= i - d[j]) {
					dp[i] = Math.min(dp[i],dp[i-d[j]]+1);
				}
			}
		}

		System.out.println(dp[n]);

		br.close();
	}
}

Measured memory_bytes: 19488
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int d = sc.nextInt();
        int x2000 = sc.nextInt();

        int x2001 = r*x2000 - d;
        int x2002 = r*x2001 - d;
        int x2003 = r*x2002 - d;
        int x2004 = r*x2003 - d;
        int x2005 = r*x2004 - d;
        int x2006 = r*x2005 - d;
        int x2007 = r*x2006 - d;
        int x2008 = r*x2007 - d;
        int x2009 = r*x2008 - d;
        int x2010 = r*x2009 - d;
        System.out.println(x2001);
        System.out.println(x2002);
        System.out.println(x2003);
        System.out.println(x2004);
        System.out.println(x2005);
        System.out.println(x2006);
        System.out.println(x2007);
        System.out.println(x2008);
        System.out.println(x2009);
        System.out.println(x2010);
    }
}





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

int main() {
  int n, m, s = 0;
  cin >> n >> m;
  vector<int> v(m), d(m-1);
  rep(i, m) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, m-1){
    d[i] = v[i+1] - v[i];
    s += d[i];
  }
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  rep(i, min(m-1, n-1)) s -= d[i];
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT32_MAX;

ll i,j;





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

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

int main(void){
    int n;
    cin>>n;
    vector<vector<bool> > jud(4,vector<bool>(13,false));
    vector<char> s(52);
    vector<int> a(52);
    for(int i=0;i<n;i++){
        cin>>s.at(i)>>a.at(i);
    }
    for(int i=0;i<n;i++){
        if(s.at(i)=='S'){
            jud.at(0).at(a.at(i)-1)=true;
        }
        if(s.at(i)=='H'){
            jud.at(1).at(a.at(i)-1)=true;
        }
        if(s.at(i)=='C'){
            jud.at(2).at(a.at(i)-1)=true;
        }
        if(s.at(i)=='D'){
            jud.at(3).at(a.at(i)-1)=true;
        }
    }
        for(int j=0;j<13;j++){
            if(!jud.at(0).at(j))cout<<"S"<<" "<<j+1<<endl;
        }
        for(int j=0;j<13;j++){
            if(!jud.at(1).at(j))cout<<"H"<<" "<<j+1<<endl;
        }
        for(int j=0;j<13;j++){
            if(!jud.at(2).at(j))cout<<"C"<<" "<<j+1<<endl;
        }
        for(int j=0;j<13;j++){
            if(!jud.at(3).at(j))cout<<"D"<<" "<<j+1<<endl;
        }
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y

using namespace std;
typedef pair<int, int> PII;

int main() {
	FAST;

	int n,i;
	cin >> n >> i;

	cout << n-i+1 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
 int A,B,K;
 cin>>A>>B>>K;
 int a;
 for(int i=0;i<K;i++){
     if(i%2==0){
       if(A%2==1)  {A=A-1;}
       a=A/2;
       A=A-a;
       B=B+a;
     }
     else {
         if(B%2==1) {B=B-1;}
         a=B/2;
         B=B-a;
         A=A+a;
     }
 }
 cout<<A<<' '<<B;
 return 0;
}


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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0; i<n; i++)cin>>a[i];
	sort(a.rbegin(), a.rend());
	int alice=0,bob=0;
	for(int i=0; i<n; i++){
		if(i%2==0)alice+=a[i];
		else bob+=a[i];
	}
	cout<<alice-bob<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=100005;
const int MOD=1e9+7;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==0) return 1;
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
int n,m;
int a[N],b[N];
struct qq
{
	int l,r;
	qq () {}
	qq (int _l,int _r)	{l=_l;r=_r;}
}c[N];int cnt=0;
int d[N];int tot=0;
bool cmp (qq x,qq y)	{return x.l==y.l?x.r>y.r:x.l<y.l;}
int f[N];
int lb (int x)	{return x&(-x);}
void modify (int x,int c)	{while (x<=tot){f[x]=add(f[x],c);x+=lb(x);}}
int query (int x)	{int lalal=0;while (x>0){lalal=add(lalal,f[x]);x-=lb(x);}return lalal;}
int main()
{
	scanf("%d%d",&n,&m);
	for (int u=1;u<=n;u++) scanf("%d",&a[u]);
	for (int u=1;u<=m;u++) scanf("%d",&b[u]);
	for (int u=1;u<=n;u++)
	{
		if (a[u]>b[1]&&a[u]<b[m])
		{
			int x=lower_bound(b+1,b+1+m,a[u])-b;
			if (b[x]==a[u]) continue;
			//printf("%d %d %d\n",a[u],b[x],b[x+1]);
			c[++cnt]=qq(a[u]-b[x-1],b[x]-a[u]);
			d[++tot]=b[x]-a[u];
		}
	}
	sort(d+1,d+1+tot);
	tot=unique(d+1,d+1+tot)-d-1;
	for (int u=1;u<=cnt;u++) c[u].r=lower_bound(d+1,d+1+tot,c[u].r)-d;//for (int u=1;u<=cnt;u++) printf("%d %d\n",c[u].l,c[u].r);
	sort(c+1,c+1+cnt,cmp);
	int ans=1;
	for (int u=1;u<=cnt;u++)
	{
		if (c[u].l==c[u-1].l&&c[u].r==c[u-1].r) continue;
		int t=query(c[u].r-1)+1;
		//printf("YES:%d %d\n",u,t);
		ans=add(ans,t);
		modify(c[u].r,t);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<cstdio> 
#include<cstring>
#define chkmin(x,y) x=min(x,y)
#define ll long long
using namespace std;
const int mod=1000000007;
int n,m,k,tim,top=0,low[55],dfn[55];
bool vis[55];
ll mi[210],ans=1,fac[210],ifac[210],inv[210];
struct edge
{
	int t;bool vis;
	edge *next,*rev;
}*con[55],*st[110];
void ins(int x,int y)
{
	edge *p=new edge;
	p->t=y;p->vis=0;
	p->next=con[x];
	con[x]=p;
}
ll ksm(ll a,int b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
void tarjan(int v,edge *fro)
{
	dfn[v]=low[v]=++tim;
	for(edge *p=con[v];p;p=p->next)
		if(!p->vis&&!p->rev->vis)
		{
			st[++top]=p;p->vis=p->rev->vis=1;
			if(!dfn[p->t])
			{
				tarjan(p->t,p);
				chkmin(low[v],low[p->t]);
				if(low[p->t]>=dfn[v])
				{
					bool cir=1;int cnt=0;ll cal=0;
//					for(int i=1;i<=n;i++)
//						cout<<vis[i]<<' ';
//					cout<<endl;	
					for(int i=top;st[i+1]!=p;cnt++,i--)
						if(vis[st[i]->t]) cir=0;
						else vis[st[i]->t]=1;		
					if(cir)
					{
						for(int i=0;i<cnt;i++)	
							cal=(cal+mi[gcd(cnt,i)])%mod;
						cal=cal*inv[cnt]%mod;	
					}
					else cal=fac[cnt+k-1]*ifac[cnt]%mod*ifac[k-1]%mod;
					//cout<<cir<<endl;
					ans=ans*cal%mod;
					for(;st[top+1]!=p;top--) vis[st[top]->t]=0;
				}
			}
			else chkmin(low[v],dfn[p->t]);
		}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	mi[0]=1;
	for(int i=1;i<=m;i++)
		mi[i]=mi[i-1]*k%mod;
	fac[0]=1;
	for(int i=1;i<=m+k;i++)
		fac[i]=fac[i-1]*i%mod;
	ifac[m+k]=ksm(fac[m+k],mod-2);
	
	for(int i=m+k-1;i>=0;i--)
		ifac[i]=ifac[i+1]*(i+1)%mod;
	for(int i=1;i<=m+k;i++)
		inv[i]=ifac[i]*fac[i-1]%mod;			
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
		con[x]->rev=con[y];con[y]->rev=con[x];
	}
	for(int i=1;i<=n;i++)
		if(!dfn[i]) tarjan(i,NULL);
	printf("%lld",ans);	
	return 0;
}
/*7 7 100 
1 2
2 3
3 4
4 1
1 5
5 6
1 7*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef unsigned long long ll;
typedef pair<int,int>PI;
typedef pair<int,pair<int,int>>PII;
const int mx=4e6+10;
bitset<mx> dp;
int main()
{
    int k,in,sum=0;
    cin>>k;
    dp[0] = 1;
    for (int i=0;i<k;i++)
    {
        cin>>in;
        dp = dp|(dp<<in);
        sum+=in;
    }
    sum=(sum+1)/2;
    for (int i=sum;i<mx;i++)
    {
        if (dp[i])
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    ll n, d;
    cin >> n >> d;
    ll x, y;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        if (sqrt(x*x + y*y) <= d) res++;
    }
    cout << res << endl;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll N = 1e6 + 10;
ll p[3];  
ll g[3];  
ll a[100007];
 
int main(){
    ll n;
    ll c=0;
    int t=1;
    int l;   
    cin >> n;
  
 
    for (int i = 0; i < n; i++) cin >> a[i];
    
 
    p[0]=a[0];
 
    for (int i = 0; i < n - 1; i++){
        l=0;
    	for (int j = 0; j < t; j++){
            if(a[i+1]!=p[j]){
                l++;
            }
            else{
                g[j]++;
            }
        }
        if(l==t){
            p[t]=a[i+1];
            t++;
        }
        if(t==4){
            c++;
            break;
        }
    }
 
    if(t==1){
        if(a[0]!=0){
            c++;
        }
    }
    if(t==2){
        if(p[0]==0){
            if(p[1]!= (p[0] xor p[1]) || (g[0]+1)*2!=g[1]+1){
                c++;
            }
        }
        else if(p[1]==0){
            if(p[0]!= (p[0] xor p[1]) || (g[1]+1)*2!=g[0]+1){
                c++;
            }
        }
        else{
            c++;
        }
    }
    if(t==3){
        if(p[0]!= (p[1] xor p[2]) || g[0]!=g[1] || g[1]!=g[2] || g[2]!=g[0]){
            c++;
        }
    }
    if(c==0){
        cout << "Yes" << endl;
    }
    else{
        cout <<  "No" << endl;
    }
}

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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back

signed main() {
    string a, b;
    cin >> a >> b;
    string x, y;
    for(int i = 0; i < (b[0] - '0'); i++) {
        x += a;
    }
    for(int i = 0; i < (a[0] - '0'); i++) {
        y += b;
    }
    cout << min(x, y);
}


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

typedef long long  LL;
int d,n,m,ans;
LL a[20],s[20];

void dfs(int x,LL d,int cnt)
{
	if (x>m)  {ans+=cnt*(n&1?10:1);  return;}
	for (int i=-9; i<=9; i++)
		if ((-9*s[x+1]<=d-i*a[x])&&(d-i*a[x]<=9*s[x+1]))
			dfs(x+1,d-i*a[x],cnt*(10-abs(i)-(x==1)*(i>=0)));
}

void work()
{
	scanf("%d",&d);
	for (n=2; n<20; n++)
		{
			LL x=1,y=1;
			m=n/2;
			for (int i=1; i<n; i++)  x*=10;
			for (int i=1; i<=m; i++)  a[i]=x-y,x/=10,y*=10;
			for (int i=m; i; i--)  s[i]=s[i+1]+a[i];
			dfs(1,d,1);
		}
	printf("%d",ans);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

void dfs(ll s, ll cur_sum, ll parent)
{
    ans[s] = update[s] + cur_sum;
    for(auto u : adj[s])
    {
        if(u == parent) continue;
        dfs(u, update[s]+cur_sum, s);
    }
}

int main()
{
    int k, x;
    cin >> k >> x;

    for(int i=x-k+1;i<=x+k-1;i++)
        cout << i << " ";

    cout << "\n";    
}




Measured memory_bytes: 6016
/*||>>>> Praveen Ojha <<<<>>>> 27 July 2019 <<<<>>>> 17:28:27 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
   int n;
   cin>>n;
   vi a(n),b(n);
   for(int i=0;i<n;i++)
    {
        cin>>a[i],b[i]=a[i];
    }
    sort(all(a));
    int cnt=0;
    for(int i=0;i<n;i++)
        if(a[i]!=b[i])
            cnt++;
    if(cnt<=2)
        cout<<"YES\n";
    else
        cout<<"NO\n";
return 0;
}

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

using namespace std;

int fact(int n, int m);

int main() {
	int a, b;
	cin >> a >> b;
	int sum = fact(a, a - 2) + fact(b, b - 2);
	cout << sum / 2;
	
	return 0;
}

int fact(int n, int m) {
	if (n <= m) {
		return 1;
	}
	else {
		return n * fact(n - 1, m);
	}
}

Measured memory_bytes: 256