akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll S;
	while(cin>>S) {
		map<ll, ll> h;
		h[S] = 1;
		RANGE(i, 2, 1000001) {
			if(S%2==0) S/=2; else S=3*S+1;
			if(h.count(S)) {
				cout<<i<<endl;
				break;
			}
			h[S]=1;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>

#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

#include <random>
#include <ctime>

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)

const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;

#define int long long

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

    int n;
    cin >> n;
    vector<int> a(n);
    FOR(i, 0, n)
        cin >> a[i];
    int curr = 2, ans = a[0] - 1;
    FOR(i, 1, n) {
        if (a[i] != curr) {
            ans += (a[i] - 1) / curr;
        } else {
            ++curr;
        }
    }
    cout << ans << "\n";

    return 0;
}


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

int main(){
    string C, temp;
    int i, j, n, h;
    
    while(1){
        cin >> C;
        if(C[0] == '-'){
            break;
        }
        
        cin >> n;
        for(i = 0; i < n; i++){
            temp = C;
            cin >> h;
            
            for(j = h; j < C.size(); j++){
                C[j-h] = temp[j];
            }
                
            for(j = 0; j < h; j++){
                C[C.size() - h +j] = temp[j];
            }
        }
        cout << C << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i > 0; i--) {
    printf("%d ", a[i]);
  }
  printf("%d\n", a[0]);
}


Measured memory_bytes: 2144
n,m = map(int,input().split())
l = [list(map(str,input().split())) for _ in range(m)]
case  = ["WA"]*n
case1 = ["T"]*n
good = 0
bad = 0
for (a,b) in l:
  a = int(a)
  if b =="AC":
    case1[a-1]="AC"
    
for (a,b) in l:
  a = int(a)
  if b=="AC" and case[a-1]=="WA":
    case[a-1]="AC"
    good += 1
  elif b=="WA" and case[a-1]=="WA" and case1[a-1]=='AC':
    bad += 1
print(good,bad)
    
  

Measured memory_bytes: 33704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define vec vector

typedef long long ll;

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

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

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n, m;
vec<pair<int, int>> lr;

/* Solve! */
void solve() {
  int maxl = 0, minr = 100005;
  rep(i, m) {
    maxl = max(lr[i].first, maxl);
    minr = min(lr[i].second, minr);
  }
  if (maxl > minr) cout << 0 << endl;
  else cout << minr - maxl + 1 << endl;
}

int main() {
  /* Input handling. */
  cin >> n >> m;
  lr = vec<pair<int, int>>(m);
  rep(i, m) cin >> lr[i].first >> lr[i].second;

  solve();
  return 0;
}

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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    string s;
    map<string,int> S;

    for(int i=0;i<N;i++){
        cin >> s;
        sort(s.begin(), s.end());
        if(S.count(s)){
            S[s]++;
        }else{
            S[s]=1;
        }
    }

    ll ans=0;
    for(auto p : S){
        ll N = p.second;
        ans+= N*(N-1)/2;
    }

    cout << ans << endl;

}

Measured memory_bytes: 11136
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		int z=0,ans=0;
		while(z<S.length()){
			if(S.charAt(z)=='x')
				ans++;
			z++;
		}
		if(ans>7)
			System.out.println("NO");
		else
			System.out.println("YES");
	}
}

Measured memory_bytes: 22228
/**
 *      purpose : CODE FESTIVAL 2016 qual C
 *      author  : kyomukyomupurin
 *      created : 2018-11-10 00:59:10
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int K, T; cin >> K >> T;
    int a[T] = {};
    for (int i = 0; i < T; ++i) cin >> a[i];

    if (T == 1){
        print(a[0] - 1); return 0;
    }

    int crack = *max_element(a, a + T) - 1;
    int res = accumulate(a, a + T, int()) - *max_element(a, a + T);

    if (res >= crack) print(0);
    else print(crack - res);

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<ll>a(3 * n);
	for (int i = 0;i < 3 * n;i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	ll ans = 0;
	for (int i = 0;i < n;i++) {
		ans += a[3 * n - 1 - 1 - i * 2];
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 2560
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a + 100*b + 50*c == X:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
 
int main(void) {
  int s1, s2, s3, d;
  
  scanf("%1d%1d%1d", &s1, &s2, &s3);
  
  if(s1 == 1) {
    d++;
  }
  if(s3 == 1) {
    d++;
  }
  if(s2 == 1) {
   	d++;
  }
  
  printf("%d", d);
  
  return 0;
}

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

void main_()
{
    int N;
    vector<int> as;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(as));

    auto it = cbegin(as);
    decltype(it) next_it;
    int num = 1;
    while ((next_it = find(it, cend(as), num)) != cend(as)) {
        ++num;
        it = next_it + 1;
    }

    cout << ((num == 1) ? -1 : (N - num + 1)) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

const long long maxn = 1e5 + 10;

long long n, m;
long long a[maxn];
long long b[maxn];
long long ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> m;
    for(long long i = 0; i < n; i++){
        cin >> a[i];
        a[i] /= 2;
    }
}

void solve(){
    long long chek = __builtin_ctz(a[0]);
    long long lcm = a[0];
    for(long long i = 0; i < n; i++){
        lcm = lcm * a[i] / __gcd(lcm, a[i]);
        if(__builtin_ctzll(a[i]) != chek || lcm > m)
            return;
    }
    ans = (m / lcm + 1) / 2;
}

void out(){
    cout << ans;
}


Measured memory_bytes: 1024
i = 1
x, y = map(int, input().split())
while x != 0 or y != 0:
    if i <= 3000:
        if x > y:
            print(str(y), str(x))
        else:
            print(str(x), str(y))
        x, y = map(int, input().split())
        i += 1
    else:
        x = 0
        y = 0


Measured memory_bytes: 5608
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vs64 p, m;
    rep (i, n)
    {
        s64 a;
        cin >> a;
        if (a >= 0) p.push_back(a);
        else m.push_back(a);
    }

    sort(p.begin(), p.end());
    sort(m.begin(), m.end(), greater<s64>());
    s64 ans = 0;
    if (m.size() & 1)
    {
        if (!p.empty() && p[0] < -m[0])
        {
            ans = -2 * p[0];
        }
        else
        {
            ans = 2 * m[0];
        }
    }
    for (auto x : p) ans += x;
    for (auto x : m) ans -= x;

    cout << ans << "\n";

    return 0;
}



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

using namespace std;
static const int infty=(1<<21);

int main(){

  int n,m;
  cin>>n>>m;
int a[n];
int sum=0;
int min=infty;
for(int i=0;i<n;i++){cin>>a[i];
m-=a[i];
sum+=1;
if(min>a[i])min=a[i];
}
while(1){
  m-=min;
  sum+=1;
  if(m<0)break;
}

cout<<sum-1<<endl;

return 0;

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000009
# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LG 20	
typedef pair<int,pair<int,int> > pii;
# define INF1 (int)1e9
# define maxn 300005

int main()
{
	int n;
	cin >> n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	ll now=0;
	ll r=0,l=0;
	ll ans=0;
	for( l=0;l<n;l++)
	{
		while(r<n && (now^a[r])==(now+a[r]))
		{
			now^=a[r];
			r++;
		}
		now^=a[l];
		ans+=(r-l);
	}
	cout << ans;
}

Measured memory_bytes: 1792
# 期待値自体が苦手なので厳しい
# 解説AC
def main():
    import sys
    sys.setrecursionlimit(10**6)
    N = int(input())
    A = [int(i) for i in input().split()]
    dp = [0]*(N*((N+1)**2) + N*(N+1) + N + 1)
    c = [0]*4
    for a in A:
        c[a] += 1

    def rec(c1, c2, c3):
        if c1 == c2 == c3 == 0:
            return 0
        if dp[c1 * (N+1)**2 + c2 * (N+1) + c3] != 0:
            return dp[c1 * (N+1)**2 + c2 * (N+1) + c3]
        ret = N
        if c1 > 0:
            ret += rec(c1-1, c2, c3) * c1
        if c2 > 0:
            ret += rec(c1 + 1, c2-1, c3) * c2
        if c3 > 0:
            ret += rec(c1, c2 + 1, c3-1) * c3
        ret /= c1 + c2 + c3
        dp[c1 * (N+1)**2 + c2 * (N+1) + c3] = ret
        return ret

    print(rec(*c[1:]))


if __name__ == '__main__':
    main()


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

int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    bool ok = s[n-1] == '0' && s[0] == '1';
    for (int i = 0; i < n-1; i++) {
        if (s[i] != s[n-2-i]) {
            ok = false;
        }
    }
    if (ok) {
        vector<pair<int, int>> res;
        int sz = n/2;
        int cur = 0;
        int nxtNode = 1;
        for (int sz = n/2; sz >= 1; sz--) {
            res.push_back({cur, nxtNode});
            if (s[sz-1] == '1') {
                cur = nxtNode;
            }
            nxtNode++;
        }
        for (int v = nxtNode; v < n; v++) {
            res.push_back({0, v});
        }
        for (auto pr: res) {
            cout << pr.first+1 << " " << pr.second+1 << "\n";
        }
    } else {
        cout << -1 << endl;
    }
}



Measured memory_bytes: 2244
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    h,w=MI()
    ss=[input() for _ in range(h)]
    print("#"*(w+2))
    for s in ss:
        print("#"+s+"#")
    print("#" * (w + 2))
main()

Measured memory_bytes: 3064
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(long long int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 60);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    fill((T*)array, (T*)(array + N), val);
}
int main() {
    ll n, k,a[15],sum,ans = INF; cin >> n >> k;
    rep(i, n) cin >> a[i];
    n--; k--;
    rep(i, (1 << n)) {
        int cnt = 0;
        rep(j, n) {
            if (i & (1 << j))cnt++;
        }
        if (cnt >= k) {
            sum = 0; ll fm = a[0];
            rep(l, n) {
                if (i & (1 << l)) {
                    sum += max(0LL, fm - a[l + 1] + 1);
                    fm = max(fm, a[l + 1] + max(0LL, fm - a[l + 1] + 1));
                }
                else {
                    fm = max(fm, a[l + 1]);
                }
            }
            ans = min(ans, sum);
        }
    }cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int a, b;
int main() {
	while (true) {
		scanf("%d%d", &a, &b);
		if (a == 0 && b == 0) break;
		printf("%d %d %d\n", (b - a) / 100 % 5, (b - a) / 500 % 2, (b - a) / 1000);
	}
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

bool mark[N];
vector<int> adj[N];
deque<int> q;

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

	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}

	int v = 0, u = 0;
	q.push_back(0);
	mark[0] = true;
	bool found = true;
	bool die = false;
	while (found)
	{
		found = false;
		if (!die)
		for (auto w : adj[v])
			if (!mark[w])
			{
				mark[w] = true;
				v = w;
				q.push_front(w);
				found = true;
				break;
			}
		if (!found)
		{
			die = true;
			for (auto w : adj[u])
				if (!mark[w])
				{
					mark[w] = true;
					u = w;
					q.push_back(w);
					found = true;
					break;
				}
		}
	}
	cout << q.size() << "\n";
	for (auto x : q)
		cout << x+1 << " ";
	cout << "\n";
	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(int i=1;i<=(int)sqrt(n);i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end());
	return(ret);
}
int main(){
    ll a,b;
    cin>>a>>b;
   ll n=gcd(a,b);
   vector<ll> d=divisor(n);
   int t=d.size();
   vector<bool> ch(t,true);
   int cnt=0;
   for(int i=0;i<t;i++){
       if(ch[i])cnt++;
       for(int j=i+1;j<t;j++){
           if(gcd(d[i],d[j])!=1LL)ch[j]=false;
       }
   }
   cout<<cnt<<endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i, N) {
		cin >> S[i];
	}
	sort(S.begin(), S.end(), less<string>());
	int count = 0;
	int ans = 0;
	rep(i, N) {
		if (i == N - 1) {
			ans = max(ans, count + 1);
			continue;
		}
		if (S[i] == S[i + 1])
			count++;
		else {
			ans = max(ans, count + 1);
			count = 0;
		}
	}
	count = 0;
	rep(i, N) {
		if (i == N - 1) {
			if (ans == count + 1) {
				cout << S[i] << endl;
			}
			continue;
		}
		if (S[i] == S[i + 1])
			count++;
		else {
			if (ans == count + 1) {
				cout << S[i] << endl;
			}
			count = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
int main()
{
	string s,t;
	cin >> s >> t;
	int m = s.length(),n=t.length();
	//output the longest sstring subsequence
	vector<vector<ll>>dp(m+1,vector<ll>(n+1,0));
	int l=0,row=0,col=0;
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0||j==0)
			{
				dp[i][j]=0;
			}
			else if(s[i-1]==t[j-1])
			{
				dp[i][j]= dp[i-1][j-1]+1;
			}
			else
				dp[i][j]=max({dp[i][j-1],dp[i-1][j]});
		}
	}
/*	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			ans = max(ans,dp[i][j]);
		}
	}*/
	ll i=m,j=n;
	string x="";
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			x+=t[j-1];
			i--;
			j--;
		}
		else if(dp[i][j-1]<dp[i-1][j])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	reverse(x.begin(),x.end());
	cout << x << endl;
}

Measured memory_bytes: 35584
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int):
    ret = -1
    for i in range(0, 10000):
        if int(i * 0.08) == A and int(i * 0.1) == B:
            ret = i
            break
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int a[maxn];
int c[maxn];
int cnt[maxn];
void run_case()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        c[a[i]]++;
    }
    for (int i = 1; i <= maxn; i++)
    {
        for (int j = i; j <= maxn; j += i)
        {
            cnt[j] += c[i];
        }
    }
    int ans = 0;
    for (int i = 1; i <= maxn; i++)
    {
        if (cnt[i] == 1 && c[i])
        {
            ans += c[i];
        }
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 12568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    for (int i = 1; i <= b; i++) {
        if ((a * i) % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(200000)


if __name__ == '__main__':

    n, m = [int(s) for s in input().split()]
    E = [set() for _ in range(n)]
    for _ in range(m):
        s, t = [int(s) for s in input().split(" ")]
        E[s].add(t)
        E[t].add(s)

    def dfs(current, prev):
        global timer
        prenum[current] = timer
        lowest[current] = prenum[current]
        timer += 1

        visited[current] = 1

        for v in E[current]:
            if visited[v] == 0:
                parent[v] = current
                dfs(v, current)
                lowest[current] = min(lowest[current], lowest[v])
            elif v != prev:  # current -> v is back-edge
                lowest[current] = min(lowest[current], prenum[v])

    prenum = [None] * n
    parent = [None] * n
    lowest = [float("inf")] * n
    timer = 1
    visited = [0] * n

    dfs(0, -1)

    ap = []
    np = 0
    for i in range(1, n):
        p = parent[i]
        if p == 0:
            np += 1
        elif prenum[p] <= lowest[i]:
            ap.append(p)

    if np > 1:
        ap.append(0)

    ap = list(set(ap))
    ap.sort()
    if ap:
        print("\n".join(map(str, ap)))



Measured memory_bytes: 25532
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int M = 100010;
const int mod = 1000000007;
int dp[N][M];
int a[N], n, sum;

int main() {
    cin >> n >> sum;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 0; i <= n; i ++) dp[i][0] = 1;
    for(int i = 1; i <= n; i ++) {
        for(int j = 1; j <= sum; j ++) {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
            if(j > a[i]) dp[i][j] = (dp[i][j] - dp[i-1][j-a[i]-1] + mod) % mod;
        }
    }
    cout << dp[n][sum] << endl;
    return 0;
}


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

int main(){
 
  int i, n, a, cnt;
 
  while(1){
 
    scanf("%d", &n);
    if(n == 0){
      break;
    }
    cnt = 0;
    int chk=0;
    for(i = 0;i<n;i++){
      scanf("%d", &a);
      if (a ==0) cnt++;
      if(a<=1) chk++;
    }
    if(n==chk){
      printf("NA\n");
    } else{
      printf("%d\n", n - cnt + 1);
    }
  }
  return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

void rec(int k,vector<pair<int, int>> &piece,vector<pair<int, int>> &queen) {
  if (k == 8) {
    rep(i,8) queen[i] = piece[i];
    return;
  }

  vector<vector<bool>> board(8, vector<bool>(8,true));

  rep(p,k) {
    rep(i,8) {
      rep(j,8) {
        if (i == piece[p].first) board[i][j] = false;
        if (j == piece[p].second) board[i][j] = false;
        if (i - j == piece[p].first - piece[p].second) board[i][j] = false;
        if (i + j == piece[p].first + piece[p].second) board[i][j] = false;
      }
    }
  }

  rep(i,8) {
    rep(j,8) {
      if (board[i][j]) {
        piece[k]= make_pair(i,j);
        rec(k+1, piece, queen);
      }
    }
  }

  return;
}

int main() {
  int k; cin >> k;
  vector<pair<int, int>> piece(8),queen(8);
  rep(i,k) {
    int r,c; cin >> r >> c;
    piece[i]= make_pair(r,c); 
  }

  rec(k,piece,queen);

  vector<vector<char>> ans(8, vector<char>(8,'.'));

  rep(i,8) ans[queen[i].first][queen[i].second] = 'Q';

  rep(i,8) {
    rep(j,8) cout << ans[i][j];
    cout << endl;
  }
}


Measured memory_bytes: 3128
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N;
    cin >> N;
    int M = N;

    int x = 0; //Nの桁数
    while (1) {
        M /= 10;
        x++;
        if (M < 1) break;
    }

    LL ans = 0;
    for (int i = 1; i <= x-1; i += 2) {
        ans += 9*pow(10, i-1);
    }

    if (x % 2) ans += (N - pow(10, x-1) + 1);

    cout << ans << endl;
    return 0;
}


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

int main() {
  int x; cin >>x;
  int ret;
       if (400 <= x && x < 600)   ret = 8;
  else if (600 <= x && x < 800)   ret = 7;
  else if (800 <= x && x < 1000)  ret = 6;
  else if (1000 <= x && x < 1200) ret = 5;
  else if (1200 <= x && x < 1400) ret = 4;
  else if (1400 <= x && x < 1600) ret = 3;
  else if (1600 <= x && x < 1800) ret = 2;
  else if (1800 <= x && x < 2000) ret = 1;

  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int K;
  ll tmp; 
  cin >> K;
  queue<ll> q;
  for(ll i=1;i < 10;++i) q.push(i);
  while(K>0){
    tmp = q.front();
    q.pop();
    if(tmp % 10 != 0){
      q.push(10 * tmp + tmp % 10 - 1);
    }
    q.push(tmp * 10 + tmp % 10);
    if(tmp % 10 != 9){
      q.push(10 * tmp + tmp % 10 + 1);
    }
    K--;
  }
  cout << tmp << endl; 
  
  return 0;
}

Measured memory_bytes: 1792
// abc132d.cpp : Blue and Red Balls
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define oute(x) cout<<(x)<<endl

#define MAX 2001
ll fac[MAX], finv[MAX], inv[MAX];

void init(int n){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  upto(i,2,n+1,1){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

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

int main(){
  int N,K; cin>>N>>K;
  int red = N-K, blue = K;
  init(red<blue? blue+1:red+1);
  upto(i,1,blue+1,1)
    oute(comb(red+1, i) * comb(blue-1, i-1) % MOD);
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ans = [1] * n
check = [False] * n
check[0] = True
for i in range(m):
  x, y = map(int, input().split())
  ans[x - 1] -= 1
  ans[y - 1] += 1
  if check[x - 1]:
    check[y - 1] = True
    if ans[x - 1] == 0:
      check[x - 1] = False
print(sum(check))


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

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	int max=1000001;
	int[] memo=new int[max];

	void run(){
		Arrays.fill(memo, -1);
		LinkedList<Integer> que=new LinkedList<Integer>();
		que.offer(1);
		memo[1]=0;
		for(; !que.isEmpty();){
			int m=que.poll();
			if(m*2<max&&memo[m*2]==-1){
				que.offer(m*2);
				memo[m*2]=memo[m]+1;
			}
			if((m-1)%3==0&&(m-1)%2!=0&&memo[(m-1)/3]==-1){
				que.offer((m-1)/3);
				memo[(m-1)/3]=memo[m]+1;
			}
		}
		/*
		for(int i=1; i<max; i++){
			if(memo[i]!=-1&&memo[i]!=cal(i)){
				debug(i, memo[i],cal(i));
				break;
			}
		}*/
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			println(""+memo[n]);
		}
	}

	int cal(int n){
		for(int i=0;; i++){
			if(n==1){
				return i;
			}
			if(n%2==0){
				n/=2;
			}else{
				n=3*n+1;
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll a, b;
  cin >> a >> b;
  ll ans = 0;
  while (a <= b) {
    a *= 2;
    ++ans;
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3656
n,W=map(int,input().split())
t = [[-1 for i in range(W + 1)] for j in range(n + 1)] 
  
  
def knapsack(wt, val, W, n):     
  
    # base conditions 
    if n == 0 or W == 0: 
        return 0
    if t[n][W] != -1: 
        return t[n][W] 
  
    # choice diagram code 
    if wt[n-1] <= W: 
        t[n][W] = max(val[n-1] + knapsack(wt, val, W-wt[n-1], n-1),knapsack(wt, val, W, n-1)) 
        return t[n][W] 
    elif wt[n-1] > W: 
        t[n][W] = knapsack(wt, val, W, n-1) 
        return t[n][W] 

weight,profit=[],[]
for _ in range(n):
  w,p=map(int,input().split())
  weight.append(w)
  profit.append(p) 
print(knapsack(weight,profit, W, n))

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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) {
        cin >> a[i];
    }
    int cnt[1000001] = {};
    rep(i, 0, n) {
        if (cnt[a[i]] >= 1) {
            cnt[a[i]] = 2;
            continue;
        }
        for (int j = a[i]; j <= 1000001; j += a[i]) {
            cnt[j]++;
        }
    }
    int ans = 0;
    rep(i, 0, n) {
        if (cnt[a[i]] == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8252
#7271131(wotsushi)解答
n = int(input())
a = []
for _ in range(n):
  a.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = []
for i in range(n):
  j = a[i][cnt[i]]
  if a[j][cnt[j]] == i and i < j:
    now.append([i,j])
ans = 0
while now:
  #print(now)
  last = now
  now = []
  for x in last:
    i = x[0]
    j = x[1]
    cnt[i] += 1
    cnt[j] += 1
    if cnt[i] < n-1:
      k = a[i][cnt[i]]
      if a[k][cnt[k]] == i:
        now.append([i,k])
    if cnt[j] < n-1:
      k = a[j][cnt[j]]
      if a[k][cnt[k]] == j:
        now.append([j,k])
  ans += 1
if all(cnt[i] == n-1 for i in range(n)):
  print(ans)
else:
  print(-1)

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

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

    bool state = true;
    int64_t count = 0;

    for(int64_t i=0;i<K;i++){
        if(A < B) break;
        B = B*2;
        count++;
        if(A < B) break;
        if(count == K) break;
    }
    
    for(int64_t i=count;i<K;i++){
        C = C*2;
        count++;
        if(count == K) break;
    }

    if(A >= B || B >= C){
        state = false;
    }
    
    //cout << A << B << C << endl;
    if(state){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int N, K;
	string S;
	cin >> N >> K >> S;
	if(S[K - 1] == 'A') S[K - 1] = 'a';
	if(S[K - 1] == 'B') S[K - 1] = 'b';
	if(S[K - 1] == 'C') S[K - 1] = 'c';
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        sc.close();

        List<Character> str = new ArrayList<>();
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == '0')
                str.add('0');
            else if(s.charAt(i) == '1')
                str.add('1');
            else{
                if(str.size() != 0)
                    str.remove(str.size()-1);
            }
        }
        for(int i = 0; i < str.size(); i++){
            System.out.print(str.get(i));
        }
    }
}

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

int main()
{
    int N,M;
    cin>>N>>M;
     int cnt=0;
    vector<int>a(N);
  
   for(int i=0;i<M;i++)
   {
       int k;
       cin>>k;
       for(int j=0;j<k;j++)
       {
           int s=0;
           cin>>s;
           s--;
         
           a[s] |= 1<<i ;
       }
    }
  int p;
  for(int i=0;i<M;i++)
  {
      int x;
      cin>>x;
      p |= x<<i;
  }

    for(int s=0;s<(1<<N);s++)
    {
        int t=0;
      for(int i=0;i<N;i++)
      {
          if((s>>i)&1)
          {
              t ^=a[i];
          }
      }
     if(t==p)
     {
           cnt++;
     }
    }
  
   cout<<cnt<<endl;

}


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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846


    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    void solve(){
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        while(b<=a && k>0){
            b*=2;
            k--;
        }
        while(c<=b && k>0){
            c*=2;
            k--;
        }
//        cout<<a<<" "<<b<<" "<<c<<"\n";
        if(c>b && b>a)
            cout<<"Yes";
        else
            cout<<"No";
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("alchemy_input.txt", "r", stdin);
//        freopen("alchemy_output.txt", "w", stdout);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  string rocks;
  cin >> rocks;
  int l = 0;
  int r = n - 1;
  int res = 0;
  while (l < r) {
    if (rocks[l] == 'R') {
      ++l;
      continue;
    }

    if (rocks[r] == 'W') {
      --r;
      continue;
    }

    if (rocks[l] == 'W' && rocks[r] == 'R') {
      ++res;
      ++l;
      --r;
      continue;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	int a;
	cin >> a;
	int x;
	x = 0;
	for (int i = 0; i < a; i++) {
		int b, c;
		cin >> b >> c;
		x += c - b + 1;
	}
	cout << x << endl;
	return 0;
}

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

const int maxn = 1e5 + 10;

typedef long long ll;

int n, mid;
ll ans;
vector<pair<int, int> > g[maxn];

int dfs(int x, int fa) {
  int siz = 1, mx = 0;
  for(auto p : g[x]) {
    if(p.first == fa) {
      continue;
    }
    int t = dfs(p.first, x);
    mx = max(mx, t);
    ans += 2ll * min(t, n - t) * p.second;
    siz += t;
  }
  mx = max(mx, n - siz);
  if(mx << 1 <= n) {
    if(mid) {
      for(auto p : g[x]) {
	if(p.first == mid) {
	  ans -= p.second;
	}
      }
      mid = -1;
    } else {
      mid = x;
    }
  }
  return siz;
}

int main(void) {
  scanf("%d", &n);
  for(int i = 1, u, v, w; i < n; i++) {
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  dfs(1, 0);
  if(~mid) {
    int mi = 1e9;
    //    cerr << mid << endl;
    for(auto p : g[mid]) {
      mi = min(mi, p.second);
    }
    ans -= mi;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13696
S = raw_input().split(' ')
for i in range(0,len(S)):
  S[i] = int(S[i])

if S[0] < S[1]:
  if S[0] < S[2]:
    a = S[0]
    if S[1] < S[2]:
      b = S[1]
      c = S[2]
    else:
      b = S[2]
      c = S[1]
  else:
    a = S[2]
    b = S[0]
    c = S[1]
else:
  if S[0] < S[2]:
    b = S[0]
    if S[1] < S[2]:
      a = S[1]
      c = S[2]
    else:
      a = S[2]
      c = S[1]
  else:
    c = S[0]
    if(S[1] < S[2]):
      a = S[1]
      b = S[2]
    else:
      a = S[2]
      b = S[1]

print(str(a) + ' ' + str(b) + ' ' + str(c))

Measured memory_bytes: 6488
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();
        int anc = 0;
       
        if(L%d == 0){
            anc = (R/d) - (L/d) + 1;
        }else{
            anc = (R/d) - (L/d);
        }
        System.out.println(anc);
    }
}


Measured memory_bytes: 35624
h, w = map(int, input().split())

M = [str(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            ans += 1

M = ['#'*w] + M + ['#'*w]
M = ['#'+c+'#' for c in M]

from collections import deque
q = deque()
q.append((1, 1))
visit = [[-1]*(w+2) for _ in range(h+2)]
visit[1][1] = 0

while q:
    y, x = q.popleft()
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        ny, nx = y+dy, x+dx
        if visit[ny][nx] == -1 and M[ny][nx] != '#':
            visit[ny][nx] = visit[y][x]+1
            q.append((ny, nx))

if visit[h][w] == -1:
    print(-1)
else:
    ans = ans -visit[h][w]-1
    print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

const ll m=1000000007;

int main(){
    string s;
    cin>>s;
    int c[11];
    for(int i=0;(i+2)<s.length();i++){
        c[i]=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    }
    int ans=10000;
    for(int i=0;(i+2)<s.length();i++){
        ans=min(ans,abs(c[i]-753));
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
//ll

ll p[51],m[51];
ll ans = 0;

ll f(int n, ll x){
  if(x<=0)return 0;
  if(n==0)return 1;
  if(x == m[n]){
    return p[n];
  }else if(x<=m[n]/2){
    return f(n-1,x-1);
  }else{
    return p[n-1] + 1 + f(n-1,x-m[n]/2-1);
  }
}

int main(){
  int n;cin>>n;
  ll x;cin>>x;
  p[0] = m[0] = 1;
  repd(i,1,51){
    p[i] = 1+p[i-1]*2;
    m[i] = 3+m[i-1]*2;
  }
  cout << f(n,x) << endl;

}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(usize, i64);
    let mut vs = scan!(i64, i64; n);
    vs.sort();

    let mut num = m;
    let mut ans = 0;
    let mut i = 0;

    while true {
        let (a, b) = vs[i];
        if num <= b {
            ans += a * num;
            break;
        } else {
            ans += a * b;
            num -= b;
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(a == b ? 2 * a : 2 * Math.max(a, b) - 1);
	}
}

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

using namespace std;
int main()

{
    string s,t;
    cin>>s>>t;
    int x=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            x++;
        }
    }
    cout<<x<<endl;


return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int N=15000,mod=1e9+7;
int n,X,D,G,sl,fh;
LL L,R,ans;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int gcd(int a,int b)
{
	if(!a||!b) return a|b;
	int r=a%b;
	for(;r;a=b,b=r,r=a%b);
	return b;
}
LL getL(int i) {return 1ll*i*(i-1)/2;}
LL getR(int i) {return 1ll*i*(n*2-i-1)/2;}
int main()
{
	n=rd();X=rd();D=rd();if(X<0) X=-X,D=-D;
	if(X==0&&D==0) return puts("1"),0;
	if(D>=0)
	{
		G=gcd(X,D);
		for(int i=0;i<=n;++i)
		{
			L=getL(i);//1ll*i*(i-1)/2;
			R=getR(i);//1ll*i*(n*2-i-1)/2;
			if(i-D/G>=0) L=max(L,getR(i-D/G)-X/G+1);
			ans+=R-L+1;
		}
	}
	else
	{
		G=gcd(X,D=-D);
		for(int i=0;i<=n;++i)
		{
			L=getL(i);
			R=getR(i);
			if(i-D/G>=0) ans-=max(0ll,min(R,getR(i-D/G)+X/G)-max(L,getL(i-D/G)+X/G)+1);
			ans+=R-L+1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

list_A = input().split()
list_B = input().split()
list_C = input().split()

#print(list_A)

mysum = 0
mypast = int(list_A[0])
for i in list_A:
    mysum += int(list_B[int(i)-1])
    if int(i)-mypast == 1:
        mysum += int(list_C[mypast-1])
        #print('C', list_C[mypast-1])

    mypast = int(i)
    #print(list_B[int(i)-1],mysum)
    
    


print(mysum)

Measured memory_bytes: 3064
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                while(sc.hasNext()){
                        int n = sc.nextInt();
                        System.out.println(primeNumber(n));
                }   
                sc.close();
        }   
        static int primeNumber(int n){
                boolean[] notprime = new boolean[n+1];
                int counter = 0;
                for(int i = 2; i <= n; i++){
                        if(!notprime[i]){
                                counter++;
                                for(int j = 2; j*i <= n; j++){
                                        notprime[j*i] = true;
                                }   
                        }   
                }   
                return counter;
        }   
}

Measured memory_bytes: 0