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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  
  REP(i,3) {
    string s;
    cin >> s;
    char c = s.at(0);
    
    c += 'A'-'a';
    
    cout << c;
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
const int MAX_N=LIMIT2;
int bit[MAX_N+1]={0},n;
//1-indexed BIT
int sum(int i){
    int s=0;
    while(i>0){
        s += bit[i];
        i -= i&(-i);
    }
    return s;
}
void add(int i,int x){
    while(i<=n){
        bit[i] += x;
        i += i&(-i);
    }
}
int rangesum(int l,int r){
  return sum(r)-sum(l-1);
}
//BIT end
void initialize(){
  
}
int c[LIMIT2]={0},a[LIMIT2]={0};
vector<ll> ql[LIMIT2],qid[LIMIT2];
int main(void){
  initialize();
  ll m,i,j,k,result=0,q,l,r;
  int results[LIMIT2]={0};
  cin >> n >> q;
  for(i=1;i<=n;i++){
    cin >> c[i];
  }
  rep(i,q){
    cin >> l >> r;
    ql[r].push_back(l);
    qid[r].push_back(i);
  }
  for(i=1;i<=n;i++) a[i]=0;
  for(i=1;i<=n;i++){
    if(a[c[i]]>0) add(a[c[i]],-1);
    add(i,1);
    a[c[i]]=i;
    rep(j,ql[i].size()){
      results[qid[i][j]]=rangesum(ql[i][j],i);
    }
  }
  rep(i,q){
    cout << results[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 54888
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
using namespace std;
const int N = 1234567;
int minCost[N];
int cost[N][3];
int happy[N][3];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>cost[i][j];
			if(i==0)
			happy[i][j]=cost[i][j];
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			happy[i][j]=cost[i][j];
			int ma=-1;
			for(int k=0;k<3;k++)
			{
				if(k!=j)
					ma=max(ma,happy[i-1][k]);
			}
			happy[i][j]+=ma;
		}
	}
	int ans = -1;
	for(int j=0;j<3;j++)
		ans=max(ans,happy[n-1][j]);
	cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
using namespace std;
int n,q,com,x,y,A[100000];
long m;
int find(int x,int y){
    m=2147483648;
    for(int j=x;j<=y;j++){
        if(m>A[j]){
            m=A[j];
        }
    }
    return m;
}
void update(int x,int y){
    A[x]=y;
}
int main(){
    cin>>n>>q;
    for(int i=0;i<n;i++){
        A[i]=2147483647;
    }
    for(int i=0;i<q;i++){
        cin>>com>>x>>y;
        if(com==0){
            update(x,y);
        }
        else{
                cout<<find(x,y)<<endl;
        }
        // for(int k=0;k<n;k++){
        //     cout<<A[k]<<" ";
        // }
        // cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3480
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int N;
	int64_t A[128];
	int64_t min, max;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd64, &A[i]) != 1) return 1;
	}
	min = max = A[0];
	for (i = 1; i < N; i++) {
		if (A[i] < min) min = A[i];
		if (A[i] > max) max = A[i];
	}
	printf("%" PRId64 "\n", max - min);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template<typename T>
void dump(T a, int n) { for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); }

template<typename T>
void dump(T a) { dump<T>(a, a.size()); }

constexpr int LIM = 1000 * 1500;

int main(void) {
	for (int N, M; cin >> N >> M, N;) {
		VI hs(N), ws(M);
		for (auto &h :hs) {
			cin >> h;
		}
		for (auto &w: ws) {
			cin >> w;
		}

		VI hsum(LIM + 1), wsum(LIM + 1);

		for (int i = 0; i < N; i++) {
			int sum = 0;
			
			for (int j = i; j < N; j++) {
				sum += hs[j];
				hsum[sum]++;
			}
		}

		for (int i = 0; i < M; i++) {
			int sum = 0;
			
			for (int j = i; j < M; j++) {
				sum += ws[j];
				wsum[sum]++;
			}
		}

		int cnt = 0;
		for (int i = 0; i <= LIM; i++) {
			cnt += hsum[i] * wsum[i];
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 12868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d %d", &a, &b);

	printf("%d\n",(a+b)/2);


	return 0;
}



Measured memory_bytes: 2112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String[] NK = bf.readLine().split(" ");
    int N = Integer.parseInt(NK[0]);
    int K = Integer.parseInt(NK[1]);
    String[] P = bf.readLine().split(" ");
    List<Integer> l = new ArrayList<Integer>();
    for (String s : P ) {
      l.add(Integer.parseInt(s));
    }
    l.sort(Comparator.naturalOrder());

    int sum = 0;
    for (int i = 0 ; i < K; i++) {
      sum = sum + l.get(i);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 32776
/*
                                        //     //     //\\\\\\\\\
                                        \\    //      \\        \\
                                        //   //       //         \\
                                        \\  //        \\          \\
                                        // //         //           \\
                                        \\//          \\            \\       
                                        //\\          //            //
                                        \\ \\         \\           //
                                        //  \\        //          //
                                        \\   \\       \\         //
                                        //    \\      //        //
                                        \\     \\     \\/////////
*/

#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vint vector <int>
#define vll vector <long long int>
#define endl cout<<'\n'
#define fre(i,l,n) for(long long int i=l;i<n;++i)
#define fr(i,l,n) for(long long int i=l;i<=n;i++)
#define rfre(i,n,l) for(long long int i=n-1;i>=l;i--)
#define rfr(i,n,l) for(long long int i=n;i>=l;--i)
#define tab '\t'
#define debug cout<<'*';
#define s(a) cin>>a
#define p(a) cout<<a
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef pair<int,pair<int,int> > tii;
typedef vector<int> vec;
typedef vector<long long> vecll;
typedef vector<pair<int,int> > vec_pii;
typedef vector<pair<long long int,long long int> > vec_pll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<pair<int,int> > > vvpii;
typedef vector<vector<pair<ll,ll> > > vvpll;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define Pi 3.14159265358979
#define gcd(a,b) __gcd(a,b)
#define sf(n) scanf("%lld",&(n))
#define pf(n) printf("%lld\n",(n))
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define w(t) while(t--)
#define flt(a) cout<<fixed<<setprecision(a)
#define cntSetBits(n) __builtin_popcountll(n)
/*****************************
*****************************/



void solve()
{
    ll n;
    s(n);
    vecll arr(n);
    ll maxi = 0;
    fre(i,0,n)
    {
        s(arr[i]);
        maxi = max(maxi,arr[i]);
    }
    ll kd[maxi+1] = {0};
    fre(i,0,n)
    {
        for(ll val=arr[i];val<=maxi;val+=arr[i])
        {
            kd[val] += 1;
        }
    }
    ll cnt = 0;
    fre(i,0,n)
    {
        if(kd[arr[i]] == 1)
        {
            cnt += 1;
        }
    }
    p(cnt);endl;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t=1;
    // s(t);
    w(t)
    {
        solve();
    }
    return 0;
}









Measured memory_bytes: 12604
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  bool f=false;
  if(A==1)f=true;
  FOR(i,1,A){
    if((B*i+C)%A==0)f=true;
  }
  cout<<(f?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: i32,
    }

    solve(n);
}

fn solve(n: i32) {
    if n % 1000 == 0 {
        println!("0");
    } else {
        let m = n / 1000 + 1;
        println!("{}", 1000 * m - n)
    }
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  if(N % 10 == 2 || N % 10 == 4 ||N % 10 == 5 ||N % 10 == 7 ||N % 10 == 9){
    cout << "hon" << endl;
  }
  else if(N % 10 == 3){
    cout << "bon" << endl;
  }
  else{
    cout << "pon" << endl;
  }
}

Measured memory_bytes: 3648
// 0022.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(ll a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while (cin >> n) {
		if (n == 0) { break; }
		ll dp[5001]; ll a[5001];
		ll ans = -9000000000;
		roop(i, n) {
			cin >> a[i];
			
			if (i > 0) {
				dp[i] = max(dp[i - 1] + a[i], a[i]);
			}
			else {
				dp[i] = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			ans = max(dp[i],ans);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3180
#include <iostream>

#define endl '\n'
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

void solve()
{
    int n;
    string s;

    cin >> n >> s;

    if(n % 2 != 0)
        cout << "No";
    else
    {
        string a(s, 0, n/2);
        string b(s, n/2);

//        cout << a << "--" << b << endl;

        if(a == b)
            cout << "Yes";
        else
            cout << "No";
    }


}

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

//    int t; cin >> t; while(t--){
        solve();
//    }
    return 0;
}


Measured memory_bytes: 3044
N, q = map(int, input().split())
name = []
time = []

for n in range(N):
  n, t = input().split()
  name.append(n)
  time.append(int(t))
  
ansn = []
anst = []  
ntime = 0

while time:
  t = time.pop(0)
  n = name.pop(0)
  
  if t <= q:
    ansn.append(n)
    ntime += t
    anst.append(ntime)
  
  else:
    name.append(n)
    time.append(t - q)
    ntime += q

for i, j in zip(ansn, anst):
  print(i,j)


Measured memory_bytes: 11104
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, a, b;
string s;

void solve() {
  int a_cnt{}, b_cnt{};
  REP(i, n) {
    char t = s[i];
    if (t == 'a' && a_cnt + b_cnt < a + b) {
      cout << "Yes" << endl;
      ++a_cnt;
    }else if (t == 'b' && a_cnt + b_cnt < a + b && b_cnt + 1 <= b) {
      cout << "Yes" << endl;
      ++b_cnt;
    } else {
      cout << "No" << endl;
    }
  }
}

int main() {
  cin >> n >> a >> b >> s;
  solve();
}


Measured memory_bytes: 896
#include <stdio.h>
int main (){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a-x<0){
        if(b-x<0){
            if(a-x<b-x){
                printf("B\n");
            }else{
                printf("A\n");
            }
        }else{
            if(x-a<b-x){
                printf("A\n");
            }else{
                printf("B\n");
            }

        }

    }else{
        if(b-x<0){
            if(a-x<x-b){
                printf("A\n");
            }else{
                printf("B\n");
            }

        }else{
            if(a-x>b-x){
                printf("B\n");
            }else{
                printf("A\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  int arr[n];
  for(int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  
  int sum;
  
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      if(i != j) {
        int c = arr[i] * arr[j];
        sum += c;
      }
    }
  }
  
  cout << sum;
  
  return 0;
}

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

using vi = vector<int>;
using ii = pair<int, int>;

#define MAX 1000010

const int MOD = 1e9 + 7;

using ll = long long;

bitset<MAX> prime, used;

vi fact;

void sieve(int n) {
  prime.set();
  int i;
  for (i = 2; i * i <= n; i++) {
    if (prime[i]) {
      fact[i] = i;
      for (int j = i * i; j <= n; j += i) {
        prime[j] = 0;
        if (fact[j] == -1)
          fact[j] = i;
      }
    }
  }

  for (; i <= n; i++)
    if (prime[i])
      fact[i] = i;
}

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

  int mx = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    mx = max(mx, v[i]);
  }

  fact.resize(mx + 1, -1);
  sieve(mx + 1);


  bool pairwise = true;
  int gcd;
  for (int i = 0; i < n; i++) {
    if (i == 0) gcd = v[i];
    else if (gcd > 1)
      gcd = __gcd(gcd, v[i]);

    if (pairwise) {
      while (v[i] > 1) {
        int &p = fact[v[i]];

        if (used[p]) {
          pairwise = false;
          break;
        }

        used[p] = true;
        while (v[i] % p == 0) v[i] /= p;
      }
    } else if (gcd == 1) break;
  }

  if (pairwise)
    printf("pairwise coprime\n");
  else if (gcd == 1)
    printf("setwise coprime\n");
  else
    printf("not coprime\n");

  return 0;
}


Measured memory_bytes: 11168
import numpy as np

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
a=np.array(a)

for i in range(60):
  keta = a>>i & 1
  num1 = int(keta.sum())
  num0 = n - num1
  ans+= ((2**i)%mod)*(num1*num0)
  ans%=mod
print(ans) 

Measured memory_bytes: 68904
#include<bits/stdc++.h>
using namespace std; 
double t[200005];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i];
        t[i]=(t[i]+1)/2;
    }
    double max1,sum;
    for(int i=0;i<m;i++)
        max1+=t[1+i];
    sum=max1;
    for(int i=2;i<=n-m+1;i++)
    {
        sum=sum-t[i-1]+t[i+m-1];
        max1=max(sum,max1);
    }
 
    cout << fixed << setprecision(12)<<max1;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int,int> pii;typedef pair <lli,lli> pll;
#define fr(i, n) for(int i = 0; i < n; i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c)(c).begin(), (c).end()
#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x)((c).find(x) != (c).end())
#define cpresent(c, x)(find(all(c), x) != (c).end())
// for mod power a^b%m use power<lli> (a,b,m)
template < class mytype >
mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;
mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;
return ans;
}
// for gcd use gcd<int> (a,b)
template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}
template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}
const lli MOD = 1e9 + 7;
int n, m;
vector< vector<int> > v(100000 , vector<int>());
pll dpdfs(int node , int p){
    pll ans = make_pair(1 , 1);
    for(int i = 0 ; i < v[node].size() ; i++){

        if(v[node][i] != p){

            pll temp = dpdfs(v[node][i] , node);
            ans.first = (ans.first *((temp.first + temp.second)%MOD))%MOD;
            ans.second = (ans.second*temp.first)%MOD;
        }
    }


    return ans;
}
int main()
{

    cin >> n;m = n-1;
    for(int i = 0 ; i < m ; i ++){
        int x,y;
        cin >> x >> y;
        v[x-1].pb(y-1);
        v[y-1].pb(x-1);
    }
    pll ans = dpdfs(0 , -1);
    cout << (ans.first + ans.second)%MOD << endl;
    return 0;
}











Measured memory_bytes: 12672
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m;
    static vector < vi > edges;
    fi>>n>>m;
    static int s[1 << 20];
    for (int i = 1;i <= n;++i)
        s[i] = 2e9;
    auto f = [&](int x)
    {
        while (x > n)
            x -= n;
        return x;
    };
    while (m --)
    {
        int a,b,c;
        fi>>a>>b>>c;
        ++a;++b;
        if (a != b)
            edges.push_back({a,b,c});
        s[a] = min(s[a],c + 1);
        s[b] = min(s[b],c + 2);
    }
    for (int i = 2;i <= 3 * n;++i)
        s[f(i)] = min(s[f(i)],s[f(i - 1)] + 2);
    for (int i = 1;i <= n;++i)
        edges.push_back({f(i),f(i + 1),s[i]});
    sort(edges.begin(),edges.end(),[&](vi a,vi b)
         {
            return a[2] < b[2];
         });
    static int ff[1 << 20];
    for (int i = 1;i <= n;++i)
        ff[i] = i;
    function < int(int) > get = [&](int k)
    {
        return ff[k] == k ? k : ff[k] = get(ff[k]);
    };
    ll ans = 0;
    for (auto it : edges)
        if (get(it[0]) != get(it[1]))
            ans += it[2],ff[get(it[0])] = get(it[1]);
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}




Measured memory_bytes: 26792
n, m, l = gets.chomp.split.map(&:to_i)

A = []
n.times{ A << gets.chomp.split.map(&:to_i)}
B = []
m.times{ B << gets.chomp.split.map(&:to_i)}

C = Array.new(n){Array.new(l, 0)}
for i in (0...n)
    for j in (0...l)
        for k in (0...m)
            C[i][j] += A[i][k] * B[k][j]
        end
    end
end
C.each{|row| puts row.join(" ")}

Measured memory_bytes: 9252
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
using namespace std;

int stoi(std::string str){
  int ret;
  stringstream ss;
  ss << str;
  ss >> ret;
  return ret;
}

int main(){
  string s;
  char c[30];
  cin >> c;

  int j=0;
  int dif=1000;
  while(c[j+2]!='\0'){
    int num = c[j+2]-'0' + 10*(c[j+1]-'0') + 100*(c[j]-'0');
    if(dif>abs(num-753))dif=abs(num-753);
    j++;
  }
  cout << dif << endl;

  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

int n;
vector<int> c;
vector<vector<pair<int, int>>> gr;

void dfs(int curr, int par) {
	for (auto child : gr[curr]) {
		if (child.ff == par) continue;
		if (child.ss % 2 == 0) c[child.ff] = c[curr];
		else c[child.ff] = (1 ^ c[curr]);
		dfs(child.ff, curr);
	}
}

int main() {

	cin >> n;
	c.resize(n + 1, 0);
	gr.resize(n + 1);
	for (int i = 1; i <= n - 1; i++) {
		int u, v, w; cin >> u >> v >> w;
		gr[u].push_back({v, w});
		gr[v].push_back({u, w});
	}

	dfs(1, 1);
	for (int i = 1; i <= n; i++) cout << c[i] << endl;


	return 0;
}

Measured memory_bytes: 10448
#include<bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define per(i,m,n) for(lli i=m-1;i>=n;i--)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int n,a,b,x,y;
  string s;
  cin>>a>>b;
  if(a==1){
    if(b==2)
      n=3;
    if(b==3)
      n=2;
  }
  else if(a==2){
    if(b==1)
      n=3;
    if(b==3)
      n=1;
  }
  else if(a==3){
    if(b==1)
      n=2;
    if(b==2)
      n=1;
  }
  cout<<n<<endl;
  return 0;
}

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

/// read the question correctly (is y a vowel?)
/// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

const int mx =  1234567;
const double exp1 =  1e-6;
const int md =  1e9+7;
typedef long long ll;

int ar[mx],xar[mx],uses[mx];
ll arr[mx];
int tab[1000][1000];
string st[1000];
int ar1[mx],ar2[mx];
map<int ,int>mpii;
map<int ,char>mpic;
map<char ,int>mpci;

int main(){

    int tk=1,n,m=0;
//    freopen("in.txt","r", stdin);
//    freopen("out.txt","w", stdout);
    ll x;
    while(scanf("%lld",&x)==1){
        cout<<(x*(x-1))/2<<endl;
    }

    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define ll long long
#define forn(i,n) for(ll i=0;i<(n);i++)
#define maxx ((ll)1e6+5)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	 int n,m;
	 ll s=0;
	 cin>>n>>m;
	 int a[m];
	 forn(i,m){
	 cin>>a[i];
	 s+=a[i];}
	 if(s>n)
	 cout<<"-1";
	 else
	 cout<<n-s;
  return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  string s;cin>>s;
  ll x,y;cin>>x>>y;
  vector<ll> a,b;
  ll tcount;
  for(i=0;i<s.size();){
    if(s[i]=='T'){tcount++;i++;}
    else{
      buf=i;
      while(s[i]=='F'&&i<s.size())i++;
      if(tcount%2==0)a.push_back(i-buf);
      else b.push_back(i-buf);
    }
    //cout<<i<<endl;
  }
  ll sumx=0,sumy=0;
  for(i=0;i<a.size();i++)sumx+=a[i];//cout<<a[i]<<endl;}
  for(i=0;i<b.size();i++)sumy+=b[i];//cout<<b[i]<<endl;}
  vector<ll> dpx(20001),dpy(20001);
  if((sumx-x)%2!=0||(sumy-y)%2!=0||sumx<x||sumy<y)judge=false;
  else{
    if(s[0]=='T')buf=0;
    else buf=1;
    dpx[0]=1;dpy[0]=1;
    for(i=buf;i<a.size();i++){
      for(j=20000;j>=0;j--){
        if(dpx[j]==1)dpx[j+a[i]]=1;
      }
    }
    for(i=0;i<b.size();i++){
      for(j=20000;j>=0;j--){
        if(dpy[j]==1)dpy[j+b[i]]=1;
      }
    }
    if(dpx[(sumx-x)/2]!=1||dpy[(sumy-y)/2]!=1)judge=false;
  }
  ans1(judge);
  /*for(i=0;i<30;i++){
    cout<<i spa dpx[i] spa dpy[i] << endl;
  }*/
  //cout<<sumx spa sumy<<endl;


  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define PI acos(-1)
int main(){
int a,b;
char d;
while(cin>>a>>d>>b,d!='?'){
int ans;
if(d=='+')ans=a+b;
else if(d=='-')ans=a-b;
else if(d=='*')ans=a*b;
else ans=a/b;
cout<<ans<<endl;
}
}

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

int main() {
	vector<P>v;
	string s; int n;
	while (cin >> s >> n) {
		v.push_back(P(s, n));
	}
	sort(v.begin(), v.end(), [](P a, P b) {return a.second < b.second; });
	stable_sort(v.begin(), v.end());
	rep(i, v.size()) {
		if (i&&v[i - 1].first == v[i].first) {
			cout << ' ' << v[i].second;
			continue;
		}
		if (i)cout << endl;
		cout << v[i].first << endl << v[i].second;
	}
	cout << endl;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
char a[6][6];
ll n,m,k;
ll f(bitset <6> bs1,bitset <6> bs2)
{
    map <ll,ll> r,c;
    ll i,j,ans=0;
    for(i=0;i<6;i++)
     if(bs1[i])
      r[i]++;
    for(i=0;i<6;i++)
     if(bs2[i])
      c[i]++;
    for(i=0;i<n;i++)
    {
        if(r[i])
         continue;
        for(j=0;j<m;j++)
        {
            if(c[j])
             continue;
            if(a[i][j]=='#')
             ans++; 
        } 
    }    
    return ans;
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       ll i,j,ans=0;
       cin>>n>>m>>k;
       for(i=0;i<n;i++)
        for(j=0;j<m;j++)
         cin>>a[i][j];
       for(i=0;i<pow(2,n);i++)
       {
           bitset <6> bs1(i);
           for(j=0;j<pow(2,m);j++)
           {
               bitset <6> bs2(j);
               ans+=(f(bs1,bs2)==k);
           }
       }  
       cout<<ans;          
   }
}

Measured memory_bytes: 4068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, b[110];

    cin >> n;
    REP(i, n)
    cin >> b[i];

    V res;

    for (int i = 0; i < n; i++)
    {
        int ma = 0;
        int mai = -1;
        int j = 1;
        for (int i = 0; i < n; i++)
        {
            if (b[i] == -1)
                continue;

            if (b[i] > j)
            {
                cout << -1 << endl;
                return 0;
            }

            if (b[i] == j)
                ma = j, mai = i;

            j++;
        }

        res.push_back(ma);
        b[mai] = -1;
    }

    for (int i = n - 1; i >= 0; i--)
        cout << res[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,k,q,ans;
    scanf("%d %d %d",&n,&k,&q);
    int score[n];
    for(int i=0;i<n;i++){
        score[i]=k-q;
    }
    for(int i=0;i<q;i++){
        scanf("%d",&ans);
        score[ans-1]++;
    }
    for(int i=0;i<n;i++){
        if(score[i]>0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 896
N, M = map(int, input().split())
k = [0]*M
s = [""]*M
for i in range(M):
    tmp = list(map(int, input().split()))
    k[i] = tmp[0]
    s[i] = tmp[1:]

p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    global_count = 0
    for j in range(M):
        local_count = 0
        for x in s[j]:
            if (i >> (x - 1)) % 2 == 0:
                continue
            else:
                local_count += 1
        if local_count % 2 == p[j]:
            global_count += 1
    if global_count == M:
        ans += 1

print(ans)


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

using namespace std;

const int maxn = 1 << 18;
int n;
int a[maxn];
int mx[maxn];
int from[maxn];
int ans[maxn];
int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 0 ; i < (1 << n) ; ++ i)
        cin >> a[i];
    from[0] = 0;
    for(int i = 1 ; i < (1 << n) ; ++ i){
        from[i] = i;
        int num = 0;
        for(int j = 0 ; j < n ; ++ j)
            if((1 << j) & i){
                if(a[from[i ^ (1 << j)]] > a[from[i]]){
                    from[i] = from[i ^ (1 << j)];
                    mx[i] = mx[i ^ (1 << j)];
                }
                num = max(num , a[from[i ^ (1 << j)]]);
            }
        if(from[i] == i)
            mx[i] = max(mx[i] , a[i] + num);
        else
            mx[i] = max(mx[i] , a[from[i]] + a[i]);
        for(int j = 0 ; j < n ; ++ j)
            if((1 << j) & from[i])
                ans[i] = max(a[from[i]] + a[from[i ^ (1 << j)]] , ans[i]);
        ans[i] = max(ans[i] , mx[i]);
    }
    for(int i = 1 ; i < (1 << n) ; ++ i)
        ans[i] = max(ans[i] , ans[i - 1]);
    for(int i = 1 ; i < (1 << n) ; ++ i)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)

using namespace std;

const int mod = 998244353;
const int nax = 1e7 + 11;

int pt(int a, int b) {
	int c = 1;
	while(b) {
		if(b & 1)
			c = 1ll * c * a % mod;
		a = 1ll * a * a % mod;
		b /= 2;
	}
	return c;
}

int n;
int fac[nax];
int rev[nax];
int two[nax];

int nt(int N, int K) {
	return 1ll * fac[N] * rev[K] % mod * rev[N - K] % mod;
}

int main() {
	fac[0] = 1;
	rev[0] = 1;
	two[0] = 1;
	for(int i = 1; i < nax; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
		rev[i] = pt(fac[i], mod - 2);
		two[i] = 1ll * two[i - 1] * 2 % mod;
	}
	scanf("%d", &n);
	int ans = pt(3, n);
	
	for(int i = n / 2 + 1; i <= n; ++i) 
		ans = (ans - 1ll * nt(n, i) * two[n - i] % mod * 2 % mod + mod) % mod;
	printf("%d\n", ans);
	
	
	return 0;
}



Measured memory_bytes: 117376
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n, tmp;
  vector<int> r;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> tmp;
    r.push_back(tmp);
  }

  int minR = min(r[0], r[1]);
  int maxDiff = r[1] - r[0];
  for (int i = 2; i < n; i++)
  {
    maxDiff = max(maxDiff, r[i] - minR);
    minR = min(minR, r[i]);
  }

  cout << maxDiff << endl;
  return 0;
}

Measured memory_bytes: 3836
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    hh = list(map(int, input().split()))

    dp = [math.inf]*nn
    dp[0] = 0
    dp[1] = chmin(dp[1],dp[0]+abs(hh[1]-hh[0]))
    for i in range(2,nn):
        dp[i] = chmin(dp[i],dp[i-1]+abs(hh[i]-hh[i-1]))
        dp[i] = chmin(dp[i],dp[i-2]+abs(hh[i]-hh[i-2]))

    print(dp[nn-1])


main()


Measured memory_bytes: 85584
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	Int n,res=0;
	string str;
	while(cin>>str){
		int i;
		n=0;
		for(i=0;i<str.size();i++){
			if('0'<=str[i]&&str[i]<='9'){
				n=n*10+str[i]-'0';
			}else{
				res+=n;
				n=0;
			}
		}
		res+=n;
	}
	cout<<res<<endl;
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(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 pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    //y /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll n;
    cin >> n;
    vll a(n);
    rep(i,n)cin >> a[i];

    ll tmp = a[0];
    ll count = 0;
    while(1)
    {
        count++;
        if(tmp == 2){
            cout << count << endl;
            return 0;
        }
        tmp = a[tmp - 1];

        if(count > n){
            cout << -1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

ll c[30],s[370][30];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);

int main()
{
    int d;
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    for(int i=0;i<d;i++){
        int x=rng()%26;
        printf("%d\n",x+1);
    }
    return 0;
}

Measured memory_bytes: 3892
n = int(input())
ls = list(map(int, input().split()))
ls.sort()
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            li = ls[i]
            lj = ls[j]
            lk = ls[k]
            if (li-lj)*(lj-lk)*(lk-li) == 0:
                continue
            if li + lj > lk and lj + lk > li and lk+li > lj:
                ans += 1
print(ans)

Measured memory_bytes: 74020
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<pair<int, int>>v;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int d, p; cin >> d >> p;
			ans += d*p;
			v.push_back(make_pair(p, d));
		}
		sort(v.begin(), v.end());
		int i = v.size() - 1;
		while (m > 0) {
			ans -= min(m, v[i].second)*v[i].first;
			m -= min(m, v[i].second);
			i--;
			if (i < 0)break;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3180
s = input()
if len(set(s))==26:
    for i in range(26):
        for j in range(i+1):
            if s[-(i+1)]<s[-(j+1)]:
                print(s[:-(i+1)]+s[-(j+1)]);exit()
    else:
        print(-1);exit()
else:
    chr_li = [ord(chr_) for chr_ in s]
    for i in range(97,97+26):
        if i not in chr_li:
            print(s+chr(i));exit()

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin>>h.at(i);
    }
    int count=1;
    int high = h.at(0);
    for(int i=0; i<n-1; i++){
        high = max(high, h.at(i));
        if(h.at(i+1) >= high){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int pasta[] = new int[3];
		int juice[] = new int[2];
		int i,j;
		int min = 0;//最小
		int result = 0;//最終的に-50円した値段800
		for(i = 0; i < 3; i++){
			int a = sc.nextInt();//パスタの値段を入力
			pasta[i] = a;
		}
		for(i = 0; i < 2; i++){
			int b = sc.nextInt();//ジュースの値段を入力
			juice[i] = b;
		}
		for(i = 0; i < 3; i++){
			for(j = 0; j < 2; j++){
				int sum = 0;
				sum = pasta[i] + juice[j];
				if(min == 0){
					min = sum;	
				}
				if(sum < min){
					min = sum;
				}
			}
		}
		result = result + min - 50;
		System.out.println(result);
	}

}

Measured memory_bytes: 17180
MOD,L,pat1,pat2 = 1000000007,'0'+input(),1,0
for i in range(1, len(L)): pat1, pat2 = (pat1*2%MOD, (pat1+pat2*3)%MOD) if L[i] == '1' else (pat1, pat2*3%MOD)
print((pat1+pat2)%MOD)


Measured memory_bytes: 3188
#include <iostream>
#include <utility>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> p(N);
	for (int i = 0; i < N; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		p[i] = make_pair(t2, t1);
	}
	sort(p.begin(), p.end());

	int nowt = 0;
	for (int i = 0; i < N; i++) {
		nowt += p[i].second;

		if (nowt > p[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
int main(void)
{
	char n[100001] = {};
	int n0 = 0, n1 = 0, l;
	std::cin >> n;
	l = std::strlen(n);
	for(int i = 0; i != l; i++){
		if(n[i] == '0') n0++;
		else n1++;
	}
	std::cout << 2 * std::min(n0, n1) << std::endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    string s;
    cin >> s;

    ll res = (1ll << 60);
    REP(i, 26){
    	string t = s + char('a'+i);
    	ll n = t.size();
    	ll ma = -1;
    	dump(i)
    	REP(j, n){
    		if(s[j]-'a'== i) continue;
    		int k = j;
    		while(k<n && s[k]-'a' != i) k++;
    		ll tmp = (k == n ? k-j-1 : k-j);
    		ma = max(tmp, ma);
    		dump(tmp)
    		j = k-1;
    	}
    	res = min(res, ma);
    }
    cout << res << endl;
    return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> D(10);
    rep(i, K){
        int d; cin >> d;
        D[d] = 1;
    }
    int mi = 100;
    int ma = -1;
    rep(i, 10){
        if(D[i] == 0){
            mi = min(mi, i);
            ma = max(ma, i);
        }
    }

    string s = to_string(N);
    int ss = s.size();
    int p = 100;
    rep(i, ss){
        int a = s[i] - '0';
        if(D[a] == 1){
            p = min(p, i);
        }
    }

    if(p == 100){
        cout << N << endl;
    } else if(s[p] - '0' < ma) {
        for (int i = 0; i < p; i++){
            cout << s[i];
        }
        int x = s[p] - '0';
        for (int i = x+1; i < 10; i++){
            if(D[i] == 0){
                cout << i;
                break;
            }
        }
        for (int i = p+1; i < ss; i++){
            cout << mi;
        }
        cout << endl;
    } else {
        int pf = p;
        for (int i = p-1; i >= 0; i--){
            if(s[i] - '0' != ma){
                p = i;
                break;
            }
        }
        if(p == pf){
            for (int i = 1; i < 10; i++){
                if(D[i] == 0){
                    cout << i;
                    break;
                }
            }
            rep(i, ss){
                cout << mi;
            }
            return 0;
        }
        for (int i = 0; i < p; i++){
            cout << s[i];
        }
        int x = s[p] - '0';
        for (int i = x+1; i < 10; i++){
            if(D[i] == 0){
                cout << i;
                break;
            }
        }
        for (int i = p+1; i < ss; i++){
            cout << mi;
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 3688
def submit():
    n, k = map(int, input().split())
    modp = 10 ** 9 + 7
    
    ans = 0
    for cur_k in range(k, n + 2):
        minsum = cur_k * (cur_k - 1) // 2
        maxsum = cur_k * (2 * n - cur_k + 1) // 2
        ans += maxsum - minsum + 1
        ans %= modp

    print(ans)


submit()

Measured memory_bytes: 9124