akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,K,ans=1;

int main(){
    cin>>N>>K;
    rep(i,N){
        ans=min(ans*2,ans+K);
    }
    out(ans);

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  double a;cin>>a;
  double b;cin>>b;
  double x;cin>>x;
  double ans;

  if(x>=a*a*b/2){
    ans=atan((a*a*b-x)*2/(a*a*a))*180/M_PI;
    cout<<setprecision(15)<<ans<<endl;

  }
  else{
    ans=atan(a*b*b/(2*x));
    cout<<setprecision(15)<<ans*180/M_PI<<endl;


  }
return 0;
}

Measured memory_bytes: 512
def main():
    n = input().split()
    a = int(n[0])
    b = int(n[1])
    c = int(n[2])
    ans = [a,b,c]
    ans.sort()

    print("{0} {1} {2}".format(ans[0],ans[1],ans[2]))

if __name__ == '__main__':
    main()

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

void dfs(ll start, ll parent, ll * dist1, vector<ll> graph[])
{
    dist1[start] = dist1[parent] + 1;
    // cout << "I am currently at start: " << start << " and my parent is : " << parent << endl;
    for(ll i = 0; i < graph[start].size(); i++)
    {
        if(graph[start][i] == parent)
        {
            continue;
        }
        dfs(graph[start][i], start, dist1, graph);
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, u, v;
    cin >> n >> u >> v;
    vector<ll> graph[n + 2];
    for(ll i = 0; i < n - 1; i++)
    {
        ll x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }


    ll dist1[n + 2], dist2[n + 2];
    dist1[0] = -1;
    dist2[0] = -1;

    dfs(u, 0, dist1, graph);
    dfs(v, 0, dist2, graph);

    ll maxi = 0;
    for(ll i = 1; i <= n; i++)
    {
        if(dist2[i] > dist1[i])
        {
            maxi = max(maxi, dist2[i] - 1);
        }
    }
    cout << maxi << endl;

    return 0;
}

Measured memory_bytes: 12544
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
    
count = [0] * 5
for i in s:
    if i[0] == "M":
        count[0] += 1
    if i[0] == "A":
        count[1] += 1
    if i[0] == "R":
        count[2] += 1
    if i[0] == "C":
        count[3] += 1
    if i[0] == "H":
        count[4] += 1
        
import itertools
ans = 0
for i in itertools.combinations(count, 3):
    ans += i[0] * i[1] * i[2]
print(ans)

Measured memory_bytes: 9752
n = int(input())
if n == 1 or n == 2:
    print(0)

else:
    len = list(map(int, input().split()))

    number = 0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                len.sort()
                if len[i] == len[j] or len[j] == len[k]:
                    continue
                elif len[j] - len[i] < len[k] and len[k] < len[i] + len[j]:
                    number += 1
                else:
                    continue
    print(number)

Measured memory_bytes: 9080
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
switch(n){
case 1: printf("1"); break;
case 2: printf("3"); break;
case 3: printf("4"); break;
case 4: printf("7"); break;
case 5: printf("11"); break;
case 6: printf("18"); break;
case 7: printf("29"); break;
case 8: printf("47"); break;
case 9: printf("76"); break;
case 10: printf("123"); break;
case 11: printf("199"); break;
case 12: printf("322"); break;
case 13: printf("521"); break;
case 14: printf("843"); break;
case 15: printf("1364");  break;
case 16: printf("2207"); break;
case 17: printf("3571"); break;
case 18: printf("5778"); break;
case 19: printf("9349"); break;
case 20: printf("15127"); break;
case 21: printf("24476"); break;
case 22: printf("39603"); break;
case 23: printf("64079"); break;
case 24: printf("103682"); break;
case 25: printf("167761"); break;
case 26: printf("271443"); break;
case 27: printf("439204"); break;
case 28: printf("710647"); break;
case 29: printf("1149851"); break;
case 30: printf("1860498"); break;
case 31: printf("3010349"); break;
case 32: printf("4870847"); break;
case 33: printf("7881196"); break;
case 34: printf("12752043"); break;
case 35: printf("20633239"); break;
case 36: printf("33385282"); break;
case 37: printf("54018521"); break;
case 38: printf("87403803"); break;
case 39: printf("141422324"); break;
case 40: printf("228826127"); break;
case 41: printf("370248451"); break;
case 42: printf("599074578"); break;
case 43: printf("969323029"); break;
case 44: printf("1568397607"); break;
case 45: printf("2537720636"); break;
case 46: printf("4106118243"); break;
case 47: printf("6643838879"); break;
case 48: printf("10749957122"); break;
case 49: printf("17393796001"); break;
case 50: printf("28143753123"); break;
case 51: printf("45537549124"); break;
case 52: printf("73681302247"); break;
case 53: printf("119218851371"); break;
case 54: printf("192900153618"); break;
case 55: printf("312119004989"); break;
case 56: printf("505019158607"); break;
case 57: printf("817138163596"); break;
case 58: printf("1322157322203"); break;
case 59: printf("2139295485799"); break;
case 60: printf("3461452808002"); break;
case 61: printf("5600748293801"); break;
case 62: printf("9062201101803"); break;
case 63: printf("14662949395604"); break;
case 64: printf("23725150497407"); break;
case 65: printf("38388099893011"); break;
case 66: printf("62113250390418"); break;
case 67: printf("100501350283429"); break;
case 68: printf("162614600673847"); break;
case 69: printf("263115950957276"); break;
    
case 78: printf("20000273725560978"); break;
case 79: printf("32361122672259149"); break;
    
case 85: printf("580696784543856761"); break;
case 86: printf("939587134549734843"); break;
default: break;
}
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    int r=0,t,f;
    char c;
    char a[(int)(6*1e5)];
    int l=2*1e5+10,h=2*1e5+10;
    for(int i=0;i<s.length();i++,h++)
    a[h]=s[i];
    
	int q;
    cin>>q;
    while(q--)
    {
    	cin>>t;
    	if(t==1)
    	{
    		r=(r+1)%2;
		}
		else
		{
			cin>>f>>c;
			if((f+r)%2==1)
			{
				l--;
				a[l]=c;
			}
			else
			{
				a[h]=c;
				h++;
			}
		}
	}
	if(r)
	{
		for(int i=h-1;i>=l;i--)
		cout<<a[i];
	}
	else
	for(int i=l;i<h;i++)
	cout<<a[i];
}




Measured memory_bytes: 1104
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int s,w;
  scanf("%d %d\n",&s,&w);
  if(w>=s){
    printf("unsafe\n");
  }
  else{
    printf("safe\n");
  }
  return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll c[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }

    bool a12 = (c[1][0] - c[0][0] == c[1][1] - c[0][1] && c[1][1] - c[0][1] == c[1][2] - c[0][2]);
    bool a23 = (c[2][0] - c[1][0] == c[2][1] - c[1][1] && c[2][1] - c[1][1] == c[2][2] - c[1][2]);
    bool b12 = (c[0][1] - c[0][0] == c[1][1] - c[1][0] && c[1][1] - c[1][0] == c[2][1] - c[2][0]);
    bool b23 = (c[0][2] - c[0][1] == c[1][2] - c[1][1] && c[1][2] - c[1][1] == c[2][2] - c[2][1]);

    if(a12 && a23 && b12 && b23){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
from itertools import permutations
import sys

def main():
    
    N, M, R = map(int, sys.stdin.readline().split())
    r = [i - 1 for i in map(int, sys.stdin.readline().split())]
    
    d = [[float('inf')] * N for _ in range(N)]
    
    for i in range(N):
        d[i][i] = 0
        
    for i in range(M):
        a, b, c = map(int,sys.stdin.readline().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c
        
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    
    ans = 10**12
    
    for each in permutations(r):
        t_dis = 0
        for i in range(R-1):
            t_dis += d[each[i]][each[i+1]]  
        
        ans = min(ans, t_dis)
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int val[105],wt[105];
int N,W;
ll knapsack()
{
    ll k[N+1][W+1];
//    for(int i=0;i<N;i++)
//    {
//        for(int m=0;m<W;m++)
//        {
//            k[i][m] = 0;
//        }
//    }
    //int i,w;
    for(int i=0;i<=N;i++)
    {
        for(int w=0;w<=W;w++)
        {
            if(i==0||w==0)
                k[i][w] = 0;
            else if (w>=wt[i-1])
            {
                k[i][w] = max((val[i-1]+k[i-1][w-wt[i-1]]),k[i-1][w]);
            }
            else
                k[i][w] = k[i-1][w];
        }
    }
    //cout<<k[0][0]<<endl;
    return k[N][W];


}
int main()
{
    cin>>N>>W;
    for(int i=0;i<N;i++)
    {
        cin>>wt[i]>>val[i];
    }
    cout<<knapsack()<<endl;
    return 0;

}


Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main()
{
    int k, s;
    cin >> k >> s;
    int num = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = i; j <= k; j++) {
            for (int u = j; u <= k; u++) {
                if (i + j + u == s) {
                    if ((j == u && i != j) || (i == j && i != u)) {
                        num += 3;
                        //cout << i << j << u << endl;
                    }   
                    else if (i == j && i == u) {
                        num += 1;
                        //cout << i << j << u << endl;
                    }   
                    else {
                        num += 6;
                    }   
                }   
            }   
        }   
    }   
    cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

namespace IntegerMath
{
  int64_t floor_div(int64_t x, int64_t y) {
    return x / y;
  }

  int64_t ceil_div(int64_t x, int64_t y) {
    return (x / y) + std::min(static_cast<int64_t>(1), x % y);
  }

  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }    

  int64_t log10(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log10l( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t number_of_digits(int64_t x) {
    return static_cast<int64_t>(
      ::ceill( ::log10l( 
        static_cast<long double>(x + 1)
      ) )
    );
  }

  uint64_t gcd(uint64_t a, uint64_t b)
  {
    uint64_t n = std::min(a, b), m = std::max(a, b);
    return (n == 0) ? m : gcd(m % n, n);
  }

  uint64_t lcm(uint64_t a, uint64_t b)
  {
    uint64_t d = gcd(a, b);
    return (a % d == 0) ? (a / d) * b : a * (b / d);
  }
};

class Prime
{
private:
  std::set<uint64_t> _primes;

  bool _is_prmie(uint64_t n) const {
    uint64_t m = IntegerMath::sqrt(n);
    for (uint64_t d : _primes) {
      if (n % d == 0) { return false; }
      if (d > m) { break; }
    }
    return true;
  }

public:
  Prime(uint64_t n) {
    _primes.insert(2);

    for (uint64_t i = 3; i <= n; i += 2) {
      if (_is_prmie(i)) {
        _primes.insert(i);
      }
    }
  }

  std::set<uint64_t> set() const { return _primes; }
};

std::map<uint64_t, uint64_t> prime_division(uint64_t n)
{
  std::map<uint64_t, uint64_t> map;

  uint64_t m = IntegerMath::sqrt(n) + 1;

  for (uint64_t p : Prime(m).set()) {
    uint64_t e = 0;

    for (e = 0; n % p == 0; ++e) { n /= p; }

    if (e > 0) { map.emplace(p, e); }

    if (n == 1) { break; }
  }

  if (n > 1) { map.emplace(n, 1); }

  return map;
}

using namespace std;

const uint64_t M = 32;

int main()
{
  uint64_t N;
  cin >> N;

  vector<uint64_t> s(M, 0);
  N_TIMES(m, M - 1) { s[m + 1] += (m + 1) + s[m]; }

  auto calc = [&](uint64_t x) {
    N_TIMES(m, M) { 
      if (x < s[m]) { return m - 1; }
    }
    return static_cast<uint64_t>(0);
  };

  uint64_t T = 0;
  std::map<uint64_t, uint64_t> P = prime_division(N);
  for (auto tuple : P) { T += calc(tuple.second); }
  cout << T << endl;

  return 0;
}

Measured memory_bytes: 11084
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  998244353
const int N = 10000;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll a,b,n;
     cin >> a >> b >> n;
     ll high = 5e6;
     high = min(high,n);
     ll maxi = -1e9;
     for(ll i=0;i<=high;i++)
     {
          ll temp = (a*i)/b  - a*(i/b);
          maxi = max(maxi,temp);
     }
     if(b-1<=n)
     {
          ll i = b-1;
          ll temp = (a*i)/b  - a*(i/b);
          maxi = max(maxi,temp);
     }
     for(ll i=b-1;i>=b-1-high;i--)
     {
          if(i<=n && i>=0)
          {
               ll temp = (a*i)/b  - a*(i/b);
               maxi = max(maxi,temp);
          }
     }
     for(ll i=n;i>=n-high;i--)
     {
          if(i>=0)
          {
               ll temp = (a*i)/b  - a*(i/b);
               maxi = max(maxi,temp);
          }
     }
     cout<<maxi;
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t; 
     for(ll i=1;i<=t;i++)
     {
         // cout<<"Case #"<<i<<": ";
          solve();
     }
}

Measured memory_bytes: 3652
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = -200; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
typedef long double ld;
signed main(){
int a,b,c,k;
cin >> a >> b >>c>>k;
if(a+b>=k){
  if(a<=k){
    cout << a;
  }else{
  cout << k;
  }
}else{
    cout<< a-(k-(a+b));
}
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[100100];
li aa[100100];

int main() {
    li n;
    cin >> n;
    li neg_cnt = 0;
    rin{
        cin >> a[i];
        if (a[i] < 0)neg_cnt++;
        aa[i] = abs(a[i]);
    }
    sort(aa, aa + n);

    li res = 0;
    if (neg_cnt % 2 == 0 ) {
        rin{
            res += abs(a[i]);
        }
    } else {
        res -= aa[0];
        repp(i, 1, n) {
            res += aa[i];
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
#include <utility>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define LL long long;


int n, x, ans = 1, tmp;
int l[102];


int main() {

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

	for (int i = 0; i < n; i++) {
		tmp += l[i];
		if (x < tmp) break;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
g = [[] for i in range(n)] #g[i]:点iに隣接している点のリスト
for i in range(m):
    x,y = map(int,input().split()) 
    x,y = x-1,y-1
    g[x].append(y)
    g[y].append(x)

for i in g[0]:
    if n-1 in g[i]:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

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

const string YES = "YES";
const string NO = "NO";

void solve(long long a, long long b, long long c){
    if (b - a == c - b) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
    return 0;
}


Measured memory_bytes: 256
#pragma region Header
#define _CRT_SECURE_NO_WARNINGS
#define FOR(i,s, e) for(int i = s; i<e; ++i)
#define rFOR(i,s, e) for(int i=s; i>=e; --i)
#define loop(len) for(int i=0; i<len; ++i)
#define rloop(len) for(int i=len-1; i>=0; --i)
#define iPair pair<int,int>
#define LPair pair<ll,ll>
#define vecP(t,t2) vector<pair<t,t2>>
#define uoMP(t, t2) unordered_map<t, t2>
#define pb push_back
#define pp pop_back
#define beg_end(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define ForFor(s, e) for(int i = s; i<e; ++i) for(int j=s; j<e; ++j)
#define MrN ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long  ll;
typedef long double  ld;
#include<bits/stdc++.h>
using namespace std;
#pragma endregion

string s1, s2, lcmString;
const int Size = 3e3 + 5;
int DP[Size][Size];

int lcm(int i, int j){
	if(i >= s1.size() || j >= s2.size())
		return 0;
	
	if(DP[i][j] != -1)
		return DP[i][j];

	if(s1[i] == s2[j])
		return DP[i][j] = lcm(i+1, j+1) + 1;

	return DP[i][j] = max(
		lcm(i+1, j),
		lcm(i, j+1)
	);
}

int main() {
	MrN;
	//freopen("input.txt", "r", stdin);
	memset(DP, -1, sizeof(DP));
	cin >> s1 >> s2;

	lcm(0, 0);

	int i = 0, j = 0;
	while(i < s1.size() && j < s2.size()){

		if(s1[i] == s2[j]){

			lcmString += s1[i];
			i++; j++;

		} else if(DP[i+1][j] > DP[i][j+1])
			i++;
		else
		 j++;

	}

	cout << lcmString << '\n';

	return 0;
}

Measured memory_bytes: 39172
#include <bits/stdc++.h>
using namespace std; 
int main(){
 int n,c;
 cin>>n>>c;
 int a[c];
 int b=0;
 for (int i=0 ; i<c ; i++){
     cin>>a[i];
     b=b+a[i];
 }
int Q=b/(n+1);
int R=b%(n+1);
     if(R==0){
         cout<<Q<<endl;
     }else{
         cout<<Q+1<<endl;}
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  in6 n;
  cin >> n;
  vi data(n);
  rep(i,n) cin >> data[i];
  sort(all(data));
  in6 a = data[n/2-1], b = data[n/2];
  cout << b-a;
  hinata;
}


Measured memory_bytes: 640
N, L = map(int, input().split())
a = list((map(int, input().split())))
longest = 0
longest_i = N
for i in range(N-1):
    knot = a[i]+a[i+1]
    if knot > longest:
        longest = knot
        longest_i = i+1
if longest < L:
    print("Impossible")
else:
    print("Possible")
    for i in range(1,longest_i):
        print(i)
    for j in range(N-1,longest_i-1,-1):
        print(j)


Measured memory_bytes: 14052
h, w = map(int, input().split())
table = [list(input()) for _ in range(h)]

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
  for  j in range(w):
    if table[i][j] == "#":
      for k in range(4):
        tx, ty = j + mx[k], i + my[k]
        if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "#":
          break
      else:
        print("No")
        exit(0)
print("Yes")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    cin >> N;
    VLL A(N);
    map<ll, ll> s;
    ll sum=0;
    rep(i,N){
        cin >> A[i];
        s[A[i]]++;
        sum+=A[i];
    }
    ll Q;
    cin >> Q;
    VLL B(Q), C(Q);
    VLL ans;
    rep(i,Q){
        cin >> B[i] >> C[i];
        ll tmp=s[B[i]];
        s[B[i]]=0;
        sum-=tmp*B[i];
        if(s[C[i]]==0){
            s[C[i]]=tmp;
        }
        else{
            s[C[i]]+=tmp;
        }
        sum+=(C[i]*tmp);
        ans.PB(sum);
    }
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 12268
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;
constexpr int mod = 1000000007;
constexpr int maxn = 100000;

namespace arithmetic {
	class utils {
	private:
	public:
		template<typename T>
		static multiset<T> factor(T n) {
			T m = n;
			multiset<T> ret;
			for (T i = 2; i <= m && i*i <= n;i++) {
				while (m % i == 0) {
					ret.insert(i);
					m = m / i;
				}
			}
			if (m != 1) ret.insert(m);
			return ret;
		}

		template<typename T>
		static long long gcd(T a, T b) {
			if (b == 0) return a;
			return gcd(b, a % b);
		}

		template<typename T>
		static pair<T, T> extgcd(pair<T, T> a) {
			if (a.second == 0) return make_pair(a.first, 0);
			auto t = extgcd(make_pair(a.second, a.first % a.second));
			return make_pair(t.second, t.first - t.second * (a.first / a.second));
		}

		template<class T>
		class combination {
		private:
			map<pair<T,T>,T> dp;
		public:
			T compute(T n, T k) {
				if (k == 0) return T(1);
				if (dp.find(make_pair(n, k)) == dp.end()) {
					dp[make_pair(n, k)] = (compute(n - 1, k - 1) * n) / k;
				}
				return dp[make_pair(n, k)];
			}
		};

	};

	template <typename T>
	class modulo {
	private:
		T n = 0;
	public:
		T mod = 1000000007;
		modulo(T n_,T mod_) {
			mod = mod_;
			n = (n_ + (n_ < 0 ? ((n_ / mod) + 1) * mod : 0)) % mod;
		}
		modulo(T n_) {
			n = (n_ + (n_ < 0 ? ((n_ / mod) + 1) * mod : 0)) % mod;
		}
		modulo() {
			n = 0;
		}
		explicit operator T() const {
			return n % mod;
		}
		modulo operator+(modulo e) {
			return modulo((n + (T)e) % mod, mod);
		}
		modulo operator-(modulo e) {
			return modulo((n - (T)e) % mod, mod);
		}
		modulo operator*(modulo e) {
			return modulo((n * (T)e) % mod, mod);
		}
		modulo operator/(modulo e) {
			return modulo(((n * utils::extgcd(make_pair((T)e, -mod)).first)) % mod, mod);
		}
		bool operator==(modulo e) const{
			return n == (T)e && mod == e.mod;
		}
		bool operator<(modulo e) const{
			return n == (T)e ? mod < e.mod : n < (T)e;
		}
	};
};

int main() {
	int n, m;
	cin >> n >> m;
	map<int, int> q;
	for (auto e : arithmetic::utils::factor(m)) q[e]++;
	arithmetic::utils::combination<arithmetic::modulo<ll>> c;
	arithmetic::modulo<ll> ret(1);
	for (auto e : q) {
		ret = ret * c.compute(e.second + n - 1, e.second);
	}
	cout << (ll)ret << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	static int mod = (int)1e9+7;
	static int[] memo;
	
	public static int dp(int rem) {
		if(rem == 0)
			return 1;
		if(rem < 3)
			return 0;
		if(memo[rem] != -1)
			return memo[rem];
		
		int cnt = 0;
		for(int i = 3; i <= rem; i++)
			cnt = (int)((1l * cnt + dp(rem - i)) % mod);
		
		return memo[rem] = cnt;
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int s = sc.nextInt();
		memo = new int[s + 1];
		Arrays.fill(memo, -1);
		
		pw.println(dp(s));
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 34024
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n,t,x,y;
	cin >> n>>t;
	int min = 1001;
	for (int i=0;i<n;i++){
		cin >> x >> y;
		if (y <= t){
			if (x < min) min = x;
		}		
	}
	if (min == 1001) cout << "TLE";
	else cout << min;
	
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
	int N = 3000;
	int x;
	int y;
	int tmp;
	int counter;
	int list_x[3000] = {};
	int list_y[3000] = {};

for(int i = 1; i < N; i++){ 
	scanf("%d %d",&x,&y);
	counter = i;

	if(x==0 && y==0){
		break;
	}
	if(x>=y){
		tmp = x;
		x = y;
		y = tmp;
	}
	list_x[i] = x;
	list_y[i] = y;

}
	for(int i = 1; i < counter; i++){	
	printf("%d %d\n", list_x[i] ,list_y[i]);
}
	return 0;
}


Measured memory_bytes: 2680
fun main(args: Array<String>) {
    var a = readLine()!!.toInt()
    val set: MutableSet<Int> = mutableSetOf()
    set.add(a)
    for (i in 1 until 1000000) {
        val next = if (a % 2 == 0) a/2 else 3*a+1
        if (set.contains(next)) {
            println(i+1)
            return
        }
        a = next
        set.add(a)
    }
}


Measured memory_bytes: 35692
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int MOD = 1000003;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

long long calcInv(long long a){
    return modPow(a, MOD-2);
}

int main(){
    vector<long long> t(MOD);
    t[0] = 0;
    t[1] = 1;
    for(int i=2;i<MOD;i++) t[i] = t[i-1] * i % MOD;
    int Q; cin >> Q;
    for(int _=0;_<Q;_++){
        int x, d, n; cin >> x >> d >> n;
        if(x == 0 || d == 0){
            cout << modPow(x, n) << endl;
        } else {
            auto inv_d = calcInv(d);
            auto start = x * inv_d % MOD;
            if(start + n - 1 >= MOD){
                cout << 0 << endl;
                continue;
            }
            cout << t[start+n-1] * calcInv(t[start-1]) % MOD * modPow(d, n) % MOD << endl;
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  if(n==25){
    cout << "Christmas" << endl;
  }else if(n==24){
    cout << "Christmas Eve" << endl;
  }else if(n==23){
    cout << "Christmas Eve Eve" << endl;
  }else{
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
struct train{
   int c,s,f; 
};
int main(){
  int n;
  cin>>n;
  vector<train> v(n-1);
  rep(i,n-1)
    cin>>v[i].c>>v[i].s>>v[i].f;
  rep(i,n){
   int now=0;
   for (int j = i; j < n-1; ++j){
      if(now<=v[j].s){
         now=v[j].s+v[j].c; 
      }else{
         now+=(v[j].f-(now-v[j].s)%v[j].f)%v[j].f+v[j].c; 
      }
   }
   cout<<now<<endl;
   }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  string s;
  map<char, int> ans, tmp;
  char a = 'a';
  for (int i = 0; i < 26; ++i) {
    ans[a] = INF;
    tmp[a] = 0;
    a++;
  }

  rep(i, n) {
    cin >> s;
    for (int i = 0; i < s.length(); ++i) tmp[s[i]]++;

    a = 'a';
    for (int i = 0; i < 26; ++i) {
      ans[a] = min(ans[a], tmp[a]);
      tmp[a] = 0;
      a++;
    }
  }

  for (auto x : ans)
    for (int i = 0; i < x.second; ++i) cout << x.first;
  cout << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int n, k;
	cin >> n >> k;
	cout << (n - 1 + k - 2) / (k - 1) << "\n";

	return 0;
}

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

using namespace std;
typedef long long ll;

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

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

  vector<ll> cum = a;
  for (int i = 1; i < n; i++) {
    cum[i] += cum[i - 1];
    if (i < k) continue;
    cum[i] -= a[i - k];
  }

  vector<ll> cum2(n);
  for (int i = 0; i < n; i++) {
    cum2[i] = max(0LL, a[i]);
    if (!i) continue;
    cum2[i] += cum2[i - 1];
  }

  ll ans = 0;
  for (int i = k - 1; i < n; i++) {
    ll sum = cum[i];
    sum += cum2[n - 1];
    sum -= cum2[i];
    sum += (i - k < 0 ? 0LL : cum2[i - k]);
    ans = max(ans, max(sum, sum - cum[i]));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int a[10000][10] = {0};

int main(){
	while(true) {
		int x;
		int y;
		cin >> y >> x;
		if ( x == 0 ) break;
		int n = 1;
		for ( int i = 0; i < y; i++ ) {
			for ( int j = 0; j < x; j++ ) {
				cin >> a[j][i];
			}
		}
		int d = 0;
		int m = 0;
		for ( int k = 0; k < ( 1<<(y-1) ); k++ ) {
			int s = 0;
			for ( int j = 0; j < x; j++ ) {
				int c = 0;
				for ( int i = 0; i < y; i++ ) {
					d = k >> i & 1;
					c += a[j][i] ^ d;
				}
				s += max( c , y-c );
			}
			m = max( m , s );
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, t;
    cin >> x >> t;
    cout << max(0LL, x - t) << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int a, b, c;
	cin >> a >> b >> c;

	bool ans = false;
	for(int i = a; i <= a * b; i += a){
		if(i % b == c){
			ans = true;
		}
	}

	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(unsigned long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 510000;


int main() {
  int n;
  cin >> n;
  int ans = n;
  vector<pair<ll,ll>>xl;
  rep(i,n){
    ll x,l;
    cin >> x >> l;
    xl.push_back(make_pair(x,l));
  }
  sort(xl.begin(),xl.end());
  ll right = 0;
  ll left = 0;
  rep(i,n){
    if(i==0) right = xl[0].first+xl[0].second;
    else{
      if(xl[i].first-xl[i].second<right){
        if(xl[i].first+xl[i].second<right){
          right=xl[i].first+xl[i].second;
          left = xl[i].first-xl[i].second<right;
          ans--;
        }
        else ans--;
      }
      else{
        right = xl[i].first+xl[i].second;
        left = xl[i].first-xl[i].second;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==5&&b==5&&c==7)
	printf("YES");
	else if(a==5&&b==7&&c==5)
	printf("YES");
	else if(a==7&&b==5&&c==5)
	printf("YES");
	else
	printf("NO");
	return 0;
}

Measured memory_bytes: 128
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	H := readInt()
	W := readInt()

	a := make([][]int, H)
	for i := range a {
		a[i] = make([]int, W)
		for j := range a[i] {
			a[i][j] = readInt() % 2
		}
	}

	x1 := make([]int, 0, H*W)
	y1 := make([]int, 0, H*W)
	x2 := make([]int, 0, H*W)
	y2 := make([]int, 0, H*W)
	pi := 0
	pj := 0
	for i := 0; i < H; i++ {
		if i%2 == 0 {
			for j := 0; j < W; j++ {
				if i == 0 && j == 0 {
					continue
				}
				if a[pi][pj] == 1 {
					x1 = append(x1, pi)
					y1 = append(y1, pj)
					x2 = append(x2, i)
					y2 = append(y2, j)
					a[i][j] = (a[i][j] + a[pi][pj]) % 2
					a[pi][pj] = 0
				}
				pi, pj = i, j
			}
		} else {
			for j := W - 1; j >= 0; j-- {
				if a[pi][pj] == 1 {
					x1 = append(x1, pi)
					y1 = append(y1, pj)
					x2 = append(x2, i)
					y2 = append(y2, j)
					a[i][j] = (a[i][j] + a[pi][pj]) % 2
					a[pi][pj] = 0
				}
				pi, pj = i, j
			}
		}

	}
	println(len(x1))
	for i := range x1 {
		println(x1[i]+1, y1[i]+1, x2[i]+1, y2[i]+1)
	}

}

// -----------------------------------------------------------------------------


Measured memory_bytes: 14976
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <stack>
#include <list>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, P> P2;
typedef pair<int, pair<P, P> > PPP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int nums[50];
vector<P> res;

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0; i < n; i++){
			cin >> nums[i];
		}
		int l = 0;
		int r = 0;
		while(l < n){
			P p;
			p.first = nums[l];
			r = l;
			while(n > r + 1&& nums[r+1] == nums[r] + 1) r++;
			p.second = nums[r];
			l = r+1;
			res.push_back(p);
		}
		for(int i = 0; i < (int)res.size(); i++){
			if(i != 0) cout << " ";
			cout << res[i].first;
			if(res[i].first != res[i].second){
				cout << "-" << res[i].second;
			}
		}
		cout << endl;
		res.clear();
	}
	return 0;
}

Measured memory_bytes: 0
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def sum2n(n: int):
    return n*(n+1) // 2

s = lc()
n = len(s)+1

yama = []
tani = []
ans = 0

# 左端判定
if s[0] == ">":
    if "<" in s:
        ans += sum2n(s.index("<"))
    else:
        ans += sum2n(n-1)
else:
    tani.append(0)

# 真ん中処理
for i in range(1, n-1):
    if s[i-1] == "<" and s[i] == ">":
        yama.append(i)
    elif s[i-1] == ">" and s[i] == "<":
        tani.append(i)

# 右端判定
if s[-1] == "<":
    if ">" in s:
        ans += sum2n(s[::-1].index(">"))
    else:
        ans += sum2n(n-1)
else:
    tani.append(n-1)

# 山・谷処理
if len(yama) > 0:
    for i in range(len(yama)):
        mx = max(yama[i] - tani[i], tani[i+1] - yama[i])
        mn = min(yama[i] - tani[i], tani[i+1] - yama[i])
        ans += sum2n(mx)
        ans += sum2n(mn-1)

print(ans)

Measured memory_bytes: 90856
N = int(input())
inputData = input().split()
p = [int(x) for x in inputData]
sorted_p = sorted(p)
diff_num = 0
for i in range(N):
    if p[i] != sorted_p[i]:
        diff_num += 1
if diff_num > 2:
    print("NO")
else:
    print("YES")

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

int main() {
	int n;
	cin >> n;
	vector<P> a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	rep(i, n) {
		cout << a[i].second << endl;
	}
	return 0;
}


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

int main()
{
    int n;
    int k;
    string s;
    cin >> k >> s;
    n = s.size();
    if(n<=k)
    {
        for(int i=0;i<n;i++)
            printf("%c",s[i]);
    }
    else
    {
        for(int i=0;i<k;i++)
            printf("%c",s[i]);
        printf("...");
    }
    return 0;
}

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

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

int main() {
    string s;cin>>s;
    int n = s.size();
    rep(i,n){
        if(s[i]=='?'){
            if(i > 0 && s[i-1]=='P')s[i]='D';
            else if(i < n-1 && s[i+1]=='D')s[i]='P';
            else if(i < n-1 && s[i+1]=='?'){
                s[i]='P';
                s[i+1]='D';
            }
            else s[i]='D';
        }
    }
    cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3756
#include <iostream>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;



void solve() {
    int n, k; scanf("%d %d", &n, &k);
    ll sum = 0;
    for (int i = k; i <= n+1; i++) {
        ll minimum = ((ll)(i)*(i-1))/2;
        ll maximum = ((ll)(2*n-i+1)*(i))/2;
        sum += (maximum-minimum+1);
    }
    while (sum > mod) sum -= mod;
    printf("%d\n", (int) sum);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
#include <string.h>

int main()
{
  int i, j;
  char t[1003], p[1003];
  fgets(t, 1002, stdin);
  fgets(p, 1002, stdin);
  if (t[strlen(t)-1]=='\n') t[strlen(t)-1]='\0';
  if (p[strlen(p)-1]=='\n') p[strlen(p)-1]='\0';
  int plen = strlen(p);
  if (plen>strlen(t)) return 0;
  for (i=0; i<strlen(t)-strlen(p)+1; i++) {
    if (t[i]==p[0]) {
      for (j=1; j<plen; j++) {
	if (t[i+j]!=p[j]) break;
      }
      if (j==plen) {
	printf("%d\n", i);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
 
int main(){
 int n,i,j,rank;
 int cards[4][14];
 char type;
 
 cin >> n;
 
 for(i = 0; i < 4; i++){
  for(j = 1; j <= 13; j++){
   cards[i][j] = 0;
  }
 }
 
 for(i = 0; i < n; i++){
  cin >> type >> rank;
   
   if(type == 'S') cards[0][rank] = 1;
   if(type == 'H') cards[1][rank] = 1;
   if(type == 'C') cards[2][rank] = 1;
   if(type == 'D') cards[3][rank] = 1;
 }
 
 for(i = 0; i < 4; i++){
  for(j = 1; j <= 13; j++){
   if(cards[i][j] == 0){
     if(i == 0)
      cout << 'S' << " " << j << endl;
     if(i == 1)
      cout << 'H' << " " << j << endl;
     if(i == 2)
      cout << 'C' << " " << j << endl;
     if(i == 3)
      cout << 'D' << " " << j << endl;
   }
  }
 }
 
 return 0;
}

Measured memory_bytes: 1160
N = int(input())
l = [0]*N
for i in range(N):
    d1,d2 = map(int,input().split())
    if d1==d2:
        l[i] = 1
ans = 0
for i in range(N-2):
    if l[i]+l[i+1]+l[i+2]==3:
        ans = 1
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62556
#include<stdio.h>
#include<string.h>
char str[100],*p;
int i;
int main()
{
	for(;!strstr(p=fgets(str,100,stdin),"END OF INPUT\n");)
	{
		for(i=0;*p;i=*(p++)<33?!printf("%d",i):i+1);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 532
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});


int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (a > x)puts("NO");
	else {
		if (a + b >= x)puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n,a,b,i,s=0;
    cin>>n;
    cin>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%n==0)
        {
            s++;
            break;
        }
    }
    if(s==0)
    {
        cout<<"NG"<<endl;
    }
    else
    {
        cout<<"OK"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620