akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

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

  string b;
  cin >> b;

  int rb = n-1, lb = 0;
  int count = 0;

  for(;;){
    
    while(b[rb] == 'W' && rb >= 0)
      --rb;
    
    while(b[lb] == 'R' && lb < n)
      ++lb;

    if(rb < 0 || lb >= n || rb <= lb){
      break;
    }
    
    else{
      b[rb] = 'W'; b[lb] = 'R'; 
      ++count;
    }
    
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3760
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))
N, Z, W = inpl()
A = inpl()

if N == 1:
    print(abs(A[0] - W))
else:
    print(max(abs(A[-1] - W),
              abs(A[-2] - A[-1])))

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,T lazydefvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;}
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(vector<T>v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
main()
{
	int n,q;cin>>n>>q;
	lazysegtree<long long>S(n);
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c)
		{
			int s,t;cin>>s>>t;
			cout<<S.query(s-1,t)<<endl;
		}
		else
		{
			int s,t,x;cin>>s>>t>>x;
			S.update(s-1,t,x);
		}
	}
}


Measured memory_bytes: 7076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
ll dp[100100][13];

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

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> v(n);
    for (ll i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ll ans2 = 0;
    for (ll a = 0; a <= min(k,n); ++a) {
        for (ll b = 0; b <= min(k,n)-a; ++b) {
            vector<ll> tmp;
            ll ans = 0;
            for (ll i = 0; i < a; ++i) tmp.push_back(v[i]),ans += v[i];
            for (ll i = 0; i < b; ++i) tmp.push_back(v[n-1-i]),ans += v[n-1-i];
            sort(tmp.begin(),tmp.end());
            for (ll j = 0; j < min(k-a-b,(ll)tmp.size()); ++j) {
                if(tmp[j] < 0) ans -= tmp[j];
            }
            ans2 = max(ans2,ans);
        }
    }
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]

    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x

    def union(self, s1, s2):
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]


n = int(input())

x = dict()
y = dict()

for i in range(n):
    input_x, input_y = map(int, input().split())
    x[i] = input_x
    y[i] = input_y

x = sorted(x.items(), key=lambda t:t[1])
y = sorted(y.items(), key=lambda t:t[1])

r = []

for i in range(n - 1):
    r.append([x[i][0], x[i + 1][0], x[i + 1][1] - x[i][1]])
    r.append([y[i][0], y[i + 1][0], y[i + 1][1] - y[i][1]])

r = sorted(r, key=lambda t:t[2])

uft = UnionFind(n)

ans = 0
for a, b, c in r:
    ra = uft.find(a)
    rb = uft.find(b)
    if ra != rb:
        ans += c
        uft.union(ra, rb)

print(ans)

Measured memory_bytes: 60764
/*
    Problem 44
    https://onlinejudge.u-aizu.ac.jp/problems/1167
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 1000005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<int> dpAll(MAX, INF), dpOdd(MAX, INF);
vector<int> sqAll, sqOdd;
/* function */
int calcSq(int x) { return x * (x+1) * (x+2) / 6; }
void initSq() {
    for (int i = 1; i < MAX; i++) {
        int cost = calcSq(i);
        if (cost >= MAX) break;
        sqAll.push_back(cost);
        if (cost % 2 == 1)
            sqOdd.push_back(cost);
    }
}
void calcDP() {
    dpAll[0] = 0;
    for (int i = 0; i < sqAll.size(); i++) {
        for (int j = sqAll[i]; j < MAX; j++) {
            dpAll[j] = min(dpAll[j], dpAll[j-sqAll[i]] + 1);
        }
    }
    dpOdd[0] = 0;
    for (int i = 0; i < sqOdd.size(); i++) {
        for (int j = sqOdd[i]; j < MAX; j++) {
            dpOdd[j] = min(dpOdd[j], dpOdd[j-sqOdd[i]] + 1);
        }
    }
}
int calcAll(int m) { return dpAll[m]; }
int calcOdd(int m) { return dpOdd[m]; }
/* main */
int main(){
    vector<int> query;
    while (1) {
        int q; cin >> q;
        if (q == 0) break;
        query.push_back(q);
    }
    initSq();
    calcDP();
    for (int q : query)
        cout << calcAll(q) << ' ' << calcOdd(q) << '\n';
}


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

int main(){
 ll n,k,ans=0;
 cin>>n>>k;
 vector<int> a(n);
 for(int i=0;i<n;i++)
    cin>>a[i];
 sort(a.begin(),a.end());
 for(int i=0;i<k;i++){
    ans+=a[i];
 }
 cout<< ans<<endl;
 return 0;
}





Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        long ans = 0L;
        int before = -1;
        for (int i=N-1;i>=0;i--) {
            if (A[i]>i || before-1>A[i]) {
                System.out.println(-1);
                return;
            }
            if (A[i]!=0 && A[i]!=before-1) {
                ans += A[i];
            }
            before = A[i];
        }
        System.out.println(ans);
    }
}

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

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    int t=1;
    while(s.size()!=1) {
      if(t) t=0;
      else t=1;
      stringstream ss;
      string t;
      ss << (int)s[s.size()-1]-48+(int)s[s.size()-2]-48;
      ss >> t;
      s=s.substr(0,s.size()-2)+t;
    }
    if(t) cout << "Audrey wins." << endl;
    else cout << "Fabre wins." << endl;
  }
  return 0;
}


Measured memory_bytes: 1232
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<50;
vector<pair<int,int>> E[2550];
int main(){
    int n,m,P;
    cin>>n>>m>>P;
    vector<tuple<int,int,int>> p;
    for(int i=0;i<m;++i){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        E[a].push_back({b,c-P});
    }
    vector<ll> from(2550,inf),to(2550,inf);
    from[0] = 0;
    ll ret = inf;
    for(int num=0;num<10000;num++){
        for(int j=0;j<n;++j)to[j] = from[j];
        for(int i=0;i<n;++i)if(from[i] < inf){
            for(auto v : E[i]){
                to[v.first] = min(to[v.first],from[i] - v.second);
                if(num >= 5050 and to[v.first] < from[v.first])to[v.first] = -inf;
            }
        }
        ret = min(ret,to[n-1]);
        swap(from,to);
    }
    ret = min(0ll,ret);
    if(ret <= -(inf>>1))ret = 1;
    cout << -ret << endl;
    return 0;
}



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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end()

const int INF=INT_MAX;
const ld PI=acos(-1);//3.1415926535897932384626433
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}
int gcd(int a,int b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}

ld log (ld a,ld b){return log(b)/log(a);}
ll power(ll base, ll exp){
    ll res=1;
    while(exp){
        exp--;
        res*=base;
    }
    return res;
}
void solve();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
void solve (){
    char a;
    cin >> a;
    for(char c='A'; c<='Z'; c++)
        if(c==a){
            cout << "A\n";
            return;
        }
    cout << "a\n";

}

Measured memory_bytes: 3556
N = int(input())


*A, = map(int, input().split())

L = [0]*(2+10**5)

for i in range(len(A)):
    up = A[i]+1
    down = A[i]-1
    no = A[i]
    L[up]=L[up]+1
    L[down]=L[down]+1
    L[no] = L[no]+1

print(max(L))

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

using ll = long long int;
using P = std::pair<int, int>;

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

int main()
{
    int n;

    std::cin >> n;

    std::vector<std::vector<int>> vec;

    int ca = -1;

    rep(i, n)
    {
        int a;
        std::cin >> a;
        if (a > ca)
        {
            vec.push_back(std::vector<int>());
            vec.rbegin()->push_back(a);
        }
        else
        {
            vec.rbegin()->push_back(a);
        }
        ca = a;
    }

    //std::cerr << "DEBUG" << std::endl;
    /*for (auto &v : vec)
    {
        for (int x : v)
            std::cerr << x << ' ';
        std::cerr << std::endl;
    }*/

    std::multiset<int> set;

    for (auto &v : vec)
    {
        for (int x : v)
        {
            if (set.empty() || *(set.begin()) >= x)
            {
                set.insert(x);
                continue;
            }
            auto it = set.lower_bound(x);
            --it;
            set.erase(it);
            set.insert(x);
        }
    }

    std::cout << set.size() << std::endl;

    return 0;
}

Measured memory_bytes: 5552
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

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

	

	for (int i = n-1; i >=0; i--) {
		cout << a[i];

		if (i != 0) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  vector<ll> ruiseki(n + 1);
  REP(i, n)
  {
    cin >> a[i + 1];
  }
  REP(i, n)
  {
    ruiseki[i + 1] = ruiseki[i] + a[i + 1];
  }
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 1e16));
  REP(i, n + 1)
  {
    dp[i][i] = a[i];
  }

  REP(i, n)
  {
    for (ll l = 1; l <= n - i; l++)
    {
      ll r = l + i;
      REP(j, i)
      {
        if (i == 1)
        {
          dp[l][r] = min(dp[l][r], a[l] + a[r]);
        }
        else
        {
          if (j == 0)
          {
            dp[l][r] = min(dp[l][r], a[l] + ruiseki[r] - ruiseki[l] + dp[l + 1][r]);
          }
          else if (j == i - 1)
          {
            dp[l][r] = min(dp[l][r], ruiseki[r - 1] - ruiseki[l - 1] + dp[l][r - 1] + a[r]);
          }
          else
          {
            dp[l][r] = min(dp[l][r], dp[l][l + j] + dp[l + j + 1][r] + ruiseki[l + j] - ruiseki[l - 1] + ruiseki[r] - ruiseki[l + j]);
          }
        }
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}


Measured memory_bytes: 1536
A,B,C = list(map(int, input().split()))

a = A % 2
b = B % 2
c = C % 2

ans = 0
if (a == 0 and b == 0 and c == 1):
    A += 1
    B += 1
    ans += 1
elif (a == 0 and b == 1 and c == 0):
    A += 1
    C += 1
    ans += 1
elif (a == 1 and b == 0 and c == 0):
    B += 1
    C += 1
    ans += 1
elif (a == 1 and b == 0 and c == 1):
    A += 1
    C += 1
    ans += 1
elif (a == 1 and b == 1 and c == 0):
    A += 1
    B += 1
    ans += 1
elif (a == 0 and b == 1 and c == 1):
    B += 1
    C += 1
    ans += 1

arr = sorted([A,B,C])
l = arr[2]
m = arr[1]
n = arr[0]
ans += (l - m) // 2
ans += (l - n) // 2
print(ans)

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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
 
int main(int argc,char* argv[]) { 
    io() ;
    #ifndef ONLINE_JUDGE
     //   freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int a,b ;
    cin >> a >> b ;
    a += b ;
    a %= 24 ;
    cout << a << endl ;
    return 0 ; 
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]p = new int[n];
     
    for(int i=0; i<n; i++) {
    	p[i] = sc.nextInt();
     	}
    Arrays.sort(p);
    int al = 0;
    for(int i=0; i<n-1; i++) {
    	al += p[i];
    }
    System.out.println(p[n-1]/2+al);
      }
}


Measured memory_bytes: 35628
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int h, w;
	cin >> h >> w;
	int a[505][505];
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}
	vector<tuple<int,int,int,int>>ans;
	bool move = false;
	P be = { 0,0 };
	rep(y, h) {
		if (y % 2 == 0) {
			rep(x, w) {
				if (move) {
					ans.push_back(make_tuple(be.first, be.second, y, x));
					if (a[y][x] % 2 == 1) move = false;
				}
				else {
					if (a[y][x] % 2 == 1) move = true;
				}
				be = { y,x };
			}
		}
		else {
			for (int x = w - 1; x >= 0; x--) {
				if (move) {
					ans.push_back(make_tuple(be.first, be.second, y, x));
					if (a[y][x] % 2 == 1) move = false;
				}
				else {
					if (a[y][x] % 2 == 1) move = true;
				}
				be = { y,x };
			}
		}
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << get<0>(ans[i]) + 1 << " ";
		cout << get<1>(ans[i]) + 1 << " ";
		cout << get<2>(ans[i]) + 1 << " ";
		cout << get<3>(ans[i]) + 1;
		cout << endl;
	}

	return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vi h(n);
    REP(i,0,n) cin>>h[i];

    Vi p1(n),p2(n);
    REP(i,0,n){
        p1[i]=i+1-h[i];
        p2[i]=i+1+h[i];
    }
    map<int,int> ma1,ma2;
    REP(i,0,n){
        ma1[p1[i]]++;
        ma2[p2[i]]++;
    }

    int ans=0;
    for(auto x : ma1){
        ans += x.second*ma2[x.first];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 42168
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__  == "__main__":
    n = int(input())
    A1 = list(map(int,input().split()))
    A2 = list(map(int,input().split()))
    ruiseki_wa = [0]*(n)
    ruiseki_wa[0] = A1[0]
    for i in range(1,n):
        ruiseki_wa[i] = ruiseki_wa[i-1] + A1[i]
    ans = 0
    for i in range(n):
        c = ruiseki_wa[i]
        for j in range(i,n):
            c += A2[j]
        ans = max(ans,c)
    print(ans)

Measured memory_bytes: 3420
#include <stdio.h>

int main(void){
    int n,m,i;
    scanf("%d %d",&n,&m);
    int A[m],sum=0;
    
    for(i=0;i<m;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    if(n-sum>=0)
        printf("%d",n-sum);
    else{
        printf("-1");
    }
    
    return 0;
}

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

int main(){
    int N, X;
    cin >> N >> X;
    int L[100];
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    int D = 0;
    int count = 0;
    for(int i = 0; i < N + 1; i++){
        if(D <= X){
            count++;
        }
        D += L[i];
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = raw_input()
enemy = map(int, raw_input().split())
hero = map(int, raw_input().split())

counter = 0
enemyKill = 0

while counter < int(N):
  if hero[counter] > enemy[counter]:
    hero[counter] -= enemy[counter]
    enemyKill += enemy[counter]
    enemy[counter] = 0
    if hero[counter] > enemy[counter + 1]:
      hero[counter] -= enemy[counter + 1]
      enemyKill += enemy[counter + 1]
      enemy[counter + 1] = 0
    else:
      enemy[counter + 1] -= hero[counter]
      enemyKill += hero[counter]
      hero[counter] = 0
  else:
    enemy[counter] -= hero[counter]
    enemyKill += hero[counter]
    hero[counter] = 0
  counter += 1  
print enemyKill

Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define ff(i,a,n) for(int i=a;i<n;i++)
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,c=0;
    cin>>n;
    vector<string> v(n);string s="";
    ff(i,0,n)
    cin>>v[i];
    sort(v.begin(), v.end());
    ff(i,0,n)
    {
        if(v[i]!=s)
            {
                c+=1;
                s=v[i];
            }
    }
    cout<<c;
    return 0;
}


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

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        long a = sc.nextLong();
        long b = sc.nextLong();

        System.out.println(a * b / gcd(a, b));

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


Measured memory_bytes: 22740
#include <stdio.h>

int main(void){
  int k,i,p=7,t=0;
  scanf("%d",&k);
  for(i=1;i<=k;i++){
    t=(t+p)%k;
    if(t==0){
      printf("%d",i);
  	  return 0;
    }
    p*=10;
    p=p%k;
  }
  printf("%d",-1);
  return 0;
}
    
    

Measured memory_bytes: 1732
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, K; cin >> N >> K;
    vector<int> As(N); for (auto &Ai : As) cin >> Ai;
    // 全ての数字を１にする必要がある
    cout << (N - 1 + K - 2) / (K - 1) << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    int a[N];
    map<int,int> mp;
    
    for(int i=0;i<N;i++){
        cin >> a[N];
        mp[a[N]]++;
    }
    
    int ans = 0,tmp = 0;
    for(int i=1;i<100000;i++){
        tmp = mp[i-1]+mp[i]+mp[i+1];
        ans = max(ans,tmp);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6528
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	int n; cin >> n;

	if (n == 3) {
		cout << "2 5 63" << endl;
		return 0;
	}

	int m = min(n - 2, 15000);
	if ((n - m) % 2 == 1) m--;

	for (int i = 1; i <= m; i++) {
		cout << 2 * i << " ";
	}

	int x = m * (m + 1);

	while(x % 2 == 0) x /= 2;

	int p = 3;

	assert(x > 1);

	while(true) {
		if (x % p == 0) break;
		p++;
	}

	int ost = n - m;

	for (int i = p;; i += p) {
		if (i % 2 == 0) continue;
		cout << i << " ";
		ost--;
		if (ost == 0) break;
	}

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int sum = 0;
    rep(i,n) sum += a[i];
    int cnt = 0;
    rep(i,n){
        if(a[i]*4*m >= sum) cnt++;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>

int researchMax(int a[5]);

int main(void)
{
    int iIndex;
    int iInput[5];
    int iSumTime = 0;
    int iMax = 0;
    for(iIndex = 0; iIndex < 5; iIndex++)
    {
        std::cin>>iInput[iIndex];
        if(0 == iInput[iIndex] % 10)
        {
            iSumTime = iInput[iIndex] + iSumTime;
        }
        else
        {
            iSumTime = iInput[iIndex] + iSumTime + (10 - iInput[iIndex] % 10);
            if((10 - iInput[iIndex] % 10) > iMax)
            {
                iMax = 10 - iInput[iIndex] % 10;
            }
        }
        //std::cout<<"iMax = "<<iMax<<" ,iSumTime = "<<iSumTime<<std::endl;
    }

    std::cout<<iSumTime - iMax<<std::endl;
    //std::cout<<"iMax = "<<iMax<<std::endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int c[210000];
int t[210000];
int sum[410000];
int M=201000;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<a;i++)t[c[i]]++;
	for(int i=1;i<=a;i++){
		sum[i-t[i]+M]++;
		sum[i+M]--;
	}
	for(int i=0;i<410000-1;i++){
		sum[i+1]+=sum[i];
	}
	int cnt=0;
	for(int i=0;i<a;i++){
		if(sum[i+M]==0)cnt++;
	}
	while(b--){
		int p,q;scanf("%d%d",&p,&q);p--;
		int fr=c[p];
		c[p]=q;
		int to=q;
		t[fr]--;
		sum[fr-t[fr]-1+M]--;
		if(fr-t[fr]-1>=0&&sum[fr-t[fr]-1+M]==0)cnt++;
		t[to]++;
		sum[to-t[to]+M]++;
		if(to-t[to]>=0&&sum[to-t[to]+M]==1)cnt--;
		printf("%d\n",cnt);
	}
}

Measured memory_bytes: 4480
#D
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
most = c.most_common()
ans = len(most)
eaten = 0
for t in most:
    if t[1] != 1:
        eaten += t[1]-1
if eaten%2 == 1:
    print(ans-1)
else:
    print(ans)

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
void solve(int tc){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool f=0;
    while(a>0&&c>0){
        if(!f)c-=b;
        else a-=d;
        f=!f;
    }
    if(a>0)cout<<"Yes";
    else cout<<"No";
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(20);
    int t=1,ctr=0;
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}

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

using namespace std;

typedef long long ll;

const ll MOD = 998244353;

ll dp[4001][4001];

int main() {
    string s;
    cin >> s;
    int n = s.length();

    dp[0][0] = 1LL;
    int red = 0, r = 0;
    for(int i=0;i<2*n;++i) {
        if(i < n) {
            r = 2 - int(s[i] - '0');
            red += r;
        }
        for(int j=0;j<=min(i,red);++j) {
            if(j < red) {
                dp[i+1][j+1] += dp[i][j];
            } else {
                dp[i+1][j+1] = 0;
            }
            dp[i+1][j+1] %= MOD;
            if(i-j < min(i+1,n)*2-red) {
                dp[i+1][j] += dp[i][j];
            } else {
                dp[i+1][j] = 0;
            }
            dp[i+1][j] %= MOD;
        }
    }

    cout << dp[2*n][red] << endl;
}

Measured memory_bytes: 123520
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

int main(){
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s  >> t;
    ll l = (n*m)/gcd(n, m);
    ll ln = l/n, lm = l/m;

    for(ll i = 0; i < l; i+=max(ln, lm)){
        if(i%ln == i%lm && i%ln==0){
            if(s[i/ln]!=t[i/lm]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << l << endl;

}

Measured memory_bytes: 640
/*input
5
7 2 3 8 5
3
4 2
1 7
4 13
*/

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

	int N, M;
	cin >> N;

	vector<int> T(N);
	for(int i=0;i<N;i++){
		cin >> T[i];
	}
	cin >> M;

	for(int i=0;i<M;i++){
		vector<int> V(T);
		int p,x;
		cin >> p >> x;
		V[p-1] = x;

		int total;
		total = accumulate(V.begin(), V.end(), 0);
		cout << total << endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            //// 整数の入力
            //long n = long.Parse(Console.ReadLine());
            //// 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');
            //// 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var iter = Math.Pow(2, (s.Length - 1));
            long ans = 0;
            var a = new bool[s.Length - 1];
            for (int i = 0; i < iter; i++)
            {
                for (int j = 0; j < s.Length - 1; j++)
                {
                    a[j] = ((i >> j) & 1) == 1;
                }
                string tmp = string.Empty;
                for (int k = 0; k < s.Length; k++)
                {
                    tmp += s[k] + ((k < s.Length-1) && a[k] == true ? "+" : "");
                }
                ans += tmp.Split('+').Select(x => long.Parse(x)).Sum();
            }

            Console.WriteLine(ans.ToString());

            Console.Out.Flush();
        }
        public static long fib(long n)
        {
            if (n == 1 || n == 2)
            {
                return 1;
            }
            return fib(n - 1) + fib(n - 2);
        }
    }
}


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

int main() {
    ll mod = 1000000007;
    ll N, M;
    cin >> N >> M;
    ll ans;
    ll Nkai = 1;
    ll Mkai = 1;
    rep(i,N) Nkai = Nkai * (i + 1) % mod;
    rep(i,M) Mkai = Mkai * (i + 1) % mod;
    if (N - M == 0) {
        ans = 2 * Nkai * Mkai % mod ;
    } else if (abs(N - M) == 1) {
        ans = Nkai * Mkai % mod ;
    } else {
        ans = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
import math
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(n-2):
  for j in range(i+1,math.ceil((i+n)/2)):
    if s[i] != s[j] and s[j] != s[j*2-i] and s[j*2-i] != s[i]:
      ans -= 1
print(ans)

Measured memory_bytes: 9112
#include <iostream>
typedef long long ll;
using namespace std;

ll mod=998244353;
const int SIZE=5010;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

ll ans[4010], beki2[2020];
ll solve(int n, int p, int q, int r){
	if(r==1) return (solve(n-1, p, q, 0)+solve(n, p, q, 0))%mod;
	ll res=0;
	for(int i=0; i<=p; ++i){
		ll now=COM(p, i, mod);
		(now *= beki2[i]) %= mod;
		(now *= COM(n+q-1, n-i, mod)) %= mod;
		(res += now) %= mod;
	}
	return res;
}

int main() {
	int N, K;
	cin >> K >> N;
	COMinit(mod);
	beki2[0]=1;
	for(int i=1; i<2020; ++i) beki2[i]=(beki2[i-1]*2)%mod;
	for(int i=2; i<=K*2; ++i){
		if(i>K+1) ans[i]=ans[K*2+2-i];
		else if(i%2==0){
			ans[i]=solve(N, i/2-1, K-i+1, 1);
		}else{
			ans[i]=solve(N, i/2, K-i+1, 0);
		}
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int len;
	int a[30];
	
	while (cin >> len, len){
		int n = 32;
		
		for (int i = 0; i < len; i++){
			cin >> a[i];
		}
		
		int i = 0, j = 0;
		while (1){
			if (i % 2 == 0){
				n -= (n - 1) % 5;
			}
			else {
				n -= a[j % len];
				j++;
			}
			
			if (0 >= n){
				n = 0;
				cout << n << endl;
				break;
			}
			cout << n << endl;
			i++;
			
		}
	}
	return (0);
}

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

const int MAXN=100005;
	
	void solve() {
        ll a,b,c,k;
        cin>>a>>b>>c>>k;
        ll xx=0;
        while(a>=b){
            xx++;
            b*=2;
        }
        while(b>=c){
            xx++;
            c*=2;
        }
        if(xx>k)
            cout<<"No";
        else
            cout<<"Yes";
        cout<<endl;
	}
	
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
    	// cout<<"Case #"<<tt<<": ";
    	solve();
    }
    cerr << "Time : " << 1000 * ((double) clock()) / (double) CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3804
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
int pt[123456], n, m, k, cl[123456];
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	cin >> n >> m >> k;
	int ans = k + 1;
	for (int i = 1; i <= n; i++) {
		pt[i] = i;
		cl[i] = m + 1;
	}
	for (int i = 1; i <= k; i++) {
		int t; cin >> t;
		if (t == 1) {
			int a, b;
			cin >> a >> b;
			cl[a] = cl[root(a)];
			cl[b] = cl[root(b)];
			if (cl[a] > m || cl[b] > m || cl[a] == cl[b]) {
				unite(a, b);
				int c = m + 1;
				if (cl[a] <= m)c = cl[a];
				else if (cl[b] <= m)c = cl[b];
				cl[a] = c; cl[b] = c; cl[root(a)] = c;
			}
			else ans = min(ans, i);
		}
		else {
			int c, x;
			cin >> c >> x;
			cl[c] = cl[root(c)];
			if (cl[c] <= m && x != cl[c])ans = min(ans, i);
			else {
				cl[c] = x;
				cl[root(c)] = x;
			}
		}
	}
	if (ans > k)cout << "0\n";
	else cout << ans << endl;
}


Measured memory_bytes: 4656
while 1:
	n = input()
	if n == 0: break
	ans = 0
	for i in range(96):
		t = i*(i+1)*(i+2)/6
		if t > n: break
		ans = max(ans,int((n-t)**(1.0/3)+1e-8)**3 + t)
	print ans

Measured memory_bytes: 4348
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays; 

public class   Main
{
  BufferedReader in;
  StringTokenizer as;
  int nums[],nums2[];
  int[] nums1[];
  boolean con = true;
  
  ArrayList < Integer >  ar = new ArrayList < Integer >();
  ArrayList < Integer >  fi = new ArrayList < Integer >();
  Map<Integer,Integer > map = new HashMap<Integer, Integer>();
  public static void main (String[] args)
  {
    new Main  ();
  }
  
  public int GCD(int a, int b) {
    if (b==0) return a;
    return GCD(b,a%b);
  }
  
  public int LIS(int arr[])
  {
    int n = arr.length;
    int sun[] = new int [n];
    int cur = 0;
    for(int x = 0;x<n;x++)
    {
      int temp = Arrays.binarySearch(sun,0,cur,arr[x]);
      if(temp < 0)
        temp = -temp -1;
      sun[temp] = arr[x];
      if(temp == cur)
        cur++;
    }
    return cur;
    
  }
  
  
  
  
  public Main  ()
  {
    try
    {
      
      in = new BufferedReader (new InputStreamReader (System.in));
      int a = nextInt();
      nums = new int [a];
      for(int x = 0;x<a;x++)
      {
        nums[x] = nextInt();
      }
      long sum = 0;
      for(int x = 0;x<a;x++)
        sum += nextInt();
      nums2 = new int [a-1];
      for(int x = 0;x<a-1;x++)
        nums2[x] = nextInt();
      for(int x = 1;x<a;x++)
      {
        if(nums[x-1] + 1 == nums[x])
          sum += nums2[nums[x-1]-1];
      }
      System.out.println(sum);
      
    }
    catch(IOException e)
    {
      
    }
  }
  
  
  
  
  
  
  
  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }
    
    
    return as.nextToken ();
  }
  
  
  
  long nextLong () throws IOException
  {
    return Long.parseLong (next ());
  }
  
  
  int nextInt () throws IOException
  {
    return Integer.parseInt (next ());
  }
  
  
  double nextDouble () throws IOException
  {
    return Double.parseDouble (next ());
  }
  
  
  String nextLine () throws IOException
  {
    return in.readLine ().trim ();
  }
}

Measured memory_bytes: 21204
n, m = map(int, input().split())
ans = ['0'] * n
for i in range(m):
    s, c = map(int,input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        break
    if ans[s-1] != '0' and c != ans[s-1]:
        print(-1)
        break
    ans[s-1] = c
else:
    if n == 1 and int(ans[0]) == 0:
        print(0)
        exit()
    elif ans[0] == '0':
        ans[0] = '1'
    ans = map(str, ans)
    print(''.join(ans))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const long double pi = acosl(-1.0);
int main() {
    long double A, B, H, M; cin >> A >> B >> H >> M;
    long double h = 30 * H + M / 2.0;
    long double m = M * 6;
    long double diff = min(abs(h - m), 360 - abs(h - m));
    diff *= pi / 180;
    cout << fixed << setprecision(20) << sqrt(A * A + B * B - 2 * A * B * cos(diff)) << '\n';
}

Measured memory_bytes: 4172
import sys
input = sys.stdin.readline
print = sys.stdout.write

class Node:
    __slots__ = ["data", "left", "right"]
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

class BinarySearchTree:
    __slots__ = ["root"]
    def __init__(self):
        self.root = None
    
    def insert(self, data):
        parent = self.root
        if parent is None:
            self.root = Node(data)
            return
        while parent:
            parent_old = parent
            parent = parent.left if data < parent.data else parent.right
        if data < parent_old.data:
            parent_old.left = Node(data)
        else:
            parent_old.right = Node(data)


def print_preorder(node):
    print(" {}".format(node.data))
    if node.left:
        print_preorder(node.left)
    if node.right:
        print_preorder(node.right)

def print_inorder(node):
    if node.left:
        print_inorder(node.left)
    print(" {}".format(node.data))
    if node.right:
        print_inorder(node.right)

if __name__ == "__main__":
    n = int(input())
    binary_search_tree = BinarySearchTree()
    for _ in range(n):
        operation, *num = input().split()
        if num:
            binary_search_tree.insert(int(num[0]))
        elif binary_search_tree.root is not None:
            print_inorder(binary_search_tree.root)
            print("\n")
            print_preorder(binary_search_tree.root)
            print("\n")


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

class Main
{
    public static void main (String args[]) throws IOException         //?????????
    {
        InputStreamReader is = new InputStreamReader(System.in);       //?????????
        BufferedReader br = new BufferedReader(is);                    //?????????
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
        else{
            System.out.println("a == b");
        }
    }
}
    

Measured memory_bytes: 26244