akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//繰り返し2乗法
ll power(ll x, ll y){//繰り返し2乗法
  if(y < 0){
    return 0;
  }else if(y == 0){
    return 1LL;
  }else if(y%2 == 0){//偶数
    return power(x,y/2)*power(x,y/2);
  }else{//奇数
    return power(x,y-1)*x;
  }
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N, A, B, C; cin >> N >> A >> B >> C;
  vector<ll> l(N); FOR(i,N){ cin >> l[i]; }
  
  //main
  //4bit全探索
  ll ans = 1e9;
  for(int i=0; i<power(4,N); i++){//2N桁
    ll la=0, lb=0, lc=0, na=0, nb=0, nc=0;
    
    for(int j=0; j<N; j++){
      switch((i>>2*j)%4){
        case 1 : la += l[j]; na ++; break; //A
        case 2 : lb += l[j]; nb ++; break; //B
        case 3 : lc += l[j]; nc ++; break; //C
      }
    }
    if(na==0||nb==0||nc==0){//竹が無い
      continue; 
    }else{
       ans = min(ans,abs(A-la)+abs(B-lb)+abs(C-lc)+10*(na-1+nb-1+nc-1));
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include"iostream"
#include"cstdio"
#include"string"

using namespace std;

long long k;
string s;

int main()
{
	cin >> s >> k;
	for(int i = 0; i < s.length(); i++)
	{
		if(k - 1 == i)
		{
			putchar(s[i]);
			return 0;
		}
		if(s[i] == '1')
			continue;
		else
		{
			putchar(s[i]);
			return 0;
		}
	}
	return 0;
}


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

int main() {
  int a, b;
  
  cin >> a >> b;
  
  string ope;
  
  if (a > b) {
  	ope = " > ";
  } else if (a < b) {
  	ope = " < ";
  } else {
  	ope = " == ";
  }
  
  cout << "a" << ope << "b" << endl;
     
  return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<map>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 2e5+7;
int a[maxn];
char s[1000][1000];
int main()
{
    int h,w;
    cin >> h >> w;
    for(int i = 0; i < h; i ++)scanf("%s",&s[i]);
    for(int i = 0; i < h; i ++)
        printf("%s\n%s\n",s[i],s[i]);
    return 0;
}


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

int main() {
	ll h, w;
	cin >> h >> w;
	ll bc = 0;
	vector<vector<int>>s(h+2, vector<int>(w+2));
	for (int i = 0; i < h+2; i++) {
		if (i == 0 || i == h + 1) {
			for (int j = 0; j < w + 2; j++)s.at(i).at(j) = -1;
		}
		else {
			for (int j = 0; j < w + 2; j++) {
				if (j == 0 || j == w + 1)s.at(i).at(j) = -1;
				else {
					char x;
					cin >> x;
					if (x == '#') {
						s.at(i).at(j) = -1;
						bc++;
					}
					else s.at(i).at(j) = 100000;
				}
			}
		}
		
	}
	s.at(1).at(1) = 0;
	//多分bfs
	queue<pair<int,int>>search;
	search.push({ 1,1 });
	while (search.size() > 0) {
		pair<int,int> a = search.front();
		if (s.at(a.first - 1).at(a.second) > s.at(a.first).at(a.second) + 1) {
			s.at(a.first - 1).at(a.second) = s.at(a.first).at(a.second) + 1;
			search.push({ a.first - 1,a.second });
		}
		if (s.at(a.first + 1).at(a.second) > s.at(a.first).at(a.second) + 1) {
			s.at(a.first + 1).at(a.second) = s.at(a.first).at(a.second) + 1;
			search.push({ a.first + 1,a.second });
		}
		if (s.at(a.first).at(a.second - 1) > s.at(a.first).at(a.second) + 1) {
			s.at(a.first).at(a.second - 1) = s.at(a.first).at(a.second) + 1;
			search.push({ a.first,a.second - 1});
		}
		if (s.at(a.first).at(a.second + 1) > s.at(a.first).at(a.second) + 1) {
			s.at(a.first).at(a.second + 1) = s.at(a.first).at(a.second) + 1;
			search.push({ a.first,a.second + 1});
		}
		search.pop();
	}
	if (s.at(h).at(w) == 100000) {
		cout << -1 << endl;
		return 0;
	}
	ll ans = h * w - s.at(h).at(w) - bc - 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
x = []
for i in range(3):
    x.append(list(map(int,input().split())))
one,two,three,four = 0,0,0,0
def push(a):
    global one,two,three,four
    if a == 1:
        one = one + 1
    elif a ==2:
        two += 1
    elif a == 3:
        three += 1
    else :
        four +=1
for i in x:
    push(i[0])
    push(i[1])
if one*two*three*four ==0 or one ==3 or two ==3 or three ==3 or four ==3:
    print("NO")
else :
    print("YES")
    

Measured memory_bytes: 3064
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  s = s.replace("eraser","*");
  s = s.replace("erase","*");
  s = s.replace("dreamer","*");
  s = s.replace("dream","*");
  s = s.replace("*","");
  System.out.println(s.equals("") ? "YES":"NO");
}}

Measured memory_bytes: 28864
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    fn f(x: i64) -> i64 { if x == 1 { 14 } else { x } }

    let ans = if f(A) > f(B) { "Alice" } else if f(A) < f(B) { "Bob" } else { "Draw" };

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


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    if(n<10)
        cout << n;
    else if(n<100)
        cout << 9;
    else if(n<1000)
        cout << 9+(n-99);
    else if(n<10000)
        cout << 9+900;
    else if(n<100000)
        cout << 9+900+(n-9999);
    else if(n==100000)
        cout << 9+900+90000;
}

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


int main(){
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for(auto& a : A){
    cin >> a;
  }
  
  int ans = X + N;
  for(auto& a : A){
    ans += (D - 1)/a;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
b=[list(map(int,input().split()))for _ in range(h)]
c=[[abs(a[i][j]-b[i][j]) for j in range(w)]for i in range(h)]
dp=[[0]*(w+1)for _ in range(h+1)]
dp[0][1]=1<<12800
for i in range(1,h+1):
    for j in range(1,w+1):
        t=c[i-1][j-1]
        dp[i][j]=(dp[i][j-1]<<t)|(dp[i][j-1]>>t)|(dp[i-1][j]<<t)|(dp[i-1][j]>>t)
ans=10**20
for i in range(25601):
    if dp[h][w]&(1<<i):
        ans=min(ans,abs(12800-i))
print(ans)


Measured memory_bytes: 26176
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    //"BC" = "D"とおく

    string tmp_s;
    cin >> tmp_s;

    ll  n = tmp_s.size();

    tmp_s += "Q";

    string s = "";

    for(int i = 0; i < n - 1; ++i)
    {
        if(tmp_s[i] == 'B' && tmp_s[i+1] == 'C')
        {
            s += "D";
            ++i;
        }
        else
        {
            s += tmp_s[i];
        }
    }

    //AD をDAに変換する
    //ADD -> DDA
    
    //AAAD -> AADA -> ADAA -> DAAA 
    //cout << s << endl;

    ll res = 0;
    ll ren = 0;
    int tmp,j;
    n = s.size();
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'A')++ren;
        else if(s[i] == 'D' && ren > 0)
        {
            res += ren;
        }
        else
        {
            ren = 0;
        }
    }

    //cout << s << endl;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 776
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
cnt = 0
for i in range(n):
    if x - a[i] < 0:
        break
    elif x - a[i] == 0:
        x -= a[i]
        cnt += 1
    else:
        if i+1 == n:
            break
        else:
            x -= a[i]
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto p = readLongs().map!"a-1".array();
    long ans;
    foreach(i; iota(n-1)) {
        if(p[i] == i) {
            p[i] = -1;
            p[i+1] = -1;
            ++ans;
        }
    }
    if(p[n-1] == n-1) {
        ++ans;
    }
    writeln(ans);
}



Measured memory_bytes: 4284
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(c) int((c).size())
#define EACH(i,c) for(auto (i)=(c).begin(); (i)!=(c).end(); ++(i))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

// repetition
#define FOR(i,m,n) for(ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define REP(i,n) FOR(i,0,n)

// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl

//constant
const double    EPS     = 1e-10;
const int       INFTY   = (1<<21);

//clear memory
#define CLR(a) memset((a),0,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << " " << __FILE__ << endl

ll solve(const vector<ll>& a, ll x) {
    ll ret = 0;
    ll l = 0, r = 0;
    ll sum = 0;
    while(l < SZ(a)) {
        while(r < SZ(a)) {
            if (sum + a[r] > x) break;
            sum += a[r];
            r++;
        }
        ret += r - l;
        sum -= a[l];
        l++;
    }
    return ret;
}

int main() {
    int n, q; cin >> n >> q;
    vector<ll> a;
    REP(i, n) {
        ll e; cin >> e;
        a.PB(e);
    }
    REP(i, q) {
        ll x; cin >> x;
        cout << solve(a, x) << endl;
    }
    return 0;
}
/*
The Number of Windows
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_C&lang=jp

しゃくとり法
[l,r]に対する何らかの条件Pを考える問題に対して使える.
* Pを満たす区間のうち最大/最小の長さを求める
* Pを満たす区間の個数を数え上げる
問題を対象とする.
条件Pは, [l,r]がPを満たすような最大のrがlの関数と見た時に広義単調関数である必要がある.

この問題では, Aiたちが正の数であるから, lを大きくすればrはそのままか大きくすることができるので, 
しゃくとり法を用いることができる.
*/


Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const lli mod = 1e9 + 7, inf = LONG_LONG_MAX;
const int maxN = 2e5; int n, k;
lli a[maxN];
vector<lli> neg, pos;
vector<double> nacc, pacc;

int main()
{
  while (scanf("%d %d", &n, &k) != EOF)
  {
    neg.clear(), pos.clear(); int zeros = 0;
    for (int i = 0; i < n; i++)
    {
      scanf("%lld", &a[i]);
      if (a[i] < 0) neg.push_back(a[i]);
      else if (a[i] == 0) zeros++;
      else pos.push_back(a[i]);
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    reverse(pos.begin(), pos.end());

    nacc.resize(neg.size() + 1);
    if (!neg.empty())
    {
      nacc[0] = 0;
      for (int i = 0; i < neg.size(); i++)
        nacc[i + 1] = nacc[i] + log10(-neg[i]);
    }
    pacc.resize(pos.size() + 1);
    if (!pos.empty())
    {
      pacc[0] = 0;
      for (int i = 0; i < pos.size(); i++)
        pacc[i + 1] = pacc[i] + log10(pos[i]);
    }

    lli hehe = 0;
    double ans = -1; int ww = 0, wi, wj;
    for (int i = 0; i <= pos.size() && i <= k; i++)
      if (!((k - i) & 1) && (k - i) <= neg.size())
      {
        double w = pacc[i] + nacc[k - i];
        if (w > ans)
          ans = w, wi = i, wj = k - i, ww = 1;
      }
    if (ww)
    {
      hehe = 1;
      for (int i = 0; i < wi; i++)
        hehe = hehe * pos[i] % mod;
      for (int j = 0; j < wj; j++)
        hehe = (hehe * neg[j] % mod + mod) % mod;
    }

    if (ans == -1 && zeros == 0)
    {
      reverse(pos.begin(), pos.end());
      reverse(neg.begin(), neg.end());
      for (int i = 0; i <= pos.size() && i <= k; i++)
        if (((k - i) & 1) && (k - i) <= neg.size())
        {
          double w = pacc[i] + nacc[k - i];
          if (w > ans)
            ans = w, wi = i, wj = k - i, ww = 1;
        }
      if (ww)
      {
        hehe = 1;
        for (int i = 0; i < wi; i++)
          hehe = hehe * pos[i] % mod;
        for (int j = 0; j < wj; j++)
          hehe = (hehe * neg[j] % mod + mod) % mod;
      }
    }

    printf("%lld\n", hehe);
  }
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    map<char, int> m;
    rep(i, s.size())
        m[s[i]]++;
    
    bool ok = true;
    ok &= m.size() == 2;

    for (auto mm: m)
    {
        ok &= mm.second == 2;
    }
    if(ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define MAX_SIZE (1000000)

// int prime[MAX_SIZE];

int main()
{
	int n;
	static int prime[MAX_SIZE];

	prime[0] = prime[1] = 0;

	for (int i = 2; i < MAX_SIZE; i++){
		prime[i] = 1;
	}

	// Sieve of Eratosthenes
	for (int i = 2; i * i < MAX_SIZE; i++){
		if (prime[i]){
			for (int j = i * i; j < MAX_SIZE; j += i){
				prime[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX_SIZE; i++){
		prime[i] += prime[i - 1];
	}

	while (scanf("%d", &n) != EOF){
		printf("%d\n", prime[n]);
	}

	return (0);
}

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

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

    string s;
    cin >> s;
    int n = s.size();

    vector<int> abc(3, 0);
    rep(i, n) ++abc[s[i] - 'a'];
    
    bool res = false;
    if(n==1) res = true;
    else if(n==2){
        if(s[0] != s[1]) res = true;
    }
    else{
        if(max({abc[0], abc[1], abc[2]}) <= min({abc[0], abc[1], abc[2]}) + 1) res = true;
    }

    if(res) puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <utility>



void fastio(){std::ios_base::sync_with_stdio(false);std::cin.tie(0);}

using std::string;using std::cin;using std::cout;using std::vector;using std::map;using std::set;using std::pair;using std::min;using std::max;

template<class T> int sz(T x){return (int)x.size();};

using ll=long long;

#define f first
#define s second

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n, 0), dp(n, 1e18);
    for(ll &i: a)cin>>i;
    dp[0]=0;
    std::function<ll(ll)> abs_=[&](ll a){return (a<0? -a: a);};
    for(int i = 1; i < n; i++){
        for(int j: {i-1, i-2}){
            if(j>=0){
                dp[i]=min(dp[i], dp[j]+abs_(a[i]-a[j]));
            }
        }
    }
    cout << dp[n-1];
    return 0;
}



Measured memory_bytes: 4776
#include <iostream>
using namespace std;
int n, x, s, m, t;
int main() {
  m = 100000000;
  t = 0;
  cin >> n >> x;
  for (int i=0; i<n; i++) {
    cin >> s;
    m = min(m,s);
    t += s;
  }
  int out;
  out = (int)((x-t)/m) + n;
  cout << out;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if (a*b<c){
	cout<<a*b<<endl;
}
	else if (a*b>c){
	cout<<c<<endl;
}
    else if (a*b==c){
    cout<<c<<endl;}
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n[3];
	int a;
	for (int i = 0; i < 3; i++) {
		scanf("%d %d %d", &n[0], &n[1], &n[2]);
	}
	for (int i = 0; i < n[1] - n[0] + 1; i++) {
		if (n[2] % (n[0] + i) == 0)
			a++;
	}
	printf("%d\n", a);
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

const int MAX_K = 5;
const int MAX_X = 10500;
const int MAX_N = 41;
const int INF = 1e+8;
int n, p[MAX_N], t[MAX_N];
int ans, get;
int dp[MAX_N][MAX_K][MAX_X];

void solve(){
	for(int i=0 ; i < MAX_N ; i++ ){
		for(int j=0 ; j < MAX_K ; j++ ){
			for(int k=0 ; k < MAX_X ; k++ ){
				dp[i][j][k] = INF;
			}
		}
	}
	
	// dp[i][k][x] := sum distance
	dp[0][0][0] = 0;
	for(int i=0 ; i < n ; i++ ){
		for(int k=0 ; k <= 3 ; k++ ){
			for(int x=0 ; x < MAX_X ; x++ ){
				if( dp[i][k][x] != INF ){
					if( k != 0 ){ // go house
						int dist = x;
						double next_time = t[i-1] + (double)dist / (1.0 / (k+1));
						
						dist += p[i];
						next_time += (double)p[i];
						//cout << "time:" << next_time << " t[i]:" << t[i] << endl;
						//cout << "dist:" << dp[i][k][x] + dist << endl;
						if( next_time <= t[i] ){
							//cout << "time:" << next_time << " t[i]:" << t[i] << endl;
							dp[i+1][1][p[i]] = min(dp[i+1][1][p[i]], dp[i][k][x] + dist );
						}
					}
					if( k != 3 ){
						int dist = abs(x - p[i]);
						double prev_time = i? t[i-1] : 0;
						double next_time = prev_time + (double)dist / (1.0 / (k+1));
						//cout << "time:" << next_time << " t[i]:" << t[i] << endl;
						if( next_time <= t[i] ){
							dp[i+1][k+1][p[i]] = min(dp[i+1][k+1][p[i]], dp[i][k][x] + dist );
						}
					}
				}
			}
		}
	}
	get = 0;
	ans = INF;
	for(int i=0 ; i <= n ; i++ ){
		for(int k=0 ; k <= 3 ; k++ ){
			for(int x=0 ; x < MAX_X ; x++ ){
				if( dp[i][k][x] != INF ){
					//cout << "i:" << i << " k:" << k << " x:" << x << " dist:" << dp[i][k][x] << endl;
					get = max(get, i);
					if( i == n ){
						ans = min(ans, dp[i][k][x] + p[i-1]);
					}
				}
			}
		}
	}
}

int main(){
	while( cin >> n , n ){
		for(int i=0; i < n ; i++ ){
			cin >> p[i] >> t[i];
		}
		ans = INF;
		solve();
		if( ans != INF ){
			cout << "OK " << ans << endl;
		}else{
			cout << "NG " << get+1 << endl;
		}
	}
}

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

using namespace std;

int main(){
  int n;
  int m;
  cin >> n >> m;
  
  vector<vector<int>> graph(n);
  for(int i = 0; i < m; i++){
    int s, t;
    cin >> s >> t;
    graph[s - 1].push_back(t - 1);
  }
  
  vector<double> e_all_open(n, 0);
  for(int i = n - 2; i >= 0; i--){
    double d = (double)graph[i].size();
    for(double e : graph[i]){
      e_all_open[i] += e_all_open[e];
    }
    e_all_open[i] /= d;
    e_all_open[i] += 1;
  }
  
  double e_min = e_all_open[0];
  
  for(int v = 0; v < n; v++){
    if(graph[v].size() <= 1){
      continue;
    }
    
    vector<double> ex(n, 0);
    
    for(int i = n - 2; i >= 0; i--){
      if(i == v){
        double d = (double)graph[i].size() - 1;
        double e_max = 0;
        for(double e : graph[i]){
          ex[i] += ex[e];
          e_max = max(ex[e], e_max);
        }
        
        ex[i] -= e_max;
        ex[i] /= d;
        ex[i] += 1;
      }else{
        double d = (double)graph[i].size();
        for(double e : graph[i]){
          ex[i] += ex[e];
        }
        ex[i] /= d;
        ex[i] += 1;
      }
    }
    e_min = min(ex[0], e_min);
  }
  
  cout << setprecision(8) << e_min << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    string ans = "";
    for(int i = 0; i < s.size(); ++i)
    {
        string temp = s;
        int flag = 1;
        for(int j = 0; j < t.size(); ++j)
        {
            if(i + j > s.size() || (s[i + j] != '?' && s[i + j] != t[j]))
            {
                flag = 0;
                break;
            }
            temp[i + j] = t[j];
        }
        if(flag)
            ans = temp;

    }
    if(ans != "")
    {
        for(int i = 0; i < ans.size(); ++i)
        {
            if(ans[i] == '?')
                ans[i] = 'a';
        }
        cout << ans << endl;
    }
    else
        cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

vector<LL> v1;

LL comb(LL b,LL c){
	LL a=1;
	for(LL i=1;i<=c;i++,b--){
		a*=b;
		a/=i;
	}
	return a;
}
	

int main(){
	LL n,m;
	LL i,j,k;
	LL p,q;
	LL a,b,c;
	long double s=0;
	cin>>n;
	cin>>p>>q;
	for(i=0;i<n;i++){
		cin>>a;
		v1.push_back(a);
	}
	sort(v1.rbegin(),v1.rend());
	a=0,b=0,c=0;
	for(i=0;i<p;i++){
		a+=v1[i];
		if(v1[i]==v1[p-1])b++,c++;
	}
	for(i=p;i<n;i++){
		if(v1[i]==v1[p-1])b++;
	}
	cout<<setprecision(10)<<fixed<<(long double)a/p<<endl;
	if(c==p){
		a=0;
		for(i=p;i<=q;i++){
			a+=comb(b,i);
		}
	}else a=comb(b,c);
	cout<<a<<endl;
		
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	int ans = 0;
	int i = 0;
	for (int j = 0; j < n; j++) {
		int y = a.at(j);
		if (y <= x) {
			x -= y;
			ans++;
		}
		else {
			cout << ans << endl;
			return 0;
		}
	}
	if (x > 0)ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[4][1000000];
ll n, w;
ll dpdp[101][1000000];
ll inf=1000000000000000;
ll dp(ll x, ll m)
{
    // cout << x << m<<" ";
    if(m<=0)
    {
        dpdp[x][m]=0;
        return 0;
    }
    if (x>=n)
    {
        dpdp[x][m]=2*inf;
        return 2*inf;
    }
    if(dpdp[x][m]!=inf)
    {

        // cout << "naklsjdf";
        return dpdp[x][m];
    }
    

    dpdp[x][m]=min(dp(x+1, m-a[1][x])+a[0][x], dp(x+1, m));
    
    // cout << dpdp[x][m]<<"\n";

    return dpdp[x][m];
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    cin >> n >> w;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[0][i]>> a[1][i];
    }
    for (int i = 0; i < 101; ++i)
    {
        for (int j = 0; j < 100001; ++j)
        {
            dpdp[i][j]=inf;
        }
    }
    ll ans=0;
    for (int i = 0; i < 100001; ++i)
    {
        if (dp(0, i)<=w)
        {
            ans=i;
        }
        // cout << dp(0, i)<<" ";
        
    }
    cout << ans<<"\n";
    
    return 0;
}


Measured memory_bytes: 294016
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
axor = 0
for ai in a:
    axor ^= ai
ans = []
for ni in range(n):
    ans.append(str(axor ^ a[ni]))
print(" ".join(ans))


Measured memory_bytes: 53916
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
using namespace std;


int main() {
	vector<pair< pair<int,int> , int> > v;
	for(int h=1;h<=150;h++){
		for(int w=1;w<150;w++){
			if(w>h){
				v.push_back( make_pair(make_pair(w*w+h*h,h),w)  );
				
			}
			
		}
	}
	sort(v.begin(),v.end());
	int h,w,t;
	while(cin>>h>>w && h){
	int i=0;
	while(v[i].first.second != h || v[i].second !=w) i++;
	cout<<v[i+1].first.second<<" "<<v[i+1].second<<endl;

	}
	
	
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b;
	cin >> a >> b;
	if(a % 2 == 0 || b % 2 == 0) No();
	else Yes();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define f first
#define s second
#define ar array
#define pb push_back
#define sz(X) ((int)(X).size())
#define pcnt __builtin_popcount
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define all(X) (X).begin(), (X).end()
#define ms(c, x)  memset(c,x,sizeof c)
#define  No(x) cout<<(x?"NO":"No")<<endl;
#define  Yes(x) cout<<(x?"YES":"Yes")<<endl;
#define  nl cout<<endl;
template<typename T>
using osl=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using osg=tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;

// for greater use greater<T>
template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out << x << " ";
    }
    out << "\n";
    return out;
}

template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out + x;
    }
    return out;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &vec) {
    for (auto &x : vec) {
        in >> x;
    }
    return in;
}

template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }

template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL

void debug() { cerr << endl; }

template<class T, class... Args>
void debug(const T &t, const Args &... args) {
    cerr << t << " ";
    debug(args...);
}

#define dbg(...) {cerr<<__LINE__<<" [[DEBUG]] ";debug(__VA_ARGS__);};
#else
#define dbg(...) void(0)
#endif
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll INF = 1e9 + 6;

ll add(ll a, ll b) {
    a += b;
    return a % mod;
}

ll mul(ll a, ll b) {
    a *= b;
    return a % mod;
}

inline ll power(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

inline ll modInverse(ll x, ll p) {
    return power(x, p - 2, p);
}

const int MXN = 1e5 + 5;
void solve() {
   int n;
   cin>>n;
   int cnt=0;
   while(n--){
       int a,b;
       cin>>a>>b;
       if(a==b){
           cnt++;
       }
       else{
           cnt=0;
       }
       if(cnt==3){
           Yes(0);
           return;
       }

   }
    No(0);
    return;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1, tc = 1;
    //cin >> t;
    while (t--) {
        // cout<<"Case #"<<tc<<": " ;
        solve();
        tc++;
    }
#ifdef LOCAL
    cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
    return 0;
}
//look if it requires ll

Measured memory_bytes: 3604
let N = Int(readLine()!)!
let h = readLine()!.split(separator: " ").map { Int($0)! }
var dp: [Int] = .init(repeating: Int.max, count: N)
dp[0] = 0
for i in 0..<N-1 {
  dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i+1] - h[i]))
  if i + 2 < N {
  	dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i+2] - h[i]))
  }
}
print(dp[N-1])

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

int main(){
	int a[400]={0};
	int i=0,n=0,s=0,d=0;
	while(cin>>a[i++]);n=i-1;
	
	for(int j=0;j<n;j+=2){
		s=a[j]+a[j+1];
		if(s!=0){d=(int)log10((double)s);d++;}
		else{d=1;}
		cout<<d<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
#include <vector>
#include <cmath>
using namespace std;
#define fi first
#define se second
#define ll long long int
int main(){
    string tar;
    cin>>tar;
    int cnt=0, ans=0;
    for (int i=0; i<tar.length(); i++){
        if (tar[i]=='R') cnt++;
        else ans=max(ans, cnt), cnt=0;
    }
    ans=max(ans, cnt);
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail==LEN) tail=1;
  else tail++;
  
  
}

P dequeue(){

  P x=Q[head];
  if(head==LEN) head=1;
  else head++;
  return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;
  for(i=1;i<=n+c;i++){
    if( Q[head].t<=q){
      elaps+=Q[head].t;
      u=dequeue();
      printf("%s %d\n",u.name,elaps);
    }
    else{
      elaps+=q;
      Q[head].t-=q;
      enqueue(Q[head]);
      dequeue();
      c++;
    }
  }
      
    
  return 0;
}

Measured memory_bytes: 12736
#include<stdio.h>
#include<ctype.h>
int num[26],a;
char ch;

main()
{
	while(scanf("%c",&ch)!=EOF){
		
		if('A'<=ch && ch<='Z'){
		a=ch-'A';num[a]++;
		}
		
		else if('a'<=ch && ch<='z'){
		a=ch-'a';num[a]++;
		}
	}
	
	for(ch='a';ch<='z';ch++){
		printf("%c : %d\n",ch,num[ch-'a']);
	}
	
	return 0;
}

Measured memory_bytes: 540
n, k = map(int, input().split())
R, S, P = map(int, input().split())
a = input()
flag = [False] * n


def win(x):
    if x == "r":
        return P
    elif x == "s":
        return R
    else:
        return S


su = 0
for i in range(n):
    if i - k >= 0 and a[i-k] == a[i] and not flag[i-k]:
        flag[i] = True
        continue
    else:
        su += win(a[i])
print(su)


Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int sum =0;
    for(int i=0; i<m; i++){
        cin >> a[i];
        sum = sum + a[i];
    }
    if( n-sum >=0 ){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}




Measured memory_bytes: 3636
n, k, q = list(map(int, input().split(' ')))
player = [0 for _ in range(n)]
for i in range(q):
    x = int(input()) -1
    player[x] += 1
for i in player:
    if k - q + i > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
# define ld long double
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int ma=1e5+5;
int arr[ma],has[ma];
int main()
{
  int n,m;
  cin>>n>>m;
  ll cor=0;
  for(int i=0;i<m;i++)
  {
    int k;
    string s;
    cin>>k>>s;
    if(has[k])
      continue;
    else
    {
      if(s[0]=='W')
        arr[k]++;
      else
      {
        cor++;
        has[k]=1;
      }
    }
  }
  ll pen=0;
  for(int i=1;i<=n;i++)
  {
    if(has[i])
      pen+=arr[i];
  }
  cout<<cor<<" "<<pen<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cstring>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <stack>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,A,B;
	scanf("%d%d%d",&N,&A,&B);
	if(B-A<0){
		printf("0\n");
		return 0;
	}
	if(N==1&&(B-A!=0)){
		printf("0\n");
		return 0;
	}
	B=B-A;
	A=0;
	long long max=(long long)(N-1)*B,min=(long long)B;
	printf("%lld\n",max-min+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int a, b;
	cin >> a >> b;
	cout << min(string(a, b + '0'), string(b, a + '0')) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

int k =VMAX;
for ( i= 0; i < n;i++){
	scanf("%d",&A[i]);
}
for ( i =0; i <= k;i++){
	C[i] = 0;
}
for ( j = 0; j< n; j++){
	C[A[j]]++;
}
for ( i = 0; i <  k ; i++){
C[i+1]+= C[i];
}
for ( j = n-1 ; j >= 0; j--){
	B[C[A[j]]] = A[j];
	C[A[j]]--;
}
for ( i = 1;i <= n;i++){
printf("%d" ,B[i]);
if ( i != n){ printf(" ");}
}
printf("\n");
  return 0;
}



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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  assert(a.size() == 32);
  int k;
  cin >> k;
  --k;
  cout << a[k] << '\n';
}


Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

const std::unordered_map<std::string, i64> table = {
  {"SUN", 7},
  {"MON", 6},
  {"TUE", 5},
  {"WED", 4},
  {"THU", 3},
  {"FRI", 2},
  {"SAT", 1}
};
int main() {
  std::string S;
  std::cin >> S;
  std::cout << table.at(S) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n, t, ans = 1e5;
    cin >> n >> t;
    pair<int, int> p[n];
    rep(i, n){
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }
    sort(p, p+n);
    if(p[0].first > t){
        cout << "TLE" << endl;
        return 0;
    }
    else{
        rep(i, n){
            if(p[i].first <= t){
                ans = min(ans, p[i].second);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
  int n,k[10000],i,j=0,pul1,pul2;

  while(1){
    
    scanf("%d",&n);
    
    if(n==0)break;

    pul1=0;
    pul2=0;
    
    for(i=0;i<n;i++)scanf("%d ",&k[i]);

    for(i=0;i<n;i++){
      if(k[i]>0)pul1++;
    }
  
    for (i=0;i<n;i++){
      if(k[i]-1>0){
      pul2=pul1+1;
      break;
      }
    }

    /* while(1){
      if(j>=n)break;
      if(k[j]>=2)pul++;
      j++;
      if(k[j]>=2)break;
     
      }*/

    if(pul2>pul1){
      printf("%d\n",pul2);
    }else{
      printf("NA\n");
    }
  }
  return 0;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	if (2*a - 1 >= a + b && 2*a - 1 >= 2*b - 1) {
		cout << 2*a - 1 << endl;
	}
	else if (a + b >= 2*a - 1 && a + b >= 2*b - 1) {
		cout << a + b << endl;
	}
	else {
		cout << 2*b - 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int nx[100][100],ny[100][100];
bool check[100][100];
bool check2[100][100];
int N;
bool loop(int x, int y){
  if(check2[x][y]){
    bool ret=true;
    REP(dx,N)REP(dy,N){
      if(check2[dx][dy]){
        if(check[dx][dy]) ret = false;
        else check[dx][dy] = true;
      }
    }
    return ret;
  }
  check2[x][y] = true;
  return loop(nx[x][y],ny[x][y]);
}
  
int main(void){
  while(cin>>N){
    if(!N) break;
    int count = 0;
    memset(check,0,sizeof(check));
    REP(y,N)
      REP(x,N)
        cin>>nx[x][y]>>ny[x][y];
    REP(y,N)
      REP(x,N)
        if(!check[x][y]){
          memset(check2,0,sizeof(check2));
          if(loop(x,y)) count++;
        }
    cout << count << endl;
  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    if(n == 7 || n == 5 || n == 3)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<string> s(n);
	for (auto &v : s) {
		cin >> v;
	}

	int ans = 0;
	for (auto str : s) {
		for (int i = 1; i < str.size(); i++) {
			ans += (str[i - 1] == 'A' && str[i] == 'B');
		}
	}

	vector<int> rightA(n);
	vector<int> leftB(n);
	vector<int> ba(n);
	for (int i = 0; i < n; i++) {
		int r = s[i].size() - 1;
		int l = 0;

		rightA[i] += (s[i][r] == 'A');
		leftB[i] += (s[i][l] == 'B');
		ba[i] += (s[i][l] == 'B' && s[i][r] == 'A');
	}

	int sumRightA = accumulate(begin(rightA), end(rightA), 0, [](int acc, int v) { return acc + v; });
	int sumLeftB = accumulate(begin(leftB), end(leftB), 0, [](int acc, int v) { return acc + v; });
	int score = min(sumRightA, sumLeftB);
	ans += score;

	// 2
	// BA
	// BA
	int sumBa = accumulate(begin(ba), end(ba), 0, [](int acc, int v) { return acc + v; });
	if (score != 0 && score == sumRightA && score == sumLeftB && score == sumBa) {
		ans--;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 896
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    l, r, d = map(int, readline().split())

    ans = 0

    for i in range(l, r + 1):
        if i % d == 0:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed 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() {
    for i in 1..100001 {
        let x:i32 = read();
        if x == 0 {
            break;
        }
        println!("Case {}: {}", i, x);
    }
}


Measured memory_bytes: 5040
import numpy as np
N=int(input())
rp=np.array([list(map(int, input().split())) for i in range(N)])
bp=np.array([list(map(int, input().split())) for i in range(N)])
rp=rp[np.argsort(rp[:, 0])]
bp=bp[np.argsort(bp[:, 0])]
rp=np.c_[rp, np.arange(N).reshape(-1, 1)]
bp=np.c_[bp, np.arange(N).reshape(-1, 1)]

counter=0
for i in range(N):
  temp=rp[rp[:, 0]<bp[i, 0], :]
  if temp.shape[0]>0:
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>0:
    temp=temp[temp[:, 2]!=-1, :]
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>0:
    temp=temp[temp[:, 1]<bp[i, 1], :]
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>1:
    temp=temp[np.argmax(temp[:, 1]), :]
    temp=temp.reshape(1, 3)
  if temp.shape[0]==1:
    counter+=1
    rp[temp[0, 2], 2]=-1
    
print(counter)

Measured memory_bytes: 12452
#include<iostream>
#include<vector>
#include<string>
#include<map>

int main(){
    int n;
    std::cin >> n;
    std::map<int, int> mp;
    for(int i = 0; i < n - 1; i++){
        int tmp;
        std::cin >> tmp;
        mp[tmp]++;
    }

    for(int i = 1; i <= n; i++){
        std::cout << mp[i] << std::endl;
    }
    
    return 0;
}


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

using namespace std;

const int maxn = 2e5 + 5;

int n,m,t[maxn],a[maxn],k;

long long ans;

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>t[i];
    sort(t,t+n);
    for(int i=1;i<n;i++)
        if((t[i] - t[i - 1]) > m){
            ans += (t[i - 1] + m - k);
            k = t[i];
        }
    ans += (t[n - 1] + m - k);
    cout<<ans;
}


Measured memory_bytes: 1024
import sys
s = list((input()))

if len(s)==2 and s[0]==s[1]:
    print(1,2)
    sys.exit()

for i in range(len(s)-2):
    si = s[i:i+3]
    if len(set(si))==2:
        print(i+1, i+3)
        break
else:
    print(-1,-1)

Measured memory_bytes: 3956
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		bool b=count(ALL(s),'7');
		if(b)
			cout<<"Yes";
		else
			cout<<"No";
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {
    int n, d;
    cin >> n >> d;
    vector<ll> x(n);
    vector<ll> y(n);
    for (int i = 0; i < n; i ++) {
        cin >> x[i] >> y[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        long double c = sqrt(x[i] * x[i] + y[i] * y[i]);
        if (c <= d)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll a,n;
        cin>>n;
ll cnt=0;
        for(int i=0;i<n;i++){
         cin>>a;
cnt+=a-1;
        }
cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256