akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int f(int n) {
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;
}

int main() {
	int s;
	cin >> s;
	set<int> a;
	bool b = true;
	int n = s, ans = 0;
	while (1) {
		ans++;
		if (a.count(n)) {
			break;
		}
		else a.insert(n);
		n = f(n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  int i,j;
  int min=0,x=0;
  cin >> S >> T;
  int Ssize=S.size(),Tsize=T.size();
  for(i=0;i<Ssize-Tsize+1;i++){
    for(j=0;j<Tsize;j++){
      if(S[i+j]!=T[j]) x++;
    }
    if(i==0) min=x;
    if(x<min) min=x;
    x=0;
  }
  cout << min << endl;
  return 0;
}


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

int main(){
  int K;
  cin >> K;
  long long ans = 0;
  for(int i = 1; i <= K; ++i){
    for(int j = 1; j <= K; ++j){
      int g = __gcd(i,j);
      for(int k = 1; k <= K; ++k){
        ans += __gcd(g,k);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double INF = 1e9;
const double EPS = 1e-9;

int main() {
	int x;
	cin >> x;
	if( x >=  30 ) {
	   cout << "Yes";
	} else {
	   cout << "No";
	}
	return 0;
}

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

int main(){
    string N = "";
    cin >> N;
    int mod = 9;
    int ans = 0;
    for (int i = 0; i < N.size(); i++){
        ans += N.at(i) - 48;
    }
    if (ans % mod == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int n,m,ans=0;
    cin >> n >> m;
    vector<int>a(n+1);
    for(int i=0,k,l;i<m;i++){
        cin >> k >> l;
        a.at(k-1)++;
        a.at(l)--;
    }
    for(int i=0,l=0;i<n;i++){
        l+=a.at(i);
        if(l==m) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    ll po[N];
    for(ll i = 0; i < N; i++) cin >> po[i];
    ll ans = 0;
    if(po[0]){
        cout << -1 << endl;
        return 0;
    }
    for(ll i = 1; i < N; i++){
        if(po[i - 1] + 1 < po[i] || i < po[i]){
            cout << -1 << endl;
            return 0;
        }else if(po[i - 1] + 1 == po[i]){
            ans++;
        }else if(po[i] <= po[i - 1]){
            ans += po[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    int count = 0;
    for(int i = a; i <= b; i++){
        int p = i/1000; 
        int q = i - (i/100*100);
        int r = q/10 + (q- q/10*10)*10;
        if(p == r){
            count++;
        } 
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll a[3];
cin >>a[0]>>a[1]>>a[2];
  ll count=0;
  for(ll i=0;i<3;i++){
  if(a[i]%2==0)
    count++;
  }
sort(a,a+3);
  ll ans=0;
  if(count==3||count==0){
  ll f=(a[2]-a[0])/2;
    ll t=(a[2]-a[1])/2;
    ans=f+t;
  }
  else if(count==1){
    for(ll i=0;i<3;i++){
  if(a[i]%2!=0)
    a[i]++;
  }
    sort(a,a+3);
      ll f=(a[2]-a[0])/2;
    ll t=(a[2]-a[1])/2;
    ans=f+t+1;
  }
  else{
      for(ll i=0;i<3;i++){
  if(a[i]%2==0)
    a[i]++;
  }
    sort(a,a+3);
      ll f=(a[2]-a[0])/2;
    ll t=(a[2]-a[1])/2;
    ans=f+t+1;
  }
  cout <<ans;
return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main()
{
  long a, b;
  cin >> a >> b;
  long r = max(a,b);
  
  int c = 0;
  while(c <= r){
    if(abs(a-c) == abs(b-c)){
      cout << c;
      return 0;
    }
    c++;
  }
  cout << "IMPOSSIBLE";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    string s;
    cin>>s;
    if(s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3628
N = int(input())

P = map(int, input().split())
P = list(P)


cnt = 0

s_1 = 0
for i in range(N):
    if P[i] != i + 1:
        if cnt == 1:
            print('NO')
            exit()

        s_1 = i

        for j in range(N):
            if P[j] == i + 1:
                s_2 = j

                v = P[s_1]
                P[s_1] = P[s_2]
                P[s_2] = v
                cnt += 1
                break
            else:
                continue

print('YES')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
  int a[n];
  double nm;
for(int i=0;i<n;i++)
{ cin>>a[i];  
 nm=nm+ 1.0/(double)a[i];}
  nm=1.0/nm;
 
    cout << fixed << setprecision(10) << nm;
  }

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

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

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

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

    for(long i = 1; i <= 1000; ++i)
    {
        if(floor(static_cast<float>(i) * 0.08) == a && floor(static_cast<float>(i) * 0.1) == b)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n;
string s;
string red, blue;
long long int res = 0LL;
map <pair <string, string>, int> M;

void go(int t){
	if(t == n){
		string help = blue;
		reverse(help.begin(), help.end());
		M[{red, help}]++;
		return;
	}
	
	red.push_back(s[t]);
	go(t + 1);
	red.pop_back();

	blue.push_back(s[t]);
	go(t + 1);
	blue.pop_back();
}

void go2(int t){
	if(t == n + n){
		string help = blue;
		reverse(help.begin(), help.end());
		
		res += M[{help, red}];
		return;
	}
	
	red.push_back(s[t]);
	go2(t + 1);
	red.pop_back();

	blue.push_back(s[t]);
	go2(t + 1);
	blue.pop_back();
}

int main(){
	cin >> n;
	cin >> s;
	go(0);
	go2(n);
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 84352
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

int main()
{
	ll n,k,r,s,p,ans=0;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	vector<char> c(n);
	vll v(100001,0);
	rep(i,SIZE(t)){
		if(i+k<SIZE(t) && t[i]==t[i+k] && t[i]!='x'){
			t[i+k]='x';
		}
	}
	rep(i,SIZE(t)){
		if(t[i]=='r') ans+=p;
		else if(t[i]=='s') ans+=r;
		else if(t[i]=='p') ans+=s;
	}
	//cout << t << endl;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    while (cin >> n >> m && n){
        vector<P> a(n);
        REP(i,n){
            int d, p;
            scanf("%d %d", &d, &p);
            a[i] = make_pair(-p, d);
        }
        sort(a.begin(),a.end());
        int ans = 0;
        REP(i,n){
            if (m > a[i].second){
                m -= a[i].second;
            }else{
                a[i].second -= m;
                m = 0;
                ans -= a[i].second*a[i].first;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char str[101];
int main() {
	int N;
	cin >> N;
	scanf("%s", str, 101);
	for (int i = 0;i < strlen(str) && i < N;i++) {
		printf("%c", str[i]);
	}
	if (N < strlen(str))
		printf("...");
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 4e2 + 10;
const ll inf = 1e16 + 10;
int n;
ll a[N], psuma[N];
ll f[N][N];


ll DP(int L, int R) {
    ll &ans = f[L][R];
    if (ans != -1) return ans;
    if (L == R) return ans = 0;
    ans = inf;
    for(int i = L; i < R; i++) 
        ans = min(ans, DP(L, i) + DP(i + 1, R));
    return ans += psuma[R] - psuma[L - 1];
}
int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) psuma[i] = psuma[i - 1] + a[i];
    memset(f, -1, sizeof(f));
    cout << DP(1, n);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 998244353;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vl a(n);
  ll A = 0;
  ll res = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    A += a[i];
    res = res * 3 % mod;
  }
  vl d(A + 1);
  vl d1(A + 1);
  d[0] = d1[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = A; j >= 0; --j) {
      if (j + a[i] <= A) {
        d[j + a[i]] = (d[j + a[i]] + d[j]) % mod;
        d1[j + a[i]] = (d1[j + a[i]] + d1[j]) % mod;
      }
      d[j] = d[j] * 2 % mod;
    }
  }
  for (int i = (A + 1) / 2; i <= A; ++i) {
    res = (res - d[i] * 3) % mod;
  }
  if (A % 2 == 0) {
    res = (res + 3 * d1[A / 2]) % mod;
  }
  cout << (res % mod + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int dp[3010][3010];

int main(){
  string s, t, ans="";
  cin >> s >> t;

  for(int i=0;i<s.length();i++){
    for(int j=0;j<t.length();j++){
      if(s[i]==t[j])dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1);
      dp[i+1][j+1]=max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  int i=s.length(), j=t.length();
  while(i+j){
    int x=dp[i][j];
    if(i&&dp[i-1][j]==x)
      i--;
    else if(j&&dp[i][j-1]==x)
      j--;
    else {
      i--;
      j--;
      ans+=s[i];
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);

    rep(i, N) cin >> x[i] >> y[i];

    double ans = 0;
    rep(i, N)
    {
        double sum = 0;
        rep(j, N)
        {
            double x_diff = (x[i] - x[j]) * (x[i] - x[j]);
            double y_diff = (y[i] - y[j]) * (y[i] - y[j]);

            sum += sqrt(x_diff + y_diff);
        }
        ans += sum / N;
    }

    printf("%.8lf\n", ans);
}

Measured memory_bytes: 384
#include<stdio.h>


int main()
{
int a,b,k;

  scanf("%d%d%d",&a,&b,&k);

  int min;
  int ar[1000];
  int t=0;
  if(a<=b)
    min=a;

  else
    min=b;

  for(int i=1;i<=min;i++){
  if(a%i==0&&b%i==0){
    ar[t]=i;
    t++;
  }

  }
  printf("%d",ar[t-k]);



return 0;
}


Measured memory_bytes: 128
S = str(input().strip())
w = int(input().strip())

a,b = divmod(len(S),w)
v = []
for i in range(a):
    v.append(S[i*w:(i+1)*w])
if b > 0:
    v.append(S[(i+1)*w:])

out = ''
for l in v:
    out = out + l[0]
print(out)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

template <typename T, typename E> struct SegmentTree {
  private:
    typedef function<T(T, T)> F;
    typedef function<T(T, E)> G;
    int n;
    T identity;
    F f;
    G g;
    vector<T> dat;
    void init(int n_) {
        n = 1;
        while(n < n_)
            n *= 2;
        dat.assign(2 * n - 1, identity);
    }
    void build(int n_, vector<T> v) {
        for(int i = 0; i < n_; i++)
            dat[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--)
            dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }

  public:
    SegmentTree(int n_, F f, G g, T id, vector<T> v = vector<T>())
        : identity(id), f(f), g(g) {
        init(n_);
        if(n_ == (int)v.size()) build(n_, v);
    }
    void update(int k, E a) {
        k += n - 1;
        dat[k] = g(dat[k], a);
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b) {
        T vl = identity, vr = identity;
        for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) vl = f(vl, dat[(l++) - 1]);
            if(r & 1) vr = f(dat[(--r) - 1], vr);
        }
        return f(vl, vr);
    }
};

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

    int n, q;
    cin >> n;
    vector<int> vec(n, 0);
    string s;
    cin >> s;
    rep(i, n) vec[i] = 1 << s[i] - 'a';
    SegmentTree<int, char> segtree(n, [](int a, int b) { return a | b; },
                                   [](int a, char b) { return 1 << b - 'a'; },
                                   0, vec);

    cin >> q;
    while(q--) {
        int x;
        cin >> x;
        if(x == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            segtree.update(i, c);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << __builtin_popcount(segtree.query(l, r)) << endl;
        }
    }
}

Measured memory_bytes: 10780
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
Q=[]
for i in range(m):
    b,c=map(int,input().split())
    Q.append([b,c])

Q=sorted(Q, key=lambda x:x[1], reverse=1)
kae=0

d=[-1]*(n)
now=0
for l in Q:
    b,c=l
    if n-now<b:
        d[now:]=[c]*(n-now)
        break
    d[now:now+b]=[c]*b
    now+=b

#print(d)
ans=sum(A)
now=ans
for kae in range(1,n+1):
    now+=d[kae-1]
    now-=A[kae-1]
    ans=max(ans,now)
print(ans)
    

Measured memory_bytes: 30156
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int H, W;

struct UnionFind
{
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int _n) :n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;
        else
            return parent[i] = find(parent[i]);
    }

    void unite(int i, int j)
    {
        i = find(i);
        j = find(j);

        if (i == j) return;

        if (rank[i] == rank[j])
        {
            parent[j] = i;
            ++rank[i];
        }
        else
        {
            if (rank[i] < rank[j]) swap(i, j);
            parent[j] = i;
        }
    }

    bool is_same(int i, int j)
    {
        return find(i) == find(j);
    }
};

void connect(int th, int tw, int sh, int sw, UnionFind& uf, const vector<string> &grid)
{
    if (sh<0 or sh>=H) return;
    if (sw<0 or sw>=W) return;
    if (grid[th][tw] == '#') return;
    if (grid[sh][sw] == '#') return;
    uf.unite(W*th+tw, W*sh+sw);
}

int main()
{
    cin >> H >> W;
    int Ch, Cw, Dh, Dw;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;

    --Ch, --Cw;
    --Dh, --Dw;

    vector<string> grid(H);
    rep(i, 0, H)
        cin >> grid[i];

    UnionFind uf(H*W);

    rep(h, 0, H)
        rep(w, 0, W)
        {
            connect(h, w, h-1, w, uf, grid);
            connect(h, w, h, w-1, uf, grid);
            connect(h, w, h+1, w, uf, grid);
            connect(h, w, h, w+1, uf, grid);
        }

    // make graph
    vector<set<int>> edge(H*W, set<int>());
    rep(h, 0, H)
        rep(w, 0, W)
        {
            if (grid[h][w] == '#') continue;

            int s = uf.find(h*W+w);
            // printf("h: %d, w: %d, s: %d\n", h, w, s);

            rep(dh, -2, 3)
                rep(dw, -2, 3)
                {
                    int th = h+dh;
                    int tw = w+dw;

                    if (th<0 or th>=H) continue;
                    if (tw<0 or tw>=W) continue;
                    if (grid[th][tw] == '#') continue;

                    int t = uf.find(th*W+tw);

                    edge[s].insert(t);
                    edge[t].insert(s);
                }
        }

    // dfs
    int from = uf.find(Ch*W+Cw);
    int to = uf.find(Dh*W+Dw);

    queue<pair<int, int>> que; 
    que.emplace(from, 0);
    set<int> visited;
    while (que.size()>0)
    {
        int now, depth;
        tie(now, depth) = que.front();
        que.pop();

        if (visited.count(now)>0) continue;
        visited.insert(now);

        if (now == to)
        {
            cout << depth << endl;
            return 0;
        }

        for (auto nxt: edge[now])
            que.emplace(nxt, depth+1);
    }

    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 91016
/**
*    author:  Dooloper
*    created: 31.05.2020 20:52:28
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <functional>
#include <cassert>


using namespace std;
typedef unsigned long long ll;

int main() {
    cin.tie(0);
    int A,B;
    cin>>A>>B;
    cout<<A*B<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int x;
    cin>>x;
    cout<<(x>=30 ? "Yes" : "No");


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3572
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {
    int N,M;
    cin>>N>>M;
    N=N*(N-1)/2;
    M=M*(M-1)/2;
    cout << N+M << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
    int X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

int n;
ll A[1000005],h[1000005],bit[1000005];
void upd(int idx,ll val)
{
    for(int i=idx;i<=n;i+=(i&-i))
    {
        bit[i]=max(bit[i],val);
    }
}
ll query(int idx)
{
    ll res=0;
    for(int i=idx;i;i-=(i&-i))
    {
        res=max(res,bit[i]);
    }
    return res;
}
int main()
{
    int t=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
    }
    ll mx=0;
    for(int i=1;i<=n;i++)
    {
        ll cur=query(h[i]);
        ll ans=cur+A[i];
        mx=max(mx,ans);
        upd(h[i],ans);
    }
    cout<<mx<<"\n";   
    return 0;
}

Measured memory_bytes: 9984
x1, y1, x2, y2 = map(int,input().split())
vec_x = y1 - y2
vex_y = x2 - x1
ans = list(map(str, [x2+vec_x, y2+vex_y, x1+vec_x, y1+vex_y]))
print(" ".join(ans))

Measured memory_bytes: 2940
#include <stdio.h>
#include <limits.h>
#include <string.h>

int main(void)
{
	char s1[102];
	char s2[102];
	scanf("%s%s", s1,s2);
	if (strlen(s1) == strlen(s2))
	{
		if (strcmp(s1,s2) > 0)
			printf("GREATER\n");
		else if (strcmp(s1,s2) < 0)
			printf("LESS\n"); 
		else if (strcmp(s1, s2) == 0)
			printf("EQUAL\n");
	}
	else if (strlen(s1) > strlen(s2))
		printf("GREATER\n");
	else
		printf("LESS\n");
	return (0);
}


Measured memory_bytes: 128
from collections import defaultdict


def submit():
    n, m = map(int, input().split())
    a = [int(e) for e in input().split()]
    
    # mod mを適用
    a_mod = [e % m for e in a]
    s_mod = []
    prev = 0
    for am in a_mod:
        prev += am
        prev %= m
        s_mod.append(prev)
    
    mod_cnt = defaultdict(int)
    mod_cnt[0] = 1
    ans = 0
    for s in s_mod:
        ans += mod_cnt[s]
        mod_cnt[s] += 1

    print(ans)


submit()
    

Measured memory_bytes: 17360
n, k = map(int, input().split())

if k == 0:
    print(n ** 2)
    exit()

result = 0
for b in range(k + 1, n + 1):
    x = (n // b) * (b - k)
    y =  n % b - k + 1
    if y > 0:
        result += x + y
    else:
        result += x

print(result)

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

int main(){

    int A, B;

    cin >> A >> B;
    
    if(1 <= A && A <=9 && 1 <= B && B <=9){
        cout << A*B << endl;
    }else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
char s[65536],t[65536];
int main(n,i,r,w,c)
{
	for(;scanf("%d",&n),n;puts(s))
		for(i=!scanf("%s",s);i++<n;t[w]=0,strcpy(s,t))
			for(r=w=0;r<strlen(s);t[w++]=s[r],r+=c){
				for(c=0;s[r+c]==s[r];++c);
				for(sprintf(t+w,"%d\0",c);t[++w];);
			}
	exit(0);
}

Measured memory_bytes: 496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int x;
		for (int i = 1;; i++) {
			x = sc.nextInt();
			if (x != 0) {

				System.out.println("Case " + i + ": " + x);
			} else {
				break;

			}

		}

	}

}


Measured memory_bytes: 41024
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = []
for i in range(b[0], b[len(b)-1] + 1):
    d = 0
    for j in range(len(b)):
        d += (b[j] - i)**2
    c.append(d)
c.sort()
print(c[0])


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
   int a,b,c,i,count = 0;
   scanf("%d %d %d",&a,&b,&c);
   i = a;
   for(i;i<=b;i++){
        if(c%i==0){
            count++;
        }
   }
   printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1844
mod = 1000003
fa = [1] * (2 * mod + 1)
fi = [1] * (2 * mod + 1)
for i in range(1, 2 * mod + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
q = int(input())
for _ in range(q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, mod))
        continue
    if x == 0 or n >= mod:
        print(0)
        continue
    x *= pow(d, mod - 2, mod)
    x %= mod
    ans = (fa[x + n - 1] * fi[x - 1] % mod) * pow(d, n, mod)
    ans %= mod
    print(ans)


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

int main(){
  int n;
  cin>>n;
  while(true){
    int log=n;
    int a=log%10;
    log/=10;
    int b=log%10;
    log/=10;
    int c =log;
    if(a==b && b==c) break;
    else n++;
  }
  cout<<n<<endl;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	long[] ds = rlong(n);
	
	long s = ds.sum;
	long t = ds.map!(x => x * x).sum;
	long ans = (s * s - t) / 2;
	
	ans.writeln;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; } // n <= 60
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = SZ(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}


void solve() {
    int n, k;
    cin >> n >> k;
    
    string str;
    cin >> str;
    
    auto v = runlength(str);
    
    
    if (SZ(v) == 1) {
        out(v[0].S);
        return;
    } else if (SZ(v) == 2) {
        out(v[0].S + v[1].S);
        return;
    }
    
    
    if (v[0].F == '0') v.insert(v.begin(), {'1', 0});
    if (v[SZ(v) - 1].F == '0') v.eb(pii{'1', 0});
    // outp(v, SZ(v));
    
    
    
    vector<int> a, b;
    a.eb(0);
    b.eb(0);
    for (int i = 0; i < SZ(v); i += 2) a.eb(a.back() + v[i].S);
    for (int i = 1; i < SZ(v); i += 2) b.eb(b.back() + v[i].S);
    // outa(a, SZ(a));
    // outa(b, SZ(b));
    
    int ans = 0;
    rep(i, SZ(a) + 1) {
        
        int tmp = a[min(SZ(a) - 1, k + 1 + i)] - a[i];
        tmp += b[min(SZ(b) - 1, k + i)] - b[i];
        chmax(ans, tmp);
        
        if (k + 1 + i >= SZ(a)) break;
    }
    
    out(ans);
}


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



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

using namespace std;

int n, a[3][3];
bool b[3][3];

bool f(){
	for(int i = 0; i < 3; ++i) if(b[i][0]&&b[i][1]&&b[i][2]) return true;
	for(int j = 0; j < 3; ++j) if(b[0][j]&&b[1][j]&&b[2][j]) return true;
	if(b[0][0]&&b[1][1]&&b[2][2]) return true;
	if(b[0][2]&&b[1][1]&&b[2][0]) return true;
	return false;
}

int main(){
	for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) cin >> a[i][j];
	cin >> n;
	int x;
	for(int i = 0; i < n; ++i){
		cin >> x;
		for(int j = 0; j < 3; ++j) for(int k = 0; k < 3; ++k) if(a[j][k]==x) b[j][k] = true;
	}
	cout << (f()?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    vi p(n);
    forn(i, n) {
        cin >> p[i];
        p[i]--;
    }
    vi a(n), b(n);
    forn(i, n) {
        a[i] = i + 1;
        b[i] = n - i;
    }
    vi used(n);
    forn(i, n) {
        int add = n - i;
        for (int j = 0; j < p[i]; j++) {
            b[j] += add;
        }
        for (int j = p[i] + 1; j < n; j++) {
            a[j] += add;
        }
    }
    forn(i, n - 1) {
        if (a[i] >= a[i + 1]) {
            throw;
        }
        if (b[i] <= b[i + 1]) {
            throw;
        }
        if (a[p[i]] + b[p[i]] >= a[p[i + 1]] + b[p[i + 1]]) {
            throw;
        }
    }
    forn(i, n) cout << a[i] << " ";
    cout << endl;
    forn(i, n) cout << b[i] << " ";
    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main() {
	int n;
	int a[100];
	int ans = 1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				ans =  0;
			}
		}
	}
	if (ans == 1) {
		printf("APPROVED");
	}
	else {
		printf("DENIED");
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long

int main(){
	int money;
	cin>>money;
	int y=money/100,m=money%100;
	if(y*5>=m) put(1);
	else put(0);
	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

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

    }
    return 0;
}

Measured memory_bytes: 3632
from operator import itemgetter
import heapq
def prim_heap():
  used=[True]*n
  edgelist=[]
  for e in edge[0]:
    heapq.heappush(edgelist,e)
  used[0] = False
  res = 0
  while len(edgelist) != 0:
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]:
      continue
    v = minedge[1]
    used[v] = False
    for e in edge[v]:
      if used[e[1]]:
        heapq.heappush(edgelist,e)
    res += minedge[0]
  return res

import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
edge=[[] for i in range(n)]
l.sort()
for i in range(n):
  l[i]=[l[i][0],l[i][1],i]
for i in range(n-1):
  edge[i].append((min(abs(l[i][0]-l[i+1][0]),abs(l[i][1]-l[i+1][1])),i+1))
  edge[i+1].append((min(abs(l[i][0]-l[i+1][0]),abs(l[i][1]-l[i+1][1])),i))
l=sorted(l,key=itemgetter(1))
for i in range(n-1):
  edge[l[i][2]].append((min(abs(l[i][0]-l[i+1][0]),abs(l[i][1]-l[i+1][1])),l[i+1][2]))
  edge[l[i+1][2]].append((min(abs(l[i][0]-l[i+1][0]),abs(l[i][1]-l[i+1][1])),l[i][2]))
print(prim_heap())

Measured memory_bytes: 126044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

vector<pair<int,int>> v;

int main(){
    ll N;//(h<=n<=w)
    cin >> N;

    for(int h=1;h < 3501;h++)
    {
        if(4*h<N){
            continue;
        }

        for(int n=h;n < 3501;n++)
        {
            if(4*h*n>=n*N+N*h){
                v.push_back(make_pair(h,n));
            }
        }
    }

    for(int i=0;i < v.size();i++)
    {
        for(int w=v.at(i).se;w<3501;w++)
        {
            if(w*((ll)4*v.at(i).fi*v.at(i).se-(ll)N*(v.at(i).fi+v.at(i).se))==(ll)N*v.at(i).fi*v.at(i).se){
                cout << v.at(i).fi << " " << v.at(i).se << " " << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 67936
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    tot = sum(T)
    for i in range(M):
        print(tot-T[P[i]-1]+X[i])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]"
    X = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        P[i] = int(next(tokens))
        X[i] = int(next(tokens))
    solve(N, T, M, P, X)


if __name__ == '__main__':
    main()


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

bool f(int num){
  if(num<2) return false;
  else if(num==2) return true;
  else if(num%2==0) return false;

  double ca=sqrt(num);
  for(int i=3;i<=ca;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int x;
  cin >> x;
  bool ha=false;
  int ans=x;
  while(ha==false){
    ha=f(x);
    ans=x;
    x++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = [0]*M
for i in range(M):
    s = list(map(int, input().split()))
    for j in s[1:]:
        S[i] += 2**(j-1)
p = list(map(int, input().split()))
ans = 0
for b in range(2**N):
    tmp = True
    for i, s in enumerate(S):
        tmp &= bin(b&s).count('1')%2==p[i]
    if tmp:
        ans += 1
print(ans)

Measured memory_bytes: 9140
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)

PQ = [(p, 0) for p in P[:X]] + [(q, 1) for q in Q[:Y]]
PQ = sorted(PQ)

y = 0
for v, t in PQ:
    y += v

ans = y
r = 0
n = [X, Y]
for v, t in PQ:
    if n[t]==0: continue
    if r<C and v<R[r]:
       y += R[r]-v
       n[t] -= 1
       ans = max(ans, y)
       r += 1
       
print(ans)

Measured memory_bytes: 30368
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

class Parsing{
public:
  string parse;
  int pos,size,x;
  Parsing(string p,int x):parse(p),x(x),size(0),pos(0){}
  int readNum(){
    int ret = 0;
    while(isdigit(parse[pos])){
      ret*=10;
      ret+=parse[pos++]-'0';
    }
    return ret;
  }
  string decode(){
    int n = readNum();
    if(parse[pos]=='(') ++pos;
    else{
      string mes="",ret="";
      while(isalpha(parse[pos])) mes+=parse[pos++];
      for(int i=0;i<n;++i){
	ret+=mes;
	if(ret.size()>=x) break;
      }
      return ret;
    }
    string mes="";
    while(isdigit(parse[pos]) || isalpha(parse[pos])){
      if(isdigit(parse[pos])) mes+=decode();
      else if(isalpha(parse[pos])) mes+=parse[pos++];
    }
    if(parse[pos]==')') ++pos;
    string ret="";
    for(int i=0;i<n;++i){
      ret+=mes;
      if(ret.size()>=x) break;
    }
    return ret;
  }

  string exp(){
    string ret;
    for(;pos<parse.size();){
      if(isdigit(parse[pos])) ret+=decode();
      else ret+=parse[pos++],size++;
      if(ret.size()>=x) break;
    }
    return ret;
  }
};

int main(){
  string s;
  int p;
  while(true){
    cin >> s >> p;
    if(s=="0") break;
    Parsing par = Parsing(s,p+1);
    string mes = par.exp();
    //    cout << mes << endl;
    if(mes.size() <= p) cout << 0 << endl;
    else cout << mes[p] << endl;
  }
  return 0;
}

Measured memory_bytes: 6096
#include <iostream>
#include <string>
#include <math.h> 
#include <algorithm>
using namespace std;

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

// 最小公倍数
long lcm(long a, long b)
{
   return a * b / gcd(a, b);
}

int main() {
  long A, B;
  cin >> A >> B;
  
  
  cout << lcm(A, B)<< endl;
  return 0;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    int ans = 0;

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
set<ll>st;
ll n,k,cnt;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	st.insert(n);
	cout<<min(n%k,k-n%k);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	cout << max(0, a - b * 2) << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(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;
}

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	string s,t; cin>>s>>t;
	int a,b; cin>>a>>b;
	string u; cin>>u;
	if(s==u) a--;
	else b--;
	printf("%d %d\n",a,b);
}


Measured memory_bytes: 256