akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;string s;cin>>n>>s;
  int x=0,maxn=0;
  REP(i,n){
    if(s[i]=='I')x++;
    if(s[i]=='D')x--;
    maxn=max(maxn,x);
  }
  P(maxn);
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	M := nextInt()
	H := make([]int, N)
	graph := make([][]int, N)

	for i := 0; i < N; i++ {
		H[i] = nextInt()
	}

	for i := 0; i < M; i++ {
		a := nextInt() - 1
		b := nextInt() - 1

		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	c := 0

	for i := 0; i < N; i++ {
		ok := true
		for j := 0; j < len(graph[i]); j++ {
			k := graph[i][j]
			if H[i] <= H[k] {
				ok = false
				break
			}
		}
		if ok {
			c++
		}
	}

	fmt.Println(c)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 14448
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

enum EventType { Start_rw=0, Person=1, End_rw=2 };

struct Event {
  EventType type;  // Start/End roadwork or Person walk
  int64_t t;  // Time of event
  int64_t x;  // Distance in the road
  int64_t inter; // Intercept
  
  Event(EventType _type, int64_t _t, int64_t _x) {
    type = _type;
    t = _t;
    x = _x;
    inter = t - x;
  }

  friend bool operator<(const Event &lhs, const Event &rhs) {
if (lhs.inter==rhs.inter){
return lhs.type>rhs.type;
}
    return lhs.inter < rhs.inter;
  }
};

int main() {
  
  int64_t n, q;
  std::cin >> n >> q;
  std::vector<Event> events;
  std::set<int64_t> activeBarriers;

  int64_t s, t, x;
  for (auto i=0; i < n; ++i) {
    std::cin >> s >> t >> x;
    events.emplace_back(Start_rw, 2*s-1, 2*x);
    events.emplace_back(End_rw, 2*t-1, 2*x);
  }

  int64_t d;
  for (auto i=0; i < q; ++i) {
    std::cin >> d;
    events.push_back(Event(Person, 2*d, 0));
  };

  std::sort(events.begin(), events.end());

  for (Event event:events) {
    if (event.type == Start_rw) {
      activeBarriers.insert(event.x);
    } else if (event.type == Person) {
      auto distance = activeBarriers.begin();
      if (distance == activeBarriers.end()) {
        std::cout << -1 << '\n';
      } else {
        std::cout << (*distance)/2 << '\n';
      }
    } else if (event.type == End_rw) {
      activeBarriers.erase(event.x);
    }
  }
  
  return 0;
}

Measured memory_bytes: 34916
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 0x3f3f3f3f
#define LL long long
#define pi acos(-1.0)
#define db double
#define N 100005
using namespace std;
IL int gi()
{
	RG int res=0,w=1;
	RG char ch;
	for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
	if(ch=='-') w=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*w;
}
int n,head[N],edge[2*N][3],dis[N],num;
int h,t,q1[N*100],q2[N*100],flag;   //deque
IL void adde(RG int u,RG int v,RG int w) {
	edge[++num][0]=v,edge[num][1]=head[u],head[u]=num,edge[num][2]=w;
}
IL void build_map()
{
	for(RG int i=1;i<=n;++i) {
		adde(i,i%n+1,1);
		adde(i,10*(i-1)%n+1,0);
	}
}
IL void bfs()
{
	RG int pos;
	memset(dis,inf,sizeof(dis));
	dis[2]=0; h=t=1,flag=0,q2[1]=2;
	while(h<=t||flag) {
		pos=flag?q1[h]:q2[h];
		if(flag) {h--;if(!h) flag=0,h=1;}
		else h++;
		for(RG int i=head[pos];i;i=edge[i][1]) {
			if(dis[edge[i][0]]>dis[pos]+edge[i][2]) {
				dis[edge[i][0]]=dis[pos]+edge[i][2];
				if(dis[edge[i][0]]==dis[pos]) {
					if(flag) q1[++h]=edge[i][0];
					else if(h==1) flag=1,q1[1]=edge[i][0];
					else q2[--h]=edge[i][0];
				}
				else q2[++t]=edge[i][0];
			}
		}
	}
	printf("%d\n",dis[1]+1);	
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=gi();
	build_map();
	bfs();
	//fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"

using namespace std;

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

	long long* wa = new long long[100001];
	bool* q = new bool[100001];
	for (int i = 0; i <= 100000; i++)
	{
		wa[i] = 0;
		q[i] = false;
	}

	long long ans = 0;
	for (int i = 0; i < m; i++)
	{
		int a;
		string b;
		cin >> a >> b;
		if (q[a]) continue;
		else {
			if (b == "AC") {
				q[a] = true;
				ans++;
			}
			else if (b == "WA") {
				wa[a]++;
			}
		}
	}

	long long ans2 = 0;
	for (int i = 1; i <= n; i++)
	{
		if (q[i]) ans2 += wa[i];
	}

	cout << ans << " " << ans2 << endl;

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main(void){
  int K,A,B;
  int judge;
  cin >> K >> A >> B;

  if (K == 1){
    judge = A;
  } else {
    judge = (B/K) * K;
  }
  
  if(judge >= A) {
    cout << "OK" << endl;
  }else {
    cout << "NG" << endl;
  }

  return 0;
}




Measured memory_bytes: 3092
N,M=map(int,input().split())
light=[]
for _ in range(M):
    light.append(list(map(int,input().split())))
on_off=list(map(int,input().split()))
ans=0
for i in range(2**N):
    flag=True
    swi=[]
    for k in range(N):
        swi.append(i%2)
        i//=2

    for l_n in range(len(light)):
        cnt=0
        for j in range(light[l_n][0]):
            cnt+=swi[light[l_n][j+1]-1]
        if cnt%2!=on_off[l_n]:
            flag=False
    if flag:
        ans+=1    
print(ans)

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << setprecision(15);

    int xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;

    int N;
    cin >> N;

    vi x(N + 2);
    x[0] = xs;
    x[N + 1] = xt;

    vi y(N + 2);
    y[0] = ys;
    y[N + 1] = yt;

    vi r(N + 2);

    for (int i = 1; i <= N; i++) {
        cin >> x[i] >> y[i] >> r[i];
    }

    N += 2;

    vector<double> sp(N, DBL_MAX);
    sp[0] = 0;

    priority_queue<pair<double, int>> pq;
    pq.push({ 0, 0 });
    while (!pq.empty()) {
        double dist = -pq.top().first;
        int loc = pq.top().second;
        pq.pop();
        if (dist != sp[loc]) continue;

        for (int nbr = 0; nbr < N; nbr++) {
            double betw = sqrt((x[nbr] - x[loc]) * 1ll * (x[nbr] - x[loc])
                             + (y[nbr] - y[loc]) * 1ll * (y[nbr] - y[loc]))
                             - r[nbr] - r[loc];
            betw = max(betw, 0.);
            if (dist + betw < sp[nbr]) {
                sp[nbr] = dist + betw;
                pq.push({ -sp[nbr], nbr });
            }
        }
    }

    cout << sp.back() << endl;

    return 0;
}



Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){
    int n;cin>>n;
    int travel[n+1];
    bool used[n+1];
    fore(i,0,n){
        int val;cin>>val;
        travel[i] = val-1;
        used[i] = false; 
    }
    bool posible = true;
    int pos = 0;
    int steps = 0;
    used[pos] = true;
    while (posible && pos!=1){
        steps++;
        pos = travel[pos];
        if(used[pos]){
            posible = false;
        }
        used[pos] = true;
    }
    if(posible){
        cout<<steps;
    }else{
        cout<<"-1";
    }
	return 0;
}

Measured memory_bytes: 768
'''
 Author: fuad Ashraful Mehmet
 University of Asia Pacific
 created :09 Sep 2019 7.33 PM
 Category :   from At Coder

 Problem:https:  
'''

 
 

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


ans=sum(B)


for i in range(n-1):

	if A[i+1]==A[i]+1:
		ans+=C[A[i]-1]




print(ans)
#fuck python if you can its just owsam

Measured memory_bytes: 3064
S = input()

ret = 'WA'

if S[0] == 'A':
    if S[2:-1].count('C') == 1:
        n = S.find('C')
        S = list(S)
        S[n] = 'c'
        S = "".join(S)
        komoji = S[1:]
        s = S[1:].lower()

        if komoji == s:
            ret = 'AC'

print(ret)




Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 21;
const long long INF = 1000000000000000ll;

int T[maxN];

long long pref[maxN][2], suf[maxN][2], dp[maxN][3];

void solve()
{
	int n;
	scanf ("%d", &n);
	FOR(i, 1, n+1)
		scanf ("%d", T+i);
		
	FOR(i, 1, n+1)
	{
		pref[i][0] = pref[i-1][0];
		pref[i][1] = pref[i-1][1];
		pref[i][i&1] += T[i];	
		
		dbg("\n------");
		dbg(i); dbg(T[i]);
		dbg(pref[i][0]);
		dbg(pref[i][1]);
	}
	
	FORD(i, n, 0)
	{
		suf[i][0] = suf[i+1][0];
		suf[i][1] = suf[i+1][1];
		suf[i][i&1] += T[i];
		
		
		dbg("\n------");
		dbg(i); dbg(T[i]);
		dbg(suf[i][0]);
		dbg(suf[i][1]);
	}
	
	
	FOR(i, 0, n+1) FOR(s, 0, 3)
		dp[i][s] = -INF;
	dp[0][0] = 0, dp[1][0] = T[1];
	FOR(i, 2, n+1)
	{
		dp[i][0] = dp[i-2][0] + T[i];
		if (i != 2)
			dp[i][1] = T[i] + max(dp[i-2][1], dp[i-3][0]);
		if (i != 2)
			dp[i][2] = T[i] + max(dp[i-2][2], dp[i-3][1]);
	}
		
	long long res = -INF;
	
	if (n % 2 == 0)
		res = max({pref[n][0], pref[n][1], dp[n][1]});
		
	else
	{
		res = pref[n-1][0];	
		dbg(res);
		FOR(i, 2, n+1)
		{
			long long prop = pref[i-2][i&1] + suf[i+1][(i&1)^1];
			dbg(prop);
			res = max(res, prop);
		}
		res = max(res, dp[n][2]);		
	}
	
	printf("%lld\n", res);
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 15484
#include<iostream>

int main(){
	int a=1,b=1,i,n;

	for(i=1;i<=9;i++){
		for(n=1;n<=9;n++){
		std::cout<<a<<"x"<<b<<"="<<a*b<<std::endl;
		b=n+1;
			}
		a=i+1;
		b=1;
		}
	
	return 0;
	}

Measured memory_bytes: 1120
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n,k,m,x,ans=0;
        cin>>n>>k;
        vll v(n+1,0);
        rep(i,0,k-1)
        {
        	cin>>m;
        	rep(j,0,m-1){cin>>x; ++v[x];}
        }
        rep(i,1,n)if(v[i]==0)++ans;
        cout<<ans;


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

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

int H, W, A, B;

int main()
{
    cin >> H >> W >> A >> B;

    if(W / 2 < A || H  / 2 < B)
    {
        cout << "No" << endl;
        return 0;
    }

    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cout << (int)((i < B) ^ (j < A));
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

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

    int a = scan.nextInt();
    int[] getNum = new int[a];
    int count = 0; //素数の個数

    //標準入力を配列に格納
    for(int i = 0; i < getNum.length; i++) {
    getNum[i] = scan.nextInt();
    }
    for(int i = 0; i < getNum.length; i++) {
    if(isPrime(getNum[i]) == true) {
    	count++;
    }
    }
    System.out.println(count);
  }
    public static boolean isPrime(int num) {
  //素数の判別
    if(num < 2) {
    	return false;
    }
    else if(num == 2) {
    	return true;
    }
    else if(num % 2 == 0) {
    	return false;
    }

    double sqrtNum = Math.sqrt(num);
    for(int i = 3; i <= sqrtNum; i+= 2) {
    	if(num % i == 0) {
    		return false;
    	}
    }
    return true;
  }
}


Measured memory_bytes: 41776
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static void search(long X , List<Long> pow5s){
		for(int i = 0 ; i < pow5s.size() ; ++i){
			for(int j = 0 ; j < pow5s.size() ; ++j){
				long x = pow5s.get(i);
				long y = pow5s.get(j);
				if(x + y == X){
//					System.out.println(x+" "+y);
					long A = i % 2 == 0 ? i / 2 : - (i / 2);
					long B = j % 2 == 0 ? j / 2 : - (j / 2);
					System.out.println(A+" "+(- B));
					return ;
				}
			}
		}		
	}
	public static void main(String[] args) {
		List<Long> pow5s = new ArrayList<Long>();
		for(long a = 0 ; a <= 6000 ; ++a){
			long v = a * a * a * a * a;
			pow5s.add(v);
			pow5s.add(- v);			
		}
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		search(X, pow5s);
	}
}


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

using namespace std;

#define ll long long

int main (){

    int a,b;

    cin>>a>>b;
    
    if((a==1 && b==2) || (a==2 && b==1)) cout<<3<<endl;
    
    else  cout<<abs(a-b)<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
class SCC{//cmp(0 - kk-1) is scc's return. Same number is group. The number is no relatoin.
	public:
	int n;
	vvi G,rG;
	vector<bool>used;
	vi vs,cmp;
	SCC(int size){
		n=size;
		G=rG=vvi(n);
		used=vector<bool>(n);
		cmp=vi(n);
		vs=vi(0);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
		rG[t].pb(s);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		rep(i,rG[v].size())if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	void dfs(int v){
		used[v]=true;
		rep(i,G[v].size())if(!used[G[v][i]])dfs(G[v][i]);
		vs.pb(v);
	}
	int scc(){
		rep(i,n)used[i]=false;
		rep(v,n)if(!used[v])dfs(v);
		rep(i,n)used[i]=false;
		int kk=0;
		for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],kk++);
		return kk;  
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	SCC scc(n);
	while(m--){
		int a,b;
		cin>>a>>b;
		scc.add_edge(a,b);
	}
	cout<<(scc.scc()!=n)<<endl;	
}

Measured memory_bytes: 1240
from operator import itemgetter

N = int(input())

e = []
for _ in range(N):
    a, b = map(int, input().split())
    e.append((b - a, a, b))  # (間に合う最終着手時間、所要時間、締め切り)

e.sort(key=itemgetter(2))
# print(e)
bl = True
cur = 0
for t, a, b in e:
    if cur <= t:
        cur += a
    else:
        bl = False
        break
print('Yes' if bl else 'No')


Measured memory_bytes: 86104
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i>=b;i--)
#define fill(a,i) memset(a,i,sizeof a);


void solve()
{ 
  int n;cin>>n;
  if(n>=30)cout<<"Yes";
  else cout<<"No"<<endl;
}

signed main()
{ 
    boost
    int test=0,t;
    //cin >> t ;
    t=1;
    while(test++ <t){
    //cout<<"Case #"<<test<<": ";
    solve();}
  
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n;
    int h[100];
    cin >> n;
    rep(i, n)
    {
        cin >> h[i];
    }

    int cnt = 0;
    for (int i = 100; i > 0; i--)
    {

        for (int j = 0; j < n;)
        {

            int cnt2 = 0;
            if (h[j] == i)
            {
                for (int k = j; k < n; k++)
                {
                    h[k]--;
                    if (k == n - 1 && !cnt2)
                    {
                        cnt2 += 1;
                        j++;
                    }
                    else if (h[k + 1] == i)
                    {
                        // OK.
                    }
                    else
                    {
                        cnt2 += 1;
                        j = k + 1;
                        break;
                    }
                }
            }
            else
            {
                j++;
            }
            // cout << i << "," << j << "," << cnt2 << endl;
            // while (1)
            // ;
            cnt += cnt2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int x, n;
  map<int, bool> mp;
  int d = INF;
  int ans = 0;
  cin >> x >> n;
  rep(i, n){
    int a;
    cin >> a;
    mp[a] = true;
  }
  //sort(p, p+n);
  for(int i = 101; i > -100; i--){
    if(mp.count(i)){
      continue;
    }
    if(abs(x - i) <= d){
      ans = i;
      d = abs(x - i);
    }
  }
  cout << ans <<endl;
}
    

Measured memory_bytes: 3636
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b, c := nextInt(), nextInt(), nextInt()
	ok := true
	if d := c - (a + b); d <= 0 {
		ok = false
	} else {
		ok = 4*a*b < d*d
	}
	if ok {
		puts("Yes")
	} else {
		puts("No")
	}
}

func sqrt(a int) float64 {
	return math.Sqrt(float64(a))
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    H,W = LMIIS()
    C = []
    for i in range(10):
        C.append(LMIIS())
    A = []
    for i in range(H):
        A.append(LMIIS())
    
    from copy import deepcopy
    for m in range(10):
        for f in range(10):
            for t in range(10):
                C[f][t] = min(C[f][t], C[f][m] + C[m][t])


    
    ans = 0
    for line in A:
        for a in line:
            if abs(a) != 1:
                ans += C[a][1]
    print(ans)


    
main()

Measured memory_bytes: 41436
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

constexpr ll mod = 1e9 + 7;
ll fact[400010], fact_inv[400010];
ll power(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
ll comb(ll n, ll r) {
	return fact[n] * fact_inv[r] % mod * fact_inv[n - r] % mod;
}

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

	fact[0] = 1;
	for (int i = 1; i <= 400000; i++)
		fact[i] = fact[i - 1] * i % mod;
	fact_inv[400000] = power(fact[400000], mod - 2);
	for (int i = 400000 - 1; 0 <= i; i--)
		fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod;
	
	ll r = 0;
	for (int i = 0; i < min(n, k + 1); i++) {
		//N = n - i, R = i  comb(N+R-1, R)=comb(n-1, i)
		r += comb(n, i) * comb(n - 1, i) % mod;
		r %= mod;
	}
	printf("%lld\n", r);
}

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

int main(void){
   int K;
   cin>>K;
   vector<int> A(K);
   A[0]=7%K;
   if(A[0]==0){
      cout<<1<<endl;
      return 0;
   }
   for(int i=1;i<K;i++){
      A[i]=(10*A[i-1]+7)%K;
      if(A[i]%K==0){
         cout<<i+1<<endl;
         return 0;
      }
   }
   cout<<-1<<endl;
   return 0;
}


Measured memory_bytes: 7112
#include<bits/stdc++.h>
using namespace std;
//void dfs(unordered_map<int,unordered_set<int>>&m,int st)
 int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    
    string s,t;
    cin>>s;
    cin>>t;

    int ans=t.size();

    for(int i=0;i<s.size()-t.size()+1;i++)
    {
        int aa=0;
        for(int j=0;j<t.size();j++)
        {
            if(s[i+j]!=t[j])
                aa+=1;
        }
        if(aa<ans)
            ans=aa;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> S;
vector<int> C;
bool f(string s0, string s1, string s2) {
	if (s0.empty()) s0 = s2; else { s1 = s2; reverse(s1.begin(), s1.end()); }
	auto x = min(s0.length(), s1.length());
	return s0.substr(0, x) == s1.substr(0, x);
}
pair<string,string> g(string s0, string s1, string s2) {
	if (s0.empty()) s0 = s2; else { s1 = s2; reverse(s1.begin(), s1.end()); }
	auto x = min(s0.length(), s1.length());
	s0 = s0.substr(x);
	s1 = s1.substr(x);
	auto s = s1;
	reverse(s.begin(), s.end());
	s = s0 + s;
	auto t = s;
	reverse(s.begin(), s.end());
	if (s == t) return {"", ""};
	return {s0, s1};
}
int main() {
	int N;
	cin >> N;
	S.resize(N);
	C.resize(N);
	for (int i = 0; i < N; ++ i) {
		cin >> S[i] >> C[i];
	}
	map<pair<string,string>, ll> dist;
	priority_queue<pair<ll,pair<string,string>>> Q;
	for (int i = 0; i < N; ++ i) {
		auto d = C[i];
		auto t = S[i];
		reverse(t.begin(), t.end());
		{
			pair<string,string> p = {S[i],""};
			if (!dist.count(p) || d < dist[p]) {
				dist[p] = d;
				Q.push({(ll)-d, p});
			}
		}
		{
			pair<string,string> p = {"",t};
			if (!dist.count(p) || d < dist[p]) {
				dist[p] = d;
				Q.push({(ll)-d, p});
			}
		}
		if (S[i] == t) {
			pair<string,string> p = {"",""};
			if (!dist.count(p) || d < dist[p]) {
				dist[p] = d;
				Q.push({(ll)-d, p});
			}
		}
	}
	while (!Q.empty()) {
		auto d0 = -Q.top().first;
		auto s0 = Q.top().second.first;
		auto s1 = Q.top().second.second;
		Q.pop();
		if (dist[{s0,s1}] != d0) continue;
		if (s0 == "" && s1 == "") {
			cout << d0 << endl;
			return 0;
		} else {
			for (int i = 0; i < N; ++ i) {
				if (f(s0, s1, S[i])) {
					auto p = g(s0, s1, S[i]);
					auto d = d0 + C[i];
					if (!dist.count(p) || d < dist[p]) {
						dist[p] = d;
						Q.push({(ll)-d, p});
					}
				}
			}
		}
	}
	cout << -1 << endl;
}


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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'i' || c == 'u'|| c == 'e' || c == 'o')
    cout << "vowel" << endl;
  
  else
    cout << "consonant" << endl;
}

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

using namespace std;

int main(void){
	string s;
	int length=0,max=0;
	map<string,int> sen;
	vector<string> w;
	while(cin >>s){
		w.push_back(s);
		if(sen.find(s)!=sen.end()){
			sen[s]++;
		}else{
			sen.insert( pair<string, int>(s,1));
		}
	}
	map<string,int>::iterator p;
	for(p = sen.begin() ; p !=sen.end() ; p++){
		if( max < p->second) max = p->second;
	}
	for(p = sen.begin() ; p !=sen.end() ; p++){
		if( max == p->second){
			cout << p->first << " ";
			break;
		}
	}
	for(int i=0 ; i<w.size() ; i++){
		if( length < w[i].size() ) length = w[i].size();
	}
	for(int i=0 ; i<w.size() ; i++){
		if( length==w[i].size() ){
			cout << w[i] << endl;
			break;
		}
	}
    return 0;
}



Measured memory_bytes: 3204
//Volume0-0065
import java.util.*;

class Cnt {
	public int     cnt = 1;
	public boolean both;
}

public class Main {

	public static void main(String[] args) {

		//declare
		TreeMap<Integer,Cnt> map = new TreeMap<Integer,Cnt>();
		Cnt     e;
		String  s;
		int     num;
		boolean flg = false;

		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			if((s = sc.nextLine()).equals("")){
				flg = true;
				continue;
			}
			num = Integer.parseInt(s.split(",")[0]);
			
			//calculate
			if(map.containsKey(num)){
				e = map.get(num);
				e.cnt++;
				if(flg){e.both = flg;}
			} else if (!flg){
				map.put(num,new Cnt());
			}
		}

		//output
		Iterator<Map.Entry<Integer, Cnt>> I;
		I = map.entrySet().iterator();
		while(I.hasNext()){
			Map.Entry<Integer, Cnt> m = (Map.Entry<Integer, Cnt>)I.next();
			if(m.getValue().both){
				System.out.println(m.getKey()+" "+m.getValue().cnt);
			}
		}
	}
}

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

int w, h;
int sx, sy;
int gx, gy;
int t[102][102];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

bool dfs(int x, int y){
  if(x == gx && y == gy){
    return true;
  }

  char c = t[y][x];
  t[y][x] = 0;

  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
    if(t[ny][nx] != c) continue;
    if(dfs(nx, ny)) return true;
  }

  return false;
}

void solve(){
  if(t[sy][sx] == 0){
    cout << "NG" << endl;
    return;
  }
  cout << (dfs(sx, sy) ? "OK" : "NG") << endl;
}

int main(){
  while(cin >> w >> h, w || h){
    cin >> sx >> sy; sx--; sy--;
    cin >> gx >> gy; gx--; gy--;

    int n;
    cin >> n;

    memset(t, 0, sizeof(t));

    for(int i = 0; i < n; i++){
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x--;
      y--;

      if(d == 0){ //脱即捉
        for(int i = y; i < y + 2; i++){
          for(int j = x; j < x + 4; j++){
            t[i][j] = c;
          }
        }
      }
      else{ //巽存側
        for(int i = y; i < y + 4; i++){
          for(int j = x; j < x + 2; j++){
            t[i][j] = c;
          }
        }
      }
    }

    solve();
  }
}

Measured memory_bytes: 1200
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
int n;
int r[200005];

int main() {
    cin>>n;
    rep(i,n) cin>>r[i];
    int maxi = -10e9-10;
    int mini = r[0];
    rep(i,n) {
        if(!i) continue;
        maxi = max(maxi,r[i]-mini);
        mini = min(mini,r[i]);
    }
    cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 1940
X, Y = [int(_) for _ in input().split()]

p = 10 ** 9 + 7
N = 670000

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((p - inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
def combination(n, r, p):
    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def solve(X, Y):
    if (X + Y) % 3 != 0:
        return 0
    Z = (X + Y) // 3
    x = (Z + X - Y) // 2
    return combination(Z, x, p)

print(solve(X, Y))


Measured memory_bytes: 88644
fun main() {
  val MOD = 998244353
  val (N, K) = readInts()
  val LR = (1..K).map { readInts() }

  val dp = Array(N) { 0 }
  dp[0] = 1
  val ds = Array(N) { 0 }
  ds[0] = 1

  fun getRangeSum(l: Int, r: Int): Int {
    val L = if (l < 1) 0 else ds[l - 1]
    val R = if (r < 0) 0 else ds[r]
    return if (R >= L) R - L else R - L + MOD
  }

  for (i in 1 until N) {
    var sum = 0
    LR.forEach { (l, r) ->
      sum = (sum + getRangeSum(i - r, i - l)) % MOD
    }
    dp[i] = sum
    ds[i] = (ds[i - 1] + sum) % MOD
  }
  println(dp.last())
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 63844
import sys; readline = sys.stdin.readline

N = int(readline())
XL = [list(map(int, readline().split())) for i in range(N)]
XL.sort()
X, L = zip(*XL)

rm = -10000000
dropc = 0
for i in range(N):
    if X[i] - L[i] < rm:
        if rm > X[i] + L[i]:
            rm = X[i] + L[i]
        dropc += 1
    else:
        rm = X[i] + L[i]

print(N - dropc)


Measured memory_bytes: 68924
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
const double EPS = 1e-8;
typedef complex<double> P;
typedef vector<P> VP;
double cross(P a, P b){
    return (conj(a)*b).imag();
}
int lccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    return 0;
}

int main(){
    int n;
    cin >> n;
    VP v(n);
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        v[i] = P(x,y);
    }

    bool ans = true;
    for(int r=0; r<2; r++){
        for(int i=2; i<n-1; i++){
            bool s1 = false;
            for(int j=0; j<i; j++){
                bool s2 = true;
                int comp = lccw(v[i], v[j], v[i+1]);
                for(int k=0; k<i; k++){
                    if(k != j && comp == lccw(v[i], v[j], v[k])){
                        s2 = false;
                        break;
                    }
                }
                if(s2){ s1 = true; break; }
            }
            if(!s1){ ans = false; break; }
        }
        reverse(v.begin(), v.end());
    }
    if(ans) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}



Measured memory_bytes: 3124
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	int N;
	cin >> N;
	vector<tuple<int, int, int>> vec(N);
	for (int i = 0; i < N - 1; ++i) {
		int c, s, f;
		cin >> c >> s >> f;
		vec[i] = make_tuple(c, s, f);
	}

	for (int i = 0; i < N; ++i) {
		int nowTime = 0;
		for (int j = i; j < N - 1; ++j) {
			int c = get<0>(vec[j]), s = get<1>(vec[j]), f = get<2>(vec[j]);

			while (nowTime < s || nowTime % f != 0)++nowTime;

			nowTime += c;
		}
		cout << nowTime << endl;
	}

	return 0;
}

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

typedef long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	ll a, b;
	cin >> a >> b;

	ll x = a + b;
	ll y = a * b;
	ll z = a - b;

	x = max(x, y);
	z = max(x, z);
	// cerr << a << ", " << b << endl;

	cout << z << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    while(cin>>a>>b>>c>>k)
    {
        vector<int>v;
        v.push_back(a);v.push_back(b);v.push_back(c);
        sort(v.begin(),v.end(),greater<int>());
        while(k--)
        {
            v[0]*=2;
        }
        cout<<v[0]+v[1]+v[2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    string s; cin >> s;
    int A[123] = {};

    if(s[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    int cnt_c = 0;
    rep(i, s.size()){
        if(i >=2 and i < s.size()-1){
            if(s[i] == 'C') cnt_c++;
        }
        A[int(s[i])]++;
    }
    int sum = 0;
    repr(i, 97, 123){
        sum+=A[i];
    }

    if(sum == s.size()-2 and cnt_c == 1){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }

    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define inf 1<<29
using namespace std;

struct edge{ int to,cap,rev; };

int V,E;
int X,Y;
vector<edge> G[1002];
bool used[1002];

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

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    fill(used,used+1002,0);
    int f=dfs(s,t,inf);
    if(f==0)return flow;
    flow+=f;
  }
}

int gcd(int a,int b){
  if(a%b==0)return b;
  return gcd(b,a%b);
} 

int main()
{
  int m,n;
  int b[500],r[500];
  while(1){
    cin>>m>>n;
    if(m+n==0)break;
    for(int i=0;i<1002;i++)G[i].clear();
    int s=m+n,t=s+1;
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>r[i];
    
    for(int i=0;i<m;i++){
      add_edge(s,i,1);
    }
    for(int i=0;i<n;i++){
      add_edge(m+i,t,1);
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	if(gcd(b[i],r[j])!=1){
	  add_edge(i,m+j,1);
	}
      }
    }
    cout<<max_flow(s,t)<<endl;
  }
  return 0;
}

Measured memory_bytes: 7708
#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];

    int m = 0;
    vector<int> b(n, 0);
    for (int i = n; i >= 1; i--) {
        int sum = 0;
        for (int j = i * 2; j <= n; j += i) sum += b[j-1];
        if ((sum + 1) % 2 == a[i-1]) {b[i-1] = 1; m++;}
    }
    
    cout << m << endl;
    for (int i = 1; i <= n; i++) {
        if (b[i-1]) cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        d: [[usize; 2]; n],
    }

    for i in 0..n-2 {
        if d[i][0]==d[i][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1] {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 2172
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype>  // isupper, islower, isdigit, toupper, tolower
#include <cmath>   // abs, sin, cos, tan
#include <ctime>   // clock

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q.r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<str> vs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
    while(1)
    {
        ll a, b; cin >> a >> b;
        if(a == b && a == 0) return;
        ll flag = 0;
        for(ll i = 1;i <= a;i++)
        {
            for(ll j = i + 1;j <= a;j++)
            {
                ll tmp = i + j;
                if(b - tmp > j&&b - tmp <= a) flag++;
            }
        }
        cout << flag << endl;
    }
}

//前処理
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20); //高精度少数表示
    Main();
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vector<P> before;
    vector<P> after;
    int n = 0;
    rep(i, h) rep(j, w) {
        if (j==w-1) {
            if (i==h-1) continue;
            if (a[i][j]%2==1) {
                a[i][j]--;
                a[i+1][j]++;
                before.emplace_back(i, j);
                after.emplace_back(i+1, j);
            }
        }
        else {
            if (a[i][j]%2==1) {
                a[i][j]--;
                a[i][j+1]++;
                before.emplace_back(i, j);
                after.emplace_back(i, j+1);
            }
        }
    }
    n = before.size();
    cout << n << endl;
    rep(i, n) {
        cout << before[i].first+1 << " " << before[i].second+1 << " " << after[i].first+1 << " " << after[i].second+1 << endl;
    }
    
    return 0;
}


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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int mx = max(a, max(b, c));
    int sum = a + b + c - mx;
    for (int i = 0; i < k; i++) {
		mx *= 2;
	}
	sum += mx;
	cout << sum;
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  const int amax = a[n - 1];
  vector<int> cnt(amax + 1, 0);
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= amax; j += a[i]) {
      cnt[j]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[a[i]] == 1) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7912
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = map {$_ - 0} split(/\s+/o,<STDIN>);

my $prev = 0;
my $acost = 0;
for(my $i=0;$i<$n;$i++){
  $acost += abs($prev - $a[$i]);
  $prev = $a[$i];
}
$acost += abs($prev);

for(my $i=0;$i<$n;$i++){
  my $dif = 0;
  if( $i==0 ){
    $dif = -( abs($a[0]) + abs($a[0]-$a[1]) ) + abs($a[1]);
  } elsif( $i==$n-1 ){
    $dif = -( abs($a[$i-1]-$a[$i]) + abs($a[$i]) ) + abs($a[$i-1]);
  } else {
    $dif = -( abs($a[$i-1]-$a[$i]) + abs($a[$i]-$a[$i+1]) ) + abs($a[$i-1]-$a[$i+1]);
  }
  my $r = $acost + $dif;
  print "$r\n";
}

exit(0);


Measured memory_bytes: 21068
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

ll N;
vll A(300000, -1*INF);
vll dp(300000, -1*INF); //dp.at(i)は最初からi桁目まで
vvll dp2(300000, vll(2, -1*INF));

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  //偶数桁まで
  dp2.at(2).at(0) = A.at(0);
  dp2.at(2).at(1) = A.at(1);
  for(int i = 2; i < N; i+=2){
    dp2.at(i+2).at(0) = dp2.at(i).at(0) + A.at(i);
    dp2.at(i+2).at(1) = max(dp2.at(i).at(0) + A.at(i+1), dp2.at(i).at(1) + A.at(i+1));
  }
  for(int i = 2; i <= N; i+=2){
    dp.at(i) = max(dp2.at(i).at(0), dp2.at(i).at(1));
  }
  
  dp.at(1) = 0;
  dp.at(3) = max(A.at(0), max(A.at(1), A.at(2)));
  for(int i = 3; i <= N; i+=2){
    dp.at(i+2) = max(dp.at(i+1), dp.at(i) + A.at(i+1));
  }
  cout << dp.at(N) << endl;
}

Measured memory_bytes: 24188
import java.util.Scanner;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		int n = 0;
		char[][] c = new char[h][w];
		for(int i = 0; i < h; i++) {
				c[i]= sc.next().toCharArray();
		}

		int a = 0;
		int ans = 0;
		for(int l = 0; l < Math.pow(2, h+w); l++) {
			int black = 0;
			String ni = "00000000000" + Integer.toBinaryString(a);
			//System.out.println(ni+ " " + ni.charAt(ni.length()-1));
			for(int i = 0; i  < h; i++) {
				for(int j = h; j < h+w; j++) {
					//System.out.println(ni.charAt(i) + ni.charAt(j));
					if(ni.charAt(ni.length()-1-i) == '0' && ni.charAt(ni.length()-1-j) == '0') {		
						if(c[i][j-h]== '#') {
							++black;
						}
					}
				}
			}
			if(black == k) {
				//System.out.println(black);
				++ans;
				//System.out.println(ni);
			}
			++a;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 30600
#include<stdio.h>

int main(){

  int i;
  int n;

  while(scanf("%d", &n), n!=0){
    
    i=0;
    while(n!=1){
      i++;
      if(n%2==0)
	n=n/2;
      else
	n=n*3+1;
    }
    printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n;
    char change[256] = {(char)0},a,b,c;
    int m;
    
    
    while(1){
        cin >> n;
        
        if(!n) return 0;
        
        rep(i,0,256){
            change[i] = (char)0;
        }
        
        rep(i,0,n){
            cin >> a >> b;
            change[(int)a] = b;
        }
        
        cin >> m;
        
        rep(i,0,m){
            cin >> c;
            if(change[c] != (char)0){
                cout << change[c];
            }
            else{
                cout << c;
            }
        }
        
        cout << endl;
        
    }
    
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){ 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

int main() {
    string s;
    cin >> s;
    string h, t;
    h = s.substr(0, s.size() / 2);
    t = s.substr((s.size() + 1) / 2);
    string r = s, rh = h, rt = t;
    reverse(r);
    reverse(rh);
    reverse(rt);
    cout << (s == r && h == rh && t == rt ? "Yes" : "No") << LN;
}


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

a = sorted(a)
ans = []
for i in range(n-1):
  if i ==0:
    ans.append((a[i]+a[i+1])/2)
  else:
    ans.append((ans[i-1]+a[i+1])/2)
print(ans[n-2])


Measured memory_bytes: 61880