akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>

using namespace std;
typedef long long  ll;
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll A[100001] = {};
ll S[100001] = {};
map<ll, ll> mp;

int main() {
	ll N, M; cin >> N >> M;

	repe(i, 1, N) {
		cin >> A[i];
		S[i] = S[i - 1] + A[i];
		mp[S[i] % M]++;
	}

	ll cnt = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		ll c = it->second;
		if (c >= 2) {
			cnt += c * (c - 1) / 2;
		}
	}

	cout << mp[0] + cnt << endl;

	return 0;
}

Measured memory_bytes: 5760
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = set()
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if X == (a*500 + b*100 + c*50):
        ans.add((a,b,c))
print(len(ans))        



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "Impossible"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int x; cin >> x;
    loop1(i, 360)
        if (x * i % 360 == 0) {
            cout << i; return;
        }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
int m1,m2,d1,d2;


int main(){
	cin >> m1 >> d1;
	cin >> m2 >> d2;
	if(m1 != m2)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    h, w, a, b = rli()
    for y in range(h):
        ans = []
        for x in range(w):
            if y < b and x < a:
                ans.append("1")
            elif y >= b and x >= a:
                ans.append("1")
            else:
                ans.append("0")
        print("".join(ans))



if __name__ == '__main__':
    main()


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

 class Main {
    static long global_mod = 1000000007;
    static long dp[][][];
   
   public static long solve2(String str, int pos, int mod, int d, int tight){
		if(pos >= str.length()){
			if(mod%d == 0)
				return 1;
			return 0;
		}
    
        if( dp[pos][mod][tight] != -1)
            return  dp[pos][mod][tight];
            
		long ans = 0;

		int allowed = tight == 1 ? str.charAt(pos)-'0' : 9;

		for(int i = 0; i <= allowed; i++){
			if(i == allowed && tight == 1)
				ans += solve2(str,pos+1, (mod +i )%d ,d ,1)%global_mod;


			else
				ans += solve2(str,pos+1,(mod  + i)%d,d,0)%global_mod;
		}

		return dp[pos][mod][tight] = ans%global_mod;

	}

	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String s = br.readLine().trim();
	    int d = Integer.parseInt(br.readLine().trim());
	    
	    dp = new long[s.length()+1][d+1][3];
	    
	    for(int i = 0; i < dp.length; i++){
	        for(int j = 0;j <= d; j++){
	            Arrays.fill(dp[i][j],-1l);
	        }
	    }
	    
		System.out.println((solve2(s,0,0,d,1)-1+global_mod)%global_mod );
	}
}

Measured memory_bytes: 84480
#include<iostream>
using namespace std;
long long lcm(long long a, long long b);
long long gcd(long long a, long long b);
int main(){
  long long a[3],b[3],c[3];
  while(cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2],a[0]||b[0]||a[1]||b[1]||a[2]||b[2]){
    for(int i=0,x; i<3; i++){
      for(c[i]=1,x=1;; c[i]++){
	x = x*a[i]%b[i];
	if(x == 1){break;}
      }
    }
    cout <<lcm(c[0],lcm(c[1],c[2]))<<endl;
  }
  return 0;
}
long long lcm(long long a, long long b){
  return a*b/gcd(a,b);
}
long long gcd(long long a, long long b){
  if(!b){return a;}
  return gcd(b,a%b);
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,m,l;
    cin>>n>>m>>l;
    vector<vector<ll>> wf1(n,vector<ll>(n,LINF));
    rep(i,n) wf1[i][i]=0;
    auto wf2=wf1;
    rep(_,m){
        ll a,b,c;cin>>a>>b>>c;a--,b--;
        wf1[a][b]=c;
        wf1[b][a]=c;   
    }
    rep(k,n)rep(i,n)rep(j,n) wf1[i][j]=min(wf1[i][j],wf1[i][k]+wf1[k][j]);
    rep(i,n){
        rep(j,n){
            if(wf1[i][j]<=l) wf2[i][j]=1;
        }
    }
    rep(k,n)rep(i,n)rep(j,n) wf2[i][j]=min(wf2[i][j],wf2[i][k]+wf2[k][j]);
    ll q;cin>>q;
    while(q--){
        ll s,t;cin>>s>>t;s--,t--;
        if(wf2[s][t]==LINF) cout<<-1<<endl;
        else                cout<<wf2[s][t]-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 1920
H,W = map(int,input().split())
s = []
n = ""
b = ""
a = []
for i in range(H):
  a.append(input())
for j in range(W+2):
  n += "#"
print(n)
for i in range(H):
  a[i] = "#"+a[i]+"#"
  print(a[i])
for j in range(W+2):
  b += "#"
print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define numarr 12
using namespace std;

int main() {
	int a[5], areal[5], adec[5], adecmin = 10, i, ans = 0;
	for (i = 0; i < 5; i++)
	{
		cin >> a[i];
		adec[i] = a[i] % 10;
		if (adec[i] == 0)
			adec[i] = 10;
		areal[i] = a[i] + 10 - adec[i];
		adecmin = min(adecmin, adec[i]);
		ans += areal[i];
	}
	ans -= 10;
	ans += adecmin;
	cout << ans << endl;
}

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

int main(){
  int D,G,p[11],c[11];
  cin>>D>>G;
  for(int i=0;i<D;i++){
    cin>>p[i]>>c[i];
  }
  int ans=1e9;
  for(int bit=0;bit<(1<<D);bit++){
    int s=0,num=0,rest_max=-1;
    for(int i=0;i<D;i++){
      if(bit&(1<<i)){
        s+=100*(i+1)*p[i]+c[i];
        num+=p[i];
      }else{
        rest_max=i;
      }
    }
    if(s<G){
      int s1=100*(rest_max+1);
      int need=(G-s+s1-1)/s1;
      if(need>=p[rest_max]){
        continue;
      }
      num+=need;
    }
    ans=min(ans,num);
  }
  cout<<ans<<endl;
}
    

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

using namespace std;

int main() {
  string s;
  int n;
  cin >>  n >> s;
  if (n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  int c = n / 2;
  string a = "", b = "";
  for (int i = 0; i < n; ++i) {
    if (i >= c) {
      a += s[i];
    } else {
      b += s[i];
    }
  }
  if (a == b) {
    cout << "Yes" << endl;
  } else {;
    cout << "No" << endl;
  }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3==0 || i%5==0){
            ans=ans;
        }
        else{
            ans+=i;
        }
    }
    cout << ans;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end(), greater<int>());
  int result = 0;
  for (i = 0; i < n; i++) {
    if (p[i] >= i + 1) {
      result = max(result, i + 1);
    }
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3164
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
  while (y != 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}

int main() {
  ll a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    int n;
    cin >> n;
    bool ok = 1;
    fori(i, n){
        int x;
        cin >> x;
        ok &= (x % 2 == 0);
    }
    if(ok){
        cout << "second" << endl;
    }
    else{
        cout << "first" << endl;
    }

        time_taken();
    return 0;
}

Measured memory_bytes: 3812
A = input()

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return -1

B = []
for i in range(8):
    if int(A[0]) + f(i//4) * int(A[1]) + f(i//2) * int(A[2]) + f(i) * int(A[3]) == 7:
        if f(i//4) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i//2) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i) == 1:
            B.append('+')
        else:
            B.append('-')
        flag = 1
        break
        
if flag == 1:
    print(A[0]+B[0]+A[1]+B[1]+A[2]+B[2]+A[3]+'=7')

Measured memory_bytes: 3188
// copied
#include <cstdio>
bool A[200001];
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int main(){
  int n,m,a,b;n=read();m=read();
  while(m--){a=read();b=read();
    // A[x] : x can be reached from 1 or x can reach N
    if(a==1){
      if(A[b])return puts("POSSIBLE"),0;
      A[b]=1; 
    }
    if(b==n){
      if(A[a])return puts("POSSIBLE"),0;
      A[a]=1;
    }
  }
  puts("IMPOSSIBLE");
}

Measured memory_bytes: 1596
#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(b-a)<=d && abs(c-b)<=d) ||abs(c-a)<=d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import collections
import itertools
import sys

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

def get_divisor(n):
    if n == 1:
        return [1]
    res = []
    for i in range(1, n):
        if i * i > n:
            break
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return res

n=getint()
divs=get_divisor(n)
res = 10
for d1 in divs:
    d2 = n // d1
    tmp = max(len(str(d1)), len(str(d2)))
    res = min(res, tmp)

print(res)

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int n, a, b;
int main() {
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int n;
int a[mx];
int b[mx];
ll ans;
int main(){
	scanf("%d",&n);
	reg(i,1,n+1){
		scanf("%d",&a[i]);
	}
	reg(i,1,n){
		scanf("%d",&b[i]);
	}
	reg(i,1,n){
		if(a[i]<=b[i]){
			ans+=a[i];
			b[i]-=a[i];
		}else{
			ans+=b[i];
			b[i]=0;
		}
		if(b[i]){
			int t=min(b[i],a[i+1]);
			ans+=t;
			a[i+1]-=t;
		}
	}
	printf("%lld",ans);
	return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

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

int mkn(int a, int b) {
	if (a > b)swap(a, b);
	return a * 1000 + b;
}

int main() {
	int n;
	//fstream fi("C:\\Users\\shinku\\Downloads\\b08.txt");
	cin >> n;
	vector<queue<int>> a(n);
	rep(i, n) {
		rep(j, n - 1) {
			int w;
			cin >> w;
			a[i].push(w - 1);
		}
	}
	int r = 0;
	unordered_set<int> p, f, g, d;
	rep(i, n)g.insert(i);
	while (true) {
		for (auto& e : g) {
			if (!a[e].empty()) d.insert(e);
		}
		if (d.empty()) {
			bool ok = f.empty();
			if (ok) break;
			else {
				r = -1;
				break;
			}
		}
		r++;
		while (!d.empty()) {
			int t = *d.begin(); d.erase(t);
			int s = a[t].front(); a[t].pop();
			if (p.find(mkn(s, t)) == p.end()) {
				f.insert(t);
				g.erase(t);
				p.insert(mkn(s, t));
			}
			else {
				f.erase(s);
				g.insert(s);
				p.erase(mkn(s, t));
			}
		}
	}
	cout << r << endl;
}

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

int main() {
    
    string S;
    cin >>  S;
    int cnt =0, max=0;
    for (int i = 0; i < S.size(); i++)
    {
        if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C'){
            cnt++;
            if(max<cnt) max=cnt;
        }
        else
        {
            cnt=0;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s; cin >> s;
    string arr[7];
    arr[0] = "MON", arr[1] = "TUE", arr[2] = "WED", arr[3] = "THU", arr[4] = "FRI", arr[5] = "SAT", arr[6] = "SUN";
    if(s == arr[6])
    {
        cout << 7;
    }
    else
    {
        for(int i=0; i<6; i++)
        {
            if(s == arr[i])
            {
                cout << 6 - i;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var Q, H, S, D, N int

func main() {
	sc.Split(bufio.ScanWords)

	Q, H, S, D, N = nextInt(), nextInt(), nextInt(), nextInt(), nextInt()

	buy1L := minInt(minInt(4*Q, 2*H), S)
	buy2L := minInt(buy1L*2, D)

	fmt.Println(minInt(buy2L*(N/2)+buy1L*(N%2), buy1L*N))
}


Measured memory_bytes: 1772
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] setu = str.split(",");
        System.out.println(String.format("%s %s %s", setu[0], setu[1], setu[2]));
    }
}

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

int main() {
  ll N, K;
  cin >> N >> K;


  ll ans;
  if (N <= K) {
    ans = min(N, abs(N-K));
  }
  else {
    ll tmp = N % K;
    ans = min(tmp, abs(tmp-K));
  }

  cout << ans << endl;

  return 0;
}


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

vector < pair <char, long long> > data;
string s;
long long k;

int main() {
    cin >> s >> k;

    long long pnt = 0;
        while (pnt < s.size()) {
            long long cnt = 1;
            while (s[pnt] == s[pnt + 1]) {
                cnt++;
                pnt++;
            }
            data.push_back(make_pair(s[pnt], cnt)) ;
            pnt++;
        }

    for (long long i = 0; i < data.size() ; i++)
        cerr << data[i].first << " " << data[i].second << endl;

    if (data.size() == 1)
        cout << (data[0].second * k) / 2 << endl;

    else if (data[0].first != (data.back()).first) {
        long long ans = 0;
        for (long long i = 0; i < data.size(); i++)
            ans += (data[i].second / 2);
        cout << ans * k << endl;
    }

    else if (data[0].second % 2 == 1 && (data.back()).second % 2 == 1) {
        long long ans = 0;
        for (long long i = 0; i < data.size() ; i++)
            ans += (data[i].second / 2);
        cout << (ans * k) + k - 1 << endl;
    }

    else {
        long long ans = 0;
        for (long long i = 0; i < data.size() ; i++)
            ans +=(data[i].second / 2);
        cout << ans * k << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Integer Product
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int K = 9;
const int KK = K * 2 + 1;

/* typedef */

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

/* global variables */

char s[32];
int cs[KK + 1][KK + 1];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    ll a = 0;
    int k = -1;
    for (int j = 0; s[j]; j++) {
      if (s[j] == '.') k = 0;
      else {
	a = a * 10 + (s[j] - '0');
	if (k >= 0) k++;
      }
    }
    if (k < 0) k = 0;
    //printf("%lldE%d\n", a, -k);

    int e2 = -k, e5 = -k;
    for (; a % 2 == 0; a /= 2) e2++;
    for (; a % 5 == 0; a /= 5) e5++;
    if (e2 > K) e2 = K;
    if (e5 > K) e5 = K;
    cs[e2 + K][e5 + K]++;
    ps[i] = pii(e2, e5);
    //printf("(%d,%d)\n", e2, e5);
  }

  for (int i = KK - 1; i >= 0; i--)
    for (int j = KK - 1; j >= 0; j--)
      cs[i][j] += cs[i + 1][j] + cs[i][j + 1] - cs[i + 1][j + 1];

  //for (int i = 0; i < KK; i++) {
  //for (int j = 0; j < KK; j++) printf("%2d ", cs[i][j]);
  //putchar('\n');
  //}

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int e2 = ps[i].first, e5 = ps[i].second;
    sum += cs[-e2 + K][-e5 + K];
    if (e2 >= 0 && e5 >= 0) sum--;
  }

  printf("%lld\n", sum / 2);
  return 0;
}


Measured memory_bytes: 4692
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const ld PI=abs(acos(-1));
int a,b,n;
ll k;
vector<pair<int,int>> vec;

int main(){
	cin >> n >> k;
	REP(i,0,n) cin >> a >> b,vec.push_back(make_pair(a,b));
	sort(vec.begin(),vec.end());
	
	ll pos=0;
	REP(i,0,vec.size()){
		pos+=vec[i].second;
		if(k<=pos){
			cout << vec[i].first << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n";
#define pb push_back
#define f first
#define s second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e3+10;
int dp[N][N];
vector<pair<int,int> >v;
int go(int pos,int l,int r)
{
    if(pos==v.size())
    {
        return 0;
    }
    int &ans=dp[l][r];
    if(ans!=-1)
        return ans;
    ans=0;
    ans=max(ans,go(pos+1,l+1,r)+v[pos].f*abs(v[pos].s-l));
    ans=max(ans,go(pos+1,l,r-1)+v[pos].f*abs(v[pos].s-r));
    return ans;

}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        v.pb({x,i});
    }
    sort(all(v));
    reverse(all(v));
    cout<<go(0,1,n)<<endl;  
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;
const ll MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve(long long X, long long Y){
  COMinit();
  if((2*X-Y)%3!=0) {
    std::cout << 0 << std::endl;
    return;
  }
  ll n = (2*X-Y)/3;
  std::cout << COM(X-n, n) << std::endl;
  
}

int main(){
  long long X;
  scanf("%lld",&X);
  long long Y;
  scanf("%lld",&Y);
  solve(X, Y);
  return 0;
}


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


int main()
{
	string s,t; int n=0;
	while(cin >> s)
	{
		t=s;
		reverse(t.begin(), t.end());
		if(s==t)n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

bool is_match(const string& s, const string& t)
{
	if (s.length() != t.length()) return false;

	FOR_LT(i, 0, s.length()) {
		if (s[i] == '?') continue;
		else if (s[i] != t[i]) return false;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	FOR_DW(i, s.length() - 1, 0) {
		if (is_match(s.substr(i, t.length()), t)) {
			FOR_LT(j, 0, t.length()) {
				s[i + j] = t[j];
			}
			FOR_LT(j, 0, s.length()) {
				if (s[j] == '?') s[j] = 'a';
			}
			cout << s << endl;

			return 0;
		}
	}

	cout << "UNRESTORABLE" << endl;

	return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()


def isOk(k):
    return k >= 0


ok, ng = max(h)//B+1, 0
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    c = mid
    for i in range(N):
        t = h[i]-mid*B
        if t > 0:
            c -= (t+A-B-1)//(A-B)
            if c < 0:
                break
    if isOk(c):
        ok = mid
    else:
        ng = mid

print(ok)

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n ;cin >> n;
	vector<int>v(n); cin >> v;
	int ans = 0;
	int want = 1;
	for(int i = 0 ; i < n ;i ++) {
		if(v[i] == want) {
			want++;
		} else {
			ans++;
		}
	}
	if(ans == n) {
		w << -1;
	} else w << ans;
}
	
		
        


Measured memory_bytes: 1792
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


n,k = map(int, input().split())
sn = list(str(input()))
snum = [1] * (10**5)

l = 0
for i in range(1,n):
  if sn[i-1] == sn[i]:
    snum[l] += 1
  else:
    l += 1
snum = snum[:l+1]

if sn[0] == '1':
  snum = [0] + snum
if sn[-1] == '1':
  snum = snum + [0]

csnum = [0] * (len(snum)+1)
for i in range(len(snum)):
  csnum[i+1] = csnum[i] + snum[i]


## solve
l = 0
mx = 0
for r in range(len(csnum)):
  if r&1 == 1 and (r-l+1)//2 > k:
    l += 2
  mx = max(mx, csnum[r] - csnum[max(0,l-1)])

print(mx)

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

ll ce(ll a, ll b) {
    if (a > 0) {
        return (a + b - 1) / b;
    } else {
        return a / b;
    }
}

ll fl(ll a, ll b) {
    if (a < 0) {
        return (a - (b - 1)) / b;
    } else {
        return a / b;
    }
}

ll check_over_x(const vll& a, ll x) {
    int n = a.size();
    ll sum = 0;

    rep(i, 1, n) {
        if (a[i] < 0) {
            ll target = ce(-x, -a[i]);
            sum += i - (distance(a.begin(), lower_bound(a.begin(), a.begin() + i, target)));
        } else if (a[i] == 0) {
            if (x >= 0) { sum += i; }
        } else {
            ll target = fl(x, a[i]);
            sum += distance(a.begin(), upper_bound(a.begin(), a.begin() + i, target));
        }
    }

    return sum;
}

int main() {
    ll n, k;
    cin >> n >> k;

    vll a(n);
    rep(i, 0, n) { cin >> a[i]; }
    sort(a.begin(), a.end());
    ll left = -1e18, right = 1e18;

    while (left + 1 < right) {
        ll mid = (left + right) / 2;
        ll sum = check_over_x(a, mid);
        if (sum >= k) {
            right = mid;
        } else {
            left = mid;
        }
    }
    cout << right << endl;
}

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

int n;
ll in[10][10];

int calc(int val) {
	while (val >= 10) val /= 10;
	return val;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	ll res;
	while (cin >> n) {
		memset(in, 0, sizeof(in));
		for (int i = 1; i <= n; ++i) {
			int a, b;
			a = calc(i);
			b = i % 10;
			in[a][b]++;
		}

		res = 0;
		for (int i = 1; i <= 9; ++i) {
			for (int j = 1; j <= 9; ++j) res = res + in[i][j] * in[j][i];
		}
		cout << res << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

string bin(int x){
    if(!x) return "0";
    string ans;
    while(x){
        ans += to_string(x&1);
        x /= 2;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}

int main() {
    int n;
    cin >> n;
    if(n == 1){
        cout << 1 << "\n";
        cout << 0 << "\n";
    }else if(n == 2){
        cout << 2 << "\n";
        cout << 0 << "\n";
        cout << 11 << "\n";
    }else {
        cout << n-1 << "\n";
        for (int i = 2; i <= n; ++i) {
            string s(i, '0');
            s.front() = s.back() = '1';
            cout << s << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    ll N,ans = 0;
    cin >> N;
    for (ll r = 1; r*r <= N ; ++r) {
        ll m = (N-r)/r;
        if((N-r)%r == 0 && m > r) ans += m;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

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

ll n, a[100000], ans = 1;
bool toobig = false;

int main() {
  cin >> n;
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (a[i] > 1000000000000000000 / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}

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

const int N = 2e5+5;

int main()
{
	long long n, d, a;
	long long ans = 0, cur = 0;
	vector<pair<long long, long long>> monsters(N);
	queue<pair<long long,long long>> q; //dist , contribution to cur
	cin >> n >> d >> a;
	d *= 2;
	for(int i = 0; i < n; ++i)
		cin >> monsters[i].first >> monsters[i].second;
	sort(monsters.begin(), monsters.begin()+n);

	for(int i = 0; i < n; ++i){
		while(!q.empty()){
			if(q.front().first < monsters[i].first){
				cur -= q.front().second;
				q.pop();
			}
			else
				break;
		}
		monsters[i].second -= (cur*a);
		if(monsters[i].second > 0){
			long long contrib = ((monsters[i].second + a - 1) / a);
			ans += contrib;
			cur += contrib;
			q.push({monsters[i].first+d, contrib});
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4992
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
// ciling(x/y) = (x+y-1)/y

typedef long long ll;
typedef unsigned long long ull;
// }}}

ll n, a, b;
vector<ll> h;

bool enagh(ll t) {
    ll count = 0;
    for(auto hh : h){
        if(b*t < hh){
            count += (hh-b*t + a-b - 1LL)/(a-b);
        }
    }
    return count <= t;
}

int main() {
    cin >> n >> a >> b;
    for(int i=0;i<n;i++){
        ll hh;cin >> hh;
        h.push_back(hh);
    }

    // binary search
    ll l = 0;
    ll r = INF;
    ll m = (l+r)/2;
    while(l!=r){
        if(enagh(m)){
            r = m;
        }else{
            l = m+1;
        }
        m = (l+r)/2;
    }

    cout << m << endl;

    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;


int dp[111][111];


struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h)cin>>s[i];
    rep(i,h)rep(j,w){
        if(i%2==0 && j%2 ==0){
            if((i-j)%4==0 && s[i][j]!='6')s[i][j]='#';
            if((i-j)%4!=0 && s[i][j]!='1')s[i][j]='#';
        }
        if(i%2==0 && j%2 != 0){
            if(j%4 == 1 && s[i][j]!='3')s[i][j]='#';
            if(j%4 == 3 && s[i][j]!='4')s[i][j]='#';
        }
        if(i%2==1 && j%2 == 0){
            if(i%4 == 1 && s[i][j]!='2')s[i][j]='#';
            if(i%4 == 3 && s[i][j]!='5')s[i][j]='#';
        }
    }
    UnionFind uf(h*w);
    rep(i,h)rep(j,w-1){
        if(s[i][j]!='#'&&s[i][j+1]!='#')uf.unite(i*w+j,i*w+j+1);
    }
    rep(i,h-1)rep(j,w){
        if(s[i][j]!='#'&&s[i+1][j]!='#')uf.unite(i*w+j,i*w+j+w);
    }
    if(uf.same(0,h*w-1))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3288
N, M, K = map(int, input().split())
INF = 10**9

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


union_find = UnionFind(N)
friend_num_list = [0]*N
block_num_list = [0]*N

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friend_num_list[a] += 1
    friend_num_list[b] += 1
    union_find.union(a, b)

for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if union_find.same(c, d):
        block_num_list[c] += 1
        block_num_list[d] += 1

ans_list = [0]*N
for i in range(N):
    ans = union_find.size(i) - friend_num_list[i] - block_num_list[i] - 1
    ans_list[i] = ans
print(*ans_list)


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

long long gcd(long long a,long long b)
{
 
  if(b==0)
  {
    return a;
  }
  
  else
  {
    return gcd(b,a%b);
  }
  
}
int main()
{
  long long a,b,ans;
  cin>>a>>b;
  
  if(a>=b)
  {
    ans= gcd(a,b);
  }
  
  else
  {
    ans = gcd(b,a);
  }
  
  long long lcm;
  
  lcm= (a*b)/ ans;
  
  cout<<lcm<<endl;
  
}

Measured memory_bytes: 256
n = int(input())
s = [int(input()) for _ in range(n)]
d = sum(s)
sortS = sorted([i for i in s if i % 10 != 0])

result = 0
if d % 10 != 0:
    print(d)
else:
    if len(sortS) == 0:
        print(0)
    else:
        print(d - sortS[0])


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
int H,W;

while(1){
cin >> H >> W;
if(H==0&&W==0)break;
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){if((i+j)%2==1){cout << ".";}else{cout << "#";}
}
cout << "\n";
}
cout << endl;
}



return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string b; cin >> b;
    for(ll i=0; i<b.size(); i++){
        if(b[i] == 'A') cout << 'T';
        if(b[i] == 'T') cout << 'A';
        if(b[i] == 'C') cout << 'G';
        if(b[i] == 'G') cout << 'C';
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace aoj
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int idx = Partion(array, 0, n - 1);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < idx; i++) sb.Append(array[i] + " ");
            sb.Append("[" + array[idx] + "]");
            for (int i = idx + 1; i < n; i++) sb.Append(" " + array[i]);
            Console.WriteLine(sb);
            //Console.ReadLine();
        }

        static int Partion(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 = i + 1;
                    int tmp = A[i];
                    A[i] = A[j];
                    A[j] = tmp;
                }

            }
            int tmp2 = A[i + 1];
            A[i + 1] = A[r];
            A[r] = tmp2;
            return i + 1;

        }
    }
}



Measured memory_bytes: 20620
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define endl '\n'
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <=n; i++)
#define rep2(i, n) for (i = 0; i < n-1; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //Sort in reverse,Vector.
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.


int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   
   int n,x;

   cin>>n;

   if(n%1000==0)
   	x=n/1000;

   else
   	x=n/1000 + 1;

   cout<<(x*1000)-n;

}    


Measured memory_bytes: 3656
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

satisfactory = 0
for i in range(n):
  bi = a[i] - 1
  satisfactory += b[bi]
  if i > 0 and a[i] - a[i-1] == 1:
    ci = a[i-1] - 1
    satisfactory += c[a[i-1]-1]
print(satisfactory)

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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 10000111;
const int maxa = 5111;
const int mod = 1e9 + 7;
int qpow(int x, int y)
{
	int ret = 1;
	while(y)
	{
		if(y & 1) ret = 1ll * ret * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return ret;
}

int n, a, fac[maxn], inv[maxn], c[maxa][maxa];
int main()
{
	fac[0] = 1; for(int i=1; i<maxn; i++) fac[i] = 1ll * i * fac[i-1] % mod;
	inv[1] = 1; for(int i=2; i<maxn; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i=0; i<maxa; i++)
	{
		c[i][0] = 1;
		for(int j=1; j<=i; j++)
		{
			c[i][j] = c[i-1][j] + c[i-1][j-1];
			if(c[i][j] >= mod) c[i][j] -= mod;
		}
	}
	
	get2(n, a);
	
	int ans = 0;
	for(int i=1; i<=a; i++)
	{
		int sum = 1ll * fac[i == a ? n : n - 1] * i % mod * inv[i + n - a] % mod;
		for(int j=1; j<i; j++)
		{
			int now = 1ll * c[i][j] * fac[(i == a ? n : n - 1) - j] % mod * (i - j) % mod * inv[i - j + n - a] % mod;
			if(j & 1)
			{
				sum -= now;
				if(sum < 0) sum += mod;
			}
			else
			{
				sum += now;
				if(sum >= mod) sum -= mod;
			}
		}
		ans += sum;
		if(ans >= mod) ans -= mod;
	}
	printendl(ans);
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  rep(i,5) {
    if (x[i] == 0) {
      cout << i+1 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
const int maxn=50000+10;
int n;
long long w;
int data[maxn];
long long sum[maxn];
int len;
int low,high,mid;
bool mark[maxn];

struct Tree {
    int a[maxn], n;
    void init(int m) {
        memset(a, 0, sizeof(a));
        n = m;
    }
    int lowbit(int x) {
        return x & (-x);
    }
    void insert(int x, int y) {
        while (x <= n) {
            a[x] += y;
            x += lowbit(x);
        }
    }
    int sum(int x) {
        int ret = 0;
        while (x) {
            ret += a[x];
            x -= lowbit(x);
        }
        return ret;
    }
}F;

bool check(int ans)
{
    memset(mark,0,sizeof(mark));
    mark[0]=1;
    int p=1,q=0;
    int tot=0;
    for (int i=2;i<=n;i++)
    {
        while (w-(sum[i]-sum[p-1])<i-p) {if (mark[p-1]) tot--;p++;}
        while (w-(sum[i]-sum[q])<=ans*(i-q-1) && q + 1 != i) {if (mark[q])tot++;q++;}
//        if (ans==1) cout<<p<<' '<<q<<' '<<tot<<endl;
        if (p<=q && tot>0) mark[i]=1;
    }
/*
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<mark[i]<<' ';
    cout<<endl;
    */
    for (int i=n;i>=0;i--)
    {
        if (mark[i] && (w-(sum[n]-sum[i])>=n-i)) return 1;
    }
    return 0;
}

void init()
{
    memset(sum,0,sizeof(sum));
    for (int i=1;i<=n;i++) sum[i]=sum[i-1]+data[i];
}

void work()
{
    for (int i=1;i<=n;i++) scanf("%d",&data[i]);
    init();
    low=0;high=w;
    int tot=0;
    while (low+1<high)
    {
        mid=(low+high)/2;

        ++tot;
        if (check(mid)) high=mid; else low=mid;
    }
    printf("%d\n",high);
}

int main() {
    while (scanf("%lld%d",&w,&n)!=EOF && (w!=0 || n!=0)) work();
    return 0;
}

Measured memory_bytes: 1832
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int A,B,C,X;
  int cnt=0;
  int num;
  int tmp1,tmp2;

  cin >> A >> B >> C >> X;

  for(int i = A; i >= 0; i--){
    if(i*500 <= X){
      tmp1 = X-i*500;
      for(int j = B; j >= 0; j--){
        
        if(j*100 <= tmp1){
          tmp2 = tmp1 - j*100;

          for(int k = C; k>=0; k--){
          
            if(tmp2/50 == k ){
              cnt++;
            }
          }
          
        }
      }
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
'use strict';

const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const numbers = input[0].split(' ').map(n => parseInt(n, 10));

const h = numbers[0];
const w = numbers[1];

console.log('#'.repeat(w + 2));

for (let i = 1; i < h + 1; i++) {
  const line = input[i];
  console.log('#' + line + '#');
}

console.log('#'.repeat(w + 2));

Measured memory_bytes: 7500