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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	ll n, s = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i % 3 != 0 && i % 5 != 0)
			s += i;
	}
	cout << s;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int W=sc.nextInt();
		int H=sc.nextInt();
		int N=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();
		int cost=0;
		for(int i=0; i<N-1; i++) {
			int tmpx=sc.nextInt();
			int tmpy=sc.nextInt();
			if(x<tmpx && y<tmpy) {//斜めが使える時
				int tmpcost=Math.max(tmpx-x, tmpy-y);
				cost+=tmpcost;
			}
			else if(x>tmpx && y>tmpy) {
				int tmpcost=Math.max(x-tmpx, y-tmpy);
				cost+=tmpcost;
			}
			else {
				cost+=Math.abs(tmpx-x)+Math.abs(tmpy-y);
			}
			x=tmpx;
			y=tmpy;
		}
		pl(cost);
	}

	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 24988
n,m=input().split()
n,m=int(n),int(m)
#辞書に気づけ
b={}
for i in range(n):
    x=input().split()
    for j in range(int(x[0])):
        if int(x[j+1]) not in b:
            b[int(x[j+1])]=1
        else:
            b[int(x[j+1])]+=1
c=0
for i in b:
    if b[i]==n:
        c+=1
print(c)


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

divisors = []
ans = 0
# # cは正の整数である
# for i in range(1, N+1):
#     for j in range(1, N+1):
#         for c in range(1, N+1):
#             if i*j+c == N:
#                 print(i, j, c)
#                 ans += 1

for i in range(1, N):  # 1~N-1まで見る
    divisors.append([i, N//i])

for a, b in divisors:
    if a*b == N:
        ans += b-1
    else:
        ans += b
print(ans)


Measured memory_bytes: 191240
# Template 1.0
import sys, re
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor, trunc
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = map(Decimal, input().split())

i = Decimal(a)*Decimal(b)

print(int(i))

Measured memory_bytes: 72808
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;

int main()
{
	in >> S;
	if (S[0] == S[1] && S[1] == S[2]) { out << "Yes" << std::endl; }
	else if (S[1] == S[2] && S[2] == S[3]) { out << "Yes" << std::endl; }
	else { out << "No" << std::endl; }
	return 0;
}

Measured memory_bytes: 256
// ?????????.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <iostream>
#include <string>
using namespace std;

int main()
{
	
	while (true) {
		string s1;
		string s2;
		cin >> s1;
		if (s1 == ".")
			break;
		cin >> s2;
		if (s1 == s2) {
			cout << "IDENTICAL" << endl;
			continue;
		}
		string t1 = s1;
		string t2 = s2;
		while (true) {
			size_t d1b = t1.find('\"');
			if (d1b == string::npos)
				break;
			t1.replace(d1b, 1, "@");

			size_t d1e = t1.find('\"');
			t1.replace(d1e, 1, "@");

			size_t d2b = t2.find('\"');
			if (d2b == string::npos)
				break;
			t2.replace(d2b, 1, "@");

			size_t d2e = t2.find('\"');
			t2.replace(d2e, 1, "@");

			string u1 = s1;
			u1.replace(d1b + 1, d1e - d1b - 1, "");
			string u2 = s2;
			u2.replace(d2b + 1, d2e - d2b - 1, "");

			if (u1 == u2) {
				t1 = u1;
				t2 = u2;
				break;
			}

		}
		if (t1 == t2) {
			cout << "CLOSE" << endl;
		}
		else{
				cout << "DIFFERENT" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
//	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		int dp[n+1]={0};
		int arr[n];
		//arr[0]=0;
		rep(i,n){
			cin>>arr[i];
		}
		dp[0]=0;
		dp[1]=abs(arr[1]-arr[0]);
		for(int i=2;i<n;i++){
			dp[i]=INT_MAX;
			int s=max(0ll,i-k);
			REP(j,s,i){
			dp[i]=min(abs(arr[i]-arr[j])+dp[j],dp[i]);
			}
		}
		cout<<dp[n-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(i,arr)       for(int& i:arr)cin>>i;
#define output(i,arr)      for(int& i:arr)cout<<i<<" ";
#define for_each(arr)      for(auto& it:arr)
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    //#ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
   // //freopen("output.txt","w",stdout);
   // #endif
    ll m;
    cin>>a>>b>>m;
    vector<int>v(a),v1(b),v2;
    int maxn=1e9;
    int mn1=1e9,mn2=1e9;
    for(int i=0;i<a;i++){
    	cin>>v[i];
    	mn1=min(mn1,v[i]);
    }
    for(int i=0;i<b;i++){
    	cin>>v1[i];
    	mn2=min(mn2,v1[i]);
    }
    
    v2.push_back(mn1+mn2);
    int x,y;
    for(int i=1;i<=m;i++){
    	cin>>x>>y>>c;
    	v2.push_back(v[x-1]+v1[y-1]-c);
    }
    sort(all(v2));
    
  // for(auto it:v2)cout<<it<<" ";
   // 	cout<<endl;
    cout<<v2[0]<<endl;

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


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

int main() {
  int n;
  cin>>n;
  int la=0,lb=0,mina=1000000000,minb=1000000000;
  long long suma=0,sumb=0;
  rep(i,n){
    int a;
    cin>>a;
    if(a<0){
      la++;
      if(mina>-a) mina=-a;
      suma-=a;
    }
    else{
      lb++;
      if(minb>a) minb=a;
      sumb+=a;
    }
  }
  
  if(la%2==0)
    cout<<suma+sumb<<endl;
  else{
    if(mina>minb)
      cout<<suma+sumb-2*minb<<endl;
    else
      cout<<suma+sumb-2*mina<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

int main(){
    string s,t;
    while(cin >> s >> t){
        if(s==".") return 0;
        vector<string> p,q;
        string tmp="";
        for(int i=0;i<s.length();i++){
            if(s[i]=='"'){
                p.push_back(tmp);
                tmp="";
            }
            else tmp.push_back(s[i]);
        }
        p.push_back(tmp);
        tmp="";
        for(int i=0;i<t.length();i++){
            if(t[i]=='"'){
                q.push_back(tmp);
                tmp="";
            }
            else tmp.push_back(t[i]);
        }
        q.push_back(tmp);
        if(p.size()!=q.size()){
            puts("DIFFERENT");
            continue;
        }
        int u=0,v=0,c=0;
        while(u<p.size()){
            if(p[u]!=q[v]){
                if(u%2==0){
                    c=2;
                    break;
                }
                else{
                    c++;
                    u++,v++;
                }
            }
            else{
                u++,v++;
            }
        }
        if(c==0) puts("IDENTICAL");
        else if(c==1) puts("CLOSE");
        else puts("DIFFERENT");
    }
    return 0;
}


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

int main() {
    std::string s[3];
    std::cin >> s[0] >> s[1] >> s[2];

    size_t p[3] = {0};
    int cur = 0;
    while (true) {
        if (p[cur] == s[cur].size()) {
            std::printf("%c\n", cur + 'A');
            return 0; 
        }

        const char c = s[cur][p[cur]];
        p[cur] += 1;

        cur = c - 'a';
    }

    return 0;
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



signed main()
{
	int64_t a,b; cin >> a >> b;
	if(a%2 != b%2){
		cout << "IMPOSSIBLE" << endl;
	}
	else
	{
		cout << (a+b)/2 << endl;
	}
	
	
}

Measured memory_bytes: 256
while True:
    table = input().split()
    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break
    if op == '+':
        print(int(a+b))
    elif op == '-':
        print(int(a-b))
    elif op == '*':
        print(int(a*b))
    else:
        print(int(a//b))


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
    ll n;
    ll mo=1000;
    ll kb=0;
    ll ans=1000;
   
    cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];
    rep(i,n){
        ll ansi;
        if(i!=n-1){
           if(a[i]>a[i+1]){
              mo+=kb*a[i];
              ansi=mo;
              kb=0;
              kb=mo/a[i+1];
              mo-=kb*a[i+1];
           }
           else{
               int x=mo/a[i];
               kb+=x;
               mo-=a[i]*x;
               mo+=kb*a[i+1];
               ansi=mo;
               kb=0;
               
           }
           
        }
        ans=max(ans,ansi);
    }
    cout<<ans<<endl;
  

}


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

int n;
double dp[M][M][M];

double f(int a, int b, int c)
{
    if(a < 0 || b < 0 || c < 0) return 0;
    if(a == 0 && b == 0 && c == 0) return 0;
    if(dp[a][b][c] > -.5) return dp[a][b][c];

    dp[a][b][c] = 1+f(a-1, b, c)*a/n+f(a+1, b-1, c)*b/n+f(a, b+1, c-1)*c/n;
    dp[a][b][c] *= 1.0*n/(a+b+c);

    return dp[a][b][c];
}

int main()
{
    scanf("%d", &n);

    int a = 0, b = 0, c = 0;

    for(int i = 1; i <= n; i++)
    {
        int p;
        scanf("%d", &p);

        if(p == 1) a++;
        else if(p == 2) b++;
        else c++;
    }

    for(int i = 0; i < M; i++)
    {
        for(int j = 0; j < M; j++)
        {
            for(int k = 0; k < M; k++) dp[i][j][k] = -1;
        }
    }

    printf("%.12lf\n", f(a, b, c));

    return 0;
}

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

#define ll long long
#define rep(i,n) for(int i = 0;i < (n); i++)
#define mod 1000000007

int main() {
	int n;

    cin >> n;
    int a[15];
    int x[15][15]; int y[15][15];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        for (int j = 0; j < a[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int ok = 1;
        for (int i = 0; i < n; i++)
        {
            if ((bit >> i) & 1){
                for (int j = 0; j < a[i]; j++)
                {
                    if (((bit >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = 0;
                }
            }
        }
        if (ok) {
            int count = 0;
            rep(i, n) {
                if ((bit >> i) & 1)count++;
            }
            ans = max(ans, count);
        }
    }
    cout << ans << endl;
	return 0;
}

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

int count(int n, int s, int u[]){
	int sum = 0;
	if(n == 1){
		if(s >= 0 && s <= 9 && u[s]) return 1;
		else return 0;
	}
	if(s < 0 || s > 9 * n * (n + 1) / 2) return 0;
	for(int i = 0; i < 10; i++){
		if(u[i]){
			u[i] = 0;
			sum += count(n - 1, s - i * n, u);
			u[i] = 1;
		}
	}
	return sum;
}

int main(){
	int n;
	int u[] = {
		1, 1, 1, 1, 1,
		1, 1, 1, 1, 1
	};
	int s;
	while(cin >> n >> s){
		cout << count(n, s, u) << endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
#define input(N) cin >> N;
#define output(N) cout << N << endl;
#define vector_input(A, N) for (int i = 0; i < N; i++) cin >> A.at(i);
#define vector_output_endl(A, N) for (int i = 0; i < N; i++) cout << A.at(i) << endl;
#define vector_output(A, N) for (int i = 0; i < N; i++) {cout << A.at(i); if (i != N - 1) cout << ' ';} cout << endl;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    long long N;
    cin >> N;
    vector<long long>A(N);
    vector_input(A, N);
    sort(A.begin(), A.end());
    vector<long long>length, square;
    length.push_back(0);
    length.push_back(0);
    square.push_back(0);
    vector<pair<long long, long long> >P;
    P.push_back(make_pair(A.at(0), 1));
    long long j = 0;
    rep(i, N - 1) {
        if (A.at(i + 1) == A.at(i)) P.at(j).second++;
        else {
            P.push_back(make_pair(A.at(i + 1), 1));
            j++;
        }
    }
    rep(i, P.size()) {
        if (P.at(i).second >= 4) square.push_back(P.at(i).first);
        if (P.at(i).second >= 2) length.push_back(P.at(i).first);
    }
    sort(length.begin(), length.end(), greater<long long>());
    sort(square.begin(), square.end(), greater<long long>());
    output(max(length.at(0) * length.at(1), square.at(0) * square.at(0)));
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
int main() {
    // 前処理
    COMinit();
	int n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1;i<n;i++)
	{
		if(i*3>n)break;
		ll now = n-i*3;
		ans += COM(i-1+now,i-1);
		ans %= MOD;
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 15568
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
using namespace std;

int main( void) {
  int N=0;
  long wa=1e9+7;
  long power=1;
  cin >> N;
  for (int i=1; i<=N; i++){
    power=(power*i)%wa;
  }
  power=power%wa;
  cout << power;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long

using namespace std;

ll freq[60];
ll sum[60];

int main() {
    ll n;
    cin >> n;
    //vector<ll> freq(61,0);
    //vector<ll> sum(61,0);
    vector<ll> ar;
    for (ll i = 0; i < n; i++) {
        ll a;
        cin >> a;
        for (ll j = 0; j < 60; j++) {
            freq[j] += (a >> j) & 1;
        }
        ar.push_back(a);
    }
    for (auto s: ar) {
        for (ll j = 0; j < 60; j++) {
            if ((s >> j) & 1) {
                sum[j] += n - freq[j];
                freq[j]--;
            }
            else {
                sum[j] += freq[j];
            }
        }
        n--;
    }
    ll ans = 0;
    for (ll i = 0; i < 60; i++) {
        ll p2 = (1LL << i) % MOD;
        sum[i] %= MOD;
        ll rs = (p2 * sum[i]) % MOD;
        ans = (ans + rs) % MOD;
    }
    cout << ans << endl;
}


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

int main(void) {
  lli n,m;
  cin >> n >> m;
  
  bool ac[100010];
  rep(i,100011){ac[i]=0;}
  
  lli accnt = 0;
  lli wacnt[100010];
  lli waans = 0;
  rep(i,100011){wacnt[i]=0;}
  rep(i,m){
    lli qnum = 0;
    string ans;
    cin >> qnum >> ans;
    if(ans == "WA"&&ac[qnum] == 0){
      wacnt[qnum]++;
    }else if(ans == "AC"&&ac[qnum] == 0){
      ac[qnum] = 1;
      waans+=wacnt[qnum];
      accnt++;
    }
  }

  cout << accnt << " " << waans << endl;

  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,o,a,b;
    cin >> a >> b;
    n=a+b;
    m=a-b;
    o=a*b;
    if(n>=m && n>=o){
        cout << n << endl;
    }
    else if(m>=n && m>=o){
        cout << m << endl;
    }
    else{
        cout << o << endl;
    }
}

Measured memory_bytes: 256
a,b,h,m = gets.split.map(&:to_i)

h_kaku = (h/12.0 + m/(60.0*12)) * 360
m_kaku = (m/60.0) * 360

kaku = (m_kaku - h_kaku).abs
if kaku >= 180
  kaku = 360 - kaku
end

puts (a**2 + b**2 - (2 * a * b * Math.cos(kaku/180.0 * Math::PI)))**(1/2.0)

Measured memory_bytes: 14888
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int k,x;

    cin >> k >> x;

    bool ans = k * 500 >= x;

    if(ans){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  int sheet[r+1][c+1];
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> sheet[i][j];
  for (int i = 0; i < r; i++) {
    int tmp = 0;
    for (int j = 0; j < c; j++) {
      tmp += sheet[i][j];
    }
    sheet[i][c] = tmp;
  }
  for (int i = 0; i < c+1; i++) {
    int tmp = 0;
    for (int j = 0; j < r; j++) {
      tmp += sheet[j][i];
    }
    sheet[r][i] = tmp;
  }
  for (int i = 0; i < r+1; i++) {
    for (int j = 0; j < c; j++) {
      cout << sheet[i][j] << " ";
    }
    cout << sheet[i][c] << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;


int main() {
	makev(v, 3);
	sort(all(v));
	if (v[0] == v[1] && v[1] == v[2]) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}






Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

fn main() {
    input! {
    a: usize,
    b: usize,
    c: usize
    }
    let ans = max(10 * a + b + c, max(10 * b + a + c, 10 * c + a + b));
    println!("{}", ans);
}


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

#define MAX_N 100 + 1

void insertionSort(int* a, int n);
void printA(int* a, int n);

int main() {
  int a[MAX_N], n;
  
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  printA(a, n);
  insertionSort(a, n);

  return 0;
}

void insertionSort(int* a, int n) {
  for (int i = 1; i < n; ++i) {
    int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;

    printA(a, n);
  }
}

void printA(int* a, int n) {
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 < n) { cout << ' '; }
  }
  cout << '\n';
}

Measured memory_bytes: 1164
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num){
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2){
		if (num % i == 0) return false;
	}
	return true;
}

int main() {
	ll N, M, K; cin >> N >> M >> K;

	for (int k = 0; k <= N; k++) {
		for (int l = 0; l <= M; l++) {
			if (k * M + l * N - 2 * k * l == K) {
				cout << "Yes"<<endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> six(8), nine(8), dp(n + 1);
    six[0] = 1; nine[0] = 1;
    for (int i = 1; i < 8; i++) {
        six[i] = six[i - 1] * 6;
        nine[i] = nine[i - 1] * 9;
    }
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1] + 1;
        for (int j = 1; j < 8; j++) {
            if (i >= six[j])
                dp[i] = min(dp[i], dp[i - six[j]] + 1);
            if (i >= nine[j]) {
                dp[i] = min(dp[i], dp[i - nine[j]] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    // if sort is required
    sort(res.begin(), res.end());
    return res;
}

void Main() {
	int N; cin >> N;
	int res = 0;
	for (int i = 1; i <= N; i += 2) {
		if (divisor(i).size() == 8) ++res;
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
using namespace std;
const int maxn = 100005;
int n,m,h[maxn],mark[maxn],ee=1,vis[maxn];
struct Edge{
	int v,next;
}e[4*maxn];
void addedge(int u,int v){
	e[ee]=Edge{v,h[u]};
	h[u]=ee++;
}
void dfs(int u){
	vis[u]=1;
	for(register int i=h[u];i;i=e[i].next){
		if(vis[e[i].v])continue;
		dfs(e[i].v);
	}
}
queue<int> Q;
void bfs(){
	Q.push(1);
	mark[1]=1;
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(register int i=h[u];i;i=e[i].next){
			if(!mark[e[i].v]){
				mark[e[i].v]=u;
				Q.push(e[i].v);
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	FOR(i,0,m){
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs(1);
	int failed=0;
	FOR(i,1,n+1){
		if(!vis[i]){
			failed=1;
			break;
		}
	}
	if(failed)printf("No\n");
	else {
		bfs();
		printf("Yes\n");
		FOR(i,2,n+1)printf("%d\n",mark[i]);
	}
}

Measured memory_bytes: 9340
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        String s = "0" + n;
        
        char[] ch = s.toCharArray();
        int[] a = new int[ch.length];
        for (int i = 0; i < ch.length; i++) {
            a[i] = ch[i] - '0';
        }

        int ans = 0;
        for (int i = a.length - 1; i > 0; i--) {
            if (a[i] == 5 && a[i - 1] >= 5) {
                a[i - 1]++;
                a[i] -= 10;
            } else if (a[i] > 5) {
                a[i - 1]++;
                a[i] -= 10;
            }
            ans += Math.abs(a[i]);
        }
        ans += Math.abs(a[0]);

        System.out.println( ans );
    }
    
}


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


long long lcm( long long a , long long b ){
	return (a*b) / __gcd(a,b);
}

int main(){

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	long long n,m;
	cin>>n>>m;

	int odd=0 , even=0;
	long long l = 1;

	vector<long long> v(n);
	for(int i=0 ; i<n ; ++i){
		long long x;
		cin>>x;

		v[i] = x;
		x /= 2;
		if( x%2 == 0 ) even++;
		else odd++;

		l = lcm(l,2*x);
		if(l > 2*m )	odd++ , even++;

	}

	for(int i=0 ; i<n ; ++i)
		if( (l/v[i])%2 == 0 ) even++ , odd++;

	if( odd > 0 && even > 0 )
		cout<<0<<'\n';
	else
		cout<< (m-(l/2))/(l) + 1 << '\n';

}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[1010];
int l;
int fl,ag;
int main()
{
	scanf("%s",s+1);
	l=strlen(s+1);
	for(int i=1;i<=l;i++)
	{
		if(s[i]=='C') fl=1;
		if(s[i]=='F'&&fl==1) ag=1; 
	}
	if(ag==1) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(100001);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		b[a[i]]++;
	}
	int ans = 0;
	for (int i = 1; i < 100000; i++) {
		ans = max(ans, b[i - 1] + b[i] + b[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

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

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
int main()
{
    int n;
    cin>>n;
    long long int s=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                s=s+gcd(i,gcd(j,k));
            }
            
        }
    }
    
    cout<<s<<endl;
    return 0;
}


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

int main(){
  string s,t;
  int n;
  cin >> s >> t;
  n = s.length();
  for(int i=0;i<n;i++){
    if(s == t.substr(i) + t.substr(0, i)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll dp[1000010][5];

int main(){
  ll N;
  string S;
  ll Q;
  cin >> N >> S >> Q;
  vector<ll> k(Q),ans(Q);
  rep(i,Q) cin >> k[i];
  rep(j,Q){
    dp[0][0] = 0;
    ll D = 0,M = 0,K = k[j];
    rep(i,N){
      if(S[i] == 'D'){
        D++;
        dp[i+1][0] = dp[i][0] + 1;
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2];
        if(i - K >= 0){
          if(S[i-K] == 'D'){
            D--;
            dp[i+1][0]--;
            dp[i+1][1] -= M;
          }
          if(S[i-K] == 'M') M--;
        }
      }else if(S[i] == 'M'){
        M++;
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1] + dp[i][0];
        dp[i+1][2] = dp[i][2];
        if(i - K >= 0){
          if(S[i-K] == 'D'){
            D--;
            dp[i+1][0]--;
            dp[i+1][1] -= M;
          }
          if(S[i-K] == 'M') M--;
        }
      }else if(S[i] == 'C'){
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2] + dp[i][1];
        if(i - K >= 0){
          if(S[i-K] == 'D'){
            D--;
            dp[i+1][0]--;
            dp[i+1][1] -= M;
            dp[i+1][2] -= M;
          }
          if(S[i-K] == 'M') M--;
        }
      }else{
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2];
        if(i - K >= 0){
          if(S[i-K] == 'D'){
            D--;
            dp[i+1][0]--;
            dp[i+1][1] -= M;
          }
          if(S[i-K] == 'M') M--;
        }
      }
    }
    ans[j] = dp[N][2];
  }
  rep(i,Q) cout << ans[i] << endl;
}


Measured memory_bytes: 40452
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N=2e5+10,mo=1e9+7;
ll f[N],n,m,lim,q[N];
char s[N];
void move(ll &a,ll b){a=(a+b)%mo;}
int main(){
	cin>>n>>m;
	scanf("%s",s+1);
	if (s[1]=='B'){
		for (ll i=1;i<=m;i++)s[i]='B'+'R'-s[i];
	}
	ll cnt=0;
	for (ll i=1;i<=m;i++){
		if (s[i]=='R')cnt++;
		else {
			if (!lim)lim=cnt|1;
			else if (cnt&1)lim=min(lim,cnt);
			cnt=0;
		}
	}
	if (!lim){
		for (int i=1;i<=n;i++){
			move(f[i],q[i-2]+i-(i==1));
			q[i]=(q[i-1]+f[i])%mo;
		}
		cout<<f[n]+1<<endl;
		return 0;
	}
	lim++;
	for (ll i=1;i<=n;i++){
		f[i]=q[i-2];
		if (i<=lim&&(i%2==0))move(f[i],i);
		q[i]=((ll)q[i-2]+f[i]-(i>lim?f[i-lim]:0)+mo)%mo;
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int
main(void)
{
#define unknown 0
#define up 1
#define down 2
    int trend = unknown;
    int count = 0;
    int n;
    scanf("%d", &n);
    if (n <= 2) {
        printf("1\n");
        exit(0);
    }
    int prev;
    scanf("%d", &prev);
    int i;
    for (i = 1; i < n; ++i) {
        int current;
        scanf("%d", &current);
        switch (trend) {
        case up:
            if (prev > current) {
                count++;
                trend = unknown;
            }
            break;
        case down:
            if (prev < current) {
                count++;
                trend = unknown;
            }
            break;
        default:
            if (prev > current)
                trend = down;
            else if (prev < current)
                trend = up;
            break;
        }
        prev = current;
    }
    count++;
    printf("%d\n", count);
    return 0;
}

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

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//#define int long long
#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define P(p) cout << (p) << endl;
#define S(s) cin << (s);
#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,n)
#define repst(i,a,b) rep(i,s,(n)+1)
#define rept(i,n) rep(i,(n)+1)
#define reprt(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define repr(i,n) reprt(i,n,0)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define debug(x) cerr << #x << ": " << x << '\n'
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

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

/*********TEMPLATE**********/

int main() {
  int n;
  cin>>n;
  int a[n];
  for (auto& e : a) cin>>e;

  int cur=0, i=0;
  while(1) {
    if (cur==1) {
      cout << i << ln;
      break;
    }
    if (i>=n) {
      cout << -1 << ln;
      break;
    }
    i++;
    cur = a[cur]-1;
  }

  return 0;
}


Measured memory_bytes: 640
/**Bismillahir Rahmanir Rahim  *///{
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
#define im(a, b) if (a>=b) a -= b; else if (a<0) a += b;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    *this << "\n[";
    for (auto &elem : x) *this << elem << ", ";
    return *this << "]";
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << "{" << x.first << ", " << x.second << "}";
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args ...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(string(#args)), args), dbg << endl
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int n, m, K, T, Q, cn;//}
const int inf = 1000000007, mxn = 205;

pair<int, int> a[mxn];

ll euclid(ll x, ll y) {
    return x*x+y*y;
}

double angle(const pair<int, int> &x) {
    return atan2(x.second, x.first);
}

struct cmp { bool operator() (const pair<int, int> &ls, const pair<int, int> &rs) const {
    return angle(ls)<angle(rs);
}};

int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.precision(11);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a+n, cmp());
    for (int i = 0; i < n; i++) {
        a[i+n] = a[i];
    }
    ll mx = 0;
    for (int i = 0; i < n; i++) {
        ll curx = 0, cury = 0;
        for (int j = i; j <= i+n-1; j++) {
            curx += a[j].first, cury += a[j].second;
            mx = max(mx, euclid(curx, cury));
        }
    }
    cout << sqrt(mx) << '\n';
}

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

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

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



struct COMB {
	static constexpr ll LIM = 200'000;
	COMB() { make_contents(); }

	//繰り返し累乗法
	ll mod_pow(ll x, ll n, ll mod) {
		ll res = 1;
		while (n > 0) {
			if (n & 1)res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}

	void make_contents()
	{
		ll tmp = 1;
		fact.push_back(0);
		FOR(i, 1, LIM) {
			tmp *= i;
			tmp %= MOD;
			fact.push_back(tmp);
		}

		tmp = mod_pow(tmp, MOD - 2, MOD);
		//inv.push_back(tmp);
		for (ll i = LIM - 1; i > 0; i--) {
			tmp *= i;
			tmp %= MOD;
			inv.push_back(tmp);
		}
		reverse(inv.begin(), inv.end());
		fact[0] = inv[0] = 1;
		/*正当性確認
		REP(i, LIM) {
			cerr << (fact[i] * inv[i]) % MOD << endl;
		}
		*/
	}

	ll comb(ll n, ll k) {
		ll res = fact[n];
		res *= inv[k]; res %= MOD;
		res *= inv[n - k]; res %= MOD;
		return res;
	}

	vector<ll> fact, inv;
};



int main()
{
	ll N, ta, tb, tc;
	cin >> N >> ta >> tb >> tc;

	COMB comb;
	ll A = ta, B = tb, C = tc;
	//pair<ll, ll>A = { ta,100 }, B = { tb,100 }, C = { tc,100 };

	map<ll, pair<ll, ll>> mp;

	ll an = comb.mod_pow(A, N, MOD);
	ll bn = comb.mod_pow(B, N, MOD);
	ll base = comb.mod_pow(A + B, N, MOD);
	ll ai = 1;
	ll bi = 1;
	FOR(i, N, 2 * N) {
		ll up = (an * bi + ai * bn) % MOD;
		(up *= comb.comb(i - 1, i - N)) %= MOD;
		mp[i] = { up, base };
		(base *= A + B) %= MOD;
		(ai *= A) %= MOD;
		(bi *= B) %= MOD;
	}

	ll res = 0;
	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		ll eval = itr->first;
		ll up = itr->second.first;
		ll base = itr->second.second;

		ll tmp = (eval*up) % MOD;
		tmp = (tmp*comb.mod_pow(base, MOD - 2, MOD)) % MOD;
		res = (res + tmp) % MOD;
	}
	//mup = comb.mod_pow(mup, MOD - 2, MOD);
	//(res *= mup) %= MOD;
	//(res *= mbase) %= MOD;

	res = (res * 100) % MOD;
	//res = (res*(A + B)) % MOD;
	res = (res* comb.mod_pow(A + B, MOD - 2, MOD)) % MOD;
	cout << res << endl;

	return 0;
}


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

signed main(){
  int N;cin>>N;
  string s;cin>>s;
  int x=0,y=0;
  for(char p:s){
    if(p>='A'&&p<='M')y++;
    if(p>='N'&&p<='Z')y--;
    if(p>='a'&&p<='m')x++;
    if(p>='n'&&p<='z')x--;
  }
  cout<<abs(x)+abs(y)<<endl;
  if(x>0)while(x--)cout<<'a';
  else while(x++)cout<<'n';
  if(y>0)while(y--)cout<<'A';
  else while(y++)cout<<'N';
  cout<<endl;
}



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

int main() {
    using namespace std;
    long N;
    long X, D;
    cin >> N >> X >> D;
    if(D < 0){
        X += D * (N - 1);
        D *= -1;
    }
    if(D == 0){
        if(X == 0)return 0 & puts("1");
        cout << N + 1 << endl;
        return 0;
    }
    vector<pair<long, pair<long, long>>> p(N + 1UL);
    auto x = (X % D + D) % D;
    for(long i = 0; i <= N; ++i){
        auto t = (x * i) % D;
        auto k = (X * i - t) / D;
        assert(t < D && 0 <= t);
        assert(k * D + t == X * i);
        p[i] = {t, pair<long, long>({k + i * (i - 1) / 2, k + i * (2 * N - i - 1) / 2 + 1})};
    }
    sort(p.begin(), p.end());
    vector<pair<long, pair<long, long>>> q;
    for(const auto& i : p){
        if(q.empty())q.push_back(i);
        else if(i.first != q.back().first)q.push_back(i);
        else if(q.back().second.second >= i.second.first)q.back().second.second = max(q.back().second.second, i.second.second);
        else q.push_back(i);
    }
    long ans{0};
    for(const auto& i : q)ans += i.second.second - i.second.first;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13168
#include <iostream>
#include <bitset>
using namespace std;
bitset<1000000> p;
int main(){
  p.flip();
  p[0] = 0;
  p[1] = 0;
  for(int i = 2; i < 1000; ++i){
    if(p[i]){
      for(int j = 2*i; j < 1000000; j += i) p[j] = 0;
    }
  }
  int n;
  while(cin >> n){
    int ret = 0;
    for(int i = 2; i <= n; ++i) ret += p[i];
    cout << ret << '\n';
  }
  return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i=0; i<h; ++i){cin >> s[i];}

    int res = 0;
    for(int is=0; is<(1<<h); ++is){
        for(int js = 0; js<(1<<w); ++js){
            int cnt = 0;
            for(int i=0; i<h; ++i){
                for(int j=0; j<w; ++j){
                    if(is&(1<<i)){continue;}
                    if(js&(1<<j)){continue;}
                    if(s[i][j]=='#'){cnt++;}
                }
            }
            if(cnt==k){res++;}
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3628