akhauriyash/Code-Regression huggingface dataset:
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

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

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int res[128][128];

void odd(int N) {
  REP(i,N) REP(j,N-1) {
    res[i][j] = (i + j + 1) % N;
  }
}

void even(int N) {
  REP(i,N) REP(j,N-1) {
    res[i][j] = (i + j + 1) % N;
  }
  REP(i,N) res[i][0]   = i < N / 2 ? i + 1 : i - N / 2;
  REP(i,N) res[i][N/2-1] = i < N / 2 ? i + N / 2 : (i + 1) % N;
}

void solve() {
  int N;
  cin >> N;
  if (N == 2) {
    cout << -1 << endl;
    return;
  }
  if (N % 2) odd(N); else even(N);
  REP(i,N) REP(j,N-1) cout << res[i][j] + 1 << " \n"[j == N-2];
  return;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)

t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = {0: 0, 1: d}

    def cost(N):
        if N in memo:
            return memo[N]
        ans = N * d
        ks = [2, 3, 5]
        abc = [a, b, c]
        for i in range(3):
            k = ks[i]
            coin = abc[i]
            div, mod = divmod(N, k)
            pay = mod * d + coin
            ans = min(ans, pay + cost(div))
            if mod == 0:
                continue
            pay = (k - mod) * d + coin
            ans = min(ans, pay + cost(div + 1))
        memo[N] = ans
        return ans

    print(cost(n))


Measured memory_bytes: 90588
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 501000;
struct point{
	ll x,y;
}p[N],st[N];
int top,n;
ll a[N],b[N],c[N],B[N];
point operator - (point a,point b){return point{a.x-b.x,a.y-b.y};}
lld operator * (point a,point b){return 1.l*a.x*b.y-1.l*a.y*b.x;}
void solve(){
	for(int i=0;i<=n;i++){
		while(top>1&&(p[i]-st[top-1])*(st[top]-st[top-1])<=0) top--;
		st[++top]=p[i];
	}
	lld ans=0;
	int now=1;
	for(int i=0;i<n;i++){
		while(st[now+1].x<=i) now++;
		ans+=1.l*((st[now+1].x-i)*st[now].y+(i-st[now].x)*st[now+1].y)/(st[now+1].x-st[now].x)-c[i];
	}
	printf("%.12Lf\n",ans/n);
}
int main(){
	read(n);
	int k=0;ll mx=-1;
	for(int i=1;i<=n;i++){
		read(a[i]);
		if(a[i]>mx) k=i,mx=a[i];
	}
	for(int i=1;i<=n;i++)
		read(b[i]);
	for(int i=0;i<n;i++)
		p[i]={i,a[(i+k-1)%n+1]},B[i]=b[(i+k-1)%n+1];
	p[n]=p[0];p[n].x=n;
	c[0]=c[1]=0;
	for(int i=1;i<n;i++){
		c[i+1]=2*c[i]-2*B[i]-c[i-1];
	}
	for(int i=0;i<=n;i++) p[i].y+=c[i];
	solve();
	return 0;
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
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; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);
ll t[120] = {};


int m[200] = { 0 };
int main()
{
	string s;
	char ans;
	cin >> s;
	
	for (int i = 0; i < s.length(); i++){ 
		m[(int)s[i]] = 1;
	}
	
	for (int i = 97; i <= 122; i++){
		if (m[i] == 0) {
			ans = (char)i;
			cout << ans << endl;
			break;
		}
		if (i == 122) {
			cout << "None" << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include<stdio.h>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n,i,ac=0,wa=0,tle=0,re=0;
    string S;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> S;
        if(S=="AC"){
            ac++;
        }else if(S=="WA"){
            wa++;
        }else if(S=="TLE"){
            tle++;
        }else{
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

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

int main(){
    string S;
    cin>>S;

    int i;

    if(S=="RRR"){
        i=3;
        cout<<i<<endl;
    }

    else if(S=="RRS"){
        i=2;
        cout<<i<<endl;
    }
    else if(S=="RSR"){
        i=1;
        cout<<i<<endl;
    }
    else if(S=="RSS"){
        i=1;
        cout<<i<<endl;
    }
    else if(S=="SRR"){
        i=2;
        cout<<i<<endl;
    }
    else if(S=="SRS"){
        i=1;
        cout<<i<<endl;
    }
    else if(S=="SSR"){
        i=1;
        cout<<i<<endl;
    }
    else if(S=="SSS"){
        i=0;
        cout<<i<<endl;
    }
}

Measured memory_bytes: 3592
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n, k = map(int, input().split())
    p = tuple(map(int, input().split()))
    c = tuple(map(int, input().split()))

    if k == 1:
        print(max(c))
        sys.exit()
    seen = [0] * n
    cycles = []
    for i1 in range(n):
        if not seen[i1]:
            cycle_t = []
            koko = i1
            while True:
                if seen[koko]:
                    cycles.append(cycle_t)
                    break
                cycle_t.append(c[koko])
                seen[koko] = 1
                koko = p[koko] - 1

    score = max(c)
    for cycle in cycles:
        score_t = max(cycle)
        cycle_len = len(cycle)
        cycle_sum = sum(cycle)
        kaisu, rem = divmod(k, cycle_len)
        if rem == 0:
            kaisu -= 1
            rem = cycle_len
        if kaisu > 0:
            kaisu -= 1
            rem += cycle_len
        cycle = tuple(accumulate(cycle + cycle + cycle))
        for i1 in range(2, rem + 1):
            for i2 in range(cycle_len):
                score_t = max(score_t, cycle[i1+i2] - cycle[i2])
        if cycle_sum > 0:
            score_t += (kaisu * cycle_sum)
        score = max(score, score_t)
    print(score)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69720
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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


int main() {
    ll A,B,K;
    cin >> A >> B >> K;

    for(ll i=A;i<=B;i++){
        if((B-A+1) >= K*2){
            if(i == A+K){
            i = B - K + 1;
            }
            cout << i << endl;
        }else{
            cout << i << endl;
        }
        
        
        
    }
}



Measured memory_bytes: 3532
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int gcd(int a, int b){
  if(b==0) return a;
  return gcd(b, a%b);
}
int main()
{
	int a, b, k; cin>>a>>b>>k;
  int d=gcd(a, b);
  int c=0;
  for(int i=d; i>=1; i--){
    if(d%i!=0) continue;
    c++;
    if(c==k){
      cout<<i<<endl;
      return 0;
    }
  }
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int H1,H2,M1,M2,K;
	cin>>H1>>M1>>H2>>M2>>K;
	H1=H1*60+M1;
	H2=H2*60+M2;
	H2-=K;
	cout<<max(H2-H1,0);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  int p[n];
  memset(p,0,sizeof(p));
  for(int i = 0; i < n; ++i){
    cin >> p[i];
  }
  
  sort(p,p+n);
  
  int res = 0;
  for(int i = 0; i < n-1; ++i){
    res += p[i];
  }
  res += p[n-1]/2;
  
  cout << res << endl;
}

Measured memory_bytes: 3636
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

from itertools import permutations

ans = 0
xs = permutations(range(1, n+1), n)
xs = sorted(xs)
# print(xs)
# print(p,q)
for i, x in enumerate(xs):
    if x == p:
        pi = i
    if x == q:
        qi = i

print(abs(pi - qi))


Measured memory_bytes: 46064
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	ll n,c,k,cnt=0;
	cin>>n>>c>>k;
	vector<ll> t(n);
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	sort(t.begin(),t.end());
	ll curbus = -1, num = 1;
	for(int i=0;i<n;i++){
		if(curbus >= t[i] && c > num){
			num++;
		}
		else{
			cnt++;
			curbus = t[i]+k;
			num = 1;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
s = input()
mae = int(s[0:2])
usi = int(s[2:])
if (1 <= usi and usi <= 12) and (1 <= mae and mae <= 12) :
    print("AMBIGUOUS")
elif 1 <= usi and usi <= 12:
    print("YYMM")
elif 1 <= mae and mae <= 12:
    print("MMYY")
else :
    print("NA")


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

using namespace std;

int main () {
  int n, k;
  string w;
  cin >> n >> k >> w;
  for (int i = 0; i < n; i++) {
    if (i + 1 != k) cout << w[i];
    else cout << char(tolower(w[i]));
  }
  cout << '\n';
  return 0;
}

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

int main()
{
    // 整数の入力
    int  N,K;
    cin >> N>>K;
    list<int> yen;
    int a;
    for(int i = 0;i<N;i++){
        cin >> a;
        yen.push_back(a);
    }
    yen.sort();
    int ret= 0;
    for(int j=0;j<K;j++){
        ret += *next(yen.begin(), j);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3608
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
ll dp[1000005][2];
int main(){
string s;
cin>>s;
int n=s.size();
for(int i=0;i<1000005;i++)for(int j=0;j<2;j++)dp[i][j]=inf;
dp[0][0]=0;
reverse(all(s));
for(int i=0;i<n;i++){
	int now=s[i]-'0';
	chmin(dp[i+1][0],min(dp[i][0],dp[i][1])+now);
	chmin(dp[i+1][1],min(dp[i][0]+11-now,dp[i][1]+9-now));
}
cout<<min(dp[n][0],dp[n][1])<<endl;
}

Measured memory_bytes: 17052
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
n, x, t = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

if n % x == 0:
    print(n//x*t)
else:
    print((n//x+1)*t)


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

int main() {
	string L;
	cin >> L;
	ll dp[100100][2];
	memset(dp, 0, sizeof(dp));
	//dp[i][j]:=上からi行目までを決めてその桁までが(0,0),(0,1),(1,0)の3通りから選ばれていて
	//a+bがLより小さいことが確定している(j=1)/いない(j=0)ような選び方の個数
	int n = L.size();
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
			dp[i + 1][1] += dp[i][1] * 3;
			if (L[i] == '1') {
				dp[i + 1][1] += dp[i][0];
				dp[i + 1][0] += dp[i][0] * 2;
			}
			else {
				dp[i + 1][0] += dp[i][0];
			}
			dp[i + 1][0] %= INF;
			dp[i + 1][1] %= INF;
	}
	ll ans = dp[n][1] + dp[n][0];
	ans %= INF;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
    {
        printf("Yes");
    }
    else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;







}


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

int main() {
  int x;
  cin >> x;
  int t=0;
  double sq=0;
  int s=0;
 
  if(x == 2 || x == 3){
    cout << x << endl;
  }
 
  else{
   for(int i=x; i<200000; i++){
     sq = sqrt(i);
     s = sq;
     for(int j=2; j<=s; j++){
       if(i%j != 0) t++;
     }
       if(t == s-1){
         cout << i << endl;
         return 0;
       }
       else{
         t=0;
       }    
   }
  }
	
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0]
    t = 0
    C = []
    for i, a in enumerate(A):
        t += a
        C.extend(t - b for b in B)
        B.append(t)
    r = 0
    k = B[-1].bit_length()
    for i in reversed(range(k + 1)):
        t = 0
        for c in C:
            if c & r != r:
                continue
            if c & (1 << i):
                t += 1
        if t >= K:
            r |= 1 << i
    return r
        
print(main())


Measured memory_bytes: 94592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<ll> X, Y, P;
vector<pair<ll, ll>> cx, cy;
int N;
bool xg[18], yg[18];
ll D[18];
ll R[18];

void chmin(ll& A, ll B) {
	A = min(A, B);
}

void dfs(int c, int k) {
	if (c == N) {
		for (int i = 0;i < N;i++)D[i] = min(abs(X[i]), abs(Y[i]));
		ll mv = -MOD;
		for (int i = 0;i < N;i++) {
			if (xg[cx[i].second]) {
				mv = cx[i].first;
			}
			chmin(D[cx[i].second], cx[i].first - mv);
		}
		mv = MOD;
		for (int i = N - 1;i >= 0;i--) {
			if (xg[cx[i].second]) {
				mv = cx[i].first;
			}
			chmin(D[cx[i].second], mv - cx[i].first);
		}
		mv = -MOD;
		for (int i = 0;i < N;i++) {
			if (yg[cy[i].second]) {
				mv = cy[i].first;
			}
			chmin(D[cy[i].second], cy[i].first - mv);
		}
		mv = MOD;
		for (int i = N - 1;i >= 0;i--) {
			if (yg[cy[i].second]) {
				mv = cy[i].first;
			}
			chmin(D[cy[i].second], mv - cy[i].first);
		}

		ll S = 0;
		for (int i = 0;i < N;i++) {
			S += D[i] * P[i];
		}
		chmin(R[k], S);
		return;
	}

	xg[c] = 1;
	dfs(c + 1, k + 1);
	xg[c] = 0;

	yg[c] = 1;
	dfs(c + 1, k + 1);
	yg[c] = 0;

	dfs(c + 1, k);
}

int main() {
	cin >> N;
	X = Y = P = vector<ll>(N);
	cx = cy = vector<pair<ll, ll>>(N);

	for (int i = 0;i < N;i++) {
		cin >> X[i] >> Y[i] >> P[i];
		cx[i] = { X[i],i };
		cy[i] = { Y[i],i };
		xg[i] = yg[i] = 0;
		R[i] = INT64_MAX;
	}
	sort(all(cx));
	sort(all(cy));

	R[N] = INT64_MAX;
	dfs(0, 0);

	for (int i = 0;i <= N;i++) {
		cout << R[i] << endl;
	}
}

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

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline void input(P &p){D x,y;cin >> x >> y;p={x,y};}
// ???????????¬????????¨???

// ccw
enum CCW{
	LEFT = 1,
	RIGHT = 2,
	BACK = 4,
	FRONT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}

B iver(L a, L b) {return ip(vec(a),vec(b) )== 0.0;}
B ipar(L a, L b) {return ep(vec(a),vec(b) )== 0.0;}


// ??????
P pLL(L a,L b){ return a.s+vec(a)*ep(vec(b),b.s-a.s)/ep(vec(b),vec(a));}


// ?????¨??´?????¨????????¢??£???????????????

B iLL(L a,L b){return !ipar(a,b);}
B eqL(L a,L b){return !iLL(a, b) && ep(vec(a), b.s - a.s)==0;}
B iLS(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) <= 0;}
B iLSs(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) < 0;}
B iSS(L a,L b){
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return ((cwa | cwb) & MID) || ((cwa & cwb) == (LEFT | RIGHT));
}
B iSSs(L a,L b) {
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return (cwa & cwb) == (LEFT | RIGHT);
}

// ?????¨??´?????¨????????¢??£????????¢

D dLP(L l,P p){return abs( ep(vec(l),p-l.s) )/abs(vec(l));}
D dSP(L s,P p){
	if (sig( ip( vec(s), p - s.s)) <= 0) return abs(p - s.s);
	if (sig( ip(-vec(s), p - s.t)) <= 0) return abs(p - s.t);
	return dLP(s,p);
}
D dLL(L a,L b){ return iLL(a,b)?0:dLP(a,b.s);}
D dLS(L a,L b){ return iLS(a,b)?0:min(dLP(a, b.s),dLP(a, b.t));}
D dSS(L a,L b){ return iSS(a,b)?0:
	min({ dSP(a,b.s),dSP(a,b.t),dSP(b,a.s),dSP(b,a.t)});}


int main(void){
	int q;
	cin >> q;
	cout.precision(10);
	rep(loop,q){
		L line[2];
		rep(i,2){
			input(line[i].s);
			input(line[i].t);
		}
		int ans=0;
		if(ipar(line[0],line[1])) ans|=2;
		if(iver(line[0],line[1])) ans|=1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import itertools
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

N, *Z = [int(_) for _ in open(0).read().split()]
A = []
B = []
C = []
for z in range(N * N):
    x, y = divmod(z, N)
    A += [x]
    B += [y]
    C += [Z[z]]
G = csr_matrix((C, (A, B)), (N, N))
F = np.array(floyd_warshall(G, directed=1), dtype=np.int64)
Z = np.array(Z).reshape(N, N)
if np.all(F==Z):
    ans = np.sum(Z)
    for i, j in itertools.product(range(N), repeat=2):
        ans -= Z[i, j] * (np.sum(Z[i] + Z[j] == Z[i, j]) > 2)
    ans //= 2
    print(ans)
else:
    print(-1)


Measured memory_bytes: 47960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	char c;
	cin >> c;
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }


  /* Iterative Function to calculate 
    (x^y)%p in O(log y) */
    static long power(long x, long y, long p) 
    { 
          
        // Initialize result 
        long res = 1L; 
      
        // Update x if it is more than or 
        // equal to p 
        x = x % p; 
                      
        while (y > 0L) 
        { 
              
            // If y is odd, multiply x 
            // with result 
            if (y % 2 == 1L) 
                res = (res * x) % p; 
      
            // y must be even now 
            y = y >> 1L; // y = y/2 
            x = (x * x) % p; 
        } 
          
        return res; 
    } 

    // Returns n^(-1) mod p 
    static long modInverse(long n, long p) 
    { 
        return power(n, p-2, p); 
    } 
      
    // Returns nCr % p using Fermat's 
    // little theorem. 
    static long nCrModPFermat(long n, long r, 
                                    long p) 
    { 
          
        // Base case 
        if (r == 0L) 
            return 1L; 
      
        // Fill factorial array so that we 
        // can find all factorial of r, n 
        // and n-r 
        long fac = 1L;
          
        for (int i = 1 ;i <= r; i++) {
          fac = (fac * (n-(i-1))) % p;
          fac = (fac * modInverse(i, p)) % p;
        }
      
        return fac; 
    }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,aCnt,bCnt,i;
      String str;
      String[] token;

      str=in.readLine().trim();
      n=str.length();
      aCnt=0;
      bCnt=0;
      for(i=0;i<n;i++) {
        if(str.charAt(i)=='A')
          aCnt++;
        else
          bCnt++;
      }

      if(aCnt==3 || bCnt==3) {
        out.println("No");
      }
      else {
        out.println("Yes");
      }


      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  rep(i,n-1) ans *= k-1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<ll> v;
    ll cnt = 1;
    rep(i,1,N){
        if(S[i] != S[i-1]){
            v.push_back(cnt);
            cnt = 1;
        }else{
            cnt++;
        }
    }
    v.push_back(cnt);
    vector<ll> zero, iti;
    if(S[0] == '0') iti.push_back(0);
    if(S[0] == '0'){
        rep(i,0,v.size()){
            if(i % 2 == 0){
                zero.push_back(v[i]);
            }else{
                iti.push_back(v[i]);
            }
        }

    }else{
        rep(i,0,v.size()){
            if(i % 2 == 0){
                iti.push_back(v[i]);
            }else{
                zero.push_back(v[i]);
            }
        }
    }
    if(S[N-1] == '0') iti.push_back(0);
    ll n0 = zero.size();
    ll n1 = iti.size();
    ll sum0[100010] = {}, sum1[100010] = {};
    rep(i,0,n0) sum0[i+1] = sum0[i] + zero[i];
    rep(i,0,n1) sum1[i+1] = sum1[i] + iti[i];
    if(n0 <= K){
        print(N);
        return 0;
    }
    ll ans = 0;
    rep(i,0,N-K+1){
        ll tt = 0;
        ll v1 = sum0[i+K] - sum0[i];
        tt += v1;
        tt += sum1[i+K+1] - sum1[i];
        ans = max(ans, tt);
    }
    print(ans);
}

Measured memory_bytes: 4212
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 3005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll dp[SIZE][SIZE];
ll nx[SIZE][SIZE];
int X[SIZE],Y[SIZE];
int A[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	for(int i=0;i<m;i++) scanf("%d %d",&X[i],&Y[i]),X[i]--,Y[i]--;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(A[i]<A[j]) dp[i][j]=1;
	ll inv=(MOD+1)/2;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j!=X[i]&&j!=Y[i])
			{
				ll s=(dp[j][X[i]]+dp[j][Y[i]])%MOD*inv%MOD;
				dp[j][X[i]]=dp[j][Y[i]]=s;
				s=(dp[X[i]][j]+dp[Y[i]][j])%MOD*inv%MOD;
				dp[X[i]][j]=dp[Y[i]][j]=s;
			}
		}
		ll s=(dp[Y[i]][X[i]]+dp[X[i]][Y[i]])%MOD*inv%MOD;
		dp[X[i]][Y[i]]=dp[Y[i]][X[i]]=s;
	}
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			ret+=dp[i][j];
			if(ret>=MOD) ret-=MOD;
		}
	}
	for(int i=0;i<m;i++) ret=ret*2LL%MOD;
	printf("%lld\n",ret);
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF 1000000000
#define int ll
#define PI (acos(-1))
const ll mod = 1000000007;

string l;
int dp[1000010][2];

signed main() {
    cin >> l;

    // 初期条件
    dp[0][1] = 1;

    for (int i = 0; i < l.size(); i++) {
        int n = l[i] - '0';
        if (n == 0) {
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][0] %= mod;
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][1] %= mod;
        } else {
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][0] %= mod;
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][0] %= mod;
            dp[i + 1][1] += dp[i][1] * 2;
            dp[i + 1][1] %= mod;
        }
    }

    int ans = dp[l.size()][0] + dp[l.size()][1];
      ans%= mod;

    cout << ans << endl;
}

// dp[i][is_smaller] = i文字目まで見たときの場合の数
// 求めるもの: dp[n][0] + dp[n][1]
// 遷移(a+b = a xor bを満たすように)
// if n==0
// is_smaller → is_smaller      0-1 dp[i+1][0] += dp[i][0]*3
// !is_smaller → is_smaller     なし
// !is_smaller → !is_smaller    n dp[i+1][1] += dp[i][1]
// else if n==1
// is_smaller → is_smaller      0-1 dp[i+1][0] += dp[i][0]*3
// !is_smaller → is_smaller     0 dp[i+1][0] += dp[i][1]
// !is_smaller → !is_smaller    n dp[i+1][1] += dp[i][1]*2
// 桁DP

Measured memory_bytes: 2048
n = int(input())
l = list(map(int, input().split()))
ans = 0
num = 1
old_i = 0
for i in range(n):
    if l[i] == num:
        # print(i, num, ans, (i - old_i))
        ans += (i - old_i)
        old_i = i + 1
        num += 1
ans += (i - old_i + 1)
if num == 1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 24920
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int ans = 1;
        for (int i = 2; i <= N; i*=2) {
        	ans = i;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <stdio.h>
#include <math.h>
 
int main(){
    int a,b,c;
    int e=0,t=0,d=0;
    int s=0;
 
    while(1){
	scanf("%d %d %d" ,&a ,&b ,&c);
	if((fabs(a-b) < c && a + b > c)){
	    s++;
	    if((a*a + b*b < c*c)||(a*a + c*c < b*b) ||(b*b + c*c < a*a) ) d++;
	    else  if((a*a + b*b == c*c) ||( a*a + c*c == b*b) || (b*b + c*c == a*a) ) t++;
	    else if((a*a + b*b > c*c) ||(a*a + c*c > b*b) ||(b*b + c*c > a*a)) e++;
	}
	else break;
    }
    printf("%d %d %d %d\n" ,s ,t ,e ,d);
    return 0;
}

Measured memory_bytes: 2672
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}
//小文字=大文字+32
int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(m), b(m);
	vector<vector<int>>ma(n, vector<int>(m,0));
	vector<int>arr(n);
	int ans=0;
	rep(i, n)arr[i] = i;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		ma[a[i]][b[i]]++;
		ma[b[i]][a[i]]++;
	}
	do {
		for (int i = 0; i < n-1; i++) {
			if (ma[arr[i]][arr[i + 1]] == 0) {
				break;
			}
			if (i == n - 2) {
				ans++;
			}
		}

	} while (next_permutation(arr.begin()+1, arr.end()));


	cout << ans;
}


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

void maxHeapify(int a[], int n, int i) {
	int l = i * 2;
	int r = l + 1;
	int largest = i;
	if (l <= n && a[l] > a[largest]) {
		largest = l;
	}
	if (r <= n && a[r] > a[largest]) {
		largest = r;
	}
	if (largest != i) {
		int tmp = a[largest];
		a[largest] = a[i];
		a[i] = tmp;
		maxHeapify(a, n, largest);
	}
}

void buildMaxHeap(int n, int a[]) {
	for (int i = n/2; i >= 1; i--) {
		maxHeapify(a, n, i);
	}
}

int main() {
	int n, i;
	cin >> n;
	int a[n+1];
	for (i=1;i<=n;i++) {
		cin >> a[i];
	}
	buildMaxHeap(n, a);
	for (i=1;i<=n;i++) {
		cout << " " <<  a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5068
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramD
    {
        static List<(int, int)>[] _graph;
        static int[] _res;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            _graph = new List<(int, int)>[n];
            _res = new int[n];
            for (var i = 0; i < n; i++)
            {
                _graph[i] = new List<(int, int)>();
            }

            for (var i = 0; i < n - 1; i++)
            {
                var inputs = Console.ReadLine().Split(" ");
                var u = int.Parse(inputs[0]) - 1;
                var v = int.Parse(inputs[1]) - 1;
                var w = int.Parse(inputs[2]);
                _graph[u].Add((v, w));
                _graph[v].Add((u, w));
            }

            dfs(0, -1, 0);

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(_res[i]);
            }
        }

        static void dfs(int v, int p, int c)
        {
            _res[v] = c;

            foreach (var e in _graph[v])
            {
                if (e.Item1 == p) continue;
                if ((e.Item2 & 1) == 1)
                    dfs(e.Item1, v, 1 - c);
                else
                    dfs(e.Item1, v, c);
            }
        }
    }
}


Measured memory_bytes: 52080
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
count = [0] * 5
for i,j in enumerate(s):
    if j[0] == 'M':
        count[0] += 1
    if j[0] == 'A':
        count[1] += 1
    if j[0] == 'R':
        count[2] += 1
    if j[0] == 'C':
        count[3] += 1
    if j[0] == 'H':
        count[4] += 1
import itertools
ans = 0
for i in itertools.combinations(count, 3):
    ans += i[0] * i[1] * i[2]
print(ans)

Measured memory_bytes: 9772
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string> 
using namespace std;
const int M = 1e5 + 50;
int map[26][M];
int main(){
	string s,t;
	int f = 0;
	cin>>s>>t;
	long long ans = 0;
	for(int i = 0; i < 26; i++)map[i][s.length()] = -1; 
	for(int i = s.length()-1 ; i >=0; i-- ){
		for(int j = 0; j < 26; j++){
			map[j][i] = map[j][i+1];
		}
		map[s[i]-'a'][i] = i;
	}
	int flag = 0;
	int wz = 0;
	for(int i = 0; i < t.length(); i++){
		if(wz == 0 && map[t[i]-'a'][wz] == -1){
			flag = 1;
			break;
		}
		else{
			if( map[t[i]-'a'][wz] != -1 ){
				ans+=map[t[i]-'a'][wz]-wz+1;
				wz = map[t[i]-'a'][wz]+1;
			}
			else{
				ans+=s.length()-wz;
				wz = 0;
				i--;
			}
		}
	}
	if(flag == 1)
		printf("-1\n");
	else{
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 10752
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  int step;
  int direction;
  double x = 0;
  double y = 0;
  int dir = 90;
  while (scanf("%d,%d\n", &step, &direction) != EOF) {
    double angle = dir * 3.1415926535 / 180;
    x += step * cos(angle);
    y += step * sin(angle);
    dir -= direction;
  }
  printf("%d\n", (int)x);
  printf("%d\n", (int)y);

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  string s;
  cin >> s;

  ll m=0;

  for(int l=0;l<n;l++){
    string t=s.substr(l);
    vector<ll> Z(t.size());
    Z[0] = t.size();
    int i = 1, j = 0;
    while(i < t.size()){
      while(i + j < t.size() && t[j] == t[i + j]) j++;
      Z[i] = j;

      if(j == 0){
          i++;
          continue;
      }
      int k = 1;
      while(k < j && k + Z[k] < j){
          Z[i + k] = Z[k];
          k++;
      }
      i += k;
      j -= k;
    }

    for(ll p=1;p<Z.size();p++){
      ll q=min(Z[p],p);
      m=max(m,q);
    }

  }

  cout << m << endl;
  

  // ll l=0;
  // ll r=n;
  // ll h;
  // bool kanou=false;
  // vector<vector<ll>> v;
  // while(abs(r-l)>1){
  //   h=(r+l)/2;

  //   kanou=false;


  //   for(ll i=0;i<n-2*h+1;i++){
  //     for(ll j=i+h;j<n-h+1;j++){
  //       //1つ目の方法(失敗)
  //       // if(s[i]==s[j]){
  //       //   string u,v;
  //       //   u=s.substr(i,h);
  //       //   v=s.substr(j,h);
  //       //   if(u==v){
  //       //     kanou=true;
  //       //     break;
  //       //   }
  //       // }
  //       //2つ目の方法(失敗)
  //       ll m=0;
  //       for(ll k=0;k<h;k++){
  //         if(s[i+k]==s[j+k])m++;
  //         else break;
  //       }
  //       if(m==h){
  //         kanou=true;
  //         v.push_back({i,j});
  //       }
  //     }
  //     //if(kanou)break;
  //   }

  //   if(kanou)break;
  //   else r=h;
  // }

  // //cout << v[0][0] <<v[0][1]<< endl;

  // if(!kanou)h=0;

  // h++;

  // //cout << h << endl;

  // while(!v.empty()){
  //   vector<vector<ll>> u;
  //   for(ll i=0;i<v.size();i++){
  //     if(v[i][1]-v[i][0]==h-1)continue;
  //     if(v[i][1]+h-1==n)continue;
  //     if(s[v[i][0]+h-1]==s[v[i][1]+h-1])u.push_back({v[i][0],v[i][1]});
  //   }
  //   //if(h==4)cout << u[0][0] << " " << u[0][1] << endl;
  //   v=u;
  //   if(!u.empty())h++;
  // }
  // h--;



  // cout << h << endl;

}

Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vvl x(m);
    rep(i, m) {
        ll k;
        cin >> k;
        rep(j, k) {
            ll s;
            cin >> s;
            s--;
            x[i].pb(s);
        }
    }

    vl p(m);
    rep(i, m) {
        cin >> p[i];
    }

    ll ans = 0;
    rep(b, 1<<n) {  // bのiビット目が1のときスイッチiはon
        vl v(n);  // v[i] : 1のときスイッチiはon
        rep(i, n) {
            if(b & (1<<i)) {
                v[i] = 1;
            }
        }
        ll flag = 1;  // すべての電球が点灯するとき1
        rep(i, m) {  // 電球iについて考える
            ll cnt = 0;  // 電球iがつながっているスイッチのうちonになっているものの個数
            rep(j, x[i].size()) {
                if(v[x[i][j]]) {
                    cnt++;
                }
            }
            if(cnt%2 != p[i]) {
                flag = 0;
            }
        }
        if(flag) {
            ans++;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

ll calc(ll a, ll b) {
    a /= b;
    return b * a * (a + 1) / 2;
}

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


Measured memory_bytes: 3648
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin>>s;
  
  int cnt=0;
  int n=s.size();
  rep(i,n){
    if(s[i]=='0') cnt++;
  }
  
  cout<<2*min(cnt,n-cnt)<<endl;
  
  return 0;
}

Measured memory_bytes: 3732
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		int i=0,data;
		String indata;
		while(true){
			indata = s.next();
			data=Integer.parseInt(indata);
			if(data==0)break;
			i++;
			System.out.println("Case "+i+": "+data);
		}
	}
}

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

long long a[12][10];

long long calc(int d) {
  long long tmp = 0;
  for (int i=1; i<10; i++) {
    tmp += a[d][i];
  }
  return tmp;
}
long long search(long long tmp2, int cur, int d, long long cnt) {
  if (d == 0) {
    return tmp2;
  }
  long long tmp = 0;
  if (cur > 0) {
    if (tmp + a[d][cur-1] >= cnt) {
      return search(tmp2*10+cur-1, cur-1, d-1, cnt);
    }
    tmp += a[d][cur-1];
  }
  if (tmp + a[d][cur]>= cnt) {
    return search(tmp2*10+cur, cur, d-1, cnt-tmp);
  }
  tmp += a[d][cur];
  return search(tmp2*10+cur+1, cur+1, d-1, cnt-tmp);
}
int main() {
  int k;
  cin>>k;
  for (int i=0; i<12; i++) {
    for (int j=0; j<10; j++) {
      a[i][j] = 0;
    }
  }
  for (int i=0; i<10; i++) {
    a[1][i] = 1;
  }
  for (int i=2; i<12; i++) {
    for (int j=0; j<10; j++) {
      a[i][j] += a[i-1][j];
      if (j > 0) {
        a[i][j] += a[i-1][j-1];
      }
      if (j < 9) {
        a[i][j] += a[i-1][j+1];
      }
    }
  }
  // for (int i=0; i<3; i++) {
  //   for (int j=0; j<10; j++) {
  //     cout<<a[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  int d = 1;
  long long cnt = 0;
  while (true) {
    long long tmp = calc(d);
    if (cnt -1 + tmp < k) {
      ++d;
      cnt += tmp;
      continue;
    }
    for (int i=1; i<10; i++) {
      if (cnt + a[d][i] >= k) {
        cout<<search(i, i, d-1, k-cnt)<<endl;
        return 0;
      }
      cnt += a[d][i];
    }
    break;
  }
}

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

#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int l; cin >> l;
    double x=(double)l/3;
    cout<<fixed<<setprecision(10)<<x*x*x<<endl;
    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();

            int ans = 0;
            for(int i = 0; i < 4; i++)
            {
                if (N[i] == '2')
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main(){
  int N,T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i=0;i<N;++i) cin >> t[i];
  
  int ans=0;
  for (int i=0;i<N;++i){
    ans+=min(T, t[i]-t[i-1]);
  }
  ans+=T;//これ忘れた
  cout << ans << endl;
}

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

int main()
{
    int t=1;


    while(t--){
        int n;
        cin >> n;
         n=n%1000;
         if(n==0)
         cout << "0" << endl;
         else cout <<1000-n<<endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
int n,a,x,y,i;
int main(){ 
	for(scanf("%d",&n);i++<n;a%4?a%2?0:y++:x++) {  scanf("%d",&a); } 
	printf(x+y/2+1>n/2 ?"Yes\n"  :"No\n");return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int cnt=0,n,s;
void func(int sum,int depth,int x){
    int i;
    if(depth>n){
        if(sum==s){
            cnt++;
        }
        return;
    }
    for(i = x;i < 10;i++){
        //if(sum+i>s)return;

        func(sum+i,depth+1,i+1);
    }
}
int main(void){
    while(scanf("%d %d",&n,&s),n || s){
        cnt = 0;
        func(0,1,0);
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
struct Edge{
	int to,nxt;
}edge[4010];
struct Point{
	int fa,size,sum,tot,val;
}point[2010];
int head[2010],cnt,n,x,y,ans;
char s[2010];
void addedge(int x,int y){
	edge[++cnt].to=y;
	edge[cnt].nxt=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa){
	point[x].fa=fa;
	point[x].size=1;
	point[x].sum=point[x].val;
	point[x].tot=0;
	for(int i=head[x];i;i=edge[i].nxt){
		int upup=edge[i].to;
		if(upup==fa)continue;
		dfs(upup,x);
		point[x].size+=point[upup].size;
		point[x].sum+=point[upup].sum;
		point[x].tot+=point[upup].sum+point[upup].tot;
	}
}
int Dfs(int x){
	int maxn=0,id;
	for(int j=head[x];j;j=edge[j].nxt){
		int upup=edge[j].to;
		if(upup==point[x].fa)continue;
		if(maxn<point[upup].tot+point[upup].sum)
			maxn=point[upup].tot+point[upup].sum,id=upup;
	}
	if(maxn<=point[x].tot-maxn)return 0;
	int y=point[x].tot-maxn;
	maxn=Dfs(id)+point[id].sum;
	if(maxn<=y)return 0;
	return maxn-y;
}
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	for(int i=1;i<=n;i++)
		point[i].val=s[i]-'0';
	ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		dfs(i,0);
		if(point[i].tot%2==1)continue;
		if(Dfs(i)==0)ans=std::min(ans,point[i].tot/2);
	}
	if(ans==0x3f3f3f3f)puts("-1");
	else printf("%d\n",ans);
}

Measured memory_bytes: 384
N, M = map(int, input().split())
inf = 10**18
edges = []

for m in range(M):
    a, b, c = map(int, input().split())
    edges.append((a-1, b-1, -c))

dist = [inf]*N
dist[0] = 0
update = False
for i in range(N):
    for a, b, c in edges:
        if dist[b]>dist[a]+c:
            dist[b] = dist[a]+c
            if b==N-1 and i==N-1:
                update = True

if update:
    print('inf')
else:
    print(-dist[N-1])

Measured memory_bytes: 3316
use std::io::*;
const MOD: u64 = 1_000_000_007;

mod enumeration {
    pub struct Enumeration {
        fact: Vec<u64>,
        finv: Vec<u64>,
        modulo: u64,
    }
    impl Enumeration {
        pub fn new(n: usize, modulo: u64) -> Enumeration {
            let mut fact: Vec<u64> = vec![1; n];
            let mut inv: Vec<u64> = vec![1; n];
            let mut finv: Vec<u64> = vec![1; n];
            for i in 2..n {
                fact[i] = fact[i - 1] * (i as u64) % modulo;
                inv[i] = modulo - (modulo / (i as u64)) * inv[(modulo as usize % i)] % modulo;
                finv[i] = inv[i] * finv[i - 1] % modulo;
            }
            Enumeration {
                fact: fact,
                finv: finv,
                modulo: modulo,
            }
        }
        pub fn c(&self, n: usize, k: usize) -> u64 {
            if n < k {
                return 0;
            }
            self.fact[n] * self.finv[n - k] % self.modulo * self.finv[k] % self.modulo
        }
    }
}

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();

    let en = enumeration::Enumeration::new(h + w + 1, MOD);
    let mut ans = 0;
    for i in 1..w - b + 1 {
        ans =
            (ans + en.c(b + i + h - a - 2, h - a - 1) * en.c(a - 1 + w - b - i, a - 1) % MOD) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int X; cin>>X;
    if (X==3) {
        cout<<"YES"<<endl;
        return 0;
    }
    if (X==5) {
        cout<<"YES"<<endl;
        return 0;
    }
    if (X==7) {
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256