akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N, M;
    cin >> N >> M;
    int p1, p2;
    p1 = 1;
    p2 = N;
    bool f[N];
    REP(i, N) f[i] = false;

    REP(i, M) {
        cout << p1 << " " << p2 << endl;
        f[p2 - p1] = true;
        f[p1 + N - p2] = true;
        p1++;
        p2--;
        while (true) {
            if (f[p2 - p1] == true || f[p1 + N - p2] == true || p2 - p1 == p1 + N - p2) {
                p2--;
            }
            else {
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3680
package main

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

func sliceAtoi(sa []string) ([]int, error) {
	si := make([]int, 0, len(sa))
	for _, a := range sa {
		i, err := strconv.Atoi(a)
		if err != nil {
			return si, err
		}
		si = append(si, i)
	}
	return si, nil
}

func main() {
	var N int
	fmt.Scan(&N)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stringInput := scanner.Text()
	A, _ := sliceAtoi(strings.Split(stringInput, " "))
	for i := 1; i <= N-1; i++ {
		str := fmt.Sprintf("%v", A)
		str = strings.Trim(str, "[]")
		fmt.Println(str)
		v := A[i]
		j := i - 1
		for j >= 0 && A[j] > v {
			A[j+1] = A[j]
			j--
		}
		A[j+1] = v
	}
	str := fmt.Sprintf("%v", A)
	str = strings.Trim(str, "[]")
	fmt.Println(str)
}



Measured memory_bytes: 1304
#include <stdio.h>
int main(void){
    // Your code here!
    long long a,b,x,tmpa;
    long long ans = 0;
    
    scanf("%lld%lld%lld",&a,&b,&x);
    
    if(a-1 < 0){
        tmpa = 0;
    }
    else{
        tmpa = ((a-1)/x+1);
    }

    ans = (b/x+1) - tmpa;
    
    printf("%lld\n",ans);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define MAX_N 50
using namespace std;

int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  printf("%d\n", n*a>b?b:n*a);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
   SPEED;
   int n,m,q;
   cin>>n>>m>>q;
   int a[q],b[q],c[q],d[q],ind=n-1;
   for(int i=0;i<q;i++)
   {
       cin>>a[i]>>b[i]>>c[i]>>d[i];
   }
   vector < vector <int> > vec;
   vector <int> ans;
   for(int i=0;i<n;i++)
   {
       ans.push_back(1);
   }
   vec.push_back(ans);
   while(ind>=0)
   {
       ++ans[ind];
       if(ans[ind]>m)
       {
           --ind;
       }
       else if(ind==n-1)
       {
           vec.push_back(ans);
       }
       else
       {
           for(int i=ind;i<n;i++)
           {
               ans[i]=ans[ind];
           }
           vec.push_back(ans);
           ind=n-1;
       }
   }
   int mx=0;
   for(int i=0;i<vec.size();i++)
   {
       int sum=0;
       for(int j=0;j<q;j++)
       {
           if(vec[i][b[j]-1]-vec[i][a[j]-1]==c[j])
           {
               sum+=d[j];
           }
       }
       mx=max(mx,sum);
   }
   cout<<mx;
}

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

#define fastread std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

int main()
{
	fastread;
	
	ll n, k, i, j;

    cin>>n>>k;

    ll ar[n], dp[n];
    fill(dp, dp+n, INT_MAX);

    for(i=0 ; i<n ; ++i)
        cin>>ar[i];
    
    dp[0] = 0;
    dp[1] = abs(ar[0] - ar[1]);
    for(i=2 ; i<n ; ++i)
    {
        for(j=1 ; j<=k && (i-j)>=0 ; ++j)
            dp[i] = min(dp[i], (dp[i-j] + abs(ar[i-j] - ar[i])));
    }
    
    cout<<dp[n-1];
    
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int MAX=1e9;
const int N=2005;
const int MOD=1e9+7;
char ss[N][N];
int L[N][N],R[N][N],U[N][N],D[N][N];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int u=1;u<=n;u++)	scanf("%s",ss[u]+1);
	for (int u=1;u<=n;u++)
	for (int i=1;i<=m;i++) if (ss[u][i]=='.')
	{
		L[u][i]=L[u][i-1]+1;
		U[u][i]=U[u-1][i]+1;
	}
	for (int u=n;u>=1;u--)
	for (int i=m;i>=1;i--) if (ss[u][i]=='.')
	{
		R[u][i]=R[u][i+1]+1;
		D[u][i]=D[u+1][i]+1;
	}
	int ans=0;
	for (int u=1;u<=n;u++)
	for (int i=1;i<=m;i++) if (ss[u][i]=='.')
	{
		//if (L[u][i]+R[u][i]+D[u][i]+U[u][i]-3==10) printf("%d %d %d %d %d %d\n",u,i,L[u][i],R[u][i],U[u][i],D[u][i]);
		ans=max(ans,L[u][i]+R[u][i]+D[u][i]+U[u][i]-3);
	}
	printf("%d\n",ans);
	return 0;
}	

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

#define OUT(x) cout << (x) << endl;
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; ++i)

int main() {
    ll N;
    cin >> N;
    double div = sqrt(N);
    ll ans;
    for(ll i=div; i>0 ; i--){
        if(N % i == 0) {
            ans = N/i;
            break;
        }
    }
    string ansstr = to_string(ans);
    OUT(ansstr.length());
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int> > a;

int val(int i) {
    if (a[i].size() == 0) return 0;
    vector<int> s(a[i].size());
    int j;
    for (j = 0; j < a[i].size(); j++) {
        s[j] = 1+val(a[i][j]);
    }
    sort(s.begin(), s.end(), greater<int>());
    int m = s[0];
    for (j = 1; j < a[i].size(); j++) {
        s[j] += j;
        m = max(m,s[j]);
    }
    return m;
}

int main() {
    int N, i, t;
    cin >> N;
    a.resize(N);
    for (i = 0; i < N-1; i++) {
        cin >> t;
        a[--t].push_back(i+1);
    }
    cout << val(0) << endl;
    return 0;
}

Measured memory_bytes: 15104
arr = gets.chomp.split(' ').map(&:to_i)
b = gets.chomp.split(' ').map(&:to_i)
lower = []
higher =[]
for i in b do
  if i > arr[0]
    break
  end
  if i > arr[2]
    higher.push i
  elsif i < arr[2]
    lower.push i
  end
end

puts [higher.count, lower.count].min


Measured memory_bytes: 1788
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	if(n / 10 == 9 || n % 10 == 9){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
bingo = [list(map(int, input().split())) for i in range(3)]
n = int(input())
nums = [int(input()) for i in range(n)]
res = 'No'
for num in nums:
    for i in range(3):
        if num in bingo[i]:
            j = bingo[i].index(num)
            bingo[i][j] = 0
            if sum(bingo[i]) == 0 or sum([row[j] for row in bingo]) == 0:
                res = 'Yes'
            elif (i + j) % 2 == 0:
                if i + j == 2 and sum([bingo[0][2], bingo[1][1], bingo[2][0]]) == 0:
                    res = 'Yes'
                elif i == j and sum([bingo[0][0], bingo[1][1], bingo[2][2]]) == 0:
                    res = 'Yes'
            break
    if res == 'Yes':
        break
print(res)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

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

	ll ans;
	ll n,x,m;

	cin >> n >> x >> m;
	
    vector<ll> sum_a(m+1,0);
	vector<ll> mem(m,0);

	ll sum = 0;

	ll first_i=0, final_i=0;
    for(ll i=0; i<n; i++){
		print(x)
		if(mem[x]){
			first_i = mem[x];
			final_i = i;
			break;
		}
		sum += x;
		mem[x] = i;
		sum_a[i+1] = sum;
        x = (x*x)%m;
	}

	ll times = 0;
	ll bsec = sum;
	ll sec = 0;
	ll asec = 0;
	ll md = 0;
	if(final_i!=first_i){
		times = (n-first_i)/(final_i - first_i);
		md = (n-first_i)%(final_i - first_i);
		
		//
		print(first_i, final_i)
		bsec = sum_a[first_i];
		sec = sum_a[final_i] - sum_a[first_i];
		asec = sum_a[first_i+md] - sum_a[first_i];
	}

	print(bsec, sec,asec, first_i,final_i, sum, times, md)

	ans = bsec + sec*times + asec;

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


Measured memory_bytes: 4764
//Minor Change

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

int main(){
  int cnt=0;
  string S,T;
  cin >> S >> T;
  for(int i=0; i<S.length(); i++){
    if(S[i]!=T[i]) cnt++;
  }
  cout << cnt << endl;
}


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

using namespace std;

int main(void) {
    long long H, W;
    cin >> H >> W;

    long long a, b, c, ans = 1e18;
    for (long long i = 1; i <= H; i++) {
        a = i * W;
        b = ((H * W - a) % 2 != 0) ? (H - i) * (W / 2) : (H * W - a) / 2;
        c = H * W - a - b;
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }

    for (long long i = 1; i <= W; i++) {
        a = i * H;
        b = ((H * W - a) % 2 != 0) ? (W - i) * (H / 2) : (H * W - a) / 2;        
        c = H * W - a - b;
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<(x)<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;
typedef long long ll;
ll MOD = (ll)998244353;
inline ll qpow(ll a, ll b) {return b? ((b&1)? a*qpow(a*a%MOD,b>>1)%MOD: qpow(a*a%MOD,b>>1))%MOD: 1;}
inline ll gcd(ll a, ll b) {return b? gcd(b, a%b): a;}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll m,n,k_;
    cin>>n>>m>>k_;
    ll c=1,ans=m*qpow(m-1,n-1)%MOD;
    rep(k,1,k_){
        c*=n-k;c%=MOD;
        c*=qpow(k,MOD-2);c%=MOD;
        ans+=m*c%MOD*qpow(m-1,n-1-k)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}
/* 
组合数学
至多k个的方案 等价于正好1..k 分别计算答案
和左边的比较
m*c(n-1,k)*1^k*kpow(M-1,N-1-k)
a
 */

Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] l = new int[n];
		for ( int i=0; i<n; i++ ) l[i] = sc.nextInt();

		int g=0;
		for ( int i=0; i<n; i++ ) {
		for ( int j=i+1; j<n; j++ ) {
			if ( l[i]==l[j] ) continue;
			int kmax = l[i]+l[j] ;
			int kmin = (int)Math.abs(l[i]-l[j]);

			for ( int k=j+1; k<n; k++ ) {
				if ( (l[k]-l[i])*(l[k]-l[j])==0 ) continue;
				if ( l[k]<=kmin || l[k]>=kmax ) continue;
				g++;
			}
		}
		}

		System.out.println(g);
	}
}

Measured memory_bytes: 36572
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int Q;
int main() {
  cout << fixed << setprecision(15);
  cin >> Q;
  REP(i,Q) {
    ll A,B;
    cin >> A >> B;
    if (B>A)swap(A,B);
    ll k=0;
    ll l=0,r=1000*1000*1000ll + 10ll;
    while(r-l>1) {
      ll m=l+(r-l)/2;
      if (m*(m+1)<=A*B)
        l=m;
      else
        r=m;
    }
    k=l;
    if (A==B+1) {
      cout << (k-1)*2<<endl;
    } else {
      cout << k + min(k,B-1) + min(A-k-1,max(0ll,(A*B-1)/(k+1)-B)) << endl;
    }

  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
	int n,l[1000],r[1000],cnt=0,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&l[i],&r[i]);
	}
	for(i=0;i<n;i++)
	{
		cnt+=r[i]-l[i]+1;
	}
	printf("%d\n",cnt);
	return 0;
}

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


int main(){
  int H,W;
  char C[101][101];
  int A[101][101];

  cin >> H >> W;

  for(int y = 1; y<H + 1; ++y){
    for(int x = 1; x<W + 1; ++x){
      cin >> C[y][x];
    }
  }

  bool work = false;
  for(int y = 1; y<H + 1; ++y){
    for(int x = 1; x<W + 1; ++x){
      if(C[y][x] == 'c'){
	A[y][x] = 0;
      }else{
	work = false;
	for(int c = x-1; c>0; --c){
	  if(C[y][c] == 'c'){
	    work = true;

	    A[y][x] = x - c;

	    break;
	  }
	}

	if(work == false){
	  A[y][x] = -1;
	  work = false;
	}
      }
    }
  }


  for(int y = 1; y<H + 1; ++y){
    for(int x = 1; x<W + 1; ++x){
      cout << A[y][x];
      if(x != W){
	cout << " ";
      }
    }
    cout << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {

		public List<Integer>[] graph;
		public int[] color;
		public int[] maxx;

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), m = in.nextInt();
			graph = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);
			for (int i = 0; i < m; i++) {
				int a = in.nextInt() - 1, b = in.nextInt() - 1;
				graph[a].add(b);
				graph[b].add(a);
			}

			int q = in.nextInt();
			color = new int[n];
			int[] v = new int[q], d = new int[q], c = new int[q];
			for (int i = 0; i < q; i++) {
				v[i] = in.nextInt() - 1;
				d[i] = in.nextInt();
				c[i] = in.nextInt();
			}

			maxx = new int[n];
			Arrays.fill(maxx, -1);
			for (int i = q - 1; i >= 0; i--) {
				process(v[i], d[i], c[i]);
			}

			for (int i = 0; i < n; i++) {
				out.println(color[i]);
			}

		}

		public void process(int v, int dist, int c) {
			if (dist <= maxx[v]) return;
			maxx[v] = dist;
			if (color[v] == 0) color[v] = c;
			for (int next : graph[v]) {
				process(next, dist - 1, c);
			}
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 74484
S = input()

if S == "MON":
    print(6)
if S == "TUE":
    print(5)
if S == "WED":
    print(4)
if S == "THU":
    print(3)
if S == "FRI":
    print(2)
if S == "SAT":
    print(1)
if S == "SUN":
    print(7)

Measured memory_bytes: 3060
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    dic = {}
    for i in range(N):
        input_raw = read_func().strip().split()
        if input_raw[0] in dic:
            dic[input_raw[0]] += 1
        else:
            dic[input_raw[0]] = 1
    input_raw = read_func().strip().split()
    [M] = [int(input_raw[0])]
    for i in range(M):
        input_raw = read_func().strip().split()
        if input_raw[0] in dic:
            dic[input_raw[0]] -= 1

    print max(max(dic.values()), 0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
# -*- coding: utf-8 -*-
import sys
'import math'
while 1:
    n,m=input().split()
    n=int(n)
    m=int(m)
    if n==m==0:sys.exit()
    a=m-1
    while a<(m-1)*n:
        a=int(m*a/(m-1)+1)
    a=n*m-a
    print(a)

Measured memory_bytes: 7536
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s[8];

void bomb(int x , int y){
  s[x][y]='0';
  for(int i = -3; i <= 3 ; i++){
    if(x+i>=0 && x+i<8 && s[x+i][y]=='1') {
      s[x+i][y]='0';
      bomb(x+i,y);
    }
    if(y+i>=0 && y+i<8 && s[x][y+i]=='1'){
      s[x][y+i]='0';
      bomb(x,y+i);
    } 
  }
}

int main(){
  int n;
  cin>>n;
  cin.ignore();
  for(int i = 0;i < n;i++){
    for(int j = 0; j < 8;j++)cin>>s[j];
    cin.ignore();
    int x,y;
    cin>>x>>y;
    bomb(y-1,x-1);
    printf("Data %d:\n",i+1);
    for(int j = 0; j < 8;j++)cout<<s[j]<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
//#define int ll
const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-9;
//#define DEBUG//#define lowbit(x) ((x) & -(x))//<<setiosflags(ios::fixed)<<setprecision(9)
void read(){}
template<typename T,typename... T2>inline void read(T &x,T2 &... oth) {
	x=0; int ch=getchar(),f=0;
	while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	if(f)x=-x;
	read(oth...);
}
signed main(signed argc, char const *argv[])
{
	std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	#ifdef DEBUG
		freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	#endif
	string s,t;
	ll ans=inf,cnt=0;
	cin>>s>>t;
	for(int i=0;i<s.length()&&i<=s.length()-t.length();i++)
	{
		cnt=0;
		for(int j=0;j<t.length();j++)
			if(s[i+j]!=t[j])
				cnt++;
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

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

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

   if (x < 1200) {
       cout << "ABC" << endl;
   } else {
       cout << "ARC" << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int H, W, p = 0;
cin >> H >> W;
string s;

vector<string> a(H);
for (int i = 0; i < H; ++i) {
        cin >> s;
        if (s.find('#') != -1) {
                a[p] = s;
                p++;
        }   
}

for (int i = 0; i < W; ++i) {
        bool flag = false;
        if (a[0][i] == '.') {
                flag = true;
                for (string j : a) {
                        if (j[i] == '#') {
                                flag = false;
                                break;
                        }   
                }   
        }   
        if (flag) {
                for (int k = 0; k < a.size(); ++k) {
                        a[k][i] = '_';
                }   
        }   
}

for (string i : a) {
        for (char j : i) {
                if (j == '_') { 
                        continue;
                }   
                cout << j;
        }   
        cout << endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a, b, c, i) for (int i = a; i < b; i += c)
#define MAX_INT 1000000007
#define ll long long
#define p(t1, t2, x) pair<t1, t2> x
#define v(t, x) vector<t> x
#define newl "\n"

using namespace std;

class PaymentChange{
public:
	int getChange(int n){
		if (n % 1000 == 0) return 0;
		return 1000 - (n % 1000);
	}
};

int main(){
	PaymentChange pmch;
	int n;
	cin >> n;
	cout << pmch.getChange(n) << newl;
}


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

int main(){
	/*input*/
	int n;	cin >> n;
	vector<vector<int> >a(2, vector<int>(n));
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	/*calculation*/
	int ans = 0;
	for(int j = 0; j < n; j++){
		int sum = 0;
		for(int i = 0; i < n; i++){	//sum
			if(i < j){
				sum += a[0][i];
			}else if(i == j){
				sum += a[0][i];
				sum += a[1][i];
			}else{
				sum += a[1][i];
			}
		}
		if(ans < sum){
			ans = sum;
		}
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int x,y,z; cin >> x >> y >> z;
	if (x==1) cout << "Hello World" << endl;
	else cout << y + z << endl;


}


Measured memory_bytes: 256
from math import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+2)
R = [0]*(N+2)

for i in range(N):
    if L[i] == 0:
        L[i+1] = A[i]
    else:
        L[i+1] = gcd(L[i], A[i])

for i in range(N, 0, -1):
    if R[i+1] == 0:
        R[i] = A[i-1]
    else:
        R[i] = gcd(R[i+1], A[i-1])

ans = 1
for i in range(N):
    if L[i] == 0:
        ans = max(ans, R[i+2])
    else:
        ans = max(ans, gcd(L[i], R[i+2]))
print(ans)

Measured memory_bytes: 84572
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        int fast = 0;
        int slow = 0;
        int limit = 0;
        int max = 0;
        while(fast < s.length() && slow < s.length()) {
            if(s.charAt(fast) == '0') {
                while(fast < s.length() && s.charAt(fast) == '0') {
                    fast++;
                }
                limit++;
                if(limit <= k && fast < s.length()) max = Math.max(max, fast - slow + 1);
                if(limit <= k && fast == s.length()) max = Math.max(max, fast - slow);
                while(limit > k && slow <= fast) {
                    if(s.charAt(slow) == '0') {
                        while(slow < s.length() && s.charAt(slow) == '0') slow++;
                        limit--;
                        if(limit <= k && fast < s.length()) max = Math.max(max, fast - slow + 1);
                        if(limit <= k && fast == s.length()) max = Math.max(max, fast - slow);
                    } else {
                        slow++;
                    }
                }
            } else {
                max = Math.max(max, fast - slow + 1);
                fast++;
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 24840
#include<iostream>
int main(){
  int n, m;
  int in, out;
  std::cin >> n >> m;
  
  bool flag = true;
  int ans = m;
  for(int i = 1; i <= n; i++){
    std::cin >> in >> out;
    m -= (out - in);
    if(m > ans) ans = m;
    if(m < 0){
      flag = false;
    }
  }
  
  if(!flag) std::cout << 0 << std::endl;
  else std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 2996
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

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

  ll a[n];
  for(int i=0; i<n; ++i){
    cin >> a[i];
  }

  sort(a, a+n);
  for(int i=0; i<n-1; ++i){
    if(a[i]==a[i+1]){
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
   
}

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

int main(){
	int a,b,c,d,e,f,g,h,i;
	cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
	if ((e == d+b-a) and (f == d+c-a) and (h == b+g-a) and (i == c+g-a)){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

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

int main() {
int a,b;
  cin>>a>>b;
 int ans=0;
  rep(i,2){
 if(a>=b){
   ans+=a;
   a--;
 }
  else{
    ans+=b;
    b--;
  }
  }
  cout<<ans<<endl;
}

  
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }

int main(){
  int n;
  cin >> n;
  char s[n];
  rep(i,n)cin >> s[i];
  vector<int>v;
  rep(i,n){
    if(s[i]=='#')v.push_back(i);
  }
  vector<int> ans;
  rep(i,v.size()){
    int t=0;
    t+=i;
    t+=n-v[i]-1-(v.size()-(i+1));
    ans.push_back(t);
  }
  ans.push_back(v.size());
  ans.push_back(n-v.size());
  int res = 1000000;
  rep(i,ans.size()){
    //cout << ans[i] << endl;
    chmin(res,ans[i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 2804
//In the name of God
#include<bits/stdc++.h>

using namespace std;

const int N = 2e3 + 100;
int n , k , a[N] , b[N] , res , now;
vector<int>e[N];

void dfs0(int v , int p = -1 , int h = 0){
	if(h > k / 2)
		return ;
	now++;
	for(auto u : e[v])
		if(u != p)
			dfs0(u , v , h+1);
}

void dfs1(int v , int x , int p = -1, int h = 0){
	if(h > k / 2)
		return ;
	now++;
	for(auto u : e[v])
		if(u != p && u != x)
			dfs1(u , x , v , h+1);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;	res = n;
	for(int i=1 ; i < n ; i++){
		cin >> a[i] >> b[i];
		e[a[i]].push_back(b[i]);
		e[b[i]].push_back(a[i]);
	}
	if(k&1){
		for(int i=1 ; i < n ; i++){
			now = 0;
			dfs1(a[i] , b[i]);
			dfs1(b[i] , a[i]);
			res = min(res , n - now);
		}
	}
	else{
		for(int i=1 ; i <= n ; i++){
			now = 0;
			dfs0(i);
			res = min(res , n - now);
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adjlist[100005];
int p[100005];
int d[100005];
int l[100005], r[100005];
int ans[100005];
int root;
bool valid =true;
void dfs(int u){
    for (auto v : adjlist[u]){
        if (v == p[u]) continue;
        d[v] = d[u]+1;
        p[v] = u;
        dfs(v);
        if (l[v] != -1 && r[v] != -1){
            if (l[v] == r[v]){
                if ((l[v]+d[v]) % 2 != (l[root] % 2)) valid = false;
            }
            l[u] = max(l[u],l[v]-1);
            r[u] = min(r[u],r[v]+1);

            if (l[u] > r[u]) valid = false;
        }
    }
    //printf("%d %d %d\n",u,l[u],r[u]);
    return;
}
void label(int u){
    //printf("label %d ",u);
    for (auto v : adjlist[u]){
        if (v == p[u]) continue;
        //printf("might label %d %d %d %d\n",v,l[v],r[v],ans[u]);
        if (l[v] <= ans[u] + 1 && ans[u] + 1 <= r[v]){
            ans[v] = ans[u]+1;
        }
        else if (l[v] <= ans[u]-1 && ans[u]-1 <= r[v]){
            ans[v] = ans[u]-1;
        }
        else valid = false;
        if (valid) label(v);
    }
}
int main(){
    scanf("%d",&n);
    int rt;
    for (int i = 0; i < n-1; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    int k;
    scanf("%d",&k);
    for (int i = 1; i <= n; i++) l[i]=-1000005, r[i]=2000005;
    for (int i =0; i < k; i++){
        int v,p;
        scanf("%d%d",&v,&p);
        l[v] = r[v] = p;
        root = v;
    }
    p[root] = root;
    d[root] = 0;
    dfs(root);
    if (!valid){
        printf("No\n");
        return 0;
    }
    ans[root] = l[root];
    label(root);
    if (!valid){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for (int i = 1; i <= n; i++){
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 13056
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

#include<iostream>

int main(){
    int n;
    cin >> n;
    if (n <= 999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
    
}

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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef unsigned long long ll;

const int MAX = 1e6 + 5;

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

	cin>>n>>m;
	if(m == n)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500 + j*100 + k*50 == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 67360
#include <iostream>
#include <string>
#include <stack>

using namespace std;

namespace Solver {

    string s;
    inline bool Read() {
        getline(cin, s);
        return s != ".";
    }

    inline void Work() {
        stack<char> stk;
        bool ok = true;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                stk.push(s[i]);
            } else if (s[i] == ']') {
                if (stk.empty() || stk.top() != '[') {
                    ok = false;
                } else {
                    stk.pop();
                }
            } else if (s[i] == ')') {
                if (stk.empty() || stk.top() != '(') {
                    ok = false;
                } else {
                    stk.pop();
                }
            }
        }

        if (stk.empty() && ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    inline void Solve() {
         while(Read()) Work();
    }
}

int main() {
    Solver::Solve();
}

Measured memory_bytes: 1180
import heapq, sys
def input():
	return sys.stdin.readline()[:-1]

class DijkstraList():
	#隣接リスト版
	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
	def __init__(self, adj, start):
		self.list = adj
		self.start = start
		self.size = len(adj)

	def solve(self):
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0
		self.prev = [-1 for _ in range(self.size)]
		self.q = []
		self.cnt = 0

		heapq.heappush(self.q, (0, self.start))

		while self.q and self.cnt < self.size:
			u_dist, u = heapq.heappop(self.q)
			if self.dist[u] < u_dist:
				continue
			for v in self.list[u]:
				if self.dist[v] > u_dist + 1:
					self.dist[v] = u_dist + 1
					self.prev[v] = u
					heapq.heappush(self.q, (self.dist[v], v))
			self.cnt += 1
		return

	def distance(self, goal):
		return self.dist[goal]

	def path(self, goal):
		self.path = [goal]
		while self.path[-1] != self.start:
			self.path.append(self.prev[self.path[-1]])
		return self.path[::-1]

n, m = map(int, input().split())
adj = [[] for _ in range(3*n)]
for _ in range(m):
	u, v = map(int, input().split())
	adj[u-1].append(v-1+n)
	adj[u-1+n].append(v-1+2*n)
	adj[u-1+2*n].append(v-1)
s, t = map(int, input().split())
s, t = s-1, t-1

d = DijkstraList(adj, s)
d.solve()
ans = d.distance(t)
print(ans//3 if ans != 10**30 else -1)

Measured memory_bytes: 62340
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
count = 0
D_temp = 0
for i in range(0, N+1):
    if i == 0:
        count += 1
    else:
        D_temp += L[i-1]
        if D_temp <= X:
            count += 1
print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define FOR(i,n,m) for(int i=n; i<(int)m; i++)
#define ROF(i,n,m) for(int i=n; i>(int)m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define all(x) x.begin(),x.end()
#define debug true
#define dprintf debug && printf

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

int n;
ii a[MAXN];
int ans[MAXN];

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

    ri(n);
    FOR(i,0,n) ri(a[i].F), a[i].S = i;
    sort(a, a + n);
    FOR(i,0,n/2) ans[a[i].S] = a[n/2].F;
    FOR(i,n/2,n) ans[a[i].S] = a[n/2 - 1].F;
    FOR(i,0,n) printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>

using namespace std;
typedef long long ll;

#define MAX_N 100
#define MAX_X 100
#define INF 10000000

int X[MAX_N];

int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sum += X[i];
  }

  // ---------------------
  // 

  double P = 1.0 * sum/N;
  //cout << P << endl;

  int a = floor(P);
  int b = ceil(P);

  //cout << a << endl;
  //cout << b << endl;
  
  int total_a = INF;
  int total_b = INF;
  
  if ( 1 <= a ) {
    total_a = 0;
    for (int i = 0; i < N; i++) {
      total_a += pow(X[i] - a, 2);
    }
  }

  if ( b <= 100 ) {
    total_b = 0;
    for (int i = 0; i < N; i++) {
      total_b += pow(X[i] - b, 2);
    }
  }

  if (total_a > total_b) cout << total_b << endl;
  else cout << total_a << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

const int mod = 1000000007;
class mint {
  long long x;
public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const { 
  return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};

int main(){
  string s;cin >> s;
  vector<vector<mint>> dp(100005,vector<mint>(13));
  if(s[0]=='?') rep(i,10) dp[0][i] = 1;
  else dp[0][s[0]-'0'] = 1;


  for(int i = 1;i <= s.size()-1;i++){
    if(s[i] =='?'){
      rep(j,13) {
        rep(k,10) {
          dp[i][(10*j+k)%13] += dp[i-1][j];
          //cout << (10*j+k)%13 << " " << j << " " << dp[i][(10*j+k)%13] << " " << endl;
        }
      }
    }else{
      rep(j,13) {
        dp[i][(10*j+(s[i]-'0'))%13] += dp[i-1][j];
        //cout << (10*j+(s[i]-'0'))%13 << " " << j << " " << dp[i][(10*j+(s[i]-'0'))%13] << " " << endl;
      }
    }
  }

  cout << dp[s.size()-1][5] << endl;
  

}

Measured memory_bytes: 16724
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,a[100005],b[100005],fa[100005],ans=0,cnt=0;
inline long long find(long long x){
	return fa[x]?fa[x]=find(fa[x]):x;
}
inline long long max(long long x,long long y){
	return x>y?x:y;
}
inline long long read(){
	char c=getchar();
	for(;c>'9'||c<'0';) c=getchar();
	long long x=0;
	for(;c>='0'&&c<='9';){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x;
}
int main(){
	n=read(),m=read();
	if(m==n-1){
		puts("0");
		return 0;
	}
	for(long long i=1;i<=n;i++)
		a[i]=read(),ans+=a[i];
	for(long long i=1;i<=m;i++){
		long long x=read(),y=read();
		x=find(x+1),y=find(y+1);
		ans-=max(a[x],a[y]);
		b[++cnt]=max(a[x],a[y]);
		if(a[x]<a[y]) fa[y]=x;
		else fa[x]=y;
	}
	if(n-m>cnt+2){
		puts("Impossible");
		return 0;
	}
	sort(b+1,b+cnt+1);
	for(long long i=1;i<=n-m-2;i++) ans+=b[i];
	printf("%lld\n",ans);
	return 0; 
}

Measured memory_bytes: 2560
//ex3_2
//TKC001

#include<stdio.h>

int main(void){
    int N, units;

    scanf("%d", &N);
    //一の位を求める
    units = N % 10;

    switch (units)
    {
    //bonを出力
    case 3:
        printf("bon");
        break;
    
    //ponを出力
    case 0:
    case 1:
    case 6:
    case 8:
        printf("pon");
        break;

    //honを出力
    default:
        printf("hon");
        break;
    }

    return 0;
}

Measured memory_bytes: 1688
import sys
from operator import itemgetter
from collections import deque

input = sys.stdin.readline

N, X = map(int, input().split())
L = list(map(int, input().split()))
L2 = [0]
for i in range(len(L)):
    L2.append(L2[i] + L[i])

counter = 0
for i in range(len(L2)):
    if L2[i] <= X:
        counter += 1
print(counter)

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

int d[5] = { 0, 1, 0, -1, 0 };
int dist[100][100][4][11];

int main() {
    int n, m, a;
    cin >> n >> m >> a;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    int si, sj, gi, gj;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i][j] == 'S') {
                si = i;
                sj = j;
            }
            if (s[i][j] == 'G') {
                gi = i;
                gj = j;
            }
            for (int k = 0; k < 4; ++k) {
                for (int l = 0; l <= a; ++l) {
                    dist[i][j][k][l] = 100;
                }
            }
        }
    }
    deque<int> qi, qj, qd, qm;
    dist[si][sj][1][0] = 0;
    qi.push_back(si);
    qj.push_back(sj);
    qd.push_back(1);
    qm.push_back(0);
    while (!qi.empty()) {
        int pi = qi.front();
        int pj = qj.front();
        int pd = qd.front();
        int pm = qm.front();
        qi.pop_front();
        qj.pop_front();
        qd.pop_front();
        qm.pop_front();
        if (pi == si && pj == sj && pd == 3) continue;
        int dis = dist[pi][pj][pd][pm];
        {
            int ti = pi + d[pd], tj = pj + d[pd + 1];
            if (ti >= 0 && ti < n && tj >= 0 && tj < m && s[ti][tj] != '#' && dist[ti][tj][pd][pm] > dis) {
                dist[ti][tj][pd][pm] = dis;
                qi.push_front(ti);
                qj.push_front(tj);
                qd.push_front(pd);
                qm.push_front(pm);
            }
        }
        if (pi == si && pj == sj || pi == gi && pj == gj) continue;

        {
            int td = pd ^ 1;
            int ti = pi + d[td], tj = pj + d[td + 1];
            if (ti >= 0 && ti < n && tj >= 0 && tj < m && s[ti][tj] != '#' && pm < a && dist[ti][tj][td][pm + 1] > dis) {
                dist[ti][tj][td][pm + 1] = dis;
                qi.push_front(ti);
                qj.push_front(tj);
                qd.push_front(td);
                qm.push_front(pm + 1);
            }
        }
        {
            int td = pd ^ 3;
            int ti = pi + d[td], tj = pj + d[td + 1];
            if (ti >= 0 && ti < n && tj >= 0 && tj < m && s[ti][tj] != '#' && dis < a && dist[ti][tj][td][pm] > dis + 1) {
                dist[ti][tj][td][pm] = dis + 1;
                qi.push_front(ti);
                qj.push_front(tj);
                qd.push_front(td);
                qm.push_front(pm);
            }
        }
    }
    int ans = 50;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j <= a; ++j) {
            ans = min(ans, dist[gi][gj][i][j] + j);
        }
    }
    cout << (ans < 50 ? ans : -1) << "\n";
    return 0;
}

Measured memory_bytes: 4852
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let m = ((2 * n) as f64).sqrt().floor() as usize + 1;
    if m * (m - 1) != 2 * n {
        println!("{}", "No");
        return;
    }
    println!("Yes");
    println!("{}", m);
    let mut sets = vec![vec![]; m];
    let mut counter = 1;
    for i in 0..m {
        for j in (i + 1)..m {
            sets[i].push(counter.to_string());
            sets[j].push(counter.to_string());
            counter += 1;
        }
    }
    for set in sets {
        println!("{} {}", m - 1, set.join(" "));
    }
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 10876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int fx[5]={1,-1,0,0},fy[5]={0,0,1,-1};
  int h,w,cx,cy,dx,dy,i,j;
  int INF=(1<<29);
  cin >> h >> w >> cx >> cy >> dx >> dy;
  cx++,cy++,dx++,dy++;
  int a[1010][1010],b[1010][1010];
  for(i=0;i<=h+3;i++){
    for(j=0;j<=w+3;j++){
      a[i][j]=1,b[i][j]=INF;
    }
  }
  for(i=2;i<=h+1;i++){
    for(j=2;j<=w+1;j++){
      char s;
      cin >> s;
      if(s=='.'){
        a[i][j]=0;
      }
    }
  }
  deque<P> que;
  que.push_front(P(cx,cy));
  b[cx][cy]=0;
  while(!que.empty()){
    P p=que.front();
    que.pop_front();
    for(i=0;i<4;i++){
      if(a[p.first+fx[i]][p.second+fy[i]]==0 && b[p.first+fx[i]][p.second+fy[i]]>b[p.first][p.second]){
        b[p.first+fx[i]][p.second+fy[i]]=b[p.first][p.second];
        que.push_front(P(p.first+fx[i],p.second+fy[i]));
      }
    }
    for(i=p.first-2;i<=p.first+2;i++){
      for(j=p.second-2;j<=p.second+2;j++){
        if(a[i][j]==0 && b[i][j]>b[p.first][p.second]+1){
          b[i][j]=b[p.first][p.second]+1;
          que.push_back(P(i,j));
        }
      }
    }
  }
  if(b[dx][dy]==INF){
    cout << -1 << endl;
    return 0;
  }
  cout << b[dx][dy] << endl;
}

Measured memory_bytes: 11516
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MAX 1005
LL xyz[3*MAX];
LL result[8];
LL temp[MAX];
LL n,m;



LL ev(int opa,int opb,int opc){
	opa=opa*2-1;
	opb=opb*2-1;
	opc=opc*2-1;

	LL s=0;
	for(int i=0;i<n;i++){
		temp[i]= xyz[i*3]*opa+xyz[i*3+1]*opb+xyz[i*3+2]*opc;
	}
	sort(temp,temp+n);
	for(int i=0;i<m;i++){
		s+=temp[n-1-i];
	}
	return s;
}



int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
cin>>xyz[i*3]>>xyz[i*3+1]>>xyz[i*3+2];
	}
	LL maxn = 0;
	  for(int i = 0;i<8;i++){
	  	maxn=max(ev(i/4%2,i/2%2,i%2),maxn);
	  }
	  cout<<maxn;
    return 0;

}


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

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(c - a) <= d) cout << "Yes" << endl;
  else {
    if ((abs(b - a) <= d) && (abs(c - b) <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int inner(const string& s) {
  int cnt = 0;
  rep(i, s.size() - 1) {
    if (s[i] == 'A' && s[i + 1] == 'B') cnt++;
  }
  return cnt;
}

int main() {
  //
  int n;
  cin >> n;
  int ans = 0;

  int ab = 0;
  int a = 0;
  int b = 0;
  rep(i, n) {
    string s;
    cin >> s;
    ans += inner(s);
    if (s[0] == 'B' && s[s.size() - 1] == 'A') {
      ab++;
    } else if (s[0] == 'B') {
      b++;
    } else if (s[s.size() - 1] == 'A') {
      a++;
    }
  }
  if (ab >= 1) {
    ans += (ab - 1);
    if (a > 0) {
      ans++;
      a--;
    }
    if (b > 0) {
      ans++;
      b--;
    }
  }
  ans += min(a, b);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256