akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	for (int i = 0; i < n; i++) cin >> q[i];
	vector<int> a(n);
	for (int i = 0; i < n; i++) a[i] = i + 1;
	int x = 0, y = 0, cnt = 0;
	do {
		cnt++;
		bool flag1 = true;
		bool flag2 = true;
		for (int i = 0; i < n; i++) {
			if (a[i] != p[i]) flag1 = false;
			if (a[i] != q[i]) flag2 = false;
		}
		if (flag1) x = cnt;
		if (flag2) y = cnt;
	} while (next_permutation(all(a)));
	cout << abs(x - y) << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
//	"strconv"
//	"sort"
//	"math"
//	"regexp"
)


var a,b,c int

func main(){
	fmt.Scan(&a,&b,&c)

	if a+b == c || a+c == b || b+c == a{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
n=int(input())
arr=list(map(int,input().split()))
ans=sum(arr)
if n==0:
  if arr[0]==1:
    print(1)
  else:
    print(-1)
  exit()
for i in range(n):
  if i<=30 and arr[i]>=2**i:
    print(-1)
    exit()
if n<=30 and arr[n]>2**n:
  print(-1)
  exit()
maxs=[0]*(n+1)
maxs[0]=1
for i in range(1,n):
  maxs[i]=2*maxs[i-1]-arr[i]
tmp=arr[n]
for i in range(n-1,-1,-1):
  maxs[i]=min(maxs[i],tmp)
  tmp+=arr[i]
mins=[0]*(n+1)
for i in range(n-1,-1,-1):
  mins[i]=(mins[i+1]+arr[i+1]+1)//2
for i in range(n):
  if maxs[i]<mins[i]:
    print(-1)
    exit()
ans+=sum(maxs)
print(ans)

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

int main() {
  vector <long long> A;
  for (int i = 0; i < 3; i++) {
    long long a;
    cin >> a;
    A.emplace_back(a);
  }
  sort(A.begin(), A.end());
  
  long long result = 0 + (A[1] - A[0]) + (A[2] - A[1]);
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;
fn main() {
    input! {
        a: usize, b: usize, n: usize,
    }
    let al = if b -1 > n {
        n
    } else {
        b - 1
    };
    let left = al * a / b;
    let right = (al / b) * a;
    println!("{}", left - right);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

const int MOD = 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	// bitset<200005>	bs;
	vector<ll>	V(200005);
	int n;
	cin >> n;
	vector<int>	VV(n);
	rep(i, n)
	{
		int x;
		cin >> x;
		V.at(x)++;
		// bs.set(x);
		VV.at(i) = x;
	}
	ll	total;
	total = 0;
	rep(i, 200005)
	{
		if (V.at(i) < 2)
			continue;
		total += V.at(i) * (V.at(i) - 1);
	}
	total /= 2;
	rep(i, n)
	{
		cout << total - (V.at(VV.at(i)) - 1) << endl;
	}
}
// END

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


Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],M=-1,m=LLINF,cntm=0,cntM=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        M=max(M,a[i]);
        m=min(m,a[i]);
    }
    rep(i,n){
        if(a[i]==m) cntm++;
        else if(a[i]==M)  cntM++;
    }
    if(M-m>=2){
        cout<<"No"<<endl;
    } else if(M==m){
        if(n==m+1||n>=2*m){
            cout<<"Yes"<<endl;
        } else{
            cout<<"No"<<endl;
        }
    } else{
        if(cntm<M&&2*(M-cntm)<=cntM){
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    long height[n];
    long maxNum = 0;
    long count = 0;
    for (long i = 0; i < n; i++)
    {
        cin >> height[i];
        if (i == 0)
        {
            continue;
        }

        if (height[i] <= height[i - 1])
        {
            count++;
            if (count > maxNum)
            {
                maxNum = count;
            }
        }
        else
        {
            count = 0;
        }
    }
    
    cout << maxNum << endl;
}

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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	char s[200001]; cin >> s;
	ll i = 0;
	ll A = -1, Z = 0;
	while (s[i]) {
		if (s[i] == 'A' && A == -1) {
			A = i;
		}
		if (s[i] == 'Z') {
			Z = i;
		}
		i++;
	}
	cout << Z - A + 1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <string>
#include <algorithm>
#include <initializer_list> 
using namespace std;

int main(){
	int N;
	cin >> N;
	int a[114514];
	int b[114514];
	int c[114514];
	int d[114514];
	int po[114514] = {};
	for (int i = 0; i < N; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		int le = a[i] * c[i] + b[i] * d[i];
		if (c[i] >= 5 && d[i] >= 2){
			po[i] = le*0.8;
		}
		else{
			int at = 5 - c[i];
			int bt = 2 - d[i];
			int k = max( at, 0 )*a[i] + max( bt, 0 )*b[i];
			int k2 = (le + k)*0.8;
			po[i] = min( le, k2 );
		}
	}
	for (int i = 0; i < N; i++){
		cout << po[i] << endl;
	}
}

Measured memory_bytes: 3388
/*
*******************
2018-11-04 Sun
*******************
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
const int INF = 1<<31;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int LL;

int x,y;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(NULL);
    cout.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	
    
    cin >> x >> y;
    int r=y/2;

    cout << x+r;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void) {
	LL N;
	cin >> N;

	// 1 100 10000
	LL ans = 0;
	for (LL i = 1; i <= N; i++) {
		if (1 <= i and i <= 9 || 100 <= i and i <= 999 || 10000 <= i and i <= 99999){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int v[4];
    loop (4, i) {
        char c; cin >> c;
        v[i] = c;
    }
    sort(v, v + 4);
    if (v[0] == v[1] && v[2] == v[3] && v[1] != v[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
n = int(input())
w = [input() for i in range(n)]
if len(w)!=len(set(w)):
  print('No')
  sys.exit()
for i in range(1,n):
  if w[i-1][-1] != w[i][0]:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;
template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    string s;cin >> s;
    ll n = s.size();
    vector<vector<ll>> dp(n+1,vector<ll>(2,-1));
    dp[0][1] = 0;
    rep(i,n){
        rep(small,2){
            ll t = s[i] - '0';
            if(small){
                rep(j,t)chmax(dp[i+1][0], dp[i][small] + j);
                chmax(dp[i+1][1], dp[i][1]+t);
            }
            else{
                if(dp[i][0] != -1)rep(j,10)chmax(dp[i+1][0], dp[i][small] + j);
            }
        }
    }

    cout << max(dp[n][0], dp[n][1]) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int in, s, h, m;
  scanf("%d",&in);
  h = in / 3600;
  in %= 3600;
  m = in / 60;
  in %= 60;
  s = in;
  printf("%d:%d:%d\n", h, m, s);

  return 0;
    }



Measured memory_bytes: 1964
#include <iostream>
#include <vector>
#include <queue>

void root(int k, std::vector< std::vector< std::pair<int, int> > > &g, long long int distances[])
{
	std::queue<int> q;
	std::queue<long long int> qcounter;
	q.push(k);
	qcounter.push(0);
	
	bool visited[100010] = { 0 };
	
	while (q.empty() == false)
	{
		int top = q.front();
		long long int counter = qcounter.front();
		q.pop();
		qcounter.pop();
		
		distances[top] = counter;
		
		if (visited[top])
			continue;
		else
			visited[top] = true;
		
		for (int i = 0; i < g[top].size(); ++i)
		{
			int node = g[top][i].first;
			if (!visited[node])
			{
				q.push(node);
				qcounter.push(counter + g[top][i].second);
			}
		}
	}
	
}

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	int n;
	std::cin >> n;
	
	std::vector< std::vector< std::pair<int, int> > > g(n);
	
	for (int i = 0; i < n - 1; ++i)
	{
		int x, y, w;
		std::cin >> x >> y >> w;
		
		g[x - 1].push_back(std::make_pair(y - 1, w));
		g[y - 1].push_back(std::make_pair(x - 1, w));
	}
	
	int q, k;
	std::cin >> q >> k;
	--k;
	
	long long int distances[100010] = { 0 };
	root(k, g, distances);
	
	while (q--)
	{
		int x, y;
		std::cin >> x >> y;
		--x;
		--y;
		
		std::cout << distances[x] + distances[y] << "\n";
	}
}

Measured memory_bytes: 8692
n,m = map(int,input().split())
list = [0]*(n+2)
for i in range(m):
    l,r = map(int,input().split())
    list[l]+=1
    list[r+1]-=1
sum = 0
cnt = 0
for x in list:
    sum += x
    if sum == m :
        cnt+=1
print(cnt)

Measured memory_bytes: 3956
n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for _ in range(m)]


def ng():
  print('-1')
  exit()


d = {}
for s, c in sc:
  if s in d and d[s] != c:
    ng()
  d[s] = c

ans = [''] * (n + 1)
ans[0] = 'Padding'
for s, c in sc:
  ans[s] = str(c)

if ans[1] == '0' and n!=1:
  ng()

for i in range(1, n + 1):
  if ans[i] == '':
    if i == 1 and n != 1:
      ans[i] = '1'
    else:
      ans[i] = '0'


print(int(''.join(ans[1:])))


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a==b&&b!=c){
    printf("Yes");
  }
  else if(a!=b&&b==c){
    printf("Yes");
  }
  else if(a==c&&b!=c){
    printf("Yes");
  }
  else{
    printf("No");
}
  return 0;
}
    


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;

    }
    cout << ans << endl;
 }


Measured memory_bytes: 256
#-----------------------------
#https://atcoder.jp/contests/agc008/submissions/15248942
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
#-----------------------------
N = ini()
ans = 0
lastA = 0
firstB = 0
BA = 0

for i in range(N):
    s = input()
    #siの文字列内のABを抽出
    for j in range(len(s)-1):
        if s[j:j+2] == "AB":
            ans += 1

    #先頭Bかつ末尾A、先頭B、末尾A、を抽出
    if s[0] == "B" and s[-1] == "A":
        BA += 1
    elif s[0] == "B":
        firstB += 1
    elif s[-1] == "A":
        lastA += 1

if BA >= 2:
    ans += BA - 1

#BAと末尾Aと先頭Bをつなげて、余った末尾Aと先頭Bをつなげる
if BA >= 1 and lastA >= 1 and firstB >=1:
    ans += 2 + min(lastA-1,firstB-1)
#BAと末尾Aをつなげる
elif BA >= 1 and lastA >= 1 and firstB == 0:
    ans += 1
#BAと先頭Bをつなげる
elif BA >= 1 and lastA == 0 and firstB >= 1:
    ans += 1
#末尾Aと先頭Bをつなげる
elif BA < 1 and lastA >= 1 and firstB >= 1:
    ans += min(lastA,firstB)

print(ans)


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

int main() {
  int h, w, sum = 0, ave;
  cin >> h >> w;
  vector<string> a(h);
  for(int i = 0; i < h; i++) cin >> a.at(i);
  for(int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
  for(int i = 0; i < h; i++) cout << '#' << a.at(i) << '#' << endl;
  for(int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
}


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

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a % b) : a;
}

signed main()
{
	int a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << endl;
	}
}

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

// #define REP(i, x) REPI(i, 0, x)
// #define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
// #define ALL(x) (x).begin(), (x).end()

// typedef long long ll;
// using namespace std;

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

//   int K;
//   cin >> K;
//   map<set<int>, int> memo;

//   ll ans = 0;

//   REPI(a, 1, K + 1) {
//     REPI(b, 1, K + 1) {
//       REPI(c, 1, K + 1) {
//         if (a == b && b == c) {
//           ans += a;
//           continue;
//         }

//         set<int> s = {a, b, c};
//         if (memo.find(s) != memo.end()) {
//           ans += memo.at(s);
//         } else {
//           int g = __gcd(__gcd(a, b), c);
//           memo.insert(make_pair(s, g));
//           ans += g;
//         }
//       }
//     }
//   }

//   cout << ans << endl;

//   return 0;
// }

#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int K;
  cin >> K;
  if (K == 1) {
    cout << 1 << endl;
    return 0;
  }

  map<pair<int, int>, int> memo;
  ll ans = 0;

  REPI(i, 1, K + 1) {
    REPI(j, 1, K + 1) { memo.insert(make_pair(make_pair(i, j), __gcd(i, j))); }
  }

  for (auto it : memo) {
    REPI(k, 1, K + 1) { ans += memo.at(make_pair(it.second, k)); }
  }

  cout << ans << endl;

  return 0;
}

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

const int MAX_N = 1100;
int par[MAX_N]; // 親
int rank_[MAX_N]; // 木の深さ
int cnt_[MAX_N]; // 属する頂点の個数(親のみ正しい)

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank_[i] = 0;
        cnt_[i] = 1;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_[x] < rank_[y]){
        par[x] = y;
        cnt_[y] += cnt_[x];
    }else{
        par[y] = x;
        cnt_[x] += cnt_[y];
        if(rank_[x] == rank_[y]) rank_[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


int main() {
    int n, m;
    cin >> n >> m;
    ll X;
    cin >> X;
    vector<pair<ll,P>> v(m);
    rep(i,m){
        cin >> v[i].second.first >> v[i].second.second >> v[i].first;
    }
    sort(v.begin(), v.end());

    if(n == 2){
        cout << 0 << endl;
        return 0;
    }

    ll ng = 0, ok = 0, free = 0;
    rep(i,m){
        UFinit();
        int x, y;
        x = v[i].second.first;
        y = v[i].second.second;
        ll w = v[i].first;
        ll sum = w;
        unite(x,y);
        rep(j,m){
            x = v[j].second.first;
            y = v[j].second.second;
            w = v[j].first;
            if(find(x)!=find(y)){
                unite(x,y);
                sum += w;
            }
        }
        // cout << i << ' ' << sum << endl;
        if(sum < X){
            ng++;
        }else if(sum == X){
            ok++;
        }else{
            free++;
        }
    }
    // cout << ok << ' ' << ng << ' ' << free << endl;
    ll MOD = 1000000007;
    ll ans = 1;
    if(ok == 0){
        cout << 0 << endl;
        return 0;
    }

    if(ng == 0){
        rep(i,ok){
            ans *= 2;
            ans %= MOD;
        }
        ans += MOD - 2;
        ans %= MOD;
        rep(i,free){
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << endl;
        return 0;
    }

    rep(i,ok){
        ans *= 2;
        ans %= MOD;
    }
    ans--;
    rep(i,free){
        ans *= 2;
        ans %= MOD;
    }
    ans *= 2;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3672
n=int(input())
w_list=[int(i) for i in input().split()]
ans=10**11
for i in range(1,n+1):
	result1=sum(w_list[:i])
	result2=sum(w_list[i:])
	if ans>abs(result1-result2):
		ans=abs(result1-result2)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    int n;
    cin>>n;
    string s;
    unordered_map<string,int>mp;

    rep(i,n){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;


    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    string s; cin >> s;
    if(s[0] == s[1] && s[1] == s[2] && s[0] == 'R') {
        cout << 3 << endl;
    } else if((s[0] == s[1] || s[1] == s[2]) && s[1] == 'R') {
        cout << 2 << endl;
    } else if(count(s.begin(), s.end(), 'R')) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
	bool flag = true;
	int N;
	int A;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		if(A%2==0){
			flag = (A%5==0)?true:(A%3==0)?true:false;
		}
		if(!flag)break;
	}
	if(flag) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return EXIT_SUCCESS;	
}

Measured memory_bytes: 256
<?php
  $an[] = trim(fgets(STDIN));
  $an[] = trim(fgets(STDIN));
  $an[] = trim(fgets(STDIN));
  $an[] = trim(fgets(STDIN));
  $an[] = trim(fgets(STDIN));
  $k = trim(fgets(STDIN));
  for($i=0; $i<4; $i++){
      for($j=$i+1; $j<5; $j++){
          if(abs($an[$i]-$an[$j]) > $k){
              echo ":(";
              exit;
          }
      }
  }
  echo "Yay!";

Measured memory_bytes: 4732
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	b := scanString()
	ans := map[string]string{}
	ans["A"] = "T"
	ans["T"] = "A"
	ans["C"] = "G"
	ans["G"] = "C"
	fmt.Fprintln(wr, ans[b])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int v[1000000];
int t;
int n;
string s;
void dfs(int x)
{
	for (int i = x; i < n; i++)
	{
		if (s[x] == s[i])
		{
			v[i] =1;
		}
		else
			break;
	}
}
int main()
{
	
	cin >> n;
	
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (!v[i] )
		{
			t++;
			dfs(i);
		}
	}
	cout << t;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=0;i<n;i+=2)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  string s;
  cin >> s;
  int n=s.length();
  r1(i, n) s.at(i)='x';
  cout << s << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, M = Scanner.map_int()
    H = Scanner.map_int()
    G = [[] for _ in range(N)]
    for _ in range(M):
        a, b = Scanner.map_int()
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    ans = 0
    for i in range(N):
        if len(G[i]) == 0:
            ans += 1
            continue
        for g in G[i]:
            if H[g] >= H[i]:
                break
        else:
            ans += 1
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

string next(string prev){
	int c = prev.size() - 1;
	while ( c != 0 && (prev[c]-prev[c-1] > 0 || (prev[c] == prev[c-1] && prev[c] == '9')) )
		c--;
	if ( c == 0 ){
		if ( prev[0] != '9' ){
			prev[0]++;
		}else{
			prev = "10" + prev.substr(1);
			c++;
		}
	}else{
		prev[c]++;
	}
	for ( int i = c + 1 ; i < prev.size() ; i++ )
		prev[i] = max(char(prev[i-1]-1),'0');

	return prev;
}

bool is_lunlun(ll n){
	int act, prev = n % 10;
	n /= 10;
	while (n){
		act = n % 10;
		if ( abs(act-prev) > 1 )
			return false;
		prev = act;
		n /= 10;
	}
	return true;
}

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin >> k;
	string res = "0";
	for ( int i = 0 ; i < k ; i++ ){
		res = next(res);
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 256
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const X = parseInt(input[0], 10);
    if (parseInt(input[1], 10) >= parseInt(input[2], 10)) {
        console.log("delicious");
    } else {
        const day = Math.abs(parseInt(input[1], 10) - parseInt(input[2], 10));
        console.log(X >= day ? "safe" : "dangerous");
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

const int MAX_N = (1 << 18) - 1;
const int MAX_L = 100000;

struct wgtval {
  int wgt, val;
};

int n;
int val[MAX_N], wgt[MAX_N];

int dpn;
vector<wgtval> dp[MAX_N];

bool operator<(const wgtval& a, const wgtval& b) {
  return a.wgt < b.wgt || (a.wgt == b.wgt && a.val < b.val);
}

void compute_dp()
{
  /* initialize */
  dpn = min(n, 1 << 12);
  dp[0] = { {0, 0}, {wgt[0], val[0]} };

  /* compute the dp table */
  for (int u = 1; u < dpn; u++) {
    int parent = (u - 1) / 2;

    dp[u] = dp[parent]; /* copy */
    for (wgtval wv : dp[parent]) {
      if (wv.wgt + wgt[u] <= MAX_L) {
        dp[u].push_back({wv.wgt + wgt[u], wv.val + val[u]});
      }
    }
    sort(dp[u].begin(), dp[u].end());

    /* remove unnecessary entries */
    int tail = 0;
    for (int i = 1; i < dp[u].size(); i++) {
      if (dp[u][tail].wgt == dp[u][i].wgt) {
        dp[u][tail] = dp[u][i];
      } else if (dp[u][tail].val < dp[u][i].val) {
        tail++;
        dp[u][tail] = dp[u][i];
      }
    }
    dp[u].resize(tail + 1);
  }
}

int solve(int u, int l)
{
  if (u < dpn) {
    const wgtval key = {l, INT_MAX};
    auto x = upper_bound(dp[u].begin(), dp[u].end(), key) - 1;
    return x->val;
  }

  int parent = (u - 1) / 2;
  int s = solve(parent, l);
  if (l >= wgt[u]) {
    s = max(s, val[u] + solve(parent, l - wgt[u]));
  }
  return s;
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> val[i] >> wgt[i];
  }

  compute_dp();

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int u, l;
    cin >> u >> l;
    cout << solve(u - 1, l) << endl;
  }

  return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  char c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c[i][j];
    }
  }
  for(int k=0;k<h;k++){
    for(int l=0;l<w;l++){
      cout << c[k][l];
    }
    cout << endl;
    for(int l=0;l<w;l++){
      cout << c[k][l];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll =  long long;
const int INF = 0x3f3f3f3f;

int R, G, B, N;
set<tuple<int,int,int>> res;

void solve()
{
	long long ans = 0;
	for(int r=0; r*R<=N;++r){
		for(int g=0; g*G<=N; ++g){
			int need = N-g*G-r*R;
			if(need >=0 && need % B == 0) ans++;
		}
	}
	cout << ans << "\n";
}

int main()
{	
	cin >> R >> G >> B >> N;
	solve();
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    vint a1(n);
    vint a2(n);
    REP(i,n) cin >> a1[i];
    REP(i,n) cin >> a2[i];
    REP(i,n){
        int t = 0;
        for(int j=0;j<=i;++j) t+=a1[j];
        for(int j=i;j<n;++j) t+=a2[j];
        ans = max(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int LIMIT = 100;
int MDT[16][16];
vector<int> puzzle(16);
int zero, val, limit;
int dfs(int depth, int prev)
{
    if(val == 0) return depth;
    if(depth + val >= limit) return LIMIT;
    int res = LIMIT;
    for(int i = 0; i < 4; i++)
    {
        if((i + 2) % 4 == prev) continue;
        int y = zero / 4, x = zero % 4;
        int ny = y + dy[i], nx = x + dx[i];
        if(ny < 0 || nx < 0 || ny >= 4 || nx >= 4) continue;
        vector<int> tmp(puzzle);
        for(int j = 0; j < 16; j++) tmp[j] = puzzle[j];
        int tmp_zero = zero, tmp_val = val;
        int piece_idx = ny * 4 + nx, piece_num = puzzle[piece_idx];
        val -= MDT[zero][15];
        val -= MDT[piece_idx][piece_num];
        val += MDT[zero][piece_num];
        val += MDT[piece_idx][15];
        swap(puzzle[zero], puzzle[piece_idx]);
        zero = piece_idx;
        res = min(dfs(depth + 1, i), res);
        puzzle = tmp, zero = tmp_zero, val = tmp_val;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0; i < 16; i++) for(int j = 0; j < 16; j++) MDT[i][j] = abs(i / 4 - j / 4) + abs(i % 4 - j % 4);
    for(int i = 0; i < 16; i++)
    {
        cin >> puzzle[i];
        if(puzzle[i] == 0) zero = i, puzzle[i] = 15;
        else puzzle[i]--;
        val += abs(i / 4 - puzzle[i] / 4) + abs(i % 4 - puzzle[i] % 4);
    }
    int ans = INF;
    for(int i = val; i <= LIMIT; i++)
    {
        limit = i;
        ans = dfs(0, -1);
        if(ans < LIMIT)
        {
            cout << ans << endl;
            break;
        }
    }
    return 0;
}




Measured memory_bytes: 3212
use std::io::*; //Not mine.
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 s: String = read();
    println!(
        "{}",
        if s.chars().filter(|&c| c == 'o').count() + 15 - s.len() >= 8 {
            "YES"
        } else {
            "NO"
        }
    );
}

Measured memory_bytes: 4476
import java.util.Scanner;
class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
  String str=scan.next();
  boolean bool=true;
  for(int i=0;i<str.length();i++){
  	char ch=str.charAt(i);
    if(i%2==0){if(ch=='L')bool=false;}
    else{if(ch=='R')bool=false;}
  }
  System.out.println(bool?"Yes":"No");
}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll L;
    int N;cin>>L>>N;
    vector<ll> X(N+2),lsum(N+2),rsum(N+2);
    for(int i=0;i<N;i++) cin>>X[i+1];
    
    for(int i=1;i<=N;i++){
        lsum[i]=lsum[i-1]+2*X[i];
    }
    
    for(int i=N;i>=1;i--){
        rsum[i]=rsum[i+1]+2*(L-X[i]);
    }
    
    ll ans=0;
    
    for(int i=1;i<=N;i++){
        int c=(N-i)/2;
        int d=(N-i)%2;
        ll sum=0;
        sum+=lsum[i+c]-lsum[i-1];
        if(d) sum+=rsum[N-c]-rsum[N+1];
        else sum+=rsum[N-c+1]-rsum[N+1];
        
        if(d) sum-=L-X[N-c];
        else sum-=X[i+c];
        
        ans=max(ans,sum);
    }
    
    vector<ll> Y(N+2);
    for(int i=1;i<=N;i++) Y[i]=L-X[N+1-i];
    
    for(int i=1;i<=N;i++){
        lsum[i]=lsum[i-1]+2*Y[i];
    }
    for(int i=N;i>=1;i--){
        rsum[i]=rsum[i+1]+2*(L-Y[i]);
    }
    
    for(int i=1;i<=N;i++){
        int c=(N-i)/2;
        int d=(N-i)%2;
        ll sum=0;
        sum+=lsum[i+c]-lsum[i-1];
        if(d) sum+=rsum[N-c]-rsum[N+1];
        else sum+=rsum[N-c+1]-rsum[N+1];
        
        if(d) sum-=L-Y[N-c];
        else sum-=Y[i+c];
        
        ans=max(ans,sum);
    }
    
    cout<<ans<<endl;
    
    
}




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

#define el '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;

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

  int n, m;
  cin >> n >> m;
  vector<ll> x(m);
  for(int i = 0; i < m; i++){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  priority_queue<ll> pq;
  ll ans = 0;
  for(int i = 1; i < m; i++){
    ans += abs(x[i]-x[i-1]);
    pq.push(abs(x[i]-x[i-1]));
  }
  n--;
  while(!pq.empty() && n){
    ans -= pq.top();
    pq.pop();
    n--;
  }
  cout << ans << el;
  
  return 0;
}

Measured memory_bytes: 2168
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val mod = 2019
    val s = readString().reversed()
    var res = 0
    var x = 1
    var total = 0
    var cnt = Array(mod+1) { 0 }
    for (i in 0 until s.length) {
        cnt[total]++
        total += ((s[i] - '0') * x) % mod
        total %= mod
        x = (x * 10) % mod
        res += cnt[total]
    }
    println(res)
}

Measured memory_bytes: 43680
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        long ans = (n - 2L) * (n - 2L);
        Map<Integer, Integer> rM = new HashMap<>();
        Map<Integer, Integer> cM = new HashMap<>();
        int m = n;
        for (int i = 0; i < q; i++) {
            int type = scan.nextInt();
            int pos = scan.nextInt();
            if (type == 1) {
                if (cM.containsKey(pos)) {
                    ans -= cM.get(pos);
                } else {
                    ans -= n - 2;
                    for (int j = pos + 1; j < m; j++) {
                        cM.put(j, n - 2);
                    }
                    m = pos;
                }
            } else {
                if (rM.containsKey(pos)) {
                    ans -= rM.get(pos);
                } else {
                    ans -= m - 2;
                    for (int j = pos + 1; j < n; j++) {
                        rM.put(j, m - 2);
                    }
                    n = pos;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 100984
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int cnt = 0;
	while(n!=0){
		int r = n % 10;
		n /= 10;
		if(r == 2)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  char t = s[0];
  for (int i = 1; i < n; i++) {
    if (t == s[i]) {
      continue;
    }
    else {
      ans++;
      t = s[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define MAX 10000

int n;

int linersearch(int a[],int key){
    int i=0;
    a[n]=key;
    while(a[i]!=key){
        i++;
    }
    if(i==n)return 0;
    else return 1;
}

int main(){
    int a[MAX],q,key,sum=0;

    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    scanf("%d",&q);

    for(int i=0;i<q;i++){
        scanf("%d",&key);
        if(linersearch(a,key))sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2760
#include <stdio.h>

int main(){
  int n,a[10001],i;
  int min,max;
  long long sum=0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  min=a[0];
  max=a[0];
  for(i=0; i<n; i++){
    if(min>a[i])min=a[i];
    if(max<a[i])max=a[i];
    sum+=a[i];
  }
  printf("%d %d %ld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, M;
    cin >> N >> M;
    vector<int> bulbs(M, 0);
    rep(i, 0, M)
    {
        int k;
        cin >> k;
        rep(j, 0, k)
        {
            int s;
            cin >> s;
            --s;
            bulbs[i] |= (1 << s);
        }
    }

    vector<int> ps(M);
    rep(i, 0, M) cin >> ps[i];

    int ans = 0;
    rep(i, 0, 1 << N)
    {
        bool allOn = true;

        rep(j, 0, M)
        {
            const int bits = i & bulbs[j];
            if (__builtin_popcount(bits) % 2 != ps[j])
            {
                allOn = false;
                break;
            }
        }

        if (allOn)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    int n, d;
    cin >> n >> d;
    int sm = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x; x--;
        x %= (d + 1);
        sm ^= x;
    }
    if (sm) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}



Measured memory_bytes: 3076
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX 100010
int sosu[MAX]={1,1,0};
vi sos;
void init(){
	for(int i=2;i*i<=MAX;i++)if(!sosu[i])
	for(int j=i*2;j<MAX;j+=i)sosu[j]=true;
	rep(i,MAX)if(sosu[i]==0)sos.pb(i);
}
int main(){
	init();
	vi dp(100010);
	rep(i,100010)if(i%2&&!sosu[i]&&!sosu[(i+1)/2])dp[i]=1;
	rep(i,100010-1)dp[i+1]+=dp[i];
	int q;
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<dp[b]-dp[a-1]<<endl;
	}
}











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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  for (int i = A; i <= B * A; i += A) {
    if (i % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
from collections import deque


def main():
    S = input()
    q = deque(S)
    order = 1
    Q = int(input())
    for _ in range(Q):
        X = input().split()
        if X[0] == "1":
            order = 3 - order
        else:
            f, c = int(X[1]), X[2]
            if f == order:
                q.appendleft(c)
            else:
                q.append(c)
    ans = "".join(q)
    if order == 2:
        ans = ans[::-1]
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L-R > 0) {
    cout << "Left" << endl;
  }
  else if (L-R == 0) {
  	cout << "Balanced" << endl;
  }
  else if (L-R < 0) {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	long long n, sum = 0, min = 1000005, max = -1000001, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		sum += c;
		if (min > c) min = c;
		if (max < c) max = c;
	}
	cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repd2(i, s, n) for (int i = n-1; i >= (s); i--)

int main() {
    char ch;
    int sum = 0;
    stack<int> S1;
    stack<pair<int, int>> S2;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0) {
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second; S2.pop();
            }
            S2.push(mp(j, a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0) {
        ans.pb(S2.top().second);
        S2.pop();
    }
    reverse(all(ans));
    cout << sum << endl;
    cout << ans.size();

    rep(i, ans.size()) {
        cout << " ";
        cout << ans[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3176