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

bool greaterfirst(std::pair<int, int> i, std::pair<int, int> j) { return (i.second > j.second); }

int main() {
	while (1) {
		// 入力
		int N, M;
		std::cin >> N >> M;
		if (N == 0 && M == 0) return 0;
		int D, P;
		std::pair<int, int> DP[10000];
		for (int i = 0; i < N; i++) {
			std::cin >> D >> P;
			DP[i] = std::make_pair(D, P);
		}
		// 演算
		std::sort(DP, DP + N, greaterfirst);
		int answer = 0;
		for (int i = 0; i < N; i++) {
			answer += DP[i].second * DP[i].first;
		}
		int remains = M;
		for (int i = 0; remains > 0 && i < N; i++) {
			if (remains >= DP[i].first	) {
				answer -= DP[i].second * DP[i].first;
			}
			else {
				answer -= DP[i].second * remains;
			}
			remains -= DP[i].first;
		}
		// 出力
		std::cout << answer << std::endl;
	}
	return 0;
}

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

int scan(char *a,char *b,int len){
	int i = 0;
	while(1){
		if(a[i] > b[i])
			return 1;
		else if(b[i] > a[i])
			return 0;

		if(i == len)
			return 114514;
		++i;
		
	}
}

int main(){
	char a[1000],b[1900];
	cin >> a;
	cin >> b;
	int f;

	if(strlen(a) == strlen(b))
		f = scan(a,b,strlen(a));


	if(f == 114514){
		cout << "EQUAL" <<endl;
		return 0;
	}

	if(strlen(a) > strlen(b) || (strlen(a) == strlen(b) && f == 1 ))
		cout << "GREATER" <<endl;
	else if(strlen(a) < strlen(b) || (strlen(a) == strlen(b) && f == 0))
		cout << "LESS" <<endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

int f(int a, int b, int c) {
    if (a != b) {
        if (a != c) {
            return a;
        } else {
            return b;
        }
    }
    return c;
}

int main() {

    int a, b, c;
    std::cin >> a >> b >> c;

    int res = f(a, b, c);
    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct edge {
    ll to, cap, rev;
};

vector<vector<edge>> G;
vector<bool> used;

void add_edge(ll from, ll to, ll cap) {
    G[from].emplace_back((edge){to, cap, ll(G[to].size())});
    G[to].emplace_back((edge){from, 0, ll(G[from].size()) - 1});
}

ll dfs(ll v, ll t, ll f) {
    if(v == t)
        return f;
    used[v] = true;
    for(auto &e : G[v]) {
        if(!used[e.to] && e.cap > 0) {
            ll 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;
}

ll max_flow(ll s, ll t) {
    ll flow = 0;
    while(1) {
        fill(used.begin(), used.end(), false);
        ll f = dfs(s, t, INF);
        if(f == 0)
            break;
        flow += f;
    }
    return flow;
}
int main() {
    cin>>n>>m;
    G.resize(n);
    used.resize(n);
    rep(i,m){
        cin>>x>>y>>z;
        add_edge(x,y,z);
    }

    cout<<max_flow(0,n-1)<<endl;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;
const int MAX = 12;

int main(){

  int n, m, x;
  int price[12];
  int value[12][12];
  int sum_value[12];
  int min_price = INFI;
  int min_value;

  cin >> n >> m >> x;
  rep(i,n){
    cin >> price[i];
    rep(j,m) cin >> value[i][j];
  }
  int bit_max = 1<<n;
  for (int i = 1; i <= bit_max; i++){
    int sum_price = 0;
    for (int j = 0; j < m; j++) sum_value[j] = 0;
    for (int j = 0; j < n; j++){
      if(1<<j & i){
        sum_price += price[j];
        for(int k = 0; k < m; k++) sum_value[k] += value[j][k];
      }
    }
    min_value = INFI;
    for (int j = 0; j < m; j++){
      min_value = min(min_value, sum_value[j]);
    }
    if (min_value >= x) min_price = min(min_price, sum_price);
  }

  if (min_price != INFI) cout << min_price << endl;
  else cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair



int main(){
	int n,i;
	scanf("%d",&n);
	string s;
	cin>>s;
	int p = s.size();
	for(i=0;i<p;i++){
		int q = s[i]-'A' + n;
		q=q%26;
		s[i]='A'+q;

	}
	cout<<s<<endl;
	return 0;
}


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

const double BTC = 380000.0;

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

    double OTSD = 0;
    
    for(int i = 0; i < N; i++)
    {
        double num;
        char C[3 + 1];
        cin >> num >> C;
        if (!strcmp(C,"JPY"))
        {
            OTSD += num;
        }
        else
        {
            OTSD += num * BTC;
        }
    }
    cout << fixed << setprecision(8) << OTSD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


struct edge{
    ll to,cost;
    constexpr bool operator<(const edge &a)const noexcept{
        if((*this).cost<a.cost)return true;
        else return false;
    }
    constexpr bool operator>(const edge &a)const noexcept{
        if((*this).cost>a.cost)return true;
        else return false;
    }
};

struct graph{
    ll v;
    vec<vec<edge>> g;
    vec<ll> d;

    graph(ll n) : v(n),g(n),d(n,INF){}

    void addedge(const ll s,const ll t,const ll cost){
        edge e;
        e.to=t;
        e.cost=cost;
        g[s].emplace_back(e);
    }
    //E+VlogV
    void dijkstra(ll s){//sからstartのdijkstra
        /*一度dijkstraをした時同じグラフでdijkstraしたいならこれも入れる
        rep(i,v)d[i]=INF;
        */
        d[s]=0;
        priority_queue<P,vec<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P pa=que.top();que.pop();
            ll k=pa.second;
            if(d[k]<pa.first)continue;
            for(auto e:g[k]){
                if(d[e.to]>d[k]+e.cost){
                    d[e.to]=d[k]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int h,w,sx,sy,gx,gy;cin >> h >> w >> sx >> sy >> gx >> gy;
    vec<vec<char>> s(h,vec<char>(w));
    rep(i,h)rep(j,w)cin >> s[i][j] ;
    sx--;sy--;gx--;gy--;
    graph g(h*w);

    //点(i,j)は点(w*i+j)に
    //点(i,j)から右下に引けるところへ辺を張る
    rep(i,h)rep(j,w){
        if(s[i][j]=='#')continue;
        rep(k,4){
            int nx=i+dx[k],ny=j+dy[k];
            if(nx<0||ny<0||nx>=h||ny>=w)continue;
            if(s[nx][ny]=='#')continue;
            g.addedge(w*i+j,w*nx+ny,0);
        }
        rep2(k,-2,3)rep2(l,-2,3){
            if(k*k+l*l==1)continue;
            if(i+k>=h||j+l>=w||i+k<0||j+l<0)continue;
            if(s[i+k][j+l]=='#')continue;
            g.addedge(w*i+j,w*(i+k)+j+l,1);
        }
    }
    g.dijkstra(w*sx+sy);
    //rep(i,h)rep(j,w)cout << g.d[w*i+j] << endl;
    if(g.d[w*gx+gy]==INF){cout << -1 << endl;return 0;}
    cout << g.d[w*gx+gy] << endl;
}

Measured memory_bytes: 175664
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n,k;
int ans;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
	}
	n-=k,ans++;
	if(n%(k-1)) ans+=n/(k-1)+1;
	else ans+=n/(k-1);
	cout<<ans; 
	re 0;
}

Measured memory_bytes: 3620
N, M = map(int, input().split(" "))

min = 1
max = N
for i in range(M):
	l, r = map(int, input().split(" "))
	if l > min:
		min = l
	if r < max:
		max = r

if max >= min:
	print(max - min + 1)
else:
	print(0)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
int n,r,i,j,a[100];
main(){
scanf("%d",&n);
for(;i<n;i++)scanf("%d",a+i);
for(i=0;i<n;i++){
for(j=0;j<i;j++){
if(a[i]<a[j])r++;
}
}
std::sort(a,a+n);
for(i=0;i<n;i++){if(i)printf(" ");printf("%d",a[i]);}
printf("\n%d\n",r);
}

Measured memory_bytes: 3256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[][] abs = new int[n - 1][];
		for (int i = 0; i < abs.length; i++)
			abs[i] = new int[] { cin.nextInt(), cin.nextInt() };

		long start = now();

		boolean ans = solve(n, abs);
		if (ans)
			cout.println("Fennec");
		else
			cout.println("Snuke");

		trace("elapsed", now() - start);
	}

	private static boolean solve(int n, int[][] abs) {
		// BFS
		int[] vis = new int[n + 1];
		Arrays.fill(vis, -1);
		int FEN = 1;
		int SNU = 2;
		int[][] adj = adjacentList(abs);
		ArrayDeque<Integer> q = new ArrayDeque<>();
		// Fennec先攻
		q.add(1);
		vis[1] = FEN;
		// Snuke後攻
		q.add(n);
		vis[n] = SNU;
		while (!q.isEmpty()) {
			int v = q.poll();
			for (int u : adj[v]) {
				if (vis[u] != -1)
					continue;
				vis[u] = vis[v];
				q.add(u);
			}
		}
		long fen = Arrays.stream(vis).filter(x -> x == FEN).count();
		long snu = Arrays.stream(vis).filter(x -> x == SNU).count();
		return fen > snu;
	}

	private static int[][] adjacentList(int[][] fromTo) {
		int mx = -1;
		for (int[] ft : fromTo)
			mx = Math.max(mx, Math.max(ft[0], ft[1]));
		int[] sz = new int[mx + 1];
		for (int[] ft : fromTo) {
			sz[ft[0]] += 1;
			sz[ft[1]] += 1;
		}
		int[][] ans = new int[mx + 1][];
		for (int i = 0; i < ans.length; i++)
			ans[i] = new int[sz[i]];
		for (int[] ft : fromTo) {
			sz[ft[0]] -= 1;
			sz[ft[1]] -= 1;
			ans[ft[0]][sz[ft[0]]] = ft[1];
			ans[ft[1]][sz[ft[1]]] = ft[0];
		}
		return ans;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

using namespace std;
typedef long long LL;

int main()
{

	LL a, b, c;
	cin >> a >> b >> c;  // nasty antidote, tasty antidote, tasty poison

	LL r = 0;

	LL x = min(a, c);
	c -= x;
	r += x;
	if (c == 0) {
		r += b;
	}
	else {
		x = min(b, c);
		r += 2*x;
		c -= x;
		b -= x;
		if (b == 0 && c > 0) {
			r++;
		}
		else if (c == 0 && b > 0) {
			r += b;
		}
	}

	cout << r << endl;
	exit(0);
}



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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    cout << (n - 1)/ k + 1 << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer sum = 0 ;
		for (int i=0 ; i<3 ; i++) sum += sc.nextInt();
		if (sum >= 22) System.out.println("bust");
		else System.out.println("win");
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(3*N);
  for(int i=0; i<a.size(); i++) cin >> a[i];

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

  long long sum=0;
  for(int i=N; i<3*N; i+=2) sum+=a[i];

  cout << sum << endl;
}


Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Triangles solver = new Triangles();
        solver.solve(1, in, out);
        out.close();
    }

    static class Triangles {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            List<Integer> list = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                list.add(in.nextInt());
            }
            Collections.sort(list);

            long result = 0;
            for (int i = 0; i < n; i++) {
                int a = list.get(i);
                for (int j = i + 1; j < n; j++) {
                    int b = list.get(j);
                    int k = Collections.binarySearch(list, a + b, new LowerBoundComparator<>());
                    if (k < 0) {
                        k = -k - 1;
                    }
                    result += Math.max((k - j - 1), 0);
                }
            }
            out.println(result);
        }

        class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T> {
            public int compare(T x, T y) {
                return (x.compareTo(y) >= 0) ? 1 : -1;
            }

        }

    }
}



Measured memory_bytes: 55116
import sys


def main():
    S = sys.stdin.readline().strip()
    # S = 'RRLLLLRLRRLL'

    def print_ans_part(start, end):
        wall_left = -1
        result = ['0'] * (end - start)
        for i in range(start, end-1):
            if S[i] == 'R' and S[i+1] == 'L':
                wall_left = i
                break

        d_start_wl = (wall_left - start) % 2
        d_wl_end = (end - wall_left) % 2
        wall_left_from_start = wall_left - start

        if (d_start_wl and d_wl_end) or (d_start_wl == 0 and d_wl_end == 0):
            assert (end - start) % 2 == 0
            wl = (end - start) // 2
            wl1 = (end - start) // 2
        else:
            if d_start_wl:
                wl = (end - start) // 2
                wl1 = (end - start) // 2 + 1
            else:
                wl = (end - start) // 2 + 1
                wl1 = (end - start) // 2
        result[wall_left_from_start] = str(wl)
        result[wall_left_from_start+1] = str(wl1)

        print(' '.join(result), end=' ')

    array = []
    cur_is_l = False
    start = 0
    for i in range(len(S)):
        cur = S[i]
        if cur_is_l and cur == 'R':
            print_ans_part(start, i)
            start = i
            array = []
            cur_is_l = False
        else:
            array.append(cur)
            if cur == 'L':
                cur_is_l = True
            else:
                cur_is_l = False
    print_ans_part(start, len(S))
    print('')


main()


Measured memory_bytes: 61144
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	int n = A * B;

	if (n % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  long a,b,n;
  cin>>a>>b>>n;
  if(b-1<=n){
    cout<<a*(b-1)/b<<endl;
  }
  else{
    cout<<a*n/b<<endl;
  }
  
}

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

using namespace std;

int main(){
    int N;
    int a[200001];
    
    // input
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    
    int x = 1;
    int count = 0;
    
    for (int i = 0; i < N; i++){
        if (a[i] == x){
            x++;
        }
        else{
            count++;
        }
    }
    
    if (count == N){
        cout << - 1;
        return 0;
    }
    
    cout << count;
    
    return 0;
}

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

int main(){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(ch == '\n') break;
        if('a'<=ch && ch<='z') printf("%c",ch-32);
        else if('A'<=ch && ch<='Z') printf("%c",ch+32);
        else printf("%c",ch);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3128
k,n = map(int,input().split())
a = list(map(int,input().split()))

max1 = 0

for i in range(n-1):
    max1 = max(max1, a[i+1] - a[i])

max1 = max(max1, k - (a[-1] - a[0]))

print(k - max1)


Measured memory_bytes: 77592
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000


int nC2(int n);

int main()
{
    int N;
    cin >> N;
    
    cout << (N+1)/2 << endl;
    
    
    
    return 0;
}

int nC2(int n)
{
    if(n <= 1) return 0;
    else return n*(n-1)/2;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long x, long long y) {
  return y ? gcd(y, x % y) : x;
}

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

int main() {
  long long a, b; cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int i,j,s,n,m;
  static int a[100][100],b[100],c[100];
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);
  for(i=0;i<m;i++)
    scanf("%d",&c[i]);
  for(i=0;i<n;i++){
    s = 0;
    for(j=0;j<m;j++)
      s += a[i][j] * c[j];
    printf("%d\n",s);
  }
  return 0;
}


Measured memory_bytes: 2056
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = sc.nextInt
    }

    // hiまでにかかるコスト
    val dp = Array.fill[Int](n)(Int.MaxValue)
    dp(0) = 0
    dp(1) = math.abs(h(1) - h(0))
    for (i <- 2 until n) {
      dp(i) = math.min(math.abs(h(i - 2) - h(i)) + dp(i - 2), math.abs(h(i - 1) - h(i)) + dp(i - 1))
    }
    println(dp(n - 1))
  }
}


Measured memory_bytes: 51820
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 998244353;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

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

	cin >> N >> M >> K >> L;
	vector<long long int>ncr(N + 1);
	ncr[0] = 1;
	for (int i = 1; i <= N; i++) {
		ncr[i] = ncr[i - 1] * (N + 1 - i);
		ncr[i] %= MOD;
		ncr[i] *= power(i, MOD - 2, MOD);
		ncr[i] %= MOD;
	}
	long long int ans = 0;
	for (int i = 0; i <= N; i++) {
		if (L - M * i < 0)continue;
		if ((L - M * i) % K)continue;
		if ((L - M * i) / K > N)continue;
		long long int add = ncr[i] * ncr[(L - M * i) / K];
		ans += add;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
    std::fill((T *)array, (T *)(array + N), val);
}

ll power(ll n, ll a)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)//2進数を利用してn & 1と論理和をとってもいい。
        {
            res = res * a;
        }
        a = a * a;
        n >>= 1;//nを右に1シフト、つまり、÷2(切り捨て)
    }
    return res;
}
int main()
{
    ll x;
    cin >> x;
    repi(a,1001,-1000){
        repi(b,10001,-10001){
            if(power(5,a) - power(5,b) == x){
                cout << a <<" " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3596
using System;
using System.Linq;
class P
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] array = new int[N];
    for (int i = 0; i < N; i++) {
      array[i] = int.Parse(input[i]);
    }
    int max = array.Max();
    int sum = array.Sum() - max;
    Console.WriteLine((max < sum) ? "Yes" : "No");
  }
}

Measured memory_bytes: 13268
#include <iostream>
#define DIVISOR 1000000007
#define ULLI unsigned long long int
using namespace std;
ULLI sq(ULLI n){
	return n*n;
}

ULLI binarypower(ULLI m, ULLI b){
	if(b==1)return m;
	return sq(binarypower(m, b-1)) % DIVISOR;
}

ULLI power(ULLI m, ULLI n){
	ULLI prod=1;
	for(int i=0;i<32;++i){
		if(n & (1<<i)){
			prod = (prod * binarypower(m,i+1)) % DIVISOR;
		}
	}
	return prod;
}

int main() {
	ULLI m,n;
	cin>>m>>n;
	cout<<power(m,n)<<endl;
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 1005
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

ll dp[N][N];
ll fac[N][N];
ll invf[N][N];

ll rev(ll n) {
	ll ret = 1;
	ll exponent = MOD - 2;
	for (ll i = exponent; i; i >>= 1, n = n * n % MOD) {
		if (i & 1) {
			ret = ret * n % MOD;
		}
	}
	return ret;
}

void get_factorial_inverse(int n, int p) {
	fac[0][1] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i][1] = i * fac[i - 1][1] % p;
		for(int j = 2;j<=n;j++){
            fac[i][j] = fac[i][j-1]*fac[i][1]%p;
		}
	}
	invf[n][1] = rev(fac[n][1]);
	for (int i = n-1; i >= 0; --i) {
		invf[i][1] = invf[i + 1][1] * (i + 1) % p;
		for(int j = 2;j<=n;j++){
            invf[i][j] = invf[i][j-1]*invf[i][1]%p;
		}
	}
}

ll C(ll a,ll b)
{
    return fac[a][1]*invf[b][1]%MOD*invf[a-b][1]%MOD;
}
int main()
{
    int n,a,b,c,d;

    while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)!=EOF)
    {
        get_factorial_inverse(n,MOD);

        dp[a-1][0] = 1;
        FOR(i,1,n)dp[a-1][i] = 0;
        FOR(i,a,b)
        {
            FOR(j,0,n)
            {
                dp[i][j] = dp[i-1][j];
                int num = c;
                while(j-num*i>=0&&num<=d)
                {
                    int pre = j-num*i;
                    dp[i][j] = (dp[i][j]+dp[i-1][j-num*i]*C(n-j+num*i,num*i)%MOD*fac[num*i][1]%MOD*invf[i][num]%MOD*invf[num][1]%MOD)%MOD;
                    num++;
                }
            }
        }
        printf("%I64d\n",dp[b][n]);
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)

ll H,W;
char field[50][50];
ll dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};

//a,b x
int main(){
	cin>>H>>W;
	rep(i,H){
		string tmp; cin>>tmp;
		rep(j,W){
			field[i][j]=tmp[j];
		}
	}
	rep(i,H)rep(j,W){
		if(field[i][j]=='#'){
			bool ans=false;
			rep(k,4){
				ll nx=i+dx[k],ny=j+dy[k];
				if(0<=nx && nx<H && 0<=ny && ny<W && field[nx][ny]=='#') ans=true;
			}
			if(!ans){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";	
	
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    int n,m;
    cin >> n >> m;
    pair<int,int> ab[m];
    int s = -1;
    int ans = 0;
    
    rep(i,0,m)cin >> ab[i].sd >> ab[i].ft;
    sort(ab,ab+m);
    
    rep(i,0,m){
	if(s <= ab[i].sd){
	    ans++;
	    s = ab[i].ft;
	}
    }
    P(ans);
	    
    return  0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I m,d;
  cin >> m >> d;
  I t=0;
  REP(i,m+1){
    REP(j,d+1){
      I d1,d10;
      if (j < 20) continue;
      if (j % 10 < 2) continue;
      d1 = j % 10;
      d10 = j / 10;
      if (d1 * d10 == i) t++;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int A[100],i,j,v,a,b;
   
  scanf("%d",&a);
 
 for(i=0;i<=a-1;i++){
	scanf("%d",&A[i]);
	}

 for(b=0;b<=a-1;b++){
    printf("%d",A[b]);
    if(b<=a-2)printf(" ");
	}
      printf("\n");
   
  for(i=1;i<=a-1;i++){
	v=A[i];
	j=i-1;
		while(j >= 0 && A[j] > v){
			A[j+1]=A[j];
			j--;
			A[j+1]=v;
	}
  for(b=0;b<=a-1;b++){
	printf("%d",A[b]);
	if(b<=a-2) printf(" ");
	}
  printf("\n");
 }
return 0;
}

Measured memory_bytes: 1852
program main
    implicit none
    integer(8), allocatable:: h(:)
    integer(8):: n, k, one
    one =1
    read*, n, k
    
    if (k >= n)then
        print*, 0
        stop
    end if
    
    allocate(h(n))
    read*, h(:)
    call marge_sort(h(:), one, n)
    h(1:k) = 0
    print*, sum(h(:))
contains

recursive subroutine marge_sort(arr,first,last)
    integer(8):: arr(:), tmp
    integer(8):: first, last, mean, diff
    diff = last - first + 1
    if (diff <= 2) then
        if (arr(first) <= arr(last))then
            tmp = arr(first)
            arr(first) = arr(last)
            arr(last) = tmp
        end if
        return
    end if
    
    mean = (first + last) / 2
    call marge_sort(arr, first, mean)
    call marge_sort(arr, mean+1, last)
    call marge(arr, first, mean, last)

end subroutine


subroutine marge(arr, first, mean, last)
    integer(8):: arr(:)
    integer(8), allocatable:: tmp(:)
    integer(8):: first, mean, last
    integer(8):: i, i_left, i_right
    
    allocate(tmp(last-first+1))
    i_left = first
    i_right = mean + 1
    i = 1
    do while((i_left <= mean) .and. (i_right <= last))
        if (arr(i_left) >= arr(i_right))then
            tmp(i) = arr(i_left)
            i_left = i_left + 1
        else
            tmp(i) = arr(i_right)
            i_right = i_right + 1
        end if
        i = i + 1
    end do

    if (i_left > mean)then
        tmp(i:) = arr(i_right:last)
    else
        tmp(i:) = arr(i_left:mean)
    end if
    arr(first:last) = tmp(:)

end subroutine
end program main

Measured memory_bytes: 4644
h,w,D = map(int,input().split())
a = [[int(i) for i in input().split()] for _ in range(h)]
px = [0]*(h*w+1)
py = [0]*(h*w+1)
d = [0]*(h*w+1)

for i in range(h):
    for j in range(w):
        px[a[i][j]] = i
        py[a[i][j]] = j

for i in range(D+1,h*w+1):
    d[i] = d[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D])

q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(d[r]-d[l])

Measured memory_bytes: 12856
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	
	string s;
	
	while( getline( cin, s ) ){
		
		if( s == "END OF INPUT" ){ return 0;}
		
		s += ' '; //SP??????
		int count {0};
		vector<int> vc;
		
		for( int i = 0; i < (int)s.size(); i++ ){
			
			if( s[i] != ' ' ){
				count++;
				continue;
			}
			
			vc.push_back( count );
			count = 0;
		
		}
		
		for( auto x : vc ){
			cout << x;
		}
		
		cout << endl;
		
	}
	
	return 0;

}

Measured memory_bytes: 3036
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    K, T = MI()
    A = LI()

    if T == 1:
        print(A[0] - 1)
        return

    A = sorted(A, reverse=True)
    mx1, mx2 = A[0], A[1]
    if mx1 == mx2:
        print(0)
        return
    else:
        ans = max(0, mx1 - 1 - sum(A[1:]))
        print(ans)
        return

if __name__ == '__main__':
    solve()


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

using namespace std;

int main(void)
{
	int n,m,c;
	int cnt=0;

	cin>>n>>m>>c;

	int b[m],a[n][m],p[n]={0};

	for(int i=0;i<m;i++){
		cin>>b[i];
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			p[i]+=(a[i][j]*b[j]);
		}
	}

	for(int i=0;i<n;i++){
		if((p[i]+c)>0) cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    string s; cin >> s;

    rep(i,s.length()){

        if((i+1)%2==1 && (s[i]=='R' || s[i]=='U' ||s[i]=='D')){
            continue;
        } else if ((i+1)%2==0 && (s[i]=='L' || s[i]=='U' || s[i]=='D')){
            continue;
        } else{
            cout << "No" << endl;
            return 0;
        }

    }

    cout << "Yes" << endl;



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n, sum;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 1; i <= n; i++)if(i % 3 && i % 5)sum += i;
	cout<<sum;
}

Measured memory_bytes: 3648
def sub():
    N = int(input())
    As = [int(e) for e in input().split()]
    ans = None
    while True:
        # print(As)
        a_min = min(As)
        As = [a % a_min for a in As]
        As = [a for a in As if a != 0]
        if len(As) == 0:
            ans = a_min
            break
        else:
            As.append(a_min)
    print(ans)

sub()


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

using namespace std;
typedef long long LL;

#define MAXN 100001
#define MOD 1000000007

int main(int argc, char** argv) {
#ifdef OJ
    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    if (max(a, b) <= 8)
        cout << "Yay!\n";
    else
        cout << ":(\n";

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = (listOf(0) + nextIntList()).toTypedArray()
    for (n in N downTo 1) {
        var num = 0
        for (m in n..N step n) num += A[m]
        val d = num % 2
        A[n] = if (A[n] == d) A[n] else if (A[n] == 0) 1 else 0
    }
    println(A.sum())
    A.forEachIndexed { i, a -> if (a == 1) println("$i ") }
    println()
}

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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++)
    cin>>vec.at(i);
  int count1=1;
  int count2=0;
  for(int i=0;i<N;i++){
  	if(count1==vec.at(i))
      count1++;
  	else
      count2++;
  }
  if(count2==N)
    cout<<-1<<endl;
  else
  	cout<<count2<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<string>
#include<algorithm>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::math;
using LL=long long;
LL N, M;
char S[100002], T[100002];
int main() {
	cin >> N >> M >> S >> T;
	LL G = gcd(N, M),L=lcm(N,M);
	for(LL i=0;i<G;i++){
      if(S[i*(N/G)]!=T[i*(M/G)]){
        printf("-1\n");
        return 0;
      }
    }
  printf("%lld\n",L);
  return 0;
}

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

public class Main {

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();

        int r = fs.nextInt();
        System.out.println( r * 2 * 3.141592 );

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int bufferLength = 0;

        private boolean hasNextByte() {
            if (ptr < bufferLength) {
                return true;
            } else {
                ptr = 0;
                try {
                    bufferLength = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return bufferLength > 0;
            }
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    private static int gcd( int a , int b ){
        int x;
        int y;
        if (a > b) {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return y;
    }

}


Measured memory_bytes: 32964
import copy
def fa():  # final answer
    global ans
    print(ans)


def getN():
    return int(input())


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


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

def check_bridge(n, a, b, edge):
    edge[a-1][b-1] = 0
    edge[b-1][a-1] = 0
    link = [1]
    stack = []
    for i in range(n):
        if edge[0][i] == 1:
            link.append(i+1)
            stack.append(i+1)

    while(stack != []):
        dep = stack[0]
        for i in range(n):
            if edge[dep-1][i] == 1:
                if i+1 not in link:
                    link.append(i+1)
                    stack.append(i+1)
        stack = stack[1:]

    if len(link) == n:
        return True
    else:
        return False

n,m = getNM()
edge = [[0 for i in range(n)] for j in range(n)]
pile = []
for i in range(m):
    a,b = getNM()
    edge[a-1][b-1] = 1
    edge[b-1][a-1] = 1
    pile.append((a,b))

ans = 0
for pair in pile:
    a, b = pair[0], pair[1]
    edge2 = copy.deepcopy(edge)
    if check_bridge(n, a, b, edge2) == False:
        ans += 1

print(ans)




Measured memory_bytes: 3572
#include<cstdio>

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

using namespace std;

const int M=10007;

struct edge{ int v,cost; };

int main(){
	for(int n;scanf("%d",&n),n;){
		static edge G[100000][2];
		rep(u,n) rep(i,2) scanf("%d%d",&G[u][i].v,&G[u][i].cost);

		static bool vis[100000];
		rep(u,n) vis[u]=false;

		int ans=1;
		rep(u,n) if(!vis[u]) {
			int v=u,pre=-1,mx=-1,cnt=0;
			do{
				vis[v]=true;

				edge e;
				rep(i,2) if(G[v][i].v!=pre) e=G[v][i];

				pre=v;
				v=e.v;
				if(mx<e.cost) mx=e.cost, cnt=1;
				else if(mx==e.cost) cnt++;
			}while(v!=u);
			ans=ans*cnt%M;
		}

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

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
#define N 200200
int v[N];
int i, n, k, h;
int main()
{
    cin >> n >> k;
    for (i = 0; i < n; ++i)
        cin >> v[i];
    sort (v, v + n);
    long long ans = 0;
    for (i = 0; i < n - k; ++i)
        ans += v[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	long long x,temp;
	cin >> x;
	int flag = 0;
	for (long long i = -120; i <= 120; i++) {
		if (flag) break;
		for (long long j = -120; j <= 120; j++) {
			temp = j * j * j * j * j - i * i * i * i * i;
			if (temp == x) {
				cout << j << ' ' << i;
				flag = 1;
				break;
			}
			if (temp > x) break;
		}
	}
	return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int A = line[0], B = line[1], X = line[2];
            var ans = false;

            if (X >= A && A + B >= X) ans = true;

            Console.WriteLine(ans ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			String str1 = sc.next();
			String str2 = sc.next();

			boolean flg = false;
			char [] array = new char[str1.length()];
			char tmp;

			for(int i =0;i<str1.length();i++) {
				if(str1.equals(str2)) {
					flg = true;
					break;
				}

				for(int j=0;j<str1.length();j++) {
					array[j]=str1.charAt(j);
				}

				tmp = array[array.length-1];

				for(int j=str1.length()-1; j>0;j--) {
					array[j]=str1.charAt(j-1);
				}

				array[0] = tmp;

				StringBuilder sb = new StringBuilder();
				for(int j=0; j<array.length;j++) {
					sb.append(array[j]);
				}
				str1 = new String(sb);

			}

			if(flg == true) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}

		}

	}




Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string N;
int dp[1010101][2];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	reverse(all(N));

	int n = N.length();
	rep(i, 0, n + 1) rep(d, 0, 2) dp[i][d] = inf;
	dp[0][0] = 0;
	rep(i, 0, n) rep(d, 0, 2) if (dp[i][d] != inf) {
		int c = N[i] - '0';

		if (c == 9 and d == 1) chmin(dp[i + 1][1], dp[i][d]);
		else {
			if (d == 1) c++;
			
			chmin(dp[i + 1][0], dp[i][d] + c);
			chmin(dp[i + 1][1], dp[i][d] + 10 - c);
		}
	}

	int ans = min(dp[n][0], dp[n][1] + 1);
	cout << ans << endl;
}







Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  double n;
  cin >> n;
  vector<double> a(n);
  rep(i,n){
    cin >> a[i];
  }
  double sum = 0;
  rep(i,n){
    sum += (1/a[i]);
  }
  
  sum = 1/sum;
  
  cout << fixed << setprecision(10) << sum;
  
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

int main(){
    int h, w;
    cin >> h >> w;
    char buf[105];
    string s;

    for(int i=0; i<h; i++){
        cin >> s;
        cout << s << endl;
        cout << s << endl;    
    }

    return 0;
}

Measured memory_bytes: 256