akhauriyash/Code-Regression huggingface dataset:
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var N = nextInt();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		var A = nextInt();
		list[i] = {};
		for(var j = 0; j < A; j++){
			var tmp = nextIntArray();
			list[i][tmp[0] - 1] = tmp[1];
		}
	}

	var output = 0;
	for(var i = 0; i < (1 << N); i++){
		var isOK = true;
		var count = 0;
		for(var j = 0; j < N; j++){
			if((i & (1 << j)) != 0){
				count++;
				//選ぶ
				var keys = Object.keys(list[j]);
				for(var k = 0; k < keys.length; k++){
					if((i & (1 << keys[k])) != 0 && list[j][keys[k]] == 1){
						
					}else if((i & (1 << keys[k])) == 0 && list[j][keys[k]] == 0){
						
					}else{
						isOK = false;
					}
				}
			}else{
				//選ばない
			}
		}
		if(isOK){
			output = Math.max(output, count);
		}
	}
	myout(output);
}

Measured memory_bytes: 24392
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
int n,k;
cin >> n >> k;
ll int ans = k;
REP(i,n-1) ans *= (k-1);
cout << ans << endl;
}

Measured memory_bytes: 256
/*================================================================
Love China, Love YALI, Love OI!
*   
*   File Name：E.cpp
*   Author：YaliKiWi
*   Date：2019年09月01日
*   Discribe：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s;i<=e;i++)
#define max_(x,y) ((x)>(y)?(x):(y))
#define min_(x,y) ((x)<(y)?(x):(y))
#define dd double
#define ull unsigned long long
#define ll long long
#define maxn 1000+10
int n,ans;
int a[maxn][maxn];
int lleft[maxn];
int nex[maxn];
int pre[maxn];
bool vis[maxn][maxn];
inline bool judge(){
	fo(i,1,n){
		if(lleft[i]>0)return 0;
	}
	return 1;
}
inline void init(){
	fo(i,1,n)lleft[i]=pre[i];
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	fo(i,1,n)
		fo(j,1,n-1)
			cin>>a[i][j];
	fo(i,1,n){
		pre[i]=n-1;
		nex[i]=a[i][1];
	}
	fo(i,1,n*n){
		init();
		int today=0;
		if(judge()){
			cout<<i-1;
			return 0;
		}
		//cout<<endl<<endl;
		fo(j,1,n){
			int nxt=a[j][n-lleft[j]];
			//cout<<j<<" "<<nxt<<endl;
			if(a[nxt][n-lleft[nxt]]==j and vis[nxt][j]==0){
				pre[j]--;
				vis[nxt][j]=1;
				vis[j][nxt]=1;
				pre[nxt]--;
				today++;
			}
		}
		if(!today){
			cout<<-1;
			return 0;
		}
		//cout<<endl;
		//fo(i,1,n)cout<<pre[i]<<" ";
		//cout<<endl;
		//init();
	}
	cout<<-1;
	return 0;
}

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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
#define case(i) "Case #" << i << ": "

template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int n;
    cin >> n;

    bool ok = false;

    for(int i = 1; i < 10; ++i) {
        for(int j = 1; j < 10; ++j) {
            if(i * j == n) ok = true;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define ll long long
typedef long long type;
typedef pair<type,type>pi;
vector<pair<type,pi>>ll,rr;
#define ff first
#define ss second
pi aa[100005],bb[100006];
#define pb push_back
struct Dsu{
    type par[100009];
    Dsu(type n)
    {
        for(type i=0;i<=n;i++)par[i]=i;
    }

    type find(type u)
    {
        if(par[u]==u)return u;
        par[u]=find(par[u]);
        return par[u];
    }
    bool cycle(type u,type v)
    {
        type x=find(u);
        type y=find(v);
        if(x==y)return 1;
        return 0;
    }
    type uni(type u,type v)
    {
        type x=find(u);
        type y=find(v);
        if(x!=y)
        {
            par[y]=x;
        }
    }
};
int main()
{
    type n;cin>>n;
    for(type i=1;i<=n;i++)
    {
        type a,b;
        cin>>aa[i].ff>>bb[i].ff;
        aa[i].ss=i,bb[i].ss=i;
    }
    sort(aa+1,aa+n+1);
    sort(bb+1,bb+n+1);
//    for(type i=1;i<=n;i++)cout<<aa[i].ff<<" "<<aa[i].ss<<endl;
//    for(type i=1;i<=n;i++)cout<<bb[i].ff<<" "<<bb[i].ss<<endl;
    for(type i=2;i<=n;i++)
    {
        type dif=aa[i].ff-aa[i-1].ff;
        ll.pb({dif,{aa[i].ss,aa[i-1].ss}});
        dif=bb[i].ff-bb[i-1].ff;
        ll.pb({dif,{bb[i].ss,bb[i-1].ss}});
    }
    Dsu dd(n);
    type ans=0;
    sort(ll.begin(),ll.end());
//    sort(rr.begin(),rr.end());
//    for(type i=0;i<ll.size();i++)cout<<ll[i].ff<<" "<<ll[i].ss.ff<<" "<<ll[i].ss.ss<<endl;
    type edge=0,i=0;
    for(i=0;i<ll.size();i++)
    {
        type u=ll[i].ss.ff;
        type v=ll[i].ss.ss;
        if(!dd.cycle(u,v))
        {
            dd.uni(u,v);
            edge++;
            ans+=ll[i].ff;
        }
        if(edge==n-1)break;
    }
    cout<<ans<<endl;
}

/*
6
8 3
4 9
12 19
18 1
13 5
7 6

*/


Measured memory_bytes: 11632
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

x,n = inp
p = inp
min = 1e20
ans = -1
(0..101).each do |d|
  next if (p.include?(d))
  if((d-x).abs < min)
    min = (d-x).abs
    ans = d
  end
end
p ans

Measured memory_bytes: 14372
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return x * modpow(x * x % mod, n / 2) % mod;
	return  modpow(x * x % mod, n / 2) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return ans;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}

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

int d, g;
P p[11];
int ans = inf;
signed main() {
	cin >> d >> g;
	rep(i, d) {
		cin >> p[i].first >> p[i].second;
	}
	rep(i, (1 << d)) {
		int sum = 0, cnt = 0;
		vector<P>vec;
		rep(j, d) {
			if ((i >> j) & 1) {
				sum += 100 * (j + 1) * p[j].first + p[j].second;
				cnt += p[j].first;
			}
			else {
				vec.push_back(P(j, p[j].first));
			}
		}
		sort(all(vec), greater<P>());
		if (sum < g) {
			rep(j, vec.size()) {
				bool can = false;
				rep(k, vec[j].second) {
					sum += 100 * (vec[j].first + 1);
					cnt++;
					if(g <= sum) {
						can = true;
						break;
					}
				}
				if(can) {
					break;
				}	
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}


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

#define pb push_back
#define F first
#define S second
#define mp make_pair

#define int long long
const int N = 1e6 + 10, Mod = 1e18 + 7, Sq = 20;

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    long long r, d, x; cin >> r >> d >> x;
    for(int i = 1; i <= 10; i++){
        x = x * r - d;
        cout << x << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
S = "keyence"
line = input()
cnt = 0
for i in range(6):
    string = ""
    if(line.rfind(S[i+1:]) > line.find(S[0:i+1])>= 0): string += line[:line.find(S[0:i+1])+(i+1)] + line[line.rfind(S[i+1:]):]
    #print(line.find("keyenc"), string)
    if(string == S): cnt += 1
if(cnt>0): print("YES")
else: print("NO")

Measured memory_bytes: 3064
N = int(input())
A = []
x = []
y = []

for i in range(N):
	Ai = int(input())
	xi = []
	yi = []
	A.append(Ai)
	x.append(xi)
	y.append(yi)
	for j in range(Ai):
		xij, yij = map(int, input().split(' '))
		xi.append(xij)
		yi.append(yij)

estab = []
for bits in range(2 ** N):
  ok = True
  for i in range(N):
    if (bits >> i) & 1 == 0:
      continue
    for j in range(A[i]):
      if (bits >> (x[i][j] - 1) & 1) != y[i][j]:
        ok = False
        #print('矛盾', i, j, bin(bits), (x[i][j]), (bits >> (x[i][j] - 1) & 1), y[i][j])
  if ok:
    estab.append(bin(bits).count('1'))
    #print('成立', bin(bits))

print(max(estab))

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

// int i,j,k;
const ll MOD = 1000000000 + 7;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string ans;
    while(true){
        
        if(c<=b){
            ans="Yes";
            break;
        }
        else{
            c-=b;
        }
        if(a<=d){
            ans="No";
            break;
        }
        else{
            a-=d;
        }
    }

    
    cout<<ans<<'\n';

    return 0;
}

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

int main(){
  int k=1009,s=0;
  for(int j=0;j<5;j++){
    int a; cin>>a;
    if(a%10==0) s += a;
    else if(a%10<=k%10){
      k=a;
      s += a/10*10 +10;
    }
    else s += a/10*10 +10;
  }
  
  if(k==1009){cout<<s<<endl; return 0;}
  else s = s -(k/10*10 + 10) +k;
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Node {
  double cost;
  int from;
  int to;
  Node() {;}
  Node(double c, int f, int t) : cost(c), from(f), to(t) {;}
  bool operator<(const Node &rhs) const {
    return cost > rhs.cost;
  }
};

struct Data {
  int x;
  int y;
  double v;
  Data() {;}
  Data(int x, int y, double v) : x(x), y(y), v(v) {;}
};

double matrix[210][210];
int capacity[210][210];
int parent[210];
Data troops[110];
Data bases[110];

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n|m) {
    REP(i, n) {
      int x, y;
      double v;
      scanf("%d %d %lf", &x, &y, &v);
      troops[i] = Data(x, y, v);
    }
    REP(i, m) {
      int x, y;
      scanf("%d %d", &x, &y);
      bases[i] = Data(x, y, 0);
    }
    REP(i, 210) REP(j, 210) { matrix[i][j] = 1e+20; }
    MEMSET(capacity, 0);
    REP(i, n) {
      matrix[n + m][i] = 0;
      capacity[n + m][i] = 1;
      REP(j, m) {
        matrix[j + n][n + m + 1] = 0;
        capacity[j + n][n + m + 1] = 1;
        matrix[i][j + n] = hypot(troops[i].x - bases[j].x, troops[i].y - bases[j].y) / troops[i].v;
        matrix[j + n][i] = hypot(troops[i].x - bases[j].x, troops[i].y - bases[j].y) / troops[i].v;
        capacity[i][j + n] = 1;
      }
    }
    double ans = 0.0;
    REP(i, m) {
      MEMSET(parent, -1);
      priority_queue<Node> que;
      que.push(Node(0, n + m, n + m));
      while (!que.empty()) {
        Node node = que.top();
        que.pop();
        if (parent[node.to] != -1) { continue; }
        parent[node.to] = node.from;
        if (node.to == n + m + 1) {
          ans = max(ans, node.cost);
          break;
        }
        int from = node.to;
        REP(to, n + m + 2) {
          if (parent[to] != -1) { continue; }
          if (capacity[from][to] == 0) { continue; }
          double ncost = max(node.cost, matrix[from][to]);
          que.push(Node(ncost, from, to));
        }
      }
      int from = parent[n + m + 1];
      int to = n + m + 1;
      while (from != to) {
        capacity[from][to]--;
        capacity[to][from]++;
        from = parent[from];
        to = parent[to];
      }
    }
    printf("%.8lf\n", ans);
  }
}

Measured memory_bytes: 1892
class Card(object):
    def __init__(self, *data):
        self.chr, self.num = data
        self.num = int(self.num)
        self.chr = str(self.chr)


def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j].num <= x.num:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


def merge(A, left, mid, right):
    L = A[left:mid] + [Card('A', 10**10)]
    R = A[mid:right] + [Card('A', 10**10)]
    i = 0
    j = 0
    # 右と左比べて小さい方をとってくる
    for k in range(left, right):
        if L[i].num <= R[j].num:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


# マージソートとクイックソート比べる
n = int(input())
A = [Card(*(input().split())) for _ in range(n)]
B = A[:]
C = A[:]

quicksort(B, 0, n-1)
mergeSort(C, 0, n)
flag = True
for b, c in zip(B, C):
    if b is not c:
        flag = False
        break
if flag:
    print('Stable')
else:
    print('Not stable')

for i in range(n):
    print(B[i].chr, B[i].num)


Measured memory_bytes: 28808
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int H, W;
int c[10][10];
int A[210][210];
int cost[10][10];
int main(void)
{
    cin >> H >> W;
    for (int i = 0; i < 10; ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            cin >> c[i][j];
            cost[i][j] = 1e9;
        }
    }

    for (int k = 0; k < 10; ++k)
    {
        for (int i = 0; i < 10; ++i)
        {
            for (int j = 0; j < 10; ++j)
            {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            int a;
            cin >> a;
            if (a != 1 && a != -1)
            {
                ans += c[a][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
 
using namespace std;
 
int main(){
  int n, a, b; cin >> n >> a >> b;
  string str;
  cin >> str;
  int tuuka=0;
  int rank=0;
  for(int i=0; i<n; i++){
    char c = str[i];
    switch(c){
      case 'a':
        if(tuuka<a+b){
          cout << "Yes" << endl;
          tuuka++;
        }else{
          cout << "No" << endl;
        }
        break;
      case 'b':
        rank++;
        if(tuuka<a+b && rank<=b){
          cout << "Yes" << endl;
          tuuka++;
        }else{
          cout << "No" << endl;
        }
        break;
      case 'c':
        cout << "No" << endl;
        break;
    }
  }
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<cinttypes>

using ull = std::uint64_t;
int main(){

	const ull prime_ = 1'000'000'000 + 7;

	std::uint32_t N;
	std::cin >> N;

	std::vector<ull> v( N, ull{} );
	
	ull sum_{};//<10^14
	for( auto& e : v )
	{
		std::cin >> e;
		sum_ += e;
	}
	//const auto sum_mod_ = sum_ % prime_;


	ull ans_{};
	for( const auto e : v )
	{
		//const auto sum_others_ =  sum_-e;
		sum_ -= e;
		ans_ += sum_%prime_ * e % prime_;
		ans_ %= prime_;
	}

//	ans_ %= prime_;
	std::cout << ans_ << "\n";

	return 0;
}

Measured memory_bytes: 4464
package main

import (
	"fmt"
	//"math"
	//"math"
	//"strings"
)

func main() {
	var a,b int
	fmt.Scan(&a,&b)
	if b % a == 0 {
		fmt.Println(a+b)
	}else{
		fmt.Println(b-a)
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)

typedef pair<int,int> P;
typedef long long ll;

const int INF = 1001001001;
const int mod = 1000000007;
const double PI=acos(-1);

int main(){
    ll H,W,D;
    cin >> H >> W >> D;
    vector<pair<ll,pair<ll,ll>>> A;

    rep(h,H) {
        rep(w,W) {
            ll tmp;
            cin >> tmp;
            A.push_back(make_pair(tmp,make_pair(h,w)));
        }
    }
    sort(A.begin(),A.end());

    ll dp[W*H] = {};
    rep(i,W*H) {
        if (i<D) {
            dp[i] = 0;
        }
        else {
            dp[i] = dp[i-D] + abs(A[i].second.first - A[i-D].second.first) + abs(A[i].second.second - A[i-D].second.second);
        }
    }

    int Q;
    cin >> Q;

    rep(i,Q) {
        int L,R;
        cin >> L >> R;
        L--;
        R--;
        cout << dp[R]-dp[L] << endl;
    }


}


Measured memory_bytes: 4980
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int i = 0;
        int j = s.length() - 1;

        for (; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                break;
            }
        }
        for (; j >= i; j--) {
            if (s.charAt(j) == 'Z') {
                break;
            }
        }
        System.out.println(j - i + 1);
    }
}


Measured memory_bytes: 26452
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, x, m = map(int, input().split())
seen = [-1] * m
is_done = True
ans = 0
for i in range(n):
    if i == 0:
        val = x
    else:
        val = val * val % m
    if seen[val] != -1:
        loop_len = i - seen[val]
        loop_val = val
        is_done = False
        cnt = i
        break
    else:
        seen[val] = i
        ans += val
if is_done:
    print(ans)
    exit()
n -= (cnt + 1)

val = loop_val
loop_sum = 0
for i in range(loop_len):
    val = val * val % m
    loop_sum += val
ans += (n // loop_len) * loop_sum

val = loop_val
for i in range(n % loop_len):
    val = val * val % m
    ans += val

print(ans + loop_val)

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

int main() {
  int s;
  int count = 0;
  cin >> s;
  
  count += s/100;
  s = s % 100;
  
  count += s/10;
  s = s % 10;
  
  count += s;
  
  cout << count << endl;
}

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

using namespace std;

int main()
{
    int n, count = 0;
    cin >> n;

    long double d;
    cin >> d;

    for(int i = 1; i <= n; i++)
    {
        long double x, y;
        cin >> x >> y;

        long double temp = (x * x) + (y * y);

        long double l = sqrtl(temp);

        if(l <= d)
            count++;
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
const int p=1e9+7;
int a[3000];
int c[3000];
int v[5000];
long long  n,k;
int mm;
long long mul(long long a,long long b)
{
	long long ans=0;
	for(;b;b>>=1)
	{
		if(b&1)
		{
			ans=(ans+a)%p;
		}
		a=(a+a)%p;
	}
	return ans;
}
int main()
{	
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	long long anss=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[j]<a[i])
			{
				c[i]++;
			}
		}
		for(int j=i+1;j<=n;j++)
		{
			if(a[j]<a[i])
			{
				v[i]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		anss+=mul(k,v[i])+mul((k*(k-1)/2),c[i]);
		anss%=p;
	}
	printf("%lld\n",anss);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int n; cin>>n;
    int four_cnt=0;
    int two_cnt=0;
    rep(i,0,n){
        ll x; cin>>x;
        if(x%4==0){
            four_cnt++;
        }else if(x%2==0){
            two_cnt++;
        }
    }
    if(n%2==1){
        if(four_cnt>=n/2 or four_cnt*2+two_cnt>=n) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;

    }
    if(four_cnt*2+two_cnt>=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 23:14:55
*/

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


int main(){
    string s,t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    
    cin >> s;
    
    for(int i = 0; i < s.length(); i++){
        cout << 'x'; 
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
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 ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  ll x; cin >> x;
  for(ll i = 1; i <= x; i++)
    if(i * (i + 1) / 2 >= x){
      cout << i << endl;
      break;
    }
}


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

int main(void){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  
  while(A>0 && C>0){
    C -= B;
    A -= D;
  }
  
  if(C<=0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,a,b) for(i=(int)a;i<(int)b;i++)
#define revloop(i,a,b) for(i=(int)a;i>=(int)b;i--)
#define stloop(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<int,int>
#define MP make_pair
#define pb push_back
#define ll long long int
#define INF 1000000005
#define PI acos(-1.0)
#define f first
#define s second
int main()
{  std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n,m;
   cin>>n>>m;
   if(n==m)
     cout<<"Draw";
   else
   {
     if(n==1)
         cout<<"Alice";
     else
     {
       if(m==1)
           cout<<"Bob";
       else
       {
        if(n>m)
         cout<<"Alice";
        else
         cout<<"Bob";
       }
     }
   }
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);

P Q[LEN];
int head,tail,n;

int main()
{
  int elaps=0,c;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);
  for (i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }
  head=1,tail=n+1;

  while(head!=tail)
    {
      u=dequeue();
      if(q<=u.t) c=q;
      if(q>u.t) c=u.t;
      u.t-=c;
      elaps+=c;
      if(u.t>0) enqueue(u);
      else
        {
          printf("%s %d\n",u.name,elaps);
        }
    }
  return 0;
}
void enqueue(P x)
{
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue()
{
  P x;
  x=Q[head];
  head=(head+1)%LEN;
  return x;
}

Measured memory_bytes: 12748
/* Author rumoisen */
/* created 2018/10/13 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    bool flag=true;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j!=i&&s[i]==s[j]) flag=false;
        }
    }
    if(flag==true) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

X = list(map(int, input().split()))

def calc_time(x_max, x_min):
    if x_max * x_min >= 0:
        if abs(x_max) > abs(x_min):
            return x_max
        else:
            return abs(x_min)
    else:
        return x_max - x_min + min(abs(x_max), abs(x_min))

def calc_start_and_goal_position(index):
    if index - K >= 0:
        start_index = index - K
    else:
        start_index = 0
    
    if N > index + K + 1:
        goal_index = index + 1
    else:
        goal_index = N - K + 1
    
    return start_index, goal_index

if __name__ == "__main__":
    index = -1
    for i, x in enumerate(X):
        if x >= 0:
            index = i 
            break
    if index == -1:
        index = i
    start_index, goal_index = calc_start_and_goal_position(index)

    time_min = float('inf')
    for i in range(start_index, goal_index):
        time = calc_time(X[i+K-1], X[i])
        if time < time_min:
            time_min = time
    print(time_min)

Measured memory_bytes: 14480
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << a << endl;
    } else if ((a % 2) == (b % 2)) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    if((n&1)&&(n>=3&&n<9))cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}


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

public class Main {
	
	static int n;
	static int[] nums;
	static int result;
	
	static void input() throws IOException {
		n = readInt();
		nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = readInt();
		}
	}
	
	static void process() {
		for (int i : nums) {
			if (isPrime(i)) {
				result++;
			}
		}
	}
	
	static boolean isPrime(int n) {
		if (n == 2) {
			return true;
		} else if (n % 2 == 0) {
			return false;
		}
		
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			if (n % i == 0) {
				return false;
			}
		}
		
		return true;
	}
	
	static void output() {
		System.out.println(result);
	}
	
	static BufferedReader in;
	
	static void initBufferedReader() {
		in = new BufferedReader(new InputStreamReader(System.in));
	}
	
	static String readString() throws IOException {
		return in.readLine();
	}
	
	static int readInt() throws NumberFormatException, IOException {
		return Integer.valueOf(readString());
	}
	
	static int[] readMultiInt() throws IOException {
		String input = readString();
		String[] values = input.split(" ");
		int[] result = new int[values.length];
		for (int i = 0; i < values.length; i++) {
			result[i] = Integer.valueOf(values[i]);
		}
		return result;
	}
	
	static String arrayToString(int[] data) {
		String result = "";
		for (int i = 0; i < data.length; i++) {
			if (i >= data.length - 1) {
				result += String.valueOf(data[i]);
			} else {
				result += String.valueOf(data[i]) + " ";
			}
		}
		return result;
	}
	
	static long factional(int n) {
		int result = 1;
		for (int i = 1; i <= n; i++) {
			result *= i;
		}
		return result;
	}
	
	public static void main(String[] args) throws IOException {
		initBufferedReader();
		input();
		process();
		output();
	}
	
}

Measured memory_bytes: 30388
#include<stdio.h>

int main(){
  char ms[2][3];
  int i,judge = 0;

  for(i=0;i<2;i++)
    scanf("%s",&ms[i]);

  for(i=0;i<3;i++){
    if(ms[0][i] != ms[1][2-i])
      judge = 1;
  }

  if(judge == 0)
    puts("YES");
  else
    puts("NO");

  return 0;
}


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

using namespace std;
long long k,x,ans1,ans2;

int main()
{
	cin>>k>>x;
	ans1=x-k+1;
	ans2=x+k-1;
	if(ans1<-1000000)ans1=-1000000;
	if(ans2>1000000)ans2=1000000;
	for(int i=ans1;i<=ans2;i++)
	{
		cout<<i<<" "; 
	}
	cout<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll A,B,K;
    cin>>A>>B>>K;
    if(A<K){
        K-=A;
        if(B<K){
            cout<<0<<" "<<0<<endl;
        } else {
            cout<<0<<" "<<B-K<<endl;
        }
    } else {
        cout<<A-K<<" "<<B<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n;
  cin>>n;
  int a[n],b[n],pre[n],pre1[n];
  rep(i,0,n){
    cin>>a[i];
    if(i==0) pre[i]=a[i];
    else pre[i]=pre[i-1]+a[i];
  }
  rep(i,0,n) cin>>b[i];
  rrep(i,n-1,0){
    if(i==n-1)pre1[i]=b[i];
    else pre1[i]=pre1[i+1]+b[i];
  }
  int mx=0;
  rep(i,0,n){
    mx=max(mx,pre[i]+pre1[i]);
  }
  cout<<mx<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}


Measured memory_bytes: 7068
#include <stdio.h>

int main(){  
    int n,m,l; 
    scanf("%d %d %d",&n,&m,&l); 
    int a[n][m], b[m][l]; 
    long ans[n][l]; 

    for(int i=0;i<n;i++){ 
        for(int j=0;j<l;j++){
            ans[i][j]=0; 
        } 
    } 

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){ 
            scanf("%d",&a[i][j]); 
        } 
    } 
    
    for(int i=0;i<m;i++){ 
        for(int j=0;j<l;j++){ 
            scanf("%d",&b[i][j]); 
        } 
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
            ans[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j!=l-1){
                printf("%ld ",ans[i][j]);
            }else{
                printf("%ld\n",ans[i][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2080
h,w = map(int, input().split())

if h%3==0 or w%3==0:
    print(0)
    exit()

c = min(max(abs(w//3*h - (h+1)//2*(w-w//3)), abs(w//3*h - h//2*(w-w//3))), max(abs((w//3+1)*h - (h+1)//2*(w-w//3-1)), abs((w//3+1)*h - h//2*(w-w//3-1))))
d = min(max(abs(h//3*w - (w+1)//2*(h-h//3)), abs(h//3*w - w//2*(h-h//3))), max(abs((h//3+1)*w - (w+1)//2*(h-h//3-1)), abs((h//3+1)*w - w//2*(h-h//3-1))))

print(min(w,h,c,d))


Measured memory_bytes: 38384
from operator import itemgetter

n,m = map(int, input().split())
al = list(map(int, input().split()))
bc = []
for _ in range(m):
    b,c = map(int, input().split())
    bc.append([b,c])


bc.sort(key=itemgetter(1), reverse=True)
al.sort()

i = 0
while len(bc)>0 and i<n:
    b,c = bc.pop(0)

    for j in range(b):
        if i+j<n and al[i+j]<c:
            al[i+j] = c
    i += b

print(sum(al))

Measured memory_bytes: 25672
#include <iostream>

using namespace std;
const int MAXN = 5e5+5;
int arr[MAXN];
int distl[MAXN];
int distr[MAXN];
int main(){
    int n;
    cin>>n;
    cin>>distl[0];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        distl[i] = min(distl[i-1],abs(distl[i-1]-arr[i]));
    }
    distr[n+1] = 1;
    for(int i=n;i>=1;i--){
        distr[i] = distr[i+1];
        if(distr[i]*2>arr[i]){
            distr[i]+=arr[i];
        }
    }
    int q;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        if(distl[x-1]<distr[x+1]){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }
    }
}

Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    uint32_t kk;
    uint32_t nn;
    uint32_t longest = 0;
    cin >> kk >> nn;

    vector<uint32_t> an(nn, 0);

    for(int i = 0; i < nn; i++){
        cin >> an[i];
    }

    for(int i = 0; i < (nn - 1); i++){
        if((an[i + 1] - an[i]) >= longest){
            longest = (an[i + 1] - an[i]);
        }
    }

    //cout << an[nn - 1] << endl;
    if(((kk - an[nn - 1]) + an[0]) >= longest)
        longest = (kk - an[nn - 1]) + an[0];

    //cout << "longest is " << longest << endl;
    cout << (kk - longest) << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a, b;
		int ab;
		a = sc.next();
		b = sc.next();
		ab = Integer.parseInt(a + b);

		int i = 0;
		boolean flg = false;
		while(i * i <= ab) {
			if(i * i == ab) {
				flg = true;
				break;
			} else {
				flg = false;
			}

			i++;
		}

		System.out.print(flg == true ? "Yes" : "No");
	}
}

Measured memory_bytes: 21716
N=int(raw_input())
A= []
for i in range(N):
    A.append(int(raw_input()))


A.sort()

if N%2==0:
    score=2*sum(A[N/2:])-A[N/2]-2*sum(A[:N/2])+A[N/2-1]
    print score
else:
    score1=2*sum(A[(N+1)/2:])-2*sum(A[:(N+1)/2])+A[(N-1)/2]+A[(N-1)/2-1]
    score2=2*sum(A[(N-1)/2:])-2*sum(A[:(N-1)/2])-A[(N-1)/2]-A[(N-1)/2+1]
    print max(score1,score2)


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

using namespace std;

#define pii pair<int,int> 
#define F first 
#define S second
#define int long long 
#define mpr make_pair
typedef long long ll;

const int maxn = 2e5+10;
const int mod = 998244353;
const ll inf = 1e18+10;

int n, m, k, A, B, C, D;
int dp[3010][3010];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

   cin>> A >> B >> C >> D;
   dp[A][B] = 1;
   for(int c = A; c <= C; c++)
      for(int d = B; d <= D; d++)
      {
         if(c == A && d == B) continue;

         int Q = (dp[c-1][d-1] * (c-1) * (d-1)) % mod;

         dp[c][d] = ((dp[c-1][d] * d) % mod + (dp[c][d-1] * c) % mod - Q) % mod;

        // cout<< c <<" "<< d <<" "<< dp[c][d] <<"\n";
      }
   cout<< (dp[C][D] + mod) % mod;
}



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

const int MAX_H = 501;
const int MAX_W = 501;
int a[MAX_H][MAX_W];
int operation[MAX_H*MAX_W][4];

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

  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  int cnt = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      if (a[i][j] % 2 == 1) {
	a[i][j]--;
	a[i][j + 1]++;

	operation[cnt][0] = i;
	operation[cnt][1] = j;
	operation[cnt][2] = i;
	operation[cnt][3] = j + 1;
	cnt++;
      }
    }
  }
  
  for (int i = 0; i < H - 1; i++) {
    if (a[i][W-1] % 2 == 1) {
      a[i][W-1]--;
      a[i+1][W-1]++;

      operation[cnt][0] = i;
      operation[cnt][1] = W - 1;
      operation[cnt][2] = i + 1;
      operation[cnt][3] = W - 1;
      cnt++;
    }
  }

  cout << cnt << endl;
  for (int i = 0; i < cnt; i++) {
    cout << operation[i][0]+1 << " " << operation[i][1]+1 << " " << operation[i][2]+1 << " " << operation[i][3]+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6076
#include <bits/stdc++.h>
#define int size_t

signed main()
{
    using namespace std;
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int l = 0;
    while (true) {
        l += m;
        if (l % n == 0) {
            break;
        }
    }
    int ln = l / n, lm = l / m;
    for (int i = 0; i < n; i++) {
        if ((ln * i) % lm == 0 && s.at(i) != t.at((m * i) / n)) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

#define NMAX 100000

int as[NMAX];

template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}

int main() {
  int N, M, a, b;
  std::cin >> N >> M;
  for (int i = 0; i < M; ++i) {
  	read(a),read(b);
    if (as[b] < a)
      as[b] = a;
  }
  int count = 0;
  int maxa = 0;
  for (int i = N; i > 0; --i) {
    if (maxa == i) {
      ++count;
      maxa = as[i];
    } else if (maxa < as[i])
      maxa = as[i];
  }
  if (maxa)
    ++count;
  printf("%d\n",count);
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    string S; cin >> S;
    string l[4] = {"esare", "resare", "maerd", "remaerd"};
    REVERSE(S);
    bool flag = true;
    while(flag && S.size()){
        flag = false;
        REP(i,4){
            if(S.substr(0,l[i].size()) == l[i]){
                S = S.substr(l[i].size());
                flag = true;
                break;
            }
        }
    }
    cout << (S.empty() ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
#shell sort
def insert(A,n,g):
    c=0
    for i in range(g,n):
        v = A[i]
        j = i-g
        while j>=0 and A[j]>v:
            A[j+g]=A[j]
            j=j-g
            c+=1
        A[j+g]=v
    return [A,c]

def shell(A,n):
    cn=0
    G=[1]
    while 3*G[0]+1 < n:
        G.insert(0,G[0]*3+1)
    m=len(G)
    for i in G:
        cn+=insert(A,n,i)[1]
        A=insert(A,n,i)[0]
    return [m,G,cn,A]

n=int(input())
A=[int(input())]
for i in range(n-1):
    A.append(int(input()))
    
m,G,cnt,A=shell(A,n)
print(m)
print(*G)
print(cnt)
for i in A:
    print(i)


Measured memory_bytes: 46060
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	int N, L, aji[210], an = 0;
	scanf("%d%d", &N, &L);
	for (int i = 1; i <= N; i++) {
		aji[i] = L + i - 1;
		an += aji[i];
	}
	int min = 110;
	for (int i = 1; i <= N; i++) {
		if (abs(aji[i]) < abs(min)) {
			min = aji[i];
		}
	}
	printf("%d", an - min);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int l , r;
    cin >> l >> r;
    sum += (r - l) + 1;
  }
  
  cout << sum << endl; 
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
struct A{
    ll x,y;
    bool flag = false;
}a[1000],b[1000];
int main() {
    ll n,m;
    sld(n) sld(m)
    for(ll i = 0; i < n; i ++){
        sld(a[i].x) sld(a[i].y)
    }
    for(ll i = 0; i < m; i ++){
        sld(b[i].x) sld(b[i].y)
    }
    for(ll i = 0; i < n; i ++){
        ll mini = 0;
        ll minn = 10000000000;
        for(ll j = 0; j < m; j ++){
            if(abs(a[i].x-b[j].x)+abs(a[i].y-b[j].y) < minn){
                mini = j;
                minn = abs(a[i].x-b[j].x)+abs(a[i].y-b[j].y);
            }
        }
        pld(mini +1ll) pn
        b[mini].flag = true;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, k = map(int, input().split())
    for i in range(k):
        if i%2 == 0:
            if a%2 == 1:
                a -= 1
            b += a//2
            a //= 2
        else:
            if b%2 == 1:
                b -= 1
            a += b//2
            b //= 2
    print(a, b)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int N;
	long long int C[1000], S[1000], F[1000];
	
	cin >> N;
	
	for(int i = 0; i < N - 1; i++){
		cin >> C[i] >> S[i] >> F[i];
	}
	
	for(int i = 0; i < N; i++){
		long long int ans = 0;
		for(int j = i; j < N - 1; j++){
			if(ans <= S[j]){
				ans = S[j];
			}else if(ans % F[j] != 0){
				ans = (ans / F[j] + 1) * F[j];
			}
			ans += C[j];
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256