akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<ll> a(n);
  ll mi = LINF;
  ll su = 0;
  ll cnt = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    if(a[i] < 0) cnt++;
    mi = min(mi, abs(a[i]));
    su += abs(a[i]);
  }
  if(cnt % 2) {
    cout << su - mi * 2 << endl;
  } else {
    cout << su << endl;
  }
}


Measured memory_bytes: 1152
a = int(input())
b = a - a // 10 * 10
c = ("pon" if b == 0 else
     "pon" if b == 1 else
     "hon" if b == 2 else
     "bon" if b == 3 else
     "hon" if b == 4 else
     "hon" if b == 5 else
     "pon" if b == 6 else
     "hon" if b == 7 else
     "pon" if b == 8 else
     "hon" if b == 9 else
     ""
     )
print(c)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
long long e[MAXN], a[MAXN];

long long quick_pow(long long a, long long b){
	long long ans = 1;
	while (b){
		if (b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
		b /= 2;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		long long tmp = a[i];
		for (int j = 2; j * j <= tmp; ++j){
			if (tmp % j == 0){
				long long cnt = 0;
				while (tmp % j == 0){
					cnt++;
					tmp /= j;
				}
				e[j] = max(e[j], cnt);
			}
		}
		e[tmp] = max(e[tmp], 1ll);
	}
	long long lcm = 1;
	for (long long i = 1; i <= 1e6; ++i){
		lcm = (lcm * quick_pow(i, e[i])) % MOD;
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i){
		ans = (ans + lcm % MOD * quick_pow(a[i], MOD - 2) % MOD) % MOD;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 8832
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n, a, b = map(int, input().split())
for i in range(1, n+1):
    s = str(i)
    chk = 0
    for j in range(len(s)):
        chk += int(s[j])
    if a <= chk and chk <= b:
        ans += i
print(ans)

Measured memory_bytes: 9280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N = 26;
int D;
ll c[26];
ll s[366][36];
int t[366];
set<int> st[26];

void input(){
    cin >> D;
    for(int i = 0; i < N; i++) {
        cin >> c[i];
        st[i].insert(0); st[i].insert(D+1);
    }
    for(int i = 1; i <= D; i++){
        for(int j = 0; j < N; j++) cin >> s[i][j];
    }
    for(int i = 1; i <= D; i++) {
        cin >> t[i];
        t[i]--;
        st[t[i]].insert(i);
    }
}


ll calc_score(){
    vector<int> last(N);
    ll S = 0;
    for(int d = 1; d <= D; d++){
        last[t[d]]  = d;
        for(int i = 0; i < N; i++){
            S -= c[i]*(d-last[i]);
        }
        S += s[d][t[d]];
    }
    return S;
}

ll solve(ll prev){
    int d, q; cin >> d >> q; q--;
    prev -= s[d][t[d]]; prev += s[d][q];
    // t[d]がなくなる
    {
        auto l = st[t[d]].find(d); l--;
        auto r = st[t[d]].upper_bound(d);
        ll dif_l = d-*l, dif_r = *r-d;
        prev -= (dif_l)*(dif_r)*c[t[d]];
    }
    // qが増える
    {
        auto l = st[q].lower_bound(d); l--;
        auto r = st[q].upper_bound(d);
        ll dif_l = d-*l, dif_r = *r-d;
        prev += (dif_l)*(dif_r)*c[q];
    }
    st[t[d]].erase(d); st[q].insert(d);
    t[d] = q;
    return prev;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    int M;
    cin >> M;
    ll prev = calc_score();
    for(int i = 0; i < M; i++){
        prev = solve(prev);
        cout << prev << endl;
    }
}

Measured memory_bytes: 3736
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

for i in range(N):
    x,y,h= (int(i) for i in input().split())
    xyh[i] =x,y,h
    h_list[i] =h

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
if len(xyh[ind:]) ==1:
    print(*xyh[-1])
else:
    for k,v in H.items():
    
        if len(v)==1:
            vv =v.pop()
            if 0 <= vv :
                print(*k,vv)
            elif vv <0:
                print(*k,0)

Measured memory_bytes: 47936
#include<stdio.h>
int main(void)
{
  int n,m,i,j;
  scanf("%d%d",&n,&m);
  int c[m],LP[n+1][m];
  for(i=0;i<m;i++) scanf("%d",&c[i]);
  for(i=0;i<=n;i++){
    LP[i][0]=i;
  }
  for(j=1;j<m;j++){
    for(i=0;i<=n;i++){
      int x=10000,y=10000,z=10000,min;
      x=LP[i][j-1];
      if(i-c[j]>=0) y=LP[i-c[j]][j-1]+1;
      if(i-c[j]>=0) z=LP[i-c[j]][j]+1;
      //if(i==4&&j==1) printf("x:%d y:%d z:%d\n",x,y,z);
      min=x;
      if(z<min) min=z;
      if(y<min) min=y;
      LP[i][j]=min;
    }
  }
/*  for(j=0;j<m;j++){
    for(i=0;i<=n;i++) {printf("%d ",LP[i][j]);}
    printf("\n");
  }
  */
  printf("%d\n",LP[n][m-1]);
  return 0;
}



Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
long long longpow(long long n, long long a) {
  if (a == 0) return 1;
  if (a == 1) return n;
  if (a % 2 == 1) return (n * longpow(n, a - 1));
  ll t = longpow(n, a / 2);
  return (t * t);
}
const int mod = 1e9 + 7;
struct Combination {
  // Combnation(x)　xCxまでを生成
  // RetCombination(n,r) nCrを返す
  vector<vector<long long>> combination;
  Combination(int x) {
    combination.resize(x + 1);
    for (int i = 0; i < x + 1; i++) {
      combination[i].resize(x + 1);
    }
    combination[0][0] = 1;
    for (int i = 0; i < x; i++) {
      for (int j = 0; j <= i; j++) {
        combination[i + 1][j] += combination[i][j];
        combination[i + 1][j + 1] += combination[i][j];
        combination[i + 1][j] %= mod;
        combination[i + 1][j + 1] %= mod;
      }
    }
  }
  long long RetCombination(int n, int r) { return combination[n][r]; }
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  vector<ll> bits(60, 0);
  REP(j, N) {
    for (int i = 59; i >= 0; i--) {
      if (longpow(2, i) <= A[j]) {
        bits[i]++;
        A[j] -= longpow(2, i);
      }
    }
  }
  ll ans = 0;
  REP(i, 60) {
    if (bits[i] == 0 || bits[i] == N) continue;
    ans += (longpow(2, i) % mod) * ((bits[i] * (N - bits[i])) % mod);
    ans %= mod;
  }
  cout << ans << endl;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  long n, d;
  cin >> n >> d;
  long count = 0;
  for (int i = 0; i < n; i++) {
    long x, y;
    cin >> x >> y;
    if ((x * x + y * y) <= d * d) {
      count++;
    }
  }
  cout << count << endl;
}


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

int main(){
	string s; cin>>s;
	string f=s.substr(0,4);
	if(f=="YAKI") cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int N,input;
  set<int> Set;
  cin>>N;
  
  FOR(i,0,N){
    cin>>input;
    Set.insert(input);
  }
  cout<<Set.size()<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	LL A, B;
	scanf("%lld%lld", &A, &B);
	if (A < 0 && B < 0)
	{
		if (!((B - A) & 1))cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	else if (A < 0 && B > 0)
		cout<<"Zero"<<endl;
	else if (A == 0 || B == 0)
		cout<<"Zero"<<endl;
	else cout<<"Positive"<<endl;
	return 0;
}

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

int main(){
    string x,y,z;
    cin >> x >> y >> z;
    int turn=1;
    while(true){
        if(turn==1){
            if(x.empty()){
                break;
            }
            if(x.at(0)=='b'){
                turn=2;
            }
            if(x.at(0)=='c'){
                turn=3;
            }
            x.erase(0,1);
        }
        else if(turn==2){
            if(y.empty()){
                break;
            }
            if(y.at(0)=='a'){
                turn=1;
            }
            if(y.at(0)=='c'){
                turn=3;
            }
            y.erase(0,1);
        }
        else if(turn==3){
            if(z.empty()){
                break;
            }
            if(z.at(0)=='a'){
                turn=1;
            }
            if(z.at(0)=='b'){
                turn=2;
            }
            z.erase(0,1);
        }
    }
    if(turn==1){
        cout << "A" << endl;
    }
    else if(turn==2){
        cout << "B" << endl;
    }
    else if(turn==3){
        cout << "C" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bitset>
 
using namespace std;
 
#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
 
 
typedef long long ll;
typedef unsigned long long int llt;
 
const int N = 5e5 + 10;
 
vector<int> g[N];
bool viss[N];
int vis[N];
 
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}
 
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}
 
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}
 
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}
 
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}
 
string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}
 
llt convertback(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}
 
int main()
{
int n;
  cin>>n;
  cout<<(n*(n+1))/2;
  
  return 0;
}

Measured memory_bytes: 12416
#include<stdio.h>
int main()
{
	int n,i;
	scanf("%d",&n);
	int a[200];
	for(i=0;i<2*n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<2*n;i++)
	{
		for(int j=i+1;j<2*n;j++)
		{
			if(a[i]>a[j])
			{
				int c=a[i];
				a[i]=a[j];
				a[j]=c;
			}
		}
	}
	int sum=0;
	for(i=0;i<2*n;i+=2)
	sum+=a[i];
	printf("%d",sum);
}

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

typedef long long ll;
typedef pair<int,int> P;

const int INF=1e9;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    ll a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    ll sum=0;
    for(int i=0;i<N;i++){
        sum+=a[i];
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        sum-=a[i];
        ans+=(a[i]%MOD)*(sum%MOD)%MOD;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5184
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int neko(ll N, ll X, ll Y, ll a, ll b) //a<b
{
    ll dis = b - a;
    ll dis2;
    if (a <= X)
    {
        if (b <= X)
        {
            dis2 = b - a;
        }
        if (b > X && b <= Y)
        {
            dis2 = X - a + 1 + Y - b;
        }
        if (b > Y)
        {
            dis2 = X - a + 1 + b - Y;
        }
    }
    if (a > X && a <= Y)
    {
        if (b > X && b <= Y)
        {
            dis2 = a - X + 1 + Y - b;
        }
        if (b > Y)
        {
            dis2 = a - X + 1 + b - Y;
        }
    }
    if (a > Y)
    {
        dis2 = b - a;
    }
    ll min_dis = min(dis, dis2);
    return min_dis;
}

int main()
{
    ll N, X, Y;
    cin >> N >> X >> Y;
    ll dis;
    ll a, b;
    vector<ll> vec(N - 1, 0);
    for (ll a = 1; a < N; a++)
    {
        for (ll b = a + 1; b < N + 1; b++)
        {
            dis = neko(N, X, Y, a, b);
            vec.at(dis - 1)++;
        }
    }
    rep(i, N - 1)
    {
        cout << vec.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,x;
  cin>>n>>x;
  int l[n+1],d[n+2];d[1]=0;int c=0;
  for(int i=1;i<=n;i++)
  {
    cin>>l[i];
  }
  for(int i=2;i<=n+1;i++)
  {
    d[i]=d[i-1]+l[i-1];
  }
  for(int i=2;i<=n+1;i++)
  {
    if(d[i]<=x)
      c++;
  }
  cout<<c+1;
  return 0;
}
  

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
q = [list(map(int, input().split())) for _ in range(Q)]

vs = []

def dfs(u, A):
    if len(A) == N:
        v = 0
        for j in range(Q):
            a, b, c, d = q[j]
            if A[b-1]-A[a-1] == c:
                v += d
        vs.append(v)
    else:
        for i in range(u, M+1):
            dfs(i, A+[i])
    
dfs(1, [1])
print(max(vs))

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

using namespace std;

const int MN = 3333;
int n;
double dp[MN][MN];

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

    cin >> n;

    dp[0][0] = 1.0;
    for (int ph = 0; ph < n; ph++) {
        double a;
        cin >> a;
        double b = 1.0 - a;
        for (int j = 0; j <= ph; j++) {
            dp[ph + 1][j] += b * dp[ph][j];
            dp[ph + 1][j + 1] += a * dp[ph][j];
        }
    }

    double sm = 0.0;
    for (int i = 0; i <= n; i++) {
        if (i > n - i) sm += dp[n][i];
    }
    cout << fixed << setprecision(20) << sm << endl;
    return 0;
}

Measured memory_bytes: 78464
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(true){
    ll x,y,s,ans=0;
    cin>>x>>y>>s;
    if(x==0 && y==0 && s==0) break;
    Rep(i,s){
      Rep(j,s){
        if(i*(100+x)/100+j*(100+x)/100==s){
          chmax(ans,(i*(100+y)/100+j*(100+y)/100));
        }
      }
    }
    cout<<ans<<endl;
  }
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;



signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll fq[n+1]={0};
        f(i,1,k)
        {
            ll d;
            cin>>d;
            f(j,1,d)
            {
                ll x;
                cin>>x;
                fq[x]=1;
            }
        }
        ll ans=0;
        f(i,1,n)
        {
            ans+=(!fq[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


















Measured memory_bytes: 3668
while line = gets
  n = line.to_i
  break if n.zero?

  data = n.to_i.times.map{ gets.split.map(&:to_i) }
  data.each{|row| row << row.inject(:+) }
  data = data.transpose
  data.each{|row| row << row.inject(:+) }
  data = data.transpose

  format = data.first.map{|n| "%5d" }.join
  data.each{|row| puts sprintf(format, *row)}

end

Measured memory_bytes: 8792
#include <atcoder/all>
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q;
    cin >> n >> q;
    vector<ll> t(q), u(q), v(q);
    rep(i, q) { cin >> t[i] >> u[i] >> v[i]; }

    atcoder::dsu d(n);

    rep(i, q) {
        if (t[i]) {
            cout << d.same(u[i], v[i]) << endl;
        } else {
            d.merge(u[i], v[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 8168
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 100005; 
using namespace std;

int a[N], b[N], ans, n, f[N], mx, cnt; 
struct node
{
	int p, l;
	bool operator < (const node &x) const
		{
			return (p - l < x.p - x.l || (p - l == x.p - x.l && p < x.p)); 
		}
} x[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (); 
	for(int i = 1; i <= n; i++)
		x[i].p = read <int> (), x[i].l = read <int> (); 
	sort(x + 1, x + n + 1); 
	for(int i = 1; i <= n; i++)
	{
		if(!mx)
			cnt = 1, mx = i; 
		else if(x[mx].p + x[mx].l <= x[i].p - x[i].l)
			mx = i, cnt++; 
		else if(x[mx].p + x[mx].l > x[i].p - x[i].l && x[i].p + x[i].l < x[mx].p + x[mx].l)
			mx = i;
	}
	printf("%d\n", cnt); 
	return 0; 
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;


void pre(){

}

void solve(){
  int n; cin>>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n,greater<ll>());

  ll ans=0;
  ans+=a[0];
  queue <ll> q1;
  q1.push(a[1]);
  q1.push(a[1]);

  for(int i=2;i<n;i++){
    ll temp=q1.front();
    ans+=temp;
    q1.pop();
    q1.push(a[i]);
    q1.push(a[i]);
  }

  cout<<ans<<"\n";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 6360
/*input

*/
// https://atcoder.jp/contests/abc163/tasks/abc163_f
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define pr pair<int,int>
#define int long long
using namespace std;
const int N = 200005;
int color[N], block[N];
int ans[N];
int child[N];
int n;
int delta = 0;
vector<int> G[N];
void dfs(int u,int par){
	int preBlock = block[color[u]] + delta;
	for (auto v : G[u]){
		if (v == par) continue;
		int preVal = block[color[u]] + delta; 
		dfs(v, u);
		int newVal = block[color[u]] + delta - preVal;
		ans[color[u]] += newVal * (newVal + 1)/2;	
	}
	delta++;
	block[color[u]] = preBlock - delta;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;++i){
		cin >> color[i];
	}
	for(int i=1;i<n;++i){
		int u,v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	// up(i,1,n) cout << block[i] << ' ';
	for(int i=1;i<=n;++i){
		block[i] += n;
		ans[i] += 1LL * block[i] * (block[i] + 1)/2;
		ans[i] = n*(n+1)/2 - ans[i];
	}
	for(int i=1;i<=n;++i) cout << ans[i] << '\n';
}

Measured memory_bytes: 37956
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc133_a

import math

def distance_square(x, y, d):
    z = 0
    for i in range(d):
        z += (x[i] - y[i]) ** 2
    return z

num, dim = map(int, input().strip().split())
points = [list(map(int, input().strip().split())) for _ in range(num)]

res = 0
for i in range(num):
    for j in range(i):
        z = distance_square(points[i], points[j], dim)
        if z == int(math.sqrt(z)) ** 2:
            res += 1

print(res)


Measured memory_bytes: 9152
#include <stdio.h>
 
int main()
{
  int A, B, C;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  
  if (A+B+C==17) {
    if (A==5 && (B==5 || B==7)) {
        printf("YES");
    }
    else if (A==7 && B==5) {
        printf("YES");
    }
    else {
      printf("NO");
    }
  } else {
    printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
int main()
{
	ios;
	ll k,i,j,m,sum=0;
	cin>>k;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(m=1;m<=k;m++)
				sum+=__gcd(i,__gcd(j,m));
		}
	}
	cout<<sum<<endl;
}


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

int main(){
    int S;
    cin>>S;
    int h, m, s;
    s=S%60;
    m=S%3600/60;
    h=S/3600;
    cout<<h<<":"<<m<<":"<<s<<endl;
}


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

B_list = list(map(int, input().split()))
B_list.reverse()

A_list = []

A_list.append(B_list[0])

for i in range(len(B_list)-1):
    if A_list[i] - B_list[i + 1] >= 0:
        A_list.append(B_list[i + 1])
    else:
        if B_list[i] - B_list[i + 1] >= 0:
            A_list.append(B_list[i + 1])
        else:
            A_list.append(B_list[i])

A_list.append(B_list[-1])
print(sum(A_list))


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

int main() {
  int n,sum=0;
  cin >>n;
  
  vector<int> a(n+1),b(n),c(n-1);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  for(int i=0;i<n-1;i++) cin >> c[i];
  a[n]=-1;
  
  for(int i=0;i<n;i++){
    sum +=b[a[i]-1];
    if(a[i]+1==a[i+1]) sum +=c[a[i]-1];
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
vector<int>e[200000];
bool c[200000];//親が決まっているか
int pa[200000];
int co[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; i++) {
		int u1, u2;
		cin >> u1 >> u2;
		u1--; u2--;
		e[u1].push_back(u2);
		co[u2]++;
	}
	queue<int>q;
	for (int i = 0; i < n; i++) {
		if (co[i] == 0) q.push(i);
	}
	while (!q.empty()) {
		int t = q.front(); q.pop();
		for (int i = 0; i < e[t].size(); i++) {
			co[e[t][i]]--;
			if (!co[e[t][i]]) {
				pa[e[t][i]] = t + 1;
				q.push(e[t][i]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << pa[i] << endl;
	}
}

Measured memory_bytes: 11136
#include <iostream>

using namespace std;

int main()
{
	string s;

	cin >> s;

	int c = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == '1')
			c++;
	}

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.chars

# 3文字未満の場合、条件を満たす組は存在しない
if n < 3
  puts 0
  exit
end

# 間隔が等しい場合の数を先に求める
cnt = 0
1.upto((n - 1) / 2) do |d|
  (n - 2 * d).times do |i|
    j = i + d
    k = j + d
    if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
      cnt += 1
      # p [i,j,k]
    end
  end
end

# 既に出現した、R,G,Bの数を覚えつつ、累積
r = 0
g = 0
b = 0
ans = 0
n.times do |i|
  case s[i]
  when 'R'
    ans += g * b
    r += 1
  when 'G'
    ans += r * b
    g += 1
  when 'B'
    ans += r * g
    b += 1
  end
end

puts ans - cnt


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, K; cin >> N >> K;
    vector<bool> D(10, false);
    REP(i, K) {
        i64 d; cin >> d;
        D[d] = true;
    }

    for (i64 x = N; x <= 100000; x++) {
        auto any = [&](i64 n) {
            while (n > 0) {
                if (D[n % 10]) return true;
                n /= 10;
            }
            return false;
        };

        if (any(x)) continue;
        cout << x << endl;
        break;
    }

    return 0;
}

Measured memory_bytes: 256
while True:
  H, W = map(int, input().split())
  
  if H == 0 and W == 0 :
    break
  for i in range(H):
      for j in range(W):
          if i == 0 or i == H-1 or j == 0 or j == W-1 :
              print("#", end="")
          else:
              print(".", end="")
      print()
      
  print()


Measured memory_bytes: 7008
def main():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    x.sort()
    y.sort()

    if X < x[len(x)-1] < y[0] < Y:
        print('No War')
    else:
        print('War')
main()  

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(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 tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,a,b;
    cin >> n >> a >> b;
    if(n == 1 && a != b) {
        cout << 0 << endl;
        return 0;
    }
    if(a > b) {
        cout << 0 << endl;
        return 0;
    }
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll mn,mx;
    mn = (ll)a*(n-2);
    mx = (ll)b*(n-2);
    cout << mx-mn+1 << endl;
}



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

vector<int> era(int N){
	vector<int> is_prime(N+1,1);
	is_prime[0]=0;
	is_prime[1]=0;
	for(int p=2;p*p<=N;p++){
		if(!is_prime[p])continue;
		for(int i=p*2;i<=N;i+=p)is_prime[i]=0;
	}
	return is_prime;
}

signed main(){
	vector<int> pri=era(555555+100);
	int N; cin>>N;
	vector<int> ans(0);
	int now=2;
	while(ans.size()<N){
		if(pri[now] and now%5==1){
			ans.push_back(now);
		}
		now++;
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<' ';
	}
	cout<<endl;
}

Measured memory_bytes: 4608
while True:
    H,W=map(int,input().split())
    if H==W==0:
        break
    for i in range(H):
        if i % 2 == 0:
            print('#.' * (W // 2) + '#' * (W % 2))
        else:
            print('.#' * (W // 2) + '.' * (W % 2))
    print()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

vector<long> divisors(long n) {
    vector<long> res;
    for (long x = 1; x * x <= n; x++) {
        if (n % x == 0) {
            res.push_back(x);
            if (x * x != n) res.push_back(n / x);
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);

//  n = (k * x + 1) * k^y
//  y > 0: k - divisor of n
//  y = 0: n - 1 = kx
    long n;
    cin >> n;
    auto d1 = divisors(n);
    set<long> ans;
    for (long x : d1) {
        if (x == 1) continue;
        long nn = n;
        while (nn % x == 0) {
            nn /= x;
        }
        if (nn % x == 1) {
            ans.insert(x);
        }
    }
    auto d2 = divisors(n - 1);
    for (long x : d2) {
        if (x == 1) continue;
        ans.insert(x);
    }
    cout << ans.size();

    return 0;
}

Measured memory_bytes: 3672
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 11; list.size() < n; i += 10) {
		    if (isPrime(i)) {
		        list.add(i);
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i > 0) {
		        sb.append(" ");
		    }
		    sb.append(list.get(i));
		}
		System.out.println(sb);
    }
    
    static boolean isPrime(int x) {
        if (x == 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }
}



Measured memory_bytes: 21204
using System;
using System.Linq;

namespace atcoder.abc171.b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputParam = getIntParams();
            int N = inputParam[0];
            int K = inputParam[1];

            int[] inputPrice = getIntParams();

            Array.Sort(inputPrice);

            int ret = 0;
            for (int i = 0; i < K; i++)
            {
                ret += inputPrice[i];
            }
            Console.WriteLine(ret);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


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

int main(){
  string s,t; cin >> s >> t;
  //vector<int> v(n);for(int i = 0; i < n; i++)cin >> v.at(i);
  bool b = true;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i)) b= false;
  }
  if(b)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
n=int(input())
XY=[]
for i in range(n):
    x,y=map(int,input().split())
    XY.append((x,y))
from itertools import permutations
perm=permutations(XY)

dists=[]
for i in perm:
    dist=0
    for j in range(1,n):
        dist+=((i[j][0]-i[j-1][0])**2+(i[j][1]-i[j-1][1])**2)**0.5
    dists.append(dist)
ans=sum(dists)/len(dists)
print(ans)

Measured memory_bytes: 41964
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); ++(i))
using P = pair<int, int>;
int n;
map<int, P>mp;
bool t[3][3];
int main() {
	rep(i, 3) {
		rep(j, 3) {
			int a;
			cin >> a;
			mp[a] = P(i, j);
		}
	}
	cin >> n;
	rep(i, n) {
		int b;
		cin >> b;
		if (mp.find(b) != mp.end()) t[mp[b].first][mp[b].second] = true;
	}
	rep(i, 3) {
		if ((t[0][i] && t[1][i] && t[2][i])||(t[i][0] && t[i][1] && t[i][2])) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if ((t[0][0] && t[1][1] && t[2][2]) || (t[0][2] && t[1][1] && t[2][0])) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
vis = {}
def dfs(i):
    if i in vis:
        return vis[i]
    vis[i] = True
    for j in g[i]:
        if dfs(j):
            return True
    vis[i] = False
    return False
for i in range(n):
    if dfs(i):
        print(0)
        break
else:
    print(-1)


Measured memory_bytes: 44504
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=2e5+100;
const double eps=1e-10;
bool vis[MAXN];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int u,v;
        bool flag=false;
        for(int i=1;i<=n;i++)
            vis[i]=false;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&u,&v);
            if(flag) continue;
            if(u==1)
            {
                if(vis[v])
                {
                    flag=true;
                }
                vis[v]=true;
            }else if(v==n)
            {
                if(vis[u])
                {
                    flag=true;
                }
                vis[u]=true;
            }
        }
        if(flag) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}

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

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



int main(){
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n)cin >> a[i];
  sort(ALL(a));
  vector<P> v;
  v.push_back(make_pair(a[0],1));
  for(int i = 1;i < n;i++){
    if(v.back().first == a[i])v.back().second++;
    else v.push_back(make_pair(a[i],1));
  }
  bool is = true;
  if(v.size() > 2)is = false;
  //if(v.size() == 2)if(v[0].first != 1 || v[1].first != 2 || v[0].second != 1)is = false;
  if(v.size() == 2)if(v[1].second == 1 || v[1].second/2+v[0].second < v[1].first || v[0].second+1 > v[1].first || v[1].first-v[0].first != 1)is = false;
  if(v.size() == 1)if(v[0].first*2 > n && v[0].first != n-1)is = false;
  cout << (is ? "Yes\n" : "No\n");

  


  return 0;
}

Measured memory_bytes: 4508
#include<stdio.h>
#include<string.h>
 
int n,len[40];
char word[11];
 
int solve(int pos) {
    int rest;
    rest = 5;
    while (rest > 0) {
        rest -= len[pos++];
        if (rest < 0)return 0;
    }
    rest = 7;
    while (rest > 0) {
        rest -= len[pos++];
        if (rest < 0)return 0;
    }
    rest = 5;
    while (rest > 0) {
        rest -= len[pos++];
        if (rest < 0)return 0;
    }
    rest = 7;
    while (rest > 0) {
        rest -= len[pos++];
        if (rest < 0)return 0;
    }
    rest = 7;
    while (rest > 0) {
            rest -= len[pos++];
            if (rest < 0) return 0;
    }
    return 1;
}
 
int main() {
    while (1) {
        scanf("%d\n", &n);
        if (n == 0)break;
        for (int i = 0; i < n; i++) {
            scanf("%s\n", word);
            len[i] = strlen(word);
        }
        for (int j = 0; j < n; j++) {
            if (solve(j)) {
                printf("%d\n", j + 1);
                break;
            }
        }
    }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,k,q,x,y,l,r,z,n,ans =0;
    cin>>n;
    ll a[n+5];
    map<ll,ll> m;
    rep(i,1,n){
    	cin>>a[i];
    	m[a[i]]++;
	}
	rep(i,1,n){
    	ans += ((m[i])*(m[i]-1))/2;
	}
	rep(i,1,n){
	    ll val = ans;
	    val -= max(((m[a[i]])*(m[a[i]]-1))/2,0ll);
	    val += max(((m[a[i]]-1)*(m[a[i]]-2))/2,0ll);
	    cout<<val<<endl;
	}
}

Measured memory_bytes: 16640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
int main() {
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> field(H, vector<char>(W));
    rep(i, H)
        rep(j, W)cin >> field[i][j];
    const ll dx[8]{ 1,1,1,0,0,-1,-1,-1 };
    const ll dy[8]{ 0,1,-1,1,-1,1,-1,0 };
    vector<vector<ll>> ans(H, vector<ll>(W));
    rep(i, H) {
        rep(j, W) {
            rep(k, 8) {
                ll dh = i + dx[k];
                ll dw = j + dy[k];
                if (dh < 0 || dw < 0 || dh >= H || dw >= W)continue;
                if (field[dh][dw] == '#') {
                    ans[dh][dw] = -9;
                    ans[i][j]++;
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (ans[i][j] < 0)cout << "#";
            else cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int a[2001],d[2001],n;

void dfs(int sum, int k) {
  if(k==n) {
    d[sum]=1;
    return;
  }
  dfs(sum,k+1);
  if(sum+a[k]<=2000) dfs(sum+a[k],k+1);
}

int main() {
  int i,m,x;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  dfs(0,0);
  scanf("%d",&m);
  for(i=0; i<m; i++) {
    scanf("%d",&x);
    if(d[x]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#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 = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

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

constexpr int MAX_ROW = 110;
constexpr int MAX_COL = 110000;
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL> &operator[](const int &i) { return val[i]; }
};

void GaussJordan(BitMatrix &A, bool is_extended = false) {
    vector<bool> used(A.H, 0);
    rep(col, A.W) {
        if(is_extended && col == A.W - 1) break;
        int pivot = -1;
        rep(row, A.H) {
            if(used[row]) continue;
            if(A[row][col]) {
                pivot = row;
                break;
            }
        }
        if(pivot == -1) continue;
        rep(row, A.H) if(row != pivot && A[row][col]) A[row] ^= A[pivot];
        used[pivot] = true;
    }
}

const int MD = 60;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll res = 0;
    BitMatrix B(MD + 1, N + 1);
    vector<bool> cannot(MD + 1, 0);
    for(ll d = MD; d >= 0; d--) {
        int num = 0;
        rep(i, N) num += A[i] >> d & 1;
        if(num == 0) {
            cannot[d] = 1;
            continue;
        } else if(num & 1) {
            cannot[d] = 1;
            res += 1LL << d;
            continue;
        }
        rep(i, N) if(A[i] >> d & 1) B[MD - d][i] = 1;
        B[MD - d][N] = 1;
    }
    GaussJordan(B, true);

    for(int d = MD; d >= 0; d--) {
        if(cannot[d]) continue;
        bool ok = false;
        rep(i, N) if(B[MD - d][i]) ok = true;
        if(!B[MD - d][N]) ok = true;
        if(ok) res += 2LL << d;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2560