akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
	static int insertionSort(int[] A, int n, int g){
		int i, j, v, cnt = 0;
		
		for(i = g; i < n; i++){
			v = A[i];
			j = i -g;
			
			while(j >= 0 && A[j] > v){
				A[j + g] = A[j];
				j = j - g;
				cnt ++;
			}
			
			A[j + g] = v;
		}
		
		return cnt;
	}
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, i, g, cnt = 0, m = 0;
		int[] A = new int[1000000], G = new int[100];
		
		n = sc.nextInt();
		for(i = 0; i < n; i++){
			A[i] = sc.nextInt();
		}
		
		while(true){
			if(m == 0){
				g = 1;
			}
			else{
				g = 3 * G[m - 1] + 1;
			}
			
			if(g > n){
				break;
			}
			
			G[m] = g;
			m ++;
		}
		
		for(i = 0; i < m; i++){
			cnt += insertionSort(A, n, G[m - 1 - i]);
		}
		
		System.out.println(m);
		for(i = 0; i < m - 1; i++){
			System.out.print(G[m - 1 - i] + " ");
		}
		System.out.println(G[m - 1 - i]);
		System.out.println(cnt);
		for(i = 0; i < n; i++){
			System.out.println(A[i]);
		}
	}
}

Measured memory_bytes: 298116
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
#define INF (1LL<<60)
#define MOD 1000000007
#define MAX_N 30000
class Dinic {
public:
  struct Edge { int to, cap, rev; };
  vector<Edge> G[MAX_N];
  int level[MAX_N], iter[MAX_N];

  void add_edge(int from, int to, int cap) {
    G[from].pb((Edge) { to, cap, (int)G[to].size() });
    G[to].pb((Edge) { from, 0, (int)G[from].size() - 1 });
  }

  void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (int i=0; i<G[x].size(); i++) {
        Edge &e = G[x][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[x] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int x, int t, int f) {
    if (x == t) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      int f;
      while (true) {
        f = dfs(s, t, INF);
        if (f <= 0) break;
        flow += f;
        if (flow >= INF) return INF;
      }
    }
  }
};


int N;
int A[100];
Dinic dinic;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  long long sum = 0;
  rep(i, N) {
    if (A[i] > 0) sum += A[i];
    if (A[i] > 0) dinic.add_edge(i, N+1, A[i]);
    else if (A[i] < 0) dinic.add_edge(N, i, -A[i]);
  }
  rep(i, N) for (int j=i+1; j<N; j++) if ((j+1) % (i+1) == 0) dinic.add_edge(i, j, INF);
  int f = dinic.max_flow(N, N+1);
  cout << sum - f << "\n";
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

const int max_N = 1000009;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> l(N);
	for(int i=0; i<N; i++) cin >> l[i];
	
	sort(l.begin(), l.end(), greater<int>());
	cout << accumulate(l.begin(), next(l.begin(), K), 0);	
	return 0;
}


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

int main(){
    long long n, m;
    cin >> n >> m;
    if((2*n)==m)
    	cout << n << endl;
    else if((2*n)<m)
    	cout << (n+((m-(2*n))/4)) << endl;
    else
    	cout << (m/2) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const LL MOD = 1e9+7;
const LL INF = 1LL<<60;
int MAXN = 1e7+2;
const double eps = 1e-13;


int main(){
	DRII(n,k);
	int gc=0,mx=0;
	REP(i,n){
		DRI(x);
		gc=__gcd(gc,x);
		mx=max(mx,x);
	}
	if(k<=mx&&mx%gc==k%gc)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

bool isPalindrome(int n) {
    return (n / 10000) == (n % 10) && (n / 1000 % 10) == (n / 10 % 10);
}

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

    int cnt = 0;
    for (int i = a; i <= b; i++) {
        if (isPalindrome(i))
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3572
def input_int():
    return int(input())

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

X = input_int()

def divs(n):
    i = 1
    res = []
    while i * i <= n:
        if n % i == 0:
            res.append(i)
            res.append(n // i)
        i += 1
    return res

import sys

for d in divs(X):
    for i in range(-10000, 10000):
        if (i + d) ** 5 - i ** 5 == X:
            print(i + d, i)
            sys.exit(0)



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



int main (){
	int a,b,c,x,y;
	int ans=0;


	cin >> a >> b >> c >> x >>y;

	if((a+b)>=2*c){
		if(x>=y){
				ans += c*y*2 + min(2*c,a)*(x-y);
		}
		else if(y>x){
			ans += c*2*x + min(2 * c,b) * (y-x);
		}
	}
	else ans = a*x+b*y;



	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    char prev = 'X';
    int ans = 0;
    for (int i = 0; s[i]; ++ i) {
        if (s[i] != prev) ans ++;
        prev = s[i];
    }
    cout << ans - 1;
    
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int N,A[100010];
bool Cmp(const int &X,const int &Y){
	return X>Y;
}
int main(){
	scanf("%d",&N);
    for(int i=1;i<=N;i++){
    	scanf("%d",&A[i]);
	}
    sort(A+1,A+N+1,Cmp);
    /*
    for(int i=1;i<=N;i++){
    	printf("%d ",A[i]);
	}
	printf("\n");
	*/
    for(int i=1;i<=N;i++){
        if(i+1>A[i+1]){
            int Ans=0;
            for(int j=i+1;A[j]==i;j++){
            	Ans=Ans^1;
			}
            Ans=Ans|((A[i]-i)&1);
            if(Ans){
            	printf("First\n");
			}else{
				printf("Second\n");
			}
            return 0;
        }
    }
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt() - 1;
			}
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[a[i]] == i) {
					++ans;
				}
			}
			out.println(ans / 2);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 22508
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  cin>>a>>b;
  c=a+b;
  d=a-b;
  e=a*b;
  a=max(d,c);
  a=max(a,e);
  cout<<a;
}

Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	string s;
	cin >> s;
	if(s[2]==s[3] && s[5]==s[4]) cout << "Yes";
	else cout << "No";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map <long long,long long> ima;
int main(){
    long long n,k,sol = 0;
    cin >> n >> k;
    for(long i = 1; i <= n; i++){
        ima[i%k]++;
    }
    for(long md = 0; md < k; md++){
        if((md*2)%k != 0){
            continue;
        }
        long long kolko = ima[md];
        //cout << md << " " << kolko << endl;
        sol += kolko;
        sol += max(0ll,kolko*(kolko-1)*3);
        sol += max(0ll,kolko*(kolko-1)*(kolko-2));
    }
    cout << sol << endl;
}


Measured memory_bytes: 6528
n = int(input())

cnt = 0

def dfs(s):    
    global cnt
    
    if int(s) > n:
        return None
    
    else:
        if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
            cnt += 1
            
        dfs(s+'3')
        dfs(s+'5')
        dfs(s+'7')


dfs('0')
print(cnt)

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int A, B;
    string S;
    cin >> A >> B >> S;
    int N = S.size();
    if (S[A] != '-') {
        cout << "No" << endl;
        return 0;
    }
    REP(i, N) {
        if (i != A && !isdigit(S[i])) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let (_n, m) = read_tuple::<i64>();
    let an: Vec<f64> = read_vec::<i64>().iter().map(|&v| v as f64).collect();
    let total: f64 = an.iter().sum();

    let count: usize = an.iter().filter(|&&v| v >= total / (4.0 * m as f64)).count();

    if count >= m as usize {
        println!("Yes");
    } else {
        println!("No");
    }

}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    string str; cin >> str;
    for(int i = 0; i < (int)str.size(); i++){
        if(i == 3){
            cout << '8';
        }else{
            cout << str[i];
        }
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
const int mod = 998244353;
int n,q,l,r,d,dp[10][maxn],Pow[maxn];
int tr[maxn<<2],lz[maxn<<2];
void build(int l,int r,int x){
    if(l == r){
        tr[x] = Pow[n-r];
        return;
    }
    int mid = (l+r) >> 1;
    build(l,mid,x<<1);
    build(mid+1,r,x<<1|1);
    tr[x] = (tr[x<<1]+tr[x<<1|1])%mod;
}
void pushdown(int x,int y,int l,int r){
    lz[y] = lz[x];
    tr[y] = 1ll*dp[lz[x]][r-l+1]*Pow[n-r]%mod;
}
void updata(int l,int r,int L,int R,int x,int d){
    if(l > R || r < L) return ;
    if(l >= L && r <= R){
        lz[x] = d;
        tr[x] = 1ll*dp[d][r-l+1]*Pow[n-r]%mod;
        return ;
    }
    int mid = (l+r) >> 1;
    if(lz[x]){
        pushdown(x,x<<1,l,mid);
        pushdown(x,x<<1|1,mid+1,r);
        lz[x] = 0;
    }
    updata(l,mid,L,R,x<<1,d);
    updata(mid+1,r,L,R,x<<1|1,d);
    tr[x] = (tr[x<<1]+tr[x<<1|1])%mod;
}
int main(){
    scanf("%d %d",&n,&q); Pow[0] = 1;
    for(int i = 1;i <= n; ++i){
        Pow[i] = 1ll*Pow[i-1]*10%mod;
        for(int x = 1;x <= 9; ++x){
            dp[x][i] = (1ll*dp[x][i-1]*10+x)%mod;
        }
    }
    build(1,n,1);
    while(q--){
        scanf("%d %d %d",&l,&r,&d);
        updata(1,n,l,r,1,d);
        printf("%d\n",tr[1]);
    }
    return 0;
}

Measured memory_bytes: 15756
#include<cstdio>
#include<cstring>

using namespace std;

int main(){
	char s1[202],t[101],p1[101];
	
	scanf("%s %s",s1,p1);
	
	strcpy(t,s1);
	strcat(s1,t);
	
	if(strstr(s1,p1) == NULL) printf("No\n");
	else printf("Yes\n");
	
	return 0;
	
}

Measured memory_bytes: 972
import sys
sys.setrecursionlimit(10**9)

n = int(input())
A = list(map(int, input().split()))

memo = [[float('inf')]*410 for _ in range(410)]
visit = [[False]*410 for _ in range(410)]

from itertools import accumulate
B = [0]+A
B = list(accumulate(B))

def dp(l, r):
  if l == r:
    return 0
  if visit[l][r]:
    return memo[l][r]
  visit[l][r] = True
  res = float('inf')
  for c in range(l, r):
    res = min(res, dp(l, c)+dp(c+1, r)+B[r+1]-B[l])
  memo[l][r] = res
  return res

print(dp(0, n-1))

Measured memory_bytes: 50208
#include<iostream>
#include <queue>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    int s[h][w];
    REP(i, h){
        string str;
        cin >> str;
        REP(j, w){
            s[i][j] = str[j];
        }
    }
    string ans = "Yes";
    REP(i, h){
        REP(j, w){
            if(s[i][j] == '.') continue;
            if(i-1>=0 && s[i-1][j] == '#') continue;
            if(i+1<h && s[i+1][j] == '#') continue;
            if(j-1>=0 && s[i][j-1]=='#')continue;
            if(j+1<w && s[i][j+1] == '#') continue;
            ans = "No";
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int n;
int a[110000];
int f[110000];

int LIS(int n)
{
    int res = 0;
    int max1 = 0;
    for(int i = 1; i < n; ++i)
    {
        if(a[i] <= a[i - 1]) {
        	res++;
			max1 = max(max1,res);
		}else{
			
			res = 0;
		}
    }
    return max1;
}


int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%d",&a[i]);
	int ans = LIS(n);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[12],c[12],kei[12],ans=inf,d,g;
bool ch[12];
void cal(){
	ll sum=0;
	ll sum1=0;
	for(ll i=0;i<d;i++){
		if(ch[i]){
			sum+=kei[i];
			sum1+=a[i];
		}
	}
	if(sum>=g){
		ans=min(ans,sum1);
		return ;
	}
	for(ll i=d-1;i>=0;i--){
		if(ch[i]){
			continue;
		}
		else{
			if(((g-sum)+(i+1)*100-1)/((i+1)*100)>a[i]){
				return ;
			}
			sum1+=((g-sum)+(i+1)*100-1)/((i+1)*100);
			ans=min(sum1,ans);
		}
	}
}
void dep(ll now){
	if(now==d){
		cal();
		return ;
	}
	ch[now]=0;dep(now+1);
	ch[now]=1;dep(now+1);
}
int main() {
	cin>>d>>g;
	for(ll i=0;i<d;i++){
		ll x,y;
		cin>>x>>y;
		a[i]=x;c[i]=y;
		kei[i]=(i+1)*x*100+y;
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iomanip>
using namespace std;
long Nchoose2(long n){
    return n*(n-1)/2;
}
int main(){
    int n,k;
    cin >> k >> n;
    int ans = 0;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> dif(n);
    int Max = 0;
    for(int i = 0; i < n-1; i++){
        dif[i] = a[i+1] - a[i];
        Max = max(Max, dif[i]);
    }
    dif[n-1] = a[0] - a[n-1] + k;
    Max = max(Max, dif[n-1]);
    ans = k - Max;
    cout << ans << endl;   
}

Measured memory_bytes: 1920
package main

import (
	"fmt"
)

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

func main() {
	var n, sum int
	fmt.Scan(&n)
	a := make([]int, n)
	d := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if i == 0 {
			d[0] = abs(a[0])
			sum = d[0]
			continue
		}
		d[i] = abs(a[i] - a[i-1])
		sum += d[i]
	}
	d[n] = abs(a[n-1])
	sum += d[n]

	for i := 0; i < n; i++ {
		r := sum - d[i] - d[i+1]
		if i == 0 {
			fmt.Println(r + abs(a[i+1]))
			continue
		}
		if i == n-1 {
			fmt.Println(r + abs(a[i-1]))
			continue
		}
		fmt.Println(r + abs(a[i-1]-a[i+1]))
	}
}


Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main(){
	
int n,a,b;
while(1){
	cin>>n>>a>>b;
	if(!n&&!a&&!b)return 0;
	vector<int>k(n+1);
	for(int i=0;i<n;i++)cin>>k[i];
	sort(k.begin(),k.end());
	reverse(k.begin(),k.end());
	int m=k[a-1]-k[a],y=a;
	for(int i=a-1;i<b;i++){
		if(k[i]-k[i+1]>=m){
			m=k[i]-k[i+1];y=i+1;
		//	cout<<m<<" ";
		}
	}
	cout<<y<<endl;
	

}

	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const string YES = "Yes";
const string NO = "No";

int main(){
    int n;
    cin >> n;
    vpii ab(n);
    rep(i, n) cin >> ab[i].second >> ab[i].first;
    sort(all(ab));
    bool ans = true;
    int t = 0;
    rep(i, n) {
        t += ab[i].second;
        if (t > ab[i].first) ans = false;
    }
    cout << (ans?YES:NO) << endl;
    return 0;
}


Measured memory_bytes: 1792
#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>
#include<stdio.h>
using namespace std;
int main(){
    while (1){
        int h, w;
        cin >> h >> w ;
        if (h == 0 && w == 0){

            break;
        } else{
            int i, j;
            for( i =  0; i<h; i++){
                for( j = 0; j < w; j++){
                    if ((i + j) % 2 == 0){
                        cout << "#" ;
                    } else {
                        cout << "." ;
                    }

                }cout << "\n";
            }
            cout << "\n";
        }
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int Ans=0;
  for(int i=0; i<10; i++){
    if(N<pow(2, i)){
      cout << pow(2, i-1) << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>

using namespace std;

/*
  replace from[i] in s to to[i]. 
  size of from and size of to should be equal.
  verified:
 */
string replace_all(const string& s, const vector<string>& from, const vector<string>& to){
  int size = from.size();
  vector<int> v[size];

  for(int i = 0; i < size; i++) v[i].push_back(-1);
  
  for(int i = 0; i < size; i++){
    while(1){
      int pos = s.find(from[i],v[i].back()+1);
      if(pos == -1) break;
      v[i].push_back(pos);
    }
  }

  string res = s;
  int diff = 0;

  for(int i = 0; i < size; i++)
    for(int j = 1; j < (int)v[i].size(); j++){
      res.replace(v[i][j]+diff, from[i].length(), to[i], 0, to[i].length());
      diff += (to[i].length()-from[i].length());
    }
  return res;
}

int main(){
  string s;
  getline(cin, s);
  vector<string> a(2),b(2);
  a[0] = b[1] = "apple";
  a[1] = b[0] = "peach";
  cout << replace_all(s, a, b) << endl;
  return 0;
}

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

int tof[1000005] ;
int fot[1000005] ;
int main(){
ll  n;cin>> n ;
vector<ll> A(n);
rep(i,n) cin>>A[i] ;
sort(A.begin(),A.end()) ;

rep(i,1000005) tof[i]=0 ;
 rep(j,n){
  ll u=A[j] ;
  if(fot[u]!=0) continue ;
  fot[u] ++ ;
   for(ll i=u*2 ;i<=1000003 ;i+=u){
      if(tof[i]!=0) continue ;
      tof[i]=1 ;
   }
  
 }
 rep(i,n) tof[A[i]]++ ;
 ll ans=0 ;
 rep(i,n) if(tof[A[i]]==1) ans++ ;
   cout<<ans<<"\n" ;
  return 0;
  }

Measured memory_bytes: 12520
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000

long long dis(long long a,long long b,long long m){
	if(b>=a)return b-a;
	else return b-a+m;
}

int main(){
	
	long long n,m;
	cin>>n>>m;
	
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	
	vector<long long> Add(m,0),Del(m,0),DelS(m,0);
	
	for(int i=0;i<n-1;i++){
		Add[(a[i]+1)%m]++;
		Del[a[i+1]]++;
		DelS[a[i+1]]+= dis(a[i],a[i+1],m)-1;
	}
	
	long long ans = Inf;
	long long now = 0;
	long long sa = 0;
	for(int i=0;i<m;i++){
		if(i==0){
			for(int j=0;j<n-1;j++){
				long long x = dis(a[j],a[j+1],m);
				long long y = 1+dis(0,a[j+1],m);
				if(x>y){
					sa--;
					now+=y;
				}
				else now+=x;
			}
				
		}
		//cout<<now<<','<<sa<<endl;
		ans = min(ans,now);
		sa -= Add[i];
		sa += Del[i];
		now += DelS[i];
		now += sa;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 2e5 + 41;

int n, k;
int ans;
int a[MAX];

int const INF = 1e9 + 41;

int calc(int x) {
	int l = -1;
	int r = n + 1;
	while (r - l > 1) {
		int h = (l + r) / 2;
		ll y = (ll) x - (ll) k * h + h;
		if (y <= 1) {
			r = h;
		} else {
			l = h;
		}
	}
	return r;
}

void solve() {
	ans = INF;
	int x = -1;
	fi(1, n) {
		if (a[i] == 1) x = i;
	}
	fi(max(1, x - k + 1), x) {
		int pans = calc(i) + calc(n - (i + k - 1) + 1) + 1;
		ans = min(ans, pans);
	}
	printf("%d\n", ans);
}

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

	scanf("%d %d", &n, &k);
	fi(1, n) {
		scanf("%d", &a[i]);
	}
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>//
#include <cmath>

using namespace std;

long long t, i;
long long ans = 0;

int main() {
    cin >> t;

    for (i = sqrt((long double) t) + 1; i > 0; --i) {
        if (t % i == 0) {
            ans += i;
            ans += t / i;
            break;
        }
    }

    cout << ans - 2;
    return 0;
}
// Created by Kevin Weng on 2019/10/30.
//



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  char a,b,c='A';
  for(;~scanf("%c,%c",&a,&b);)
    {
    if(c==a)
      c=b;
    else if(c==b)
      c=a;
    }
  printf("%c\n",c);
  exit(0);      
}

Measured memory_bytes: 544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

int main(){
    int N;
    cin >> N;
    vi(A, N);
    rep(i, N) cin >> A.at(i);
    srt(A);
    cout << A.at(N-1) - A.at(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
int n;
int a[200007];
ll ans;
int main(){
	scanf("%d",&n);
	int maxn=0;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		maxn=std::max(maxn,a[i]);
		ans+=maxn-a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
ll dp[3030][3030][5] = {0};
int main(){ 
  int n, m, K;
  cin >> n >> m >> K;
  vector<vector<int>> v(n, vector<int>(m, 0));
  
  rep(i,K) {
    int r, c, d;
    cin >> r >> c >> d;
    r--; c--;
    v[r][c] = d;
  }


  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 4; k++) {
        if (i > 0) dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
      }

      for (int k = 0; k < 4; k++) {
        if (j > 0) dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
      }

      for (int k = 3; k >= 0; k--) {
        dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + v[i][j]);
      }
    }
  }

  ll res = 0;
  for (int i = 0; i < 4; i++) res = max(res, dp[n - 1][m - 1][i]);
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 393580
def main():
    A, V = map( int, input().split())
    B, W = map( int, input().split())
    T = int( input())
    if A == B:
        print("YES")
        return
    if V <= W:
        print("NO")
        return
    d = V-W
    need = (abs(A-B)+d-1)//d
    if need <= T:
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
ll a[100001];
ll pref[100001];
ll prefix[100001];
ll suff[100001];
ll sum(int l, int r)
{
	if(l<0) l=0;
	if(l==0) return prefix[r];
	else return prefix[r]-prefix[l-1];
}

int n,k;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>k;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		prefix[i]=a[i];
		if(i>0) prefix[i]+=prefix[i-1];
		if(a[i]>=0) pref[i]=a[i];
		if(i>0) pref[i]+=pref[i-1];
	}
	for(int i = n - 1; i >= 0; i--)
	{
		if(a[i]>=0) suff[i]=a[i];
		if(i<n-1) suff[i]+=suff[i+1];
	}
	if(n==k)
	{
		cout<<max(0LL,prefix[n-1])<<'\n';
		return 0;
	}
	
	ll ans = 0;
	for(int i = 0; i + k - 1 < n; i++)
	{
		int l = i; int r = i + k - 1;
		ll s = max(0LL, sum(l,r));
		if(l-1>=0) s+=pref[l-1];
		if(r+1<n) s+=suff[r+1];
		ans=max(ans,s);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 3328
N,T=gets.split.map(&:to_i)

#menu=N.times.map{[rand(1..100),rand(1..100)]}
#menu=[[68, 98], [9, 1], [53, 6], [100, 40], [65, 41]]

menu=N.times.map{ gets.split.map(&:to_i)}
maxs=Array.new(T+3001,0)
menu.sort_by!{|x| x}

menu.each do |m|
  a,b=m
  new_maxs=maxs.dup
  T.times do |t|
    temp=maxs[t]+b
    new_maxs[t+a]=temp if temp>new_maxs[t+a]
  end
  maxs=new_maxs
end
max=0
(T+3001).times do |t|
  max=maxs[t] if maxs[t]>max
end
p max

Measured memory_bytes: 58992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  string s;cin>>s;
  
  ans(s.at(2)==s.at(3) && s.at(4)==s.at(5));
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b;
  while(1) {
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    if(a > b) {
      cout << b << " " << a << endl;
    } else {
      cout << a << " " << b << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3060
ar = []
5.times do
  ar.push(gets.to_i)
end

ar_0 = []
count = 0
while count < ar.length do
  if (ar[count] % 10) == 0 then
    ar_0.push(ar[count])
    ar.delete_at(count)
  end
  count += 1
end
ar = ar.sort_by {|num| num % 10}.reverse

sorted_ar = []
sorted_ar.push(ar_0).push(ar).flatten!

ans = 0
time = 0

for i in 0..4 do
  ans = time + sorted_ar[i]
  time += sorted_ar[i]
  if (time % 10) != 0 then
    time = ((time / 10) * 10) + 10
  end
end

puts ans


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

using namespace std;

const int INFTY = (1 << 30);

int main()
{
    int N, M, a, b, c;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> C(M);
    vector<int> dp((1 << N), INFTY);
    for (int i = 0; i < M; ++i)
    {
        cin >> a >> b;
        A.at(i) = a;
        for (int j = 0; j < b; ++j)
        {
            cin >> c;
            --c;
            C.at(i) |= (1 << c);
        }
    }

    dp[0] = 0;
    for (int n = 0; n < (1 << N); ++n)
    {
        for (int m = 0; m < M; ++m)
        {
            int s = n | C.at(m);
            int cost = A.at(m) + dp[n];
            dp[s] = min(dp[s], cost);
        }
    }
    if(dp[(1 << N)-1] == INFTY) dp[(1 << N)-1] = -1;
    cout << dp[(1 << N)-1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

double B;
ll A,ans;

cin >> A >> B;

B = B*100 + 0.1;

ans = A*ll(B);

ans /= 100;

cout << ans << endl;

//printf("%0.8f\n",A);
//printf("%0.8f\n",B);
//printf("%0.8f\n",A*B);

//cout << A << endl;
//cout << B << endl;
//cout << A*B << endl;

//ans = 100 * B;

//printf("%0.8f\n",B*100.0);

//printf("%0.8f\n",A*B);

return 0;

}   


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

bool prime[200000];
int s[200000];

int main()
{
	memset(prime, 1, sizeof(prime));
	prime[0] = prime[1] = 0;
	
	for(int i=2; i*i<=150000; ++i)
	{
		if(prime[i])
		{
			for(int j=i*2; j<=150000; j+=i)
			{
				prime[j] = 0;
			}
		}
	}
	
	for(int i=1; i<150000; i+=2)
	{
		if(prime[i])
		{
			if(prime[(i+1)/2])
			{
				s[i] = 1;
			}
			
		}
	}
	for(int i=1; i<150000; ++i)
	{
		s[i] += s[i-1];
	}
	
	
	int q;
	cin >> q;
	int a, b;
	
	while(q--)
	{
		cin >> a >> b;
		cout << s[b] - s[a-1] << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
	int dat[3], tmp;

	scanf("%d %d %d", &dat[0], &dat[1], &dat[2]);

	if (dat[0] > dat[1]){
		tmp = dat[0];
		dat[0] = dat[1];
		dat[1] = tmp;
	}
	if (dat[1] > dat[2]){
		tmp = dat[1];
		dat[1] = dat[2];
		dat[2] = tmp;
	}
	if (dat[0] > dat[1]){
		tmp = dat[0];
		dat[0] = dat[1];
		dat[1] = tmp;
	}
	printf("%d %d %d\n", dat[0], dat[1], dat[2]);

	return 0;
}

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

int main() {
	int n;
  	cin>>n;
  
  	bool kuku=false;
  
  	for(int i=1;i<=9;i++){
    	for(int j=1;j<=9;j++){
        	if(n==i*j){
            	kuku=true;
            }
        }
    }
  
  if(kuku){
  	cout<<"Yes"<<endl;
  }
  
  else{
  	cout<<"No"<<endl;
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,m,tot,c[N],a[N],head[N],nex[N],to[N],id[N];
void add(int u,int v,int i){to[++tot]=v;nex[tot]=head[u];head[u]=tot;id[tot]=i;}
bool vis[N];
int dis[N];
int ans;
struct node
{
    int u,x;
    node(int u=0,int x=0):u(u),x(x){}
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
};
priority_queue<node>q;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    bool flag=false;
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v,i);add(v,u,i);
        if(a[u]==a[v]&&!vis[u]&&!vis[v])
        {
            q.push(node(u,a[u]));
            q.push(node(v,a[v]));
            c[u]=1;c[v]=0;
            vis[u]=vis[v]=true;
            ans+=2;
            dis[i]=a[u];
            flag=true;
        }
    }
    if(!flag){printf("-1\n");return 0;}
    while(!q.empty())
    {
        node now=q.top();q.pop();
        for(int i=head[now.u];i;i=nex[i])
        {
            int v=to[i];if(vis[v]||a[v]<now.x) continue;
            vis[v]=true;ans++;
            dis[id[i]]=a[v];
            c[v]=c[now.u]^1;
            q.push(node(v,a[v]));
        }
    }
    if(ans!=n){printf("-1\n");return 0;}
    for(int i=1;i<=n;i++)
        putchar(c[i]?'B':'W');
    putchar('\n');
    for(int i=1;i<=m;i++)
        printf("%d\n",!dis[i]?1000000000:dis[i]);
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

using P = pair<ll, int>;
struct Edge{
    ll to,cost;
};

template<class T> void dijkstra(vector<vector<Edge>>& G, int s, vector<T>& dis){
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> q;
    dis[s] = 0;
    q.push({dis[s],s});

    while(!q.empty()){
        auto pos = q.top(); q.pop();

        int v = pos.second;
        if(dis[v] < pos.first) continue;

        for(auto next: G[v]){
            if(next.to == v)continue; //無限ループの回避
            if(dis[next.to] > dis[v]+next.cost){
                dis[next.to] = dis[v]+next.cost;
                q.push({dis[next.to], next.to});
            }
        }
    }
}

int main() {
    int K; cin >> K;
    vector<vector<Edge>> G(K);

    REP(i,K){
        G[i].push_back({(i+1)%K,1});
        G[i].push_back({(i*10)%K,0});
    }
    vector<ll> dis;
    dijkstra(G,1,dis);

    cout << dis[0]+1 << endl;
    return 0;
}

Measured memory_bytes: 12076
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  vector<int>c(b);
  rep(i,b)cin>>c[i];
  string s;
  rep(i,2*a)s+=i;
  rep(i,b){
	if(!c[i]){
	  string tmp;
	  rep(j,a){tmp+=s[j];tmp+=s[j+a];}
	  s=tmp;
	}else
	  s=s.substr(c[i])+s.substr(0,c[i]);
	//rep(i,2*a)cout<<1+s[i];
	//cout<<endl;
  }
  rep(i,2*a){if(s[i]+1>0)cout<<1+s[i]<<endl;else cout<<257+s[i]<<endl;}
}

Measured memory_bytes: 1216
n=int(input())
s=input()
t=input()

fin=1
for i in range(n):
    flag=1
    j=0
    while i+j<n:
        if t[j]!=s[i+j]:
            flag=0
        j=j+1
    if flag and fin:
        print(n-i+i*2)
        fin=0
if fin:
    print(2*n)

Measured memory_bytes: 3060
#!/usr/bin/env pypy3
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    N=I()
    a=[[0]*N for _ in range(N)]
    for i in range(N):
        a[i]=LI()
    MS=pow(2,N)
    
    dp=[0]*MS
    #状態Sの時の最大値
    #各Sから見て，全てのSの補集合Tを考える（bit1つだけ落とすのではなく，全部みる．例えば，1111から1100と0011とかもみる．）
    #Sの補集合Tで回して，dp[S]=max(dp[T]+dp[S-T])
    #Sに出てくるものが全て同じグループに入るパターンだけ別に計算する必要あり．
    
    #初期化，全部同じグループの場合を先に入れておく
    for S in range(1,MS):
        for j in range(N):
            if S>>j&1:#j番目のbitがあるなら，
                dp[S]=dp[S-(1<<j)]#j番目を加えた時の繊維を見てみる
                for k in range(N):
                    if S>>k&1:#k番目があれば
                        dp[S]+=a[j][k]
                break
            
    #メイン
    for S in range(1,MS):
        #Sの補集合，Tを列挙する
        T=S
        while T:
            T=(T-1)&S#bit演算を上手く使った補集合の列挙
            dp[S]=max(dp[S],dp[T]+dp[S-T])
            
    print(dp[MS-1])
                        
    
main()


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

int k[2020],a[200001],b[200001],f[200001];

int main()
{
	string s;
	cin>>s;
	int n=s.size();
	
	for(int i=1;i<=n;i++)
		a[i]=s[i-1]-48;
	
	int x=1;
	for(int i=n;i>=1;i--)
	{
		b[i]=x;
		x=(x*10)%2019;
	}
	
	for(int i=n;i>=1;i--)
	{
		f[i]=(f[i+1]+a[i]*b[i])%2019;
		k[f[i]]++;
	}
	
	int sum=k[0];
	for(int i=0;i<2019;i++)
		sum+=k[i]*(k[i]-1)/2;
	cout<<sum<<endl;
	return 0;
}

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

int main (){
  string s;cin>>s;
  reverse(s.begin(),s.end());
  ll n = s.size(),num = 0,a = 1;
  vector<ll> v(n+1,0);
  rep(j,n){
    num += ((s.at(j) - '0')*a);
    v.at(j+1) = num;
    v.at(j+1)%=2019;
    a = (a*10)%2019;
  }
  map<ll,ll> m;  
  for (auto i : v) {
    m[i]++;
  }
 
  ll ans = 0;
  for (auto i : m) {
    ans += (i.second*(i.second-1))/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int sq = sqrt(300000);
	int n, m; cin >> n >> m;
	vi s(m + 2);
	REP(lp, n)
	{
		int l, r; cin >> l >> r;
		int pre = INF;
		FOR(i, 1, INF)
		{
			int a = l / i + (l % i == 0 ? 0 : 1);
			int b = r / i;
			if (b >= pre) b = pre - 1;
			if (a <= sq)
			{
				a = sq;
				if (a > b) break;
				s[a]++;
				s[b + 1]--;
				break;
			}
			s[a]++;
			s[b + 1]--;
			pre = a;
		}
		FOR(i, 1, sq)
		{
			int t = l / i * i;
			if ((l <= t && t <= r) || (l <= (t + i) && (t + i) <= r))
			{
				s[i]++;
				s[i + 1]--;
			}
		}
	}
	vi ans(m + 1);
	REP(i, m) ans[i + 1] = ans[i] + s[i + 1];
	REP(i, m) cout << ans[i + 1] << endl;
	return 0;
}

Measured memory_bytes: 1664
#include<string.h>
#include<stdio.h>
int main()
{
	char s[10010];
	int joi=0,ioi=0;
	while(scanf("%s",s)!=EOF){
		for(int i=0;i<strlen(s)-2;i++){
			if(s[i+1]=='O'&&s[i+2]=='I'){
				if(s[i]=='J'){
					joi++;
				}else if(s[i]=='I'){
					ioi++;
				}
			}
		}
		printf("%d\n%d\n",joi,ioi);
		joi=0;
		ioi=0;
	}
	return 0;
}

Measured memory_bytes: 2684
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    //ll a[n];
    vector <ll> a(n);
    int count = 0;
    ll sum=0;
    REP(i,n){
        cin >> a[i];
        if(a[i]<0){
            count++;
            a[i]*=-1;
        }
        sum+=a[i];
    }
   
   if(count%2){
        cout << sum-2*(*min_element(a.begin(),a.end())) << endl;
   }
   else{
       cout << sum << endl;
   }
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();

			if (b <= c || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void dfs(int i,vector<int>* v,int* vis){
    vis[i]=1;
    for(int j=0;j<v[i].size();j++){
        if(vis[v[i][j]]==0)
        dfs(v[i][j],v,vis);
    }
}
int main() {
	int n;
	cin>>n;
	int m;
	cin>>m;
	int vis[n+1];
	for(int i=0;i<=n;i++)
	vis[i]=0;
	vector<int> v[n+1];
	for(int i=0;i<m;i++){
	    int s,f;
	    cin>>s>>f;
	    v[s].push_back(f);
	    v[f].push_back(s);
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
	    if(vis[i]==0){
	        dfs(i,v,vis);
	        cnt++;
	    }
	    
	}
	cout<<cnt-1;
	return 0;
}


Measured memory_bytes: 10344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(var,start,stop,step) for(long long var=start;var<stop;var+=step)
#define vi vector<int>
#define vl vector<long long>
#define fio  cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr);
 
int main()
{
    fio;
    ll n;cin>>n;
    unsigned long ans=0;
    vi f(n);
    loop(i,1,n+1,1) 
    {
        
        loop(j,i,n+1,i) f[j]++;
        ans+=i*f[i];
    }  
    cout<<ans<<endl;
    return 0;

}  

Measured memory_bytes: 42280
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    K, N = input_nums()
    A = input_nums()
    dist = []
    for i in range(len(A)-1):
        dist.append(A[i+1]-A[i])
    dist.append(K+A[0]-A[-1])
    maxv = max(dist)
    print(sum(dist) - maxv)
    

if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n - 1; i++)
    {
        int k;
        cin >> k;
        a[k-1]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 4316