akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

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

int dp[100005] = {};
vector<int> v;

int fun(int idx) {
  if (idx + 1 >= v.size())return 0;

  int &ref = dp[idx];
  if (ref != -1)return ref;

  ref = fun(idx + 1) + abs(v[idx] - v[idx + 1]);

  if (idx + 2 < v.size()) {
    ref = min(ref, fun(idx + 2) + abs(v[idx] - v[idx + 2]));
  }
  return ref;
}

class AFrog1 {
 public:
  void solveOne(std::istream &in, std::ostream &out) {
    int n;
    in >> n;
    v.resize(n);
    forn(i, n)in >> v[i];

    memset(dp, -1, sizeof dp);
    out << fun(0) << endl;
  }
  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int i = 0; i < nt; ++i)
      solveOne(in, out);
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  AFrog1 solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;




ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}


// int main(){
//     //多くて10^4くらいしか組み合わせがない 各クエリ見ても50なので余裕だけど作るのがわからない
//     //最終的に必要なのはdの合計なので配列すべての概要を知る必要はない
//     int N, M, Q;
//     cin >> N >> M >> Q;
//     // vector<vector<int>> q(Q,vector<int>(4));
//     // rep(i, Q)cin >> q[i][0] >> q[i][1] >> q[i][2] >> q[i][3];
//     vector<pair<int, vector<int>>> p(Q);
//     rep(i,Q){
//         vector<int> t(3);
//         cin >> t[0] >> t[1] >> t[2];
//         int c;
//         cin >> c;
//         p[i] = make_pair(c, t);
//     }
//     sort(all(p), greater<pair<int, vector<int>>>());
//     for(auto x: p){
//         cout << x.first << " " << x.second[0] << " " <<x.second[1] << " " << x.second[2]<<endl;
//     }
//     vector<int> ans(N, -1);
//     rep(i, Q){
//         if(ans[p[i].second[0] - 1] == -1 && ans[p[i].second[1] - 1] == -1){
//             ans[p[i].second[0] - 1] = 1;
//             ans[p[i].second[1] - 1] = 1 + p[i].second[2];
//         }else if(ans[p[i].second[0] - 1] == -1 && ans[p[i].second[1] - 1] != -1){
//             ans[p[i].second[0] - 1] = ans[p[i].second[1] - 1] - p[i].second[2];
//         }else if(ans[p[i].second[0] - 1] != -1 && ans[p[i].second[1] - 1] == -1){
//             ans[p[i].second[1] - 1] = ans[p[i].second[0] - 1] + p[i].second[2];
//         }
//     }
//     rep(i, N)cout << ans[i] << endl;
//     ll res = 0;
//     rep(i,Q){
//         if(ans[p[i].second[1] - 1] - ans[p[i].second[0] - 1] == p[i].second[2])res += p[i].first;
//     }
//     cout << res << endl;
    
// }
int digNum(int x, int n){
    int num = pow(10, n);
    num = x % num;
    num /= pow(10, n - 1);
    return num;
}


int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    vector<ll> dp(N, INF);
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        rep(j, K){
            if(i + j + 1 < N) dp[i + j + 1] = min(dp[i] + abs(h[i + j + 1] - h[i]), dp[i + j + 1]);
        }
    }
    cout << dp[N - 1] << endl;
}


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

typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin >> x;
	ll t = 100;
	for (int i = 1; ; i++)
	{
		double z = 1.01 * t;
		t = z;
		if( t >= x )
		{
			cout << i << '\n';
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>
int c[1001][1001] = {0};
int LCS(std::string s, std::string t){
    int n, m;
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
       
        std::cout << LCS(s1,s2) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 7024
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s;
  cin>>t;
  long a=s.length();
  int count=0;
  for(long i=0;i<a;i++)
  {
    if(s[i]!=t[i])
      count++;
  }
  cout<<count;
  return 0;
  
}


Measured memory_bytes: 3924
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  cout << max((B+C)-A,0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
#include <time.h>
using namespace std;

string max_str(string a,string b){
	if(a.size()>b.size())return a;
	if(a.size()<b.size())return b;
	if(a>b)return a;
	return b;
}

int main(){
	int N,M;
	cin>>N>>M;
	char cnt[10] ={0,2,5,5,4,5,6,3,7,6};
	vector<pair<int,char>> vec;
	for(int i=0;i<M;i++){
		int a;
		cin>>a;
		vec.push_back(make_pair(cnt[a],'0'+a));
	}
	
	vector<string> dp(N+1,"");
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<vec.size();j++){
			if(i-vec[j].first<0)continue;
			if(i-vec[j].first>0){
				if(dp[i-vec[j].first]=="")continue;
			}
			dp[i] = max_str(dp[i-vec[j].first]+vec[j].second,dp[i]);
		}
	}
	
	cout<<dp[N]<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 41600
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
x,y = map(int,input().split())
if x == 2 or y == 2:
  print("No")
elif x in A and y in A:
  print("Yes")
elif x in B and y in B:
  print("Yes")
else:
  print("No")

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void Main()
{
	int N; cin >> N;
	cout << (N % 2 == 0 ? N : 2 * N) << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,i,j,k,c=0;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
	for(i=0;i<n-2;i++){
     for(j=i+1;j<n-1;j++){
      for(k=j+1;k<n;k++){
        if((a[i]+a[j])>a[k]&&a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]) c++;
      }
     }
    }
  cout<<c;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

lli find(lli h){
	if(h==1)return 1;
	return 1+2*find(h/2);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli h;
	cin>>h;
	cout<<find(h)<<endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		boolean end=false;
		while(!end){
			String[] array = br.readLine().split(" ");
	        int a = Integer.parseInt(array[0]);
	        int b = Integer.parseInt(array[2]);
	        switch(array[1].charAt(0)){
	        case '+':
	        	System.out.println(a+b);
	        	break;
	        case '-':
	        	System.out.println(a-b);
	        	break;
	        case '*':
	        	System.out.println(a*b);
	        	break;
	        case '/':
	        	System.out.println(a/b);
	        	break;
	        default:
	        	end=true;
	        	break;
	        }
		}
	}
}

Measured memory_bytes: 16964
Imports System
Public class HEX
  Public Shared Sub Main()
    Dim i() As String
    Dim a As Char
    Dim b As Char
    i=Split(Console.Readline())
    a=i(0)
    b=i(1)
    If Asc(a)<Asc(b) Then
      Console.Writeline("<")
    Else If Asc(a)>Asc(b) Then
      Console.Writeline(">")
    Else
      Console.Writeline("=")
    End If
  End Sub
End class

Measured memory_bytes: 13536
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000-N%1000)



Measured memory_bytes: 10560
#include<stdio.h>

void mergeSort(int S[], int temp[], int array_size);
void m_sort(int S[], int temp[], int left, int right);
void merge(int S[], int temp[], int left, int mid, int right);

int n,count=0;
int numbers[500001];
int temp[500001];


int main()
{
  int i;
  scanf("%d",&n);
  
  for (i = 0; i < n; i++){
   scanf("%d",&numbers[i]);
  }
  mergeSort(numbers, temp, n);


  for (i = 0; i < n-1; i++){
    printf("%d ", numbers[i]);
}
  printf("%d",numbers[n-1]);
  printf("\n");

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


void mergeSort(int numbers[], int temp[], int array_size)
{
  m_sort(numbers, temp, 0, array_size - 1);
}



void m_sort(int numbers[], int temp[], int left, int right)
{
  int mid;

  if (right > left)
  {
    mid = (right + left) / 2;
    m_sort(numbers, temp, left, mid);
    m_sort(numbers, temp, mid+1, right);

    merge(numbers, temp, left, mid+1, right);
  }
}


void merge(int numbers[], int temp[], int left, int mid, int right)
{
  int i, left_end, num_elements, tmp_pos;

  left_end = mid - 1;
  tmp_pos = left;
  num_elements = right - left + 1;

  while ((left <= left_end) && (mid <= right))
  {
    if (numbers[left] <= numbers[mid])
    {
      temp[tmp_pos] = numbers[left];
      tmp_pos = tmp_pos + 1;
      left = left +1;
      count++;
    }
    else
    {
      temp[tmp_pos] = numbers[mid];
      tmp_pos = tmp_pos + 1;
      mid = mid + 1;
      count++;
    }
  }

  while (left <= left_end)
  {
    temp[tmp_pos] = numbers[left];
    left = left + 1;
    tmp_pos = tmp_pos + 1;
    count++;
  }
  while (mid <= right)
  {
    temp[tmp_pos] = numbers[mid];
    mid = mid + 1;
    tmp_pos = tmp_pos + 1;
    count++; 
 }

  for (i=0; i <= num_elements; i++)
  {
    numbers[right] = temp[right];
    right = right - 1;
  }
}

Measured memory_bytes: 4508
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    sc.close();

    long ans = 0;
    ans += (X / 500) * 1000;
    int x = X % 500;
    ans += (x / 5) * 5;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static int n, q;
	static String s;
	static long[][][][] dp = new long[110][5][5][5];
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int h=cin.nextInt();int w=cin.nextInt();
		int a=cin.nextInt(),b=cin.nextInt();
		int ans=h*w-w*a-(h-a)*b;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int N;
    map<int, int> a;

    cin >> N;

    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
        a[A[i]]++;
        a[A[i]+1]++;
        a[A[i]-1]++;
    }

    int ans = -1;

    //for(int x = a.begin()->first; x <= a.rbegin()->first; x++) { 
    for(auto X : a) {
        int x = X.second;
        //int tmp = 0;
        //cout << x << endl;
        //for(auto itr : a) {
            //cout << "first " <<  itr.first << "second " << itr.second << endl; 
         //   if(abs(x - itr.first) <= 1) { tmp += itr.second; }   
        //}
        ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5120
import fractions
import sys

N, X = map(int, input().split())
li = list(map(int, input().split()))

if len(li) == 1:
  print(abs(li[0] - X))
  sys.exit()
  
li.append(X)
li.sort(reverse=True)

ans = li[0] - li[1]

for index, i in enumerate(li):
  if index == 0:
    continue

  if index == len(li) - 1:
    break

  ans = fractions.gcd(ans, i - li[index+1])

print(ans)

Measured memory_bytes: 16240
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,tot,mx,mn,e[500010],hd[500010],nt[500010],f[500010],v[500010],mp[500010],cnt,fa[500010];
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
void dfs(int x){
	int i;
	for(i=hd[x];i;i=nt[i]){
		if(mp[e[i]])continue;
		dfs(e[i]);
	}
	for(i=hd[x];i;i=nt[i]){
		if(mp[e[i]])continue;
		v[f[e[i]]]=1;
	}
	while(v[f[x]])f[x]++;
	for(i=hd[x];i;i=nt[i]){
		if(mp[e[i]])continue;
		v[f[e[i]]]=0;
	}
}
int main(){
	int i,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&fa[i]);
		build(fa[i],i);
	}
	x=1;
	while(!v[x])v[x]=1,x=fa[x];
	while(!mp[x])mp[x]=1,x=fa[x];
	for(i=0;i<=n;i++)v[i]=0;
	mn=n+1;
	for(i=1;i<=n;i++)if(mp[i]){
		dfs(i);
		mx=max(mx,f[i]);
		mn=min(mn,f[i]);cnt++;
	}
	if(mx==mn&&cnt%2==1)puts("IMPOSSIBLE");
	 else puts("POSSIBLE");
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    int m, d, res, d10, d1;
    cin >> m >> d;

    res = 0;
    d10 = d / 10;
    d1 = d % 10;

    rep2(i, 4, m + 1)
    {
        rep2(j, 2, d10 + 1)
        {
            rep2(k, 2, 9+1)
            {
                if (j == d10 && k > d1)
                    break;

                if (i == (j * k))
                    res++;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int max(int len, ...) {
    int i, _max, num;
    va_list ap;
    va_start(ap, len);

    _max = va_arg(ap, int);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, int);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}

int main(void) {
    int i, N, a[100010], b[100010], c[100010], dp[100010][3];
    scanf("%d", &N);
    for(i=1;i<=N;i++) {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
    }

    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];    
    for (i=2;i<=N;i++) {
        dp[i][0] = max( 2, dp[i-1][1] + a[i] , dp[i-1][2] + a[i] );
        dp[i][1] = max( 2, dp[i-1][0] + b[i] , dp[i-1][2] + b[i] );
        dp[i][2] = max( 2, dp[i-1][0] + c[i] , dp[i-1][1] + c[i] );
    }
    printf("%d\n", max( 3, dp[N][0], dp[N][1], dp[N][2] ));
    return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 100005
using namespace std;
int n,a[MN];long long maxn=2,minn=2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n;i>=1&&maxn>=minn;i--){
		if(minn%a[i])minn=minn/a[i]*a[i]+a[i];
		maxn=(maxn/a[i]+1)*a[i]-1;
	}
	if(maxn<minn)puts("-1");
	else printf("%lld %lld\n",minn,maxn);
}

Measured memory_bytes: 512
import numpy as np
import math





n,m= map(int, input().split())


num=np.zeros(n)
num[:] = np.nan

sandc=np.zeros((m,2))

flag=0
for i in range(0,m):
    sandc[i][0], sandc[i][1]= map(int, input().split())

for i in range(0,m):

    if (not math.isnan(num[int(sandc[i][0]-1)])) and num[int(sandc[i][0]-1)]!= sandc[i][1]:
        flag=-1
        break

    if  n>1 and int(sandc[i][0]==1) and int(sandc[i][1]==0):
        flag=-1
        break
       

    num[int(sandc[i][0]-1)]=sandc[i][1]
    



for i in range(0,n):
     if  math.isnan(num[i]):
         if  i==0 and n>1:
            num[i]=1
         else:
            num[i]=0


pri_num=0
if flag==-1:
    print(flag)
else:
    for i in range(0,n):
   
       pri_num=pri_num+num[i]*10**(n-i-1)


    print(int(pri_num))
        
      

Measured memory_bytes: 12512
#include<stdio.h>
typedef struct{
    char m;
    int n;
}Card;

int main(){
    int a, b, d = 0, i, j;
    scanf("%d",&a);
    Card x[a], y[a],c = {0};
    for(i = 0; i < a; i++){
        scanf(" %c%d",&x[i].m, &x[i].n);
        y[i] = x[i];
    }
    for(i = 0; i < a-1; i++){
        for(j = a-1; j > i; j--){
            if(x[j].n < x[j-1].n){
                c = x[j-1];
                x[j-1] = x[j];
                x[j] = c;
            }
        }
    }
    for(i = 0;i < a; i++){
        if(i == a-1){
          printf("%c%d\n", x[i].m, x[i].n);
        }else{
          printf("%c%d ", x[i].m, x[i].n);
        }
    }
    puts("Stable");
    for(i = 0; i < a; i++){
        b = i;
        for(j = i; j < a; j++){
            if(y[j].n < y[b].n){
                b = j;
            }
        }
        if(i != b){
            c = y[i];
            y[i] = y[b];
            y[b] = c;
        }
    }
    for(i = 0; i < a; i++){
        if(i == a-1){
          printf("%c%d\n", y[i].m, y[i].n);
        }else{
          printf("%c%d ", y[i].m, y[i].n);
        }
    }
    for(i = 0; i < a; i++){
        if(x[i].m == y[i].m){
           d++;
        }
    }
    if(a == d){
      puts("Stable");
    }else{
      puts("Not stable");
    }

    return 0;
}

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

using namespace std;

struct unionfind
{
	//rankのオーバーフローに注意
	vector<int> par, rank;
	unionfind(int n)
	{
		par.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 1;
		}
	}

	bool same(int u, int v)
	{
		return root(u) == root(v);
	}

	void unite(int u, int v)
	{
		if (same(u, v)) return;
		u = root(u), v = root(v);
		if (rank[u] > rank[v]) swap(u, v);
		par[u] = v;
		rank[v] += rank[u];
	}

	int root(int v)
	{
		if (par[v] == v) return v;
		return par[v] = root(par[v]);
	}
};

void solve()
{
	int s, t;
	cin >> s >> t;
	vector<pair<int, int>> es(t);
	for (int i = 0; i < t; i++)
	{
		int a, b;
		cin >> a >> b;
		es[i] = make_pair(a-1, b-1);
	}
	reverse(es.begin(), es.end());

	unionfind uf(s);

	long a = 1L*s*(s-1)/2;
	vector<long> ans;

	for (auto e : es)
	{
		ans.push_back(a);
		int v = e.first, u = e.second;
		if (!uf.same(u, v)) a -= 1L*uf.rank[uf.root(u)]*uf.rank[uf.root(v)];
		uf.unite(u, v);
	}

	reverse(ans.begin(), ans.end());

	for (long a : ans)
	{
		cout << a << endl;
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 3828
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, k = nm()
    l = nl()
    print(sum(sorted(l)[:k]))
    return

solve()


Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long int ll;
int main()
{
	
	while(true){
		ll N;
		ll INF=1000000000000000;
		scanf("%lld",&N);
		if(N==0)break;
		ll ans=0;
		int cou=0;
		ll mul=1;
		while(N!=0){
			if(cou&1){
				N=0-N;
				ans+=((N+INF)%10)*mul;
				N-=(N+INF)%10;
				N/=10;
				N=0-N;
			}
			else{
				ans+=((N+INF)%10)*mul;
				N-=(N+INF)%10;
				N/=10;
			}
			cou++;
			mul*=10;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
N, M = map(int, input().split(' '))
if M == 0:
    if N == 1:
        print(0)
    else:
        print('1', '0' * (N - 1), sep='')
else:
    is_end = False
    rst = [''] * N
    for i in range(M):
        s, c = input().split(' ')
        idx = int(s) - 1
        if idx == 0 and N != 1 and c == '0':
            print(-1)
            is_end = True
            break
        if rst[idx] == '':
            rst[idx] = c
        if rst[idx] != c:
            print(-1)
            is_end = True
            break
    if not is_end:
        for i, j in enumerate(rst):
            if i == 0 and j == '':
                print('1', end='')
            elif j == '':
                print('0', end='')
            else:
                print(j, end='')

Measured memory_bytes: 9248
n,k=map(int,input().split())
arr=list(map(int,input().split()))
dp=[False]*(2*k+1)
for i in range(k):
  for val in arr:
    if dp[i]==False:
      dp[i+val]=True
if dp[k]==True:
  print('First')
else:
  print('Second')

Measured memory_bytes: 10284
#include <cstdio>
#include <algorithm>

using namespace std;

long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    long long a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    if (b > a || b > d) {
      puts("No");
      continue;
    }
    if (c + 1 >= b) {
      puts("Yes");
      continue;
    }
    long long by = max(0LL, a - (c + 1)) / b + 1;
    a -= by * b;
    if (a < 0) {
      puts("No");
      continue;
    }
    long long r = d % b;
    if (r == 0) {
      puts("Yes");
      continue;
    }
    long long lo = c + 1 - a;
    long long hi = b - 1 - a;
    long long g = gcd(r, b);
    long long v = (lo + g - 1) / g * g;
    puts(lo > 0 && v > hi ? "Yes" : "No");
  }
}


Measured memory_bytes: 128
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;

bool comp(pll p1,pll p2)
{
    if(p1.ff==p2.ff)
        return p1.ss<p2.ss;

    return p1.ff<p2.ff;
}

int main()
{
   
    IOS
    ll a,b,n;
    cin>>a>>b;
    n=__gcd(a,b);
    set<ll> s;
    while (n % 2 == 0)  
    {  
        s.in(2);  
        n = n/2;  
    }  
  
    
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
          
        while (n % i == 0)  
        {  
            s.in(i);  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        s.in(n);

    cout<<s.size()+1<<endl;  


    




    
    
}
    
 
    
    



Measured memory_bytes: 256
n, m, l = gets.chomp.split.map(&:to_i)
a = n.times.map{ gets.chomp.split.map(&:to_i) }
b = m.times.map{ gets.chomp.split.map(&:to_i) }

n.times do |n_i|
  puts l.times.map{|l_i|
    m.times.reduce(0){|t, m_i|
      t + a[n_i][m_i] * b[m_i][l_i]
    }
  }.join(" ")
end



Measured memory_bytes: 7328
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	long sum = 0;
      	
      	for(int i=1;i<=n;i++){
			if(i%15==0){

            }else if(i%5==0){

            }else if(i%3==0){

            }else{
				sum = sum+i;
            }
        }
      
      	System.out.println(sum);
    }
}

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

import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  

c = collections.Counter(prime_factorize(N))

A = c.keys()
count = c.values()

ans = 0

for i in count:
  k = 0
  for j in range(1,i+1):
    k += j
    if k <= i:
      ans += 1
      
print(ans)


Measured memory_bytes: 9464
n, p = map(int, input().split())
s = input()
if p==2 or p==5:
    ans = 0
    for i in range(n):
        if int(s[i])%p==0:
            ans += i+1
    print(ans)
else:
    di = {0: 1}
    tmp = 0
    for i in range(n):
        tmp += int(s[n-i-1])*pow(10, i, p)
        tmp %= p
        if tmp in di:
            di[tmp] += 1
        else:
            di[tmp] = 1
    ans = 0
    for i in di.values():
        ans += i*(i-1)//2
    print(ans)

Measured memory_bytes: 4072
fun main(args: Array<String>) {
    val N = nextInt()
    val P = listOfInt().sorted()
    val ans = P[N / 2] - P[N / 2 - 1]
    println(if (ans <= 0) 0 else ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 53828
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;
	
	ll H, W;
	cin >> H >> W;
	vector<vector<char>> ma(H + 2, vector<char>(W + 2, '.'));
	rep(i, H) {
		string s;
		cin >> s;
		rep(j, W) ma[i + 1][j + 1] = s[j];
	}

	ll dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
	ll dy[8] = {1, 0, -1, -1, -1, 0, 1, 1};
	fori(i, 1, H + 1) {
		fori(j, 1, W + 1) {
			if (ma[i][j] == '#') cout << '#';
			else {
				ll tmp = 0;
				rep(k, 8) if (ma[i + dx[k]][j + dy[k]] == '#') ++tmp;
				cout << tmp;
			}
			
		}
		cout << endl;
	}
}

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

int main(){

    string s;
    cin >> s;

    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[(int)s.size()-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=0;i<s.size()/4;i++){
        if(s[i]!=s[(int)s.size()/2-i-1]){
            cout << "No" << endl;
            return 0;
        }
        if(s[i+s.size()/2+1]!=s[(int)s.size()-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
X = list(map(int, [input() for _ in range(5)]))
X = sorted(X, key=lambda x: x%10)
r = 0
for x in X:
    if x % 10 == 0:
        r += x
    else:
        if r % 10 == 0:
            r += x
        else:
            r += (1+x//10) * 10
print(r)


Measured memory_bytes: 9192
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

constexpr ll ten(int n) {
  ll v = 1;
  for (int i = 0; i < n; i++) v *= 10;
  return v;
}

const ll INF = ten(18) + 10;

ll count(const vector<ll>& A, ll X) {
  int N = A.size();
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      if (X >= 0) {
        cnt += N - i - 1;
      }
      continue;
    }
    if (A[i] < 0) {
      auto it = partition_point(A.begin() + i + 1, A.end(), [&](ll v) {
        return A[i] * v > X;
      });
      cnt += distance(it, A.end());
    } else {
      auto it = partition_point(A.begin() + i + 1, A.end(), [&](ll v) {
        return A[i] * v <= X;
      });
      cnt += distance(A.begin() + i + 1, it);
    }
  }
  return cnt;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (auto& x : A) cin >> x;
    sort(A.begin(), A.end());
    ll fail = -INF, pass = INF;
    while (pass - fail > 1) {
      ll X = (pass + fail) / 2;
      if (count(A, X) >= K) {
        pass = X;
      } else {
        fail = X;
      }
    }
    cout << pass << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  char naka;
  
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  
  cout << endl;
  
  for(int j=0; j<H; j++){
    cout << '#';
    for(int i=0; i<W; i++){
      cin >> naka;
      cout << naka;
    }
    cout << '#' << endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  
  cout << endl;
}

Measured memory_bytes: 256
import bisect
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for b in range(n):
    for a in range(b):
        tmp = l[a] + l[b]
        r = bisect.bisect_left(l, tmp)
        ll = b + 1
        ans += max(0, r - ll)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}
ll comb(ll n,ll k){
    ll a=1;
    ll b=1;
    for(ll i=n;i>=n-k+1;i--){
        a=mod(a*i);
    }
    rep(i,1,k){
        b=mod(b*i);
    }
    b=hpow(b,i_7-2);
    return mod(a*b);
}

int main(){fastio
    ll s;cin>>s;
    ll ans=0;
    rep(i,1,s){
        ll n=s-i*3;
        if(n<0)break;
        ans=mod(ans+comb(n+i-1,i-1));
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3656
n=int(input())
r=[]
for _ in range(n):
    r.append(int(input()))
maxv=r[1]-r[0]
minv=r[0]
for j in range(1,n):
    maxv=maxv if maxv>r[j]-minv else r[j]-minv
    minv=minv if minv<r[j] else r[j]
print(maxv)


Measured memory_bytes: 13588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define ll long long

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

    int ans  = a+b;
    ans = max(ans, a-b);
    ans = max(ans, a*b);

    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int x,a,b;
cin>>x>>a>>b;
x-=a;
x-=(x/b)*b;

cout<<x<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		boolean[] prime = new boolean[1000001];
		Arrays.fill(prime, true);
		prime[0] = prime[1] = false;
		for (int i = 2; i < prime.length; ++i) {
			if (prime[i]) {
				for (long j = (long) i * i; j < prime.length; j += i) {
					prime[(int) j] = false;
				}
			}
		}
		while (true) {
			int A = sc.nextInt();
			if (A == 0) break;
			int D = sc.nextInt();
			int N = sc.nextInt();
			while (true) {
				if (prime[A]) {
					--N;
					if (N == 0) break;
				}
				A += D;
			}
			System.out.println(A);
		}
	}

}

Measured memory_bytes: 23492
program ABC_080_B_HarshadNumber
   implicit none
   integer i
   integer(8) N, Nold, fN
   read(*, *) N
   fN = 0
   Nold = N
   do i = 1, 8
       fN = fN + mod(N, 10) 
	   N = N / 10
   end do
   if(mod(Nold, fN) == 0) then
       write(*, *) 'Yes'
   else
       write(*, *) 'No'
   end if
end program ABC_080_B_HarshadNumber

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

int culc(int n){
    int count = 0;
    while (n != 0){
        n /= 10;
        count++;
    }
    return count;
}

int main () {
    int a;
    cin >> a;
    int cnt = 0;
    for(int i = 1; i <= a; ++i){
        if(culc(i) % 2 == 1)    cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

typedef struct _task {
  char name[11];
  int t;
} task;

int head, tail;

task tasks[MAX];

void enqueue(task t) {
  tasks[tail] = t;
  tail = (tail + 1) % MAX;
}

void dequeue() {
  head = (head + 1) % MAX;
}

int main() {
  int n, q, i, min, timer;
  head = tail = timer = 0;

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

  for(i = 0;i < n;i++) {
    scanf("%s %d", tasks[i].name, &tasks[i].t);
  }
  tail = n;

  while(tail != head) {
    min = tasks[head].t > q ? q : tasks[head].t;
    tasks[head].t -= min;
    timer += min;

    if(tasks[head].t == 0) {
      printf("%s %d\n", tasks[head].name, timer);
    } else {
      enqueue(tasks[head]);
    }
    dequeue();
  }

  return 0;
}



Measured memory_bytes: 3300
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const ll MOD=998244353;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    vector<vector<ll>> sum(C+10,vector<ll>(D+10,0));
    REP2(i,A,C+1){
        sum[i][B]=1*mod_pow(B,i-A,MOD);
        sum[i][B]%=MOD;

    }

    REP2(i,B,D+1){
        sum[A][i]=1*mod_pow(A,i-B,MOD);
        sum[A][i]%=MOD;
    }

    REP2(i,A,C){
        REP2(j,B,D){
            sum[i+1][j+1]=((sum[i+1][j]*(i+1))%MOD+(sum[i][j+1]*(j+1))%MOD)%MOD-(sum[i][j]*(i*j))%MOD;
            sum[i+1][j+1]%=MOD;
            while(sum[i+1][j+1]<0) sum[i+1][j+1]+=MOD;
        }
    }

    cout<<sum[C][D]<<endl;
}

    
    



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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

void solve(){

    int n,k;
    cin>>n>>k;
    ll ans = 1;
    ans = k*(pow(k-1,n-1));
    cout << ans;line
  	return;

}

int main(){
	fast
	int t=1;
	//cin >> t;
	while(t--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3888
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int Max = 1e5 + 1;
int n, h;
int a[Max], b[Max];
int kiruhito;
int ans;
vector<int> nageru;
int main(void) {
	cin >> n >> h;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		if (a[i] < a[kiruhito]) continue;
		if (a[i] == a[kiruhito] && b[kiruhito] <= b[i] && i != 0) continue;
		kiruhito = i;
	}
	for (int i = 0; i < n; ++i) {
		if (b[i] < a[kiruhito]) continue;
		if (i == kiruhito) continue;
		nageru.push_back(b[i]);
	}
	sort(nageru.begin(), nageru.end());
	reverse(nageru.begin(), nageru.end());
	for (auto itr = nageru.begin(); itr != nageru.end(); ++itr) {
		if (h <= b[kiruhito] || h <= a[kiruhito]) {
			h -= max(b[kiruhito], a[kiruhito]);
			++ans;
		}
		else {
			h -= *itr;
			++ans;
		}
		if (h <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
	while (true) {
		if (h <= b[kiruhito]) {
			h -= b[kiruhito];
		}
		else {
			h -= a[kiruhito];
		}
		++ans;
		if (h <= 0) break;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> rs(26, -1), rt(26, -1);
	rep(i, s.size()){
		char cs = s[i];
		char ct = t[i];
		cs -= 'a';
		ct -= 'a';
		if(rs[cs] == -1){
			rs[cs] = ct;
		}else{
			if(rs[cs] != ct){
				cout << "No" << endl;
				return 0;
			}
		}
		if(rt[ct] == -1){
			rt[ct] = cs;
		}else{
			if(rt[ct] != cs){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e6+7 , MOD = 1e9+7;
const double PI = acos(0.0) * 2;
int a,b,c,d;
int main()
{
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(c > b)printf("0\n");
        if(c <= b&&c >= a)
        {
            if(d >= b)printf("%d\n",b-c);
            if(d < b)printf("%d\n",d-c);
        }
        if(c < a)
        {
            if(d <= a)printf("0\n");
            if(d > a&&d <= b)printf("%d\n",d-a);
            if(d > b)printf("%d\n",b-a);
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {

		int n = sc.nextInt();

		int prev = -1;
		int count = 0;
		for(int i = 0; i < n ; i++){
			int now = sc.nextInt();
			
			if(prev == now){
				count ++;
				now = -1;
			}
			prev = now;
		}
				
		System.out.println(count);
	}
}


Measured memory_bytes: 21204
n = int(input())
a = [int(input()) for i in range(n)]
dic = {}
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        if dic[i] == 0:
            dic[i] = 1
        else:
            dic[i] = 0
ans = 0
for value in dic.values():
    if value == 1:
        ans += 1
print(ans)

Measured memory_bytes: 59736
import sys
input = sys.stdin.readline
S = list(input())[: -1]
K = 13
mod = 10 ** 9 + 7
dp = [[0] * (K) for _ in range(len(S) + 1)]
dp[0][0] = 1
for i in range(len(S)):
  for j in range(K):
    for k in range(10):
      if S[i] == "?":
        dp[i + 1][(j * 10 + k) % K] += dp[i][j]
        dp[i + 1][(j * 10 + k) % K] %= mod
      elif int(S[i]) == k:
        dp[i + 1][(j * 10 + k) % K] += dp[i][j]
        dp[i + 1][(j * 10 + k) % K] %= mod
print(dp[-1][5])

Measured memory_bytes: 66840
using System;
using System.Collections.Generic;

namespace NTL_1_A
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			Console.WriteLine($"{n}: {string.Join(" ", PrimeFactorize(n))}");
		}

		private static IEnumerable<int> PrimeFactorize(int n)
		{
			int i = 2;
			int buf = n;

			while(Math.Pow(i, 2) <= n) {
				if(buf % i == 0) {
					buf /= i;
					yield return i;
				}
				else {
					i++;
				}
			}

			if(buf != 1) {
				yield return buf;
			}
		}
	}
}



Measured memory_bytes: 19980
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
using namespace std;

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); i += 2) {
		cout << s[i];
	}
}


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

int main(void)
{
    int n, Taro=0, Hanako=0;
    cin >> n;
    for(int i=0;i<n;i++){
        string a, b;
        cin >> a >>b;
        if(a>b){
            Taro += 3;
        }
        else if(a<b){
            Hanako += 3;
        }
        else {
            Taro +=1;
            Hanako +=1;
        }
    }
    cout << Taro <<" "<<Hanako<<endl;
}


Measured memory_bytes: 3156
n = int(input())
a = [0] * n
b = [0] * n

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

ans = 0
for i in range(n-1, -1, -1):
  a[i] += ans
  if a[i] % b[i] != 0:
    ans += ((a[i] // b[i]) + 1) * b[i] - a[i]

print(ans)

Measured memory_bytes: 21432
#include <stdio.h>

int main(void){
  //int型の配列seq
  int seq[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  //int型変数 K
  int K;
  char num[1000];

  //Kに値を格納する
  fgets(num, sizeof(num), stdin);
  sscanf(num, "%d", &K);
  
  printf("%d\n", seq[K - 1]);  
  return 0;
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y;
int a[233333],cnt[233333];
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cnt[i]=1;
	a[1]=1;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		cnt[x]--;cnt[y]++;
		if(a[x])a[y]=1;
		if(cnt[x]==0)a[x]=0;
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024