akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

int N, M, Q;
vector<vector<int>> tate(2222, vector<int>(2222, 0)), yoko(2222, vector<int>(2222, 0));
vector<vector<int>> s(2222, vector<int>(2222, 0)), sum(2222, vector<int>(2222, 0));

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

    cin >> N >> M >> Q;
    for (int i = 1; i <= N; i++)
    {
        string str;
        cin >> str;
        str = '$' + str;
        for (int j = 1; j <= M; j++)
        {
            s[i][j] = str[j] - '0';
            sum[i][j] = s[i][j];
            if (s[i][j] && s[i - 1][j])
                tate[i][j]++;
            if (s[i][j] && s[i][j - 1])
                yoko[i][j]++;

            tate[i][j] += tate[i - 1][j] + tate[i][j - 1] - tate[i - 1][j - 1];
            yoko[i][j] += yoko[i - 1][j] + yoko[i][j - 1] - yoko[i - 1][j - 1];
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }
    for (int i = 0; i < Q; i++)
    {
        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        int t = tate[gx][gy] - tate[sx][gy] - tate[gx][sy - 1] + tate[sx][sy - 1];
        int y = yoko[gx][gy] - yoko[sx - 1][gy] - yoko[gx][sy] + yoko[sx - 1][sy];
        int num = sum[gx][gy] - sum[sx - 1][gy] - sum[gx][sy - 1] + sum[sx - 1][sy - 1];
        // cout<<num<<" "<<t<<" "<<y<<endl;
        cout << num - (t + y) << endl;
    }
}


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

using i64 = int64_t;

int main(){
    int V, E;
    cin >> V >> E;
    vector<char> v;
    for(int i=0;i<V;++i){
        char a;
        cin >> a;
        v.push_back(a);
    }
    vector<vector<int>> graph(V, vector<int>());
    for(int i=0;i<E;++i){
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    for(int i=0;i<V;++i){
        if(v[i] != '?')continue;
        set<char> st;
        for(auto to: graph[i]){
            if(v[to] == '?')continue;
            st.insert(v[to]);
        }
        char c = 'a';
        while(st.count(c))c++;
        v[i] = c;
    }
    for(auto e: v)cout << e;
    cout << endl;

    return 0;
}


Measured memory_bytes: 9640
"use strict"
function Main(stdin){
stdin = stdin.trim().split("\n").reverse();
let stdout = [];
function input(){return stdin.pop()};
function print(x){stdout.push(x)};
function mapint(x){return x.map(n=>parseInt(n))};
function mapfloat(x){return x.map(n=>parseFloat(n))};
function max(x){return x.reduce(function(a,b){ return Math.max(a,b) }) }
function min(x){return x.reduce(function(a,b){ return Math.min(a,b) }) }
function sum(x){return x.reduce(function(a,b){ return a+b }) }
function all(x){return x.reduce(function(a,b){ return a && b }) }
function any(x){return x.reduce(function(a,b){ return a || b }) }
function inlist(x, xs){return xs.includes(x)}
function inset(x, xs){return xs.has(x)}
function list(iterable){return Array.from(iterable)}
function array(iterable){return Array.from(iterable, x => parseInt(x))}
function tile(val, len){return Array(len).fill(val)}
const range = (start, stop, step) => Array.from(
    { length: (stop - start) / step }, (_, i) => start + (i * step));
/*START*/

let s = array(input())
let n = s.length
let zero = 0
let one = 0
for (let i = 0; i < n; i++){
    if (s[i]%2 == i%2){ zero++ }else{ one++ }
}
print(Math.min(zero, one))


/*END*/
stdout = stdout.join("\n");
console.log(stdout);
return stdout
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 15012
N, M, Q = map(int, input().split())
reqs = []
for _ in range(Q):
    reqs.append(tuple(map(int, input().split())))

reqs = sorted(reqs, key=lambda x: x[1])

def search(A, req_head):
    if req_head >= len(reqs):
        return 0

    max_score = 0
    for e in range(A[-1], M+1):
        score = 0
        i = req_head
        while i < len(reqs) and reqs[i][1] < len(A):
            i += 1
        while i < len(reqs) and reqs[i][1] == len(A):
            a, b, c, d = reqs[i]
            if e - A[a] == c:
                score += d
            i += 1
        score += search(A + [e], i)
        max_score = max(max_score, score)

    return max_score

print(search([None, 1], 0))


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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int N;
	cin >> N;
	for (int i = 111; i <= 999; i = i + 111) {
		if (N <= i) {
			cout << i;
			return 0;
		}
	}
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pii pair<int,int>

int N, S;
int A[3010];
int dp[3010][3010];
int mod = 998244353;

signed main()
{
    cin >> N >> S;
    rep(i, N)cin >> A[i];

    dp[0][0] = 1;
    rep(i, N)
    {
        rep(j, S + 1)
        {
            // use
            if(j + A[i] <= S)dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j]) % mod;

            // dont
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 2) % mod;
        }
    }

    cout << dp[N][S] << endl;

    return 0;
}


Measured memory_bytes: 74208
var n,a,b,s,i,m:Longint;
begin
	read(n,a,b);
	for i:=1 to n do begin
		m:=m+1;
		if i mod 10 = 0 then m:=m-9;
		if i mod 100 = 0 then m:=m-9;
		if i mod 1000 = 0 then m:=m-9;
		if i mod 10000 = 0 then m:=m-9;
		if (a<=m)and(m<=b)then s:=s+i;
	end;
	writeln(s);
end.


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

#define ll long long

bool isPossible(ll *arr, ll k , ll mid, ll n){

    ll i=0;
    while(i < n && k>=0){
    	
    	if(arr[i]  > mid){
    		k -= arr[i]/mid;
    		if(arr[i]%mid ==0)
            {
    			k+=1;
			}
		}
    	++i;
	}
    if(k<0) return false;
	if(i==n) return true;
}

int main()
{
	
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	ll maxi = 0;
	ll mini = 1;
	for(ll i=0;i<n;++i){
		cin>>arr[i];
		if(arr[i] > maxi){
			maxi  = arr[i];
		}
	}
  ll ans  = maxi;
	maxi  = maxi + 1;
	// now we will check if it is possible to divide it 
    
    ll mid;
    while(mini <= maxi)
    {
    	mid = (mini + maxi)/2;
       	if(isPossible(arr,k,mid,n))
		   {
       		  ans = min(ans,mid);
       		  maxi = mid-1;
		   }else{
		   	 mini = mid+1;
		   }
	}
	cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 5140
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
FF = [inpl() for i in range(N)]
PP = [inpl() for i in range(N)]

ans = -INF
for flags in itertools.product([0,1], repeat=10):
	if sum(flags) == 0: continue
	tans = 0
	for i in range(N):
		tmp = 0
		for c in range(10):
			if FF[i][c] and flags[c]:
				tmp += 1
		tans += PP[i][tmp]
	ans = max(tans,ans)

print(ans)


Measured memory_bytes: 4324
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()

int main() {
    ll H,W; scanf("%lld%lld",&H,&W);
    ll h,w; scanf("%lld%lld",&h,&w);
    cout << H*W-H*w-W*h+h*w << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        String date = sc.next();
        int date1 = Integer.parseInt(date.substring(0, 2));
        int date2 = Integer.parseInt(date.substring(2, 4));

        int yymm = 0;
        int mmyy = 0;

        if (date2 != 0 && date2 < 13) {
            yymm = 1;
        }
        if (date1 != 0 && date1 < 13) {
            mmyy = 1;
        }

        if (yymm == 1 && mmyy == 1) {
            System.out.println("AMBIGUOUS");
        } else if (yymm == 0 && mmyy == 0) {
            System.out.println("NA");
        } else if (yymm == 1) {
            System.out.println("YYMM");
        } else {
            System.out.println("MMYY");
        }
	}
}

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

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define ii pair <int,int>
#define ever (;;)

const int N = 210;

int n,a[N],ans;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<2*n;i++)
        scanf("%d",&a[i]);
    sort(a,a+2*n);

    for(int i=0;i<2*n;i+=2)
        ans += a[i];

    printf("%d",ans);
}


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

int main(){
  int n;
  cin >> n;
  int b[n-1];
  int ans;
  ans = 0;
  for(int i = 0;i < n-1;i++){
    cin >> b[i];
  }
  for(int i = 0;i < n-1;i++){
    if(i == 0){
      ans += b[i];
    }else if(b[i] > b[i-1]){
      ans += b[i-1];
    }else{
      ans += b[i];
    }
  }
  ans += b[n-2];
  cout << ans << endl;
}


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

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+')ans++;
		else ans--;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import os, sys, re, math

(N, T) = [int(i) for i in input().split()]

min_cost = sys.maxsize
for i in range(N):
    (c, t) = [int(j) for j in input().split()]
    if t <= T and c < min_cost:
        min_cost = c

print (min_cost if min_cost < sys.maxsize else 'TLE')


Measured memory_bytes: 3188
#include <stdio.h>

main(){
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    printf("%d %d %d %d",x2-(y2-y1),y2+(x2-x1),x1-(y2-y1),y1+(x2-x1));
}

Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n;
	cin >> n;
	ll ar[n];
	F0R(i, n)
		cin >> ar[i];
	sort(ar, ar+n);
	reverse(ar, ar+n);
	ll ans = 0LL;
	int u = n - 1;
	F0R(i, n) {
		int cur = min(u, i ? 2 : 1);
		ans += ar[i] * cur;
		u -= cur;
	}
	cout << ans << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N,K;
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
        A[i]--;
    }
    vector<ll> S(N+1);
    rep(i,N){
        S[i+1] = S[i] + A[i];
        S[i+1] %= K;
    }
    map<int, int> map;
    ll ans = 0;
    queue<int> q;
    rep(i,N+1){
        ans += map[S[i]];
        map[S[i]]++;
        q.push(i);
        if((int)q.size() == K){
            int top = q.front();
            q.pop();
            map[S[top]]--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13568
#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int N, K;
string ans = "NO";
int main()
{

    cin >> N >> K;
    if (N % 2 == 0)
    {
        if ((int)N / 2 >= K)
            ans = "YES";
    }
    else
    {
        if (int(N / 2) + 1 >= K)
            ans = "YES";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N] , n , val[N];
multiset <int> myset;
int main(){
    cin >> n;
    for(int i = 0 ; i < n ;i++)
        cin >> arr[i];
    myset.insert(-arr[0]);
    for(int i = 1 ; i < n ; i++){
        int val = (*myset.rbegin());
        if (-val >= arr[i])myset.insert(-arr[i]);
        else{
            myset.erase(myset.upper_bound(-arr[i]));
            myset.insert(-arr[i]);
        }
    }
    cout << myset.size();
    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      
      	int A = sc.nextInt(), B = sc.nextInt(), K = sc.nextInt();
      
      	for (int i=Math.min(A, B); i>=1; i--) {
        	if (A % i == 0 && B % i == 0) {
            	K--;
              	if (K==0) {
                 	System.out.println(i); 
                }
            }
        }
    }
}

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

using namespace std;

#define ll long long
#define ii pair<int ,int>
#define iii tuple<int ,int, int>
#define vi vector<int>
#define vii vector<int, int>
#define fo(i,a,n) for(int i = (a); i < (n); i++)
#define pb push_back
#define newl cout<<"\n"
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define N1 100000

//int visited[N1]={};
//int st[4*N1 + 10]={};
const ll MAXN=2e+5+7;
vector<int> adj[MAXN];
ll val[MAXN]={};
ll n, q;
ll x, y;

void AddEdge(int x, int y){
	adj[x].pb(y);
	adj[y].pb(x);
}

void DFS(ll par, ll child, ll sum){
	val[child]+=sum;
	for(auto it: adj[child]){
		if (par==it) continue;
		DFS(child, it, val[child]);
	}
} 

int main(){
	cin>>n>>q;
	fo(i,0,n-1){cin>>x>>y; AddEdge(x,y);}
	fo(i,0,q){cin>>x>>y;val[x]+=y;}
	DFS(0,1,0);
	fo(i,1,n+1){cout<<val[i]<<" ";}
}

Measured memory_bytes: 24320
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        while(true){
            int h = input.nextInt();
            int w = input.nextInt();
            if(h==0&&w==0){
                break;
            }
            for(int n = 0; n < h; n++){
                for(int i = 0; i < w; i++){
                    if((n%2 == 1 && i%2 == 1) || (n%2 == 0 && i%2 == 0)){
                    build.append("#");
                    }else{
                    build.append(".");
                    }
                }
                build.append("\n");
            }
             build.append("\n");
        }
        System.out.print(build);
    }
}

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

int main() 
{
    int N; cin >> N;
    long long ans = 0;
    for (int i = 0; i < N; i++) 
    {
        int t = 0;
        cin >> t;
        
        int j = 0;
        while (t % 2 == 0)
        {
            t /= 2;
            j++;
        }
        ans += j;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int N, a[110], ans;

  cin >> N;
  for(int i = 0; i < N; i++) cin >> a[i];

  sort(a, a+N);

  ans = a[N-1] - a[0];

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, X, M; cin >> N >> M >> X;
	vector<int>c(N + 1, 0);
	rep(i, M) {
		int a; cin >> a;
		++c[a];
	}
	int ans = INF;
	int cnt = 0;
	rep(i, c.size()) {
		if (c[i] == 1)++cnt;
		if (i == X) {
			chmin(ans, cnt);
			cnt = 0;
		}
	}
	chmin(ans, cnt);
	cout << ans << "\n";

	return 0;
}


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

using namespace std;

int N,H,W;
int X1[1000],X2[1000],Y1[1000],Y2[1000];
int fld[3002][3002],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};

int compress(int *x1,int *x2,int w){
  vector<int>xs;

  for(int i=0;i<N;i++){
      int tx1=x1[i],tx2=x2[i];
      if(1<=tx1 && tx1<w)xs.push_back(tx1);
      if(1<=tx2 && tx2<w)xs.push_back(tx2);
  }
  xs.push_back(0);
  xs.push_back(w);
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i=0;i<N;i++){
    x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
    x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
  }
  return xs.size()-1;
}

int bfs(void){

  int ans=0;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(fld[i][j])continue;
      ans++;
      queue<pair<int,int> >que;
      que.push(make_pair(j,i));
      while(!que.empty()){
	int nx=que.front().first,ny=que.front().second;
	que.pop();

	for(int i=0;i<4;i++){
	  int tx=nx+dx[i],ty=ny+dy[i];
	  if(tx<0 || W<tx || ty<0 || H<ty || fld[ty][tx]>0)continue;
	  que.push(make_pair(tx,ty));
	  fld[ty][tx]=1;
	}
      }
    }
  }
  return ans;
}

int main(void){

  while(cin >> W >> H,W|H){
    cin >> N;
    for(int i=0;i<N;i++)
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    
    fill(fld[0],fld[3002],0);
    
    W=compress(X1,X2,W);
    H=compress(Y1,Y2,H);
    
    for(int i=0;i<N;i++){
      fld[Y1[i]][X1[i]]++;
      fld[Y1[i]][X2[i]]--;
      fld[Y2[i]][X1[i]]--;
      fld[Y2[i]][X2[i]]++;
    }
    
    for(int i=0;i<H;i++){
      for(int j=1;j<W;j++){
	fld[i][j]+=fld[i][j-1];      
      }
    }
    
    for(int i=1;i<H;i++){
      for(int j=0;j<W;j++){
	fld[i][j]+=fld[i-1][j];
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 36452
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    ll ans = 1;
    VL a(n); cin >> a;
    if (*min_element(all(a)) == 0) {
        print(0);
        return 0;
    }
    FOR(i, 0, n) {
        if (1000000000000000000LL / ans < a[i]) {
            print(-1);
            return 0;
        }
        ans *= a[i];
    }
    print(ans);

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n); 
  for(int i=0; i<n;i++){
    cin >> d[i];
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
int N;
VL a, b, p;

int main() {
    cin >> N;
    p.resize(N);
    a.resize(N);
    b.resize(N);
    VECCIN(p);
    REP(i, N) a[i] = 30000 * i + 1;
    REP(i, N) {
        b[N - 1 - i] += 30000 * i + 1;
        b[p[i] - 1] += i;
    }
    FOREACH(x, a) cout << x << " ";
    cout << "\n";
    FOREACH(x, b) cout << x << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1152
const main = (input) => {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          Y = parseInt(args[1], 10);

    var result = '-1 -1 -1';

    for (var a = 0; a <= N; a++) {
        for (var b = 0; b <= N; b++) {
            if ((a + b) > N) {
                continue;
            }

            var sum = (a * 10000) + (b * 5000) + ((N - a - b) * 1000);
            if (sum === Y) {
                result = `${a} ${b} ${N - a - b}`;
                break;
            }
        }        
    }

    console.log(result);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

class State
{
public:
	int to,ct[2];	//cost,time
	State(int to, int cost,int time) :
	to(to){ct[0] = cost, ct[1] = time;}

};

// routes, stations
int n,m;
int d[101];

int dijkstra(vector<State> *vec, int p, int q, int r)
{
	queue<State> que;
	que.push(State(p,0,0));	//first position
	fill(d, d+101, INF);
	d[p] = 0;
	

	while(que.size()){
		State sta = que.front();
		que.pop();

		rep(i, vec[sta.to].size()){
			if(d[vec[sta.to][i].to] > vec[sta.to][i].ct[r] + d[sta.to]){
				d[vec[sta.to][i].to] = vec[sta.to][i].ct[r] + d[sta.to];
				que.push(vec[sta.to][i]);
			}
		}
	}
	return d[q];
}


int main(void)
{
	int a,b,cost,time;
	int k;
	int p,q,r;
	while(cin >> n >> m, n){
		vector<State> *vec = new vector<State>[m+1];

		rep(i,n){
			cin >> a >> b >> cost >> time;
			vec[a].push_back(State(b,cost,time));
			vec[b].push_back(State(a,cost,time));
		}
		cin >> k;
		rep(i,k){
			cin >> p >> q >> r;
			cout << dijkstra(vec, p, q, r) << endl;
		}
	}
}

Measured memory_bytes: 2800
#include<iostream>
#include<vector>
using namespace std;
 
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
bool dp[500005];

int main(){
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i];
    }
    for(i=0;i<n-1;i++){
        if(x[i+1] <= x[i]){
            num++;
        }else{
            ans = max(num, ans);
            num = 0;
        }
    }
    ans = max(num, ans);
    p(ans);
    return 0;
}






Measured memory_bytes: 2304
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;//T
 
Node treeMinimum(Node x){
 
 
}
 
Node treeSearch(Node u, int k){
  while((u != NIL) && (k != u->key)){
    if (k < u->key){
    u = u->left;
    }
    else u = u->right;
  }
  return u;
}
 

 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
   
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y = x;
    if (z->key < x->key)
    x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if (y == NIL)
  root = z;
  else if(z->key < y->key)
    y->left = z;
  else y->right = z;
}
 
void inorder(Node u){
  if(u != NIL) {
    if(u->left != NIL) inorder(u->left);
    printf(" %d",u->key);
    if(u->right != NIL) inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    if(u->left != NIL) preorder(u->left);
    if(u->right != NIL) preorder(u->right);
  }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}

Measured memory_bytes: 19364
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;

inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}


int main() {
	int r; cin >> r;
	cout << 3 * r*r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int saiki(int n){
	int a,b,c,d;
	for(int i=0;i<10;i++){
		
	}
}

int main(void){
	int n,cnt;
	while(scanf("%d",&n)!=-1){
		cnt=0;
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					for(int l=0;l<10;l++){
						if(i+j+k+l==n)cnt++;
					}
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <unordered_map>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int M;

bool unique(string s, unordered_map<string, bool> &v) {
  if(v[s]) return false;
  return v[s] = true;
}

int main(void) {
  cin >> M;
  REP(i, 0, M) {
    string S; cin >> S;
    unordered_map<string, bool> v;
    int cnt = 0;

    REP(i, 1, S.length()) {
      string s1 = S.substr(0, i), s2 = S.substr(i, S.length());
      string r1 = S.substr(0, i), r2 = S.substr(i, S.length());
      reverse(r1.begin(), r1.end());
      reverse(r2.begin(), r2.end());

      if(unique(s1 + s2, v) == 1) cnt++;
      if(unique(s1 + r2, v) == 1) cnt++;
      if(unique(r1 + s2, v) == 1) cnt++;
      if(unique(r1 + r2, v) == 1) cnt++;
      if(unique(s2 + s1, v) == 1) cnt++;
      if(unique(s2 + r1, v) == 1) cnt++;
      if(unique(r2 + s1, v) == 1) cnt++;
      if(unique(r2 + r1, v) == 1) cnt++;
    }

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;
ll dp[MAX_N][13];

int main(void){
    string S;
    ll answer = 0;
    ll N;

    cin >> S;

    N = S.length();

    rep(i, N){
        ll idx;
        if (i == 0){
            if (S[i] == '?') rep(j, 13) if (j < 10) dp[i][j] = 1; else dp[i][j] = 0;
            else rep(j, 13) if (ll(S[i] - ll('0')) == j) dp[i][j] = 1; else dp[i][j] = 0;
            continue;
        }

        if (S[i] == '?'){
            rep(j, 13) dp[i][j] = 0;
            rep(k, 10){
                rep(j, 13){
                    idx = (j * 10 + k) % 13;
                    dp[i][idx] = (dp[i][idx] + dp[i - 1][j]) % mod;
                }
            }
        }else{
            rep(j, 13){
                idx = (j * 10 + ll(S[i]) - ll('0')) % 13;
                dp[i][idx] = dp[i - 1][j];
            }
        }

        }

    cout << dp[N - 1][5] << endl;

    return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 5/24/2020

 15:28-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,K;

void nope() {
  cout<<-1<<endl;
  exit(0);
}
void solve() {
  if(K>(N-1)*(N-2)/2) nope();
  vector<II> es;
  REP(j,N)REP(i,j) es.emplace_back(i,j);
  sort(ALL(es));
  int k=K;
  while(k--) es.pop_back();
  cout<<SZ(es)<<endl;
  FORR(p,es) cout<<p.first+1<<" "<<p.second+1<<endl;
}

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

  cin>>N>>K;
  solve();

  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for(ll i=0;i<(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n),b(n);;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    ll q;cin>>q;
    while(q--){
        ll l,r,m;cin>>l>>m>>r;
        for(ll i=0;i<r-l;i++){
            a[l+((i+(r-m))%(r-l))]=b[i+l];
        }
        for(ll i=0;i<n;i++){
            b[i]=a[i];
        }
    }
    for(ll i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    

    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 3176
package main

import (
	"fmt"
	"sort"
)

func main() {
	var num int
	var quant int
	fmt.Scan(&num)
	var tmpNum int
	hash := make([]int, 1000001)
	for i := 0; i < num; i++ {
		fmt.Scan(&tmpNum)
		hash[tmpNum]++
	}
	sum := 0
	for key, value := range hash {
		sum += key * value
	}
	fmt.Scan(&quant)
	qa := make([][]int, quant)
	for i := 0; i < quant; i++ {
		tmp := scanNums(2)
		qa[i] = tmp
		def1 := tmp[0]*hash[tmp[0]] + tmp[1]*hash[tmp[1]]
		hash[tmp[0]], hash[tmp[1]] = 0, hash[tmp[0]]+hash[tmp[1]]
		def2 := tmp[1] * hash[tmp[1]]
		sum = sum + def2 - def1
		fmt.Println(sum)
	}
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 16564
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int data[3];
    scanf("%d %d %d", data, data+1, data+2); 
    qsort(data, 3, sizeof(int), compare_int);
    printf("%d %d %d\n", data[0], data[1], data[2]);
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;




int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	int odd_cnt = 0;
	int four_cnt = 0;
	rep(i, n) {
		cin >> a.at(i);
		if (a.at(i) % 2 != 0) {
			odd_cnt++;
		}
		else if (a.at(i) % 4 == 0) {
			four_cnt++;
		}
	}

	if (four_cnt >= odd_cnt) {
		cout << "Yes" << endl;
	}
	else if (n % 2 != 0 && (odd_cnt - four_cnt) == 1 && (odd_cnt + four_cnt) == n) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	
	return 0;
	
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
struct op { int y1, x1, y2, x2; };
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n + 1, vector<int>(m + 1));
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    vector<op> ops;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(a[i][j] % 2) {
                a[i][j]--;
                if(j < m) {
                    a[i][j + 1]++;
                    ops.push_back({i, j, i, j + 1});
                } else if(i < n) {
                    a[i+1][j]++;
                    ops.push_back({i, j, i + 1, j});
                }
            }
        }
    }
    cout << ops.size() << endl;
    for(auto& ope : ops) {
        cout << ope.y1 << " " << ope.x1 << " " << ope.y2 << " " << ope.x2 << endl;
    }
    return 0;
}


Measured memory_bytes: 5236
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;

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

    ll d = x / 11LL;
    ll ans = 2 * d;
    int n = x % 11;

    if (n == 0);
    else if (n <= 6) ans++;
    else if (n <= 11) ans += 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define INF 3000000000000001
#define ll_max 9000000000000000001
#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 1;

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, x = 0, y = 0, k, W, H;
        cin >> n >> m;
        ll a[n];
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
        }   
        sort(a, a + n);
        for(int i = 0; i < n - m; i++) x += a[i];
        cout << x << "\n";
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
int main(){
  ll n,k;
  cin >> n >> k;
  ll a[n],b[n];
  rep(i,n){
    cin >> a[i];
    b[i]=-2;
  }
  b[0]=-1;
  ll h=0,v;
  rep(i,k){
    h=a[h]-1;
    if(b[h]>=-1){
      v=((k-i-1)%(i-b[h]));
      rep(j,v){
        h=a[h]-1;
      }
      break;
    }
    b[h]=i;
  }
  cout << h+1 << endl;
}

Measured memory_bytes: 6748