akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }else if(A>=6){
        cout << B/2 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
def a():
    # import math
    # import itertools
    import scipy.misc as scm

    n, p = map(int, input().split())
    A = [int(a)%2 for a in input().split()]
    odd = A.count(1)
    even = A.count(0)
    def combination(pick_from, pick_how_many):
        # return math.factorial(pick_from) / math.factorial(pick_how_many)
        # return len(list(itertools.combinations(range(pick_from), pick_how_many)))
        return scm.comb(pick_from, pick_how_many, 1)

    result = 0
    for o in range(0+p, odd+1, 2):
        for e in range(0, even+1):
            result += combination(even, e) * combination(odd, o)
    print(result)

a()


Measured memory_bytes: 15272
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define mp make_pair
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

int main(){
    FASTIO
    int n;
    cin >> n;
    int s[n];
    rep(i, 0, n)
    cin >> s[i];
    int g = s[0];
    rep(i, 1, n)
    g = __gcd(g ,s[i]);
    cout << g;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
#define X first
#define Y second
typedef long long ll; 
int arr[100005]; 
int main()
{
	// freopen("ARC093-C.in", "r", stdin); 
	int n, sum = 0; 
	scanf("%d", &n); 
	for (int i = 1; i <= n; i++)
		scanf("%d", arr + i); 
	for (int i = 1; i <= n + 1; i++)
		sum += my_abs(arr[i - 1] - arr[i]); 
	for (int i = 1; i <= n; i++)
		printf("%d\n", sum - my_abs(arr[i] - arr[i - 1]) - my_abs(arr[i] - arr[i + 1]) + my_abs(arr[i - 1] - arr[i + 1]));
	return 0; 
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    map<ll, ll> mp;
    ll ans = 0;
    for(long long i = 0; i < n; i ++){
        ll tmp;
        cin >> tmp;
        mp[tmp]++;
        ans += tmp;
    }
    ll Q; cin >> Q;

    rep(q, Q){
        ll b, c; cin >> b >> c;
        if(mp.count(b) == 0){
            cout << ans << endl;
            continue;
        }else{
            ll tmp = c - b;
            ans += ((c - b) * mp[b]);
            mp[c] += mp[b];
            mp[b] = 0;          
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 8712
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, M;

int main()
{
    cin >> N >> M;
    if (M == N)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define REP(i,a,b)	for(i=a;i<=b;i++)
#define REPr(i,b,a) for(i=b;i>=a;i--)
#define pi 3.14159265358979323846
using namespace std;

int main(){
	int l,r,d;	cin>>l>>r>>d;
	if(d==1)	cout<<(r-l+1)<<endl;
	else{
		if(l%d==0 && r%d==0)	cout<<(r-l+1)/d+1<<endl;
	else	cout<<(r-l+1)/d<<endl;
	}
	
}

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

using namespace std;

int N;

int main(){
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i< N; i++){
    cin >> h[i];
  }
  h.push_back(0);
  int count = 0;
  int i;
  for(i = 0; i < N; i++){
    if (h[i] > 0){
      while(h[i] != 0){
        h[i]--;
        i++;
      }
      i = -1;
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
n=int(input());f=["aabbc","hi..c","hi..d","g.jjd","gffee"];x=["c","d"]
if n==2:print(-1);exit()
if n==3:print("abb","a.c","ddc");exit()
if n==5:print("aabbc","hi..c","hi..d","g.jjd","gffee");exit()
if n==7:print("..abc..","..abc..","aax..aa","bbx..bb","cc.yycc","..abc..","..abc..");exit()
a=[n*["."]for _ in range(n)]
if n%2:
  for i in range(5):
    for j in range(5):a[-i-1][-j-1]=f[i][j]
  n-=5
for i in range(0,n,2):
  a[i][i],a[i][i+1]="a","a"
  a[i+1][i],a[i+1][i+1]="b","b"
if n%4==0:
  for i in range(0,n,2):
    a[n-i-2][i],a[n-i-2][i+1]=x
    a[n-i-1][i],a[n-i-1][i+1]=x
else:
  for i in range(0,n,2):
    a[i][(i+2)%n],a[i][(i+3)%n]=x
    a[i+1][(i+2)%n],a[i+1][(i+3)%n]=x
for i in a:print("".join(i))

Measured memory_bytes: 11892
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int a, b;
    cin >> a >> b;

    if (b%a == 0) cout << a+b << endl;
    else cout << b-a << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, x, n) for(int i = (x);i < (n);i ++)
#define reps(i, x, n) for(int i = (x);i <= (n);i ++)
#define lol long long
#define SUM(n) (((n)+1)*(n)/2) //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) ((a+b-1)/b) //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

int h, w;
lol cost[1005][1005];
char c[1005][1005];
priority_queue<tuple<lol, int, int>, vector<tuple<lol, int, int>>, greater<tuple<lol, int, int>>> que; // <cost, y, x>

void BFS(){
  lol y, x, sum;
  while(!que.empty()){
    tie(sum, y, x) = que.top();
    que.pop();
    
    if(cost[y][x] > sum){
      cost[y][x] = sum;
      rep(i, 0, 4){
	int ny = y + dy[i];
	int nx = x + dx[i];
	if(c[ny][nx] != '#' && cost[ny][nx] > sum && (ny <= h && 1 <= ny && nx <= w && 1 <= nx)){
	  //cost[ny][nx] = sum;
	  que.emplace(sum, ny, nx);
	}
      }
      
      for(int i = -2;i <= 2;i ++){
	for(int j = -2;j <= 2;j ++){
	  int ny = y + i, nx = x + j;
	  if((ny <= h && 1 <= ny && nx <= w && 1 <= nx)){
	    if(c[ny][nx] != '#'){
	      que.emplace(sum + 1, ny, nx);
	    }
	  }	
	}
      }
      
    }
  }
  return;
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cin >> h >> w;
  reps(i, 1, h){
    reps(j, 1, w){
      cost[i][j] = LINF;
    }
  }
  int sx, sy, gx, gy;
  cin >> sy >> sx >> gy >> gx;
  //cost[sy][sx] = 0;
  reps(i, 1, h){
    reps(j, 1, w){
      cin >> c[i][j];
    }
  }
  que.emplace(0, sy, sx);
  BFS();
  if(cost[gy][gx] == LINF){
    cout << "-1\n";
  } else {
    cout << cost[gy][gx] << '\n';
  }
  /*reps(i, 1, h){
    reps(j, 1, w){
      cout << cost[i][j] << " ";
    }
    cout << '\n';
    }*/
  return 0;
}


Measured memory_bytes: 16168
#include <stdio.h>
int main(){
	int n,m;
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0&&m==0)break;
	int mem[n],i=0,flg=0,last=0;
	for(i=0;i<n;i++)mem[i]=0;
	while(1){
		if(!mem[i]){
			flg++;
			if(flg==m){
				mem[i]=1;
				flg=0;
				last++;
				if(last==n){
					printf("%d\n",i+1);
					break;
				}
			}
		}
	i++;
	if(i==n+1)i=0;
	}
	}
return 0;
}
	

Measured memory_bytes: 600
mod = 10 ** 9 + 7
n, k = map(int, input().split())
binomial = [1]
cum = 1
for i in range(1, n + 2):
    cum *= i
    cum = cum % mod
    binomial.append(cum)
inv = []
tmp = pow(cum, mod - 2, mod)
inv.append(tmp)
for j in range(n + 1, 0, -1):
    tmp = j * tmp % mod
    inv.append(tmp)
inv.reverse()

def comb(n, k):
    return binomial[n] * inv[n - k] % mod * inv[k] % mod if n >= k else 0
k = min(k, n - 1)
ans = 0
for m in range(k + 1):
        tmp = comb(n, m) * binomial[n - 1] * inv[n - 1 - m] * inv[m]
        ans += tmp % mod
ans %= mod
print(ans)

Measured memory_bytes: 18980
n,k=map(int,input().split())
a=list(map(int,input().split()))

d=60
dp=[[-1]*n for i in range(d+1)]
for i,aa in enumerate(a):
  dp[0][i]=aa-1
for i in range(d):
  for j in range(n):
    dp[i+1][j]=dp[i][dp[i][j]]
ans=0
for i in range(d):
  if k&(1<<i):
    ans=dp[i][ans]
print(ans+1)


Measured memory_bytes: 174124
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
bool check(string s){
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'){
      for(int j=i+1;j<s.size();j++){
	if(s[j]=='B'){
	  if(j-i>1)return true;
	  break;
	}else if(s[j]=='.')break;
      }
    }
  }
  return false;
}
ll calc(string s){
  ll ret=0;
  if(check(s))return 0;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='W'){
      for(int j=i+1;j<s.size();j++){
	if(s[j]=='W'){
	  ret=max(ret,j-i-1);
	  break;
	}else if(s[j]=='.')
	  break;
      }
    }
  }
  return ret;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;string s;
  cin>>n>>s;
  ll ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='.'){
      s[i]='W';
      ans=max(ans,calc(s));
      s[i]='.';
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int mod = 998244353;
const int maxn = 250;
const double eps = 1e-7;
int n, cnt = 0, in[maxn];
bool flag[maxn][maxn] = {0};
struct points
{
	double x, y;
	points(double xx = 0, double yy = 0) : x(xx), y(yy) {}
	points operator-(const points &a) const {return points(x - a.x, y - a.y);}
	double cross(const points &a) const {return x * a.y - y * a.x;}
}p[maxn];
long long power(long long x, long long k)
{
	long long ans = 1;
	while(k)
	{
		if(k & 1)
			(ans *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return ans;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> p[i].x >> p[i].y;
	long long sum = (power(2, n) - n - 1+ mod) % mod;
	for(int i = 1; i <= n; i ++)
		for(int j = i + 1; j <= n; j ++)
			if(!flag[i][j])
			{
				cnt = 2;
				in[1] = i, in[2] = j;
				for(int k = j + 1; k <= n; k ++)
					if(abs((p[i] - p[j]).cross(p[k] - p[i])) <= eps)
						in[++ cnt] = k;
				sum = (sum - power(2, cnt) + 1 + cnt + mod) % mod;
				for(int k = 1; k <= cnt; k ++)
					for(int t = k + 1; t <= cnt; t ++)
						flag[in[k]][in[t]] = 1;
			}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
n, m = list(map(int, input().split()))

c = [tuple(map(int, input().split())) for i in range(n)]

def f(g):
    t = sorted(c, key=g)[:m]
    x = sum(map(lambda x:x[0], t))
    y = sum(map(lambda x:x[1], t))
    z = sum(map(lambda x:x[2], t))
    return abs(x) + abs(y) + abs(z)

print(max([
    f(lambda x: x[0] + x[1] + x[2]),
    f(lambda x: x[0] + x[1] - x[2]),
    f(lambda x: x[0] - x[1] + x[2]),
    f(lambda x: x[0] - x[1] - x[2]),
    f(lambda x: -x[0] + x[1] + x[2]),
    f(lambda x: -x[0] + x[1] - x[2]),
    f(lambda x: -x[0] - x[1] + x[2]),
    f(lambda x: -x[0] - x[1] - x[2]),
]))


Measured memory_bytes: 3280
def mk2d(n)
  arr = Array.new
  n.times do
    a = Array.new(10, 0)
    arr << a
  end
  arr
end
def smallInk(x, y)
  a = [[x, y],
       [x + 1, y],
       [x - 1, y],
       [x, y + 1],
       [x, y - 1]]
  a 
end
def midInk(x, y)
  arr = smallInk(x, y)
  arr << [x + 1, y + 1]
  arr << [x - 1, y + 1]
  arr << [x - 1, y - 1]
  arr << [x + 1, y - 1]
  arr
end
def largeInk(x, y)
  arr = midInk(x, y)
  arr << [x + 2, y]
  arr << [x - 2, y]
  arr << [x, y + 2]
  arr << [x, y - 2]
  arr
end
def drop(arr)
  arr.each do |i|
    x = i[0]
    y = i[1]
    if x >= 0 and x <= 9 and y >= 0 and y <=9
      $paper[i[0]][i[1]] += 1
    end
  end
end
  
#main
$paper = mk2d(10)
arr = Array.new
while line = gets
  arr << line 
end
arr.each do |i|
  a = i.split(",")
  a.map!{|j| j.to_i}
  case a[2]
    when 1
    drop(smallInk(a[0], a[1]))
    when 2
    drop(midInk(a[0], a[1]))
    when 3
    drop(largeInk(a[0], a[1]))
  end
end
empty = 0
max = 0
0.upto($paper.length - 1) do |i|
  0.upto($paper.length - 1) do |j|
    if $paper[i][j] == 0
      empty += 1
    end
    if max < $paper[i][j]
      max = $paper[i][j]
    end
  end
end
p empty
p max

Measured memory_bytes: 6116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    long long n,ans=0,x,y;
    cin>>n;
    rep(i,sqrt(n)) {
        x=n-(i+1);
        if(x%(i+1)==0&&x/(i+1)>i+1) ans+=x/(i+1);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

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


int main() {
	ll n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	vector<pair<ll, char> > v(n + m);

	
	ll lcm = m*n/gcd(n, m);
	ll lo = 0, hi = 1e8;
	bool ok = false;
	while (hi - lo > 1) {
		ll mid = lo + (hi - lo) / 2;
		for (int i = 0; i < n; i++) v[i] = { lcm*mid/n * i + 1, s[i] };
		for (int i = 0; i < m; i++) v[n + i] = { lcm*mid/m * i + 1, t[i] };
		sort(v.begin(), v.end());

		bool flag = true;
		for (int i = 0; i < n + m - 1; i++) {
			if (v[i].first == v[i + 1].first && v[i].second != v[i + 1].second) {
				lo = mid;
				flag = false;
				break;
			}
		}
		if (flag) hi = mid, ok = true;
		else lo = mid;
	}
	if (ok) cout << hi*lcm << endl;
	else cout << -1 << endl;
	return 0;
}

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

using namespace std;

const long MOD=1'000'000'007;

int main(){
    long N;
    cin>>N;
    vector<long> A(N);
    for(int i=0; i<N; ++i){
        cin>>A[i];
    }

    vector<long> dp(N, 0);
    long c1 = 0;
    long c2 = 0;
    long c3 = 0;

    if(A[0] != 0){
        cout<<0<<endl;
        return 0;
    }
    dp[0] = long(3);
    c1 += 1;
    for(int i=1; i<N; ++i){
        int cnt = 0;
        bool countup = false;
        if(A[i] == c1){
            cnt++;
            if(countup == false){
                countup = true;
                c1++;
            }
        }
        if(A[i] == c2){
            cnt++;
            if(countup == false){
                countup = true;
                c2++;
            }
        }
        if(A[i] == c3){
            cnt++;
            if(countup == false){
                countup = true;
                c3++;
            }
        }
        dp[i] = (dp[i-1] * cnt) % MOD;
    }

    cout<<dp[N-1]<<endl;

    return 0;
}









Measured memory_bytes: 1792
from math import gcd


def solve(p, q):
    GCD = gcd(p, q)
    p = p // GCD
    q = q // GCD
    print(p, q, sep="/")


s = input()
x, y = s.split('.')
if(y[-1] != ')'):
    p = int(x) * pow(10, len(y)) + int(y)
    q = pow(10, len(y))
    solve(p, q)

else:
    y, z = y.split('(')[0], y.split('(')[1][:-1]
    a = int(x+y+z)
    b = int(x+y)
    solve(a-b, (pow(10, len(z))-1)*pow(10, len(y)))



Measured memory_bytes: 5668
#include <cmath>
#include <iostream>

using namespace std;

using ll = long long;

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

  ll a = 0;
  for (ll i = 1; i < sqrt(n) + 1; ++i)
    if (n / i * i == n)
      a = i;

  ll ans = (a - 1) + (n / a - 1);
  cout << ans << endl;
}

Measured memory_bytes: 256
from operator import itemgetter

N, M = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(M)]

ab = sorted(ab, key=itemgetter(0, 1))
ans = 1
x, y = ab[0]
for i in range(1, M):
    a, b = ab[i]
    if b <= x or y <= a:
        ans += 1
        x, y = a, b
    else:
        x = max(x, a)
        y = min(y, b)
print(ans)


Measured memory_bytes: 30048
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a*b % 2 == 0) {
        std::cout << "Even" << '\n';
    }
    if (a*b % 2 == 1) {
        std::cout << "Odd" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	int cnt = 0;
	while(cnt<k) {
		if(cnt<a) ans++;
		if(cnt>=a+b)ans--;
		cnt++;
	}
	cout << ans << endl;
}

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

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    long double dist = 1ll * x * x + 1ll * y * y;
    res += dist <= 1ll * d * d;
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int  binary_search(ll key, vector<ll> &a)
{
    ll left = 0;
    ll right =a.size() - 1;
    while (right >= left)
    {
        ll mid = left + (right - left) / 2;
        if (a[mid] == key) return 1;
        else if (a[mid] > key) right = mid - 1;
        else if (a[mid] < key) left = mid + 1;
    }
  return 0;
}

int main(){
  ll ans=0;
  ll n;
  ll q;
  cin >>n;
  vector<ll> N(n);// already sorted
  rep(i,n) cin  >>N[i];
  cin >>q;
  vector<ll> Q(q);// different with each other
  rep(i,q)  cin  >>Q[i];
  for(ll x : Q)  if( binary_search( x , N )==1) ans ++;
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 3756
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int d, t[370];
ll c[26], s[370][26], last[370][26];


ll calc(){
	ll score = 0;
        REP(i, 1, d+1){
                REP(j, 0, 26){
                        if(j==t[i]-1){
                                score += s[i][j];
                                last[i][j] = i;
                        }else last[i][j] = last[i-1][j];
                        score -= c[j] * (i - last[i][j]);
                }
        }
	return score;
};

int main(){
        scanf("%d", &d);
        REP(i, 0, 26) scanf("%ld", &c[i]);
        REP(i, 1, d+1) REP(j, 0, 26) scanf("%ld", &s[i][j]);
        REP(i, 1, d+1) scanf("%d", &t[i]);
        REP(i, 0, 1+d) REP(j, 0, 26) last[i][j] = 0;

	int m;
	scanf("%d", &m);
	REP(I, 0, m){
		int st, nex;
		scanf("%d %d", &st, &nex);
		t[st] = nex;
		printf("%ld\n", calc());
//		int pre = t[st];
//		REP(i, last[st-1][pre], st){
//			score -= c[pre] * (last[i][pre] - last[st-1][pre]);
//			last[i][pre] = last[st-1][pre];
//		}
//		for(ll i=st; i<=d and st>=last[i][nex]; i++){
//			score += c[nex] * (st - last[i][nex]);
//			last[i][nex] = st;
//		}
//		printf("%ld\n", score);
	}
	return 0;
}



Measured memory_bytes: 3924
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;	cin >> s;
	if (s.size() <= 1) {
		cout << "-1 -1" << endl;
		return 0;
	}
	else if (s.size() == 2) {
		if (s[0] == s[1])	cout << "1 2" << endl;
		else	cout << "-1 -1" << endl;
		return 0;
	}
	for (int i = 2; i < s.size(); i++) {
		if (s[i] == s[i - 1] || s[i - 1] == s[i - 2] || s[i] == s[i - 2]) {
			cout << i - 1 << " " << i + 1 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

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

int main() {
    int i;
    string s, tmp, out;
    cin >> s;
    for(i = 0;i < s.size();i++) {
        if(s[i] == 'A') break;
    }
    for(;i < s.size();i++) {
        tmp += s[i];
        if(s[i] == 'Z') {
            out += tmp;
            tmp = "";
        }
    }
    cout << out.size() << endl;
}

Measured memory_bytes: 904
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace test
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N, Q;
            N = int.Parse(str[0]);
            Q = int.Parse(str[1]);
            int[] Data = new int[N + 1];
            string[] input;
            for(int a = 0; a < Q; a++)
            {
                input = Console.ReadLine().Split(' ');
                Data[int.Parse(input[0])]++;
                Data[int.Parse(input[1])]++;
            }
 
            for(int a = 0; a <= N; a++)
            {
                if(Data[a] % 2 == 1)
                {
                    Console.WriteLine("NO");
                    break;
                }
                if(a == N)
                {
                    Console.WriteLine("YES");
                    break;
                }
            }
 
        }
    }
}

Measured memory_bytes: 17324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		int ai,bi,ci,aj,bj,cj;
		ai = a;
		bi = b;
		ci = c;
		int count =0;
		while(ai%2==0&&bi%2==0&&ci%2==0){
			aj = (bi+ci)/2;
			bj = (ci+ai)/2;
			cj = (ai+bi)/2;
			ai = aj;
			bi = bj;
			ci = cj;
			if(ai==a&&bi==b&&ci==c) {
				count = -1;
				break;
			}
			count ++;
		}
		System.out.println(count);

	}

}

Measured memory_bytes: 24148
#include "bits/stdc++.h"
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];


void solve()
{
      int a, c;
      cin >> n >> a >> c;
      int a1 = n/(a+c);
      cout << a1*a + min(n-a1*(a+c), a);
      
}


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

      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 256
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
ans=0

for i in range(q):
  left=0
  right=n
  while left<right:
    mid=(left+right)//2
    if s[mid]==t[i]:
      ans+=1
      break
    elif t[i]<s[mid]:
      right=mid
    else:
      left=mid+1
print(ans)


Measured memory_bytes: 16712
def main():
    A, B = map(int, input().split())
    count = 0
    for n in range(A, B+1):
        s = str(n)
        k = len(s)
        isPalindrome = True
        for i in range(k//2):
            if s[i] != s[k-1-i]:
                isPalindrome = False
                break
        if isPalindrome:
            count += 1
    return count

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll              long long 
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=2e5+4;

int main()
{
    IOS
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        if(x>=k)
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> t(n+1, 0), x(n+1, 0), y(n+1, 0);
  rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
  rep(i, n){
    int dt = t[i+1]-t[i];
    int dx = x[i+1]-x[i];
    int dy = y[i+1]-y[i];
    if(abs(dx)+abs(dy) > dt){
      cout << "No" << "\n";
      return 0;
    }
    else if((dt - abs(dx)- abs(dy)) %2 == 1){
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";
  
}  

Measured memory_bytes: 1408
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[1005][1005]={0};
char c[1005][1005];
int main(){
	ll n,m;cin>>n>>m;
	string s[n];
	for(ll i=0;i<n;i++)cin>>s[i];
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			c[i][j]=s[i-1][j-1];
		}
	}
	for(ll j=1;j<=m;j++){
		if(c[1][j]!='#'){
			dp[1][j]=1;
		}
		else break;
	}
	for(ll i=1;i<=n;i++){
		if(c[i][1]!='#'){
			dp[i][1]=1;
		}
		else break;
	}

	for(ll i=2;i<=n;i++){
		for(ll j=2;j<=m;j++){
			if(c[i][j]!='#')
			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%hell;
			else dp[i][j]=0;
		}
	}		
	cout<<dp[n][m]<<endl;
}

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

#ifdef _WIN32
#define scanfll(x) scanf("%I64d", x)
#define printfll(x) printf("%I64d", x)
#else
#define scanfll(x) scanf("%lld", x)
#define printfll(x) printf("%lld", x)
#endif
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>;
using ld = long double;  using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
string bits_to_string(ll mask, ll n) { string s; rep(i, n) s += '0' + !!(mask & (1ll << i)); return s; }
#define ldout fixed << setprecision(40) 

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    rep(i, s.length()) {
        if (s[i] == ',') 
            s[i] = ' ';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int l, k;
  ll dp[201][2] = {};
  ll ans = 0;
  
  scanf("%d%d",&l,&k);
  
  dp[0][0] = 1;
  
  for(int i=0;i<l;i++){
    dp[i+1][1] += dp[i][0];
    dp[i+1][0] += dp[i][1];
    dp[i+k][1] += dp[i][0];

    ans += dp[i+1][1];
  }

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



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, i;
    cin >> N >> i;
    cout << (N - i + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll p;
	ll ans=0;
	if (n%1000==0)
	{
		ans=0;	
	}
	else
	{
		p=(n%1000);
		ans=1000-p;	
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3616
<?php
    // 標準入力
    $input = fgets(STDIN);

    // メイン処理
    $A = "";
    $countA = 0;
    $B = "";
    $countB = 0;

    $inputSplit = str_split($input);

    foreach ($inputSplit as $split) {
        if (empty($A)) {
            $A = $split;
        }
        if ($A == $split) {
            $countA++;
            continue;
        }
        if (empty($B)) {
            $B = $split;
        }
        if ($B == $split) {
            $countB++;
        }
    }

    if ($countA == 2 && $countB == 2) {
        echo "Yes";
    } else {
        echo "No";
    }


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

using namespace std;
using ll = long long;

//int A,B,C,D,N,M;
ll A,B,C,D,N,M,K,W;
ll dp[200][200000] = {0}; //i番目までで重さj以下のときの価値
ll v[200000];
ll w[200000];

void solve() {
  for(int i = 1; i <= N; i++) {
    for(int j = 0; j <= W; j++) {
      if( j - w[i] >= 0) {
        dp[i][j] = max( dp[i][j], dp[i-1][j-w[i]] + v[i]);  //i番目を選べる
      }
      /*else {
        dp[i][j] = max(dp[i][j], dp[i-1][j]);
        ここをelseにしてはいけない
      }*/
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }
  }
}



int main() {
  ios::sync_with_stdio(false);
  cin >> N >> W;
  for(int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
  }

  solve();
  cout << dp[N][W];


  return 0;
}


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

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 2000000001;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    int i = s.size() - 1;
    while (i > -1) {
        if (i - 4 > -1 && s[i] == 'm' && s[i - 1] == 'a' && s[i - 2] == 'e' && s[i - 3] == 'r' && s[i - 4] == 'd')
            i -= 5;
        else if (i - 4 > -1 && s[i] == 'e' && s[i - 1] == 's' && s[i - 2] == 'a' && s[i - 3] == 'r' && s[i - 4] == 'e')
            i -= 5;
        else if (i - 5 > -1 && s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 's' && s[i - 3] == 'a' &&
                 s[i - 4] == 'r' && s[i - 5] == 'e')
            i -= 6;
        else if (i - 6 > -1 && s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 'm' && s[i - 3] == 'a' &&
                 s[i - 4] == 'e' && s[i - 5] == 'r' && s[i - 6] == 'd')
            i -= 7;
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

public class Main {

	void submit() {
		int n = nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] -= nextLong();
		}
		for (int i = 0; i < n; i++) {
			a[i] += nextLong();
		}
		
		long ops = 0;
		for (long x : a) {
			ops += x;
		}
		
		if (ops < 0) {
			out.println("No");
			return;
		}
		
		long sub2 = 0;
		long add1 = 0;
		
		for (long x : a) {
			if (x <= 0) {
				add1 += -x;
			} else {
				long tmp = (x + 1) / 2;
				sub2 += tmp;
				add1 += -(x - tmp * 2);
			}
		}
		
		if (sub2 > ops || add1 > ops) {
			out.println("No");
			return;
		}
		
		sub2 = ops - sub2;
		add1 = ops - add1;
		
		if (sub2 * 2 != add1) {
			out.println("No");
			return;
		}
		
		out.println("Yes");
		
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 26068
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  int n = in();
  int m = in();
  vvector<int> light(m);
  foreach(i,light){
    i.resize(in());
    foreach(j,i)j=in()-1;
  }
  vector<int> sum(m);
  int ans = 0;
  foreach(i,sum)i=in();
  rep(i,bit(n)){
    vector<int> current(m,0);
    rep(j,m){
      foreach(k,light[j]){
        if(bit(k)&i)++current[j];
      }
    }
    ans += [&](){
             rep(i,m){
               current[i] %= 2;
               if(current[i]!=sum[i])return 0;
             }
             return 1;
           }();
  }
  cout << ans << endl;
  return 0;
}


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

int gcd(int l,int s) {
  int L,S;
  while(l%s!=0) {
    L=l;
    S=s;
    l=max(S,L%S);
    s=min(S,L%S);
  }
  return s;
}
int gcd3(int a,int b,int c) {
  b = gcd(max(a,b),min(a,b));
  return gcd(max(b,c),min(b,c));
}

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

Measured memory_bytes: 3608
n, x, y = map(int, input().split())
l = [0]*(n - 1)


for i in range(1, n):
    for j in range(i + 1, n + 1):
        ans = min(abs(y - j) + abs(x - i) + 1, abs(j - i))
        l[ans - 1] += 1

for i in l:
    print(i)

Measured memory_bytes: 3444
/**
 * @Author:      G_bg
 * @DateTime:    2019-07-20 20:00:17
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn=1e5+10;
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int r;cin >> r;
	cout << 3*r*r << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      if i*(i-1)>N:
        cd.append(i-1)
      if i != n//i and (n//i)*(n//i-1)>N:
        cd.append(n//i-1)
    i += 1
  return cd

N = int(input())
print(sum(divisor(N)))

Measured memory_bytes: 9084
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  int N;
  ll a, b;
  cin >> N;
  vector<pair<ll, ll>> jobs;
  for (int i=0; i<N; i++){
    cin >> a >> b;
    jobs.emplace_back(pair<ll, ll>(b, a));
  }
  sort(jobs.begin(), jobs.end());
  bool flag = true;
  ll limit = 0, did = 0;
  for (int i=0; i<N; i++){
    limit = jobs[i].first;
    did += jobs[i].second;
    if (limit < did){
      flag = false;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}

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

#define ll long long int

int main()
{
    ll n, m, x[1000], y[1000], z[1000];
    ll ans = 0;

    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
    }
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                ll sum[1000] = {};
                for (int l = 0; l < n; l++)
                {
                    if (i == 0)
                        sum[l] += x[l];
                    else
                        sum[l] -= x[l];
                    if (j == 0)
                        sum[l] += y[l];
                    else
                        sum[l] -= y[l];
                    if (k == 0)
                        sum[l] += z[l];
                    else
                        sum[l] -= z[l];
                }
                sort(sum, sum + n);
                reverse(sum, sum + n);
                ll su = 0;
                for (int l = 0; l < m; l++)
                {
                    su += sum[l];
                }
                ans = max(ans, su);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    titles = []
    times = []
    for i in range(N):
        title, s_time = input().split()
        time = int(s_time)
        titles.append(title)
        times.append(time)
    target = input()
    started = False
    total = 0
    for i in range(N):
        if started:
            total += times[i]
        if titles[i] == target:
            started = True

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int C = sc.nextInt();
    
    int[] A = new int[M];
    for (int i = 0; i < M; i++){
      A[i] = sc.nextInt();
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
      int s = 0;
      for (int j = 0; j < M; j++){
        int B = sc.nextInt();
        s += A[j] * B;
      }
      if (s+C > 0) ans++;
    }
    System.out.println(ans);
  }
}
    

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

vector<bool> isprime(100010, true);
vector<int> counter(100010, 0);

void set_prime() {
    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i < 100010; i++) {
        if (isprime[i])
            for (int j = i * 2; j < 100010; j += i)
                isprime[j] = false;
    }
}

void get_counter() {
    int count = 0;
    for (int i = 2; i < 100010; i++) {
        if (isprime[i] && isprime[(i+1)/2])
            count++;
        counter[i] = count;
    }
}

int main() {
    int q; cin >> q;
    set_prime();
    get_counter();
    for (int i = 0; i < q; i++) {
        int l, r; cin >> l >> r;
        cout << counter[r] - counter[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1152
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, T = readmap()
c = []
t = []
for _ in range(N):
    ci, ti = readmap()
    c.append(ci)
    t.append(ti)

ans = 10000
for i in range(N):
    if t[i] <= T:
        ans = min(ans, c[i])

if ans > 1000:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[1001];
int main(){
  ll i,j,k,n,m;
  cin>>n>>k;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  int ans = 0;
  for(int i=0;i<k;i++) ans+=a[i];
  cout<<ans<<"\n";
  
}

Measured memory_bytes: 3628