akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}

vector<int> seive(int n) {
    vector<int> prime;
    vector<bool> flag(n+1);
    int cnt = 0;
    for (int i=2; i<=n+1; i++) {
        cnt++;
        if (!flag[i]) {
            for (int j=2; j*i<=n; j++) {
                flag[i*j] = true;
                cnt++;
            }
        }
    }
    // cout << cnt << endl;
    for (int i=2; i<=n; i++)
        if (!flag[i])
            prime.pb(i);
    return prime;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int n;
    cin >> n;
    vector<int> arr = seive(n);
    map<int, int> pcnt;
    for (int j=2; j<=n; j++) {
        int t = j;
        for (int i: arr) {
            if (t == 1)
                break;
            while (t%i == 0) {
                pcnt[i]++;
                t /= i;
            }
        }
    }   
    long long int res = 1;
    for (auto it: pcnt) {
        res *= (it.second+1);
        res %= 1000000007;
    }
    cout << res << endl;

    // printV(res);
    // time(&end); 
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}      

Measured memory_bytes: 3620
n =int(input())
a = list(int(i) for i in input().split())
sa = []
for i in range(n):
  sa.append(a[i]-i-1)
sa.sort()
b = sa[n//2]
su =0
for i in range(n):
  su+= abs(sa[i]-b)
print(su)

Measured memory_bytes: 26832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		int count = 0;
		int leng = S.length();
		char N[] = new char[leng];
		
		for (int i = 0; i< leng; i++){
			N[i]= S.charAt(i);
		}
		
		for(int i=0; i<(leng-1); i++){
			char n = N[i+1];
			if(N[i+1]!=N[i]){
				count++;
			}
		}
		
		System.out.println(count);
			
	}
}

Measured memory_bytes: 14544
a = input().split()
N = list(map(int,input().split()))
A = int(a[0])

counter = 1

for i in range(2,A+1):
  N_new = N[0:i]
  N_new_len = len(N_new)
  if max(N_new) == N_new[int(N_new_len)-1]:
    counter += 1
print(counter)

Measured memory_bytes: 3060
unittest
{
	assert( [ "<>>" ].parse.expand.solve == 3 );
	assert( [ "<>>><<><<<<<>>><" ].parse.expand.solve == 28 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto ans = 0L;
	auto m = 0L;
	foreach( g; s.group )
	{
		auto c = cast( long ) g[ 1 ];
		if( g[ 0 ] == '<' )
		{
			ans += c * ( c - 1 ) / 2;
			m = c;
		}
		else
		{
			ans += max( m, c ) + c * ( c - 1 ) / 2;
			m = 0;
		}
	}
	ans += m;
	return ans;
}


Measured memory_bytes: 4240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;

int main(){
	int n, r, inner;
	cin >> n >> r;
	inner = 0;
	if(n < 10){
		inner = r+(100*(10-n));
	}
	else{
		inner = r;
	}
	cout << inner << endl;
	return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const int MAX_N = 200000;
int H, W, N;
int sr, sc;
string S, T;
int slr[MAX_N], tlr[MAX_N], sud[MAX_N], tud[MAX_N];

template<typename... Args>
void debug(Args... args) {
    for (auto arg:{args...})cerr << arg << " ";
    cerr << endl;
}

signed main() {
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S >> T;
    rep(i, N) {
        if (S[i] == 'L')slr[i] = -1;
        else if (S[i] == 'R')slr[i] = 1;
        else if (S[i] == 'U')sud[i] = -1;
        else if (S[i] == 'D')sud[i] = 1;
        if (T[i] == 'L')tlr[i] = -1;
        else if (T[i] == 'R')tlr[i] = 1;
        else if (T[i] == 'U')tud[i] = -1;
        else if (T[i] == 'D')tud[i] = 1;
    }
    //lrwc
    {
        int l = 1, r = W;
        int k = N - 1;
        while (k >= 0 && slr[k] == 0)k--;
        if (k == -1)goto label1;
        if (slr[k] == 1)r--;
        else if (slr[k] == -1)l++;
        else {
            assert(0);
        }
        for (int i = k - 1; i >= 0; --i) {
            if (tlr[i] == 1)l--;
            else if (tlr[i] == -1)r++;
            if (l <= 0)l = 1;
            if (r > W)r = W;
            if (slr[i] == 1)r--;
            else if (slr[i] == -1)l++;
            if (l > r) {
                l = INF;
                break;
            }
            //debug(l, r);
        }
        if (sc < l || r < sc) {
            cout << "NO" << endl;
            return 0;
        }
        //debug(l, r);
    }
    label1:;
    {
        //udhr
        int u = 1, d = H;
        int k = N - 1;
        while (k >= 0 && sud[k] == 0)k--;
        if (k == -1)goto label2;
        if (sud[k] == 1)d--;
        else if (sud[k] == -1)u++;
        else {
            assert(0);
        }
        for (int i = k - 1; i >= 0; --i) {
            if (tud[i] == 1)u--;
            else if (tud[i] == -1)d++;
            if (u <= 0)u = 1;
            if (d > H)d = H;
            if (sud[i] == 1)d--;
            else if (sud[i] == -1)u++;
            if (u > d) {
                u = INF;
                break;
            }
            //debug(u, d);
        }
        if (sr < u || d < sr) {
            cout << "NO" << endl;
            return 0;
        }
        //debug(u, d);
    }
    label2:
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 7048
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
#define MXN 2000005
const int mod=1e6+3;
int X[4]={0,0,1,-1};
int Y[4]={1,-1,0,0};
int main(){
    int w,d,n;
    scanf("%d %d %d",&w,&d,&n);
    priority_queue<pair<int,pii> > pq;
    int dis[55][55];
    for(int i = 0;i<55;i++){
        for(int j=0;j<55;j++)
            dis[i][j]=-1e9;
    }
    for(int i = 0;i<n;i++){
        int x,y,u;
        scanf("%d %d %d",&x,&y,&u);
        dis[x][y]=u;
        pq.push(mp(u,mp(x,y)));
    }
    LL ans=0;
    while(!pq.empty()){
        auto p=pq.top();
        pq.pop();
        ans+=p.x;
      //  printf("%d %d %d\n",p.x,p.y.x,p.y.y);
        for(int i = 0;i<4;i++){
            int x=p.y.x+X[i],y=p.y.y+Y[i];
            if(x>=1&&x<=w&&y>=1&&y<=d){
                if(dis[x][y]==-1e9){
                    dis[x][y]=p.x-1;
                    pq.push(mp(p.x-1,mp(x,y)));
                }
                else{
                    if(abs(dis[x][y]-p.x)>1){
                        printf("No\n");
                        return 0;
                    }
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

#define ll long long

using namespace std;

int a[16][16];
int n;
ll cost[1 << 16];
ll dp[1 << 16];

ll go(int gr, int mask) {
	
}

main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		vector < int > res;
		for (int j = 0; j < n; j++) {
			if ((mask >> j) & 1) {
				res.push_back(j);
			}
		}
		for (int i = 0; i < res.size(); i++) {
			for (int j = i + 1; j < res.size(); j++) {
				cost[mask] += a[res[i]][res[j]];
			}
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = mask; i > 0; i = mask & (i - 1)) {
			dp[mask] = max(dp[mask], dp[mask ^ i] + cost[i]);
		}
	}
	cout << dp[(1 << n) - 1];
}


Measured memory_bytes: 1280
import java.util.*;
import java.lang.*;

// class Pair implements Comparable<Pair>{
//   long a;
//   int cnt;
//   public Pair(long i, int j){
//     this.a = i;
//     this.cnt = j;
//   }
//   public int compareTo(Pair p){
//     if(this.cnt>=2 && p.cnt >=2 && this.a<p.a) return -1;
//     if(this.cnt<2 && p.cnt>=2) return -1;
//     return 1;
//   }
// }

class Main{
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int cnt4 = 0;
      int cnt2 = 0;
      int odd = 0;
      int N = Integer.parseInt(sc.next());
      for(int i = 0; i<N; i++){
        long a = Long.parseLong(sc.next());
        if(a%2 == 0){
          a/= 2;
          if(a%2 == 0) cnt4++;
          else cnt2++;
        }
        else odd++;
      }
      if(cnt2==0 && odd <= cnt4+1) System.out.println("Yes");
      else if(cnt2>0 && odd<=cnt4) System.out.println("Yes");
      else System.out.println("No");

  }
}

Measured memory_bytes: 42484
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include<iostream>
using namespace std;
const int MAXV = 100005; //素数表范围
int fla[MAXV];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {   memset(fla,0,sizeof(fla));
        int cnt=0,ma=0;
        for(int i=0; i<n; i++)
        {
            int a;
            scanf("%d",&a);
            cnt=max(cnt,a);
            fla[a]++,fla[a-1]++,fla[a+1]++;
        }
        for(int i=0; i<=cnt; i++)
        {
            ma=max(ma,fla[i]);
        }
        cout<<ma<<endl;

    }
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  if(s.compare("hi") == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(s.compare("hihi") == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(s.compare("hihihi") == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(s.compare("hihihihi") == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(s.compare("hihihihihi") == 0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 888
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

type box struct {
	value, index int
}

func (p *problem) solve() {
	N := p.NextInt()
	xs := strings.Split(p.Next(), " ")

	var list boxs
	for i, v := range xs {
		list = append(list, box{value: stoi(v), index: i})
	}
	sort.Sort(list)

	m := make([]int, N)
	for i, l := range list {
		m[l.index] = i
	}

	//log.Printf("N=%v, list=%v", N, list)
	for i := 0; i < N; i++ {
		c := N / 2
		if m[i] < c {
			p.PrintInt(list[c].value)
		} else {
			p.PrintInt(list[c-1].value)
		}
	}
}

type boxs []box

func (p boxs) Len() int {
	return len(p)
}

func (p boxs) Less(i, j int) bool {
	return p[i].value < p[j].value
}

func (p boxs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func del(i int, a []int) []int {
	var new []int
	for ii, v := range a {
		if ii == i {
			continue
		}
		new = append(new, v)
	}
	return new
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 24448
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main(){
    int n;
    int flag = 1;
    scanf("%d",&n);
    string str[n];
    for(int i=0;i<n;i++){
        cin >> str[i];
    }
    for(int a=0;a<n-1;a++){
        for(int b=a+1;b<n;b++){
            if(str[a] == str[b]){
                flag = 0; //No
            }
        }
    }
    for(int c=0;c<n-1;c++){
        if(str[c].back() != str[c+1].front()){
            flag = 0; //No
        }
    }
    if(flag == 0){
        printf("No");
    }
    else {
        printf("Yes");
    }
}


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

int main() {
  int x; cin >> x;
  int i = 0, c = 0;
  while(c < x) {
    c += i;
    i++;
  }
  cout << i-1 << endl;
  return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
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; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vint s(n); vin(s);
    sort(all(s));
    int sum = accumulate(all(s), 0);
    
    int pos = 0;
    while(pos < n) {
        if(sum % 10 != 0) break;
        if(s[pos] % 10 != 0) {
            sum -= s[pos];
            break;
        }
        pos ++;
    }
    if(sum % 10 == 0) sum = 0;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
while 1:
	W,Q = map(int,raw_input().split())
	if W == 0: break
	cat = [map(str,raw_input().split()) for i in range(Q)]
	wall = [-1]*W
	for i in range(Q):
		if cat[i][0] == "s":
			id,w = int(cat[i][1]),int(cat[i][2])
			for j in range(W-w+1):
				if wall[j:j+w] == [-1]*w:
					wall[j:j+w] = [id]*w
					print j
					break
			else:
				print "impossible"
		else:
			flag = 0
			for j in range(W):
				if wall[j] == int(cat[i][1]):
					wall[j] = -1
					flag = 1
				elif flag == 1:
					break
	print "END"

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);

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

    sort(l.begin(), l.end(), greater<int>());

    int ans = 0;
    for(i = 0; i < k; i++) {
        ans += l[i];
    }

    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> mochi(N);
  for (int i = 0; i < N; i++) cin >> mochi.at(i);
  sort(mochi.begin(), mochi.end());

  int currentMochiSize = mochi.at(0),
  	  total = 1;

  for (int i = 1; i < N; i++) {
	if (currentMochiSize < mochi.at(i)) {
      currentMochiSize = mochi.at(i);
      total++;
    }
  }

  cout << total << endl;  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
const LL mod = 1e9 + 7;
LL m[1010];
bool s[1010];
LL N;
LL ans = 1;
int main() {
	std::cin >> N;
	for (int i = 2; i <= N; i++) {
		int copy = i;
		for (int j = 2; j <= i; j++) {
			while (!(copy%j)) {
				m[j]++;
				copy/=j;
			}
		}
	}
	for (int i = 2; i <= N; i++)ans *= (m[i] + 1), ans %= mod;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
lis_AC = []
lis_WA = []
for i in range(M):
    p,s = input().split()
    if s == "AC":
        lis_AC.append(p)
    else:
        if p not in lis_AC:
            lis_WA.append(p)
lis_AC = set(lis_AC)
cnt_WA = 0
for i in lis_WA:
    if i in lis_AC:
        cnt_WA += 1

print(len(lis_AC), end = " ")
print(cnt_WA)

Measured memory_bytes: 89708
a,b = [int(i) for i in input().split()]

import numpy as np
n = []

for i in range(a):
    buf = list(input())
    if "#" in buf:
        n.append(buf)

buffer = []
for i in range(len(n)):
    for j in range(b):
        if "#" in n[i][j]:
            buffer.append(j)

buffer = list(set(buffer))

for i in range(len(n)):
    joined = [n[i][j] for j in buffer]
    print("".join(joined))


Measured memory_bytes: 12520
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf (int)50000000000 //5･10^10
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n,x,sum=0,cnt=0;
  cin>>n>>x;
  int a[n];
  rep(i,n) {
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  if(sum<x) cout<<n-1<<endl;
  else {
    rep(i,n) {
      if(a[i]<=x) {
        x-=a[i];
        cnt++;
      }
      else {
        cout<<cnt<<endl;
        break;
      }
      if(i==n-1) cout<<cnt<<endl;
    }
  }
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    bool flag = true;
    int count = 0;
    while (flag)
    {
        flag = false;
        for (int j = n - 1; j > 0; j--) {
            if (a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                flag = true;
                count++;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << '\n' << count << '\n';

    return 0;
}


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

int main(){
    int N; cin >> N;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    
    int ans=0;
    sort(A.begin(),A.end());
    rep(i,N-1) ans+=A[i];
    ans+=A[N-1]/2;
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MAX_DIGIT = 50;
long long dp[100][2]; // dp[上から i 桁まで][ smaller ]

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    for (int d = 0; d < MAX_DIGIT; ++d) {
        long long mask = 1LL<<(MAX_DIGIT - d - 1);
        
        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        
        // X の d 桁目を 0, 1 にしたときのコスト
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);
        
        // smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        
        // exact -> smaller
        if (dp[d][0] != -1) {
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        }
        
        // exact -> exact (K にぴったり合わせる)
        if (dp[d][0] != -1) {
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            else chmax(dp[d+1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  int N; cin >> N;
  int a[110];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  sort(a, a+N, greater<int>());
  int d = 0;
  for (int i = 0; i < N; i++)
    d += a[i] * pow(-1, i);
  cout << d << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)

int main(){
fast ;
int n,W ;
cin >> n >> W ;
long long v[n], w[n] ;
for(int i=0;i<n;i++)
cin >> w[i] >> v[i] ;
ll dp[W+1] = {0};

for(int i=0;i<n;i++){
	for(int j=W;j>=w[i];j--){
		dp[j] = max(dp[j],v[i]+dp[j-w[i]]) ;
	}
}
cout << dp[W] << endl ;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b;
  cin >> a >> b ;
  if (a < 10 && b < 10) cout << a * b << endl;
  else cout << -1 << endl;
  
}


Measured memory_bytes: 892
from collections import Counter
import numpy as np

N = 10 ** 6
Nsq = 10 ** 3
mod = 10 ** 9 + 7

fac = np.arange(N, dtype=np.int64).reshape(Nsq, Nsq)
fac[0, 0] = 1
for i in range(1, Nsq):
    fac[:, i] *= fac[:, i - 1]
    fac[:, i] %= mod
for i in range(1, Nsq):
    fac[i] *= fac[i - 1, -1]
    fac[i] %= mod
fac = fac.ravel()

finv = np.arange(1, N + 1, dtype=np.int64)[::-1].reshape(Nsq, Nsq)
finv[0, 0] = pow(int(fac[N - 1]), mod - 2, mod)
for i in range(1, Nsq):
    finv[:, i] *= finv[:, i - 1]
    finv[:, i] %= mod
for i in range(1, Nsq):
    finv[i] *= finv[i - 1, -1]
    finv[i] %= mod
finv = finv.ravel()[::-1]


def nCr(a, b):
    if b > a:
        return 0
    else:
        comb = fac[a] * finv[b] % mod * finv[a - b] % mod
        return comb


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

ind = 0
for i, x in enumerate(A):
    if C[x] > 1:
        ind = i - ind

for i in range(1, n + 2):
    res = nCr(n + 1, i) - nCr(n - ind, i - 1)
    res %= mod
    print(res)


Measured memory_bytes: 56496
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var n = parseInt(tmp[0], 10);
    var k = parseInt(tmp[1], 10);
    var count = 0;
 
 while(t!==0 ){
    var t=Math.floor(n/k); n=t;   //商の小数点以下切り捨て
    count=count+1;
   // console.log(t,n,count );
                   }
  console.log(count);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));// inputに入力データ全体が入る


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

struct Combination{
    const int MAX=5000010;
    const int MOD;
    vector<long long> FAC;
    vector<long long> INV;
    vector<long long> FAC_INV;
    Combination(const int MOD):
        MOD(MOD)
        {
            FAC=vector<long long>(MAX);
            INV=vector<long long>(MAX);
            FAC_INV=vector<long long>(MAX);
            FAC[0]=INV[1]=FAC_INV[0]=1;
            for(int i=1;i<MAX;i++){
                FAC[i]=FAC[i-1]*i%MOD;
                if(i>1) INV[i]=MOD-INV[MOD%i]*(MOD/i)%MOD;
                FAC_INV[i]=FAC_INV[i-1]*INV[i]%MOD;
            }
        }
    long long C(long long n,long long r){
        if(n<0||r<0||n<r) return 0;
        return FAC[n]*FAC_INV[r]%MOD*FAC_INV[n-r]%MOD;
    }
    long long P(long long n,long long r){
        if(n<0||r<0||n<r) return 0;
        return FAC[n]*FAC_INV[n-r]%MOD;
    }
    long long H(long long n,long long r){
        if(r==0) return 1;
        return C(n+r-1,r);
    }
};

int main() {
	Combination com(MOD);
	int n,k; cin>>n>>k;
	int b=k,r=n-k;
	for(int i=1;i<=k;i++){
		cout<<com.C(b-1,i-1)%MOD*com.H(i+1, r-(i-1))%MOD<<endl;
	}
	return 0;
}

Measured memory_bytes: 117504
n = int(input())
a1 = int(input())
a2 = int(input())
if a1 >= a2:
    maxa1 = a1
    maxa2 = a2
    res = 0
else:
    maxa1 = a2
    maxa2 = a1
    res = 1

for i in range(2, n):
    a_ = int(input())
    if maxa1 <= a_:
        maxa2 = maxa1
        maxa1 = a_
        res = i
    elif maxa2 <= a_:
        maxa2 = a_

for i in range(n):
    if i == res:
        print(maxa2)
    else:
        print(maxa1)

Measured memory_bytes: 4668
#include <bits/stdc++.h>
using namespace std;
int a[200002], b[200002];
int main(){
    int n;
    scanf("%d", &n);
    bool ok = 1;
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        if(a[i] > a[i-1] && a[i]-a[i-1] > 1){
            ok = 0;
        }
        if(i == 1 && a[i] != 0){
            ok = 0;
        }
    }   
    if(!ok) printf("-1\n");
    else{
        long long ans = 0;
        for(int i=n;i>=1;i--){
            if(a[i] == 0) continue;
            if(a[i]+1 == a[i+1]) continue;
            ans += a[i];
        }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
#define NIL -1
typedef struct Node{
  int k,l,m;
}N;

N S[100005];
int T[100005];

int setDepth(int a,int b)
{
  T[a]=b;
  if(S[a].m!=NIL)
    {
      setDepth(S[a].m,b);
    }
  if(S[a].l!=NIL)
    {
      setDepth(S[a].l,b+1);
    }
}


int main()
{
  int i,j,n,l,m,x,y,c;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      S[i].k=NIL;
      S[i].l=NIL;
      S[i].m=NIL;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&x,&y);
      for(j=0;j<y;j++)
        {
          scanf("%d",&c);
          if(j==0)
            {
              S[x].l=c;
            }
              else
                  S[l].m=c;
                  l=c;
                  S[c].k=x;
                
        }
    }
      for(i=0;i<n;i++)
         if(S[i].k==NIL)
              m=i;
         setDepth(m,0);
  for(i=0;i<n;i++)
    {
      printf("node %d: parent = %d, depth = %d, ",i,S[i].k,T[i]);
      if(S[i].k==NIL)
        {
          printf("root, ");
        }
      else if(S[i].l==NIL)
        {
          printf("leaf, ");
        }
      else
          printf("internal node, ");
        
      printf("[");

      for(j=0,c=S[i].l;c!=NIL;j++,c=S[c].m)
        {
          if(j)
             printf(", ");
          printf("%d",c);
        }
      printf("]\n");
    }

  return 0;
}
              




Measured memory_bytes: 6412
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define vel vector<ll>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
#define pin pair<ll,ll>
#define mkp make_pair
#define mot pair<D,D>//time,dist
#define path pair<ll,int>//cost,to
#define int long long
using namespace std;
vvel ta_min(0);
vvel ta_max(0);
int leth = 1024 * 512;
int p = 1000000007;
vel par;
vel dis;
int n;
void mmax(ll &a, ll b) { a = max(a, b); }
void mmin(ll &a, ll b) { a = min(a, b); }
pin root(int ser) {
	if (par[ser] == -1) {return mkp(ser,0);}
	pin x=root(par[ser]);
	x.second += dis[ser];
	par[ser] = x.first;
	dis[ser] = x.second;
	return x;
}
void uni(int a, int b,int d) {
	pin p1 = root(a);
	pin p2 = root(b);
	int a1 = p1.first;
	int b1 = p2.first;
	if (a1 != b1) {
		par[b1] = a1;
		dis[b1] = d + dis[a] - dis[b];
	}
}
bool issame(int x, int y) {
	return root(x).first == root(y).first;
}
void ref(int &x) { x = x % p; x = (x + p) % p; }
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);//return a^n%p
	x *= x; ref(x);
	if (n % 2 == 1) { x *= a; }
	ref(x);
	return x;
}
void nim(int x, int k) {
	while (1) {
		int x; int k; cin >> x >> k;
		vel gr(x + 1);
		gr[0] = 0;
		for (int i = 1; i <= x; i++) {
			vel ko(x + 1, 0);
			for (int j = 1; j <= i / k; j++) { ko[gr[i - j]]++; }
			int ind = 0;
			while (ko[ind] != 0) { ind++; }
			gr[i] = ind;
		}
		for (int i = 1; i <= x; i++) { cout << gr[i] << " "; }
	}
}
signed main() {
	int n, m; cin >> n >> m;
	cout << abs((n - 2)*(m - 2)) << endl;
	return 0;
}


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

int main(){
	
	ll n; cin>>n;
	ll cc = 0;
	while(n-500 >= 0){
		n -= 500;
		cc += 1000;
	}
	while(n-5 >= 0){
		n-= 5;
		cc+= 5;
	}
	cout<<cc<<"\n";
	
	
	
	
	
	
}

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

S = []
for _ in range(N):
    A = int(input())
    S.append([tuple(map(int, input().split())) for _ in range(A)])

def sol(state):
    for i, A in enumerate(S):
        if (state & (1 << i)) == 0:
            continue
        for j, s in A:
            if ((state & (1 << (j - 1))) != 0) != (s != 0):
                return 0
    return sum(map(int, bin(state)[2:]))

ans = 0
for state in range(1 << N):
    ans = max(ans, sol(state))
print(ans)


Measured memory_bytes: 3064
N = int(input())
sorted_X = sorted([(v, i) for i, v in enumerate(map(int, input().split()))])
med_former = sorted_X[N // 2][0]
med_latter = sorted_X[N // 2 - 1][0]
ans = [-1] * N
for j, (v, i) in enumerate(sorted_X):
    if j < N // 2:
        ans[i] = med_former
    else:
        ans[i] = med_latter
print("\n".join(map(str, ans)))


Measured memory_bytes: 48964
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
    cin >> a ;
  int r1 = a % 2;
  int r1m = (a - r1) / 10;
  int r2 = r1m % 2;
  int r2m = (r1m -r2) / 10;
  cout << r1 + r2 + r2m <<endl;
}
  


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void A_task();

int main()
{
	A_task();
	
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int A, B;
	scanf(" %d %d", &A, &B);

	int fee = 0;
	if (A >= 13) {
		fee = B;
	}
	else if ((A < 13) && (A >= 6)) {
		fee = B / 2;
	}
	else if (A < 6) {
		fee = 0;
	}
	printf("%d\n", fee);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   string N;
   cin >> N;
   int cnt = 0;
   for (int i = 0; i < N.size(); i++)
   {
      cnt += N[i] - '0';
      cnt %= 9;
   }
   if (cnt == 0)
   {
      cout << "Yes" << endl;
   }
   else
   {
      cout << "No" << endl;
   }
   return 0;
}


Measured memory_bytes: 3716
#include <cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	ll check = min({ a,b,c,d,e });
	if (n % check != 0) {
		cout << (n / check) + 5 << endl;
	}
	else
	cout << (n / check) + 4 << endl;
	return 0;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    *L, = sorted(map(int, input().split()))

    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            if L[i] == L[j]:
                continue
            for k in range(j + 1, N):
                if L[i] == L[k]:
                    continue
                if L[j] == L[k]:
                    continue
                if L[k] < L[i] + L[j]:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9188
#include <iostream>
using namespace std;
int N, A[3][3], b[11];
bool appear[3][3];
int main()
{
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> A[i][j];
    }
  }
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> b[i];
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
    	appear[i][j] = false;
    	for (int k = 0; k < N; k++)
    	{
      		if (A[i][j] == b[k])
        		appear[i][j] = true;
        }
    }
  }
  string ANS = "No";
  for (int i = 0; i < 3; i++)
  {
    if (appear[i][0] && appear[i][1] && appear[i][2])
      ANS = "Yes";
  }
  for (int i = 0; i < 3; i++)
  {
    if (appear[0][i] && appear[1][i] && appear[2][i])
      ANS = "Yes";
  }
  if (appear[0][0] && appear[1][1] && appear[2][2])
    ANS = "Yes";
  if (appear[0][2] && appear[1][1] && appear[2][0])
    ANS = "Yes";
  cout << ANS << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
long long n,tmp;
std::vector<long long> num,ai;
void solve(){
    rep(i,n){
        ai.at(i) = 0;
    }
    rep(i,n-1){
        tmp=num.at(i)-1;
        ai.at(tmp)++;
    }
    rep(i,n){
        cout<<ai.at(i)<<endl;
    }

}

int main(){
    cin>>n;
    rep(i,n-1){
        cin>>tmp;
        num.emplace_back(tmp);
    }
    ai.resize(n);


    solve();
    return 0;
}


Measured memory_bytes: 6384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        String s = sc.next();
        String[] slist = s.split("");
        int i;
      	if(slist[0].equals("A") && slist[1].equals("A") && slist[2].equals("A")){
        	System.out.println("No");
        }else if(slist[0].equals("B") && slist[1].equals("B") && slist[2].equals("B")){
          System.out.println("No");
        }else{
          System.out.println("Yes");          
        }
	}
}

Measured memory_bytes: 35604
n = int(input())
a = list(map(int, input().split()))
count = 0
flag = True
while flag:
	flag = False
	for j in range(n-1, 0, -1):
		if a[j-1] > a[j]:
			a[j-1], a[j] = a[j], a[j-1]
			count += 1
			flag = True
print(*a)
print(count)


Measured memory_bytes: 5608
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
string s;
vector<pair<int, int>> v;
int main(){
    cin >> n >> k;
    cin >> s;
    REP(i, n){
        if(!i){
            v.emplace_back(make_pair(s[i] - '0', 1));
        }else{
            if(s[i] == s[i - 1])v[(int)v.size() - 1].second++;
            else{
                v.emplace_back(make_pair(s[i] - '0', 1));
            }
        }
    }
    int ans = 0;
    n = (int)v.size();
    int l = 0, r = 0;
    int cnt = 0, num = 0;
    while(l < n && r < n){
        while(l < n && r < n && (cnt < k || v[r].first == 1)){
            num += v[r].second;
            if(v[r].first == 0)cnt++;
            r++;
        }
        ans = max(ans, num);
        num -= v[l].second;
        if(v[l].first == 0)cnt--;
        l++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int k, q;
int d[5010];

void solve() {
    int n, x, m;
    cin >> n >> x >> m;
    vector<int> d2(k);
    int zero = 0, sumd = 0;
    REP (i, k) {
        d2[i] = d[i] % m;
        zero += (d2[i] == 0);
        sumd += d2[i];
    }
    int res = zero * ((n - 1) / k);
    int last = x + sumd * ((n - 1) / k);
    REP (i, (n - 1) % k) {
        res += (d2[i] == 0);
        last += d2[i];
    }
    res += (last / m) - (x / m);
    cout << n - 1 - res << endl;
}

void _main() {
    cin >> k >> q;
    REP (i, k) cin >> d[i];
    REP (i, q) solve();
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 384
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;
#[derive(Clone, Debug, Default)]
struct Struct;

// 最も遠い点までの距離を計算
// 二部グラフになるはず
fn calc_dist(start: usize, n: usize, s: &Vec<Vec<char>>) -> Option<usize> {
    let mut q = VecDeque::new();
    let mut dist = vec![None; n];
    q.push_back((start, 1));

    let mut max_dist = 0;
    while let Some((i, d)) = q.pop_front() {
        if let Some(old_d) = dist[i] {
            if d != old_d {
                return None;
            }
        } else {
            dist[i] = Some(d);
            max_dist = max(max_dist, d);
            for j in 0..n {
                if s[i][j] == '1' && dist[j] != Some(d - 1) {
                    q.push_back((j, d + 1));
                }
            }
        }
    }
    return Some(max_dist);
}

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        s:[Chars;n],
    }

    let mut v = Vec::new();
    for i in 0..n {
        if let Some(d) = calc_dist(i, n, &s) {
            v.push(d);
        }
    }
    if let Some(d) = v.iter().max() {
        println!("{}", d);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 3052
#include<bits/stdc++.h> 
	using namespace std; 
	#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"

	void inputoutput()
	{
	    ios_base::sync_with_stdio(0);
	    cin.tie(0); 
	    #ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	    #endif
	    
	}
const long long  INF = 1e18;
	int32_t main()
	{
	    inputoutput();
	   
	   	long long int  a,b,c,d;
	   	cin>>a>>b>>c>>d ;

	   	long long int ans=-INF;

	   	ans=max(ans,a*c);
	   	ans=max(ans,a*d);
	    ans=max(ans,b*d);
	    ans=max(ans,b*c);

	    cout<<ans;

	    return 0;
	}




Measured memory_bytes: 3648
use proconio::input;

fn main() {
  input! {
    x: isize,
  }
  // 500 yen => 1000
  //   5 yen => 5
  let a = x / 500;
  let b = (x % 500) / 5;
  println!("{}", a*1000+b*5);
}


Measured memory_bytes: 2060
N, S = gets.to_i, gets.chomp
num = S[1..-1].count("E")
min = num

1.upto(N-1) do |pos|
  num -= 1 if S[pos] == "E"
  num += 1 if S[pos-1] == "W"
  min = num if num < min
end

puts min

Measured memory_bytes: 2436
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(rbegin(b), rend(b));
    int m2 = b[1];
    for(int i = 0; i < n; i++){
        if(a[i] != b[0]){
            cout << b[0] << endl;
        }else{
            cout << m2 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
import sys
input=sys.stdin.readline
import collections

n = int(input())
a = list(map(int, input().split()))
ans = collections.deque()
for i,v in enumerate(a):
    if i%2 == 0:
        ans.appendleft(v)
    else:
        ans.append(v)
if n%2 == 0:
    ans.reverse()
print(*ans)
    


Measured memory_bytes: 25552
N,M = list(map(int,input().split()))
ans = [-1 for i in range(N)]

if N == 1 and M == 0:
  print(0)
  exit()
if M == 0:
  ans[0] = str(1)
  for i in range(1,N):
    ans[i] = str(0)
  print("".join(ans))
  exit()

for i in range(M):
  S,C = list(map(int,input().split()))
  if N != 1 and C == 0 and S == 1:
    print('-1')
    exit()
  if ans[S-1] == C:
    continue
  elif ans[S-1] != -1:
    print('-1')
    exit()
  ans[S-1] = C
  
for i in range(N):
  if ans[i] == -1:
    if i == 0:
      ans[i] = 1
    else:
      ans[i] = str(0)
  ans[i] = str(ans[i])

print("".join(ans))

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int gcd(int a,int b);
int compare(const void* a, const void* b);

int main(void){
    int N,A,B;
    int br = 0;
    int ret = 0;
    char S[100000];
    int i;
    scanf("%d %d %d",&N,&A,&B);
    scanf("%s",S);
    for(i=0;i<N;i++){
        if (S[i]=='a'){
            if (ret < (A+B)){
                printf("Yes\n");
                ret++;
            }else{
                printf("No\n");
            }
        }else if (S[i]=='b'){
            br++;
            if ((br<=B)&&(ret < (A+B))){
                printf("Yes\n");
                ret++;
            }else{
                printf("No\n");
            }
        }else{
                printf("No\n");
        }
    }
    return 0;
}
int compare(const void* a, const void* b){
    return strcmp(a, b);
}
// 最大公約数
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cstdlib>

const long long MOD = 10e9 + 7;

using namespace std;

typedef long long ll;

long long f(long long i){
	long long n=i;
	int mul=1;
	while(i/10!=0){
		int i1 = i%10;
		int i2 = (i/10)%10;
		if(i1==i2){
			n=n-i1*mul;
		}	
		i=i/10;
		mul*=10;
	}	
	return n;
}

int main(){
	//int mi=1000000000; 
	//cout<<mi<<endl;
	int N,K,n,t;
	vector<int> h;
	cin>>N>>K;
	h.push_back(0);
	for(int i=0;i<N;i++){
		cin>>t;
		h.push_back(t);	
	}
	int arr[100001];
	arr[1]=0;
	for(int i=2;i<=N;i++){
		int minv=1000000000;
		for(int j=1;j<=K;j++){
			if(i-j>=1){
				minv = min(arr[i-j] +abs(h[i] - h[i-j]), minv );
			}
		}
		arr[i]=minv;
	}	
	cout<<arr[N]<<endl;
}

Measured memory_bytes: 1144
#include <stdio.h>

int main(void)
{
        char s[5];
        scanf("%s",s);

        if(s[0]==s[1] && s[1]==s[2] || s[1]==s[2] && s[2]==s[3])printf("Yes\n");
        else printf("No\n");
        return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>

int main() {
    int n, q;
    scanf("%d", &n);
    
    int S[n];
    for (int i=0; i<n; i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    
    int tmp, count=0, flag;
    for (int i=0; i<q; i++) {
        scanf("%d", &tmp);
        flag=1;
        for (int j=0; j<n; j++) {
            if(S[j] == tmp && flag) { 
                count++;
                flag=0;
            }
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 2696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){

		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		int c = Integer.parseInt(line[2]);
		if(a==0){break;}

		int products[] = new int[(a+b+c)];
		Arrays.fill(products, 2);

		int n = Integer.parseInt(br.readLine());
		ArrayList<Integer[]> wronglist = new ArrayList<Integer[]>();

		for(int i=0; i<n; i++){
			String test[] = br.readLine().split(" ");
			if(test[3].equals("1")){
				products[Integer.parseInt(test[0])-1] = 1;
				products[Integer.parseInt(test[1])-1] = 1;
				products[Integer.parseInt(test[2])-1] = 1;
			}else{
				Integer[] addlist = {Integer.parseInt(test[0])-1, Integer.parseInt(test[1])-1, Integer.parseInt(test[2])-1};
				wronglist.add(addlist);
			}
		}

		for(Integer[] testno: wronglist){
			if(products[testno[0]] * products[testno[1]] * products[testno[2]] == 2){
				if(products[testno[0]] == 2){
					products[testno[0]] = 0;
				}else if(products[testno[1]] == 2){
					products[testno[1]] = 0;
				}else{
					products[testno[2]] = 0;
				}
			}
		}

		for(Integer result: products){
			System.out.println(result);
		}
		}
	}
}

Measured memory_bytes: 26900