akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}




/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}

/*int struct_ascending_compare(const void *p, const void *q) {
    return ((structname*)p)->member - ((strcutname*)q)->member;
}*/

char field[4][4];

int main(void){
    int a, b;
    int cpy;
    int check[10];
    int ans = 0;
    scanf("%d %d", &a, &b);
    for (int i = a; i <= b; i++){
        cpy = i;
        for (int j = 0; j < 5; j++){
            check[j] = cpy%10;
            cpy /= 10;
        }
        int flag = 1;
        for (int j = 0; j < 5; j++){
            if (check[j] != check[4-j]){
                flag = 0;
            }
        }
        if (flag == 1){
            ans++;
        }
    }

    printf("%d\n", ans);

}


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

int main(){
    string s;cin>>s;
    string t;cin>>t;
    int a,b;cin>>a>>b;
    string u;cin>>u;
    if(s==u){
        cout<<a-1<<' '<<b<<endl;
    }
    else if(t==u){
        cout<<a<<' '<<b-1<<endl;
    }
    else{
        cout<<a<<' '<<b<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y;
cin>>x>>y;
if(x<y){
    if(2*x<y){
        cout<<2*x;
    }else{

    for(int i=2;i<100*y;i++){
    if((i*x)%y!=0){
        cout<<i*x;
        break;
    }
}

    }
}else{
if(x%y==0){
    cout<<-1;
}else{
for(int i=2;i<100*y;i++){
    if((i*x)%y!=0){
        cout<<i*x;
        break;
    }
}
}
}
cout<<"\n";
return 0;
}


Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto d=new int[](n);
  foreach(i; 0..n) rd(d[i]);

  bool ok=true;
  void f(){
    int r=0;
    foreach(int i, int e; d){
      ok&=i*10<=r;
      chmax(r, i*10+e);
    }
  }

  f();
  reverse(d);
  f();

  if(ok) writeln("yes");
  else writeln("no");
  
}

void chmax(T)(ref T x, T y){
  if(x<y) x=y;
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 998244353;
const double PI = 3.141592653589793238463;
const int MAXN = 1000030;

int main()
{
    FAST
    int k;
    string h;
    cin>>k>>h;
    if(h.size()<=k)
        cout<<h<<endl;
    else{
        cout<<h.substr(0,k)<<"..."<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val n = int()
    val a = LongArray(n){long()}
    var cnt = 0
    var i = 1
    while (i < n) {
        if (a[i-1] == a[i]) {
            i += 2
            cnt++
        } else {
            i++
        }
    }
    println(cnt)
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 31392
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    std::vector<int> V;
    V.resize(3);
    std::cin >> V[0] >> V[1] >> V[2];

    std::sort(std::begin(V), std::end(V));

    size_t count = 0;
    for (;;) {
        if (V[0] < V[1]) {
            V[0] += 2;
            count++;
        }
        else {
            break;
        }
    }
    if (V[0] == V[1]) {
        count += V[2] - V[1];
    }
    else {
        V[1]++;
        V[2]++;
        count++;
        // これで V[0] == v[1] <= V[2]

        count += V[2] - V[1];
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
	string S, Sm = "CODEFESTIVAL2016";
	cin >> S;

	int cnt = 0;
	for(int i = 0; i < Sm.size(); ++i){
		if(S[i] != Sm[i]) cnt++;
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int a[110];

int main(){
    ll n; cin >> n;
    rep(i,n)    cin >> a[i];
    ll ans =0;

    rep(i,n)    rep(j,n){
        ll b = abs(a[i]-a[j]);
        ans = max(ans, b);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/**
*   @Author : MeGaCrazy
*   @InitTime : Thu Jan 17 08:32:08 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
  int n;
  cin>>n;
  set<int>s;
  for(int i=0;i<n;i++){
  	int a;
  	cin>>a;
  	mp[a]++;
  	mp[a-1]++;
  	mp[a+1]++;
  	s.insert(a);
  	s.insert(a-1);
  	s.insert(a+1);
  }
  long long mx=-1;
  for(int a:s){
  	if(mp[a] > mx){
  		mx=mp[a];
  	}
  
  }
  cout<<mx<<endl;


}

Measured memory_bytes: 9216
#include <iostream>
#include <list>

int main(int argc, char const* argv[])
{
    int a, b;
    std::cin >> a >> b;

    int result = 0;
    for(int i = a; i <= b;++i)
    {
        std::list<int> vec;
        int val = i;
        while(val != 0)
        {
            int digit = val % 10;
            val /= 10;
            vec.push_back(digit);
        }

        while(true)
        {
            if(vec.size() == 1)
            {
                result++;
                break;
            }
            if(vec.size() == 0)
            {
                break;
            }
            if(vec.front() == vec.back())
            {
                vec.pop_front();
                vec.pop_back();
                continue;
            }
            break;
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    bool f = true;
    rep(i, 3)
    {
        if (s[i] == s[i + 1])
        {
            f = false;
            break;
        }
    }
    cout << (f ? "Good" : "Bad") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){

int N,k,i;
ll X=0,x=0,z,ans=1000000000000000000LL;

cin >> N;

std::vector<ll> a(N);

for(k=0;k<N;k++){
  cin >> a[k];
  X+=a[k];
}

for(i=0;i<N-1;i++){
  x+=a[i];

  z=abs(X-2*x);

  ans=min(ans,z);

}

cout << ans << endl;


}


Measured memory_bytes: 4848
#include <iostream>

int main() {
  int n;
  int a[200001] = {0};
  std::cin >> n;
  for(int i=1; i<n; i++) {
    int b;
    std::cin >> b;
    a[b] += 1;
  }
  for(int i=1; i<n; i++) {
    std::cout << a[i] << " ";
  }
  std::cout << a[n] << std::endl;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
char p[10005];
long long kn[10005][105];
main()
{
	int t,r;
	scanf("%s%d",&p[1],&r);
	kn[0][0]=1;
	int si=strlen(&p[1]);
	for(int i = 0;i < si;i++)
	{
		for(int j = 0;j < r;j++)
		{
			for(int k = 0;k < 10;k++)
			{
				//if(i==0 && (j!=0 || k!=0))
				//kn[i+1][(j+k)%r]+=kn[i][j];
				//else if(i!=0)
				kn[i+1][(j+k)%r]+=kn[i][j];
				kn[i+1][(j+k)%r]%=1000000007;
			}
			//printf("%d ",kn[i][j]);
		}
		//printf("\n");
	}
	int to=0;
	int sm=0;
	for(int i = 1;i <= si;i++)
	{
		for(int j = 0;j < p[i]-'0';j++)
		{
			to+=kn[si-i][(r-sm-j+r)%r];
			to%=1000000007;
		}
		sm+=p[i]-'0';
		sm%=r;
	}
	if(sm!=0)
	{
		to--;
		to+=1000000007;
		to%=1000000007;
	}
	//to++;
	//to%=1000000007;
	printf("%d",to);
}

Measured memory_bytes: 8448
#include <iostream>
#include <cstdlib>

using namespace std;

void displayYes(bool isYes) {
	cout << (isYes ? "Yes" : "No") << endl;
}

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	while (true) {
		if ((x < 0 || y < 0)
			|| (W < x || H < y)) {
			displayYes(false);
			break;
		}
		if (r - x > 0 || r - y > 0) {
			displayYes(false);
			break;
		}
		if (r - abs(W - x) > 0 || r - abs(H - y) > 0) {
			displayYes(false);
			break;
		}
		displayYes(true);
		break;
	}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
signed int  a,b,c,d,e=0; cin>>a>>b>>c>>d;
 if(d>0){ e=min(d,a);d=d-min(d,a);}
 if(d>0){d=d-b;}
 if(d>0){e-=min(d,c);}
  cout<<e;
}




Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int m, n;
    std::cin >> n >> m;
    std::cout << ((n==m) ? "Yes" : "No") << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const ll N = 3000;

ll p,dp[N][N];
ll f[N]={1},t[N],ans[N],inv[N];
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> p;
    for(int i = 0; i < p; i++) cin >> dp[1][i];
    for(int i = 1; i < p; i++) for(int j = 1; j <= i; j++) if(i*j%p==1) inv[i]=j, inv[j]=i;
    for(int L = 2; L <= p; L++) {
        for(int i = 0; i+1 < p; i++) {
            dp[L][i] = (dp[L-1][i+1] - dp[L-1][i] + p) * inv[L-1] % p;
        }
    }
    for(int i = 0; i < p; i++) {
        for(int j = 0; j < p; j++) ans[j] = (ans[j]+dp[i+1][0]*f[j])%p;
        t[0] = (p-i)*f[0]%p;
        for(int j = 1; j < p; j++) t[j] = (f[j-1] - i*f[j]%p + p)%p;
        for(int j = 0; j < p; j++) f[j] = t[j];
    }
    for(int i = 0; i < p; i++) cout << ans[i] << " \n"[i==p-1];
}


Measured memory_bytes: 70656
#include <iostream>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <list>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9;

int sum_base(int n, int b = 10) {
  int s = 0;
  while (n) { s += n % b; n /= b; }
  return s;
}

void solve_a() {
  int n; cin >> n;
  int r = inf;
  fore(a, 1, n - 1) uin(r, sum_base(a) + sum_base(n - a));
  cout << r << endl;
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_a();
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int ans=INT_MAX;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        int d=0;
        while(x%2==0)
        {
            d++;
            x/=2;
        }
        ans=min(ans,d);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main(){
    LL n,k;
    cin>>n>>k;
    LL a[n];
    for(LL i=0;i<n;i++){
        cin>>a[i];
    }
    LL dp[n];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(LL i=2;i<n;i++){
        LL minans=100000000000;
        for(LL j=i-1;j>=0&&(i-j)<=k;j--){
            LL ans1=abs(a[j]-a[i])+dp[j];
            minans=min(ans1,minans);
        }
        dp[i]=minans;
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i;
  int b = 0; //0番目0
  int w = 0; //0番目1
  for(i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]%2==1) b++;
    }
    else {
      if(s[i]%2==0) b++;
    }
  }
  for(i=0;i<s.size();i++){
    if(i%2==1) {
      if(s[i]%2==1) w++;
    }
    else {
      if(s[i]%2==0) w++;
    }
  }
  cout << min(b,w) << "\n";
  return 0;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    ll x;cin>>x;
    vector<int> cost(n);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<n;++i){
        cin>>cost[i];
        for(int j=0;j<m;++j){
            cin>>a[i][j];
        }
    }
    ll ma = inf;
    for(int mask = 1; mask<1<<n;++mask){
        vector<int> vec(m);
        ll tmp = 0;
        for(int i=0;i<n;++i){
            if((mask>>i)&1){
                tmp += cost[i];
                for(int j=0;j<m;++j){
                    vec[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int i=0;i<m;++i){
            if(vec[i] < x) ok = false;
        }
        if(ok)ma = min(ma,tmp);
    }
    if(ma == inf) cout << -1 << endl;
    else cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3664
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int N,M;cin>>N>>M;
  int max_n;
  int min_n;
  if(N==1) {
    min_n=0;
    max_n=10;
  } else if(N==2) {
    min_n=10;
    max_n=100;
  } else if(N==3) {
    min_n=100;
    max_n=1000;
  }
  int s[N];
  char c[N];
  REP(i,M) {
    cin>>s[i]>>c[i];
  }
  string S;
  for(int i=min_n;i<max_n;++i) {
    S = to_string(i);
    bool marker = true;
    REP(j,M) {
      if(S.length() < s[j]) {
        marker = false;
        break;
      }
      if(S[s[j]-1] != c[j]) {
        marker = false;
      }
    }
    if(marker) {
      p(S);
      return 0;
    }
  }
  p("-1");
  return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

var a map[int64]int64

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	n := nextInt64()
	a = map[int64]int64{}

	for i := int64(0); i < n; i++ {
		as := nextInt64()
		addA(as)
	}
	q := nextInt64()
	sum := sumA()
	for i := int64(0); i < q; i++ {
		b, c := nextInt64(), nextInt64()
		sum = sumSubA(b, c, sum)
		chBC(b, c)
		fmt.Println(sum)
	}
}

func addA(n int64) {
	_, ok := a[n]
	if ok {
		a[n]++
	} else {
		a[n] = 1
	}
}

func chBC(b int64, c int64) {
	_, ok := a[b]
	if ok {
		_, cok := a[c]
		if cok {
			a[c] += a[b]
			delete(a, b)
		} else {
			a[c] = a[b]
			delete(a, b)
		}
	}
}

func sumSubA(b int64, c int64, sum int64) int64 {
	_, ok := a[b]
	if ok {
		return sum + a[b]*c - a[b]*b
	}
	return sum
}

func sumA() int64 {
	sum := int64(0)
	for key, value := range a {
		sum += key * value
	}
	return sum
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


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

int main()
{
    int N;
    bool flag = false;
    string S;
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> S;
        if(S == "Y")flag = true;
    }
    if(flag)cout << "Four" << endl;
    else cout << "Three" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int MAXN=200005;
int f[MAXN],g[MAXN];
int a[MAXN],ln,n;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	scanf("%d",&n);int lst=0;
	for(int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		if(x==lst)continue;
		if(lst)a[++ln]=lst;
		lst=x;
	}
	a[++ln]=lst;n=ln;
	f[a[1]]=1;
	for(int i=1;i<=n;i++)
	{
		g[i]=f[a[i]];
		ad(f[a[i+1]],g[i]);
	}
	printf("%d\n",g[n]);
}

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

int main(){
    int N;
    cin >> N;
    int a[3*N];
    for (int i=0;i<3*N;i++) cin >> a[i];
    sort(a,a+N*3,greater<int>());
    long ans = 0;
    for (int i=0;i<N;i++) {
        ans+=a[i*2+1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(void)
{
	int n, m, s[5], c[5], i, ans[4], con = 0, l;
	for(i = 0; i < 4; i++){
		ans[i] = 0;
	}
	
	scanf("%d %d", &n, &m);
	for(i = 0; i < m; i++){
		scanf("%d %d", &s[i], &c[i]);
	}
	
	for(i = 0; i < m; i++){
		if(con == 1){
			break;
		}
		if(s[i] == 1 && c[i] == 0 && n != 1){
			printf("-1");
			con = 1;
			break;
		}
		for(l = 0; l < m; l++){
			if(i != l && s[i] == s[l] && c[i] != c[l]){
				printf("-1");
				con = 1;
				break;
			}
		}
	}
	
	if(con == 0){
		for(i = 0; i < m; i++){
			ans[s[i]] = c[i];
		}
		if(n != 1 && ans[1] == 0){
			ans[1] = 1;
		}
		for(i = 1; i <= n; i++){
			printf("%d", ans[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
#define ll int64_t
#define REP(i, n) for (int i=0; i<n; i++)

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

    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    if (2*Q < H) H = 2*Q;
    if (2*H < S) S = 2*H;

    ll ans = 0;

    if (2*S < D){
        ans = S*N;
    } else {
        ans = D * (N/2) + (N % 2) * S;
    }



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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iterator>
#include<deque>
#include<cstdio>

#define lp(i,a,n) for(int i=a;i<n;++i)
#define rep(i,a,n) for(ll i=a;i<=n;++i)
#define all(v) v.begin(),v.end()
#define clr(n,a) memset(n,a,sizeof(n))
#define vi vector <int>
#define sc set <char>
#define si set<int>
#define pb push_back
#define vb vector <bool>
#define pi(n) printf("%d\n",n)
#define ln "\n"
#define mahmoud_abdelsamie ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


int main()
{
    mahmoud_abdelsamie
    int n,cnt=0; cin>>n;
    rep(i,1,n){
        int x; cin>>x;
        if(i%2 && x%2)
            ++cnt;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3652
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    if k == 0:
        print(n**2)
        exit()

    res = 0
    for b in range(1, n+1):
        if k >= b:
            continue
        res += (b-k) * ((n+1) // b)
        res += max(((n+1)%b)-k, 0)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
a,b,c,d= input().split()
w,x,y,z=(int(a),int(b),int(c), int(d))
x_ps_str=input().split()
y_ps_str=input().split()
x_ps = []
y_ps=[]
for i in range(w):
    x_ps.append(int(x_ps_str[i]))
    
for i in range(x):
    y_ps.append(int(y_ps_str[i]))

count =0 
ans_list = []
for i in range(101):
    ans_list.append(i)
    ans_list.append(-1*i)
ans_list.sort()
for i in range(len(ans_list)):
    if y<i and i <= z:
        if max(x_ps) < i and i <= min(y_ps):
            print('No War')
            break
        else:
            count += 1
    else:
        count += 1
if count == 202:
    print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int n ;
  string s;
  cin >> n >> s;

  if(n&1)
  {
    cout <<"No"<<endl;
    return 0;
  }

  int c = n/2 ;

  
  if(s.substr(0,c) == s.substr(c,c) ) 
  {
    cout << "Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;
using p = pair<int, pair<int, int>>;

int main() {
    int H, W, CH, CW, DH, DW;
    cin >> H >> W >> CH >> CW >> DH >> DW;
    CH -= 1; CW -= 1;
    DH -= 1; DW -= 1;
    vector<vector<int>> MAZE(H);
    char tmp;
    rep(i, H) {
        MAZE[i].reserve(W);
        rep(j, W) {
            cin >> tmp;
            MAZE[i][j] = tmp == '#' ? -1 : INF;
        }
    }
    deque<p> que;
    que.push_back({0, {CH, CW}});

    auto ret = -1;
    while(!que.empty()) {
        auto top = que.front();
        que.pop_front();
        auto cost = top.first;
        auto h = top.second.first;
        auto w = top.second.second;
        if(h == DH && w == DW) {
            ret = cost;
            break;
        }

        for(int dh = -2; dh <= 2; ++dh) {
            for(int dw = -2; dw <= 2; ++dw) {
                if(dh == 0 && dw == 0)
                    continue;
                auto nh = dh + h;
                auto nw = dw + w;
                if (nh < 0 || nh >= H || nw < 0 || nw >= W || MAZE[nh][nw] == -1) {
                    continue;
                }

                if (abs(dh) == 2 || abs(dw) == 2 || (abs(dh) == 1 && abs(dw) == 1)) {
                    if(MAZE[nh][nw] > cost + 1) {
                        MAZE[nh][nw] = cost + 1;
                        que.push_back({cost+1, {nh, nw}});
                    }
                } else {
                    if(MAZE[nh][nw] > cost) {
                        MAZE[nh][nw] = cost;
                        que.push_front({cost, {nh, nw}});
                    }
                }
            }
        }
    }
#if 0
    rep(i, H) {
        rep(j, W) {
            printf("%02d ", MAZE[i][j]);
        }
        printf("\n");
    }
#endif
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a + b == 15) cout << "+" << endl;
    else if(a * b == 15) cout << "*" << endl;
    else cout << "x" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

bitset<4194304> v(0);
bitset<4194304> pre(0);

int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	REP(i,N){
		cin>>A[i];
	}

	int sum = A[0];
	v.set(A[0]);
	for(int i=1; i<N; i++){
		pre = v;
		v = pre | (pre << A[i]);
		v.set(A[i]);
		sum += A[i];
	}
	int ans=0;
	for(int i = (sum+1)/2; ; i++){
		if(v[i]){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2816
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    cout << 360 / std::__gcd(360, input<int>()) << "\n";

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1)
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX             100005
#define MOD             1000000007

typedef long long ll;

int main()
{
    FastRead

    ll x;

    cin>>x;

    ll ans = (x/500)*1000;

    ans+=((x%500)/5)*5;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int get(int x) {
    int L = (n + x - 1) / x;
    int R = n / x;

    int l = L - 1, r = R + 1;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (n % m >= x) l = m;
        else r = m;
    }   

    if (l && n % l == x) return l;
    else return 0;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    int ans = 0;
    vector <int> a;
    for (int i = 1; i * i <= n; ++i) a.push_back(i);
    for (int i = 1; i * i <= n; ++i) a.push_back(n / i);
    sort(a.begin(), a.end());
    a.resize(unique(a.begin(), a.end()) - a.begin());
    for (int e : a) ans += get(e);
    cout << ans << '\n';
}

Measured memory_bytes: 18664
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll sum = 0;
  REP(i, N) {
    if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0)
      sum += (i + 1);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        s = s.replace("1", "x");
        s = s.replace("9", "1");
        s = s.replace("x", "9");

        System.out.println(s);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string s1 = s.substr(0, 2);
  string s2 = s.substr(2, 2);
  int a = atoi(s1.c_str());
  int b = atoi(s2.c_str());
  if ((a >= 1 && a <= 12) && (b >= 1 && b <= 12)) {
    cout << "AMBIGUOUS" << endl;
  } else if (a >= 1 && a <= 12) {
    cout << "MMYY" << endl;
  } else if (b >= 1 && b <= 12) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}

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

using namespace std;

const int MAX_N = 1e5 + 10;

int N, K;

struct Perm {
    int p[MAX_N];
    int &operator[](int x) { return p[x]; }
    const int &operator[](int x) const { return p[x]; }

    Perm() { iota(p + 1, p + N + 1, 1); }

    Perm kth_power(int k) {
        Perm res;
        static bool vis[MAX_N];
        fill_n(vis + 1, N, false);
        for (int i = 1; i <= N; i++) {
            if (!vis[i]) {
                vector<int> cycle;
                for (int j = i; !vis[j]; vis[j] = true, j = p[j]) cycle.push_back(j);
                int n = cycle.size();
                for (int j = 0; j < n; j++)
                    res[cycle[j]] = cycle[(j + n + k) % n];
            }
        }
        return res;
    }
};

Perm mult(const Perm &A, const Perm &B) {
    Perm C;
    for (int i = 1; i <= N; i++) C[i] = B[A[i]];
    return C;
}

Perm small_cases[7];
Perm P, Q;

int main() {
    scanf("%d%d", &N, &K);
    for (int i = 1; i <= N; i++) scanf("%d", &P[i]);
    for (int i = 1; i <= N; i++) scanf("%d", &Q[i]);
    small_cases[1] = P;
    small_cases[2] = Q;
    for (int i = 3; i <= 6; i++) {
        small_cases[i] = mult(small_cases[i - 2].kth_power(-1), small_cases[i - 1]);
    }
    int m = (K - 1) / 6;
    Perm res = small_cases[K - 6 * m], head = Q.kth_power(-1);
    head = mult(head, P);
    head = mult(head, Q);
    head = mult(head, P.kth_power(-1));
    head = head.kth_power(m);
    res = mult(head, res);
    res = mult(res, head.kth_power(-1));
    for (int i = 1; i <= N; i++) printf("%d ", res[i]);
    printf("\n");
}


Measured memory_bytes: 8316
N=int(input())
s=[int(input()) for _ in range(N)]
s.sort()
ans=sum(s)

for i in range(N):
    if ans%10!=0:
        print(ans)
        exit()
    else:
        if (ans-s[i])%10!=0:
            print((ans-s[i]))
            exit()

print("0")



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

int main () {
  int N, A;
  cin >> N;
  
  int min = 100;
  
  for (int i = 0; i < N; i++) {
    cin >> A;
    int r = 0;
    while (A % 2 == 0) {
      A /= 2;
      r++;
    }
    if (min > r) min = r;
  }
  cout << min << endl;
}
    


Measured memory_bytes: 256
#include <cstdio>
long long A, B, C, D, lcm;
long long gcd(long long a, long long b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

long long calc(long long x)
{
	return x - x / C - x / D + x / lcm;
}

int main()
{
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
	lcm = C / gcd(C, D) * D;
	long long ans = calc(B) - calc(A - 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::vector<int> v(3);
std::cin >>x;
std::cout << (2*x)/gcd(x,2) << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
vector<vector<int>> a;

int main() {
	int h, w;
	cin >> h >> w;
	vector<int> ans;
	a= vector<vector<int>>(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w-1; j++) {
			if (a[i][j] % 2 == 1) {
				a[i][j + 1]++;
				ans.push_back(i + 1);
				ans.push_back(j + 1);
				ans.push_back(i + 1);
				ans.push_back(j + 2);
			}
		}
	}
	for (int i = 0; i < h-1; i++) {
		if (a[i][w - 1] % 2 == 1) {
			a[i + 1][w - 1]++;
			ans.push_back(i + 1);
			ans.push_back(w);
			ans.push_back(i + 2);
			ans.push_back(w);
		}
	}
	cout << ans.size() / 4<<endl;
	int x = 0;
	for (auto itr = ans.begin(); itr != ans.end(); itr++) {
		x++;
		cout << *itr;
		if (x % 4 == 0) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
	return 0;
}

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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, dp[1100], s[1100][1100], now[1100];
queue<P> q;
bool used[1100];
int main() {
	cin >> n;
	REP(i, n) {
		REP(j, n - 1) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	REP(i, n) {
		if (!used[i] and s[s[i][0]][0] == i) {
			q.push(P(i, s[i][0]));
			used[i] = true;
			used[s[i][0]] = true;
		}
	}
	while (!q.empty()) {
		P tp = q.front();
		q.pop();
		//cout << tp.first << " " << tp.second << endl;
		ll a = max(dp[tp.first], dp[tp.second]) + 1;
		dp[tp.first] = a;
		dp[tp.second] = a;
		now[tp.first]++;
		now[tp.second]++;

		ll tf = s[tp.first][now[tp.first]];
		//cout << tf << endl;
		if (now[tp.first] < n - 1 and s[tf][now[tf]] == tp.first) {
			q.push(P(tp.first, tf));
		}

		ll ts = s[tp.second][now[tp.second]];
		if (now[tp.second] < n - 1 and s[ts][now[ts]] == tp.second) {
			q.push(P(tp.second, ts));
		}
	}
	REP(i, n) {
		if (now[i] != n - 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	REP(i, n) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

	

Measured memory_bytes: 8832
#include <iostream>
#include "stdio.h"
#include "string.h"
#include "queue"
#include "stack"
#include "utility"
#include "algorithm"
#include "vector"
 
using namespace std;

#define MAX_N 100

int N;
vector<int> L;
int ans = 0;

int main(){

scanf("%d",&N);
for(int i=0;i<2*N;i++){
	int tmp;
	scanf("%d",&tmp);
	L.push_back(tmp);
}

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

for(int i=0;i<N;i++){
	ans += L[2*i];
}

printf("%d",ans);


return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJVolume16_1611
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> anss = new List<int>();
            while (true)
            {
                var n = int.Parse(Console.ReadLine());
                if (n == 0) break;

                int[] A = new int[n + 1];
                var input = ReadInt();
                for (int i = 0; i < n; i++)
                {
                    A[i + 1] = input[i];
                }

                int[,] dp = new int[n + 2, n + 2];
                for (int i = n - 1; i > 0; i--)
                {
                    for (int j = i + 1; j <= n; j++)
                    {
                        int ans = 0;
                        if (Math.Abs(A[i] - A[j]) <= 1 && dp[i + 1, j - 1] == j - i - 1)//内部消えきる？
                        {
                            ans = j - i + 1;
                        }

                        for (int k = i; k <= j - 1; k++)
                        {
                            int cand = dp[i, k] + dp[k + 1, j];
                            ans = Math.Max(ans, cand);
                        }
                        dp[i, j] = ans;
                    }
                }

                int a = dp[1, n];
                anss.Add(a);
            }

            foreach (var a in anss)
            {
                Console.WriteLine(a);
            }
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}



Measured memory_bytes: 32140
use std::f64::consts::PI;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! {
        n: isize,
        m: isize,
        a: [isize; m],
    }

    let mut answer = n;

    for num in a {
        answer -= num;
    }

    if answer < 0 {
        answer = -1;
    }
    println!("{}", answer);
}

Measured memory_bytes: 2260
#include <stdio.h>
#include <string.h>
int main(void){
  int k,t;
  char s[100];
  scanf("%d",&k);
  scanf("%s",s);
  t=strlen(s);
  if(k>=t) printf("%s",s);
  else{
   printf("%.*s...",k,s);
  }
  return 0;
 }

Measured memory_bytes: 1736
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans1 = a[-1]
del a[-1]
long = ans1 

if ans1 % 2 == 0:
    x = ans1 // 2
    for i in a:
        y = abs(x - i) 
        if y < long:
            ans2 = i
            long = y
else:
    x = ans1 // 2
    z = ans1 // 2 + 1
    for i in a:
        y = min (abs(x - i),abs(z - i))
        if y < long:
            ans2 = i
            long = y
print(ans1,ans2)



Measured memory_bytes: 14060