akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  int n;

  while(cin>>n,n){
    int sum = 0;
    rep(i,n/4){
      int x;
      cin>>x;
      sum += x;
    }
    cout<<sum<<endl;
  }
}

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

struct dise{
 int lab1, lab2, lab3, lab4, lab5, lab6;
};

void s( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab5;
     d.lab5 = d.lab6;
     d.lab6 = d.lab2;
     d.lab2 = tmp;
}

void e( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab4;
     d.lab4 = d.lab6;
     d.lab6 = d.lab3;
     d.lab3 = tmp;
}

void n( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab2;
     d.lab2 = d.lab6;
     d.lab6 = d.lab5;
     d.lab5 = tmp;
}

void w( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab3;
     d.lab3 = d.lab6;
     d.lab6 = d.lab4;
     d.lab4 = tmp;
}

void lot( dise &d ){
     int tmp = d.lab2;
     d.lab2 = d.lab3;
     d.lab3 = d.lab5;
     d.lab5 = d.lab4;
     d.lab4 = tmp;
}


int main(){
 dise d1,d2;
 cin >> d1.lab1 >> d1.lab2 >> d1.lab3 >> d1.lab4 >> d1.lab5 >> d1.lab6;
 cin >> d2.lab1 >> d2.lab2 >> d2.lab3 >> d2.lab4 >> d2.lab5 >> d2.lab6;

 bool flag = false;
 for( int i=0; i<4; i++ ){
  for( int j=0; j<4; j++ ){
   if( d1.lab1==d2.lab1 && d1.lab2==d2.lab2 && d1.lab3==d2.lab3 && d1.lab4==d2.lab4 && d1.lab5==d2.lab5 && d1.lab6==d2.lab6 ){
     flag = true;
     break;
   }
   lot(d1);
  }
  if( flag ){
   break;
  }
  n(d1);
 }

 e(d1);

 for( int i=0; i<4; i++ ){
  for( int j=0; j<4; j++ ){
   if( d1.lab1==d2.lab1 && d1.lab2==d2.lab2 && d1.lab3==d2.lab3 && d1.lab4==d2.lab4 && d1.lab5==d2.lab5 && d1.lab6==d2.lab6 ){
     flag = true;
     break;
   }
   lot(d1);
  }
  if( flag ){
   break;
  }
  n(d1);
 }

 if( flag ){
   cout << "Yes" << endl;
 }else{
   cout << "No" << endl;
 }

 return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 500010
#define maxm 100010
#define inf 1000000007
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,mx,mn;
int ci_n[maxn],ci_m[maxn];
int fac[maxn],inv[maxn];
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int ans;
void add(int &x,int y)
{
    x=(x+y>=mod)?x+y-mod:x+y;
}
int C(int x,int y)
{
    return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    n=read();m=read();mx=max(n,m);mn=min(n,m);
    fac[0]=1;
    for(int i=1;i<=mx;i++)  fac[i]=1ll*fac[i-1]*i%mod;
    inv[mx]=quick_pow(fac[mx],mod-2);
    for(int i=mx-1;i>=0;i--)  inv[i]=1ll*inv[i+1]*(i+1)%mod;
    ci_m[0]=ci_n[0]=1;
    for(int i=1;i<=n;i++)  ci_m[i]=1ll*ci_m[i-1]*(m+1)%mod;
    for(int i=1;i<=m;i++)  ci_n[i]=1ll*ci_n[i-1]*(n+1)%mod;
    for(int i=0;i<=mn;i++)
    {
        int tmp=1ll*C(n,i)*C(m,i)%mod*fac[i]%mod*ci_m[n-i]%mod*ci_n[m-i]%mod;
        add(ans,(i&1)?mod-tmp:tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8064
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] w = new int[n];
      int s1 = 0;
      int s2 = 0;
      int count = 0;
      for(int i = 0;i < n;i++){
      	w[i] = sc.nextInt();
        s1 += w[i];
      }
      for(int i = 0;i < n && s1 > s2;i++){
      	s1 -= w[i];
        s2 += w[i];
        if(s1-s2 <= w[i+1]*2){
          count = i+1;
          break;
        }
      }
      System.out.println(Math.min(Math.abs(s1-s2),Math.abs(s1-s2-w[count]*2)));
    }
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

long long int mod_pow(long long int x, long long int n, long long int p) {
    long long int res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

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

    long long x, y;
    cin >> x >> y;

    long long a, b;
    a = 2 * y - x;
    b = 2 * x - y;

    if (a % 3 != 0 || b % 3 != 0 || b < 0 || a < 0) {
        cout << 0 << endl;
    } else {
        a /= 3;
        b /= 3;

        long long c = a + b;

        long long ans = 1;

        long long p = 1;

        for (long long i = 0; i < b; i++) {
            ans *= c - i;
            ans %= mod;

            if (b - i > 0) {
                p *= b - i;
                p %= mod;
            }
        }

        ans = ans * mod_pow(p, mod - 2, mod) % mod;

        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll dp[101][4][2] = {};
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;

  ll init = n[0] - '0';
  dp[1][1][1] = 1;
  dp[1][0][0] = 1;
  dp[1][1][0] = init - 1;

  int size = n.length();
  FOR(i, 1, size) {
    int num = n[i] - '0';
    dp[i + 1][0][0] = dp[i][0][0];
    dp[i + 1][0][1] = 0;
    FOR(j, 1, k + 1) {
      dp[i + 1][j][0] = dp[i][j][0] + dp[i][j - 1][0] * 9;
      if (num != 0) {
        dp[i + 1][j][0] += dp[i][j][1] + dp[i][j - 1][1] * (num - 1);
      }
      if (num == 0) {
        dp[i + 1][j][1] = dp[i][j][1];
      } else {
        dp[i + 1][j][1] = dp[i][j - 1][1];
      }
    }
  }

  ll ans = dp[size][k][0] + dp[size][k][1];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n,k;
    cin>>n>>k;
    cout<<k*2-n<<endl;


    return 0;
}

Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))

MOD = 10 ** 9 + 7


def modInverse(a, p):
    # Fermat's little theorem, a**(p-1) = 1 mod p
    return pow(a, p - 2, p)


def nCr(n, r, p=MOD):
    # Modulo binomial coefficients. TODO: Can try to use lucas's instead?
    num = 1
    den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return num * modInverse(den, p) % p


print((pow(2, N, MOD) - 1 - nCr(N, A) - nCr(N, B)) % MOD)


Measured memory_bytes: 3060
import sys

# sys.stdin = open('c1.in')

M = 10 ** 9 + 7


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve():
    N = 10 ** 5 + 1
    fac = [0] * N
    fac[0] = 1
    for i in range(1, N):
        fac[i] = i * fac[i - 1] % M

    n, m = read_int_list()
    if n == m:
        return 2 * fac[n] * fac[m] % M
    if abs(n - m) == 1:
        return fac[n] * fac[m] % M
    else:
        return 0


def main():
    res = solve()
    print(res)


main()


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX = 510000;
const int MOD = 998244353;
 
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main(){
  COMinit();
  ll N,M,K,ans=0; cin>>N>>M>>K;
  vector<ll> pow(N+1,1);
  for(ll i=1; i<=N; i++) (pow[i]=pow[i-1]*(M-1))%=MOD;
  for(ll i=0; i<=K; i++){
    ll tmp=1;
    tmp*=COM(N-1,i);
    (tmp*=M)%=MOD;
    (tmp*=pow[N-1-i])%=MOD;
    (ans+=tmp)%=MOD;
  }
  if(ans<0) ans+=MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 16720
#include <iostream>
#include <queue>
#include <string>
using namespace  std;

typedef pair<string, int> PAIR;

void fnInput(int &rnQtm, queue<PAIR> &rqPPrc)
{
  int nMaxProc;
  cin >> nMaxProc >> rnQtm;
  
  for (int i = 0; i < nMaxProc; i++)
  {
    string sPrcNam;
    int nPrcTim;
    cin >> sPrcNam >> nPrcTim;
    rqPPrc.push(PAIR(sPrcNam, nPrcTim));
  }
}

void fnSchedule(int nQtm, queue<PAIR> &rqPPrc)
{
  int nTtlTim = 0;
  while (rqPPrc.size())
  {
    PAIR PProcess = rqPPrc.front(); rqPPrc.pop(); 
    if (PProcess.second > nQtm)
    {
      PProcess.second -= nQtm;
      rqPPrc.push(PProcess);
      nTtlTim += nQtm;
    }
    else
    {
      nTtlTim += PProcess.second;
      cout << PProcess.first << " " << nTtlTim << endl;
    }
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int nQtm;
  queue<PAIR> qPPrc;
  
  fnInput(nQtm, qPPrc);
  fnSchedule(nQtm, qPPrc);

  return 0;
}

Measured memory_bytes: 4408
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
l=[a,b,c,d,e]
k=[]
for i in l:
    m=10
    for j in range(14):
        if 10*j-i>=0:
            m=10*j-i
            break
    k.append(m)
print(sum(l)+sum(k)-max(k))


Measured memory_bytes: 38384
package main

import "fmt"

func divmod(a, b int) (int, int) {
	return a / b, a % b
}

func main() {
	var s int
	fmt.Scanln(&s)
	hh, s := divmod(s, 60*60)
	mm, ss := divmod(s, 60)
	fmt.Printf("%d:%d:%d\n", hh, mm, ss)
}


Measured memory_bytes: 1128
d1=input().split()
d2=input().split()

def roll(Dice,Vector):
    if Vector == "N":
        c=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=c
    elif Vector == "W":
        c=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=c
    elif Vector == "E":
        c=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=c
    elif Vector == "S":
        c=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=c

v=list("NNNNWNNNWNNNENNNENNNWNNN")
f=0
for item in v:
    roll(d2,item)
    if d1==d2:
        print("Yes")
        f+=1
        break
if f==0:
    print("No")


Measured memory_bytes: 5572
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,s,t,tot,head[N],nex[N],to[N],a[N],b[N];
ll disa[N],disb[N];
ll ans[N];
void add(int u,int v,int wa,int wb){to[++tot]=v;nex[tot]=head[u];head[u]=tot;a[tot]=wa;b[tot]=wb;}
struct node
{
    int u;
    ll x;
    node(int u=0,ll x=0):u(u),x(x){}
    bool operator<(const node&o)const
    {
        return x>o.x;
    }
};
priority_queue<node>q;
bool vis[N];
void solvea(int s)
{
    memset(vis,false,sizeof(vis));
    q.push(node(s,0));
    disa[s]=0;
    while(!q.empty())
    {
        int u=q.top().u;q.pop();
        if(vis[u]) continue;
        vis[u]=true;
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];
            //cout<<u<<' '<<v<<' '<<disa[v]<<' '<<disa[u]+a[i]<<endl;
            if(disa[v]>disa[u]+a[i])
            {
                disa[v]=disa[u]+a[i];
                q.push(node(v,disa[v]));
            }
        }
    }
}
void solveb(int s)
{
    memset(vis,false,sizeof(vis));
    q.push(node(s,0));
    disb[s]=0;
    while(!q.empty())
    {
        int u=q.top().u;q.pop();
        if(vis[u]) continue;
        vis[u]=true;
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];
            if(disb[v]>disb[u]+b[i])
            {
                disb[v]=disb[u]+b[i];
                q.push(node(v,disb[v]));
            }
        }
    }
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=1;i<=m;i++)
    {
        int u,v,a,b;
        scanf("%d%d%d%d",&u,&v,&a,&b);
        add(u,v,a,b);
        add(v,u,a,b);
    }
    memset(disa,inf,sizeof(disa));
    memset(disb,inf,sizeof(disb));
    solvea(s);
    solveb(t);
    for(int i=1;i<=n;i++)
        ans[i]=disa[i]+disb[i];
    for(int i=n-1;i>=1;i--)
        ans[i]=min(ans[i],ans[i+1]);
    for(int i=1;i<=n;i++)
        printf("%lld\n",1000000000000000ll-ans[i]);
}


Measured memory_bytes: 10100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int a,b;
	cin >> a >> b;
  	if (a%3==0 or b%3==0 or (a+b)%3==0){
      cout<<"Possible";
    }
  	else{
      cout<<"Impossible";
    }
  }

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

int main(){
 int A1,A2,A3;
  
  cin >> A1 >>A2 >> A3;
  
  int sum;
  sum=A1+A2+A3;
  
  if(sum>=22){
    cout << "bust" << endl;
  }
  
  else{
   cout << "win" << endl; 
  }
  
}

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

public class Main {
    private static final int MINIMUM = 1;

    public static String process(TestCase testCase) {
        final int N = testCase.N;
        final int K = testCase.K;

        return String.valueOf(numOpsNeeded(K, N - 1));

//        final List<Integer> A = testCase.A;
//
//        long count = 0, op = 0;
//        for (int i = 0; i < N; ++i) {
//            if (A.get(i) == MINIMUM) {
//                if (count >= K - 2) {
//                    op = op + numOpsNeeded(K, count);
//                    count = 0;
//                }
//            } else {
//                count++;
//            }
//        }
//        op = op + numOpsNeeded(K, count);
//        return String.valueOf(op);
    }

    private static long numOpsNeeded(int k, long count) {
        return (count + (k - 1) - 1) / (k - 1);
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            A.add(sc.nextInt());
        }

        return new TestCase(N, K, A);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final int K;
        final List<Integer> A;

        public TestCase(int N, int K, List<Integer> A) {
            this.N = N;
            this.K = K;
            this.A = A;
        }
    }
}


Measured memory_bytes: 50476
a, b, k = map(int, input().split())
if (b-a+1) <= 2 * k :
    count = a
    while count <= b :
        print(count)
        count += 1
else :
    for i in range(k) :
        print(a+i)
    for i in range(k) :
        print(b-((k-1)-i))


Measured memory_bytes: 9116
#include <stdio.h>
int main(void){
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    int ans = 0;
    int i = 1;
    while (i != 2){
        i = a[i-1];
        ans++;
        if (ans >= n){
            ans = -1;
            break;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    int N, K;
    cin >> N >> K;
    int ans = (N - 1) * (N - 2) / 2;
    vector<pair<int, int>> res;
    rep2(i, 2, N + 1) {
        res.emplace_back(make_pair(1, i));
    }
    if (ans < K) {
        cout << -1 << endl;
        return 0;
    }
    if (ans != K) {
        for (int i = 2; i <= N; ++i) {
            for (int j = i + 1; j <= N; ++j) {
                if (i == j) {
                    continue;
                } else {
                    res.emplace_back(make_pair(i, j));
                    ans -= 1;
                    if (ans == K) {
                        break;
                    }
                }
            }
            if (ans == K) {
                break;
            }
        }
    }
    cout << res.size() << endl;
    rep(i, res.size()) {
        cout << res[i].first << " " << res[i].second << endl;
    }
}


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

int main()
{
    long A, B;
    cin >> A >> B;
    if (A < B)
    {
        int tmp = B;
        B = A;
        A = tmp;
    }
    long p = A * B;
    int r = A % B;
    while (r != 0)
    {
        A = B;
        B = r;
        r = A % B;
    }
    cout << p / B << endl;
}


Measured memory_bytes: 256
use std::cmp;
fn main() {
    let mut sc = Scanner::new();
    let h = sc.usize_read();
    let w = sc.usize_read();
    let mut map = vec![vec![0; w]; h];

    for i in 0..h {
        for j in 0..w {
            map[i][j] = sc.usize_read();
        }
    }

    let mut ans = vec![];
    for i in 0..h {
        for j in 0..w {
            if map[i][j] % 2 == 1 {
                if j == w - 1 {
                    if i != h - 1 {
                        map[i][j] -= 1;
                        map[i + 1][j] += 1;
                        ans.push((i, j, i + 1, j));
                    }
                } else {
                    map[i][j] -= 1;
                    map[i][j + 1] += 1;
                    ans.push((i, j, i, j + 1));
                }
            }
        }
    }

    println!("{}", ans.len());
    for &(i, j, ni, nj) in ans.iter() {
        println!("{} {} {} {}", i + 1, j + 1, ni + 1, nj + 1);
    }
}
struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 13304
#include <cstdio>
int quick_power(int a,int b,int Mod){
	int ans=1;
	while(b){
		if(b&1){
			ans=1ll*ans*a%Mod;
		}
		b>>=1;
		a=1ll*a*a%Mod;
	}
	return ans;
}
const int Maxn=10000;
const int Mod=998244353;
int f[Maxn+5][Maxn+5];
int n,k;
char a[Maxn+5],b[Maxn+5];
int s_1,s_2;
int frac[Maxn+5],inv_f[Maxn+5];
void init(){
	frac[0]=1;
	for(int i=1;i<=Maxn;i++){
		frac[i]=1ll*frac[i-1]*i%Mod;
	}
	inv_f[Maxn]=quick_power(frac[Maxn],Mod-2,Mod);
	for(int i=Maxn-1;i>=0;i--){
		inv_f[i]=1ll*inv_f[i+1]*(i+1)%Mod;
	}
}
int C(int n,int m){
	return 1ll*frac[n]*inv_f[m]%Mod*inv_f[n-m]%Mod;
}
int main(){
	init();
	scanf("%s",a+1);
	scanf("%s",b+1);
	while(a[++n]!='\0');
	n--;
	for(int i=1;i<=n;i++){
		if(a[i]=='1'){
			k++;
		}
		if(a[i]=='1'&&b[i]=='1'){
			s_1++;
		}
		else if(a[i]=='1'){
			s_2++;
		}
	}
	f[0][0]=1;
	for(int i=0;i<=s_1;i++){
		for(int j=1;j<=s_2;j++){
			if(i==0&&j==0){
				continue;
			}
			f[i][j]=(f[i][j]+1ll*f[i][j-1]*j%Mod*j)%Mod;
			if(i>0){
				f[i][j]=(f[i][j]+1ll*f[i-1][j]*i%Mod*j)%Mod;
			}
		}
	}
	int ans=0;
	for(int i=0;i<=s_1;i++){
		ans=(ans+1ll*f[s_1-i][s_2]*frac[i]%Mod*frac[i]%Mod*C(s_1,i)%Mod*C(k,i))%Mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 71912
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
using namespace std;
int main(){

	long long n;
	
	while(cin>>n,n!=0){
		long long c=0;
		while(n!=1){
			if(n%2==0)
				n=n/2;
			else
				n=n*3+1;
			c++;
		}
		cout<<c<<endl;
	}
	
	
}

Measured memory_bytes: 1156
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        a: u64,
        b: u64,
        c: u64,
    }
    match c.cmp(&(a + b)) {
        Ordering::Less => println!("{}", b + c),
        Ordering::Greater => println!("{}", a + 2 * b + 1),
        Ordering::Equal => println!("{}", b + c),
    }
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  string s = stin();
  if(s[1] == 'B') {
    cout << "ARC";
  } else {
    cout << "ABC";
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

int dp[1<<14][21];

int dfs(int total_players,int upto[21],
	int current_stones,int player_idx){
  if(dp[current_stones][player_idx] != -1){
    return dp[current_stones][player_idx];
  }
  if(current_stones == 0){
    return 1;
  }

  int res = 0;

  for(int use = 1; 
      use <= upto[player_idx] 
	&& current_stones - use >= 0; 
      use++){
    if(dfs(total_players,upto,
	   current_stones - use,
	   (player_idx + 1) % total_players) == 0){
      res = 1;
      break;
    }
  }
  return (dp[current_stones][player_idx] = res);
}

int main(){
  int total_players;
  while(~scanf("%d",&total_players)){
    if(total_players == 0) break;

    int initial_stones;
    scanf("%d",&initial_stones);

    int upto[21];
    memset(upto,0,sizeof(upto));
    for(int player_idx=0;player_idx < total_players * 2;player_idx++){
      scanf("%d",upto + player_idx);
    }

    memset(dp,-1,sizeof(dp));
    printf("%d\n",dfs(total_players * 2,upto,initial_stones,0));
  }
}

Measured memory_bytes: 2968
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int w[n];
  for(int i = 0; i < n; i++) cin >> w[i];

  int ans = INF_INT;
  for(int i = 0; i < n; i++){
    int s = 0, t = 0;
    for(int j = 0; j <= i; j++){
      s += w[j];
    }
    for(int j = i + 1; j < n; j++){
      t += w[j];
    }
    ans = min(ans, abs(s - t));
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

//dp[i][j] : 
//先頭i文字として考えられるのものうち,
//13で割った余りがjであるもの.
ll dp[MAX_N][13];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, c, k;
	cin >> n >> c >> k;

	vector<ll> t(n);
	rep(i, n) cin >> t[i];

	sort(all(t));

	ll ans = 0;
	ll l = 0, r = 0;
	while (r < n) {
		while (r < n && r - l + 1 <= c && t[r] - t[l] <= k) {
			r++;
		}
		ans++;
		l = r;
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 1024
def solve(idx, money, current)
  return money if current.all? { |u| u >= X }
  return -1 if idx >= N

  s1 = solve(idx + 1, money, current.dup)
  M.times do |i|
    current[i] += UNDERSTANDINGS[idx][i]
  end
  s2 = solve(idx + 1, money + PRICES[idx], current.dup)

  return s2 if s1 == -1
  return s1 if s2 == -1

  [s1, s2].min
end

N, M, X = gets.split.map(&:to_i)
a = N.times.map { gets.split.map(&:to_i) }
PRICES = []
UNDERSTANDINGS = []
a.each do |a1|
  PRICES << a1[0]
  UNDERSTANDINGS << a1[1..-1]
end

current = Array.new(M, 0)
puts solve(0, 0, current)


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

#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

// vector<vector<int>> data(3, vector<int>(4));

const string YES = "Yes";

typedef pair<ll, ll> P;
#define MAX_V 200001
struct edge {
    ll to, cost;
};
vector<edge> g[MAX_V];
ll d[MAX_V];
ll res[MAX_V];

void dijkstra(int s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < g[v].size(); i++) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                res[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

// void solve(long long N, vector<string> S){
// 	// グラフ初期設定
// 	rep(i, N) {
// 		rep(j, N) {
// 			if (S[i][j] == '1') {
//				// e2を用意して双方向貼ることもできる
// 				edge e1 = {j,1};
// 				g[i].push_back(e1);
// 			}
// 		}
// 	}
//
// 	ll res = 0;
// 	rep(i, N) {
// 		dijkstra(i);
// 		rep(j, N) {
// 			res = max(res, d[j]);
// 		}
// 	}
// 	cout << res+1 << endl;
// }

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B) {
    rep(i, M) {
        edge e1 = {A[i], 1};
        g[B[i]].push_back(e1);
        edge e2 = {B[i], 1};
        g[A[i]].push_back(e2);
    }
    dijkstra(0);
    cout << "Yes" << endl;
    rep(i, N - 1) { cout << res[i + 1] + 1 << endl; }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
        A[i]--;
        B[i]--;
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 25692
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    long l[n];
    for(int i=0;i<n;i++)cin >> l[i];
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i] == l[j] || l[i]==l[k] || l[j]==l[k])continue;
                if(l[i]+l[j] >l[k] && l[i]+l[k]>l[j] && l[j]+l[k]>l[i])ans++;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <queue>
#include <cstring>
#define LL long long
const int INF = 0x3f3f3f3f;
const int maxn = 105;
const int S = 0;
const int T = 104;
using namespace std;
struct E{
	int to, nxt, f;
}e[maxn * 1000];
int head[maxn], tot = 1;
void addedge(int u, int v, int f){
	e[++tot].to = v, e[tot].nxt = head[u], e[tot].f = f;
	head[u] = tot;
}
void ins(int u, int v, int f){
	addedge(u, v, f); addedge(v, u, 0);
}
int dep[maxn], now[maxn];
bool bfs(){
	queue <int> q; while (!q.empty()) q.pop(); q.push(S);
	memset(dep, 0, sizeof dep); dep[S] = 1;
	memcpy(now, head, sizeof now);
	while (!q.empty()){
		int cur = q.front(); q.pop();
		for (int i = head[cur]; i; i = e[i].nxt){
			int v = e[i].to;
			if (dep[v] == 0 && e[i].f > 0) dep[v] = dep[cur] + 1, q.push(v);
		}
	}
	return dep[T] != 0;
}
LL dfs(int cur, LL Max){
	if (cur == T) return Max;
	int flow = 0;
	for (int i = now[cur]; i; i = e[i].nxt){
		int v = e[i].to; now[cur] = i;
		if (dep[v] == dep[cur] + 1 && e[i].f > 0){
			LL tmp = dfs(v, min(Max - flow, 1ll * e[i].f));
			flow += tmp;
			e[i].f -= tmp;
			e[i ^ 1].f += tmp;
			if (flow == Max) return flow;
		}
	}
	return flow;
}
LL maxflow = 0;
void Dinic(){
	while (bfs()) maxflow += dfs(S, INF);
}
int n, a[maxn];
LL ans = 0;
int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1; i <= n; i++)
		if (a[i] > 0) ins(i, T, a[i]), ans += 1ll * a[i];
		else ins(S, i, -a[i]);
	for (int i = 1; i <= n; i++)
		for (int j = 2; i * j <= n; j++)
			ins(i, i * j, INF);
	Dinic();
	printf("%lld\n", ans - maxflow);
	return 0;
}

Measured memory_bytes: 384
n = int(input())
s = input()
ans=0
for stone in s:
    if stone==".":
        ans+=1
ans_mn=ans
for i in range(len(s)):
    if s[i]=="#":
        ans+=1
    if s[i]==".":
        ans-=1
    if ans < ans_mn:
        ans_mn=ans
print(ans_mn)

Measured memory_bytes: 3500
#include <iostream>
char c = 0;
int main(void){
    std::cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
        std::cout << "vowel" << std::endl;
    }else{
        std::cout << "consonant" << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  	static Scanner scanner = new Scanner(System.in);
 
	public static void main(String[] args) {
		int[] n = {scanner.nextInt(), scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
    	Arrays.sort(n);
      	System.out.println(Arrays.equals(n, new int[] {1, 4, 7, 9}) ? "YES" : "NO");
    }
}

Measured memory_bytes: 21844
while True:
    try:
        a,da, b = [], [], []
        m = int(raw_input())
        for i in range(m):
            a.append(map(int, raw_input().split()))
        a = sorted(a)
        dax,day = [],[]
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
            day.append(a[i][1]-a[0][1])
        n = int(raw_input())
        for i in range(n):
            b.append(map(int, raw_input().split()))
        b = sorted(b)
        bx,by = [],[]
        for i in b:
            bx.append(i[0])
            by.append(i[1])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0 or by.count(by[i]+day[j]) == 0:
                    break
            else:
                print bx[i]-a[0][0],by[i]-a[0][1]
                break
    except:
        break

Measured memory_bytes: 4484
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 2'009;

int a[N];
int b[N];

int main() {
  int n, k, q;
  scanf("%d %d %d", &n, &k, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    b[i] = a[i];
  }
  a[n] = 0;
  sort(b, b + n);
  int ans = 2'000'000'000;
  for (int s = 0; s < n; ++s) {
    vector<int> cur, all;
    for (int i = 0; i <= n; ++i) {
      if (a[i] < b[s]) {
        sort(cur.begin(), cur.end());
        for (int j = 0; j < (int)cur.size() - k + 1; ++j) {
          all.push_back(cur[j]);
        }
        cur.clear();
      } else {
        cur.push_back(a[i]);
      }
    }
    sort(all.begin(), all.end());
    if ((int)all.size() >= q) {
      ans = min(ans, all[q - 1] - all[0]);
    }
  }
  printf("%d\n", ans);
}


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

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(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;
		}
	}
}

Node * find(Node *u,int k){
	while(u != NIL && k != u->key){
		if(k < u->key)u = u->left;
		else u = u->right;
	}
	return u;
}

void inorder(Node *u){
	if(u==NIL)return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL)return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n,i,x;
	string com;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> com;
		if(com=="insert"){
			cin >> x;
			insert(x);
		}else if(com=="find"){
			cin >> x;
			Node *t = find(root,x);
			cout << (t!=NIL?"yes":"no") << endl;
		}else if(com=="print"){
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 21724
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	d := 1000000007
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(stringLineScan())
	}
	ans := 0
	for i := 1; ; i = i * 2 % d {
		b := 0
		c := n
		for j := 0; j < n; j++ {
			if a[j]%2 == 1 {
				b++
			}
			a[j] /= 2
			if a[j] == 0 {
				c--
			}
		}
		ans += b * (n - b) % d * i
		ans %= d
		if c == 0 {
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7040
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
	int n,m,sum[100000],a,ans=0,k;
	cin>>n>>m;
	sum[0]=0;
	for(int i=1;i<n;i++){
		cin>>a;
		sum[i]=sum[i-1]+a;
	}
	int p=0;
	for(int i=0;i<m;i++){
		cin>>k;
		ans=(ans+abs(sum[p+k]-sum[p]))%100000;
		p+=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1548
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
      
        int[] a = new int[n];
        for(int i = 0 ; i < n; i++) {
          a[i] = sc.nextInt();
          
        }
      
      int max1 = 0;
      int max2 = 0;
      int idx = 0;
      for(int i = 0; i < n; i++) {
        if(a[i] > max2) {
          max2 = a[i];
        }
        if(a[i] > max1) {
          max2 = max1;
          max1 = a[i];
          idx = i;
        }
      }
      
      for(int i = 0; i < n ; i++ ) {
        if(i == idx) {
          System.out.println(max2);
        } else {
          System.out.println(max1);
        }
      }
          
    
    }
}

Measured memory_bytes: 117064
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007
#define N 1000010
ll fac[N],inv[N],ivf[N];
void initmo(){
    fac[0]=ivf[0]=inv[1]=1;
    for(ll i=1;i<N;i++){
	if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }
}
ll C(ll n,ll k){
    return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
int main(){
    initmo();
  ll a,b,c;cin>>a>>b>>c; if(a>N||b>N||c>N)return 0;
  a--; if(b>c)swap(b,c);
  ll ans=0,sum=1;
  for(ll k=a;k<=a+b+c;k++){
      ll cur=po(3,a+b+c-k)*C(k,a)%mod;
      cur=cur*sum%mod;
      ans=(ans+cur)%mod;
      ll s=k-a;
      sum=sum*2%mod;
      if(b<=s)sum-=C(s,b);
      if(c<=s)sum-=C(s,s-c);
  }
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 23680
N = int(input())
line  = list(map(int, input().split()))
money = 1000
k = line[0]
ln = [line[0]]
for i in range(1,N):
    if line[i] != ln[-1]:
        ln.append(line[i])

while len(ln) > 1:
    if ln[0] >  ln[1]:
        ln = ln[1:]
        
    else:
        break
#print(ln)
while len(ln) > 1:
    if ln[-1] < ln[-2]:
        ln = ln[:-1]
        #print(ln)
    else:
        break
#print(ln)

ln1= [ ln[0]]
st = True
for i in range(1,len(ln)-1):
    if (ln1[-1] < ln[i] <ln[i +1]) or (ln1[-1] > ln[i] > ln[i +1]):
        pass
    else:
        ln1.append(ln[i])
            
ln1.append(ln[-1])        
#print(ln1)

for i in range(int(len(ln1)/2)):
    money = ln1[2*i +1] * int(money / ln1[2*i]) + (money %ln1[2*i])
    #print(money)
print(money)
    


Measured memory_bytes: 9256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
int main(){
    ll n, m; 
    cin >> n >> m;
    vector<vector<ll> > v(110000);
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    ll ans = 0;
    priority_queue<ll> p;
    REP(i,1,m+1){
        rep(j, v[i].size())p.push(v[i][j]);
        if(!p.empty()){
            ans += p.top();
            p.pop();
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using psi = std::tuple<std::string, int, int>;
int n, p;
std::string s;
std::vector<std::tuple<std::string, int, int>> vec;
int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s >> p;
        vec.push_back(std::make_tuple(s, p, i+1));
    }
    std::sort(vec.begin(), vec.end(), [](psi &a, psi& b) {
            if (std::get<0>(a) == std::get<0>(b)) {
                return std::get<1>(a) > std::get<1>(b);
            }
            else {
                return std::get<0>(a) < std::get<0>(b);
            }
            });
    for (int i = 0; i < n; i++) {
        std::cout << std::get<2>(vec[i]) << std::endl;
    }
}


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

void solve() {
    int n;
    cin >> n;
    
    int a[n], b[n];
    for(int i=0; i<n; i++) {
        int u, v;
        cin >> u >> v;
        a[i] = u+v;
        b[i] = u-v;
    }
    
    sort(a, a+n);
    sort(b, b+n);
    
    cout << max(abs(a[n-1]-a[0]), abs(b[n-1]-b[0])) << endl;
}

int main() {
	// your code goes here
	
	solve();
	
	return 0;
}


Measured memory_bytes: 5180
import math

a, b = map(int, input().split(" "))

maxp = int(math.sqrt(min(a,b))) + 1

primes = [1]
is_prime = [True] * (maxp + 1)
#print(is_prime)
i = 2
cnt = 1
for i in range(2, maxp+1):
    #print(i)
    if is_prime[i]:
        primes.append(i)
        if a % i == 0 and b % i == 0:
            #print(i)
            cnt += 1
        while a % i == 0:
            a = a // i
        while b % i == 0:
            b = b // i
    j = i * i
    while j <= maxp:
        is_prime[j] = False
        j += i


if a > 1 and b > 1:
    if max(a, b) % min(a, b) == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 14016
#include<stdio.h>
int main()
{
int p[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int M,D,sum;
while(1)
{
sum=0;
scanf("%d",&M);
scanf("%d",&D);if(M==0)break;
if(M==0)break;
for(int i=0;i<M-1;i++)
sum+=p[i];

sum+=D;

switch(sum%7)
{
case 4:
printf("Sunday\n");break;
case 5:
printf("Monday\n");break;

case 6:
printf("Tuesday\n");break;

case 0:
printf("Wednesday\n");break;

case 1:
printf("Thursday\n");break;

case 2:
printf("Friday\n");break;

case 3:
printf("Saturday\n");break;
}
}
return 0;
}

Measured memory_bytes: 1012