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

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<Integer> A = new ArrayList<>();
        List<Integer> B = new ArrayList<>();
        int t = 0;
        while(true){
            A.add(sc.nextInt());
            B.add(sc.nextInt());
            if(A.get(A.size()-1) == 0) break;
            if(B.get(A.size()-1) == 0) break;
            t++;
        }
        for(int n=0;n<t;n++){
            for(int i=0; i < A.get(n); i++){
                for(int j=0; j < B.get(n); j++){
                    if(i==0 || i==A.get(n)-1) System.out.print("#");
                    else if(j==0) System.out.print("#");
                    else if(j==B.get(n)-1) System.out.print("#");
                    else{
                        System.out.print(".");
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
        sc.close();
    }
}


Measured memory_bytes: 36588
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int k;

const int INF = 10000000;
int dist[100000+10];

struct K {
  int v, c;
};
bool operator>(const K& k1, const K& k2) {
  return k1.c > k2.c;
}

int go(void) {
  REP(i, 100000+10) {
    dist[i] = INF;
  }
  priority_queue<K, vector<K>, greater<K> > q;
  q.push((K){1, 1});
  dist[1] = 1;
  while(!q.empty()) {
    K cur = q.top(); q.pop();
    if(dist[cur.v] < cur.c) {
      continue;
    }
    if(cur.v == 0) {
      break;
    }
    REP(i, 2) {
      K next = {(cur.v*10+i)%k, cur.c + i};
      if(next.c < dist[next.v]) {
        q.push(next);
        dist[next.v] = next.c;
      }
    }
  }
  return dist[0];
}

int main(void) {
  while(~scanf("%d", &k)) {
    int res = go();
    printf("%d\n", res);
  }
  return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
long long A[1000000],cums[1000000];
map <long long ,long long > a;
vector <long long> v;
long long M=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n,i,j,k,x,y,z;
    cin>>n;
    x=0;
    for (i=0;i<n;i++)
    {
    	cin>>A[i];
    	x=(x+A[i])%M;
	}
	cums[n-1]=A[n-1];
	for (i=(n-2);i>=0;i--)
	{
		cums[i]=(cums[i+1]+A[i])%M;
	}
	z=0;
	for (i=0;i<n;i++)
	{
		z=(z+(cums[i+1]*A[i])%M)%M;
	}
	cout<<z<<endl;
}

Measured memory_bytes: 6744
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, x;
		while (true) {
			n = sc.nextInt();
			x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j; k <= n; k++) {
						if (x == i + j + k && i != j && i != k && j != k) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 26348
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
bool ok[maxn],tmp[maxn];
string ss;
int n;
bool check(int left,int end)
{
	memset(ok,0,sizeof(ok));
	ok[left]=true;
	for(int i=left+1;i<=end;i++)
		if((ok[i-1]||ok[i-2])&&ss[i]=='.')
			ok[i]=true;
	return ok[end];
}
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
	ios::sync_with_stdio(0);
//  fl();
	int a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	cin>>ss;
	ss='#'+ss;
	if(c<d)
	{
		if(!check(b,d))
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(!check(a,c))
		{
			cout<<"No"<<endl;
			return 0;
		}
		cout<<"Yes"<<endl;
		return 0;
	}
	else
	{
		if(!check(b,d))
		{
			cout<<"No"<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
			tmp[i]=ok[i];
		for(int i=b;i<=d;i++)
			if(tmp[i])
				if(ss[i-1]=='.'&&ss[i+1]=='.'&&check(i,d))
				{
					cout<<"Yes"<<endl;
					return 0;
				}
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

/*
まず状態を愚直に持つことを考える
例えば oxooxoxooxo (oが未使用, xが使用済み)
          ^
          |
このとき最後に使ったのが5番目だったとすると
s[i]が'>'なら次に使える数は3つあるとわかるし、'<'なら4つとわかる

そこで (最後に使ったやつの前に何個数が余っているか, 後ろに何個余っているか) だけを覚えておくことにするとこれで情報としては十分とわかる

ただ遷移を高速にするために (i個使った, 最後に使ったやつの前or後ろに何個余っているか) を覚えておくことになる
*/

const ll MOD = 1e9 + 7;

vector<ll> sumup(const vector<ll>& a) {
  int N = a.size();
  vector<ll> res(N + 1, 0);
  for (int i = 0; i < N; i++) res[i + 1] = (res[i] + a[i]) % MOD;
  return res;
}

int main() {
  int N;
  string s;
  while (cin >> N >> s) {
    s = "<" + s;
    vector<ll> dp(N + 1, 0);
    dp[N] = 1;
    for (int i = 0; i < N; i++) {
      auto sum = sumup(dp);
      vector<ll> ndp(N + 1, 0);
      int rem = N - i;
      for (int r = 0; r < rem; r++) {
        if (s[i] == '<') {
          ndp[r] = (sum[rem + 1] - sum[r + 1] + MOD) % MOD;
        } else {
          ndp[r] = sum[r + 1];
        }
      }
      dp = ndp;
    }
    cout << dp[0] << endl;
  }
  return 0;
}


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

using namespace std;

int memo[3123][3123],N,T;

vector <pair <int,int> > vet;

int Ray(int pos, int tempo){
	if (pos == N)
		return 0;
	if (tempo >= T)
		return 0;
	if (memo[pos][tempo] != -1)
		return memo[pos][tempo];

	return memo[pos][tempo]=max(Ray(pos+1,tempo),Ray(pos+1,tempo+vet[pos].first)+vet[pos].second);
}
int main() {
	int aux1,aux2;
	scanf("%d%d", &N, &T);
	memset(memo, -1, sizeof(memo));
	for (int i = 0;i < N;i++) {
		scanf("%d%d", &aux1,&aux2);
		vet.push_back(make_pair(aux1,aux2));
	}
  sort(vet.begin(), vet.end());

	printf("%d\n",Ray(0,0));

	return 0;
}


Measured memory_bytes: 38528
#include<stdio.h>

typedef struct{
  char a[100];
  int b;
}Record;

Record dequeue(void);
void queue(Record a);

int head=0 ,tail=0;
Record Z[1000000],q;

int main(){
  int z,time,count=0,i=0;
  scanf("%d %d",&z,&time);
  for(i=0;i<z;i++){
    scanf("%s%d",Z[i].a,&Z[i].b);
  }
  tail=z;
  i=0;
  while(i<z){
    q=dequeue();
    if(q.b-time>0){
      q.b=q.b-time;
      queue(q);
      count+=time;
    }
    else {
      count+=q.b;
      printf("%s %d\n",q.a,count);
      i++;
    }
  }
}
Record dequeue(void){
  head++;
  return Z[head-1];
  
}
void queue(Record a){
  Z[tail]=a;
  tail++;
  
}

  



Measured memory_bytes: 21848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		String str = br.readLine();

		int num = Integer.parseInt(str);

		calc(num);
	}

	public static void calc(int x){
		System.out.println(x*x*x);
	}
}

Measured memory_bytes: 24168
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define vi vector<int>
#define LLMAX 4000000000000000000LL
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
struct edge
{
	int t, f, w;
	bool operator < (const edge& e) const
	{
		return w > e.w;
	}
	edge(int from, int to, int weight)
	{
		t = to;
		f = from;
		w = weight;
	}
};
#define ii pair<int,int>
#define MOD 1000000007
const double EPS = (1e-5);
long long binpow(long long a, long long b){long long res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
int findXOR(int n){switch (n % 4){case 0:return n;case 1:return 1;case 2:return n + 1;case 3:return 0;}}
int rangeXOR(int l, int r){return (findXOR(l - 1) ^ findXOR(r));}
int getbit(int mask, int bit){return (mask & (1 << bit));}void setbit(int& mask, int bit, int val){if (val)mask |= (1 << bit);else mask &= ~(1 << bit);}
//ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
//ll lcm(ll a, ll b){return a * (b / gcd(a, b));}
const int N = 1e5+10;
const int M = 1e6+3;
const ll INF = 1e9;
int h[N];
int dp[N][3];
tuple<int,int,int> ar[N];
void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		ar[i] = make_tuple(a, b, c);
	}
	dp[0][0] = get<0>(ar[0]);
	dp[0][1] = get<1>(ar[0]);
	dp[0][2] = get<2>(ar[0]);
	for (int i = 1; i < n; ++i)
	{
		dp[i][0] = get<0>(ar[i]) + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = get<1>(ar[i]) + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = get<2>(ar[i]) + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}
int main(void)
{
	//freopen("commandos.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tc = 1;
	//cin >> tc;
	//scanf("%d", &tc);
	while (tc--)
	{
		solve();
	}
}

Measured memory_bytes: 2560
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int N,D,i,j,k,l,m=0;
    int X[20][20];
    double a;
    cin>>N>>D;
    for(i=0;i<N;i++)
    {
        for(j=0;j<D;j++)
        {
            cin>>X[i][j];
        }
    }
    for(i=0;i<N;i++)
    {
        for(k=0;k<N;k++)
        {
            a=0.0;
            if(k==i)
            {
                break;
            }
            for(j=0;j<D;j++)
            {
                a=a+((X[i][j]-X[k][j])*(X[i][j]-X[k][j]));
            }
            a=sqrt(a);
            l=(int)a;
            if(a==l)
            {
                m=m+1;
            }
        }
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>
#include<unordered_map>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
#define mod  998244353
const int N = 1e6 + 5;
const int M = 1e6 + 5;
double x[10],y[10];
int main(){
    int n;
    double sum = 0;
    cin>>n;
    for(int i =  1;i <= n;++i) cin>>x[i]>>y[i];
    int a[] = {0,1,2,3,4,5,6,7,8,9};
    int num = 0;
    do{
        num ++;
        for(int i = 2;i <= n;++i){
            sum += sqrt((x[a[i]] - x[a[i - 1]])*(x[a[i]] - x[a[i - 1]]) + (y[a[i]] - y[a[i - 1]]) *(y[a[i]] - y[a[i - 1]]));
        }
    }while(next_permutation(a + 1,a + n + 1));
    printf("%.10lf",sum / num);
}


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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

using namespace std;

const int MOD = 1000000007;

void init();
void treeDP(int v);

int n, k;
vector<vector<int>> g;
vector<int> vval, vcnt;

int main()
{
	init();

	treeDP(0);

	long long ans = 1;
	REP(i, n)
		ans = ans * vval[i] % MOD;

	cout << ans << endl;
}

void init()
{
	cin >> n >> k;
	g.resize(n);

	REP(_i, n - 1)
	{
		int a, b; cin >> a >> b; --a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vval.resize(n, -1);
	vcnt.resize(n, 0);
}

void treeDP(int v)
{
	int c = k;
	int fixed = 0;
	for (int u : g[v])
		if (vval[u] != -1)
		{
			c -= vcnt[u];
			++fixed;
		}

	vval[v] = max(0, c);
	vcnt[v] = 1 + fixed;

	for (int u : g[v])
		if (vval[u] == -1)
		{
			treeDP(u);
			++vcnt[v];
		}
}

//// done E in 50mins on 30th Sep, 2019 ////


Measured memory_bytes: 8832
package main

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

func main() {
	x := nextLine()
	y := nextLine()

	if x == y[:len(x)] && len(x) + 1 == len(y) {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

Measured memory_bytes: 1756
#include <iostream>
using namespace std;
const int MAX = 71;

char judge(char c){
    if('0' <= c && c <= '9') return c;
    return '#';
}

string strMax(string x,string y){
    string tx = "",ty = "";
    bool flg = false;
    
    if(x == "#" && y == "#") return "#";
    if(x == "#") return y;
    if(y == "#") return x;
    
    for(int i = 0 ; i < x.size() ; i++){
        if(x[i] == '0' && !flg){
            continue;
        }
        else{
            flg = true;
            tx += x[i];
        }
    }
    x = tx;
    flg = false;
    for(int i = 0 ; i < y.size() ; i++){
        if(y[i] == '0' && !flg){
            continue;
        }
        else{
            flg = true;
            ty += y[i];
        }
    }
    y = ty;
    
    if(x.size() > y.size()) return x;
    else if(x.size() < y.size()) return y;
    
    for(int i = 0 ; i < x.size() ; i++){
        if(x[i] > y[i]) return x;
        else if(x[i] < y[i]) return y;
    }
    return x;
}

int main(){
    int H,W;
    string str[MAX];
    
    while(cin >> H >> W , H + W){
        string dp[MAX][MAX];
        for(int i = 0 ; i < W ; i++){
            cin >> str[i];
        }
        dp[0][0] = judge(str[0][0]);
        
        for(int i = 1 ; i < W ; i++){
            if(judge(str[i][0]) == '#'){
                dp[i][0] = "#";
            }
            else if(dp[i-1][0] != "#"){
                dp[i][0] = dp[i-1][0];
                dp[i][0] += judge(str[i][0]);
            }
            else{
                dp[i][0] += judge(str[i][0]);
            }
        }
        
        for(int j = 1 ; j < H ; j++){
            if(judge(str[0][j]) == '#'){
                dp[0][j] = "#";
            }
            else if(dp[0][j-1] != "#"){
                dp[0][j] = dp[0][j-1];
                dp[0][j] += judge(str[0][j]);
            }
            else{
                dp[0][j] += judge(str[0][j]);
            }
        }
        
        string ans = "0";
        for(int i = 1 ; i < W ; i++){
            for(int j = 1 ; j < H ; j++){
                if(judge(str[i][j]) == '#') dp[i][j] = '#';
                else{
                    dp[i][j] = strMax(dp[i-1][j],dp[i][j-1]);
                    if(dp[i][j] != "#"){
                        dp[i][j] += judge(str[i][j]);
                    }
                    else{
                        dp[i][j] = "";
                        dp[i][j] += judge(str[i][j]);
                    }
                }
            }
        }
        for(int i = 0 ; i < W ; i++)
            for(int j = 0 ; j < H ; j++)
                ans = strMax(ans,dp[i][j]);
        
        cout << ans << endl;
    }
    
    return 0;
}

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

using namespace std;

int main() {
  int l, r, d;
  
  cin >> l >> r >> d;
  
  int count = 0;
  
  for (int i = l; i <= r; i++) {
    if (i % d == 0) {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3620
N, H = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

A, B = [], []
for a, b in AB:
  A.append(a)
  B.append(b)

maxA = max(A)
B_stack = []
for b in B:
  if b > maxA:
    B_stack.append(b)
B_stack.sort()
B_stack = B_stack[::-1]

answer = 0
for b in B_stack:
  H -= b
  answer += 1
  if H <= 0:
    print(answer)
    exit()

answer += -(-H // maxA)
print(answer)

Measured memory_bytes: 70872
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
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 rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int n, m;
bool can = false;
vvi g;

void dfs(int now, int step) {
    if(now == n-1) can = true;
    if(step == 2) return;

    for(int next : g[now]) {
        dfs(next, step + 1);
    }
    return;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
    }

    dfs(0, 0);

    if(can) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}


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

string S;
int K;
set<string> T;

int main() {
  cin >> S >> K;
  for(int i = 0; i < (int)S.size(); ++i) {
    for(int j = 1; i + j <= (int)S.size() && j <= K; ++j) {
      T.insert(S.substr(i, j));
    }
  }
  auto it = T.begin(); advance(it, K - 1);
  cout << *it << endl;
  return 0;
}


Measured memory_bytes: 1664
#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};

int main() {
	string s; cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n / 2; ++i) {
		if(s[i] != s[n - 1 - i]) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
5 10 1
*/

#include <iostream>

using namespace std;

int main(){

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

	int v;
	if(b > a+W){
		v = b - (a + W);
	}else if(a > b+W){
		v = a - (b + W);
	}else{
		v = 0;
	}

	cout << v << endl;

	return 0;
}


Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, d, x, a, ans;


int main(){
    ios::sync_with_stdio(0);
    cin >> n >> d >> x;
    ans = x;
    forn(i,n){
        ans++;
        cin >> a;
        forr(j,1,INF){
            if(a*j+1 > d) break;
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int k,a,b;
signed main(){
    cin>>k>>a>>b;
    if(k==1)cout<<2<<endl;
    else if(k<=a||a+2>=b)cout<<1+k<<endl;
    else{
        k-=a-1;
        int x=k/2,y=k%2;
        cout<<a+(b-a)*x+y<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#coding:utf-8
N = int(input())
H = list(map(int,input().split()))
task = []
#print (N,H)
ans = 0
while(1):
    min_H = min(H)
    ans += min_H
    H = [h -  min_H for h  in H]
    idx = H.index(0)
    #print (H)
    head = H[:idx]
    tail = H[idx+1:]
    #print (head,tail)
    if len(head) > 0:
        task.append(head)
    if len(tail) > 0:
        task.append(tail)
    if len(task) == 0:
        break
    H = task.pop(0)
print (ans)


Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String target = sc.nextLine();
        String queryIn = sc.nextLine();
        CharSequence query = queryIn.subSequence(0, queryIn.length());
        String ring = target.concat(target);
        if (ring.contains(query)) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=405,mod=998244353;
int f[N][N][N],a[N],b[N],c[N][N];
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
int main(){
	ri n,i,j,k,x,sa,sb,prea,preb,inv,w,power,ans;
	gi(n);
	sa=sb=0;
	for(i=1;i<=n;++i) gi(a[i]),gi(b[i]),sa+=a[i],sb+=b[i];
	
	inv=fpow(sa,mod-2);
	
	for(i=0;i<=sb;++i){
		c[i][0]=1;
		for(j=1;j<=i;++j)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	
	f[0][0][0]=1;
	prea=preb=0;
	for(i=1;i<=n;++i){
		prea+=a[i];
		preb+=b[i]-1;
		w=(ll)a[i]*inv%mod;
		for(j=0;j<=prea;++j) // T != empty
			for(k=0;k<=preb;++k){
				f[i][j][k]=f[i-1][j][k];
				if(j>=a[i]){
					power=1;
					for(x=0;x<=min(b[i]-1,k);++x)
						f[i][j][k]=(f[i][j][k]-(ll)c[k][x]*power%mod*f[i-1][j-a[i]][k-x])%mod,
						power=(ll)power*w%mod;
				} 
			//	if(f[i][j][k])
			//		printf("f %d %d %d %d\n",i,j,k,f[i][j][k]);
			}
	}
	ans=0;
	for(i=0;i<=preb;++i)
		for(j=1;j<=prea;++j)
			ans=(ans-(ll)f[n][j][i]*fpow((ll)sa*fpow(j,mod-2)%mod,i+1))%mod;
	ans=ans<0?ans+mod:ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 260992
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull a[110];
int n;
ull gcd(ull x,ull y){
	if(y==0)return x;
	return gcd(y,x%y);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=2;i<=n;i++)
		a[i]=a[i]/gcd(a[i],a[i-1])*a[i-1];
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


bool check(string t){
	set<char> se;
	for(auto u : t) se.insert(u);
	// printf("size %d\n",set.size() );
	if(se.size() == 1) return true;
	else return false;
}

int main(void) {
	string s; cin >> s;
	int ans = INF;
	rep(i, s.size()){
		char c = s[i];
		// printf("c %c\n", c);
		string tmp = s;

		while(!check(tmp)){
			// cout << tmp <</ endl;
			string d;
			rep(k, tmp.size() - 1){
				if(tmp[k] == c || tmp[k + 1] == c){
					// printf("	k %d\n", k);
					d += c;
				}else{
					d += tmp[k];
				}
			}
			tmp = d;
		}
		chmin(ans, s.size() - tmp.size());
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    int N, M;
    cin >> N >> M;
    vector< int > t(N, -1);
    for(int i = 0; i < M; i++) {
        int k, x;
        cin >> k >> x;
        --k;
        if(t[k] == -1 || t[k] == x) {
        t[k] = x;
        } else {
        cout << -1 << endl;
        return 0;
        }
    }
    if(N == 1) {
        for(auto &x : t) cout << max(x, 0);
        cout << endl;
    } else {
        if(t[0] == 0) {
        cout << -1 << endl;
        return 0;
        }
        if(t[0] == -1) t[0] = 1;
        for(auto &x : t) cout << max(x, 0);
        cout << endl;
    }
}

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

#define ll long long int
#define vi vector<int>
#define ii pair< int , int >
#define vii vector<ii>
#define FOR(i, n) for(ll i = 0; i < (ll)n; i++)
int MAX(int a, int b){return (a > b) ? a:b;}
int MIN(int a, int b){return (a < b) ? a:b;}
int ABS(int x){return (x > 0) ? x:-x;}
int left(int x){return (x<<1);}
int right(int x){return (x<<1)+1;}
int lsone(int x){return (x&(-x));}

const int maxn = 1e3 + 5;
const int MOD = 1e9 + 7;

int h, w;
char grid[maxn][maxn];
int ans[maxn][maxn];
bool found[maxn][maxn];

int dp(int posH, int posW){
	if(posH >= h || posW >= w) return 0;
	if(grid[posH][posW] == '#') return 0;
	if(posH == h-1 && posW == w-1) return 1;
	if(found[posH][posW]) return ans[posH][posW];
	found[posH][posW] = true;
	return ans[posH][posW] = (dp(posH+1, posW)+dp(posH, posW+1))%MOD;
}

int main(){
	scanf("%d %d", &h, &w);
	for(int i = 0; i < h; i++){
		scanf("%s", grid[i]);
	}
	printf("%d\n", dp(0, 0));
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int h, w, n;
vector <pair <int, int> > a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> n;
    a.resize(n);
    for(auto &i : a) cin >> i.first >> i.second;
    sort(a.begin(), a.end());
    int cnt = 0;
    for(auto &i : a){
        if(i.second + cnt < i.first) finish(i.first - 1);
        cnt += i.first - cnt == i.second;
    }
    cout << h << endl;
}


Measured memory_bytes: 1792
if __name__ == '__main__':
    a,b,c,x,y = map(int, raw_input().split())
    if c * 2 > a + b:
        print a * x + b * y
    else:
        cost = c * 2 * min(x,y)
        z = abs(x-y)
        if x < y :
            if c * 2 * z < b * z:
                print cost + c * 2 * z
            else:
                print cost + b * z
        else:
            if c * 2 * z < a * z:
                print cost + c * 2 * z
            else:
                print cost + a * z
        


Measured memory_bytes: 2696
#include<iostream>
using namespace std;
int main(){

    int n;
    while(cin>>n,n){
        int L[10]={0};
        while(n--){
            int A;
            cin>>A;
            L[A]++;
        }
        for(int i=0;i<10;i++){
            if(L[i]==0)cout<<"-";
            else for(int j=0;j<L[i];j++)cout<<"*";
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
 
int main() 
{
  int n;
  cin >> n;
  int i;
  int j;
  for(i = 1;i <= n;i++){
    if(i % 3 == 0){
      cout << " " << i;
      continue;
    }else{
      j = i;
      while(j != 0){
        if(j % 10 == 3){
          cout << " " << i;
          break;
        }else{
          j /= 10;
        }
      }
    }
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
// #include "/Users/Coder_Jay/Desktop/Codeforces/header.h"
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
#define  START      auto start = chrono::steady_clock::now()
#define END         auto end = chrono::steady_clock::now()

using namespace std;
typedef pair <lli,lli> pll;
 
// CODE BEGINS :

int main()
{
    kira; START;
    
    lli n; cin>>n;
    string s; cin>>s;

    lli cnt=0;
    forz(i,s.le-2)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        cnt++;
    }

    cout<<cnt<<endl;
    
    END;
    return 0;
}





















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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    reverse(b.begin(), b.end());
    int l = 0, r = n - 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            if (b[i] != a[l] && b[i] != b[l]) {
                swap(b[i], b[l++]);
            }
            else if (b[i] != a[r] && b[i] != b[r]) {
                swap(b[i], b[r--]);
            }
            else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    for (int i : b) {
        cout << i << " ";
    }
    return 0;
}



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

int n, s, l, r, m;
int a[100005], ps[100005];

int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  l = 1, r = n;
  m = a[1];
  partial_sum(a, a + n + 1, ps);
  int ans = n + 1;
  while (l <= n) {
    while (ps[r - 1] - ps[l - 1] >= s)
      r--;
    if (r > n)
      break;
    if (ps[r] - ps[l - 1] >= s)
      ans = min(ans, r - l + 1);
    l++, r++;
  }
  cout << (ans <= n ? ans : 0) << endl;
}


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

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    while(true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D; 
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}
 
var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main() {
  var a = nextbig();
  var b = nextbig();
  var c = nextbig();
  var d = nextbig();

	var ans = a * c;
  	if(a * d > ans) ans = a * d;
  	if(b * c > ans) ans = b * c;
  	if(b * d > ans) ans = b * d;

    return ans;
}




Measured memory_bytes: 29616
import collections
from collections import deque
import bisect

n=int(input())
a=list(int(input()) for i in range(n))
b=deque()
b.append(-1)


for i in range(n):
    if a[i]>b[0]:
        x=bisect.bisect_right(b,a[i]-1)
        b[x-1]=a[i]
    else:
        b.appendleft(a[i])
print(len(b))

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

int main() {
	int N; cin >> N;
	vector<int>A(N); for (int i = 0; i < N; i++)cin >> A[i];

	int maxi = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			maxi = max(maxi, abs(A[i] - A[j]));
		}
	}
	cout << maxi << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
const int INF = 999999999;
int main(){
    int n, L;
    cin >> n >> L;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> ans;
    int mx = 0, mx_id = -1;
    rep(i, n-1){
        if(a[i]+a[i+1] > mx){
            mx = a[i]+a[i+1];
            mx_id = i;
        }
    }
    assert(mx_id >= 0);
    if(mx < L){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        rep(i, mx_id) cout << i+1 << endl;
        for(int i=n-1; i >= mx_id+1; i--) cout << i << endl;
    }
}

Measured memory_bytes: 1152
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();
    let n = s.len()+ 1;
    let mut v =  vec![0; n];
    let mut acc = 0;
    for i in 1..n {
        if s[i-1] == '<' {
            acc += 1;
        } else {
            acc = 0;
        }
        v[i] = acc;
    }
    acc = 0;
    for i in (0..n-1).rev() {
        if s[i] == '>' {
            acc += 1;
        } else {
            acc = 0;
        }
        v[i] = std::cmp::max(v[i], acc);
    }
    println!("{}", v.into_iter().sum::<i64>());
}

Measured memory_bytes: 8240
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 1e6 + 7;

void solve() {
    int n, w = 0; cin >> n;
    vector <int> a(n);
    loop(i, n) {
        char c; cin >> c;
        if (c == 'W') {
            ++w; a[i] = 1;
        }
    }
    int lans = 0, rans = 0;
    loop(i, n - w)
        lans += a[i];
    for (int i = n - 1; i >= n - w; --i)
        rans += !a[i];
    cout << min(lans, rans);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

bool all_lighted(vector<int> onoff_pattern, map<int, vector<int>> bulb_swis, map<int, int> oddeven, int m) {
    int sum_light = 0;
    for (int bulb_id = 0; bulb_id < m; bulb_id++) {
        int sum_on = 0;
        vector<int> swis = bulb_swis[bulb_id];
        for (int swi : swis) {
            if (onoff_pattern[swi]) {
                sum_on++;
            }
        }
        if (sum_on % 2 == oddeven[bulb_id]) {
            sum_light++;
        }
    }
    if (sum_light == m) {
        return true;
    }
    else {
        return false;
    }
}


int recursive(int switch_id, vector<int> onoff_pattern, int n, map<int, vector<int>> bulb_swis, map<int, int> oddeven, int m) {
    if (switch_id < n) {
        vector<int> onoff_pattern_on = onoff_pattern;
        vector<int> onoff_pattern_off = onoff_pattern;
        onoff_pattern_on.push_back(1);
        onoff_pattern_off.push_back(0);
        int sum_a = recursive(switch_id+1, onoff_pattern_on, n, bulb_swis, oddeven, m);
        int sum_b = recursive(switch_id+1, onoff_pattern_off, n, bulb_swis, oddeven, m);
        return sum_a + sum_b;
    }
    else {
        if (all_lighted(onoff_pattern, bulb_swis, oddeven, m)) {
            return 1;
        }
        else {
            return 0;
        }
    }
}

int main() {
    int n, m, ans;
    cin >> n >> m;
    map<int, vector<int>> bulb_swis;
    for (int bulb_id = 0; bulb_id < m; bulb_id++) {
        int swi_n;
        cin >> swi_n;
        vector<int> swis;
        for (int j = 0; j < swi_n; j++) {
            int swi;
            cin >> swi;
            swis.push_back(swi-1);
        }
        bulb_swis.emplace(bulb_id, swis);
    }
    map<int, int> oddeven;
    for (int bulb_id = 0; bulb_id < m; bulb_id++) {
        int p;
        cin >> p;
        oddeven.emplace(bulb_id, p);
    }
    vector<int> tmp;
    ans = recursive(0, tmp, n, bulb_swis, oddeven, m);
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        char[] c = in.next().toCharArray();
        int w = 0;
        int r = N - 1;
        int ans = 0;
        while (true) {
            while (w < N && c[w] != 'W')
                w++;
            while (r >= 0 && c[r] != 'R')
                r--;
            if (w > r)
                break;
            w++;
            r--;
            ans++;
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 36788
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
using namespace std;
int main() {
    int n,mx,mi; cin >> n; vector<int> a(n);
    rep(i, n) cin >> a[i];
    mx = *max_element(ALL(a)); mi = *min_element(ALL(a));
    cout << 2 * n - 1 << endl;
    if (abs(mx) >= abs(mi)) {
        int mxid = max_element(ALL(a)) - a.begin()+1;
        rep(i, n) {
            a[i] += mx;
            cout << mxid << " " << i+1 << endl;
        }
        rep(i, n-1)  cout << i + 1 << " " << i+2 << endl;
    }
    else {
        int miid = min_element(ALL(a)) - a.begin()+1;
        rep(i, n) {
            a[i] += mi;
            cout << miid << " " << i + 1 << endl;
        }
        rrep(i, n - 1) cout << i+2 << " " << i + 1 << endl;// 足す法、足されるほう
    }
}

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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXN 1000005
#define MAXC 205
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;

bool did[MAXN];
string oth(string x)
{
	if(x == "Male") return "Female";
	else return "Male";
}
int main(void)
{
	
	int N; 
	cin >> N;
	int l = 0;
	int r = N-1;
	string lft;
	printf("%d\n", l);
	fflush(stdout);
	cin >> lft;
	if(lft == "Vacant") { return 0; }
	did[l] = 1;
	while(l < r) {
		int md = (l+r)/2;
		string s;
		if(did[md]) break;
		printf("%d\n", md);
		fflush(stdout);
		did[md] = 1;
		cin >> s;
		if(s == "Vacant") { return 0; }
		int dst = (md-l);
		string t;
		if(dst%2) t = oth(lft);
		else t = lft;
		
		if(s == t) {
			l=md;	
			lft = s;
		}
		else {
			r=md-1;
		}
	}
	if(!did[r]) {
		printf("%d\n", r);
		fflush(stdout);
		cin >> lft;
	}
	
}

Measured memory_bytes: 852
package main

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

const Inf = 1 << 60

func main() {
	N := ReadInt()
	a := ReadInts(N)

	minIdx, maxIdx := 0, 0
	for i := 1; i < N; i++ {
		if a[i] > a[maxIdx] {
			maxIdx = i
		} else if a[i] < a[minIdx] {
			minIdx = i
		}
	}

	ans := make([][]int, 0)
	if a[maxIdx] > 0 && a[minIdx] < 0 {
		if Abs(a[maxIdx]) >= Abs(a[minIdx]) {
			for i := 0; i < N; i++ {
				ans = append(ans, []int{maxIdx, i})
				a[i] += a[maxIdx]
			}
		} else {
			for i := 0; i < N; i++ {
				ans = append(ans, []int{minIdx, i})
				a[i] += a[minIdx]
			}
		}
	}

	if a[0] > 0 {
		for i := 1; i < N; i++ {
			if a[i-1] <= a[i] {
				continue
			}
			ans = append(ans, []int{maxIdx, i})
			a[i] += a[maxIdx]
			if a[i] > a[maxIdx] {
				maxIdx = i
			}
		}
	} else {
		for i := N - 2; i >= 0; i-- {
			if a[i] <= a[i+1] {
				continue
			}
			ans = append(ans, []int{minIdx, i})
			a[i] += a[minIdx]
			if a[i] < a[minIdx] {
				minIdx = i
			}
		}
	}

	fmt.Println(len(ans))
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i][0]+1, ans[i][1]+1)
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll X, Y;
    cin >> X >> Y;
    ll temp = __gcd(X, Y);
    if(temp == Y) cout << -1;
    else cout << X / temp * X;
    cout << endl;
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;

    double p, sum = 0., ans = 0.;
    queue<double> q;
    for (int i = 1; i <= n; i++) {
        cin >> p;
        p = (p+1.)/2.;
        sum += p;
        q.push(p);
        if (i >= k) {
            ans = max (ans, sum);
            sum -= q.front();
            q.pop();
        }
    }
    printf("%.7lf", ans);
}

Measured memory_bytes: 5416
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> C(N); vector<int> S(N); vector<int> F(N);
 for(int i = 1; i <= N - 1; i++){ cin >> C[i] >> S[i] >> F[i];}
  
  for(int i = 1; i <= N; i++){ //depatures iterators
   int t = 0;
    if( i == N ){ cout << 0 << endl; return 0;}
    for(int j = i; j <= N - 1 ; j++){ // in this region, i is under N
      if( t < S[j]){ t = S[j];}
      else{ int k = ( t - S[j] + F[j] - 1) / F[j]; t = S[j] + k * F[j];}
      t += C[j];} // move to the N-1 station as soon as possible
    cout << t << endl;}
}


Measured memory_bytes: 256
import sys

class UnionFind():
    def __init__(self, n):
        self.parent = [-1] * n
        
    def root(self, x):
        '''
        Returns index of the root of the union to which x belongs to.
        '''

        if self.parent[x] < 0:
            return x

        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def size(self, x):
        '''
        Returns the size of the union to which input index belongs.
        '''
        
        return -1 * self.parent[self.root(x)]
    
    def unite(self, x, y):
        '''
        Unite two vertices x and y.\n
        Input:
            x and y: indices of vertices to unite.
        '''

        x, y = self.root(x), self.root(y)

        if x == y:
            return False

        else:
            size_x = - self.size(x)
            size_y = - self.size(y)

            if size_x > size_y:
                x, y = y, x

            self.parent[x] += self.parent[y]
            self.parent[y] = x

            return True


input = sys.stdin.readline
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x,y)

roots = set()

for i in range(N):
    
    roots.add(uf.root(i))

print(len(roots))

Measured memory_bytes: 12780