akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, s, e) for (ll i = s; i < e; i++)
#define Forr(i, s, e) for (ll i = s; i > e; i--)
#define pb push_back
#define ll long long
#define int ll
#define mp make_pair
#define infi 1e12
const ll mod = 1e9 + 7;
ll r, c;
class point
{
public:
    ll x;
    ll y;
    ll d;
    point(int a, int b, int c)
    {
        x = a;
        y = b;
        d = c;
    }
};
bool operator<(const point &p1, const point &p2)
{
    return p1.d > p2.d;
}
bool operator>(const point &p1, const point &p2)
{
    return p1.d < p2.d;
}
bool isvalid(ll i, ll j)
{
    if (i < 0)
        return 0;
    if (i >= r)
        return 0;
    if (j < 0)
        return 0;
    if (j >= c)
        return 0;
    return 1;
};
signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(8);

    ll ii, ij, fi, fj;
    cin >> r >> c >> ii >> ij >> fi >> fj;
    string gd[r];
    For(i, 0, r) cin >> gd[i];
    vector<vector<ll>> res(r, vector<ll>(c, mod));
    vector<vector<bool>> tvd(r, vector<bool>(c, 0));
    ll count = 0;
    priority_queue<point> Q;
    point ini(ii - 1, ij - 1, 0);
    Q.push(ini);
    while (!Q.empty())
    {
        point c = Q.top();
        Q.pop();
        if (tvd[c.x][c.y] == 0)
        {
            tvd[c.x][c.y] = 1;
            For(i, c.x - 2, c.x + 3)
            {
                For(j, c.y - 2, c.y + 3)
                {
                    if (isvalid(i, j))
                    {
                        if (i == c.x && j == c.y)
                            continue;
                        else if (abs(c.x - i) + abs(c.y - j) == 1)
                        {

                            if (gd[i][j] == '.')
                            {
                                res[i][j] = min(c.d, res[i][j]);
                                point pttt(i, j, c.d);
                                Q.push(pttt);
                            }
                        }
                        else
                        {
                            if (gd[i][j] == '.')
                            {
                                res[i][j] = min(c.d + 1, res[i][j]);
                                point pttt(i, j, c.d + 1);
                                Q.push(pttt);
                            }
                        }
                    }
                }
            }
            res[c.x][c.y] = min(c.d, res[c.x][c.y]);
        }
    }
    if (res[fi - 1][fj - 1] == mod)
        cout << -1 << endl;
    else
        cout << res[fi - 1][fj - 1] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const int N=6666;

ll n,k;

ll c[N][N];

ll dp[N];

ll C(ll n,ll m)

{

    if(c[n][m]) return c[n][m];

    if(m==0||n==m) return 1;

    if(m==1) return n;

    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;

}

int main()

{

    scanf("%lld%lld",&n,&k);

    int s=n-k;

    for(int i=1;i<=s;i++)

        dp[i]=C(s-1,i-1);

    for(int i=1;i<=k;i++)

    {

        if(i>n-k+1)

        {

            printf("0\n");

            continue;

        }

        ll ans=0;
if(n==k&&i==1) ans=1;
        ans=(ans+C(k-1,i-1)*dp[i-1])%mod;

        ans=(ans+C(k-1,i-1)*dp[i]%mod*2%mod)%mod;

        ans=(ans+C(k-1,i-1)*dp[i+1]%mod)%mod;

        printf("%lld\n",(ans%mod+mod)%mod);

    }

}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)

#define BR "\n"

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

  vector<vector<ll>> c(H + 1, vector<ll>(W + 1, 0));
  vector<vector<ll>> s(H + 1, vector<ll>(W + 1, 0));

  rep1(i, H) rep1(j, W) {
    cin >> c[i][j];
    s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + c[i][j];
  }

  ll l = 0, r = min(H, W) + 1, m;
  while(l + 1 < r) {
    m = (l + r) / 2;

    bool check = false;
    rep1(i, H - m + 1) {
      rep1(j, W - m + 1) {
        ll temp = 0;
        temp += s[i + m - 1][j + m - 1];
        temp -= s[i + m - 1][j - 1];
        temp -= s[i - 1][j + m - 1];
        temp += s[i - 1][j - 1];

        if (temp == 0) check = true;
        if (check) break;
      }
      if (check) break;
    }
    if (check) l = m; else r = m;
  }
  cout << l * l << BR;

  return 0;
}


Measured memory_bytes: 33676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;

int main(){
    int n, k;
    cin >> n >> k;
    set<int> memo;
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            memo.insert(a);
        }
    }
    cout << n - memo.size() << endl;
}

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

int main()
{
    int a=0, b=0, c=0;
    cin >> a >> b >> c;
    if((a==b && b!=c)||(a==c && a!=b)||(c==b && b!=a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] arrayA = new int[b];
		int[] arrayB = new int[a];
		String amozi = "";
		String bmozi = "";


		for(int i=0;i<b;i++) {
			arrayA[i] = a;
			amozi = amozi + String.valueOf(arrayA[i]);

		}

		for(int i=0;i<a;i++) {
			arrayB[i] = b;
			bmozi = bmozi + String.valueOf(arrayB[i]);
		}

		System.out.println(arrayA[0]>=arrayB[0]?bmozi:amozi);

		scan.close();

	}

}


Measured memory_bytes: 23764
from collections import deque

s = input()
q = int(input())
isInversed = False
front = deque()
back = deque()
for _ in range(q):
    inp =  list(input().split())
    if inp[0] == '1':
        isInversed = not isInversed
    else:
        if inp[1] == '1':
            if not isInversed:
                front.appendleft(inp[2])
            else:
                back.append(inp[2])
        else:
            if not isInversed:
                back.append(inp[2])
            else:
                front.appendleft(inp[2])

front_str = ''.join(front)
back_str = ''.join(back)
ans = front_str + s + back_str

if not isInversed:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl; 
#endif
#define MAXVAL 1000005
using namespace std;
typedef long long int lli;

lli mp[MAXVAL];
bool does_not_divide(lli ele){
	for(lli i=2; i*i<=ele; ++i){
		if(ele%i == 0){
			if(mp[ele/i] != 0 || mp[i] != 0){
				return false;
			}
		}
	}
	return mp[ele] == 1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(mp, 0, sizeof(mp));
	lli n, x;
	cin>>n;
	vector<lli> v;
	for(int i=0; i<n; ++i){
		cin>>x;
		v.push_back(x);
		mp[x]++;
	}
	if(n == 1){
		cout<<1<<endl;
		return 0;
	}
	int cnt = 0;
	if(mp[1LL] == 0){
		for(int i=0; i<n; ++i){
			bool res = does_not_divide(v[i]);
			cnt += res;
		}
	}
	else if(mp[1LL] == 1){
		cnt++;
	}
	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 13144
#include<bits/stdc++.h>
#include <regex>
#include<ext/numeric>
#include<ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v)  (int)v.size()
#define WHITE -1
#define GREY   0
#define BLACK  1
#define CLR(a,v) memset(a,v,sizeof a)
#define PC(x) __builtin_popcount(x)
#define MP make_pair

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
//typedef unsigned int ui;

typedef complex<double> point;
//#define X real()
//#define Y imag()
#define vec(a,b) ((b)-(a))
//#define dot(a,b) ((conj(a)*(b)).real())
#define cross(a,b) ((conj(a)*(b)).imag())
#define colliner pointOnLine

const double PI = acos(-1.0);

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

int DX[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int DY[] = { 1, 1, 0, -1, -1, -1, 0, 1 };

const int MAX = 55, MOD = 1e9 + 7, oo = (1 << 30);
const ll OO = 1ll << 60;
const double EPS = 1e-6;

int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	int cnt = 0;
	while (n--) {
		int x;
		scanf("%d", &x);
		if (x & 1)
			++cnt;
	}
	puts((cnt & 1) ? "NO" : "YES");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
const ll MOD = 1000000007;
 
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
 
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() {
    ll N,M,c,b,m,ans;
    m=0;
    cin >> N >> M;
    ans=0;
    vector<ll> vec(N);
    rep (i,N)
    {
        cin >> vec.at(i);
    }

    vector<pair<ll, ll>> cb;
    rep (i,M)
    {
        cin >> b >> c;
        cb.PB(MP(c,b));
    }
    sort(cb.rbegin(), cb.rend());
    rep(i,M)
    {
        rep(j,cb.at(i).second)
        {
            vec.push_back(cb.at(i).first);
        }
        m += cb.at(i).second;
        if (m > N)
        break;
    }
    sort(vec.rbegin(), vec.rend());
    rep(i,N)
    {
        ans += vec.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6624
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] p = Enumerable.Repeat(1, n + 1).ToArray();
        for (int i = 1; i <= n; i++)
        {
            int[] f = factors(i);
            for (int j = 0; j < f.Length; j++)
            {
                p[f[j]]++;
            }
        }
        Console.WriteLine(product(p));
    }

    static int product(int[] a)
    {
        int mod = 1000000007;
        long res = 1;
        for (int i = 0; i < a.Length; i++) res = (res * a[i]) % mod;
        return (int)res;
    }
    static int[] factors(int n)
    {
        int i = 2;
        List<int> res = new List<int>();
        while (i * i <= n)
        {
            if (n % i == 0)
            {
                res.Add(i);
                n /= i;
            }
            else
            {
                i++;
            }
        }
        if (n != 1) res.Add(n);
        return res.ToArray();
    }
}

Measured memory_bytes: 13268
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int l = Integer.parseInt(sc.next());
		List<String> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(sc.next());
		}
		String ans = list.stream().sorted().collect(Collectors.joining());
		System.out.println(ans);

	}

}


Measured memory_bytes: 29004
n = int(input())

ai = [False for _ in range(n)]

ai = [int(s) for s in input().split()]

#print(ai)

dic = {}

for i in ai:
    if(i in dic):
        dic[i] += 1
    else:
        dic[i] = 1
mx = 0
for i in dic:
    if(dic[i] < 2):
            continue
    else:
        mx += int(dic[i]*(dic[i]-1)/2)

for i in ai:
    if(dic[i] < 2):
        print(mx)
    else:
        res = mx - (dic[i]-1)
        print(int(res))

        
    

Measured memory_bytes: 27340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
    ll after = H2 * 60 + M2;
    ll before = H1 * 60 + M1;
    cout << after - before - K << endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int n, w;
int dp[105][10005];
int value[105], weight[105];

int main() {
    ios_base::sync_with_stdio(0);
    int i, j;
    cin >> n >> w;
    
    for(i=1; i<=n; i++){
        cin >> value[i] >> weight[i];
    }
    
    for(i=1; i<=n; i++){
        for(j=1;j<weight[i];j++){
            dp[i][j]=dp[i-1][j];
        }
        for(j=weight[i]; j<=w; j++){
            dp[i][j]=max(dp[i][j-weight[i]]+value[i], dp[i-1][j]);
        }
    }
    
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 7120
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for (auto& s : A) cin >> s;
  int mono, bi, tetra;
  mono = bi = tetra = 0;
  vector<int> tally(26);
  for (auto s : A) for (auto c : s) tally[c - 'a']++;
  for(int x : tally) {
    if (!x) continue;
    tetra += x / 4; x %= 4;
    bi += x / 2; x %= 2;
    mono += x;
  }
  
  bool f=false;
  if (H % 2 && W % 2){
    f = (mono == 1 && bi <= H / 2 + W / 2);
  }
  else if (H % 2){
    f = (mono == 0 && bi <= W / 2);
  }
  else if (W % 2){
    f = (mono == 0 && bi <= H / 2);
  }
  else{
    f = (mono == 0 && bi == 0);
  }
  cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,flag[100100][20],ans;
struct edge
{
    int v;
    edge *nxt;
} pool[200100],*tp=pool,*fst[100100];

void dfs(int x,int fa)
{
    for (edge *i=fst[x]; i; i=i->nxt)
        if (i->v!=fa)
            dfs(i->v,x);
    int w=0;
    repu(i,0,19)
        if (flag[x][i]>1)
            w=i+1;
    for (; flag[x][w]; ++w);
    ans=max(ans,w),++flag[fa][w];
    repu(i,w+1,19)
        if (flag[x][i])
            ++flag[fa][i];
}

int main()
{
    scanf("%d",&n);
    repu(i,1,n-1)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        *tp=(edge){v,fst[u]},fst[u]=tp++;
        *tp=(edge){u,fst[v]},fst[v]=tp++;
    }
    dfs(1,0);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 15360
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

ll mem[109][10009];
signed main(){
    ll n,w;
    pair<ll,ll> p[1009];
    scanf("%lld %lld",&n,&w);
    rep(i,n){
        scanf("%lld %lld",&p[i].first,&p[i].second);
    }
    rep(i,n+1){
        rep(j,w+1){
            if(i==0) break;
            else{
                if(j<p[i-1].second) mem[i][j]=mem[i-1][j];
                else mem[i][j]=max(mem[i-1][j],mem[i-1][j-p[i-1].second] + p[i-1].first);
            }
        }
    }
    ll res=0;
    rep(j,w+1) res = max(res,mem[n][j]);
    cout<<res<<endl;
}



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

int main()
{
    int n, count = 0; 
    cin >> n;
    vector<int> d1(n), d2(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d1[i] >> d2[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (d1[i] == d2[i])
        {
            count += 1;
        }
        else if(count < 3)
        {
            count = 0;
        }
    }
    if (count >= 3)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const long long inf = 1LL << 22;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

bool ok[26];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	rep(i, 26) {
		ok[i] = false;
	}
	rep(i, s.size()) {
		ok[s[i] - 'a'] = true;
	}
	rep(i, 26) {
		if (!ok[i]) {
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int r = 0,b = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == '0') r++;
    else b++;
  }
  cout << min(r,b)*2 << endl;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
p=list(map(int,input().split()))
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
uf=UnionFind(n)
for _ in range(m):
    x,y=map(int,input().split())
    uf.union(x,y)
ans=0
for i in range(n):
    if uf.same_check(i+1,p[i]):ans+=1
print(ans)

Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    char a;
    cin >> a;

    int ch=(int)a;
    if('a' <= ch && ch <= 'z')
    {
        cout << "a" << endl;
    }
    else if('A' <= ch && ch <= 'Z')
    {
        cout << "A" << endl;
    }
    
    return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    vector<int> ans;
    int T, D, L;
    while(true){
        int res = 0;
        cin >> T >> D >> L;
        if(T == 0) break;
        int wet = 0;
        rep(i, T){
            if(wet > 0) res++;
            int x; cin >> x;
            if(L <= x) wet = D;
            else wet--;
        }
        ans.push_back(res);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3148
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    string a,b;
    cin >> a;
    cin >> b;
    int len;
    len=b.size();
    b=b.erase(len-1);
    if(a==b){
        cout << "Yes"<< endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    A = list(map(int, input().split()))
    total = [0]*(N+1)
    wa = 0
    for i in range(N):
        wa += A[i]
        total[i+1] = wa
    res = 0
    c = Counter(total)
    for i in c.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41524
#include <iostream>
using namespace std;
int main(){
  int a1, a2, a3, a4;
  cin >> a1 >> a2 >> a3 >> a4;
  int count = 0;
  if(a1 == 1 || a2 == 1 || a3 == 1 || a4 == 1){
    count = count + 1;
  }
  if(a1 == 7 || a2 == 7 || a3 == 7 || a4 == 7){
    count = count + 1;
  }
  if(a1 == 9 || a2 == 9 || a3 == 9 || a4 == 9){
    count = count + 1;
  }
  if(a1 == 4 || a2 == 4 || a3 == 4 || a4 == 4){
    count = count + 1;
  }
  if(count == 4){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,m = li()

cnt = [0]*51

for _ in range(m):
    a,b = li()
    cnt[a] += 1
    cnt[b] += 1
    
for i in range(1,n+1):
    print(cnt[i])

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



void print(int *A, int N) {
    for (int i = 0; i < N; i++){
        if (A[i] == 1) printf("%s", "S");
        else printf("%s", "W");
    }
}

bool flag(int *A, int N, char *s) {
    bool flg;
    for (int i = 1; i < N; i++) {
        if (s[i] == 'o') A[i+1] = A[i] * A[i-1];
        else A[i+1] = -1 * A[i] * A[i-1];
    }
    
    if (s[0] == 'o') {
        if (A[0] * A[1] == A[N-1] && A[N] == A[0]){
            print(A, N);
            flg = true;
        } else {
            flg =  false; 
        }

    } else {
        if (A[0] * A[1] == -A[N-1] && A[N] == A[0]){
            print(A, N);
            flg =  true;
        } else {
            flg =  false; 
        }
    }
    return flg;
}

int main() {
    int N, A[100005];
    char s[100005];
    scanf("%d", &N);
    scanf("%s", s);

    bool flg = false;
    A[0] = A[1] = 1;
  
    flg = flag(A, N, s);
    if (flg == false) {
        A[0] = 1; A[1] = -1; flg = flag(A, N, s);
    } 
    if (flg == false) {
        A[0] = -1; A[1] = 1; flg = flag(A, N, s);
    }
    if (flg == false) {
        A[0] = A[1] = -1; flg = flag(A, N, s);  
    } 
    if (flg == false) printf("%d", -1);
    return 0;
}

Measured memory_bytes: 768
#define A 1111
a[A],b[A],c[A],d[A],p[A],i,j,x,y,z;main(){for(;scanf("%d%d%d",a,b,c)&&(*a+=*b+*c);){for(i=332;i;p[i--]=2);for(i=0,scanf("%d",p);i++<*p;scanf("%d%d%d%d",a+i,b+i,c+i,d+i));for(i=0;i++<*p;)for(j=0;j++<*p;d[j]?p[a[j]]=p[b[j]]=p[c[j]]=1:(x=p[a[j]]&1)&(y=p[b[j]]&1)?p[c[j]]=0:x&(z=p[c[j]])?p[b[j]]=0:y&z?p[a[j]]=0:0);for(i=0;i<*a;printf("%d\n",p[++i]));}exit(0);}

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

int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	int n,l;
	cin >> n >> l;
	vector<string> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	string answer = "";
	for(string c : v){
		answer += c;
	}
	cout << answer << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
ll A[300100];
int main() {
	int N;
	cin >> N;
	REP(i, N)cin >> A[i];
	ll cnt[61] = {};
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 61; ++j) {
			if ((A[i] & 1LL << j)) {
				cnt[j]++;
			}
		}
	}
	ll ans = 0;
	for (ll i = 0; i<60; ++i) {
		ans += ((cnt[i] * (N - cnt[i]) % INF)*((1LL << i) % INF));
		ans %= INF;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll P, Q, R;
    cin >> P >> Q >> R;
    print(min(P+Q, min(Q+R, P+R)));
    return 0;
}

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

int main(){
    int A,B,C,X;cin>>A>>B>>C>>X;
    int ans=0;
    rep(i,A){
        rep(j,B){
            rep(k,C){
                if(500*i+100*j+50*k==X){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

const int MAX_N = 100;
const int MAX_W = 100000;

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

	long long dp[MAX_W+1];
	for(int i = 0; i <= MAX_W; i++)
		dp[i] = 0;

	for(int i = 0; i < N; i++){
		int w,v;
		cin >> w >> v;
		for(int j = W - w; j >= 0; j--)
			dp[j+w] = max(dp[j+w], dp[j] + v);
	}

	long long ans = 0;
	for(int i = 0; i <= W; i++)
		ans = max(ans, dp[i]);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    char n[5];
    cin >> n;
    int ans=1;//yes
    for(int i=0; i<=1; i++){
        if(n[i]!=n[i+1]){
            ans=0;
        }
    }
    if(ans==0){
        ans=1;
        for(int i=1; i<=2; i++){
            if(n[i]!=n[i+1]){
                ans=0;
            }
        }
    }
    if(ans){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var w string
	fmt.Scan(&w)
	m := map[rune]int{}
	for _, v := range w {
		m[v]++
	}
	for _, v := range m {
		if v%2 == 1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
int a;
  cin >> a;
  cout << "ABC" << a <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int b[n]={};
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if (i)
        b[i]=a[i]+b[i-1];
        else
        b[i]=a[i];
    }
    int sum1=0;
    for (int i=1;i<n;i++)
    {
        sum1=sum1+(a[i]*b[i-1]);
    }
    printf("%d\n",sum1);
    return 0;
}

Measured memory_bytes: 3724
from string import ascii_lowercase
from bisect import bisect_right, bisect_left


def main():
    s = input()
    t = input()
    len_s = len(s)
    s_all = {s: [] for s in ascii_lowercase}
    for i in range(len_s):
        s_all[s[i]].append(i + 1)
    ans = 0
    if any(s_all[tt] == [] for tt in t):
        ans = -1
    else:
        s_ind = 1
        for ss in ascii_lowercase:
            s_all[ss].sort()
        for i in range(len(t)):
            next_ind = bisect_left(s_all[t[i]], s_ind)
            if next_ind == len(s_all[t[i]]):
                ans += len_s - s_ind + 1
                ans += s_all[t[i]][0]
                s_ind = s_all[t[i]][0] + 1
            else:
                ans += s_all[t[i]][next_ind] - s_ind + 1
                s_ind = s_all[t[i]][next_ind] + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int ans;
char s[100001];
int main()
{
	cin>>s;
	for(int i=1;i<=strlen(s);i++)
      if(s[i]!=s[i-1])ans++;
      cout<<ans-1<<endl;
    return 0;
 }

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

int Frog1(vector<int> input, int n, vector<int> dp){
	if(n <= 0){
		return 0;
	}
	if(dp[n] != INT_MAX){
		return dp[n];
	}
	int ans1 = INT_MAX, ans2 = INT_MAX;
	ans1 = abs(input[n]-input[n-1]) + Frog1(input, n-1, dp);
	if(n-2 >= 0){
		ans2 = abs(input[n]-input[n-2]) + Frog1(input, n-2, dp);
	}
	return dp[n] =  min(ans1, ans2);
}

int Frog1TopDown(vector<int> input, int n){
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(input[0]-input[1]) + dp[0];
	for(int i = 2; i < n; i++){
		int ans1 = abs(input[i]-input[i-1]) + dp[i-1];
		int ans2 = abs(input[i]-input[i-2]) + dp[i-2];
		dp[i] = min(ans1, ans2);
	}
	return dp[n-1];
}

int main(){

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	int n;
	cin>>n;
	vector<int> input(n);
	for(int i = 0; i < n; i++){
		cin>>input[i];
	}
	vector<int> dp(n+1);
	// memset(dp, INT_MAX, sizeof(dp));
	for(int i = 0; i <= n; i++){
		dp[i] = INT_MAX;
	}
	// cout<<Frog1(input, n-1, dp)<<endl;
	cout<<Frog1TopDown(input, n)<<endl;

	return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string s)
{
    int r = 0, b = 0;
    for (int i = 0; i < N; i++)
    {
        if (s[i] == 'R')
        {
            r++;
        }
        else
        {
            b++;
        }
    }

    if (r > b)
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string s;
    std::cin >> s;
    solve(N, s);
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from itertools import product

n = int(input())

mod = 10**9 + 7
A, G, C, T = range(1, 5)
dp = np.zeros((n+1, 5, 5, 5), dtype=np.int64)
dp[0, 0, 0, 0] = 1
for m in range(n):
    for i, j, k, l in product(range(5), range(5), range(5), range(1, 5)):
        if i == A and j == G and l == C:
            continue
        if i == A and k == G and l == C:
            continue
        if j == A and k == G and l == C:
            continue
        if j == G and k == A and l == C:
            continue
        if j == A and k == C and l == G:
            continue
        dp[m+1, j, k, l] += dp[m, i, j, k]
        dp[m, i, j, k] %= mod

res = 0
for i, j, k in product(range(1, 5), repeat=3):
    res += dp[n, i, j, k]
    res %= mod
print(res)


Measured memory_bytes: 27212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__


vector<vi> mp = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main() {
    int H, W; cin >> H >> W;
    vector<vc> G(H, vc(W));
    vector<pii> blk;
    rep(i, H) {
        rep(j, W) {
            cin >> G[i][j];
            if (G[i][j] == '#') blk.push_back(make_pair(i, j));
        }
    }

    vector<vi> route(H, vi(W, INF));
    queue<pii> q;
    for (int i = 0; i < blk.size(); i++) {
        pii bp = blk[i];
        int bx = bp.first;
        int by = bp.second;

        route[bx][by] = 0;
        for (int j = 0; j < 4; j++) {
            int nx = bx + mp[j][0];
            int ny = by + mp[j][1];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && G[nx][ny] != '#') {
                route[nx][ny] = 1;
                q.push(make_pair(nx, ny));
            }
        }
    }

    while (!q.empty()) {
        pii p = q.front(); q.pop();
        int ux = p.first, uy = p.second;
        if (G[ux][uy] == '#') continue;
        G[ux][uy] = '#';

        for (int j = 0; j < 4; j++) {
            int vx = ux + mp[j][0];
            int vy = uy + mp[j][1];

            if (vx >= 0 && vx < H && vy >= 0 && vy < W && G[vx][vy] != '#') {
                route[vx][vy] = min(route[vx][vy], route[ux][uy] + 1);
                q.push(make_pair(vx, vy));
            }
        }
    }

    int cnt = -1;
    rep(i, H) {
        rep(j, W) {
            cnt = max(cnt, route[i][j]);
        }
    }

    cout << cnt << endl;
}


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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	map<string, int> mp;
	string a[4]={"AC", "WA", "TLE", "RE"};
	for(int i=0; i<n; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(int i=0; i<4; ++i)
		cout << a[i] << " x " << mp[a[i]] << "\n";
}


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

using namespace std;

void A_Duplex_Printing(void) {

	int N;
	cin >> N;
	cout << int((N + 1) / 2);
	return;
}

void B_Bingo(void) {

	struct Num {
		int a = 0;
		bool state = false;
	};

	struct Num num[3][3];
	
	for (int loop1 = 0; loop1 < 3; loop1++) {
		for (int loop2 = 0; loop2 < 3; loop2++) {
			cin >> num[loop1][loop2].a;
		}
	}

	int N;
	cin >> N;

	int b;
	for (int loop = 0; loop < N; loop++) {
		cin >> b;
		for (int loop1 = 0; loop1 < 3; loop1++) {
			for (int loop2 = 0; loop2 < 3; loop2++) {
				if (num[loop1][loop2].a == b) {
					num[loop1][loop2].state = true;
					goto label1;
				}
			}
		}
	label1:
		continue;
	}

	for (int loop = 0; loop < 3; loop++) {
		if (num[loop][0].state && num[loop][1].state && num[loop][2].state
			|| num[0][loop].state&& num[1][loop].state&& num[2][loop].state) {
			cout << "Yes" << flush;
			return;
		}
	}
	if (num[0][0].state && num[1][1].state && num[2][2].state
		|| num[0][2].state&& num[1][1].state&& num[2][0].state) {
		cout << "Yes" << flush;
		return;
	}

	cout << "No" << flush;
	return;
}

void C_Guess_The_Number(void) {

	int N, M;
	cin >> N >> M;

	int num[3] = { -1, -1, -1 };
	int s, c;
	for (int loop = 0; loop < M; loop++) {
		cin >> s >> c;
		if (num[s - 1] == -1 || num[s - 1] == c) {
			num[s - 1] = c;
		}
		else {
			cout << -1 << flush;
			return;
		}
	}

	if (N > 1 && num[0] == 0) {
		cout << -1 << flush;
		return;
	}
	if (N > 1 && num[0] == -1) num[0] = 1;
	for (int loop = 0; loop < N; loop++) {
		cout << ((num[loop] == -1) ? 0 : num[loop]) << flush;
	}
	return;
}

void D_Friend_Suggestion(void) {

	int N, M, K;
	cin >> N >> M >> K;

	struct Human {

		vector<int> Friend;
		vector<int> Block;
	};
	vector<struct Human> human(N);
	int A, B;
	for (int loop = 0; loop < M; loop++) {
		cin >> A >> B;
		human[A].Friend.push_back(B);
		human[B].Friend.push_back(A);
	}
	int C, D;
	for (int loop = 0; loop < M; loop++) {
		cin >> C >> D;
		human[C].Block.push_back(D);
		human[D].Block.push_back(C);
	}

	return;
}

int main(void) {

	//A_Duplex_Printing();
	//B_Bingo();
	C_Guess_The_Number();
	//D_Friend_Suggestion();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int a[100003], b[100003];
int l[200003], r[200003];
int sum[100003], x[100003];
bool vis[100003];
vector<pii> g[200003];
vector<int> ans;
void dfs(int u){
    vis[u] = 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i].first, j = g[u][i].second;
        if(vis[v]) continue;
        dfs(v);
        if(sum[v] == 1){
            sum[u] ^= 1;
            sum[v] ^= 1;
            ans.push_back(j);
        }
    }
}
int main(){
    int n, m;
    scanf("%d%d", &n, &m);

    vector<int> v;
    v.push_back(0);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &a[i], &b[i]);
        v.push_back(a[i]);
    }       
    v.push_back(1e9+1);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=1;i<=m;i++){
        scanf("%d%d", &l[i], &r[i]);
        l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin() + 1;
        r[i] = upper_bound(v.begin(), v.end(), r[i]) - v.begin() + 1;
        g[l[i]].push_back(pii(r[i], i));
        g[r[i]].push_back(pii(l[i], i));
    }
    for(int i=1;i<=n;i++){
        a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
        x[a[i]] = b[i];
    }
    for(int i=1;i<=v.size();i++) sum[i] = (x[i]^x[i-1]);
    for(int i=1;i<=v.size();i++){
        if(vis[i]) continue;
        dfs(i);
        if(sum[i] == 1){
            printf("-1\n");
            return 0;
        }
    }
    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(int i=0;i<ans.size();i++) printf("%d ", ans[i]);
}

Measured memory_bytes: 20088
#include <bits/stdc++.h>
#define rep(i, n) for (int i=1; i < n + 1; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int N, K;
  cin >> N >> K;

  int kakanai = K;
  int genkai = (N - 1) * (N - 2) / 2;
  int kaku = (N * (N - 1) / 2) - K;

  if (kakanai > genkai) {
    cout << -1 << endl;
  } else {
    cout << kaku << endl;

    int now = 0, prev = 0;
    for (int i = 1; i <= N; i ++) {
      for (int j = i + 1; j <= N; j ++) {
        if (kakanai == 0 || (i + 1 == (j) && i == 1) || (prev == N && i == 2)) {
          cout << i << " " << j << endl;
        } else {
          kakanai -= 1;
          now = j;
        }
      }
      prev = now;
    }
  }
  return 0;
}


Measured memory_bytes: 256
// AOJ 0563: Walking Santa
// 2017.10.25 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

char buf[65], *p;
int getInt(void)
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

typedef struct { int x, y; } PP;
PP pp[100002]; int n;
long long ans; int xx, yy;

int xcmp(PP *a, PP *b) { return a->x - b->x; }
int ycmp(PP *a, PP *b) { return a->y - b->y; }

void calc(int x0, int y0, int yid)
{
	int i, dx;
	long long sum, d, max;
	PP *p;

	sum = 0, max = 0;
	for (p = pp, i = 0; i <= yid; i++, p++) {
		dx = x0 - p->x;	if (dx < 0) dx = -dx;
		if ((d = dx + y0 - p->y) > max) max = d;
		sum += d << 1;
	}
	for ( ; i < n; i++, p++) {
		dx = x0 - p->x; if (dx < 0) dx = -dx;
		if ((d = dx + p->y - y0) > max) max = d;
		sum += d << 1;
	}
	sum -= max;
	if (sum < ans) ans = sum, xx = x0, yy = y0;
}

int main()
{
	int w, h, i, m, x1, x2, y1, y2;
	PP *pt;

	fgets(p=buf, 64, stdin), w = getInt(), p++, h = getInt();
	fgets(p=buf, 64, stdin), n = getInt();
	for (pt = pp, i = n; i--; pt++) {
		fgets(p=buf, 64, stdin);
		pt->x = getInt(), p++, pt->y = getInt();
	}
	m = (n-1)/2;
	qsort(pp, n, sizeof(PP), xcmp), x1 = pp[m].x, x2 = pp[m+1].x;
	qsort(pp, n, sizeof(PP), ycmp), y1 = pp[m].y, y2 = pp[m+1].y;

	ans = 1LL << 62, xx = x1, yy = y1;
	calc(x1, y1, m);
	if (!(n & 1)) {
		if (x1 == x2 && y1 == y2);
		else if (x1 == x2) calc(x1, y2, m+1);
		else if (y1 == y2) calc(x2, y1, m);
		else calc(x1, y2, m+1), calc(x2, y1, m), calc(x2, y2, m+1);
	}
	printf("%lld\n%d %d\n", ans, xx, yy);
	return 0;
}

Measured memory_bytes: 3412
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){

    int n,m,l;
    cin >> n >> m >> l;
    long long int a[n][m],b[m][l],c[n][l];

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> b[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            c[i][j] = 0;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                c[i][j] += a[i][k] * b[k][j];
            }
            cout << c[i][j];
            if(j != l-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3284
#include<stdio.h>
#define max(xx,yy) (xx>yy) ? (xx) : (yy)
#define abs(zz) (zz>=0) ? (zz) : (-(zz))

int main()
{
    int n,i,j,k,high,x[110],y[110],h[110],kari,zure,ansx,ansy,ansh=-1;
	int testx,testy,testh,flag=0;
	int board[101][101]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&(x[i]),&(y[i]),&(h[i]));
		board[x[i]][y[i]]=h[i];
		if(h[i]!=0)
		{
			flag=1;
			testx=x[i];
			testy=y[i];
			testh=h[i];
		}
	}
	
	for(i=0;i<=100;i++)
	{
		for(j=0;j<=100;j++)//(i,j)が中心
		{
			if(flag)
			{
				high=testh+(abs(testx-i))+(abs(testy-j));
				for(k=0;k<n;k++)
				{
					if(h[k]!=(max((high-(abs(i-x[k]))-(abs(j-y[k]))),0)))break;
					else if(k==n-1)
					{
						ansx=i;
						ansy=j;
						ansh=high;
					}
				}
			}/*
			else
			{
				if(i!=0&&i!=100&&j!=0&&j!=100)break;
				else
				{
					high=testh+(abs(testx-i))+(abs(testy-j));
				}
			}*/
		}
	}
	int l;
	int ansi[4]={0,0,100,100};
	int ansj[4]={0,100,0,100};
	if(ansh==-1)
	{
		for(l=0;l<4;l++)
		{
			i=ansi[l];
			j=ansj[l];
			if(flag)high=testh+(abs(testx-i))+(abs(testy-j));
			else high=1;
			for(k=0;k<n;k++)
			{
				if(h[k]!=(max((high-(abs(i-x[k]))-(abs(j-y[k]))),0)))break;
				else if(k==n-1)
				{
					ansx=i;
					ansy=j;
					ansh=high;
				}
			}
		}
	}
	printf("%d %d %d",ansx,ansy,ansh);
}


Measured memory_bytes: 128
t = input()

ans = ""

if t[0] == '?':
    ans += 'D'
else:
    ans += t[0]

for i in range(1,len(t)-1):
    if t[i] == "?":
        if t[i-1 ] == "D" and t[i +1] == "D":
             ans += "P"
        else :
            ans += "D"
    else:
        ans += t[i]

if t[len(t)-1] == '?' and len(t) != 1:
    ans += 'D'
elif len(t) != 1:
    ans += t[len(t)-1]

print(ans)


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,q;
  cin >> n>>q;
  string s;
  cin >> s;
  vector<ll> a(q),b(q);
  rep(i,q){
    cin>>a.at(i)>>b.at(i);
  }
  vector<ll> rui(n+1,0);
  for(ll i=1;i<s.size();i++){
    if(s.at(i-1)=='A' &&s.at(i)=='C'){
      rui.at(i+1)=rui.at(i)+1;
    }else{
      rui.at(i+1)=rui.at(i);
    }
  }
  rep(i,q){
    cout << rui.at(b.at(i))-rui.at(a.at(i))<<endl;
  }
}
 

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n)
    {
        int cnt = 0, day = 1;
        while (day <= d)
        {
            day += a[i];
            cnt++;
        }
        x += cnt;
    }
    cout << x << '\n';
    return 0;
}


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

int go(vector<long long> v,int num){
	vector<long long> diff;
	for(int i = 0 ; i < v.size() ; i++){
		if( v[i] == -1e15 ) v[i] = num;
		if(i)diff.push_back(v[i]-v[i-1]);
		
	}
	for(int i = 0 ; i < diff.size() ; i++){
		if( ((i%2)^(diff[i]<0)) || diff[i] == 0 ){
			return false;
		}
	}
	return true;
}
int main(){
	int N;
	while(cin >> N && N){
		vector<long long> u = {0,1,2,3,4,5};
		vector<long long> h;
		for(int i = 0 ; i < N ; i++){
			string s;
			cin >> s;
			if( s == "x" ){
				h.push_back(-1e15);
			}else{
				stringstream ss(s);
				long long w;
				ss >> w;
				h.push_back(w);
				for(int j = -2 ; j <= 2 ; j++){
					u.push_back(w+j);
				}
			}
		}
		sort(u.begin(),u.end());
		u.erase(unique(u.begin(),u.end()),u.end());
		long long res = 0;
		long long val;
		for(int i = 0 ; i < u.size() ; i++){
			if( go(h,u[i]) ){
				val = u[i];
				res ++;	
			}
		}
		if( res == 1) cout << val << endl;
		else if( res == 0 ) cout << "none" << endl;
		else cout << "ambiguous" << endl;
	}
			
}

Measured memory_bytes: 1344