akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
	int x, y, i,z;
	for (i = 0; i < 3000; i++) {
		scanf("%d %d", &x, &y);
		if ((x == 0) && (y == 0)) {
			break;
		}

		if (x>y) {
			z = x;
			x = y;
			y = z;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}



Measured memory_bytes: 2028
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a, T b) { return a<b?(a=b,true):false; }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define bs2int(bs) (int)((bs).to_ulong())
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

ll n,a,b;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n>>a>>b;
  ll pre = 0; cin>>pre;
  ll ans = 0;
  FOR(i,1,n)
  {
    ll x; cin>>x;
    ans += min(a*(x-pre), b);
    pre = x;
  }
  cout << ans << endl;
}


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

int main(){
  
  string n;
  cin >> n;
  
  if(n.at(n.size()-1) == '3'){
    cout << "bon" << endl;
  }
  else if( n.at(n.size()-1) == '0' || n.at(n.size()-1) == '1' || n.at(n.size()-1) == '6' || n.at(n.size()-1) == '8'){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
  
}


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

int main() {
  std::string x(1, ' ');
  scanf("%s", &x[0], x.size());
  if (x[0] == 'a' || x[0] == 'e' || x[0] == 'i' || x[0] == 'o' || x[0] == 'u')
    printf("vowel");
  else
    printf("consonant");
}


Measured memory_bytes: 256
// Title: 
// URL: 
// {{{
#include <bits/stdc++.h>
using namespace std;
using ll = long long int; // int_fast64_t;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
constexpr int INF = 1 << 30;  // 1073741824 2倍すると -2147483648
constexpr ll INFL = 1l << 62; // 4611686018427387904 2倍すると-0.9*10^18
constexpr int dx4[] = {0, 1, 0, -1};
constexpr int dy4[] = {1, 0, -1, 0};
constexpr int dx8[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy8[] = {0, -1, 0, 1, -1, -1, 1, 1};
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, 0, (n))
// }}}
int main() {
	int X, Y;
	cin >> X >> Y;
	int r = 0;
	if (X <= 3) r += 100000 * (4-X);
	if (Y <= 3) r += 100000 * (4-Y);
	if (X == 1 && Y == 1) r += 400000;
	cout << r << endl;
  return 0;
}
/* vim: set fdm=marker: */


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    string S;
    cin >> S;

    u64 ans[13];
    u64 temp[13];
    u64 offset[6] = {1, 10, 9, 12, 3, 4};
    int mod;

    int N = S.size();
    if (S[N - 1] == '?')
    {
        rep (i, 10)
        {
            ans[i] = 1;
        }
        ans[10] = 0; ans[11] = 0; ans[12] = 0;
    }
    else
    {
        rep (i, 13)
        {
            ans[i] = 0;
        }
        ans[S[N - 1] - '0'] = 1;
    }

    for (int i = N - 2; i >= 0; --i)
    {
        if (S[i] == '?')
        {
            rep (j, 13)
            {
                temp[j] = 0;
            }
            rep (j, 10)
            {
                mod = (j * offset[(N - 1 - i) % 6]) % 13;
                rep (k, 13)
                {
                    temp[k] +=  ans[(k + 13 - mod) % 13] % MOD;
                    temp[k] %= MOD;
                }
            }
            rep (j, 13)
            {
                ans[j] = temp[j];
            }
        }
        else
        {
            mod = ((S[i] - '0') * offset[(N - 1 - i) % 6]) % 13;
            rep (j, 13)
            {
                temp[j] = 0;
            }
            rep (j, 13)
            {
                temp[j] += ans[(j + 13 - mod) % 13] % MOD;
                temp[j] %= MOD;
            }
            rep (j, 13)
            {
                ans[j] = temp[j];
            }
        }
    }

    cout << ans[5] << "\n";

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    int k ; cin >> k ;
    string s ; cin >> s ;
    int l = s.size() ;
    if(l > k) cout << s.substr(0, k) << "...\n" ;
    else cout << s << endl ;
}


Measured memory_bytes: 3628
// Aizu Vol-0 0086: Patrol
// 2017.8.5

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int a, b, i, n, f, c[105];

	while (scanf("%d%d", &a, &b) == 2) {
		memset(c, 0, sizeof(c)), n = 0;
		do {
			if (a != b) c[a]++, c[b]++;
			if (a > n) n = a;
			if (b > n) n = b;
			scanf("%d%d", &a, &b);
		} while (a);
		f = 0;
		if ((c[1] & 1) && (c[2] & 1)) {
			for (i = 3; i <= n; i++) if (c[i] & 1) break;
			if (i > n) f = 1;
		}
		puts(f ? "OK" : "NG");
	}
	return 0;
}

Measured memory_bytes: 580
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = CodeForces.FastReader()
    var d = fs.nextInt()
    var t = fs.nextInt()
    var s = fs.nextInt()
    if(d/s.toDouble() <= t) println("Yes")
    else println("No")

}

class CodeForces {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

        fun nextLine(): String {
            var str = ""
            try {
                str = br.readLine()
            } catch (e: IOException) {
                e.printStackTrace()
            }
            return str
        }

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


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

int main(){
	int N,M,unk,ans=0;
	cin>>N>>M;
	int K[N],A[N][M];
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			A[i][j]=0;
		}
	}
	for(int i=0;i<N;i++){
		cin>>K[i];
		for(int j=0;j<K[i];j++){
			cin>>unk;
			A[i][unk]=1;
		}
	}
	for(int i=0;i<=M;i++){
		for(int j=0;j<N;j++){
			if(A[j][i]==0){break;}
			if(j==N-1 && A[j][i]==1){ans++;}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

bool match( const string& s, const string& t, int pos ) {
	if( pos + t.size() > s.size() ) {
		return false;
	}

	for( int i = 0; i < t.size(); ++i ) {
		if( s[pos+i] != t[i] && s[pos+i] != '?' ) {
			return false;
		}
	}

	return true;
}

int main() {
	ios_base::sync_with_stdio( false );

	string s, t;
	cin >> s >> t;

	bool res = false;

	for( int i = (int)(s.size()-t.size()); i >= 0; --i ) {
		res = match( s, t, i );

		if( res ) {
			s.replace( i, t.size(), t );
			break;
		}
	}

	if( res ) {
		replace( s.begin(), s.end(), '?', 'a' );
		cout << s << endl;
	}
	else {
		cout << "UNRESTORABLE\n";
	}

	return 0;
}


Measured memory_bytes: 256
MOD = 10**9+7
MAX = 10**5+1

n,x = map(int,input().split())
s =  list(map(int,input().split()))

fac = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
for i in range(2,MAX):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD - inv[MOD%i]*(MOD // i)%MOD

s.sort()
dp = [0 for i in range(x+1)]
for i in range(x+1):dp[i] = (i%s[0])*fac[n-1]%MOD

for i in range(1,n):
    dpp = dp[:]
    for j in range(x+1):
        dpp[j] = (dp[j]+dp[j%s[i]]*inv[i])%MOD
    dp = dpp


print(dp[x])

Measured memory_bytes: 88304
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  string s; cin>>s;
  int a,b;
  rep(i,s.size()){
    if(s[i]=='A'){
      a=i;break;
    }
  }
  rep(i,s.size()){
    if(s[s.size()-1-i]=='Z'){
      b=s.size()-1-i;break;
    }
  }
  // string ans=s.substr(i,b-i+1);
  cout<<b-a+1<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define pc putchar
//#define mp std::make_pair
#define pr std::pair<int,int>
#define gc() getchar()
#define ID(x,y) ((x-1)*m+y)
typedef long long LL;
const int N=405,Way[]={1,0,-1,0,1};

int n,m,mp[N][N],vis[N][N];

inline int read()
{
	int now=0,f=1;register char c=gc();
	for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now*f;
}
LL DFS(int X,int Y)
{
	static int qx[N*N],qy[N*N];
	int h=0,t=1,c[2]={0,0}; qx[0]=X, qy[0]=Y, vis[X][Y]=1;
	while(h<t)
	{
		int x=qx[h],y=qy[h++];
		++c[mp[x][y]];
		for(int i=0,xn,yn; i<4; ++i)
			if((xn=x+Way[i]) && xn<=n && (yn=y+Way[i+1]) && yn<=m && !vis[xn][yn] && mp[xn][yn]^mp[x][y])
				vis[xn][yn]=1, qx[t]=xn, qy[t++]=yn;
	}
	return 1ll*c[0]*c[1];
}

int main()
{
	static char s[N];
	n=read(),m=read();
	for(int i=1; i<=n; ++i)
	{
		scanf("%s",s+1);//black:0 white:1
		for(int j=1; j<=m; ++j) mp[i][j]=s[j]=='.';
	}
	LL ans=0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j)
			if(!vis[i][j] && !mp[i][j]) ans+=DFS(i,j);
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 2688
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
D=list(map(int,input().split()))
M=max(D)
l=[0]*(M+1)
for i in D:
    l[i]+=1
if l[0]==1 and D[0]==0:
    a=1
    for i in range(M):
        a*=pow(l[i],l[i+1],998244353)
    a%=998244353
    print(a)
else:
    print(0)

Measured memory_bytes: 14020
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
Int mod = 1e9+7;

int main() {
    Int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if (s[k - 1] == 'A') {
        s[k - 1] = 'a';
    }
    else if (s[k - 1] == 'B') {
        s[k - 1] = 'b';
    }
    else if (s[k - 1] == 'C') {
        s[k - 1] = 'c';
    }
    dump(s);
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
typedef pair<int, int> P;


int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, H, W, N, K,h,w,C;
	cin >> N >> M >> C;
	vector<int>B(M);
	vector<int>A(M);
	REP(i, 0, M) {
		cin >> B[i];
	}
	cc = 0;
	REP(i, 0, N) {
		sum = 0;
		REP(j, 0, M) {
			
			cin >> A[j];
			sum += A[j] * B[j];
		}
		sum += C;
		
		if (sum > 0) {
			cc++;
		}
	}
	output(cc);
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int n;
string s;

int main(){
    cin >> n;
    cin >> s;
    int cnt = 0;

    for (size_t i = 0; i < n; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
        cnt += 1;
      }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    //unordered_map<long long, int, custom_hash>
    //gp_hash_table<long long, int, custom_hash>
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	
	int n, m; cin>>n>>m;
	if(n%2==1){
		for(int i = 1; i<=m; i++){
			cout<<i<<' '<<n - i<<endl;
		}
	}
	else{ 
		int fg = 1, r = n, l = 1;
		for(int i = 1; i<=m; i++){
			if(r-l<=n/2 && fg){
				fg = 0; r--;
			}
			cout<<l<<' '<<r<<endl;
			l++;
			r--;
		}
	}
	
	return 0;
}

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

int main() {
  		int N, M;
  		cin >> N >> M;
  		vector<int> Ans(N,0);
  		vector<int> road(2*M);
        for (int i=0; i<2*M; i++){
          		cin >> road[i];
        }
  	 	for (int i=0; i<2*M; i++){
          		Ans[road[i]-1]++;
        }
  		for (int i=0; i<N; i++){
          		cout << Ans[i] << endl;
        }
}


Measured memory_bytes: 3644
n,k=map(int,input().split())
p=list(map(int,input().split()))

def kitai(n):
  result = 0
  for i in range(1,n+1):
    result += i
  return result/n

s=[0]*(n+1)
for i in range(n):
  s[i+1] = s[i] + p[i]

resi = 0
tmp = 0
for i in range(n-k+1):
  if s[i+k]-s[i] > tmp:
    resi = i
    tmp = s[i+k]-s[i]

result = 0
for i in range(resi,k+resi):
  result += kitai(p[i])
print(result)

Measured memory_bytes: 99072
#include <cstdio>

int main(){
	long long S;
	scanf("%lld", &S)+1;

	int x1 = 0;
	int y1 = 0;
	int x2 = 1000000000;
	int y2 = 1;
	int x3, y3;

	y3 = ((S - 1) / x2) + 1;
	x3 = x2 * y3 - S;

	printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

struct LowestCommonAncestor {
    struct edge {
        int to;
        ll no;

        bool operator!=(const edge &e) const {
            return no != e.no;
        }
    };

    vector<vector<edge>> G;
    vector<int> depth;
    vector<edge> parent;
    const int root;

    LowestCommonAncestor(int V, int root)
        : G(V), depth(V), root(root), parent(V) {}

    void add_edge(int u, int v, int idx) {
        G[u].push_back({v, 1LL << idx});
        G[v].push_back({u, 1LL << idx});
    }

    void dfs(int v, edge par, int d) {
        parent[v] = par;
        depth[v] = d;
        for (edge &e : G[v]) {
            if (e != par) dfs(e.to, {v, e.no}, d + 1);
        }
    }

    void setup() {
        dfs(root, {-1, -1}, 0);
    }

    void search_path(int u, int v, ll &e) {
        if (depth[u] > depth[v]) swap(u, v);
        while (depth[v] != depth[u]) {
            e |= parent[v].no;
            v = parent[v].to;
        }
        while (u != v) {
            e |= parent[v].no;
            e |= parent[u].no;
            v = parent[v].to;
            u = parent[u].to;
        }
        return;
    }
};

void solve() {
    int n;
    cin >> n;
    LowestCommonAncestor lca(n, 0);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        lca.add_edge(a, b, i);
    }
    lca.setup();
    int m;
    cin >> m;
    vector<pii> M(m);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        M[i] = {u, v};
    }
    ll ans = 0;
    rep(bit, 1 << m) {
        int sign = __builtin_popcount(bit) & 1 ? -1 : 1;
        ll e = 0LL;
        rep(i, m) {
            if ((bit >> i & 1) == 0) continue;
            lca.search_path(M[i].fi, M[i].se, e);
        }
        int num = __builtin_popcountll(e);
        ans += sign * (1LL << (n - 1 - num));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3640
// Running Offline
// g++ tester.cpp
// ./a.out
//#include "/Users/manasgupta/Desktop/stdc++.h"

 #include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define float double
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
#define inf 1e9
#define EPS 1e-6
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FILEIO(name1, name2) \
    freopen(name1".txt","r",stdin); \
    freopen(name2".txt","w",stdout);

const int N=105;
const int mod = 1000000007;

int power(int a, int b, int c)
{
	int res=1;
	while (b)
	{
		if (b&1) res=(res*a)%c;
		a=(a*a)%c;
		b=b>>1;
	}
	return res;
}

int n,k;
int a[N];
int dp[100005];

signed main()
{
	IOS;
	cin>>n>>k;
	int m=1e9;
	for (int i=1; i<=n; i++) 
	{
		cin>>a[i]; 
		m=min(m, a[i]);
	}
	for (int i=0; i<m; i++) dp[i]=1;
	for (int i=m; i<=k; i++)
	{
		int flag=0;
		for (int j=1; j<=n; j++)
		{
			if (a[j]>i)
			{

			}
			else
			{
				if (dp[i-a[j]]==1) flag=1;
			}
		}
		if (flag==1)
		{
			dp[i]=0;
		}
		else
		{
			dp[i]=1;
		}
		// cout<<i<<" "<<dp[i]<<endl;
	}
	if (dp[k]==0)
	{
		cout<<"First"<<endl;
	}
	else
	{
		cout<<"Second"<<endl;
	}
    return 0;
}





Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <queue>
#include <complex>
using namespace std;
typedef complex<double> P;
static const double EPS = 1e-6;
inline double cross(const P& a, const P& b) { return a.real()*b.imag() - b.real()*a.imag(); }

struct line/*{{{*/
{
  P a, b;
  line() {}
  line(const P& p, const P& q) : a(p), b(q) {}
};/*}}}*/

struct segment/*{{{*/
{
  P a, b;
  segment() {}
  segment(const P& x, const P& y) : a(x), b(y) {}

  inline bool intersects(const line& ln) const
  {
    return cross(ln.b - ln.a, a - ln.a) * cross(ln.b - ln.a, b - ln.a) < EPS;
  }

  inline P intersection(const line& ln) const
  {
    const P x = b - a;
    const P y = ln.b - ln.a;
    return a + x*(cross(y, ln.a - a))/cross(y, x);
  }
};/*}}}*/

int main()
{
  int N;
  while (scanf("%d", &N) != EOF && N != 0) {
    int vw, vc;
    scanf("%d %d", &vw, &vc);
    vector<P> ps;
    for (int i = 0; i < N; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      ps.push_back(P(x, y));
    }

    vector<vector<pair<int,double> > > g(3*N);
    for (int i = 0; i < N-1; i++) {
      g[3*i].push_back(make_pair(3*(i+1), abs(ps[i+1] - ps[i])/vw));
    }
    for (int i = 0; i < N; i++) {
      if (i > 0 && ps[i-1].imag() > ps[i].imag()) {
        // left edge
        const line ln(ps[i], ps[i] + P(1, 0));
        for (int j = i-2; j >= 0; j--) {
          const segment s(ps[j], ps[j+1]);
          if (s.intersects(ln)) {
            const P p = s.intersection(ln);
            const int n = 3*i+1;
            g[3*j].push_back(make_pair(n, abs(p - ps[j])/vw));
            g[n].push_back(make_pair(3*i, abs(ps[i] - p)/vc));
            break;
          }
        }
      }
      if (i < N-1 && ps[i].imag() < ps[i+1].imag()) {
        // right edge
        const line ln(ps[i], ps[i] + P(1, 0));
        for (int j = i+1; j < N-1; j++) {
          const segment s(ps[j], ps[j+1]);
          if (s.intersects(ln)) {
            const P p = s.intersection(ln);
            const int n = 3*i+2;
            g[3*i].push_back(make_pair(n, abs(p - ps[i])/vc));
            g[n].push_back(make_pair(3*(j+1), abs(ps[j+1] - p)/vw));
            break;
          }
        }
      }
    }

    static const double INF = 1e10;
    vector<double> dist(3*N, INF);
    dist[0] = 0;
    priority_queue<pair<double,int> > q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
      const double c = -q.top().first;
      const int n = q.top().second;
      q.pop();
      if (n == 3*(N-1)) {
        printf("%.6f\n", c);
        break;
      }
      if (c > dist[n]) {
        continue;
      }
      for (vector<pair<int,double> >::const_iterator it = g[n].begin(); it != g[n].end(); ++it) {
        const int m = it->first;
        const double cc = c + it->second;
        if (cc < dist[m]) {
          dist[m] = cc;
          q.push(make_pair(-cc, m));
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int a,b,c,n;
	n=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b)	n=n+0;
	else	n++;
//	printf("%d\n",n);
	if(a==c)	n=n+0;
	else	n++;
//	printf("%d\n",n);
	if(b==c)	n=n+0;
	else	n++;
	if(n==0)	n++;
	printf("%d\n",n);
	return 0;
}	

Measured memory_bytes: 128
#include <stdio.h>

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

int
main (void)
{
  unsigned a, b;
  unsigned buf;
  while (scanf ("%d%d", &a, &b) != EOF)
    {
      if (a > b)
	{
	  a ^= b;
	  b ^= a;
	  a ^= b;
	}
      buf = gcd (a, b);
      printf ("%d ", buf);
      printf ("%d\n", a * (b / buf));
    }
  return 0;
}

Measured memory_bytes: 596
from collections import deque
s = input()
Q = int(input())
q = [list(input().split()) for _ in range(Q)]

ans = deque(s)
ok = True
for v in q:
  if v[0] == "1":
    if ok: ok = False
    else: ok = True
  else:
    if v[1] == "1":
      if ok: ans.appendleft(v[2])
      else: ans.append(v[2])
    else:
      if ok: ans.append(v[2])
      else: ans.appendleft(v[2])

ans = list(ans)
if not ok: ans = ans[::-1]
print("".join(ans)) 

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll dp[300*300+10];
ll dy[300*300+10];
ll dx[300*300+10];

int main(int argc, char **argv)
{
	ll H, W, D; cin >> H >> W >> D;
	REP(h, H)REP(w, W)
	{
		ll a; cin >> a;
		dy[a] = h;
		dx[a] = w;
	}

	memset(dp, 0, sizeof dp);

	for (ll i = D+1; i <= H*W; ++i)
	{
		ll k = i - D;
		dp[i] = dp[k] + abs(dy[i] - dy[k]) + abs(dx[i] - dx[k]);
	}

	ll Q; cin >> Q;
	REP(_, Q)
	{
		ll a, b; cin >> a >> b;
		std::cout << dp[b] - dp[a] << std::endl;
	}
}

Measured memory_bytes: 3200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author CompuWare
 */

#include <bits/stdc++.h>

using namespace std;

class ERedScarf {
public:
    void solve(istream &in, ostream &out) {
        int c;
        in >> c;
        vector<int> v(c);
        int64_t res = 0;
        bool f = 1;
        for (int i = 0; i < c; i++) {
            in >> v[i];
            if (f) {
                res = v[i];
                f = 0;
            }
            else res ^= v[i];
        }
        for (int i = 0; i < c; i++) {
            out << abs((res ^ ~v[i]) + 1) << " ";
        }
    }
};


int main() {
    ERedScarf solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4044
import sys
import os
import math

N = int(input())
T = [0 for _ in range(N)]
A = [0 for _ in range(N)]
for i in range(N):
    t,a = list(map(int,input().split()))
    T[i] = t
    A[i] = a

for i in range(1,N):
    times = max( ( (T[i-1]+T[i]-1) // T[i] ) ,( (A[i-1]+A[i]-1) // A[i] ) )
    T[i] = T[i]*times
    A[i] = A[i]*times
print(T[N-1]+A[N-1])


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
  int box[101][101]={};
  int r,c,x,y,v;
  cin>>r>>c;
  for(y=0;y<r;y++){
    for(x=0;x<c;x++){
      cin>>v;
      box[y][x]=v;
      box[y][c]=box[y][c]+v;
    }
  }
  for(x=0;x<c;x++){
    for(y=0;y<r;y++){
      box[r][x]=box[r][x]+box[y][x];
    }
  }
  for(x=0;x<c;x++){
    box[r][c]=box[r][c]+box[r][x];
  }
  for(y=0;y<=r;y++){
    for(x=0;x<=c;x++){
      if(x<c){
	cout<<box[y][x]<<" ";
      }
      if(x==c){
	cout<<box[y][c]<<endl;
      }
    }
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<ll> G[101010];
ll res = 0;
ll N, K;

ll dfs(ll now, ll par){
	ll depth = 1;
	REP(i, G[now].size()){
		ll next = G[now][i];
		depth = max(dfs(next, now)+1, depth);
	}
	if(depth>=K && par != 0 && now != 0){
		res++;
		depth = 0;
	}
	return depth;
}

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

    cin >> N >> K;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    if(a[0] != 1) res++;
    REP(i, N){
    	if(i==0) continue;
    	G[a[i]-1].push_back(i);
    }
    dfs(0, -1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 14336
import itertools
from collections import Counter
D, G = map(int, input().split())
P = [list(map(int, input().split())) for i in range(D)]
min_num = 10**8

judge_list = list(itertools.product([0, 1, 2], repeat=D)) #0:中途半端に解く 1:一問も解かない 2: 全部解く


for judge in judge_list:
    score = 0
    num = 0
    d = Counter() #インスタンスを生成
    d.update(judge)
    if (d[0] <= 1):
        for i in range(1, len(judge) + 1):
            if score >= G:
                break

            if judge[-i] == 1:
                pass

            if judge[-i] == 2:
                score += P[-i][0] * (D - i + 1) * 100 + P[-i][1]
                num += P[-i][0]

            if (judge[-i] == 0):
                for j in range(P[-i][0]):
                    if score >= G:
                        break
                    score += 100 * (D - i + 1)
                    num += 1

        if score >= G:
            min_num = min(num, min_num)

print(min_num)

Measured memory_bytes: 11508
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> H_ {};
    for (int i { 0 }; i < N; ++i) {
        int tmp;
        cin >> tmp;
        H_.push_back(tmp);
    }

    int maxLength { 0 };

    int startPos { 0 };
    for (int i { 1 }; i < N; ++i) {
        int current = H_[i];
        int prevPos = i-1;
        int prev = H_[prevPos];

        if (prev < current) {
            maxLength = max({ maxLength, prevPos - startPos });
            startPos = i;
        }
    }

    maxLength = max({ maxLength, (N - 1) - startPos});


    cout << maxLength << endl;

    return 0;
}


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

using namespace std;


int main(void) {
	int N;
	cin >> N;

	vector <int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v.begin(), v.end());

	double ans = v[0];
	for (int i = 1; i < N; i++) ans = (ans+v[i])/2;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
bool comp(pli& a,pli& b){
  return a.first>b.first;
}//降順ソート

int main() {
 int n,m;
  cin >> n >> m;
  vector<long long> a(n);
  vector<pair<long long,int> > pairs(m);
  for(int i=0;i<n;i++){
  cin >> a[i];
  }
  for(int i=0;i<m;i++){
  cin >> pairs[i].second >> pairs[i].first;
  }
  sort(a.begin(),a.end());
  sort(pairs.begin(),pairs.end(),comp);//Ciで降順ソート



 ll k=0,sum=0;
  for(int i=0;i<m;i++){
    ll b=pairs[i].second,c=pairs[i].first;
    for(int j=0;j<b;j++){
      if(c>=a[k]){
        a[k]=c;k++;
      }
      else{

        for(int g=0;g<n;g++){
        sum+=a[g];
        }
        cout << sum << endl;
        return 0;
      }
    }
  }
  for(int g=0;g<n;g++){
  sum+=a[g];
  }
  cout << sum << endl;

}

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

int a[100000],n;

int part(int a[],int p,int r)
{
	int x=a[r];
	int i=p-1;
	for(int j=p;j<r;j++)
	{
		if(a[j]<=x)
		{
			i++;
			swap(a[i],a[j]);
		}
	}
	swap(a[i+1],a[r]);
	return i+1;
}

int main()
{
	cin>>n;
	for(int i=0;i<n;cin>>a[i++]);
	int q=part(a,0,n-1);
	for(int i=0;i<n;i++)
	{
		if(i)cout<<" ";
		if(i==q)cout<<"[";
		cout<<a[i];
		if(i==q)cout<<"]";
	}
	cout<<endl;
	return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    set<int> d;
    for (int i = 0; i < n; ++i) {
        int r; cin >> r;
        d.insert(r);
    }

    cout << d.size() << endl;
}

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

int isUpper(char c){
  return c < 97 || 122 < c;
}

int main(void)
{
  char S[11];
  scanf("%s", S);
  int state = 0;
  const int len = strlen(S);
  if(S[0] != 'A' || isUpper(S[1]) || isUpper(S[len-1]))
    state = 0;
  else{    
    int c = 0;
    for(int i = 2; i < len-1; i++){
      if(S[i] == 'C'){
        if(c){
          state = 0;
          break;
        } else {
          c++;
          state = 1;
        }
      } else {
        if(isUpper(S[i])){
          state = 0;
          break;
        }
      }

    }
  }
  printf("%s\n", state ? "AC" : "WA");
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
# C

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
from itertools import product

N = int(input())
A = [0] * N
x = []

for i in range(N):
    A[i] = int(input())
    d = []
    for j in range(A[i]):
        d.append(tuple(map(int, input().split())))
    x.append(d)

ans = 0

# for case in list(product([0,1], repeat=N)):
for m in range(2**N):
    # print(case)
    flg = [-1] * N
    cond = True
    for i in range(N):
        if not cond:
            continue
        if m >> i & 1 == 0:
            continue

        for a in range(A[i]):
            c, d = x[i][a]
            c = c-1

            # print(c, d)
            if m >> c & 1 != d:
                cond = False
                # print('矛盾')
    if cond:
        # ans = max(ans, sum(case))
        ans = max(ans, bin(m).count('1'))

print(ans)


Measured memory_bytes: 43756
n = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        x = 4*a*b-a*n-b*n
        y = a*b*n
        if x != 0:
            if y/x >= 1 and int(y/x) == y/x:
                print(a,b,int(y/x))
                exit()

Measured memory_bytes: 41068
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e5 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
ll tree[Max+5];

ll query(ll idx)
{
    ll sum=0;

    while(idx>0)
    {
        sum=max(tree[idx],sum);

        idx-= idx & (-idx);

    }

    return sum;
}

void update(ll idx,ll x,ll n)
{
    while(idx<=n)
    {
        tree[idx]=max(tree[idx],x);

        idx+= idx & (-idx);
    }
}

int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;

      cin>>n;

      ll ara[n+2],dp[n+2];



      ll mx=0;

       input(ara,n);

       for(i=0; i<n; i++)
       {
         cin>>a;

        a+=query(ara[i]-1);

          update(ara[i],a,Max);

          mx=max(mx,a);


       }

       cout<<mx<<endl;

}



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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int QUA = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<bool> A(n + 1, true);

  ll ans = 1;
  for(int i = 2;i <= n;i++){
    if(A.at(i)){
      for(int j = 2 * i;j <= n;j += i){
        A.at(j) = false;
      }
      int tmp = 0, copy = i;
      while(copy <= n){
        tmp += (n / copy);
        copy *= i;
      }
      ans = (ans * (tmp+ 1)) % QUA;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

std::string s[3];

int main(){
	for(int i=0;i<3;++i)
		std::cin>>s[i];
	int index=0,tmp;
	while(1){
		if(s[index].empty())
			break;
		tmp=s[index].front()-'a';
		s[index].erase(s[index].begin());
		index=tmp;
	}
	std::cout<<char('A'+index)<<std::endl;
	return 0;
}

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

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

Measured memory_bytes: 256
def get_max_expo(x)
  b = Math.sqrt(x).floor
  ans = 1

  while b > 1
    num = b*b

    while num <= x
      num *= b
    end

    num /= b
    ans = num if ans < num
    b -= 1
  end

  ans
end

x = gets.chomp.to_i
puts get_max_expo(x)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, sfmin = INT_MAX, count;
  cin >> N;
  for(int i = 0; i < N; i++){
    count = 0;
    cin >> A;
  	while(A % 2 == 0){
    	count++;
		A /= 2;
  	}
 	sfmin = min(sfmin, count);
  }
  cout << sfmin << endl;
} 

Measured memory_bytes: 256
(let* ((n (read))
       (k (read))
       (sunuke (make-array `(,(1+ n)) :initial-element nil))
       (ans 0))
  ;
  (loop :for i :from 1 :to k
        :do (let ((d (read)))
              (loop :for j :from 1 :to d
                    :do (let ((a (read)))
                          (setf (aref sunuke a) t)))))
  (loop :for i :from 1 :to n
        :unless (aref sunuke i)
        :do (incf ans))
  (format t "~A~%" ans))


Measured memory_bytes: 29796
#include<stdio.h>
int main()
{
	int n,p,t=0,s=0,i;

	scanf("%d",&n);
	while(n--){
		scanf("%d",&p);
		if(t<p)
			t=p;
		s+=p;
	}
	printf("%d",s-t+t/2);
	return 0;
}

Measured memory_bytes: 128
import itertools
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
total=0
route=list(itertools.combinations(X,2))
for i in route:
    total+=((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2)**(1/2)
print(total*2/N)

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

int main(){
  int n,a[1000007],cur = INT_MAX;
  cin>>n;
	int k;
	cin>>k;
  int dp[1000007];
  dp[0]=0;
  for(int i=0;i<n;i++){
  cin>>a[i];
  }
  dp[1]=abs(a[0]-a[1]);
int min1=0;
  for(int i=2;i<k;i++){
    cur = INT_MAX;
    for(int j=0;j<i-1;j++)
      {  
        min1 = dp[j]+abs(a[i]-a[j]);
        cur = min(min1,cur);
      }
      dp[i]=cur;
    }
    for(int i=k;i<n;i++){
      cur = INT_MAX;
      for(int j=i-k;j<i;j++){
        min1 = dp[j]+abs(a[i]-a[j]);
        cur = min(min1,cur);
      }
      dp[i]=cur;
    }
    cout<<dp[n-1]<<endl;
    return 0;
  }

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

const int maxd=12;

int d,g;
int p[maxd],c[maxd];

int up(int a,int b)
{
	if(a%b==0)return a/b;
	else return a/b+1;
}

int main()
{
	scanf("%d%d",&d,&g);
	for(int i=1;i<=d;i++)
		scanf("%d%d",&p[i],&c[i]);
	
	int ans=2e9;
	for(int i=0;i<(1<<d);i++)
	{
		int cnt=0,tot=0;
		for(int j=0;j<d;j++)
			if((i&(1<<j)))tot+=(j+1)*p[j+1]*100+c[j+1],cnt+=p[j+1];
		if(tot>=g)ans=min(ans,cnt);
		else for(int j=0;j<d;j++)
			if(!(i&(1<<j))&&(j+1)*p[j+1]*100>=g-tot)
				ans=min(ans,up(g-tot,(j+1)*100)+cnt);
	}
	
	printf("%d",ans);
	
	return 0;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	int num = 1;

	for (int i = 0; i < n; i++)
	{
		if (num * 2 <= num + k)
		{
			num *= 2;
		}
		else
		{
			num += k;
		}
	}

	cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int a,b,c=0;
while(1){
cin>>a;
  if(a==0){
       break;
}else{
    b=1000-a;
    c=b/500;
    c=c+b%500/100;
    c=c+b%500%100/50;
    c=c+b%500%100%50/10;
    c=c+b%500%100%50%10/5;
    c=c+b%500%100%50%10%5/1;
    a=0; 
   }
cout<< c << endl;
} 
return 0;
}

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

using namespace std;

struct QueueEle {
    int u;
    int prev;
    int dist;
    QueueEle() {}
    QueueEle(int u, int prev, int dist): u(u), prev(prev), dist(dist) {}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
    }
    auto find_smallest_cycle = [&](int i) {
        vector<int> dists(n, -1);
        vector<int> prev(n, -1);
        deque<QueueEle> q;
        q.push_back(QueueEle(i, -1, 0));
        while (!q.empty()) {
            auto ele = q.front();
            q.pop_front();
            if (prev[ele.u] != -1) {
                continue;
            }
            dists[ele.u] = ele.dist;
            prev[ele.u] = ele.prev;
            for (int v : adj_list[ele.u]) {
                q.push_back(QueueEle(v, ele.u, ele.dist+1));
            }
        }
        vector<int> nodes;
        if (prev[i] == -1) {
            return nodes;
        }
        int u = i;
        while (true) {
            nodes.push_back(u);
            u = prev[u];
            if (u == i) {
                break;
            }
        }
        return nodes;
    };
    vector<int> smallest_cycle;
    for (int i = 0; i < n; ++i) {
        vector<int> candidate = find_smallest_cycle(i);
        if (candidate.size() > 0 && (smallest_cycle.size() == 0 || candidate.size() < smallest_cycle.size())) {
            smallest_cycle = candidate;
        }
    }
    if (smallest_cycle.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << smallest_cycle.size() << endl;
        for (int u : smallest_cycle) {
            cout << u+1 << "\n";
        }
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

struct UnionFind{
    vector<int> rank,p,size;
    UnionFind(int n){
        rank.resize(n,0);
        p.resize(n,0);
        size.resize(n,0);
        for(int i = 0; i < n; i++){
            p[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
            size[rx] += size[ry];
        }else{
            p[rx] = ry;
            size[ry] += size[rx];
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
        return true;
    }
    int tree_size(int x){
        return (size[root(x)]);
    }
};

int main()
{
    int n,m; cin >> n >> m;
    int p[n]; rep(i,n) cin >> p[i];
    UnionFind uf(n);
    rep(i,m){
        int x,y; cin >> x >> y;
        uf.unite(x-1,y-1);
    }
    int ans = 0;
    rep(i,n){
        if(uf.same(i,p[i]-1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// look at 0 - K and subtract 1.

string k;
int n, d;
const int MOD = 1e9 + 7;

// dp[i][j]: if we have i 0-9 choices and we want j mod d, how many ways?
int dp[10002][101];

// solve: int i is the first letter index of the suffix we look at. left is the modulus mod D we want.
long long solve(int i, int left)
{
    if (i == n)
    {
        // base case
        return (left == 0);
    }
    long long ret = 0;
    // take the first char
    ret += solve(i + 1, ((left - (k[i] - '0')) % d + d) % d);

    for (int c = 0; c < (k[i] - '0'); c++)
    {
        ret += dp[n - i - 1][((left - c) % d + d) % d];
        ret %= MOD;
    }

    ret %= MOD;
    return ret;
}

int main()
{
    cin >> k >> d;      
    n = k.length();

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            int ret = 0;
            for (int c = 0; c < 10; c++)
            {
                ret += dp[i - 1][((j - c) % d + d) % d];
                ret %= MOD;
            }
            dp[i][j] = ret;
        }
    }

    cout << ((solve(0, 0) - 1) % MOD + MOD) % MOD << endl;
}

Measured memory_bytes: 8000
#include <iostream>
using namespace std;
 
int main(){
    int i, j, r, c;
    int array[102][102];
 
    cin >> r >> c;

    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            array[i][j] = 0;
        }
    }
 
    for (i = 1; i <= r; i++){
        for (j = 1; j <= c; j++){
            cin >> array[i][j];
            array[i][c+1] += array[i][j];
            array[r+1][j] += array[i][j];
            array[r+1][c+1] += array[i][j];
        }
    }
 
    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            if (j != 1) cout << " ";
            cout << array[i][j];
        }
        cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1200
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    long[] v = new long[N];
    for(int i = 0; i < N; i++) {
      v[i] = sc.nextLong();
    }
    Arrays.sort(v);
    // パスカルの三角形
    long[][] dp = new long[51][51];
    dp[0][0] = 1;
    dp[1][0] = 1;
    dp[1][1] = 1;
    for(int i = 2; i < 51; i++) {
      dp[i][0] = 1;
      dp[i][i] = 1;
      for(int j = 1; j < i; j++) {
        dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
      }
    }
    double maxAve = 0;
    long sum = 0;
    for(int i = 1; i <= A; i++) {
      sum += v[N - i];
    }
    // 平均の最大値
    maxAve = (double)sum / (double)A;
    // 場合の数
    long ans = 0;
    if(A == N) {
      ans = 1;
    } else {
      if(v[N - A] > v[N - A - 1]) {
        ans = 1;
      } else {
        int K = 0;
        for(int i = 0; i < N; i++) {
          if(v[N - A] == v[i]) K++;
        }
        int s = 0;
        for(int i = N - A; i < N; i++) {
          if(v[N - A] == v[i]) s++;
        }
        if(v[N - 1] > v[N - A]) {
          ans = dp[K][s];
        } else {
          for(int i = A; i < B + 1; i++) {
            ans += dp[K][i];
          }
        }
      }
    }
    System.out.println(maxAve);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764