akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> xa(N), ya(N), xb(N), yb(N);
	for (int i = 0; i < N; ++i) {
		cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
	}
	vector<int> xc = xa; xc.insert(xc.end(), xb.begin(), xb.end());
	vector<int> yc = ya; yc.insert(yc.end(), yb.begin(), yb.end());
	sort(xc.begin(), xc.end());
	xc.erase(unique(xc.begin(), xc.end()), xc.end());
	sort(yc.begin(), yc.end());
	yc.erase(unique(yc.begin(), yc.end()), yc.end());
	for (int i = 0; i < N; ++i) {
		xa[i] = lower_bound(xc.begin(), xc.end(), xa[i]) - xc.begin();
		ya[i] = lower_bound(yc.begin(), yc.end(), ya[i]) - yc.begin();
		xb[i] = lower_bound(xc.begin(), xc.end(), xb[i]) - xc.begin();
		yb[i] = lower_bound(yc.begin(), yc.end(), yb[i]) - yc.begin();
	}
	int H = xc.size(), W = yc.size();
	int szx = 1, szy = 1;
	while (szx < H) szx *= 2;
	while (szy < W) szy *= 2;
	vector<set<int> > segx(szx * 2), segy(szy * 2);
	vector<set<pair<int, int> > > stx(H), sty(W);
	for (int i = 0; i < N; ++i) {
		if (xa[i] > xb[i]) swap(xa[i], xb[i]);
		if (ya[i] > yb[i]) swap(ya[i], yb[i]);
		if (ya[i] == yb[i]) {
			bool intersect = false;
			int apos = ya[i] + szy;
			while (apos >= 1) {
				set<int>::iterator it = segy[apos].lower_bound(xa[i]);
				if (it != segy[apos].end() && *it <= xb[i]) {
					intersect = true;
					break;
				}
				apos >>= 1;
			}
			set<pair<int, int> >::iterator itl = sty[ya[i]].lower_bound(make_pair(xa[i], 0));
			set<pair<int, int> >::iterator itr = sty[ya[i]].lower_bound(make_pair(xb[i], 1));
			if (itl != itr || (itr != sty[ya[i]].end() && itr->second == 1)) {
				intersect = true;
			}
			if (intersect) {
				cout << "0\n";
			}
			else {
				cout << "1\n";
				int al = xa[i] + szx, ar = xb[i] + 1 + szx;
				while (al < ar) {
					if (al & 1) segx[al++].insert(ya[i]);
					if (ar & 1) segx[--ar].insert(ya[i]);
					al >>= 1; ar >>= 1;
				}
				sty[ya[i]].insert(make_pair(xa[i], 0));
				sty[ya[i]].insert(make_pair(xb[i], 1));
			}
		}
		else /* (xa[i] == xb[i]) */ {
			bool intersect = false;
			int apos = xa[i] + szx;
			while (apos >= 1) {
				set<int>::iterator it = segx[apos].lower_bound(ya[i]);
				if (it != segx[apos].end() && *it <= yb[i]) {
					intersect = true;
					break;
				}
				apos >>= 1;
			}
			set<pair<int, int> >::iterator itl = stx[xa[i]].lower_bound(make_pair(ya[i], 0));
			set<pair<int, int> >::iterator itr = stx[xa[i]].lower_bound(make_pair(yb[i], 1));
			if (itl != itr || (itr != stx[xa[i]].end() && itr->second == 1)) {
				intersect = true;
			}
			if (intersect) {
				cout << "0\n";
			}
			else {
				cout << "1\n";
				int al = ya[i] + szy, ar = yb[i] + 1 + szy;
				while (al < ar) {
					if (al & 1) segy[al++].insert(xa[i]);
					if (ar & 1) segy[--ar].insert(xa[i]);
					al >>= 1; ar >>= 1;
				}
				stx[xa[i]].insert(make_pair(ya[i], 0));
				stx[xa[i]].insert(make_pair(yb[i], 1));
			}
		}
	}
	return 0;
}


Measured memory_bytes: 85528
{-# LANGUAGE BangPatterns #-}

import Control.Applicative ((<$>))
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS
import Data.List (scanl')

main :: IO ()
main = do
  n <- read <$> getLine
  s <- getLine
  print $ VU.maximum
    $ VU.map (\ !gap -> min gap $ test s $ drop gap s)
    $ VU.tail $ VU.generate n id

test :: String -> String -> Int
test v1 v2
 = maximum
   $ scanl' (\ !l !b -> if b then l+1 else 0) (0::Int)
   $ zipWith (==) v1 v2


Measured memory_bytes: 1148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 *
 * @author Milo
 */
public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static FastReader in = new FastReader();
    public static void main(String[] args) {
        int t = 1; //in.nextInt();
        while (t-- > 0)
            solve();
    }
 
    public static void solve() {
     
        int n = in.nextInt();
        HashSet<String> g = new HashSet();
        
        for(int i = 0; i < n; ++i){
            String t = in.nextLine();
            g.add(t);
        }
        System.out.println(g.size());
    }
 
    public static int max(int a, int b) {
        return a > b ? a : b;
    }
 
    public static int min(int a, int b) {
        return a < b ? a : b;
    }
 
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, (a % b));
    }
}


Measured memory_bytes: 66112
w1, w2, s1, s2, sp, l = map(int, input().split())
w1 *= 100
w2 *= 100

ws = set()
for i1 in range(l // w1 + 1):
    for i2 in range(l // w2 + 1):
        if i1 * w1 + i2 * w2 <= l:
            ws.add(i1 * w1 + i2 * w2)


ss = set()
for i1 in range((l * sp // 100) // s1 + 1):
    for i2 in range((l * sp // 100) // s2 + 1):
        if i1 * s1 + i2 * s2 <= l * sp / 100:
            ss.add(i1 * s1 + i2 * s2)


maxd, maxws, maxs = 0, 0, 0
for w in ws:
    for s in ss:
        if w + s > l or w == 0 or s > w * sp / 100:
            continue

        d = s / (w + s)
        if d >= maxd:
            maxd = d
            maxws = w + s
            maxs = s

print(maxws, maxs)

Measured memory_bytes: 3188
#include<stdio.h>
char n[200000];
int main(void)
{
	int ans=0,i = 0;
	scanf("%s",n);

	while(n[i]!='\0'){
		ans+=n[i]-'0';
//		printf("%d ",ans);
		i++;
	}
	
	(ans % 9 == 0) ? puts("Yes") : puts("No"); 
	//printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

void solve(ll index, ll k){


}

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

  ll n;
  cin>>n;
  ll k=0;
  while((1<<k)<n)
    k++;

  REP(i,n){
    for(ll j=i+1; j<n; j++){
      REP(g,k){
        if((i&(1<<g))!=(j&(1<<g))){
          if(j!=i+1)
            cout<<" ";
          cout<<g+1;
          break;
        }
      }
    }
    if(i!=n-1)
      cout<<endl;
  }
}



Measured memory_bytes: 3644
hoge = gets
hello = hoge.split(//)

if hello[0] == hello[1] && hello[1] == hello[2]
  puts "Yes"
elsif hello[1] == hello[2] && hello[2] == hello[3]
  puts "Yes"
elsif hello[2] == hello[3] && hello[3] == hello[4]
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
using ll = long long;
int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   int s = 0;
   rep(i,n) s^=a[i];
   rep(i,n) a[i] ^=s;
   rep(i,n){
      cout << a[i] << endl;
   }
   return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;


int main() {
  int a, b;
  cin >> a >> b;

  if (a <= 8 && b <= 8) puts("Yay!");
  else puts(":(");

  return 0;
}


Measured memory_bytes: 3628
import copy
n = int(input())
a = list(map(int,input().split()))
b = copy.copy(a)
ans_a = 0
ans_b = 0
sum_a = 0
sum_b = 0
for i in range(n):
    if i%2==0:
        if sum_a+a[i]>0:
            tmp = 0
        else:
            tmp = abs(sum_a+a[i])+1
            a[i] += tmp
            ans_a += tmp
    else:
        if sum_a+a[i]<0:
            tmp = 0
        else:
            tmp = abs(sum_a+a[i])+1
            a[i] -= tmp
            ans_a += tmp
    sum_a+=a[i]
    if i%2==1:
        if sum_b+b[i]>0:
            tmp = 0
        else:
            tmp = abs(sum_b+b[i])+1
            b[i] += tmp
            ans_b += tmp
    else:
        if sum_b+b[i]<0:
            tmp = 0
        else:
            tmp = abs(sum_b+b[i])+1
            b[i] -= tmp
            ans_b += tmp
    sum_b+=b[i]
#print(a)
#print(sum_a)
print(min(ans_a,ans_b))

Measured memory_bytes: 90500
#include <iostream>
#include <string>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	double T, A;
	cin >> N;
	cin >> T >> A;
	double min_num = INF32;
	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		double tmp;
		cin >> tmp;

		if (abs(A - (T - 0.006 * tmp)) < min_num)
		{
			min_num = min(min_num, abs(A - (T - 0.006 * tmp)));
			ans = i + 1;
		}
	}
	cout << ans << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

struct RollingHash {
    typedef long long int_type;
    int_type base1;
    int_type mod1;
    vector<int_type> hash1;
    vector<int_type> pow1;
 
    void init(const string &s) {
        int n = s.size();
 
        hash1.assign(n+1,0);
        pow1.assign(n+1,1);
 
        for(int i=0;i<n;i++) {
            hash1[i+1] = (hash1[i]+s[i]) * base1;
            pow1[i+1] = pow1[i] * base1;
        }
    }
 
    RollingHash() : base1(10007){};
 
    int_type get(int l,int r) {
        int_type t1 = hash1[r] - hash1[l] * pow1[r-l];
        return t1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    string s;
    cin >> n >> m >> s;
    set<RollingHash::int_type> S;
    RollingHash rh;
    rh.init(s);

    int l = 0, r = 1;
    REP(i,m){
        string q;
        cin >> q;
        if(q == "R++") r++;
        if(q == "R--") r--;
        if(q == "L++") l++;
        if(q == "L--") l--;
        S.insert(rh.get(l,r));
    }
    cout << S.size() << endl;
}


Measured memory_bytes: 21984
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a[2][21],s,N,i;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&a[0][i]);
	for(i=0;i<N;i++)
		scanf("%d",&a[1][i]);
	/*for(i=0;i<N;i++)
		printf("%d ",a[0][i]);
		for(i=0;i<N;i++)
			printf("%d ",a[1][i]);*/
	for(i=0,s=0;i<N;i++)
	{
		if(a[0][i]-a[1][i]>0)
			s=s+a[0][i]-a[1][i];
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

/*各位の和　
int sum = 0;
for(int i = 0; i <= 5; i++){
   sum += n%10;
   n /= 10;  
}
*/

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll a,b;
  cin>>a>>b;

  rep(i,1010)
  {
    p=i*0.08;
    q=i*0.1;
    if(a==p&&b==q)
    {print(i)return 0;}
    
  }
  
  cout<<"-1"<<endl;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

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

	if(s == "Sunny") {
		cout << "Cloudy" << endl;
		return 0;
	} else if (s == "Cloudy") {
		cout << "Rainy" << endl;
		return 0;
	} else if (s == "Rainy") {
		cout << "Sunny" << endl;
		return 0;
	}

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int K,A,B,i,j=0;
  cin>>K>>A>>B;
  for(i=A;i<=B;i++)
{
 if(i%K==0)
{
 j++;
}
}
if(j>0)
cout<<"OK";
else
cout<<"NG";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)
	cout<<"No";
	else if(a==c||a==b||b==c)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n, b, f, r, v, i, j, k;
  int x[3][10], y[3][10], z[3][10], w[3][10];

  for(i = 0; i < 3; i++){
    for(j = 0; j < 10; j++){
      x[i][j] = 0;
      y[i][j] = 0;
      z[i][j] = 0;
      w[i][j] = 0;
    }
  }

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d%d%d%d",&b, &f, &r, &v);
    if(b == 1) x[f-1][r-1] += v;
    else if(b == 2) y[f-1][r-1] += v;
    else if(b == 3) z[f-1][r-1] += v;
    else w[f-1][r-1] += v;
  }

  for(k = 0; k < 4; k++){
    for(i = 0; i < 3; i++){
      for(j = 0; j < 10; j++){
        if(k == 0) printf(" %d", x[i][j]);
        else if(k == 1) printf(" %d", y[i][j]);
        else if(k == 2) printf(" %d", z[i][j]);
        else printf(" %d", w[i][j]);
      }
      printf("\n");
    }
    if(k != 3) printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,A=0,B=0;
  cin >> n;
  long long a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]<b[i]){
      A+=(b[i]-a[i])/2;
    }else{
      B+=a[i]-b[i];
    }
  }
  if(A>=B){
    cout << "Yes" << endl;
  }else{    
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N + 1);
    ll c = 0;
    ll d = 0;
    vi dp(N + 1);
    for (ll i = N; i >= 0; --i)
    {
        // DUMP(i);
        // DUMP(A[i]);
        // DUMP(c);
        // DUMP(d);
        ll vacant = INF;
        if (i <= 40)
        {
            vacant = (1LL << i) - A[i];
        }
        // DUMP(vacant);
        if (vacant < (d + 1) / 2)
        {
            OUT(-1);
            return 0;
        }
        dp[i] = min({vacant + A[i], c + A[i]});
        c = min({vacant + A[i], c + A[i]});
        d = (d + 1) / 2 + A[i];
    }
    // DUMP(dp);
    ll ans = 0;
    ll prev = INF;
    REP(i, N + 1)
    {
        ll cap = prev * 2;
        // ll x = min( - A[i], dp[i]);
        // DUMP(i);
        // DUMP(prev);
        // DUMP(x);
        if (dp[i] > cap)
        {
            ans += cap;
            prev = cap - A[i];
        }
        else
        {
            ans += dp[i];
            prev = dp[i] - A[i];
        }
    }
    OUT(ans);
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
long long modinv(long long a, long long m) {
    long long 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 main(){
  ll N;
  cin>>N;
  ll a[N];
  ll temp1 = 0;
  ll temp2 = 0;
  ll ans;
  for(ll i = 0;i<N;i++){
    cin>>a[i];
  }
  for(ll i = 0;i<N;i++){
    temp1 += a[i];
    temp1 = temp1%MOD;
    temp2+=a[i]*a[i]%MOD;
    temp2 = temp2%MOD;
  }
  temp1 = temp1*temp1%MOD;
  if(temp1<temp2){
    ans = temp1+MOD-temp2;
    ll kkk = modinv(2,MOD);
    cout << ans*kkk%MOD << endl;
  }
  else{
    ans = temp1-temp2;
    ll kkk = modinv(2,MOD);
    cout << ans*kkk%MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 5172
#include<stdio.h>

int main(){

  int i,x,y,z;

  for(i=1; 1; i++){
    scanf("%d %d",&x,&y);
    if(x == 0 && y == 0)break;

    if(x > y){
      z = y;
      y = x;
      x = z;
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}

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

int main(){
  int N,N0;
  int j=0;
  ll int ans=0;
  ll int tmp;
  int tmp2;
  string s="";
  
  
  cin>>N;
  N0=N;
  while(abs(N)>0){
    tmp=0;
    tmp2=0;
    tmp = abs(N)%2;
    N=(N-tmp)/(-2);
    s = to_string(tmp)+s;
    j++;
  }
  if(N0==0)s="0";
  cout<<s<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut f = vec![vec![true; w + 2]; h + 2];

    for y in 1..h + 1 {
        let a = read::<String>().chars().map(|c| c == '#').collect::<Vec<bool>>();
        f[y][1..w + 1].copy_from_slice(&a[..]);
    }

    let mut c1 = vec![vec![0; w + 2]; h + 2];
    let mut c2 = c1.clone();
    let mut c3 = c1.clone();
    let mut c4 = c1.clone();

    for y in 0..h + 2 {
        for x in 0..w + 2 {
            c1[y][x] = if f[y][x] { 0 } else { c1[y][x - 1] + 1 };
        }
        for x in (0..w + 2).rev() {
            c2[y][x] = if f[y][x] { 0 } else { c2[y][x + 1] + 1 };
        }
    }
    for x in 0..w + 2 {
        for y in 0..h + 2 {
            c3[y][x] = if f[y][x] { 0 } else { c3[y - 1][x] + 1 };
        }
        for y in (0..h + 2).rev() {
            c4[y][x] = if f[y][x] { 0 } else { c4[y + 1][x] + 1 };
        }
    }

    let ans = (0..h + 2).map(|y|
        (0..w + 2).map(|x| c1[y][x] + c2[y][x] + c3[y][x] + c4[y][x] - 3).max().unwrap()
    ).max().unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 73980
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const int mod = 1e9 + 7;
ll fac[100001];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  if(abs(n - m) > 1){
    cout << 0 << endl;
    return 0;
  }
  fac[0] = 1;
  for(int i = 1; i < 100001; i++){
    fac[i] = (fac[i - 1] * i) % mod;
  }
  ll res = fac[n] * fac[m] % mod;
  if(n == m)res = res * 2 % mod;
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#ifndef POINT_RADIAN_H
#define POINT_RADIAN_H

#include <iostream>
#include <cmath>

using namespace std;

static const double PI = 3.141592;


class Point{
public:
    double x, y;
    Point(double x=0, double y=0): x(x),y(y){}

    Point operator + (Point p) {return Point(x+p.x, y+p.y);}
    Point operator - (Point p) {return Point(x-p.x, y-p.y);}
    Point operator * (double a) {return Point(a*x, a*y);}
    Point operator / (double a) {return Point(x/a, y/a);}

};

int main(){
    int d, a;
    int degree(0);
    Point p;
    double radian = 0;
    
    while (scanf("%d,%d",&d, &a)){
        if(d == 0 && a == 0){break;}
        radian = degree * (PI/180);
        p.x = p.x + d * sin(radian);
        p.y = p.y + d * cos(radian);
        degree += a;

    }
    cout << static_cast<int>(p.x) << "\n";
    cout << static_cast<int>(p.y) << "\n";


}


#endif // POINT_RADIAN_H

Measured memory_bytes: 3420
n,w = map( int, input().split() )
wv = []
for _ in range(n): wv.append( list( map( int, input().split() ) ) )

dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j-wv[i][0] < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max( dp[i-1][j-wv[i][0]]+wv[i][1], dp[i-1][j] )

print(dp[n-1][w])

Measured memory_bytes: 120172
fn main() {
    let mut buf: String = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse::<usize>().unwrap();
    let mut v1: Vec<usize> = vec![0; 100001];
    let mut v2: Vec<usize> = vec![0; 100001];
    let mut buf: String = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut itr = buf.split_whitespace();
    while let Some(i) = itr.next() {
        v1[i.parse::<usize>().unwrap()] += 1;
        if let Some(i) = itr.next() {
            v2[i.parse::<usize>().unwrap()] += 1;
        }
    }
    let (mut m11,mut m12,mut m21,mut m22,mut m31,mut m32): (usize,usize,usize,usize,usize,usize) = (0,0,0,0,0,0);
    for x in 0..100001 {
        if v1[x] > m12 {
            if v1[x] > m11 {
                m12 = m11;
                m11 = v1[x];
                m31 = x;
            } else {
                m12 = v1[x];
            }
        }
        if v2[x] > m22 {
            if v2[x] > m21 {
                m22 = m21;
                m21 = v2[x];
                m32 = x;
            } else {
                m22 = v2[x];
            }
        }
    }
    println!("{}", if m31 != m32 {n-m11-m21} else {std::cmp::min(n-m11-m22,n-m12-m21)});
}


Measured memory_bytes: 8444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();
		
		int sum = 0;
		
		for(int i = 0; i <= N / R; i++) {
			for(int j = 0; j <= N / G; j++) {
				int b = N - i * R - j * G;
				if(b >= 0 && b % B == 0) {
					sum++;
				}
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   int n,m,l;
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String line = br.readLine(); 
   String[] token = line.split(" ");
   n = Integer.parseInt(token[0]);
   m = Integer.parseInt(token[1]);
   l = Integer.parseInt(token[2]); 
   long[][] matrixA = new long[n][m];
   long[][] matrixB = new long[m][l];
   long[][] matrixanswer = new long[n][l]; 
 
   for(int i = 0; i < n ;i++){
     String line2 = br.readLine(); 
     String[] token2 = line2.split(" ");
     for(int j = 0; j < m ;j++){
        matrixA[i][j] = Integer.parseInt(token2[j]);
         
     }//for  
   }//for
 
   for(int k = 0; k < m ;k++){
     String line2 = br.readLine(); 
     String[] token2 = line2.split(" ");
     for(int x = 0; x < l ;x++){
        matrixB[k][x] = Integer.parseInt(token2[x]);
         
     }//for  
   }//for
 
   for(int o = 0; o < n ;o++){
      for(int p = 0; p < l ;p++){
        matrixanswer[o][p] = 0;
         
     }//for 
   }   
   
   for(int a = 0; a < n ; a++ ){
    for(int b = 0; b < l ;b++){
      for(int c = 0; c < m;c++){ 
         matrixanswer[a][b] =matrixanswer[a][b]+  matrixA[a][c]*matrixB[c][b]; 
      } 
    }
   }    

    for(int s = 0; s < n ;s++){
      for(int t = 0; t < l ;t++){
       if(t!=0){ System.out.print(" ");}

        System.out.print(matrixanswer[s][t]);
       
      }
       System.out.println(); 
    }
 
  }
}

Measured memory_bytes: 32504
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    TSTART();
    int ans = 0;
    REP(i,n){
      ans += i + 1;
    }
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

ll ans = 0;

void use(ll& K) {
	if(K <= 2) return;
	ll u = (K-1)/2;
	K -= u*2;
	ans += u*4;
}

void go(ll K) {
	if(K == 2)
		ans += 4;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll R,O,Y,G,B,I,V;
	cin >>R>>O>>Y>>G>>B>>I>>V;
	ans = 2*O;
	use(R);
	use(G);
	use(B);
	if(R>G) swap(R,G);
	if(G>B) swap(G,B);
	if(R>G) swap(R,G);
	if(R==1 && G==1 && (B==2 || B==1)) {
		--R;--G;--B;
		ans += 6;
	}
	// cout << R << " " << G << " " << B << " " << ans << endl;
	go(R);
	go(G);
	go(B);
	cout << ans/2 << "\n";
	return 0;
}

Measured memory_bytes: 256
#!python3

# input
N = int(input())
A = list(map(int, input().split()))


def main():
    mx = max(A)
    mn = min(A)
    idx = A.index(mn) if abs(mx) < abs(mn) else A.index(mx)
    idx += 1
    ans = []
    for i in range(N):
        ans.append((idx, i + 1))
    
    if A[idx - 1] > 0:
        for i in range(1, N):
            ans.append((i, i + 1))
    else:
        for i in range(N - 1, 0, -1):
            ans.append((i + 1, i))
    
    n = len(ans)
    print(n)
    for i in range(n):
        print(*ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int tate,yoko;
  cin >> tate >> yoko;
  int goal;
  cin >> goal;
  if(goal % max(tate,yoko) != 0){
  cout << goal / max(tate,yoko) + 1 << endl;
  }
  else{
    cout << goal / max(tate,yoko) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    long ans = 0;
    int[] X = new int[100007];
    for(int i=0;i<n;i++){
      int a = nextInt();
      X[a] ++;
      ans += a;
    }



    int q = nextInt();
    for(int i=0;i<q;i++){
      int b = nextInt();
      int c = nextInt();

      int d = c-b;

      ans += d*X[b];
      X[c] += X[b];
      X[b] = 0;

      System.out.println(ans);
    }

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

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

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 63708
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=5005,mod=1e9+7;
int f[N][2],g[N][2],n,A,B,ans;

signed main(){
	read(n,A,B);
	if(A>B) swap(A,B);
	f[0][0]=f[0][1]=1;
	for(int i=1;i<B;i++){
		for(int j=A;j<=i;j++) f[i][0]=(f[i][0]+f[i-j][1])%mod;
		for(int j=1;j<=i;j++) f[i][1]=(f[i][1]+f[i-j][0])%mod;
	}
	for(int i=1;i<n;i++){
		if(i<A) g[i][0]=1;
		for(int j=1;j<A&&j<i;j++) g[i][0]=(g[i][0]+g[i-j][1])%mod;
		if(i<B) g[i][1]=f[i][1];
		for(int j=1;j<B&&j<i;j++) g[i][1]=(g[i][1]+1ll*g[i-j][0]*f[j-1][1]%mod)%mod;
		if(n-i<A) ans=(ans+g[i][1])%mod;
		if(n-i<B) ans=(ans+1ll*g[i][0]*f[n-i][1]%mod)%mod;
	}
	int pw2=1;
	for(int i=1;i<=n;i++) pw2=(pw2+pw2)%mod;
	write((pw2+mod-ans)%mod);
}

Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int n,N;
int main(void){
    cin>>n;
    if(n==3){
        cout<<"2 5 63"<<endl;
        return 0;
    }
    if(n==4){
        cout<<"2 5 20 63"<<endl;
        return 0;
    }
    cout<<"2 3 4 9 ";
    N=n-4;
    if(N%2==1){
        cout<<6<<" ";
    }
    for(int i=1;i<=min(4999,(N-N%2)/2);i++){
        cout<<6*i+2<<" "<<6*i+4<<" ";
    }
    n-=9998+5;
    if(n>=0&&N%2==0)cout<<6<<" "<<endl;
    if(n<=0){cout<<endl;return 0;}
    if(n==9997){n--;cout<<12<<" ";}
    for(int i=0;i<(n-1)/4;i++){
        cout<<12*i+27<<" "<<12*i+30<<" "<<12*i+33<<" "<<12*i+36<<" ";
    }
    //cout<<n<<endl;
    N=n%4;
    if(N==0)N=4;
    if(N==1){
        cout<<18<<endl;
        return 0;
    }
    if(N==2){
        cout<<18<<" "<<24<<endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        cout<<3*i+15<<" ";
    }
    cout<<endl;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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


int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;

	if(a==12&&c==1){
		cout<<1<<endl;
		return 0;
	}else if(c-a==1){
		cout<<1<<endl;
		return 0;
	}else{
		cout<<0<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 200005;

int n, q;
struct Node {
    int c[N];
    int sum(int x) {
        int res = n;
        while (x) {
            res = min(res, c[x]);
            x -= x & -x;
        }
        return res;
    }
    void add(int x, int d) {
        while (x <= n) {
            c[x] = min(c[x], d);
            x += x & -x;
        }
    }
} T1, T2;
int main() {
    cin >> n >> q;
    LL ans = (n - 2LL) * (n - 2);
    for (int i = 1; i <= n; i++) T1.c[i] = T2.c[i] = n;
    while (q--) {
        int op, x;
        cin >> op >> x;
        if (op == 1) {
            int z = T1.sum(n - x + 1);
            T2.add(n - z + 1, x);
            ans -= z - 2;
        } else {
            int z = T2.sum(n - x + 1);
            T1.add(n - z + 1, x);
            ans -= z - 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5160
#include<bits/stdc++.h>
using namespace std;
#define faster cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define mod (int)(1e9+7)

//  0-1 knapsack


// solve(n,k) 

// solve(n-1,k-1);
// solve(n-1,k-2);
// solve(n-1,k-3);
// .
// .
// solve(n-1,k-arr[n])


// // rem all are invalid states
// solve(n-1,k-arr[n]-1)
// .
// .
// .

int main()
{
	int n,k;
	cin>>n>>k;
	
	int arr[n];  
	for(int i=0;i<n;i++) cin>>arr[i];
	
	int dp[n+1][k+1];
	for(int i=0;i<=n;i++) dp[i][0] = 1;
	for(int i=1;i<=k;i++) dp[0][i] = 0;
 
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			dp[i][j] = dp[i][j-1];
			dp[i][j] += dp[i-1][j];
			
			
			if(dp[i][j]>=mod)
				dp[i][j] %= mod;
			
			if(j-arr[i-1]-1>=0)
			dp[i][j]=(dp[i][j]-dp[i-1][j-arr[i-1]-1]+mod)%mod;
		}
	}
	cout<<dp[n][k];
	
	
}
	


Measured memory_bytes: 39680
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int main(){
	int n, foot[2], now, ans;
	string s;
	while(1){
		cin >> n;
		if(!n) break;
		foot[0] = 0;
		foot[1] = 0;
		now = 0;
		ans=0;
		for(int i = 0;i<n ;i++){
			cin >> s;
			if(s[0]=='l'&&s[1]=='u')foot[0]=1;
			else if(s[0]=='l'&&s[1]=='d')foot[0]=0;
			else if(s[0]=='r'&&s[1]=='u')foot[1]=1;
			else if(s[0]=='r'&&s[1]=='d')foot[1]=0;
			
			if(foot[0]==foot[1]&&now+foot[0]==1){
				ans++;
				now=1-now;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    int n;cin >>n;
    string S;
    cin >> S;
    string sub1 = S.substr(0,n),sub2 = S.substr(n,2*n);
    reverse(sub2.begin(),sub2.end());
    map<pair<string,string>,ll> map;
    for(int i = 0; i < (1 << n ); i++){
        string red,blue;
        for(int j = 0; j < n ; j++){
            if(i&(1<<j))red += sub1[j];
            else blue += sub1[j]; 
        }
        map[{red,blue}]++;
    }
    ll ans = 0;
    for(int i = 0; i < (1 << n ); i++){
        string red,blue;
        for(int j = 0; j < n ; j++){
            if(i&(1<<j))red += sub2[j];
            else blue += sub2[j]; 
        }
        ans += map[{red,blue}];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    long long int a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    if(t*(v-w) >= abs(a-b)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int A, int B) {
  if (A <= 8 && B <= 8) {
    printf("Yay!\n");
  } else {
    printf(":(\n");
  }
}

int main() {
  int A, B;
  cin >> A >> B;
  solve(A, B);
  return 0;
}

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

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

Measured memory_bytes: 3848
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder_ABC140
{
    class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            WriteLine($"{a*a*a}");
        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <array>
#include <utility>

template <unsigned int N> struct shuumai{
    unsigned int minPrime[N + 1];
    unsigned int Primes[N + 1];
    unsigned int size_;

    constexpr shuumai(void): minPrime(), Primes(), size_(0U){
        minPrime[0] = 1; minPrime[1] = 1;
        for(int even = 2, odd = 3; odd <= N; even += 2, odd += 2){
            minPrime[even] = 2;
            minPrime[odd] = odd;
        }
        if(!(N & 1)) minPrime[N] = 2;
        Primes[size_++] = 2;

        for(int x = 3; x <= N; x += 2){
            if(minPrime[x] == x) Primes[size_++] = x;
            for(int y = 0; y < size_ and Primes[y] <= minPrime[x] and x * Primes[y] <= N; ++y)
                    minPrime[x * Primes[y]] = Primes[y];
        }
    }
    // 範囲for文用の begin() と end()
    const unsigned int *begin(void) const noexcept{ return Primes; }
    const unsigned int *end(void) const noexcept{ return Primes + size_;}
    const unsigned int size(void) const {return this.size_;}
};

using uint = unsigned int;
constexpr uint N = 1e6;
constexpr uint mod = 1e9 + 7;
constexpr uint M = mod - 2;
constexpr shuumai<N> P;
std::array<uint, N + 1> Count;

// a^nを返す関数
const uint power(uint a, uint n)noexcept{
    unsigned long long res = 1, waiting = a;
    while(n){ 
        if(n & 1) { res *= waiting; res %= mod; }
        waiting *= waiting; waiting %= mod; 
        n >>= 1;
    }
    return res;
}

uint fastRead(void) {
	char c;
	while(true){
        c = getchar();
        if('0' <= c and c <= '9') break;
	}
    uint res = c - '0';
	while(true){
		c = getchar();
        if(c < '0' or c > '9') break;
		res = 10 * res + (c - '0');
	}
    return res;
}


int main(void){
    uint n = fastRead();
    uint inv_sum = 0;
    for(uint _ = 0; _ < n; ++_){
        uint a = fastRead();
        inv_sum += power(a, M); if(inv_sum >= mod) inv_sum -= mod;
        while(a - 1U){
            uint fac = P.minPrime[a];
            uint cnt = 1; a /= fac;
            while(a % fac == 0) a /= fac, cnt++;
            if(Count[fac] < cnt) Count[fac] = cnt; 
        }
    }

    unsigned long long int lcm = 1;
    for(unsigned int x : P) if(Count[x]) (lcm *= power(x, Count[x])) %= mod;
    unsigned int res = lcm * inv_sum % mod;
    
    printf("%u\n", res);
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    ll n;
    cin >> n;
    ll a, res = 0;
    map<ll, ll> mp;
    REP(i, n) {
        cin >> a;
        res += mp[i - a];
        mp[i + a]++;
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  
  bool b=true;
  for(int i=0;i<s.size();i++){
    int count=0;
    for(int j=0;j<s.size();j++){
      if(s.at(i)==s.at(j)){
        count++;
      }
    }
    if(count!=2)
      b=false;
  }
  
  if(b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

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

	vector<uint64_t> dp(n + 1, -1);
	dp.at(0) = 1;

	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;

		dp.at(a) = 0;
	}

	for (int i = 1; i <= n; i++)
	{
		if (dp.at(i) == -1)
		{
			uint64_t s = 0;
			s = dp.at(i - 1);
			if (i - 2 >= 0)
			{
				s = (s + dp.at(i - 2)) % MOD;
			}
			dp.at(i) = s % MOD;
		}
	}

	cout << dp.back() << endl;
}

Measured memory_bytes: 1024