akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
string A,B;
int main(){
    cin>>A>>B;
    if(A.size()>B.size()) cout<<"GREATER"<<"\n";
    else if(A.size()<B.size()) cout<<"LESS"<<"\n";
    else{
        if(A>B)cout<<"GREATER"<<"\n";
        else if(A==B) cout<<"EQUAL"<<"\n";
        else cout<<"LESS"<<"\n";
    }
    return 0;
}

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

#define V vector<int>
#define VV(v, n, m) vector<V> v(n, V(m));
#define _4(i, n) for(int i = 0; i < n; i++)
#define g_arr(arr, n) _4(i, n) cin >> arr[i];
#define p_vec(vec) _4(i, (int)vec.size()) cout << vec[i] << ' '; cout << endl;

typedef long long ll;

using namespace std;

string lcs(string s, string t);

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    string s, t;
    cin >> s >> t;

    cout << lcs(s, t);

    return 0;
}

string lcs(string s, string t) {
    int s1 = s.length(), s2 = t.length();

    VV(dp, s1 + 1, s2 + 1);

    for(int i = 0; i <= s1; i++) {
        for(int j = 0; j <= s2; j++) {

            if(!i || !j)
                dp[i][j] = 0;
            else if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    int i = s1, j = s2;

    string out = "";

    while(i > 0 && j > 0) {
        if(s[i - 1] == t[j - 1]) {
            out = s[i - 1] + out;
            i--;
            j--;
        } else if(dp[i - 1][j] < dp[i][j - 1])
            j--;
        else
            i--;
    }

    return out;
}


Measured memory_bytes: 35584
main(){float a,b,c,d,e,f,x;for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(c-b*x)/a+0.0,x/=a*e-b*d+0.0))x=a*f-d*c;exit(0);}

Measured memory_bytes: 648
/*
* @author:  codancer
* @createTime:  2020-02-22, 19:58:19
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	int n,r;
	cin>>n>>r;
	if(n>=10){
		cout<<r<<endl;
	}else{
		cout<<r+100*(10-n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>

#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1000000007
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<long,long>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).begin(),(a).end(),greater<int>())
#define MP(a,b) make_pair(a,b)
#define FORE(a,b) for(auto &&a:b)

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int main(void){
	int a,b; cin>>a>>b;
	cout<<a*b<<" "<<(a*2)+(b*2)<<endl;
}

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

/*
   AtCoder contest
   coder : yoichidon
 */

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        int change = 0;
        for(int n=0; n<N; n++){
            char a = A.charAt(n);
            char b = B.charAt(n);
            char c = C.charAt(n);

            if(a==b && b==c) change += 0;
            else if(a==b || b==c || c==a) change += 1;
            else change += 2;
        }
        System.out.println(change);
    }
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	if((a + b) % 2 == 0) {
		cout << (a + b) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
}

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

int main() {
  int S,K;
  cin >> K >> S;
  
  int count=0;
  for(int i=K;i>=0;i--){
    int last = S- i;
    if(last<0){ 
      continue;
    }
    if(last==0){
      count++;
      continue;
    }
    for(int j=K;j>=0;j--){
      int last2 =last - j;
      if(last2>=0 && last2 <=K){
        count++;
        continue;
      }else{
        continue;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;    
        } 
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;    
        } 
    }
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000


int main(void) {
	char s; cin >> s;

	if (s - 'a' < 0) {
		cout << 'A' << endl;
	}
	else {
		cout << 'a' << endl;
	}
	return 0;
}

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

int main(){
    int h, w;
    
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i % 2 == 1 && j % 2 == 1) cout << '#';
                if(i % 2 == 1 && j % 2 == 0) cout << '.';
                if(i % 2 == 0 && j % 2 == 0) cout << '#';
                if(i % 2 == 0 && j % 2 == 1) cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
import numpy as np

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

exist = np.zeros(sum(A)+1, dtype=bool)
exist[sum(A)] = True
for a in A:
    exist[:-a] |= exist[a:]

for i in range((sum(A)+1) // 2, sum(A) + 1):
    if exist[i]:
        print(i)
        exit()


Measured memory_bytes: 16564
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  cin >> n;
  lvec t(n);
  REP(i, n) { cin >> t[i]; }
  ll ans = 1;
  REP(i, n) { ans = lcm(ans, t[i]); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
typedef struct sub{
	ll score,b,l,u;
	bool operator<(const sub&key)const{
		return this->score>key.score;
	}
}sub;
vector<sub> v;
#define N 200010
ll rui[N];
ll rangesum(ll r,ll i){
	ll res=rui[r+1];
	if(r>=i){
		res-=v[i].score;
	}
	return res;
}
ll n,X;
ll func(ll i,ll rem){
	if(rem>v[i].b*v[i].l+(X-v[i].b)*v[i].u)return 1e17;
	ll cost=0;
	if(rem>=v[i].b*v[i].l){
		rem-=v[i].b*v[i].l;
		cost+=v[i].b;
		cost+=(rem+v[i].u-1)/v[i].u;
	}
	else{
		cost+=(rem+v[i].l-1)/v[i].l;
	}
	return cost;
}
int main(){
	cin>>n>>X;
	ll aoki=0;
	rep(i,n){
		ll b,l,u; cin>>b>>l>>u;
		ll score=b*l+(X-b)*u;
		v.push_back((sub){score,b,l,u});
		aoki+=b*l;
	}
	sort(all(v));
	rui[0]=0;
	for(int i=0;i<n;i++)rui[i+1]=rui[i]+v[i].score;
	ll ans=1e17;
	for(int i=0;i<n;i++){
		ll l=-1,r=n,mid;
		while(l<r-1){
			mid=(l+r)>>1;
			(rangesum(mid,i)<=aoki?l:r)=mid;
		}
		ll rem=aoki-rangesum(l,i);
		chmin(ans,func(i,rem)+(l+1-(i<=l))*X);
		chmin(ans,func(i,aoki));
	}
	cout<<ans<<endl;
}





Measured memory_bytes: 6512
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto p = RDA;
	long cnt;
	foreach (i; 0..N)
	{
		if (p[i] != i+1)
			++cnt;
	}

	writeln(cnt <= 2 ? "YES" : "NO");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

int main()
{

	int a = 0, b = 0, c = 0, d = 0, e = 0, maxy = 0, max = -1, ans = 1, count = 0, min = 0;

	int yoko = 0, tate = 0;
	std::string output, output2, output3, input = {};
	bool okada = false;
	int array[1000];


	cin >> a ;
	for (int i = 0; i < a; i++) {
		cin >> array[i];
	}
	for (int i = 0; i < a; i++) {
		if (array[i] == 1) {
			count++;
		}
		if (array[i] == 0||i==a-1) {
			max = std::max(count, max);
			count = 0;
		}
	
	}
	cout << max + 1 << endl;
	
}








Measured memory_bytes: 3112
import sys
line1, line2 = [sys.stdin.readline() for i in range(2)]
components = [int(i) for i in line2.strip().split()]
count = 0
while all([i % 2 == 0 for i in components]):
    count += 1
    components = [i//2 for i in components]
else:
    print(count)

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

lint w[105], v[105];
vector<lint> mono[4], ss[4];

int main(){
    lint N, W; cin >> N >> W;
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
        mono[w[i]-w[0]].push_back(v[i]);
    }

    for(int i=0;i<4;i++){
        sort(mono[i].begin(), mono[i].end()); reverse(mono[i].begin(), mono[i].end());
        ss[i].push_back(0);
        for(int j=1;j<=mono[i].size();j++) ss[i].push_back(ss[i][j-1]+mono[i][j-1]);
    }

    lint ans = 0;
    for(lint i=0;i<=mono[0].size();i++){
        for(lint j=0;j<=mono[1].size();j++){
            for(lint k=0;k<=mono[2].size();k++){
                for(lint l=0;l<=mono[3].size();l++){
                    if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3)<=W){
                        ans = max(ans, ss[0][i]+ss[1][j]+ss[2][k]+ss[3][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

N=int(input())
D=collections.Counter(list(map(int,input().split())))
M=int(input())
T=list(map(int,input().split()))

for i in range(M):
  temp=T[i]
  D[temp]-=1
  if D[temp]==-1:
    print('NO')
    break
else:
  print('YES')

Measured memory_bytes: 50740
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

/*
	計算ミス

	ボブは小学校の児童で、算数があまり得意でない。彼は父親の電卓を見つけ、
	それを使って宿題でズルをしようとした。彼の宿題は掛け算と足し算を含む
	数式を計算することである。もちろん、掛け算は足し算の前に行わなければならないが、
	計算機は式を左から右に計算し、演算子の優先順位を無視する。
	そのため彼の答えは次の二つの計算規則のいずれかの結果となりうる。

		足し算の前に掛け算を行う
		演算子の優先順位を無視して左から右に計算を行う

	彼の答えと数式から、どちらの規則が適用されたを出力するプログラムを書け。

	数式は整数と演算子からなる。全ての整数は一桁、すなわち0から9である。
	演算子は+と*の二種類であり、それぞれ足し算と掛け算を示す。
	以下は数式の例である。
		
		1+2*3+4
	
	この数式を、掛け算を最初に計算する規則によって計算すると、入力例１のように、答えは11になる。
	しかし、左から右に計算する規則によると、答えは入力例２で示されるように、答えは13になるだろう。

	どちらの規則で計算しても同じ結果になる場合もありえ、その場合には
	どちらの規則が適用されたか判別できない。加えて、ボブはたまに計算ミスをする。
	いずれの規則でもボブの答えにならない場合、彼が本当に宿題をしたのは明らかである。

	入力
	入力は二行のテストケースからなる。最初の一行には計算する数式が含まれる。
	数式の文字数は常に奇数であり、17以下である。数式中の奇数番目の文字は0から9までの数字である。
	偶数番目の文字は+か*の演算子である。二行目には0から999999999までの整数が含まれる。
	この整数は最初の行で与えられた数式に対するボブの答えである。

	出力
	以下の４つの文字のうち１つを出力せよ。
	M　掛け算を先に行う規則のみの計算結果がボブの答えになる場合
	L　左から右に行う規則のみの計算結果がボブの答えになる場合
	U　両方の規則の計算結果がボブの答えになる場合
	I　いずれの規則の計算結果もボブの答えにならない場合

*/


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	
	vector< int > num;
	string str;
	int ans;
	getline(cin, str);
	cin >> ans;
	int r[2] = {0, 0};

	// multiplication-first rule
	int tmp = -1;
	for(int i = 0; str.length() > 1 && i < str.length() - 2; i += 2) {
		if( str[i + 1] == '+' ) {
			if( tmp == -1 ) tmp = str[i] - '0';
			else tmp *= ( str[i] - '0' );
			num.push_back( tmp );
			tmp = -1;
		} else {
			if( tmp == -1 ) tmp = str[i] - '0';
			else tmp *= ( str[i] - '0' );
		}
	}

	if( tmp == -1 ) {
		num.push_back( str[ str.length() - 1 ] - '0' );
	} else {
		num.push_back( ( str[ str.length() - 1 ] - '0' ) * tmp );
	}

	//left-to-right rule
	r[1] = str[0] - '0';
	for(int i = 2; i < str.length(); i += 2) {
		if( str[i-1] == '+' ) {
			r[1] += str[i] - '0';
		} else {
			r[1] *= str[i] - '0';
		}
	}

	for(int i = 0; i < num.size(); i++)
		r[0] += num[i];

	if( ans == r[0] && ans == r[1] ) {
		cout << "U" << endl;
	} else if( ans == r[0] && ans != r[1] ) {
		cout << "M" << endl;
	} else if( ans != r[0] && ans == r[1] ) {
		cout << "L" << endl;
	} else if( ans != r[0] && ans != r[1] ) {
		cout << "I" << endl;
	}

	//while(1){}
    return 0;
}

Measured memory_bytes: 1224
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a>=3200)
	cout<<s;
	else 
	cout<<"red";
}
void q2(){
	int n;cin>>n;
	long double tp=0;
	for(int i=0;i<n;++i){
		long double xp;
		cin>>xp;
		xp=1/xp;
		tp+=xp;
	}
	tp=1/tp;
	cout<<fixed<<setprecision(10)<<tp;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	q2();
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll X;
    cin >> X;

    REP(i,1,300000) {
        if(i*(i+1)/2 >= X) {
            PR(i);
            break;
        }
    }

    return 0;
}

/*



*/

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

using namespace std;

template<int MOD>
struct Modular {
  int value;
  Modular(const Modular& k) : value(k.value) {}
 
  template<typename V>
  Modular(const V& v) : value(v % MOD) {
    if (value < 0) {
      value += MOD;
    }
  }
  
  Modular() : Modular(0) {}
 
  Modular& operator+=(Modular const& b) { value += b.value; if (value >= MOD) value -= MOD; return *this; } 
  Modular& operator-=(Modular const& b) { value -= b.value; if (value < 0) value += MOD; return *this; }
  Modular& operator*=(Modular const& b) { value = (long long)value * b.value % MOD; return *this; }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { return *this += 1; }
  Modular operator--(int) { return *this -= 1; }

  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) { return os << a.value; }
  friend bool operator==(Modular const& a, Modular const& b) { return a.value == b.value; }
  friend bool operator!=(Modular const& a, Modular const& b) { return a.value != b.value; }
};
 
template <int T, typename V>
Modular<T> mexp(Modular<T> a, V e) {
  if (a == 0) return e == 0 ? 1 : 0; 
  Modular<T> res = 1; 
  while (e) { 
    if (e & 1) 
      res *= a; 
    a *= a; 
    e >>= 1; 
  }
  return res;
}

const int N = 3010;

using Mint = Modular<998244353>;

Mint dp[N][N];

void Run() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b] = 1;
  for (int i = a; i <= c; ++i) {
    for (int j = b; j <= d; ++j) {
      dp[i][j] += j * dp[i - 1][j];
      dp[i][j] += i * dp[i][j - 1];
      dp[i][j] -= (i - 1) * (j - 1) * dp[i - 1][j - 1];
    }
  }
  cout << dp[c][d] << '\n';
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}

Measured memory_bytes: 39008
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        if (line.length()==2) System.out.println(line);
        else {
            System.out.print(line.charAt(2));
            System.out.print(line.charAt(1));
            System.out.print(line.charAt(0)+"\n");
        }
        //System.out.println("XXXXXXXX");
    }
}


Measured memory_bytes: 23124
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			for (int bit = 1; bit < (1<<n); bit++) {
				if(isTrueNum(bit, k)) {
					System.out.print(bit + ":");
					for (int j = 0; j < n; j++) {
						if (((bit>>j) & 1) == 1) {
							System.out.print(" " + j);
						}
					}
					System.out.println();
				}
			}
		}
	}
	public static boolean isTrueNum(int flags, int num) {
		int cnt = 0;
		for(int j = 0; j < 32; j++) {
			if((flags>>j&1)>0)
				cnt++;
		}
		return num == cnt;
	}
}


Measured memory_bytes: 69832
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    map<string, int> mp{};
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        mp[S]++;
    }

    int mx_cnt = 0;
    for (auto k : mp) {
        mx_cnt = max(mx_cnt, k.second);
    }
    for (auto k : mp) {
        if (k.second == mx_cnt) {
            cout << k.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 26624
#include <iostream>

using namespace std;

int main() {
  int S;
  int h;
  int m;
  int s;

  cin >> S;

  h = S / 3600;
  m = (S - h * 3600) / 60;
  s = S % 60;

  cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S(N,'0');
  string T(N,'0');

  string newST = "";
  
  for(int i=0;i<N;i++){
    
    cin>>S.at(i);
    
  }
  
  for(int i=0;i<N;i++){
    
    cin>>T.at(i);
    
  }
  
  for(int i=0;i<N;i++){
    
    newST = newST + S.at(i)+T.at(i);
    
  }
  
  cout<<newST<<endl;
  
  return 0;
  
}

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

int main() {
  int age, cost;  
  cin >> age >> cost;

  if(age >= 13){
    cout << cost << endl;
  }else if (12 >= age && age >= 6){
    cout << cost * 0.5 << endl;
  }else{
    cout << 0 << endl;
  }
}



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

int main()
{
    char str[100];
    int i,len,num=0;
    scanf("%s",str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(len<3)
            break;
        else if(i>0&&i<len-1)
        {
            num++;
        }
    }
    if(len>2)
        printf("%c%d%c\n",str[0],num,str[len-1]);
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

int main(){
    ll A,B,Q;cin>>A>>B>>Q;
    vector<ll> S(A+1),T(B+1);
    for(int i=1;i<=A;++i) cin>>S[i];
    for(int i=1;i<=B;++i) cin>>T[i];
    S.push_back(INF);T.push_back(INF);
    S[0]=T[0]=-INF;
    while(Q--){
        ll X;cin>>X;
        ll ans=INF;
        auto is=lower_bound(S.begin(),S.end(),X);
        auto it=lower_bound(T.begin(),T.end(),X);
        ans=min(ans,max(*is,*it)-X);
        ans=min(ans,abs(*is-*(it-1))+min(*is-X,X-*(it-1)));
        ans=min(ans,abs(*(is-1)-*it)+min(X-*(is-1),*it-X));
        ans=min(ans,X-min(*(is-1),*(it-1)));
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 5608
//in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define forn(i,n) for(int i =0; i < (int)(n); i++)
#define rfr(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int rec(int ind,int n)
{
  if(n==1)
  return ind;
  if(n%2==0)
  return rec(ind+1,n/2);
  else
  return rec(ind+1,3*n+1);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
  int n;
  cin>>n;
  if(n<=2)
  cout<<4<<"\n";
  else
  cout<<rec(0,n)+2<<"\n";
  return 0;
}


Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, p;
    std::cin >> n >> p;

    bool has_odd = 0;
    for (usize i=0; i<n; i++) {
        usize x;
        std::cin >> x;
        has_odd |= x&1;
    }
    u64 all = 1ull << n;
    std::cout << (has_odd ? all/2 : p&1 ? 0 : all) << '\n';
}


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

int main()
{
	int x,y;
	while( true ) {
		cin>>x>>y;
		if( 0==x && 0==y ) { break; }
		
		if( x < y ) {
			cout <<x<<" "<<y<<endl;		
		} else {
			cout <<y<<" "<<x<<endl;
		}
	}
	 
    return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

void Main() {
  int n = read<int>();
  int m = read<int>();

  vector<int> X(n);
  rep(i, n) X[i] = read<int>();

  vvi Y(m);
  vi C(m);
  forr(x, X) {
    Y[x % m].push_back(x);
    C[x % m]++;
  }

  int ans = 0;

  rep(i, m / 2 + 1) {
    int s = i;
    int t = m - s;
    if (s == 0 || s == t) {
      ans += C[s] / 2;
      continue;
    }
    if (C[t] > C[s]) swap(s, t);

    // |t| <= |s|

    ans += C[t];

    int use_in_s = C[s] - C[t];
    use_in_s -= use_in_s % 2;
    {
      map<int, int> co;
      forr(y, Y[s]) co[y]++;
      forr(yc, co) {
        int c = yc.snd;
        if (c >= 2) {
          int u = min(c / 2 * 2, use_in_s);
          ans += u / 2;
          use_in_s -= u;
        }
      }
    }
  }

  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

using namespace std;

int main() {
	long long n;
	long long p = 100;
	long long t = 1;
	cin >> n;

	while (t) {
		p = p * 1.01;
		if (p - n >= 0) {
			cout << t << endl;
			break;
		}
		t++;
	}
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main(){
int n,m;cin>>n>>m;
if(n<=m) for(int i=1;i<=m;i++) cout<<n;
else for(int i=1;i<=n;i++) cout<<m;
return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		//String[][] array = new String[100][500];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		String s = sc.next();
		List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list_moji=new ArrayList<String>();

		loop:for(int i=0;list.size()>i;i++) {
			//System.out.println(i);
			if(i==0) {
				list_moji.add(list.get(i));
				//list.remove(i);
				continue;
			}

			else if(i!=0) {
				String add="";

				while(true) {
					if(i==list.size())
						break loop;
					add=add+list.get(i);
					//System.out.println(add);
					if(add.equals(list_moji.get(list_moji.size() - 1))) {
						i++;
						continue;
					}
					else {
						list_moji.add(add);
						break;
					}
				}
			}
			//System.out.println(list_moji);
		}

		System.out.println(list_moji.size());
		/*
		while(true) {
			if(roop==0) {
				list_moji.add(list.get(roop));
				roop++;
				continue;
			}
			int tuika = roop;

			while(true) {

				String add="";
				add=add+list.get(tuika);
				if(add.equals(list_moji.get(list_moji.size() - 1))) {
					tuika++;
					continue;
				}
				else {
					list_moji.add(add);
					break;
				}
			}
			roop++;
		}
		 */

	}

}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W, A, B; cin >> H >> W >> A >> B;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << ((i < B) ^ (j < A));
		}
		cout << '\n';
	}

	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int a, b;
    cin >> a >> b;
    bool success = false;

    for(int i = 0; i <= 100; i ++) {
       for(int j = 0 ; j <= 100 ; j ++) {
           if ( i + j == a && i * 2 + j * 4 == b) {
               success = true;
           }
       }
    }
    cout<<(success ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3164
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,M; cin>>N>>M;
  vector<ll> a(N),b(N); rep(i,N) cin>>a[i]>>b[i];
  vector<ll> c(M),d(M); rep(i,M) cin>>c[i]>>d[i];
  
  vector<ll> vec(N,0);
  rep(i,N){
    ll ans=INF;
    ll check=-1;
    rep(j,M){
      if(chmin(ans,abs(a[i]-c[j])+abs(b[i]-d[j]))) check=j;
    }
    vec[i]=check;
  }
  
  for(auto v:vec) cout<<v+1<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

#define int ll

int parseL(string s){
    int res = s[0]-'0';
    rep(i,s.size()){
        if(s[i]=='*') res*=s[i+1]-'0';
        else if(s[i]=='+')res+=s[i+1]-'0';
    }
    return res;
}

int parseM(string s){
    vi v={s[0]-'0'};
    rep(i,s.size()){
        if(s[i]=='*') v.back()*=s[i+1]-'0';
        else if(s[i]=='+') v.pb(s[i+1]-'0');
    }
    int x = 0;
    rep(i,v.size()) x+=v[i];
    return x;
}

signed main(){
    string s;
    while(cin >> s){
    ll x; cin >> x;
    int a = parseM(s);
    int b = parseL(s);
    char ans;
    if(x==a && x==b) ans = 'U';
    else if(x==a) ans = 'M';
    else if(x==b) ans = 'L';
    else ans = 'I';
    cout << ans << endl;
}
}

Measured memory_bytes: 1224
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
#include <queue>
using namespace std;

#define X first
#define Y second
#define N 100010
typedef long long ll;
typedef pair<int,int> pii;
const int Mod=1000000007;

const double INF=1e18;

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout<<max(a*b,c*d)<<endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pi pair<int,int>
#define Pl pair<ll,ll>
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main(){
	int R, C, N, x, y;
	cin >> R >> C >> N;
	priority_queue<Pi> E;
	vector<int> A(N, 2);
	for (int i = 0;i < 2 * N;i++) {
		cin >> x >> y;
		if (x == 0)
			E.push({ y, i / 2 });
		else if (y == C)
			E.push({ C + x, i / 2 });
		else if (x == R)
			E.push({ C + R + C - y, i / 2 });
		else if (y == 0)
			E.push({ C + R + C + R - x, i / 2 });
		else
			A[i / 2]--;
	}
	stack<int> S;
	while (!E.empty()){
		x = E.top().second;
		E.pop();
		if (A[x] != 2) continue;
		if (S.empty()) S.push(x);
		else if (S.top() == x) S.pop();
		else S.push(x);
	}
	if (S.empty()) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 2804
N, Y = map(int, input().split())
flag = False
for x in range(N+1):
    for y in range(N+1):
        z = N - (x + y)
        if z < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            flag = True
            break
    if flag:
        break
else:
    print(-1, -1, -1)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    string solve(string& str) {
        int n = str.size();
        if(n > 1) {
            string s1 = str.substr(0,  (n - 1) / 2),
            s2 = str.substr((n - 1) / 2 + 1, (n - 1) / 2);
            if(s1 != s2) return "No";
            int m = s1.size();
            for(int l = 0, h = m - 1; l < h; ++l, --h) {
                if(s1[l] != s1[h] || s2[l] != s2[h]) return "No";
            }
        }
        return "Yes";
    }

};

int main() {
    string s;
    cin >> s;
    Solution sol;
    auto ret = sol.solve(s);
    cout << ret << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int n,m,a;
ll ans;
int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    
   cin>>n>>m;
   
   for(int i=0 ; i<m ; i++)
   {
   	cin>>a;
   	ans+=a;
   }
   
   if(n>=ans)
   {
   	ans=n-ans;
   	cout<<ans;
   }
   else
   {
   	puts("-1");
   }
    
	
	
}







Measured memory_bytes: 3656
s = input()
t = input()

c = [0] * (len(s) - len(t)+1)

for i in range(len(s) - len(t) +1):
  for j in range(len(t)):
    if s[i+j] == t[j]:
      c[i] += 1

print(len(t)-max(c))

Measured memory_bytes: 67728
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll MOD = 1E9 + 7;

int main() {
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    int st = (N + M - 1) / (K - 1);
    ll A[2010], B[2010];
    memset(A, 0, sizeof(A));
    ll res = 0;
    for (int i = 0;i < K;i++) {
    	A[i] = 1;
    	if (i != 0 && (N - i) % (K - 1) == 0 && (N - i) / (K - 1) < st) res++;
    }
    for (int i = 1;i < st;i++) {
    	int rem = st - i - 1;
    	memset(B, 0, sizeof(B));
    	ll sum = 0;
    	for (int j = 1;j <= N;j++) {
    		sum += A[j - 1];
    		sum %= MOD;
    		// Place 1 ~ K - 1.
    		B[j] = sum;
    		if ((N - j) % (K - 1) == 0 && (N - j) / (K - 1) <= rem) {
    			res += B[j];
    			res %= MOD;
    		}
    		if (j - (K - 1) >= 0) {
    			sum += MOD - A[j - (K - 1)];
    			sum %= MOD;
    		}
    	}
    	// Place 0.
    	for (int j = 0;j <= N;j++) {
    		B[j] += A[j];
    		B[j] %= MOD;
    	}
    	swap(A, B);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int sign(int x){
    if(x==0) return 0;
    return x/abs(x);
}

pair<int,int> f(int x,int y){
    if(x==0 or y==0) return {y,x};
    if(x<0){
        return {y,-x};
    }
    else return {-y,x};
}

int p[maxn];

int32_t main(){
    fast_io;
    int n;
    p[0]=1;
    fo(i,1,maxn-1){
        p[i] = (p[i-1]*2ll)%MOD;
    }
    cin>>n;
    vector<pair<int,int> > v;
    map<pair<int,int>, int> m;
    map<pair<int,int>, int> visited;
    int temp=0;
    for (int i = 0; i < n; ++i)
    {
        int x,y;
        cin>>x>>y;
        if(x==0 and y==0) {
            temp++;
            continue;
        }
        int g = __gcd(abs(x),abs(y));
        x/=g;
        y/=g;
        if(sign(x)==0 or sign(y)==0){
            x = abs(x);
            y = abs(y);
        }
        else if(sign(x) != sign(y)){
            x = -abs(x);
            y = abs(y);
        }
        else{
            x = abs(x);
            y = abs(y);
        }
        m[{x,y}]++;
    }
    for(auto it:m){
        if(visited[it.first]) continue;
        int x = it.first.first;
        int y = it.first.second;
        visited[it.first] = 1;
        auto inverse = f(x,y);
        // cout<<x<<" "<<y<<" "<<inverse.first<<" "<<inverse.second<<endl;
        // cout<<m[it.first]<<" "<<m[inverse]<<endl;
        visited[inverse] = 1;
        v.emplace_back(m[it.first] , m[inverse]);
    }
    int ans = 1;
    for(const auto &it:v){
        ans = (ans * (p[it.first] + p[it.second] -1ll))%MOD;
    }
    ans--;
    if(temp) ans += temp; 
    ans = (ans+MOD)%MOD;
    show(ans);
    return 0;
}

Measured memory_bytes: 58000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int n,m,a,temp=0,sum=0;
    cin>>n>>m;
    priority_queue<int> q;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        q.push(a);
    }
    while(m>0)
    {
        temp=q.top()/2;
        q.pop();
        q.push(temp);
        --m;
    }
    while(!q.empty())
    {
        sum+=q.top();
        q.pop();
    }
    cout<<sum;
}


Measured memory_bytes: 892
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split())) # A[0]=W, A[i]=ai

GX = [None]*N # GX[i] := YがA[i] を取った直後の状況から到達しうる最大のスコア
GY = [None]*N # GY[i] := XがA[i] を取った直後の状況から到達しうる最小のスコア
minGX = 10**20
maxGY = 0

for k in range(N-1, -1, -1):
    GX[k] = max(abs(A[k]-A[N]), maxGY)
    GY[k] = min(abs(A[k]-A[N]), minGX)
    minGX = min(minGX, GX[k])
    maxGY = max(maxGY, GY[k])

print(GX[0])

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct node{
  int key;
  struct node *next, *prev;
};
 
typedef struct node *NodePointer;
 
void insert(int);
void deleteNode(NodePointer);
void delete(int);
void init(void);
void deletefirst(void);
void deletelast(void);
NodePointer finditem(int);
void listprint(void);
 
NodePointer head;
 
int main(){
  int n, i, b;
  char c[15];
 
  scanf("%d", &n);
  init();
  for(i = 0;i < n; i++){
    scanf("%s%d", c, &b);
    if(strcmp(c, "insert") == 0){
      insert(b);
    }
    else if(strcmp(c, "delete") == 0){
      delete(b);
    }
    else if(strcmp(c, "deleteFirst") == 0){
      deletefirst();
    }
    else if(strcmp(c, "deleteLast") == 0){
      deletelast();
    }
  }
  listprint();
  return 0;
}
 
void insert(int data){
  NodePointer x = (NodePointer)malloc(sizeof(NodePointer));
 
  x->key = data;
  x->next = head->next;
  head->next->prev = x;
  head->next = x;
  x->prev = head;
}
 
void listprint(){
  NodePointer n = head->next;
  int flg = 0;
 
  while(1){
    if(n == head) break;
    if(flg++ > 0) printf(" ");
    printf("%d", n->key);
    n = n->next;
  }
  printf("\n");
}
 
NodePointer finditem(int data){
  NodePointer n = head->next;
 
  while(n != head && n->key != data){
    n = n->next;
  }
  return n;
}
 
void init(){
  head = (NodePointer)malloc(sizeof(NodePointer));
  head->next = head;
  head->prev = head;
}
 
void deleteNode(NodePointer a){
  if(a == head) return;
  a->prev->next = a->next;
  a->next->prev = a->prev;
  free(a);
}
 
void delete(int keydata){
  deleteNode(finditem(keydata));
}
 
void deletefirst(){ 
  deleteNode(head->next);
}
 
void deletelast(){
  deleteNode(head->prev);
}

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

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

using namespace std;
using ll = long long;

typedef struct Node{
    vector<int> edges_number;
    vector<int> edges_to;
    vector<int> edges_cost;

    int id;
    int from;

    bool done; //確定ノードかどうか
    int cost; //現時点での最小コスト
} Node;

void initNode(int N, Node *nodes, int *decide);
void dijkstra(int *use, int *decide, Node *nodes, int s, int N);

bool operator > (Node a, Node b){
    return a.cost > b.cost;
}
bool operator < (Node a, Node b){
    return a.cost < b.cost;
}

int main(void){
    int N, M;
    cin >> N >> M;
    int use[M] = {0};
    int decide[N] = {0};
    Node nodes[N];
    initNode(N, nodes, decide);
    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        nodes[a-1].edges_number.push_back(i); nodes[a-1].edges_to.push_back(b-1); nodes[a-1].edges_cost.push_back(c);
        nodes[b-1].edges_number.push_back(i); nodes[b-1].edges_to.push_back(a-1); nodes[b-1].edges_cost.push_back(c);
    }

    for(int i = 0; i < N; i++){
        dijkstra(use, decide, nodes, i, N); //ノードiからの各最短経路を出し、使った辺をuseに記録
        initNode(N, nodes, decide); //最小コストや確定ノードの情報をリセット
    }
    int ans = 0;
    rep(i, M) if(use[i] == 0) ans++;
    cout << ans << endl;
    return 0;
}

void initNode(int N, Node *nodes, int *decide){
    int bignum = 1000000000;
    rep(i, N){
        nodes[i].id = i;
        nodes[i].done = false;
        nodes[i].cost = bignum;
        decide[i] = 0;
    }
}

void dijkstra(int *use, int *decide, Node *nodes, int s, int N){
    //最短経路を求める
    priority_queue<Node, vector<Node>, greater<Node>> q;
    nodes[s].cost = 0;
    nodes[s].from = -1;
    q.push(nodes[s]); //63行目と順序を入れ替えるのはダメ(入れたものに対して変更するとヒープの整合性がね)
    while(!q.empty()){
        Node doneNode = q.top();
        q.pop();
        if(decide[doneNode.id] == 1) continue; //既に確定ノード -> continue

        doneNode.done = true; //確定ノードとする
        decide[doneNode.id] = 1;
        if(doneNode.cost != 0) use[doneNode.from] = 1; //使用した辺を記録
        int loop = doneNode.edges_to.size();
        rep(i, loop){
            int to = doneNode.edges_to[i];
            int c = doneNode.cost + doneNode.edges_cost[i];
            if(c < nodes[to].cost){
                nodes[to].cost = c;
                nodes[to].from = doneNode.edges_number[i];
                q.push(nodes[to]);
            }
        }
    }
}

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

using namespace std;

int main() {
  int n;
  string a;
  cin >> n >> a;
  int ans = 0;
  for (int i = 0, j; i < n; i = j) {
    for (j = i; j < n && a[i] == a[j]; j++);
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<vector<P>> g(n);
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(P(v, w));
    g[v].push_back(P(u, w));
  }
  vi c(n, -1);
  stack<int> st;
  st.push(0);
  c[0] = 0;
  while(!st.empty()) {
    int i = st.top();
    st.pop();
    for(auto v : g[i]) {
      int ni = v.first;
      int d = v.second;
      if(c[ni] != -1) continue;
      if(d % 2)
        c[ni] = 1 - c[i];
      else
        c[ni] = c[i];
      st.push(ni);
    }
  }
  rep(i, n) cout << c[i] << endl;
}

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

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

    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    int cnt = 0;
    REP (i, H) {
        REP (j, W) {
            cin >> A[i][j];
            if (A[i][j] == '#') {
                cnt++;
            }
        }
    }    

    if (cnt == H + W - 1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }


}

Measured memory_bytes: 256