akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

long long nibeki(long long n){
  int k = 0;
  while(n % 2 == 0){
    k++;
    n /= 2;
  }
  return k;
}

int main()
{
  int n;
  cin >> n;
  long long ans = 0;
  long long a[10001];
  for(int i = 0; i < n; i++){
    cin >> a[i];
    ans += nibeki(a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (unsigned lld)1e18
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

int main()
{
	fastio
	unsigned lld n;
	cin>>n;

	std::vector<unsigned lld> v(n);

	unsigned lld ans=1,prevans=0;

	for(lld i=0;i<n;i++)
		cin>>v[i];

	sort(v.begin(), v.end());

	for(lld i=0;i<n;i++)
	{
		ans=ans*v[i];

		if(ans>MAX || ans<prevans)
		{
			cout<<"-1"<<endl;
			return 0;
		}

		prevans=ans;
	}

	cout<<ans<<endl;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
char d[10];
int n,k;
int main()
{
	cin >>n>>k;
	for(int i=0;i<k;i++)
	{
		char f;
		cin >>f;
		d[f-'0']=1;
	}
//	for(int i=0;i<10;i++)
//	cout <<d[i];
	for(int i=n;i<100000;i++)
	{
		string s=to_string(i);
		for(int j=0;j<s.size();j++)
		if(d[(s[j]-'0')]==1)
		goto E;
		cout <<i<<endl;
		break;
		E:;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	char strings[100001];
	int i = 1;
	cin >> strings;
	cout << strings[0];
	while(strings[i * 2 - 1] != '\0' && strings[i * 2] != '\0'){
		cout << strings[i * 2];
		i++;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = min(a, k) - max(0, k-a-b);


    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3592
a,b;g(x,y){return y?g(y,x%y):x;}main(r){scanf("%d%d",&a,&b);b=b/g(a,b);for(a=2;a*a<=b;a++)if(b%a==0)for(r*=a;b%a==0;b/=a);a=!printf("%d\n",r*b);}

Measured memory_bytes: 596
Tani = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
while True:
    m,n = map(int,input().split())
    Kazu =[]
    i = 0
    if m == 0 and n == 0:
        break
    ans = ""
    num = m ** n
    Num = list(str(num))[::-1]
    Num_keta = []
    while len(Num) >= 4 * i:
        ketasuu = ""
        for j in range(4 * i,min(4 * (i + 1),len(Num))):
            ketasuu = Num[j] + ketasuu
        Num_keta.append(ketasuu)
        i += 1
    for j in range(len(Num_keta)):
        if Num_keta[j] != '0000' and Num_keta[j] != '':
            ans = (str(int((Num_keta[j]))) + Tani[j]) + ans
    print(ans)

Measured memory_bytes: 7648
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n, m;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	cin >> m;
	vector<string> t(m);
	for (int i = 0; i < m; ++i) {
		cin >> t[i];
	}
	int mx = 0, counter;
	for (string x : s) {
		counter = 0;
		for (string y : s) {
			counter = x == y ? ++counter: counter;
		}
		for (string z : t) {
			counter = x == z ? --counter : counter;
		}
		mx = max(mx, counter);
	}
	cout << mx << endl;
}

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

const ll mod = 1e9+7;

int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans = 0;
  int p = 1;
  
  rep(i,60){
    ll res = 0;
    rep(j,n){
      if(a[j]>>i & 1) res++;
    }
    ans = (ans + (((res * (n - res))%mod)*p)%mod)%mod;
    p = p*2%mod;
  }
  cout << ans << endl;
}

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

int main() {
  int64_t a, b;
  cin >> a >> b;
  if (a*b <= 0) {
    cout << "Zero" << endl;
  } else if (a > 0) {
    cout << "Positive" << endl;
  } else if (b < 0) {
    if ((b-a+1)%2 == 0) {
      cout << "Positive" << endl;
    } else {
      cout << "Negative" << endl;
    }
  }
}

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

class potentialized_unionfind{
    private:
    std::vector<int> UF,rank,pot;
    public:
    
    void init(int N){
        UF.clear();
        rank.clear();
        for(int i=0;i<N;i++){
            UF.push_back(i);
            rank.push_back(0);
            pot.push_back(0);
        }
    }
    
    int root(int k){
        if(UF[k]==k){
            return k;
        }else{
            int r = root(UF[k]);
            pot[k] += pot[UF[k]];
            UF[k] = r;
            return UF[k];
        }
    }
    
    int potential(int k){
        root(k);
        return pot[k];
    }
    
    bool same(int p,int q){
        return root(p)==root(q);
    }
    
    bool unite(int P,int Q,int d){
        //pot(Q)-pot(P)=dを満たす
        d+=potential(P);
        d-=potential(Q);
        int p=root(P), q=root(Q);
        if(p==q)return false;
        if(rank[p]<rank[q]){
            std::swap(p,q);
            d = -d;
        }
        UF[q]=p;
        if(rank[p]==rank[q])rank[p]++;
        pot[q]=d;
        
        return true;
    }
    
    int diff(int P,int Q){
        return potential(Q)-potential(P);
    }
    
};

signed main(void){
    int N,M,l;
    vector<int> L,R,D;
    cin >> N >> M;
    REP(i,M){
        cin >> l;
        l--;
        L.push_back(l);
        cin >> l;
        l--;
        R.push_back(l);
        cin >> l;
        D.push_back(l);
    }
    
    potentialized_unionfind potUF;
    potUF.init(N);
    
    REP(i,M){
        bool c = potUF.unite(L[i],R[i],D[i]);
        if(!c){
            if(potUF.diff(L[i],R[i])!=D[i]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    //REP(i,N){cout << potUF.potential(i) << endl;}
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 4448
#include<iostream>
using namespace std;
int a[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int MAXN=-2e9;
    int MINN=a[0];
    for(int i=1;i<n;i++)
    {
        MAXN=max(MAXN,a[i]-MINN);
        MINN=min(MINN,a[i]);
    }
    cout<<MAXN<<endl;
    return 0;
}



Measured memory_bytes: 3868
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++)cin >> a[i];

	if(a[0] != 0){
		cout << -1 << endl;
		return 0;
	}

	for(int i = 0;i < n-1;i++){
		if(a[i+1] > a[i] && a[i+1] != a[i] + 1){
			cout << -1 << endl;
			return 0;
		}
	}

	ll ans = 0;
	for(int i = 0;i < n;i++){
		int now = a[i];
		int j = i;
		while(j+1 < n && a[j+1] == a[j] + 1){
			j++;
		}
		ans += a[j];
		i = j;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INF = 1LL << 60;

 int main() {
   int N;
   cin >> N;
   vector<ll> A(N);
   rep(i, 0, N) cin >> A.at(i);
   ll ans = 0;
   rep(i, 0, 60) {
      ll n0 = 0, n1 = 0;
      rep(j, 0, N) {
        if (A.at(j) & (1LL << i)) n1++;
        else n0++;
      }
      ans = ((1LL << i) % MOD * n0 % MOD * n1 % MOD + ans) % MOD;
   }
   cout << ans << endl;
 }


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    string n;
    cin >> n;
    
    if ((n[0] == n[1]) && (n[1] == n[2]) ) {
        cout << "Yes" << endl;
        return 0;
    }

    if ((n[1] == n[2]) && (n[2] == n[3])) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 3e3+5;

string s;
string t;
int mem[N][N];

int go(int idx1 , int idx2){
    if(idx1 == s.size())
        return 0;
    if(idx2 == t.size())
        return 0;
    if(~mem[idx1][idx2])
        return mem[idx1][idx2];
    int best = 0;
    if(s[idx1] == t[idx2])
        best = 1 + go(idx1 + 1 , idx2 + 1);
    else
        best = max(go(idx1 + 1 , idx2) , go(idx1 , idx2 + 1));
    return mem[idx1][idx2] = best;
}

void build(int idx1 , int idx2){
    if(idx1 == s.size())
        return;
    if(idx2 == t.size())
        return;
    if(s[idx1] == t[idx2]){
        cout << s[idx1];
        build(idx1 + 1 , idx2 + 1);
    } else {
        if(mem[idx1][idx2] == mem[idx1 + 1][idx2]){
           build(idx1 + 1 , idx2);
        } else {
           build(idx1 , idx2 + 1);
        }
    }
}

int main(){
    cin >> s >> t;
    memset(mem , -1 , sizeof mem);
    go(0 , 0);
    build(0 , 0);
}


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

using namespace std;
using ll = long long;

int main(void) {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    } else {
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  string A,B;
  cin >> A >> B;
  map<char,char> judgeA;
  map<char,char> judgeB;
  bool ok = true;
  rep(i,A.size()){
    if(judgeA[A[i]] == 0){
      judgeA[A[i]] = B[i];
    }
    else if(judgeA[A[i]] == B[i]){
      continue;
    }
    else if(judgeA[A[i]] != B[i]){
      //cout << "A" << i << endl;
      ok = false;
    }
  }
  rep(i,B.size()){
    if(judgeB[B[i]] == 0){
      judgeB[B[i]] = A[i];
    }
    else if(judgeB[B[i]] == A[i]){
      continue;
    }
    else if(judgeB[B[i]] != A[i]){
      //cout << "B" << i << endl;
      ok = false;
    }
  }
  if(ok){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


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

using namespace std;

int a[100010];
int b[100010];
int is_prime(int n)
{
    int i;
    if(n == 1)
        return 0;
    for(i = 2; i * i <= n; i++)
        if(n % i == 0)
            return 0;
    return 1;
}

int main()
{
    memset(a,0,sizeof(a));
    for(int i=1; i<100010; i++)
    {
        if(i%2)
            if(is_prime(i)&&is_prime((i+1)/2))
                a[i]=1;
        b[i]=b[i-1];
        if(a[i]==1)
            b[i]++;
    }
    int Q,l,r;
    scanf("%d",&Q);
    for(int i=0; i<Q; i++)
    {
        scanf("%d%d",&l,&r);
        int ans=b[r]-b[l];
        if(a[l]==1)
            ans++;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


ll fact(ll n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(ll n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

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

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

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else
  return 0;
}

vector<ll> divisors(ll n)
{
  vector<ll> v;
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(i==n/i)
      v.PB(i);
      else
      v.PB(i),v.PB(n/i);
    }
  }
return v;
}

ll bin_expo(int x,int n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_expo(x*x,n/2);
    else                             //n is odd
        return x*bin_expo(x*x,(n-1)/2);
}

ll modular_expo(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modular_expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modular_expo((x*x)%M,(n-1)/2,M))%M;
}

ll kadane_algo(int a[],int n)
{
   ll max_so_far=0,max_ending_here=0;
   forp(i,0,n)
   {
     max_ending_here+=a[i];
     if(max_ending_here<0)
     max_ending_here=0;

     if(max_ending_here>max_so_far)
     max_so_far=max_ending_here;
   }

   return max_so_far;
}

// <----- Actual solve() function to print output -----> //
void solve()
{
   int n,z=0,k,x,y;

   string s;
   cin>>s;
   if(s=="RRR")
    cout<<3;
   else if((s[0]=='R' && s[1]=='R')||((s[1]=='R' && s[2]=='R')))
    cout<<2;
   else if(s[0]=='R' || s[2]=='R' || s[1]=='R')
    cout<<1;
   else
    cout<<0;
   //cout<<"\n";      //if t>1 uncomment this
}


// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
    single_testcase_t   //Uncomment this if only single testcase & single answer to print
   //multiple_testcases_t  //Uncomment this if t>1(t is given in question)(multiple testcases)
return 0;
}





Measured memory_bytes: 3672
#include<stdio.h>
int main(void){
	int r,c,i,j,a[100][100],b=0,t[100],v[100];
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&a[i][j]);
			t[i]+=a[i][j];
			v[j]+=a[i][j];
			b+=a[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			printf("%d ",a[i][j]);
		}
		printf("%d\n",t[i]);
	}
	for(j=0;j<=c;j++){
		if(j!=c){
			printf("%d ",v[j]);
		}else{
			printf("%d\n",b);
		}
	}
	return 0;
}

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


Measured memory_bytes: 7004
import numpy as np

N = int(input())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
               a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
print(a[-1])


Measured memory_bytes: 38692
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    vector<int> ans;
    vector<int> to[200005];
    void dfs(int v,int p = -1){
        for(auto nv : to[v]){
            if(nv == p)continue;
            ans[nv] += ans[v];
            dfs(nv,v);
        }
    }
    
    int main(){
        int n,q;cin>>n>>q;
        ans.resize(n);
        rep(i,n-1){
            int a,b;cin>>a>>b;
            a--;b--;
            to[a].push_back(b);
            to[b].push_back(a);
        }
        rep(i,q){
            int p,x;cin>>p>>x;
            p--;
            ans[p] += x;
        }
        //rep(i,n)c[i] = mp[0];
        dfs(0);
        rep(i,n)cout<<ans[i]<<" ";
    }
    


Measured memory_bytes: 23424
'''
問題：
    直角三角形 ABC があります。∠ABC=90° です。

    三角形 ABC の三辺の長さである
    |AB|,|BC|,|CA| が与えられるので、
    直角三角形 ABC の面積を求めて下さい。
    ただし、三角形 ABC の面積は整数となることが保証されています。
'''

'''
制約：
    1 ≦ |AB|,|BC|,|CA| ≦ 100
    入力はすべて整数である。
    三角形 ABC の面積は整数である。
'''

# 標準入力から AB, BC, CA の値を取得する
ab, bc, ca = map(int, input().split())

print(int( ab * bc / 2) )


Measured memory_bytes: 9148
#include <stdio.h>

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

    int a[n][m];
    int b[m][l];

    int i, j, k;

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (j = 0; j < m; j++) {
        for (k = 0; k < l; k++) {
            scanf("%d", &b[j][k]);
        }
    }

    long int c[n][l];
    for (i = 0; i < n; i++) {
        for (k = 0; k < l; k++) {
            c[i][k] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        for (k = 0; k < l; k++) {
            for (j = 0; j < m ; j++) {
                c[i][k] = c[i][k] + (a[i][j] * b[j][k]);
            }
        }
    }

    for (i = 0; i < n; i++) {
        for (k = 0; k < l; k++) {
            printf("%ld", c[i][k]);
            if (k == l-1) {
                printf("\n");
            } else{
                printf(" ");
            }

        }
    }

    return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;
 
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		for(int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
		}
		int m= sc.nextInt();
		for(int i = 0; i < m; i++) {
			int result = 0;
			int index = sc.nextInt()-1;
			int effect = sc.nextInt();
			for(int j = 0; j < n ;j++) {
				if(j == index) {
					result+=effect;
				}
				else {
				result += t[j];
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 23764
from sys import setrecursionlimit

setrecursionlimit(10**6)

def dfs(v):
    flag = True

    for nxt in edge[v]:
        if l[v] == l[nxt]:
            return False
        elif l[v] + l[nxt] == 1:
            continue
        else:
            l[nxt] = 1 - l[v]
            cnt[1-l[v]] += 1
            flag &= dfs(nxt)
    
    return flag
        

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

l = [-1] * n
l[0] = 0
cnt = [1, 0]

if dfs(0):
    print(cnt[0] * cnt[1] - m)
else:
    print(n * (n - 1) // 2 - m)

Measured memory_bytes: 43752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll N; cin >> N;
    vector<ll> D(N);
    for(int i = 0; i <N ; ++i) cin >> D[i];
    ll sum = 0;
    for(int i = 0; i < N ; ++i) for(int j = i + 1 ; j < N ; ++j) {
        sum += D[i]*D[j];
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define L 14
#define M 1100000

char H[M][L];
int IntegerChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C')return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}

long long IntegerKey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(IntegerChar(str[i]));
    p*=5;
  }
  return sum;
}
int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
  long long key,i,h;
  key=IntegerKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=IntegerKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
	strcpy(H[h],str);
	return 0;
      }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];

  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
  
    if(com[0]=='i')insert(str);
    else {if( find(str) )printf("yes\n");
	else printf("no\n");
	  }
  }
  return 0;


}

Measured memory_bytes: 15644
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int H,W; cin>>H>>W;
    vector<string> s(H);
    rep(i,H){
        cin>>s[i];
    }
    mat dp(110,vec(110));
    if(s[0][0]=='.') dp[0][0]=0;
    else             dp[0][0]=1;
    FOR(j,1,W){
        dp[0][j]=dp[0][j-1];
        if(s[0][j-1]=='.' && s[0][j]=='#') dp[0][j]++;
    }
    FOR(i,1,H){
        dp[i][0]=dp[i-1][0];
        if(s[i-1][0]=='.' && s[i][0]=='#') dp[i][0]++;
        FOR(j,1,W){
            ll res1=dp[i-1][j], res2=dp[i][j-1];
            if(s[i][j]=='#'){
                if(s[i-1][j]=='.') res1++;
                if(s[i][j-1]=='.') res2++;
            }
            dp[i][j]=min(res1,res2);
        }
    }
    cout<<dp[H-1][W-1]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    double ans;
    int n;
    cin >> n;
    if(n % 2 == 0)
        ans = (double)1 / 2;
    else
        ans = (double)(n / 2 + 1) / n;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100
#define maxk 100000

using namespace std;

const ll mod = 1000000007;
ll d[maxn+5][maxk+5];///nr impartire la i copii j bomboane
ll s[maxn+5][maxk+5];///s[i][j]=d[i][0]+d[i][i+1]+..+d[i][j]
int v[maxn+5];

ll suma (int i, int j1, int j2) {
  if (j1 == 0) return s[i][j2];
  return (s[i][j2] - s[i][j1-1] + mod) % mod;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k; cin >> n >> k;
  int i, j, z;
  for (i = 1; i <= n; i++) cin >> v[i];
  for (j = 0; j <= v[1]; j++) d[1][j] = 1;
  for (s[1][0] = 1, j = 1; j <= k; j++) s[1][j] = s[1][j-1] + d[1][j];
  for (i = 2; i <= n; i++) {
    for (j = 0; j <= k; j++) d[i][j] = suma(i-1, max(j-v[i], 0), j);
    for (s[i][0] = d[i][0], j = 1; j <= k; j++) s[i][j] = (s[i][j-1] + d[i][j]) % mod;
  }
  cout << d[n][k];
  return 0;
}


Measured memory_bytes: 159232
#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int op= 1;
    for(int i = 0;i<n;i++)
    {
        if(op< k) op *= 2    ;
        else{
            op +=k;
        }
    }
    printf("%d\n",op);
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}
 
class Eratosthenes{
  public:
    int n, sqlim;
    vector<bool> prime;
    Eratosthenes(int N):n(N+1){
        sqlim=(int)ceil(sqrt(n));
        prime=vector<bool>(n,1); prime[0]=prime[1]=0;
        for(int i=2;i<=sqlim;i++) if(prime[i]) for(int j=i*i;j<=n;j+=i) prime[j]=0;}
    vector<int> primeArray(int s=0, int l=10000){vi ret; for(int i=s;ret.size()!=l;i++) if(prime[i]) ret.push_back(i); return ret;}
};


int main(){
	int p,q;
	while(cin>>p>>q,p){
	    map<string,pii> y;
	    rep(i,p){
	        string a;int b,c;
	        cin>>a>>b>>c;
	        y[a]=mp(b,c);
	    }
        rep(i,q){
            int n;cin>>n;
            for(auto m:y){
                if(m.sc.sc-n>=0 && m.sc.sc-n<m.sc.fs){
                    cout<<m.fs<<" "<<m.sc.fs-m.sc.sc+n<<endl;
                    goto fin;
                }
            }
            cout<<"Unknown"<<endl;
            fin:;
        }
	}
	return 0;
}

Measured memory_bytes: 3148
import sys
n, m = map(int,input().split())
aList = list(map(int,input().split()))
aList.sort()
bcDict = dict()
for i in range(m):
  b, c = map(int,input().split())
  if c in bcDict:
    bcDict[c] += b
  else:
    bcDict[c] = b
bcDict_sorted = sorted(bcDict.items(), key=lambda x:-x[0])
num = 0
for (k, v) in bcDict_sorted:
  for i in range(v):
    if num < len(aList) and aList[num] < k:
      aList[num] = k
      num += 1
    else:
      print(sum(aList))
      sys.exit()
print(sum(aList))

Measured memory_bytes: 31848
/*
 神仙啊 
 定义a = 1,b = 1发现在%3的情况下所有变换的相等的
 性质:一个字符串，能变成字符c的条件是val[a] == val[c]并且a中有一个可以变换的位置
 只需要判断这种变换不经过ababab这种就好了
 那我们要求得就把字符串划分为k段，第i段的val值和第i字符的val值相等
 f_i表示前i个看做一段的方案数
   
*/
#include<cstdio> 
#include<cctype> 
#include<cstring> 
#include<algorithm> 
#define gc getchar() 
#define pc putchar
#define LL long long
inline int read() { 
	int x = 0,f = 1; 
	char c = getchar(); 
	while(c < '0' || c > '9') c = gc; 
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
}
void print(LL x) { 
	if(x < 0) { 
		pc('-'); 
		x = -x; 
	} 
	if(x >= 10) print(x / 10); 
	pc(x % 10 + '0'); 
} 
const int maxn = 100007; 
char t[maxn]; 
int n,s[maxn]; 
int f[maxn]; 
const int mod = 1e9 + 7; 
int main() { 
	scanf("%s",t + 1); 
	n = strlen(t + 1); 
	bool flag = false ; 
	for(int i = 2;i <= n;++ i) if(t[i] == t[i - 1])flag = true; 
	if(!flag) { 
		puts("1");  
		return 0; 
	} 
	int now = 0,pre[3] = {0,-1,-1}; 
	f[0] = 1; 
	for(int i = 1;i <= n;++ i) { 
		now = (now + 2 - (t[i] == 'a')) % 3; 
		if(!now && i < n) f[i] = 1; 
		++ now,now %= 3; 
		if(pre[now] != - 1) (f[i] += f[pre[now]]) %= mod;  
		++ now,now %= 3; 
		if(pre[now] != -1) (f[i] += f[pre[now]]) %= mod;
		++ now,now %= 3; 
		pre[now] = i; 
	} 
	print(f[n]); 
} 

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CExamAndWizard solver = new CExamAndWizard();
        solver.solve(1, in, out);
        out.close();
    }

    static class CExamAndWizard {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // Aの余りを大きい順に取っていく。
            // ・不足している分を足す
            // ・余りが不足以上になるまで足す
            int n = in.nextInt();
            long[] a = new long[n];
            long[] b = new long[n];
            ArrayList<Long> amari = new ArrayList<>();
            long husoku = 0;
            long res = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
                if (a[i] > b[i]) {
                    amari.add(a[i] - b[i]);
                }
                if (b[i] > a[i]) {
                    husoku += b[i] - a[i];
                    res++;
                }
            }
            amari.sort(Comparator.reverseOrder());
            int index = 0;

            while (husoku > 0) {
                if (index == amari.size()) {
                    out.println(-1);
                    return;
                }
                husoku -= amari.get(index++);
                res++;
            }
            out.println(res);
        }

    }
}



Measured memory_bytes: 92756
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {

    int n;
    cin >> n;
    set<ll> a;

    rep(i,n) {
        int d;
        cin >> d;
        a.insert(d);
    }

    print(a.size());
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    string s;
    cin >> s;
    ll n = s.length();
    ll num[n + 1] = {};
    rep(i, n + 1) { num[i] = -1; }

    if (s[0] == '<') {
        num[0] = 0;
    }
    if (s[n - 1] == '>') {
        num[n] = 0;
    }

    repd(i, 1, n) {
        if (s[i - 1] == '>' && s[i] == '<') {
            num[i] = 0;
        }
    }
    rep(i, n) {
        if (num[i] != -1 && s[i] == '<') {
            num[i + 1] = max(num[i + 1], num[i] + 1);
        }
    }
    for (ll i = n - 1; i >= 0; i--) {
        if (num[i + 1] != -1 && s[i] == '>') {
            num[i] = max(num[i], num[i + 1] + 1);
        }
    }

    ll ans = 0;
    rep(i, n + 1) { ans += num[i]; }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4740
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint X,Y;
	for(int i=0;i<N;i++){
		int x,y;
		cin>>x>>y;
		X.pb(x);
		Y.pb(y);
	}
	//x+yが全部同じじゃないなら無理
	bool flag=abs(X[0]+Y[0])%2;
	for(int i=0;i<N;i++){
		if(abs(X[i]+Y[i])%2!=flag){
			cout<<-1<<endl;
			return 0;
		}
	}
	//V=X+Y,W=X-Y
	vint V,W;
	for(int i=0;i<N;i++){
		V.pb(X[i]+Y[i]);
		W.pb(X[i]-Y[i]);
	}
	int arms=31;
	vint A={1};
	if(!flag)
		A.pb(1);
	for(int i=1;i<arms;i++)
		A.pb(A.back()*2);
	reverse(A.begin(),A.end());
	cout<<A.size()<<endl;
	for(int i=0;i<A.size();i++)
		cout<<A[i]<<(i==A.size()-1?'\n':' ');
	for(int i=0;i<N;i++){
		int v=0,w=0;
		for(int j=0;j<A.size();j++){
			if(v<=V[i] && w<=W[i]){
				cout<<'R';
				v+=A[j],w+=A[j];
			}
			else if(v<=V[i] && w>W[i]){
				cout<<'U';
				v+=A[j],w-=A[j];
			}
			else if(v>V[i] && w<=W[i]){
				cout<<'D';
				v-=A[j],w+=A[j];
			}
			else{
				cout<<'L';
				v-=A[j],w-=A[j];
			}
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((100*a + 10*b + c) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
    long long N;
    long long A[200001];
    long long B[200001];
    cin >> N;
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) B[i] = A[i];
    
    
    sort(A, A+N);
    for (int i=0; i<N; i++) {
        if (B[i] == A[N-1]) {
            cout << A[N-2] << endl;
        }
        else {
            cout << A[N-1] << endl;
        }
    }
    
    return 0;
}



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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

bool flag = false;
string s = "+-*";
int n[4];

int calc(int a, int o, int b) {
	if(o == 0) return a + b;
	else if(o == 1) return a - b;
	return a * b;
}

bool solve(int a, int b, int c){
	flag++;
	if(calc( calc( calc(n[0], a, n[1]), b, n[2]), c, n[3]) == 10){
		return printf("(((%d %c %d) %c %d) %c %d)\n", n[0], s[a], n[1], s[b], n[2], s[c], n[3]);
	}
	if(calc( calc(n[0], a, n[1]), b, calc(n[2], c, n[3])) == 10){
		return printf("((%d %c %d) %c (%d %c %d))\n", n[0], s[a], n[1], s[b], n[2], s[c], n[3]);
	}
	if(calc( calc(n[0], a, calc(n[1], b, n[2])), c, n[3]) == 10){
		return printf("((%d %c (%d %c %d)) %c %d)\n", n[0], s[a], n[1], s[b], n[2], s[c], n[3]);
	}
	return flag = false;
}

bool judge(){
	rep(i,3) rep(j,3) rep(k,3) if(solve(i, j, k)) return true;
}

int main() {
	while(1) {
		rep(i, 4) cin >> n[i];
    	if(!n[0] && !n[1] && !n[2] && !n[3]) break;
    	sort(n, n + 4);
    	do {
    		if(judge()) break; 
    	}while(next_permutation(n, n + 4));
   		if(!flag) puts("0");
	}
	return 0;
}

Measured memory_bytes: 3232
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=3000010;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
void print(int x) {if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,ans;
inline bool Check(int x,int y)
{
	while(x<=y) (y%x)?y%=x:y/=x;
	if(y==1) return true; else return false;
}
signed main()
{
	n=read(); n--;
	if(n==1) {puts("1"); return 0; }
	for(ri int i=2;i<=sqrt(n);i++)
	{
		if(n%i) continue;
		ans++; if(i^(n/i)) ans++;
	} n++;
	for(ri int i=2;i<=sqrt(n);i++)
	{
		if(n%i) continue;
		if(Check(i,n)) ans++;
		if(i==(n/i)) continue;
		if(Check(n/i,n)) ans++;
	}
	printf("%lld\n",ans+2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){

  int n;
  int i;

  scanf("%d", &n);

  char p[n];
  int x[n];
  int s[16], h[16], c[16], d[16];

  for(i = 0; i < 13; i++){
    s[i] = 0, h[i] = 0, c[i] = 0; d[i] = 0;
  }

  for(i = 0; i < n; i++){
    scanf("%s %d", &p[i], &x[i]);
    if(p[i] == 'S'){
      s[x[i] - 1] = 1;
    }else if(p[i] == 'H'){
      h[x[i] - 1] = 1;
    }else if(p[i] == 'C'){
      c[x[i] - 1] = 1;
    }else if(p[i] == 'D'){
      d[x[i] - 1] = 1;
    }
  }

  for(i = 0; i < 13; i++){
    if(s[i] == 0){
      printf("S %d\n", i + 1);
    }
  }
  for(i = 0; i < 13; i++){
    if(h[i] == 0){
      printf("H %d\n", i + 1);
    }
  }
  for(i = 0; i < 13; i++){
    if(c[i] == 0){
      printf("C %d\n", i + 1);
    }
  }
  for(i = 0; i < 13; i++){
    if(d[i] == 0){
      printf("D %d\n", i + 1);
    }
  }
  
  return 0;
}


Measured memory_bytes: 2056
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var output = 0;
  for(var i = 1; i < N - 1; i++){
    output += Math.floor((N - 1) / i);
  }
  myout(output + 1);
}


Measured memory_bytes: 33032
n,k = [int(x) for x in input().split()]

arr  = [int(x) for x in input().split()]

# dp[i] -> having i stones in pile, True if player A can win starting from here

dp = [False]*(k+1)

dp[0] = False


for i in range(1,k+1):
    for e in arr:
        if i - e < 0:
            dp[i] = False
            break
        if dp[i-e] == False:
            dp[i] = True
            break

# print(dp)
if dp[k]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 3828
defmodule Main do
  def alter_altar(_n, seq) do
    r_count = Regex.scan(~r/R/, seq)
            |> Enum.count
    post_processed_seq = String.slice seq, 0, r_count
    w_count = Regex.scan(~r/W/, post_processed_seq)
            |> Enum.count
  end

 def main do
    n = IO.gets("") |> String.trim() |> String.to_integer
    seq = IO.read(:line) |> String.trim()
    IO.puts alter_altar(n, seq)
 end
end

Measured memory_bytes: 200860
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	int n,m,a,b;
	vector<pair<int,int>> w;
	cin >> n >> m;
	for(int i = 0;i < m;i++) {
		cin >> a >> b;
		w.push_back(make_pair(a,b));
		w.push_back(make_pair(b,a));
	}
	sort(w.begin(),w.end());
	for(int i = 2;i < n;i++) {
		if(binary_search(w.begin(),w.end(),make_pair(i,1)) && binary_search(w.begin(),w.end(),make_pair(i,n)) ) {
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}


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

// NもMも小さいから全探索しかないな
// 再帰(スタック)で{Ai}を全列挙するぞ

int simulate(vector<int> &A, vector<vector<int>> &List)
{
    int res = 0;
    for(auto &p : List)
    {
        int a = p[0], b = p[1], c = p[2], d = p[3];
        if(A[b-1] - A[a-1] == c) res += d;
    }
    return res;
}

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> List(Q, vector<int>(4,0));
    for(int i = 0; i < Q; ++i) {
        for(int j = 0; j < 4; ++j) {
            cin >> List[i][j];
        }
    }

    vector<int> A(N, 0);
    stack<pair<int,int>> Task;
    for(int i = 1; i <= M; ++i) {
        Task.push({0, i});
    }
    int res = 0;
    while(!Task.empty())
    {
        auto q = Task.top(); Task.pop();
        if(q.first >= N) {
            res = max(res, simulate(A, List));
            continue;
        }
        A[q.first] = q.second;
        for(int i = q.second; i <= M; ++i) {
            Task.push({q.first + 1, i});
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include<math.h>
int main(void)
{
 double a,b,c,d;
 double e;
 scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
 e=(a-c)*(a-c)+(b-d)*(b-d);
 e=sqrt(e);
 printf("%f",e);
 return 0;
} 


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

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

	int n, k;
	cin >> n >> k;
	vector<int> sticks;

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sticks.push_back(x);
	}

	sort(sticks.begin(), sticks.end());

	int sum = 0;
	for (int i = n - 1; i >= n - k; i--) {

		sum += sticks.at(i);
	}

	cout << sum << endl;

	return 0;

}


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

int N;
vector<int> P(9);
vector<int> Q(9);

void solve(){
    if(equal(P.begin() + 1, P.begin() + N + 1, Q.begin() + 1)){
        cout << 0;
        return;
    }
    vector<int> prev_P(P);
    bool b1 = true;
    bool b2 = true;
    int ans = 1;
    while(true){
        if(b1) b1 = prev_permutation(prev_P.begin() + 1, prev_P.begin() + N + 1);
        if(b1 && equal(prev_P.begin() + 1, prev_P.begin() + N + 1, Q.begin() + 1)) break;
        if(b2) b2 = next_permutation(P.begin() + 1, P.begin() + N + 1);
        if(b2 && equal(P.begin() + 1, P.begin() + N + 1, Q.begin() + 1)) break;
        ans++;
    }
    cout << ans;
}
int main(){
    cin >> N;
    for(int i = 1; i <= N; ++i){
        cin >> P[i];
    }
    for(int i = 1; i <= N; ++i){
        cin >> Q[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=12;
int n,m,P[N],K[N],A[N][N];
bool ok(int i) {
	For(j,1,m) {
		int c=0;
		For(k,1,K[j]) if(i&(1<<A[j][k]>>1)) ++c;
		if(c%2!=P[j]) return 0;
	}
	return 1;
}
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,m) {
		scanf("%d",&K[i]);
		For(j,1,K[i]) scanf("%d",&A[i][j]);
	}
	For(i,1,m) scanf("%d",&P[i]);
	int ans=0;
	For(i,0,(1<<n)-1)
		if(ok(i)) ++ans;
	printf("%d",ans);
	return 0;
}

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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
      a[i]--;
  }
  int cnt=0,ans=a[0];
  rep(i,n){
    cnt++;
    if(ans==1){
      cout<<cnt<<endl;
      return 0;
    }
    ans=a[ans];
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 3676