akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

int main() {
  ll n, d, a; cin >> n >> d >> a;
  vll xh(n);
  rep(i,n) {
    cin >> xh[i].ff >> xh[i].ss;
  }
  SORT(xh);
  vl imos(n+1,0);
  ll cnt = 0, ans = 0;
  rep(i,n) {
    cnt -= imos[i];
    xh[i].ss -= cnt * a;
    // if (xh[i].ss <= 0) continue;
    ll num = max(0ll, (xh[i].ss+a-1) / a);
    int it = upper_bound(all(xh), mp(xh[i].ff+2*d, infl)) - xh.begin();
    imos[it] += num;
    cnt += num;
    ans += num;
    // cerr << ans << "("<<xh[i].ss<<")" << endl;
  }
  outa(imos, n+1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=3005;
double p[maxn],ans[maxn][maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lf",&p[i]);
    ans[0][0]=1.0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=i;j++)
        {
            ans[i][j]=ans[i-1][j]*(1.0-p[i]);
            if(j) ans[i][j]+=ans[i-1][j-1]*p[i];
        }
    double out=0.0;
    for(int i=(n+1)/2;i<=n;i++)
        out+=ans[n][i];
    printf("%.12lf\n",out);
    return 0;
}


Measured memory_bytes: 47844
h,w=map(int,input().split())
ansa,ansn="",0
for i in range(h):
  s=input().split()
  if "snuke" in s:
    ansa=[chr(ord('A')+j)for j in range(w)][s.index("snuke")]
    ansn=i+1
print(ansa+str(ansn))

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

struct time_check {
    int find_time, end_time;
};

int G[101][101] = {0};
time_check t[101];
int elapsed = 0, n;
stack<int> S;

void dfs(int start) {
    S.push(start);
    while (! S.empty()) {
        elapsed++;
        int u = S.top();
        for (int i = 1; i <= n + 1; i++) {
            if (G[u][i] == 1 && t[i].end_time == 0 && t[i].find_time == 0) {
                t[i].find_time = elapsed;
                G[u][i] = 0;
                S.push(i);
                break;
            }
            if (i == n + 1) {
                t[u].end_time = elapsed;
                S.pop();
            }
        }
    }
}

int main() {
    for (int i = 1; i <= 100; i++) t[i].end_time = 0;

    int u, v, k;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (t[i].end_time == 0) {
            t[i].find_time = ++elapsed;
            dfs(i);
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << t[i].find_time << " " << t[i].end_time << endl;
    }

    return 0;
}

/*
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BRACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

// uに隣接するvを番号順に取得
int next(int u) {
    for (int v = nt[u]; v < n; v++) {
        nt[u] = v + 1;
        if (M[u][v]) return v;
    }
    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r) {
    for (int i = 0; i < n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (! S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BRACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    // 初期化
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for (int u = 0; u < n; u++) {
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) M[i][j] = 0;
    }

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}
*/


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using llint = long long int;
using namespace std;

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

  vector<pair<pair<string, int>, int>> city;

  rep(i, n) {
    string s;
    cin >> s;
    int p;
    cin >> p;
    // -point for desc scores
    city.push_back(make_pair(make_pair(s, -p), i));
  }

  sort(city.begin(), city.end());

  for(auto pair: city) {
    cout << pair.second + 1 << endl;
  }
}


Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))
flag = 1
counter = 0
while flag:
    flag = 0
    for j in reversed(range(1, N)):
        if A[j]<A[j-1]:                
            A[j], A[j-1] = A[j-1], A[j]
            counter += 1
            flag = 1
print(' '.join(map(str, A)))
print(counter)


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    ll sum = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
        mp[a[i]]++;
    }

    ll q; cin >> q;
    for (ll i = 0; i < q; ++i) {
        ll b, c; cin >> b >> c;

        ll t = (c - b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        sum += t;

        cout << sum << endl;
    }
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, m; std::cin >> n >> m;
  vector<pi> ab(n), cd(m);
  rep(i, n) std::cin >> ab[i].fi >> ab[i].se;
  rep(i, m) std::cin >> cd[i].fi >> cd[i].se;
  rep(i, n) {
    int ans = 0, dist = inf;
    int x = ab[i].fi, y = ab[i].se;
    rep(j, m) {
      int px = cd[j].fi, py = cd[j].se;
      int tmp = abs(x-px)+abs(y-py);
      if (dist > tmp) dist = tmp, ans = j;
    }
    std::cout << ans+1 << "\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int main()
{

  int n,m,c,count(0);
  cin>>n>>m>>c;
  for(int i=0 ;i<m && cin>>A[i] ; i++);
   while(n--)
   {
       int sum=c;
       for(int i=0 ;i<m && cin>>arr[i] ; i++)
       {
           sum+=(arr[i]*A[i]);
       }
       if(sum>0)
        count++;

   }
 cout<<count;
 go;
}


Measured memory_bytes: 256
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 3e18
#define ULMAX 18446744073709551615
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

inline int add(int a, int b){a = (a+b); if(a>=mod)a-=mod; return a;}
inline int sub(int a, int b){a = a-b; if(a<0)a+=mod; return a;}
inline int mul(int a, int b){a = (a*b)%mod; return a;}



void mymain(){
  string a,b;
  cin >> a >> b;
  if(b.size() == a.size()+1 && b.substr(0,b.size()-1) == a)
    cout << "Yes" <<endl;
  else cout << "No" << endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;

for(int tt=0;tt<t;tt++){
   //cout << "Case #" << tt+1 <<": ";
   mymain();
}
return 0;
}
/*

*/


Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
typedef struct data{int node,time;}data;
int cmp(void const *a,void const *b){
	return ((data*)a)->time < ((data*)b)->time;
}
int time = 0;
int visited[10001];
data a[10001];
vector<int> vec[10001];
int dfs(int x){
	if(visited[x]==1){
		return 0;
	}
	else{
		int i;
		visited[x]=1;
		for(i=0;i<vec[x].size();i++){
			dfs(vec[x][i]);
		}
		a[x].node = x;
		a[x].time = time++;
	}
}
int main(){
	int n,m,u,v,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&u,&v);
		vec[u].push_back(v);
	}
	for(i=0;i<n;i++){
		visited[i]=0;
	}
	for(i=0;i<n;i++){
		dfs(i);
	}
	qsort(a,n,sizeof(data),cmp);
	for(i=0;i<n;i++){
		printf("%d\n",a[i].node);
	}
	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(){
	char games[15];
  	int i; //loop
  
  	int win;
  	int lose;
  
  scanf("%s",games);
  
  for(i=0;i<sizeof(games);i++){
  	if(games[i] == 'x') lose++;
  }

  
  if(lose<=7) printf("YES");
  else printf("NO");
 
  return 0;
  
}


Measured memory_bytes: 128
// Problem : B - Go to Jail
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

Falling down is an accident, Staying down is a choice.

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    ll n;
    cin>>n;
    vpll dice(n);
    FOR(i,0,n)
    {
    	ll x,y;
    	cin>>x>>y;
    	dice[i].F=x;
    	dice[i].S=y;
    }
    FOR(i,0,n-2)
    {
    	if(dice[i].F==dice[i].S && dice[i+1].F==dice[i+1].S  && dice[i+2].F==dice[i+2].S)
    	{
    		cout<<"Yes";return 0;
    	}
    }
    cout<<"No";
    return 0;
}



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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
int main() {
    lli X, Y;
    cin >> X >> Y;
    ulli ans = X;
    int cnt = 0;
    while (ans <= Y) {
        ans *= 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int x = n;
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x /= 10;
	}
	if (n%sum == 0) puts("Yes");
	else puts("No");
	return 0;
}


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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD 1000000007
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;


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

    int temp;
    cin >> n >> temp;

    cout << (n+temp-1)/temp << endl;
    


    return 0;

}



Measured memory_bytes: 256
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
# N = int(input())
# A = list(map(int,input().split()))
# A, B, N = map(int,input().split())
S = input()
if S=='ABC':
    print ('ARC')
else:
    print('ABC')

Measured memory_bytes: 9096
using Yorukatsu025.Questions;
using Yorukatsu025.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu025.Questions
{
    /// <summary>
    /// ABC160 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            yield return (s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No";
        }
    }
}


namespace Yorukatsu025
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu025.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu025.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=(n)-1;i>=0;--i)
#define REPI(i,a) for(typeof((a).begin()) i=(a).begin();i!=(a).end();++i)
#define REPIR(i,a) for(typeof((a).rbegin()) i=(a).rbegin();i!=(a).rend();++i)
#define FOR(i,a,b) for(typeof(a) i=a;i!=(b);++i)
#define CLEAR(a,v) memset(a,v,sizeof(a))
#define SORT(a) sort(a,a+sizeof(a)/sizeof(a[0]))
#define ALL(v) (v).begin(),(v).end()
#define MP make_pair
#define PB push_back
using namespace std;

typedef vector<int> VI;
typedef long long int LL;

int main(){
  int N;
  VI A, B;
  cin >> N;
  REP(i,N){
    int a, b;
    cin >> a >> b;
    A.PB(a);
    B.PB(b);
  }
  LL ret = 0;
  REPR(i,N){
    LL a = A[i], b = B[i];
    ret += (b - (a + ret) % b) % b;
  }
  cout << ret << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
    long long sum =0;
    for(int i=0;i<N;i++){
        sum += A[i];
    }
    long double p = sum  /(long double) (4 *M);
    sort(A.rbegin(),A.rend());
    if(A[M-1] >= p){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N; cin >> N;
  vector<ll> C(N - 1), S(N - 1), F(N - 1);
  rep(i, 0, N - 1) {
  	cin >> C[i] >> S[i] >> F[i];
  }
  rep(i, 0, N - 1) {
  	ll T = S[i] + C[i];
    rep (j, i + 1, N - 1) {
      	if (T < S[j]) T = S[j];
   		ll b = (T - S[j]) % F[j];
   		if (b != 0) {
			T += F[j] - b;
        }
      	T += C[j];
    }
    cout << T << endl;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

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

int main(){
  int n,k;
  cin >> n >> k;
  ll h[n];
  for(int i=0;i<n;i++) cin >> h[i];
  sort(h,h+n);
  ll ans = 0;
  for(int i=0;i<n-k;i++) ans += h[i];
  cout << ans << endl;
  return 0;
}


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

int main(){
  vector<int>height(10);
  for(int i=0;i<10;i++){
    cin >> height.at(i);
  }
  for(int j=0;j<10;j++){
    for(int i=0;i<9;i++){
      if(height.at(i)>height.at(i+1)){
        swap(height.at(i),height.at(i+1));
      }
    }
  }
cout <<height.at(9)<<endl;
cout <<height.at(8)<<endl;
cout <<height.at(7)<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int a,b;cin >>a>>b;
  if(a<=0 && b>=0){
    cout << "Zero" << endl;
  } else if(a>0){
    cout << "Positive" << endl;
  } else {
    if(((b-a)+1)%2==0){
      cout << "Positive" << endl;
    } else {
      cout << "Negative" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
mod = 998244353
N = int(input())
a = [int(input()) for _ in range(N)]
s = sum(a)
dp = [[0]*(s+1) for _ in range(N)]
dp2 = [[0]*(s+1) for _ in range(N)]
dp2[0][0] = 1
dp2[0][a[0]] = 1
dp[0][0] = 1
dp[0][a[0]] = 2
for i in range(1, N):
    for j in range(s+1):
        dp[i][j] = dp[i-1][j]
        dp2[i][j] = dp2[i-1][j]
        if j-a[i]>=0:
            dp[i][j]+=dp[i-1][j-a[i]]*2
            dp2[i][j] += dp2[i-1][j-a[i]]
        dp[i][j]%=mod
        dp2[i][j]%=mod
if s%2 == 0:
    ans = pow(3, N, mod)-sum(dp[-1][:s//2+1])*3+dp2[-1][s//2]*3
else:
    ans = pow(3, N, mod)-sum(dp[-1][:s//2+1])*3
print(ans%mod)




Measured memory_bytes: 457240
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[10000][10000];
long long u[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=1,f=0;
  string s;
  cin >>a>>b;
  cout <<a+1-b<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int n, m, a, b, c;
  cin >> n >> m >> a >> b >> c;
  vector<pair<int, int>> uv(m);
  for(int i = 0; i < m; i++) cin >> uv[i].first >> uv[i].second;
  vector<vector<int>> p(n);
  for(int i = 0; i < m; i++) p[uv[i].second - 1].push_back(uv[i].first - 1);
  vector<vector<vector<bool>>> bd(n);
  for(int i = 0; i < n; i++) bd[i].resize(102);
  for(int i = 0; i < n; i++) for(int j = 0; j < 102; j++) bd[i][j].resize(n);
  for(int i = 0; i < n; i++) bd[i][0][i] = true;
  for(int l = 0; l < n; l++) for(int i = 0; i < 101; i++) for(int j = 0; j < n; j++) if(bd[l][i][j]) for(int k = 0; k < p[j].size(); k++) bd[l][i + 1][p[j][k]] = true;
  vector<int> ans(n);
  for(int i = 0; i < n; i++) ans[i] = -1;
  ans[n - 1] = 0;

  for(int i = 1; i <= n; i++) {
    bool bb = false;
    vector<int> bit(n);
    for(int j = 0; j < n; j++) if(ans[j] >= 0) for(int k = 0; k < n; k++) {
      if(bd[j][a][k]) bit[k] |= 1;
      if(bd[j][b][k]) bit[k] |= 2;
      if(bd[j][c][k]) bit[k] |= 4;
    }
    for(int j = 0; j < n; j++) if(bit[j] == 7 && ans[j] < 0) {
      if(j == 0) {
        cout << i << endl;
        return 0;
      }
      ans[j] = i;
      bb = true;
    }
    if(!bb) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
  }
  cout << ans[0] << endl;
  return 0;
}

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

#define INF ((int)1e9)
int main(){
  int T, D, L;

  for(;;){
    int X, ans = 0;
    cin>>T>>D>>L;

    if(!T&&!D&&!L) break;

    for(int i = 0, num = INF; i < T-1; i++, num++){
      cin>>X;
      if(X >= L) num = 0;
      if(num < D) ans++;
    }

    cin>>X;

    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3048
N = int(input())
S = input()
w_count = 0
e_count = 0
w_counts = [0 for _ in range(N)]
e_counts = [0 for _ in range(N)]
for i in range(N):
    if S[i] == 'W':
        w_count += 1
    w_counts[i] = w_count
for i in range(N-1, -1, -1):
    if S[i] == 'E':
        e_count += 1
    e_counts[i] = e_count
_min = -1
for i in range(N):
    total = w_counts[i] + e_counts[i]
    if _min == -1:
        _min = total
    if _min > total:
        _min = total
print(_min-1)

Measured memory_bytes: 17872
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
typedef long long         ll;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
#define pb					push_back
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w	", stdout);
#else
#endif

}
string a, b, ans = "";
int mem[3001][3001];
int lcs(int i, int j)
{
	if (i >= sz(a) || j >= sz(b))return 0;
	int& ret = mem[i][j];
	if (~ret)return ret;
	ret = -1;
	if (a[i] == b[j]) {
		// += a[i];
		return  ret=lcs(i + 1, j + 1)+1;
	}
	int ch1 = lcs(i, j + 1);
	int ch2 = lcs(i + 1, j);
	return ret = max(ch1, ch2);

}
void solve(int i, int j)
{
	if (i >= sz(a) || j >= sz(b))return;
	if (a[i] == b[j]) {
		ans += a[i];
		solve(i + 1, j + 1);
	}
	else
	{
		if (mem[i + 1][j] >= mem[i][j+1])
			solve(i + 1, j);
		else solve(i, j + 1);
	}


}
int main()
{
	//GOAT();
	clr(mem, -1);
	cin >> a >> b;
	lcs(0, 0);
	solve(0, 0);
	cout << ans << endl;


}


Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	int N, K; cin >> N >> K;
	int x[120];
	for (int i = 0; i < N; i++)cin >> x[i];
	int out = 0;
	for (int i = 0; i < N; i++) {
		out += 2 * min(x[i], K - x[i]);
	}
	print(out);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main()
{
	int m[N][N];
	int n,u,k,v;
	scanf("%d",&n);
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++) m[i][j] = 0;
	}
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d %d",&u,&k);
		u--;
		for(int j = 0; j < k; j++)
		{
			scanf("%d",&v);
			v--;
			m[u][v] = 1;
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		for( int j = 0; j < n; j++)
		{
			if(j) printf(" ");
			printf("%d",m[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint n; cin >> n;
  lint ans = 0;
  for (int j = 1; j <= n; j++) {
    lint x = n / j;
    ans += j * (x + 1) * x / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i = 0; i < ty - sy; i++)
        cout << 'U';
    for(int i = 0; i < tx - sx; i++)
        cout << 'R';
    for(int i = 0; i < ty - sy; i++)
        cout << 'D';
    for(int i = 0; i <= tx - sx; i++)
        cout << 'L';
    for(int i = 0; i <= ty - sy; i++)
        cout << 'U';
    for(int i = 0; i <= tx - sx; i++)
        cout << 'R';
    cout << "DR";
    for(int i = 0; i <= ty - sy; i++)
        cout << 'D';
    for(int i = 0; i <= tx - sx; i++)
        cout << 'L';
    cout << 'U' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N;
	cin >> N;
	vector<int> A(N);
	int allxor = 0;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		allxor ^= A[i];
	}
	for(int i = 0; i < N; i++){
		cout << (A[i] ^ allxor) << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3916
from collections import deque
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n,m=nii()

tree=[[] for i in range(n)]
for i in range(m):
  a,b=nii()
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(a)

ans=[-1 for i in range(n)]
ans[0]=0

dq=deque()
dq.append(0)
while dq:
  x=dq.popleft()
  for i in tree[x]:
    if ans[i]==-1:
      ans[i]=x
      dq.append(i)

print('Yes')
for i in ans[1:]:
  print(i+1)

Measured memory_bytes: 34732
#include <bits/stdc++.h>
#define faster ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
int main() {
    faster
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                cout << "No\n";
                return 0;
            }
        }
        else {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    return 0;
}


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

int arr[3];

int main( void ) {
    
    cin >> arr[0] >> arr[1] >> arr[2];
    sort( arr, arr + 3 );
    
    if( arr[0] == 5 && arr[1] == 5 && arr[2] == 7 )
        cout << "YES\n";
    else
        cout << "NO\n";
    
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
xs = gets.split.map(&:to_i)
sorted_xs = xs.sort
middle = n / 2 - 1
xs.each do |x|
  i = sorted_xs.bsearch_index { |e| e >= x }
  if i <= middle
    puts sorted_xs[middle + 1]
  else
    puts sorted_xs[middle]
  end
end


Measured memory_bytes: 23396
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
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; }
#define MOD 1000000007

int main(){
    int n;
    cin>>n;
    int d[100][2];
    rep(i,n) rep(j,2) cin>>d[i][j];

    rep(i,n){
        if(d[i][0]==d[i][1]){
            i++;
          	if(i==n) break;
            if(d[i][0]==d[i][1]){
                i++;
              	if(i==n) break;
                if(d[i][0]==d[i][1]) {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int d=1;
  vector<int> data;
  //iとi+1
  //vector<pair<int, int>> d;
  int sakai = 0;
  //どのように並んでいるか
  for (int i = 1; i < N; i++)
  {
    if(S[i-1]!=S[i]){
      sakai++;
    }
  }
  cout << N-1-max(sakai-2*K,0) << endl;

  //cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 256;

int n, x[N], y[N];

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

void solve()
{
    int mx = 0, my = 0, Mx = 0, My = 0;

    x[0] = y[0] = 0;
    repi(i, 1, n) {
        int a, d;
        cin >> a >> d;
        x[i] = x[a] + dx[d];
        mx = min(mx, x[i]);
        Mx = max(Mx, x[i]);
        y[i] = y[a] + dy[d];
        my = min(my, y[i]);
        My = max(My, y[i]);
    }

    cout << Mx - mx + 1 << ' ' << My - my + 1 << endl;
}

int main()
{
    while (cin >> n and n) {
        solve();
    }

    return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;
    vector<i64> p(N);
    rep(i,0,N) cin >> p[i];
    sort(rbegin(p),rend(p));
    p[0]/=2;
    i64 ans=0;
    rep(i,0,N) ans+=p[i];
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

void swap(int &a, int &b) {
	int temp = b;
	b = a;
	a = temp;
}

int partition(std::vector<int> &A, int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; ++j) {
		if (A[j] <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

int main(int argc, char const *argv[]) {
	int N;
	cin >> N;

	std::vector<int> array(N, 0);
	for (int i = 0; i < N; ++i) {
		int temp;
		cin >> temp;
		array[i] = temp;
	}

	int c = partition(array, 0, N - 1);
	for (int i = 0; i < N; ++i) {
		if (c != i) cout << array[i]; else {
			cout << "[" << array[i] << "]";
		}
		if (i != N - 1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1532
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]

    N = 0
    res = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == 0:
                continue
            d = ((-1, 0), (0, -1))
            flag = False
            for dh, dw in d:
                nh = h + dh
                nw = w + dw
                if nh < 0 or H <= nh or nw < 0 or W <= nw:
                    continue
                if A[nh][nw] % 2 != 0:
                    N += 1
                    res.append((h + 1, w + 1, nh + 1, nw + 1))
                    A[h][w] -= 1
                    A[nh][nw] += 1
                    flag = True
                    break
            if flag:
                continue
            d = ((0, 1), (1, 0))
            for dh, dw in d:
                nh = h + dh
                nw = w + dw
                if nh < 0 or H <= nh or nw < 0 or W <= nw:
                    continue
                if A[h][w] % 2 != 0:
                    N += 1
                    res.append((h + 1, w + 1, nh + 1, nw + 1))
                    A[h][w] -= 1
                    A[nh][nw] += 1
                    break

    print(N)
    for r in res:
        print(*r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78808
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    vs64 u(n, (int)1e9);
    vs64 d(n, 0);
    vs32 t(n + 1);
    vs32 a(n + 1);
    t[0] = 0;
    a[n] = 0;
    rep (i, n) cin >> t[i + 1];
    rep (i, n) cin >> a[i];

    rep (i, n)
    {
        if (t[i + 1] > t[i])
        {
            u[i] = d[i] = t[i + 1];
        }
        else
        {
            u[i] = t[i + 1];
            d[i] = 1;
        }
    }

    for (int i = n - 1; i >= 0; --i)
    {
        if (a[i] > a[i + 1])
        {
            if (u[i] < a[i] || d[i] > a[i])
            {
                cout << "0\n";
                return 0;
            }
            u[i] = d[i] = a[i];
        }
        else
        {
            if (a[i] < d[i])
            {
                cout << "0\n";
                return 0;
            }
            if (u[i] > a[i])
            {
                u[i] = a[i];
            }
        }
    }

    s64 ans = 1;
    rep (i, n)
    {
        ans *= (u[i] - d[i] + 1);
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define vll vector<ll>
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define f(i, n) for(int i=0; i<n; ++i)
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define repd(i, a, b) for(int i=a; i>=b; i--)
#define MAXN 200001
#define umapi unordered_map<int, int>
#define umapll unordered_map<ll, ll> 
 
 
int add(int a, int b)
{
    int temp=a+b;
    if(temp<0)
        temp=mod+temp;
    else if(temp>mod)
        temp=temp%mod;
    return temp;
}
 
int mul(int a, int b)
{
    ll temp=(1ll*a*b);
    if(temp<0)
        temp=mod+temp;
    else if(temp>=mod)
        temp=temp%mod;
    return temp;
}

bool perfect(int x)
{
    if(x<0)
        return false;
    if(x==0)
        return true;
    int temp=sqrt(x);
    return (temp*temp)==x;
}

ll dp[MAXN];

int cost(int* A, int n, int curr)
{
    if(dp[curr]!=0)
        return dp[curr];
    if(curr>n)
        return 10000;
    if(curr==n)
        return 0;
    return dp[curr]=min(abs(A[curr]-A[curr+1])+cost(A, n, curr+1), abs(A[curr]-A[curr+2])+cost(A, n, curr+2));
}

 
void solve()
{   
    int n, A[MAXN]; cin>>n;
    f(i, n)
        cin>>A[i+1];
    memset(dp, 0, sizeof(dp));

    rep(i, 2, n)
    {
        if(i==2)
            dp[i]=abs(A[i]-A[i-1])+dp[i-1];
        else
            dp[i]=min(abs(A[i]-A[i-1])+dp[i-1], abs(A[i]-A[i-2])+dp[i-2]);
    }
    //int ans=cost(A, n, 1);
    ll ans=dp[n];
    printf("%lld\n", ans);
}
 

void io()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
 
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //io();
    
    //int t; cin>>t; 
    int tc=0;
    //while(t--)
    {
        tc++;
        //printf("Case #%d: ", tc); 
        solve();
    }  
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back

string a[55], b[55];
int n, m;

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

cin >> n >> m;
rep(i, 0, n-1)cin>>a[i];;
rep(i, 0, m-1)cin>>b[i];

rep(i, 0, n-m+1){

    rep(j, 0, n-m+1){

    bool flag = true;
    rep(k, 0, m-1){
    rep(l, 0, m-1)
    if(a[i+k][j+l]!=b[k][l])flag = false;
    }
    if(flag)return 0*printf("Yes");
    }

}

cout << "No";

return 0;}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7


n = I()
a, t, w, r = 0, 0, 0, 0
for _ in range(n):
    s = S()
    if s[0] == "A":
        a += 1
    elif s[0] == "T":
        t += 1
    elif s[0] == "R":
        r += 1
    else:
        w += 1

print("AC x", a)
print("WA x", w)
print("TLE x", t)
print("RE x", r)


Measured memory_bytes: 83632
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;

    if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2]  && s[2] == s[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate
    import bisect
    n, m, k = map(int, readline().split())
    a = [0] + list(map(int, readline().split()))
    b = [0] + list(map(int, readline().split()))
    a_cum = list(accumulate(a))
    b_cum = list(accumulate(b))

    ans = 0

    for ai in range(n+1):
        cur = a_cum[ai]
        rem = k - cur
        if rem < 0:
            break
        else:
            bi = bisect.bisect_right(b_cum, rem)
        ans = max(ans, ai + bi - 1)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 135236
inf = 10**9

while 1:
    W,H = map(int,raw_input().split())
    if W == 0: break
    S = [map(int,raw_input().split()) for i in xrange(H)]
    c = map(int,raw_input().split())

    costs = [[[[inf]*W for i in xrange(H)] for j in xrange(3)] for k in xrange(3)]
    costs[2][0][0][0] = 0
    que = [[0,0,1,0,0]]
    while que:
        w,h,dw,dh,cost = que.pop(0)
        if (w,h) == (W-1,H-1): continue
        if costs[dw+1][dh+1][h][w] < cost: continue

        dxy = [(dw,dh),(-dh,dw),(-dw,-dh),(dh,-dw)]

        for i in xrange(4):
            dx,dy = dxy[i]
            nw,nh = w+dx,h+dy
            if 0 <= nw < W and 0 <= nh < H:
                ncost = cost+bool(i != S[h][w])*c[i]
                if costs[dx+1][dy+1][nh][nw] <= ncost: continue
                costs[dx+1][dy+1][nh][nw] = ncost
                que.append([nw,nh,dx,dy,ncost])
    print min(min(costs[i][j][H-1][W-1] for i in xrange(3)) for j in xrange(3))
        

Measured memory_bytes: 4344