akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

//freopen("input.txt", "r", stdin);

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

   int t; cin>>t;
   set<string>st;
   while(t--)   {
        string s; cin>>s;

        st.insert(s);
   }
   cout<<st.size()<<endl;
   End;
}


Measured memory_bytes: 19244
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200000+10;
struct dong{
    int id,x,y;
} p[maxn],p1,p2;
struct suan{
    dong x,y;
}a[maxn];
int sta[maxn];
int i,j,k,l,t,n,m,x,y,r,c,tot,top;
bool is(dong x){
    return x.x==0||x.y==0||x.x==r||x.y==c;
}
int sum(dong x){
    if(x.x==0) return 2*r+c+c-x.y;
    if(x.y==0) return x.x+x.y;
    if(x.x==r) return r+x.y;
    if(x.y==c) return r+c+r-x.x;
}
bool cmp(dong a,dong b){
    return sum(a)<sum(b);
}
int main(){
    scanf("%d%d%d",&r,&c,&n);
    fo(i,1,n){
        scanf("%d%d",&x,&y);
        p1=(dong){i,x,y};
        scanf("%d%d",&x,&y);
        p2=(dong){i,x,y};
        a[i]=(suan){p1,p2};
        if (is(p1)&&is(p2)){
            p[++tot]=p1;
            p[++tot]=p2;
        }
    }
    sort(p+1,p+tot+1,cmp);
    fo(i,1,tot){
        if (top&&sta[top]==p[i].id) top--;
        else sta[++top]=p[i].id;
    }
    if (top) printf("NO\n");else printf("YES\n");
}

Measured memory_bytes: 7552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string s;
set<int> st[26];

int main(void){
	int n,q,t,i,j,l,r,ans;
	char c;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		s[i] -= 'a';
		st[s[i]].insert(i);
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> t;
		if(t>1){
			cin >> l >> r; --l;
			ans = 0;
			for(j=0; j<26; ++j){
				ans += (st[j].lower_bound(l) != st[j].end() && *st[j].lower_bound(l) < r);
			}
			cout << ans << endl;
		}else{
			cin >> j >> c; --j;
			c -= 'a';
			st[s[j]].erase(j);
			st[c].insert(j);
			s[j] = c;
		}
	}
	return 0;
}


Measured memory_bytes: 24196
#include <stdio.h>
#include <math.h>

int main(void){
    int tg,i,j,n,l[300001]={0},c=0;
    for(i=2;i<300001;i++){
        if(i%7==1 | i%7==6){
            l[c]=i; 
            c++;
        }
    }
    for(i=0;i<(int)(sqrt(c));i++){
        if(!l[i]){continue;}
        for(j=i+1;j<c;j++){
            if(!(l[j]%l[i])){l[j]=0;}
        }
    }

    while(1){
        scanf("%d",&tg);
        if(tg==1){break;}
        printf("%d:",tg);
        for(i=0;i<c;i++){
            if(l[i] && !(tg%l[i])){printf(" %d",l[i]);}
        }
        printf("\n");
    }
    return 0;
}
    
            



Measured memory_bytes: 2904
#include <iostream>
using namespace std;
 
#define MAX   100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY  1
#define BLACK 2
 
int n, M[MAX][MAX];
 
void dijkstra() {
  int d[MAX], p[MAX], color[MAX];
  int minv, u;
  for ( int i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
 
  d[0] = 0;
color[0] = GRAY;
  while ( 1 ) {
    minv = INFTY;
    u = -1;
    for ( int i = 0; i < n; i++ ) {
      if ( minv > d[i] && color[i] != BLACK ) {
        minv = d[i];
u = i;
      }
    }
    if ( u == -1 ) break;
    color[u] = BLACK;
    for ( int v = 0; v < n; v++ ) {
      if ( color[v] != BLACK && M[u][v] != INFTY ) {
        if ( d[v] > d[u] + M[u][v] ) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
 
  for ( int i = 0; i < n; i++ ) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}
 
int main() {
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      M[i][j] = INFTY;
    }
  }
 
  int k, c, u, v;
  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    for ( int j = 0; j < k; j++ ) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
 
  dijkstra();
 
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define endl '\n'
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define inf 1e18
#define pf push_front
#define pob pop_back
#define pof pop_front
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

typedef pair<int,int> pi;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;

int32_t main()
{
   // boost
    int t=1;
    //cin>>t;
    while(t--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;

        cout<<max(a*c,max(a*d,max(b*c,b*d)));
    }


    

}

Measured memory_bytes: 3632
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
  return a>b ? a : b
end
N=gets.to_i
a=array(N,0,2)
a[0]=get_i
a[1]=get_i
dp=array(N,0,2)
dp[0][0]=a[0][0]
2.times do|i|
  N.times do|j|
    next if i-1<0 and j-1<0
    if i-1<0
      dp[i][j]=dp[i][j-1]+a[i][j]
    elsif j-1<0
      dp[i][j]=dp[i-1][j]+a[i][j]
    else
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j]
    end
  end
end
puts dp[1][N-1]

Measured memory_bytes: 1916
#include <stdio.h>
void insertionSort(int *, int );
void print(int *, int );

int main(){
  int A[100],N=0,i,j;
  
  scanf("%d",&N);
  for( i = 0; i < N; i++ ){
    scanf("%d",&A[i]);
  }
  print(A,N);
  insertionSort(A, N);

  return 0; 
}

void insertionSort(int *A, int N){
  int v=0,j=0,i;
  for( i = 1; i < N; i++ ){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    print(A,N);
  }
}

void print(int *A, int N){
  int i;
  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }
  if(i==N-1){
    printf("%d",A[i]);
  }
  printf("\n");
}



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

int main(void)
{
    int m, n, g;
    int a[10], b[10];
    int dp[11][1001];
    int i, j, k;
    int sum;
    
    while (1){
        scanf("%d", &m);
        
        if (m == 0){
            break;
        }
        
        for (i = 0; i < m; i++){
            scanf("%d%d", &a[i], &b[i]);
        }
        
        memset(dp, 0, sizeof(dp));
        
        dp[0][0] = 1;
        for (i = 0; i < m; i++){
            memcpy(dp[i + 1], dp[i], sizeof(dp[i]));
            for (j = a[i] * b[i]; j >= a[i]; j -= a[i]){
                for (k = 1000; k - j >= 0; k--){
                    dp[i + 1][k] += dp[i][k - j];
                }
            }
        }
        scanf("%d", &g);
        
        for (i = 0; i < g; i++){
            scanf("%d", &n);
            printf("%d\n", dp[m][n]);
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i,N) cin >> h[i];
  int ans = 0;
  rep(i,N) {
    if (h[i] >= K) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3192
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class BIT:
    def __init__(self, li):
        self.n, self.data = len(li) + 1, [0] + li
        for i in range(1, self.n):
            if i + (i & -i) < self.n: self.data[i + (i & -i)] += self.data[i]

    def add(self, i, a):
        i += 1
        while i < self.n:
            self.data[i] += a
            i += i & -i

    # sum of [0, i)
    def acc(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res

    # sum of [l, r)
    def get(self, l, r = None):
        if r is None: r = l+1
        return self.acc(r) - self.acc(l)

def main():
    N, Q = LI()
    A = LI()
    query = LIR(Q)
    bit = BIT(A)
    # print([bit.get(i) for i in range(N)])

    for a, b, c in query:
        if a == 0:
            bit.add(b, c)
        else:
            print(bit.get(b, c))
        # print([bit.get(i) for i in range(N)])




if __name__ == '__main__':
    main()

Measured memory_bytes: 179536
#include<stdio.h>
#include<math.h>
#include<string.h>


int main(void){
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  int i,j;
  int ans=0;
  for(i=0;i<n;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      ans++;
    }
  }
  printf("%d",ans);


  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int n; cin >> n;
    deque<Int> dq;

    rep(i, 0, n) {
        Int a; cin >> a;
        if (i%2 == 0) dq.emplace_back(a);
        else dq.emplace_front(a);
    }

    if (n%2 == 0) {
        for(auto itr = dq.begin(); itr != dq.end(); ++itr) cout << *itr << " ";
    }
    else {
        for(auto itr = dq.rbegin(); itr != dq.rend(); ++itr) cout << *itr << " ";
    }
    cout << endl;
}


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

int main() {
  string S;
  cin >> S;
  if (S.at(0) == S.at(3) && S.at(1) == S.at(2) && S.at(0) != S.at(1) ){
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(1) && S.at(3) == S.at(2) && S.at(1) != S.at(2) ){
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(2) && S.at(1) == S.at(3) && S.at(1) != S.at(2) ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

b = 0

for i in range(N):
  a = 0
  for j in range(i+1):
    a += A1[j]
  for j in range(1,N+1-i):
    a += A2[N-j]
  if a > b:
    b = a

print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  int c = N/(A+B);
  N %= (A+B);

  cout << c*A+min(N, A) << "\n";

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = sum(a)
for i in range(len(b)):
  if a[i]+a[i+1]<b[i]:
    a[i] = 0
    a[i+1] = 0
  elif a[i]<b[i]:
    a[i+1] = a[i]+a[i+1]-b[i]
    a[i] = 0
  else:
    a[i]-=b[i]
    
print(x-sum(a))

Measured memory_bytes: 97756
#include<cstdio>
const int maxn=100000;
int n,m,fa[maxn+10],dfa[maxn+10];
int getfa(int x){
	int u=x,d=0; 
	for(;fa[u]!=u;u=fa[u]) d+=dfa[u];
	for(int i=x,p;fa[i]!=i;i=p){
		p=fa[i]; fa[i]=u; d-=dfa[i]; dfa[i]+=d;
	}
	return u;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) fa[i]=i;
	for(int i=1;i<=m;++i){
		int l,r,d; scanf("%d%d%d",&l,&r,&d);
		int ll=getfa(l),rr=getfa(r);
		if(ll!=rr){
			fa[ll]=rr; dfa[ll]=dfa[r]-dfa[l]-d;
		}else if(dfa[r]-dfa[l]-d){
			printf("No"); return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a = 0, b = 0, c = 0, d = 0;
	char aa[202];
	scanf("%d", &n);
	getchar();
	for(int i = 0; i < n; i++)
	{
		scanf("%c", &aa[i]);
		getchar();
		}
	for(int i = 0; i < n; i++)
	{
		if(aa[i] == 'G')
		{
			a = 1;
			}
		if(aa[i] == 'P')
		{
			b = 1;
			}
		if(aa[i] == 'W')
		{
			c = 1;
			}
		if(aa[i] == 'Y')
		{
			d = 1;
			}
		}
	if(a + b + c + d == 3)
	{
		printf("Three\n");
		return 0;
		}
	if(a + b + c + d == 4)
	{
		printf("Four\n");
		return 0;
		}
	}

Measured memory_bytes: 128
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define s second
#define f first
#define mp make_pair
typedef std::pair<int,int> pii ;

using namespace std;

const int N=1e5+10;
int n,m,x,y,dp[N],ans;
bool mark[N];
vector<int> adj[N];

void dfs(int v){
    mark[v]=true;
    for(int i=0;i<adj[v].size();i++){
        int u=adj[v][i];
        if(!mark[u]){
            mark[u]=true;
            dfs(u);
        }
        dp[v]=max(dp[v],dp[u]+1);
    }
    ans=max(ans,dp[v]);
}

int32_t main(){
	ibsws(true==false);
	cin>>n>>m;
	for(int i=0;i<m;i++){
        cin>>x>>y;
        adj[x].pb(y);
	}
	for(int i=1;i<=n;i++){
        if(!mark[i]){
            dfs(i);
        }
	}
	cout<<ans;
}


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

using namespace std;

const int maxn  = 2005;
struct Node {
	int id;
	char color;
} a[maxn*2];

int F[maxn][maxn];
int costB[maxn][maxn];
int costW[maxn][maxn];
int N;

int v[maxn];

void init()
{
	int vsize = 0;
	for(int i=0; i<2*N; i++)
	{
		if(a[i].color=='B') {
			int j=0;
			int k=0;
			int cnt=0;
			for(int j=0; j<i; j++) if(a[j].color=='B' && a[j].id>a[i].id) cnt++;
			while(k<vsize) {
				while(v[k]>j)
				{
					costB[a[i].id][j]=vsize-k+cnt;
					j++;
				}
				k++;
			}
			while(j<=N)
			{
				costB[a[i].id][j] = cnt;
				j++;
			}
			cnt++;
		}
		else {
			// insert sort
			v[vsize++] = a[i].id;
			int j = vsize-1;
			while(j>0 && v[j-1]>v[j] )
			{
				swap(v[j-1], v[j]);
				j--;
			}
		}
	}
	
	// change to w
	vsize = 0;
	for(int i=0; i<2*N; i++)
	{
		if(a[i].color=='W') {
			int j=0;
			int k=0;
			int cnt=0;
			for(int j=0; j<i; j++) if(a[j].color=='W' && a[j].id>a[i].id) cnt++;
			while(k<vsize) {
				while(j<v[k]) {
					costW[j][a[i].id]=vsize-k+cnt;
					j++;
				}
				k++;
			}
			while(j<=N) {
				costW[j][a[i].id] = cnt;
				j++;
			}
			cnt++;
		}
		else {
			v[vsize++] = a[i].id;
			int j = vsize-1;
			while(j>0 && v[j-1]>v[j]) {
				swap(v[j], v[j-1]);
				j--;
			}
		}
	}
}

int main()
{
	cin>>N;
	for(int i=0; i<2*N; i++) cin>>a[i].color>>a[i].id;
	memset(costB,0,sizeof(costB));
	memset(costW,0,sizeof(costW));
	memset(F,0,sizeof(F));
	init();
	for(int i=1; i<=N; i++)
		F[i][0] = costB[i][0] + F[i-1][0];
	for(int i=1; i<=N; i++)
		F[0][i] = costW[0][i] + F[0][i-1];

	for(int i=1; i<=N; i++)
		for(int j=1; j<=N; j++)
		{
			F[i][j] = min(F[i-1][j]+costB[i][j], F[i][j-1]+costW[i][j]);
		}
	cout<<F[N][N]<<endl;
	return 0;
}



Measured memory_bytes: 50796
#include"bits/stdc++.h"
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define D(i,j,n) for(register int i=j;i>=n;i--)
#define ll long long
using namespace std;
namespace io{
	const int L=(1<<19)+1;
	char ibuf[L],*iS,*iT,c;int f;
	char gc(){
		if(iS==iT){
			iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
			return iS==iT?EOF:*iS++;
		}
		return*iS++;
	}
	template<class I>void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
};
using io::gi;
using io::gc;
int n,m,a[5];
int main(){
	#ifdef JHR
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	#endif
	gi(n);a[n]++;
	gi(n);a[n]++;
	gi(n);a[n]++;
	gi(n);a[n]++;
	gi(n);a[n]++;
	gi(n);a[n]++;
	puts(max(max(a[1],a[2]),max(a[3],a[4]))==2&&min(min(a[1],a[2]),min(a[3],a[4]))==1?"YES":"NO");
	return 0;
}



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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll MOD = 1e9 + 7;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

constexpr ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(a, b, dummy1, dummy2);
}

struct Fp {
  ll val;

  Fp(ll t = 0) :
    val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {}

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val > MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

ll N, K;
constexpr ll maxN = 2000;
vector<Fp> fact(maxN+1);
vector<Fp> invFact(maxN+1);

Fp combi(ll n, ll r) {
  return fact.at(n) * invFact.at(r) * invFact.at(n-r);
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  fact.at(0) = 1;
  for (ll i = 1; i <= maxN; i++) fact.at(i) = i * fact.at(i-1);
  invFact.at(maxN) = fact.at(maxN).inv();
  for (ll i = maxN; i >= 1; i--) invFact.at(i-1) = i * invFact.at(i);

  cin >> N >> K;
  for (ll i = 1; i <= K; i++) {
    if (i > N - K + 1) {
      cout << "0\n";
    }else {
      Fp x = combi(K-1, i-1);
      Fp y = combi(N - K + 1, i);
      cout << x*y << "\n";
    }
  }
  
  return 0;
}



Measured memory_bytes: 256
n=int(input())
memo=[0]*10**5
a=list(map(int,input().split()))
for i in a:
    memo[i]+=1
ans=0
for i in range(10**5):
    tmp=0
    tmp+=memo[i]
    if i!=0:
        tmp+=memo[i-1]
    if i!=10**5-1:
        tmp+=memo[i+1]
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 14768
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=100+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
}
int s,t,n;
void input()
{
	n=read<int>(),s=read<int>(),t=read<int>();
}
void out(int s,int t,int v)
{
	//cerr<<s<<' '<<t<<' '<<v<<endl;
	if(s==t)write(s,' ');
	else
	{
		int x=(s^t)&-(s^t);
		v^=x;
		int y=v&-v;
		out(s,s^y,v);
		out(s^x^y,t,v);
	}
}
void work()
{
	if(__builtin_popcount(s^t)&1)
	{
		puts("YES");
		out(s,t,(1<<n)-1);
	}
	else puts("NO");
}
int main()
{
	input();
	work();
	return 0;
}



Measured memory_bytes: 1024
// ABC 062 B- Picture Frame
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
// 縦横配列をどう考えるか

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> vec1(W + 2, '#'); // 最初に#で横の列を作っておく
  vector<string> vec2(H);

  // 入力
  rep(i, H) {
    cin >> vec2.at(i);
  }
  // #の囲み
  rep(i, W + 2) {
    cout << vec1.at(i);
  }
  cout << endl;
  // #を前後に入れてから出力
  rep(i, H) {
    cout << '#' << vec2.at(i) << '#' << endl;
  }
  // #の囲み
  rep(i, W + 2) {
    cout << vec1.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ki = 0;
    ll gu = 0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        if(a[i] % 2 == 0){
            gu++;
        }else if(a[i] % 2 == 1){
            ki++;
        }
    }

    string ans = "YES";
    if(ki % 2 == 1){
        ans = "NO";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int sx = in.nextInt();
		int sy = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		List<Pos> remain = new ArrayList<>();
		remain.add(new Pos(sx, sy, 0));
		remain.get(0).distAmi = 0;
		for(int i=0; i<n; i++){
			x[i] = in.nextInt();
			y[i] = in.nextInt();
			remain.add(new Pos(x[i], y[i], i+1));
		}
		List<Pos> base = new ArrayList<>();
//		List<Line> ami = new ArrayList<>();
		int used = 0;
		double sum = 0;
		for(int i=0; i<m+1; i++){
			Collections.sort(remain);
			Pos p = remain.get(used++);
//			System.err.println(p.id);
			p.distAmi = 0;
			Pos min = null;
			int minID = 100000000;
			double dist = Integer.MAX_VALUE;
			if(i==0){
				base.add(p);
				for(int j=used; j<n+1; j++){
					Pos pos = remain.get(j);
					pos.distAmi = pos.dist(p);
//					System.err.println(j+" "+pos.distAmi);
				}
				continue;
			}
			for(Pos pos: base){
				if(pos.id == p.id) continue;
				int d = p.dist2(pos);
				if(d<dist || Math.abs(d-dist)<1e-8 && minID>pos.id){
					dist = d;
					min = pos;
					minID = pos.id;
				}
			}
			base.add(p);
//			System.err.println("dist:"+dist);
			sum += Math.sqrt(dist);
//			System.err.println("minid: "+min.id);
			Line line = (new Line(p, min));
			for(int j=used; j<n+1; j++){
				Pos pos = remain.get(j);
//				if(dist(line.p1, line.p2, pos)<0){
//					System.err.println("Error!");
//				}
//				System.err.println(j+" "+dist(line.p1, line.p2, pos));
				double d = Math.min(Math.abs(dist(line.p1, line.p2, pos)), pos.dist(p));
				pos.distAmi = Math.min(d, pos.distAmi);
			}
//			ami.add(line);
		}
		System.out.println(sum);
	}
	
	public static double dist(Pos a, Pos b, Pos c){
		if(dot(b.x-a.x, b.y-a.y, c.x-a.x, c.y-a.y)<=0)
			return Math.sqrt(a.dist2(c));
		if(dot(a.x-b.x, a.y-b.y, c.x-b.x, c.y-b.y)<=0)
			return Math.sqrt(b.dist2(c));
		return triarea(a, b, c)/Math.sqrt(a.dist2(b));
	}
	
	public static double triarea(Pos a, Pos b, Pos c){
		double dx1 = b.x - a.x;
		double dy1 = b.y - a.y;
		double dx2 = c.x - a.x;
		double dy2 = c.y - a.y;
		return dx1*dy2 - dx2*dy1;
	}
	
	public static double dot(double x, double y, double x1, double y1){
		return x*x1+y*y1;
	}
	
	public static double dot(Pos a, Pos b){
		return a.x*b.x+a.y*b.y;
	}
}

class Line{
	Pos p1, p2;
	Line(Pos p1, Pos p2){
		this.p1 = p1;
		this.p2 = p2;
	}
}

class Pos implements Comparable<Pos>{
	int x, y;
	int id;
	double distAmi = Integer.MAX_VALUE;
	int baseId;
	Pos(int x, int y, int id){
		this.x = x;
		this.y = y;
		this.id = id;
	}
	double dist(Pos a){
		return Math.sqrt(dist2(a));
	}
	int dist2(Pos a){
		return sq(a.x-x)+sq(a.y-y);
	}
	int sq(int a){
		return a*a;
	}
	@Override
	public int compareTo(Pos p) {
		if(Math.abs(distAmi-p.distAmi)>1e-8) return Double.compare(distAmi, p.distAmi);
		else return id-p.id;
	}
}

Measured memory_bytes: 48668
N, M, C = map(int, input().split())
b = list(map(int, input().split()))
l=[]
k,s=0,0
for i in range(N):
    l.append([int(j) for j in input().split()])
    
for i in range(N):
    for j in range(M):
        s+=l[i][j]*b[j]
    if s+C>0:
        k+=1
    s=0

print(k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdlib.h>
#include <numeric>
#include <math.h>
using namespace std;
int main(){
  	string S;
    cin>>S;
    int count=0;
    for(int i = 0; i < (int)S.size(); ++i){
    if(i%2==0){
      if(S[i]=='L'){
        break;
      }
    }
    if(i%2==1){
      if(S[i]=='R'){
        break;
      }
    
    }
    count++;
    //cout<<S[i]<<endl;
    }
    if(count==S.size()){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}


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

typedef long long ll;
const int MAX_N = 100000;
const ll INF = (ll) 2e+18;

int main() {
	int N, K;
	ll x[MAX_N];

	std::cin >> N >> K;
	for(int i = 0; i < N; ++i) {
		std::cin >> x[i];
	}

	ll ans = INF;
	for(int i = 0; i + K - 1 < N; ++i) {
		ll cost;
		if(x[i] * x[i + K - 1] < 0) {
			cost = x[i + K - 1] - x[i] + std::min(std::abs(x[i]), std::abs(x[i + K - 1]));
		} else {
			cost = std::max(std::abs(x[i]), std::abs(x[i + K - 1]));
		}
		ans = std::min(ans, cost);
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 1024
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    for h in range(1, 3501):
        if N >= 4 * h:
            continue
        for n in range(h, 3501):
            if N * (h + n) >= 4 * h * n:
                continue
            t1 = N * h * n
            t2 = 4 * h * n - N * n - N * h
            if t1 % t2 == 0:
                print(h, n, t1 // t2)
                return True

if __name__ == '__main__':
    main()

Measured memory_bytes: 65364
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) { cin >> A[i]; }

    sort(all(A), greater<int>());
    double half = A[0] / 2;
    ll min_diff = INF;
    ll min_num = 0;
    for (int i = 1; i < n; i++) {
        if (min_diff > abs(A[i] - half)) {
            min_diff = abs(A[i] - half);
            min_num = A[i];
        }
    }
    cout << A[0] << " " << min_num << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define N 4001
int c[N][N];
int lcs(string s,string t){
    int m=s.size();
    int n=t.size();
    int maxl=0;
    s=' '+s;
    t=' '+t;
    for(int i=0; i<=m; i++) for(int j=0; j<=n; j++) c[i][j]=0;
    for(int i=1; i<=m; i++){
        for(int j=1; j<=n; j++){
            if(s[i]==t[j]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=0;
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}

int main(){
    string s,t;
    while(cin>>s>>t){
        cout<<lcs(s,t)<<endl;
    }
}

Measured memory_bytes: 65588
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

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

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	string s;
	cin >> n;
	cin >> s;
	
	int counter = 0;
	
	vector<bool> flags1;
	for (int number = 0; number < 10; number++)
	{
		flags1.push_back(false);
	}
	
	for (int i = 0; i < (n - 2); i++)
	{
		char c1 = s[i];
		if (flags1[c1 - '0'] == true)
		{
			continue;
		}
		flags1[c1 - '0'] = true;
		
		vector<bool> flags2;
		for (int number = 0; number < 10; number++)
		{
			flags2.push_back(false);
		}
		
		for (int j = (i + 1); j < (n - 1); j++)
		{
			char c2 = s[j];
			if (flags2[c2 - '0'] == true)
			{
				continue;
			}
			flags2[c2 - '0'] = true;
			
			vector<bool> flags3;
			for (int number = 0; number < 10; number++)
			{
				flags3.push_back(false);
			}
			
			for (int k = (j + 1); k < n; k++)
			{
				char c3 = s[k];
				if (flags3[c3 - '0'] == true)
				{
					continue;
				}
				flags3[c3 - '0'] = true;
				counter++;
			}
		}
	}
	
	
	cout << counter << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 300005;
ll bit[MAX_N+1];
int nn = MAX_N; //　1-index

void adds(int a, ll w){
    for(int x = a; x <= nn; x += x & -x) bit[x] += w;
}
ll sums(int a){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
}

ll bit2[MAX_N+1];
void adds2(int a, ll w){
    for(int x = a; x <= nn; x += x & -x) bit2[x] += w;
}
ll sums2(int a){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit2[x];
    return ret;
}

// 座標圧縮 a[n] -> z[n](zは1-index)
vector<int> zaatsu(vector<int> a){
    int n = a.size();
    vector<int> b, pre_b, z;
    rep(i,n)pre_b.push_back(a[i]);
    sort(pre_b.begin(), pre_b.end());
    rep(i,n){
        if(i == 0){
            b.push_back(pre_b[i]);
        }else{
            if(pre_b[i] != pre_b[i-1]){
                b.push_back(pre_b[i]);
            }
        }
    }
    rep(i,n){
        int tmp_z = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
        z.push_back(tmp_z);
    }

    return z;
}

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    ll MOD = 998244353;
    vector<P> v(n);
    rep(i,n){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<int> x_(n), y_(n);
    rep(i,n){
        x_[i] = v[i].first;
        y_[i] = v[i].second;
    }

    vector<int> x = zaatsu(x_);
    vector<int> y = zaatsu(y_);

    srep(i,1,n+1){
        adds2(i,1);
    }
    
    ll ans = 0;

    rep(i,n){
        ans += mod_pow(2,n-1,MOD);
        ans %= MOD;

        int kx = x[i], ky = y[i];
        adds(ky, 1);
        adds2(ky, -1);
        
        ll a = 0;
        if(ky > 1)a = sums2(ky-1);
        ll d = n - 1 - i - a;
        ll b = 0;
        if(ky > 1)b = sums(ky-1);
        ll c = i - b;

        ll tmp = (mod_pow(2,a,MOD) - 1) * (mod_pow(2,c,MOD) - 1) % MOD * mod_pow(2,b+d,MOD) % MOD
               + (mod_pow(2,b,MOD) - 1) * (mod_pow(2,d,MOD) - 1) % MOD * mod_pow(2,a+c,MOD) % MOD
               - (mod_pow(2,a,MOD) - 1) * (mod_pow(2,c,MOD) - 1) % MOD * (mod_pow(2,b,MOD) - 1) % MOD * (mod_pow(2,d,MOD) - 1) % MOD
               + MOD;
        
        ans += tmp;
        ans %= MOD;
        
    }

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


Measured memory_bytes: 14596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func isEven(x int) bool {
	return x%2 == 0
}

func isOdd(x int) bool {
	return !isEven(x)
}

func main() {
	h, w := readInt(), readInt()
	a := make([][]int, h)
	for i := range a {
		a[i] = make([]int, w)
		for j := range a[i] {
			a[i][j] = readInt()
		}
	}

	type move struct{ y1, x1, y1d, x1d int }
	ans := make([]move, 0, h*w)
	cnt := 0
	for i := range a {
		if isEven(i) {
			for j := range a[i][:len(a[i])-1] {
				if isOdd(a[i][j]) {
					ans = append(ans, move{i + 1, j + 1, i + 1, j + 2})
					a[i][j+1]++
					cnt++
				}
			}
			if lai := len(a[i]) - 1; i != len(a)-1 && isOdd(a[i][lai]) {
				ans = append(ans, move{i + 1, lai + 1, i + 2, lai + 1})
				a[i+1][lai]++
				cnt++
			}
		} else {
			for j := len(a[i]) - 1; j > 0; j-- {
				if isOdd(a[i][j]) {
					ans = append(ans, move{i + 1, j + 1, i + 1, j})
					a[i][j-1]++
					cnt++
				}
			}
			if i != len(a)-1 && isOdd(a[i][0]) {
				ans = append(ans, move{i + 1, 1, i + 2, 1})
				a[i+1][0]++
				cnt++
			}
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	wr.WriteString(strconv.Itoa(cnt) + "\n")
	for _, m := range ans {
		wr.WriteString(strconv.Itoa(m.y1) + " " + strconv.Itoa(m.x1) + " " + strconv.Itoa(m.y1d) + " " + strconv.Itoa(m.x1d) + "\n")
	}
	wr.Flush()
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
using u64 = uint_fast64_t;
using i64 = int_fast64_t;
#define rep(i, n) for(u64 i = 0; i < n; ++i)
#define dump(x) cout << #x << " = " << x << endl
template<class T>
bool chmin(T &a, const T &b){
  if(b < a){
    a = b;
    return true;
  }
  return false;
}

int main(){
  u64 n, m;
  cin >> n >> m;
  vector<vector<u64>> g(n);
  vector<vector<u64>> dist(n, vector<u64>(n, u64(1) << 30));
  rep(i, m){
    u64 a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    dist[a][b] = 1;
  }
  rep(j, n){
    rep(i, n){
      rep(k, n){
        chmin(dist[i][k], dist[i][j] + dist[j][k]);
      }
    }
  }
  u64 minlen = n + 1, v = n;
  rep(i, n){
    if(chmin(minlen, dist[i][i])){
      v = i;
    }
  }
  if(v == n){
    cout << "-1" << endl;
    return 0;
  }
  const u64 vm = v;
  vector<u64> ans;
  ans.push_back(v);
  while(minlen){
    --minlen;
    rep(i, n){
      if(dist[v][i] == 1 && dist[i][vm] == minlen){
        ans.push_back(i);
        v = i;
        break;
      }
    }
  }
  cout << ans.size() << endl;
  for(const auto e : ans){
    cout << e + 1 << endl;
  }
  
  /*
  rep(i, n){
    rep(j, n){
      cout << dist[i][j] << ' ';
    }
    cout << endl;
  }
  */
}


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

using namespace std;

int main()
{
    int k, t;
    vector<int> a;
    int max_num = 0;
    int max_ind = -1;

    cin >> k >> t;
    for (int i = 0; i < t; i++) {
        int a0;
        cin >> a0;
        a.push_back(a0);
        if (a0 > max_num) { max_num = a0; max_ind = i; }
    }

    int other = 0;
    int ans = 0;
    for (int i = 0; i < t; i++) {
        if (i != max_ind) { other += a[i]; }
    }
    ans = max_num - other - 1;

    if (ans > 0) { cout << ans << "\n"; }
    else { cout << 0 << "\n"; }

    return 0;
}

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


int MOD=1000000007;

int N,M;
int a[50],b[50];

bool graph[50][50];
bool visit[50];

void dfs(int v){
    visit[v]=true;
    for(int v2=0; v2<N; ++v2){
        if(graph[v][v2]==false) continue;
        if(visit[v2]==true) continue;
        dfs(v2);
    }
}

int main(void){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
        }
        int ans=0;

        for(int i=0; i<M; ++i){
            graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
            for(int j=0; j<N; j++) visit[j]=false;
            dfs(0);
            bool cheak=false;
            for(int j=0; j<N; j++) if(visit[j]==false) cheak=true;
            if(cheak) ans+=1;

            graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;

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


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

#define LL long long

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF=9999999;
const int MAXN=100000;
int A,B,C,D,E,F;
double ans=-1;
int t1,t2;

int main(){
	A=read(),B=read(),C=read(),D=read(),E=read(),F=read();
	for(int d1=0;d1<=F/C;d1++){
		for(int d2=0;d2<=(F-C*d1)/D;d2++)
		    for(int s1=0;s1<=(F-C*d1-D*d2)/A;s1++)
		        for(int s2=0;s2<=(F-C*d1-D*d2-A*s1*100)/B;s2++){
		        	if(d1*C+d2*D+s1*A*100+s2*B*100>F) continue;
		        	if((double)(d1*C+d2*D)/(s1*A+s2*B)>E) continue;
		        	if(ans<(double)(100.0*(d1*C+d2*D)/(d1*C+d2*D+s1*A*100+s2*B*100))){
		        		ans=(double)(100.0*(d1*C+d2*D)/(d1*C+d2*D+s1*A*100+s2*B*100));
		        		t1=d1*C+d2*D+s1*A*100+s2*B*100; t2=d1*C+d2*D;
					}
				}
	}
	printf("%d %d\n",t1,t2);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace _100to105
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            if (X / 100 >= CalcMin(X))
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
        static int CalcMin(int price)
        {
            int shimo2 = price % 100;
            int min = 0;
            for (int i = 5; i > 0; i--)
            {
                min += shimo2 / i;
                shimo2 = shimo2 % i;
            }
            return min;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    int n;
    scanf("%d", &n);
    int cnt = 0, x;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        if (x&1) ++cnt;
    }
    int ans1 = 1;
    for (int i = 1; i <= n; ++i) {
        ans1 *= 3;
    }
    int ans2 = 1;
    for (int i = 1; i <= n-cnt; ++i) {
        ans2 *= 2;
    }
    printf("%d\n", ans1-ans2);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,n,a) for(int i=n;i>a;i--)
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,INF,sizeof(x))
#define INF 100000000
using namespace std;
typedef pair<int,int> p;
typedef long long LL;
int h,w;
int nh,nw;
int dw[4]={0,1,0,-1},dh[4]={1,0,-1,0};
int cal;
char maze[105][105];
void DFS_1(int sh,int sw)
{
    maze[sh][sw]='.';
    for(int i=0;i<4;i++)
    {
        nh=sh+dh[i];nw=sw+dw[i];
        if(1<=nh&&nh<=h&&1<=nw&&nw<=w&&maze[nh][nw]=='#')
        {
            DFS_1(nh,nw);
        }
    }
}
void DFS_2(int sh,int sw)
{
    maze[sh][sw]='.';
    for(int i=0;i<4;i++)
    {
        nh=sh+dh[i];nw=sw+dw[i];
        if(1<=nh&&nh<=h&&1<=nw&&nw<=w&&maze[nh][nw]=='*')
        {
            DFS_2(nh,nw);
        }
    }
}
void DFS_3(int sh,int sw)
{
    maze[sh][sw]='.';
    for(int i=0;i<4;i++)
    {
        nh=sh+dh[i];nw=sw+dw[i];
        if(1<=nh&&nh<=h&&1<=nw&&nw<=w&&maze[nh][nw]=='@')
        {
            DFS_3(nh,nw);
        }
    }
}
int main()
{
    //freopen("input.in","r",stdin);
    while(cin>>h>>w)
    {
        if(h==0&&w==0)break;
        cal=0;
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=w;j++)
            cin>>maze[i][j];
        }
        for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(maze[i][j]=='#')
            {
                DFS_1(i,j);
                cal++;
            }

        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(maze[i][j]=='*')
            {
                DFS_2(i,j);
                cal++;
            }
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(maze[i][j]=='@')
            {
                DFS_3(i,j);
                cal++;
            }
        }
    }
    cout<<cal<<endl;
    }
    return 0;
}

Measured memory_bytes: 1480
def main():
    N = int(input())
    S = input()

    ans = 0
    tmp = list(map(str, range(0,10)))

    def myindex(Stringlist, Checkstr, default = -1):
        if Checkstr in Stringlist:
            return Stringlist.index(Checkstr)
        else:
            return default


    for V1 in tmp:
        C1 = myindex(S[:N-2], V1, default = -1)
        if C1 == -1:
            continue
        for V2 in tmp:
            C2 = myindex(S[C1+1:N-1], V2, default = -1)
            if C2 == -1:
                continue
            for V3 in tmp:
                C3 = myindex(S[C1+C2+2:], V3, default = -1)
                if C3 == -1:
                    continue
                #print("str:{}, index:{}/{}/{}".format(V1+V2+V3,C1, C1+1+C2, C1+1+C2+1+C3))
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    long long int N;
    cin >> N;
    long long int T[N+1],X[N+1],Y[N+1];
    vector<tuple<int,int,int>> A(N+1);
    A[0] = make_tuple(0,0,0);
    for(int i = 1;i < N+1;i++){
      cin >> T[i] >> X[i] >> Y[i];
      A[i] = make_tuple(T[i],X[i],Y[i]);
    }
    sort(A.begin(),A.end());
    bool frag = 1;
    int a = 0;
    for(int i = 0;i < N;i++){
      long long int t = get<0>(A[i+1])-get<0>(A[i]);
      long long int x = get<1>(A[i]),y = get<2>(A[i]);
      long long int x1 = get<1>(A[i+1]),y1 = get<2>(A[i+1]);
      long long int dis = abs(x1-x) + abs(y1-y);
      if(t >= dis && t % 2 == dis % 2){
        a++;
      }else{
        frag = 0;
      }
    }
    if(frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define SIZE 300005

using namespace std;
typedef long long ll;

int main(){
	int x;
	bool msp[SIZE];
	vector<int> ms;
	for (int i=1; i<SIZE; i++){
		if (i%7!=1 && i%7!=6) msp[i] = false;
		else{
			msp[i] = true;
			ms.push_back(i);
		}
	}
	/*
	for (int i=2; i<100; i++){
		if (msp[i]>0) printf("%d ", i);
	}
	cout << endl;
	*/
	for(int i=2; i*i<SIZE; i++){
		if (msp[i]>0){
			for(int j=1; (j<ms.size() && i*ms[j]<SIZE); j++){
				msp[i*ms[j]] = false;
			}
		}
	}
	/*
	for (int i=2; i<100; i++){
		if (msp[i]>0) printf("%d ", i);
	}
	cout << endl;
	*/
	while(1){
		vector<int> ans;
		cin >> x;
		if (x==1) break;
		for (int i=2; i<=x; i++){
			if (msp[i] && x%i==0) ans.push_back(i);
		}
		printf("%d:", x);
		if (msp[x]){
			printf(" %d", x);
		}else{
			REP(i,ans.size()){
				printf(" %d", ans[i]);
			}
		}
		cout << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3552
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
bool com (int a,int b) {     
    return a<b;   
} 
int main(){
    int n,ans=0,tmp;
    cin >>n ;
    vector<int> a;
    for(int i=0;i<n;i++){
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end(),com);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[k]<a[j]+a[i]){ans++;}
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 384