akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(input())

le = [[0,0]]
ri = [[0,0] for i in range(n)]
for i in range(n-1):
    if s[i] == 'W':
        le.append([le[-1][0],le[-1][1]+1])
    else:
        le.append([le[-1][0]+1,le[-1][1]])
for i in range(n-1,0,-1):
    if s[i] == 'W':
        ri[i-1] = [ri[i][0],ri[i][1]+1]
    else:
        ri[i-1] = [ri[i][0]+1,ri[i][1]]

res = 10**9
for i in range(n):
    res = min(res,le[i][1]+ri[i][0])
print(res)

Measured memory_bytes: 85860
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 1e6 + 5;
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll v[n + 1] = {};
    f(n + 1) {
        cin >> v[i];
    }
    n++;
    ll suf[n + 1] = {};
    suf[n] = 0;
    for (int i = n-1;i>=0;i--) {
        suf[i] = suf[i + 1] + v[i];
    }
    ll cb = 1;
    ll ans = 1;
    for (int i = 0 ; i < n ; i++) {
        //cout << cb <<' '<<v[i] <<' '<<suf[i]<<endl;
        if (cb < v[i]) {
            cout << -1 << endl;
            exit(0);
        }
        cb -= v[i];
        cb = min(cb * 2, suf[i+1]);
        ans += cb;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5208
def solve(N, K, R, S, P, T):
    hands = [None] * N
    score = {"r":P, "s":R, "p":S}

    for s in range(K):
        hands[s] = True # 最初は勝てる
        cont = 1

        # K ずつ増やす
        for i in range(s+K, N, K):
            if T[i] != T[i-K]:
                hands[i] = True
                cont = 1
            else:
                cont += 1
                if cont % 2 == 0:
                    hands[i] = False
                else:
                    hands[i] = True

    answer = 0
    #print(hands)
    for i in range(N):
        if hands[i]:
            #print(i, T[i], score[T[i]])
            answer += score[T[i]]
    return answer

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input().rstrip()

print(solve(N, K, R, S, P, T))


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    string s;
    cin>>s;
    int sum=0;
    for (char c: s) {
	sum += int(c-'0');
	sum %= 9;
    }
    cout<<(sum==0 ? "Yes\n": "No\n");
    return 0;
}


Measured memory_bytes: 3708
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static int[] X = new int[4];
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(in.readLine());

		ArrayList<long[]> list = new ArrayList<>();
		for(int i=0;i<N;i++){
			String W = in.readLine();
			String[] Ws = W.split(" ");
			long[] X = new long[2];
			X[0] = Long.parseLong(Ws[0]);
			X[1] = Long.parseLong(Ws[1]);
			list.add(X);
		}
		Collections.sort(list,(v1,v2) -> {return (int)(v1[1] - v2[1]);});

		long time=0;
		for(long[] x:list){
			time+=x[0];
			if(time <=x[1]){

			}else{
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 66600
#include <iostream>

using namespace std;

string s;

int main() {
	cin >> s;
	if (s.length() < 3) {
		throw "MoveToEx is juruo!";
	}
	cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1<<21
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
vector< P > houzyu[10005];
int w,h;
char maps[102][102][10];
int ruiseki[102][102];
int sx,sy,gx,gy;//スタートとゴールの座標
int n=0;//宝珠の最大値
int dp[105][105]={0};//メモ用
int memtan(int now,int x,int y);
int distance(int a,int b);
main(){
  //0,0座標から見た距離を記憶しておく
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      ruiseki[i][j]=i+j;
    }
  }
  while(1){
    cin>>w>>h;                         
    for(int i=0;i<max(h,w)+5;i++){     //<---------初期化----------
      for(int j=0;j<max(h,w)+5;j++){   //            
	dp[i][j]=INF;                  //            
      }                                //            
    }                                  //<------------------------           
    if(w==0&&h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>maps[i][j];
	if(maps[i][j][0]!='.'){
	  if(maps[i][j][0]=='S'){//スタートの記憶
	    sx=j;
	    sy=i;
	  }
	  else if(maps[i][j][0]=='G'){//ゴールの記憶
	    gx=j;
	    gy=i;
	  }
	  else{
	    int num=atoi(maps[i][j]);//文字を数字にする
	    if(num>n){
	      n=num;
	    }
	    P p;
	    p.first=j;
	    p.second=i;
	    houzyu[num].push_back(p);//宝珠の番号ごとに座標を記憶しておく
	  }
	}
      }
    }
    cout<<memtan(1,sx,sy)<<endl;//出力
    for(int i=1;i<=n;i++){             //<----------初期化------- 
	houzyu[i].clear();             //      
    }                                  //
    n=0;                               //<----------------------
  }
  return 0;
}

int Distance(int a,int b){//２点間のマンハッタン距離を返す
  return abs(a)+abs(b);
}

int memtan(int now,int x,int y){
  if(now>n){
    return Distance(gx-x,gy-y);//最後に壊した場所からゴールまでの距離を返す
  }
  else if(dp[x][y]!=INF){
    return dp[x][y];
  }
  else{
    int sizes=houzyu[now].size();//nowの宝珠の数
    int mins=INF;//一番小さい距離の記憶
    for(int i=0;i<sizes;i++){
      P vecnow=houzyu[now][i];
      mins=min(mins,memtan(now+1,vecnow.F,vecnow.S)+Distance(x-vecnow.F,y-vecnow.S));//ここから割ってゴールするまでの最小距離を求める
    }
    return dp[x][y]=mins;
  }
}

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

int main() {
    int n;
    cin >> n;
    set<int> s;
    rep(i,n){
        int a;
        cin >> a;
        if(s.count(a)==0) s.insert(a);
        else s.erase(a);   
    }
    int ans = s.size();
    cout << ans << endl;
    return 0;
}

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

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

int fact(ll n) {
    int num = 0;
    while(n > 0) {
        num++;
        n /= 10;
    }
    return num;
}

int main(void) {
    ll n;
    cin >> n;
    vector<ll> decomp;
    ll a = 2;
    int ans = max(fact(1),fact(n));
    while ( n >= a* a) {
        if(n % a == 0) {
            ans = min(ans, max(fact(n/a), fact(a)));
            a++;
        }else {
            a++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def next(s):
    if s%2 == 0:
        s = s/2
    else:
        s = s*3+1
    return int(s)

s = int(input())

cap = ["no"] * 1000000
for i in range(1000000):

    if cap[s] == ["yes"]:
        print(i+1)
        break
    cap[s] = ["yes"]
    s = next(s)
    









Measured memory_bytes: 10868
#include<stdio.h>

int main(){

int num,i,j,a,b,c,d;
int date[51]={0};


for(i=0;i<=9999;i++){
	
	a=i/1000;
	b=i%1000/100;
	c=i%100/10;
	d=i%10;
	date[a+b+c+d]++;

}


while(scanf("%d",&num)!=EOF){



printf("%d\n",date[num]);
}
return 0;
}

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

#define forn(l, r) for(int i = l; i < (r); ++i)
#define forj(l, r) for(int j = l; j < (r); ++j)
#define TAM 1000100
#define SYNC ios::sync_with_stdio(0);
#define $ << ' ' <<
#define F first
#define S second
#define endl '\n'


using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
const ll mod = 1000000007;




int main() {
    //SYNC
    string s;
    vector<int> numLet;
    cin >> s;
    numLet.assign(28, 0);
    for (auto i : s) {
        numLet[i-'a']++;
    }
    string beaut = "Yes";
    for (auto i : numLet) {
        if(i&1) beaut = "No";
    }
    cout << beaut << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	int left_len,maximum = 0,right_len,tmp,pre;

	scanf("%d",&tmp);

	left_len = tmp-1;
	pre = tmp;

	if(M == 1){
		right_len = N-tmp;
		printf("%d\n",max(left_len,right_len));
	}else{

		for(int i = 0; i < M-1; i++){
			scanf("%d",&tmp);
			maximum = max(maximum,tmp-pre);
			pre = tmp;
		}
		right_len = N-tmp;

		printf("%d\n",max(max(left_len,right_len),maximum/2));
	}
	return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll l,r;cin >> l>>r;
  ll len = r-l+1LL;
  ll l_mod = l%2019LL;
  ll r_mod = r%2019LL;
  ll min_val = 2020LL;
  for(int i=l_mod;i< l_mod + min(2019LL,len);++i){
    for(int j=i+1;j< l_mod + min(2019LL,len);++j){
      min_val = min(min_val, ((i%2019)*(j%2019))%2019LL);
    }
  }
  cout << min_val << endl;
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;

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

  vector<char>  v = {'M', 'A', 'R', 'C', 'H'};
  sort(v.begin(), v.end());

  ll ans = 0;

  int n; cin>>n;
  map<char,int> freq;
  for (int i=0; i<n; i++) {
    string s; cin>>s;
    freq[s[0]]++;
  }

  //for (auto p: freq) cout<<p.first<<" "<<p.second<<endl;

  do {
    ans += 1LL*freq[v[0]]*freq[v[1]]*freq[v[2]];
    //cout<<v[0]<<v[1]<<v[2]<<endl;
  } while (std::next_permutation(v.begin(), v.end()));

  // 3! permutations
  // 2! ways to place last 2 letters
  ans = ans / 12;

  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MOD 1000000007

int main(){
  long long n,m;
  cin >> n >> m;
  long long s[n+1],t[m+1];
  for(int i=1;i<n+1;i++){
    cin >> s[i];
  }
  for(int i=1;i<m+1;i++){
    cin >> t[i];
  }
  long long sum[n+1][m+1];
  long long dp[n+1][m+1];
  for(int i=0;i<n+1;i++){
    for(int j=0;j<m+1;j++){
      sum[i][j] = 0;
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 0;

  for(int i=1;i<n+1;i++){
    for(int j=1;j<m+1;j++){
      if(s[i] == t[j]){
        dp[i][j] = sum[i-1][j-1]+1;
      }
      else{
        dp[i][j] = 0;
      }
      dp[i][j] %= MOD;
      sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j];
      sum[i][j] %= MOD;
    }
  }
  long long ans = sum[n][m];
  ans += 1;
  ans %= MOD;
  ans += MOD;
  ans %= MOD;

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 62848
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <random>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<61 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmax(ll &a,ll b){	if(a<b) a = b ;}

int main(){
	ll n,m,s,t ;
	cin >> n >> m >> s >> t ;
	s-- ; t-- ;
	vector<vector<pll>> yen(n),snk(n) ;
	for(int i=0;i<m;i++){
		ll a,b,c,d ;
		cin >> a >> b >> c >> d ;
		a-- ; b-- ;
		yen.at(a).emplace_back(b,c) ;
		snk.at(a).emplace_back(b,d) ;
		yen.at(b).emplace_back(a,c) ;
		snk.at(b).emplace_back(a,d) ;
	}
	vll d1(n,INF),d2(n,INF) ;
	priority_queue<pll> pq ;
	pq.emplace(0,s) ;
	while(!pq.empty()){
		int p = pq.top().second ;
		ll cost = -pq.top().first ;
		pq.pop() ;
		if(d1.at(p)!=INF) continue ;
		d1.at(p) = cost ;
		for(int i=0;i<yen.at(p).size();i++){
			int np = yen.at(p).at(i).first ;
			int mny = yen.at(p).at(i).second ;
			if(d1.at(np)!=INF) continue ;
			pq.emplace(-cost-mny,np) ;
		}
	}
	pq.emplace(0,t) ;
	while(!pq.empty()){
		int p = pq.top().second ;
		ll cost = -pq.top().first ;
		pq.pop() ;
		if(d2.at(p)!=INF) continue ;
		d2.at(p) = cost ;
		for(int i=0;i<snk.at(p).size();i++){
			int np = snk.at(p).at(i).first ;
			int mny = snk.at(p).at(i).second ;
			if(d2.at(np)!=INF) continue ;
			pq.emplace(-cost-mny,np) ;
		}
	}
	vll ans(n) ;
	for(int i=0;i<n;i++) ans.at(i) = d1.at(i)+d2.at(i) ;
	for(int i=n-2;i>=0;i--) ans.at(i) = min(ans.at(i),ans.at(i+1)) ;
	for(int i=0;i<n;i++) cout << (ll)1e15-ans.at(i) << endl ;
}


Measured memory_bytes: 20988
n,k = map(int,input().split())
a = list(map(int,input().split()))

gen=10**9+7

count=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]>a[j]:
      count+=1

kaburi = 0
sorta=sorted(a)
scnt=0
for i in range(n-1):
  if sorta[i]==sorta[i+1]:
    scnt+=1
  if sorta[i]!=sorta[i+1]:
    kaburi+=scnt*(scnt+1)//2
    scnt=0
kaburi+=scnt*(scnt+1)//2

print((k*count+(n*(n-1)//2-kaburi)*k*(k-1)//2)%gen)

Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <map>
#include <math.h>
 
using namespace std;
 
typedef signed long long ll;
 
int main(void)
{
    long long int count = 0;
    int N = 0;
    cin >> N;
 
    vector<int> A(N, 0);
    vector<int> B(N, 0);
    vector<int> C(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }
    sort(C.begin(), C.end());
 
    long long int ab = 0;
    long long int bc = 0;
    for (int j = 0; j < N; j++, ab = 0, bc = 0)
    {
        auto it_A = lower_bound(A.begin(), A.end(), B[j]);
        ab = distance(A.begin(), it_A);
        auto it_C = upper_bound(C.begin(), C.end(), B[j]);
        bc = N - distance(C.begin(), it_C);
 
        count = count + (ab * bc);
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,ans,l;
char a[1005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	if(a[i]=='D')
	--ans;
	if(a[i]=='I')
	++ans;
	l=max(l,ans);
	}
	cout<<l<<endl;
	return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

// nCk @mod を計算する
long long nCk(long long n, long k, long long mod){
  long long retval = 1;
  for (int i=0; i<k; i++){
    retval *= (n-i);
    retval %= mod;
  }
  for (int i=1; i<=k; i++){
    retval *= modinv(i, mod);
    retval %= mod;
  }
  return retval;
}

// nPk @mod を計算する
long long nPk(long long n, long k, long long mod){
  long long retval = 1;
  for (int i=0; i<k; i++){
    retval *= (n-i);
    retval %= mod;
  }
  return retval;
}

int N, M;
long long PP[500004], CC[500004];
long long mod = 1e9+7;

void init(){
  PP[N]=1;
  for (int i=N-1; i>=0; i--){
    PP[i]=(PP[i+1]*(M-i))%mod;
    PP[i] %= mod;
  }
  CC[0]=1;
  for (int i=1; i<=N; i++){
    CC[i] = (((CC[i-1]*(N-i+1))%mod)*modinv(i, mod))%mod;
    CC[i] %= mod;
  }
  return;
}

// return (M-i)P(N-i)
long long evalP(int i){
  return PP[i];
}

// return NCi
long long evalC(int i){
  return CC[i];
}

int main(){
  scanf("%d", &N);
  scanf("%d", &M);
  init();
  long long MPN = 1;
  for (int i=0; i<N; i++){
    MPN *= (M-i);
    MPN %= mod;
  }

  long long total = MPN;
  long long subt = 0;
  long long sign=1;
  for (int i=1; i<=N; i++){
    subt += sign*(evalC(i)*evalP(i))%mod;
    //printf("evalC(%d)=%lld, evalP(%d)=%lld \n", i, evalC(i), i, evalP(i));
    //printf("subt += %lld\n", sign*(evalC(i)*evalP(i))%mod);
    if (subt>mod) subt%=mod;
    else if (subt<0) subt += mod;
    sign *= -1;
  }
  
  long long ans = (total-subt)*MPN;
  while (ans>mod) ans %= mod;
  while (ans<0) ans+= mod;
  //printf("total=%lld, subt=%lld, MPN=%lld, ans =%lld\n", total, subt, MPN, ans);
  std::cout << ans << std::endl;
  return 0;
  
}


Measured memory_bytes: 11016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;


int main(void){
    ll m,k;
    cin>>m>>k;
    if(m==0){
        if(k==0)cout<<0<<" "<<0<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    if(m==1){
        if(k==0)cout<<0<<" "<<0<<" "<<1<<" "<<1<<endl;
        else cout<<-1<<endl;
        return 0;
    }
    if((ll)pow(2,m)-1<k)cout<<-1<<endl;
    else{
        if(k==0){
            for(ll i=0;i<(ll)pow(2,m);i++){
                if(i==(ll)pow(2,m)-1){
                    cout<<i<<" "<<i<<endl;
                }
                else{
                    cout<<i<<" "<<i<<" ";
                }
            }
        }
        else{
            if(k==(ll)pow(2,m)-1){
                cout<<0<<" "<<k<<" "<<0<<" ";
                for(ll i=(ll)pow(2,m)-2;i>0;i--)cout<<i<<" ";
                cout<<k<<" ";
                for(ll i=1;i<(ll)pow(2,m)-2;i++)cout<<i<<" ";
                cout<<k-1<<endl;
            }
            else{
                cout<<0<<" "<<k<<" "<<0<<" ";
                for(ll i=(ll)pow(2,m)-1;i>0;i--){
                    if(i==k)continue;
                    else cout<<i<<" ";
                }
                cout<<k<<" ";
                for(ll i=1;i<(ll)pow(2,m)-1;i++){
                    if(i==k)continue;
                    else cout<<i<<" ";
                }
                cout<<(ll)pow(2,m)-1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m; cin >> n >> m;
	vector<int> x(m, 0);
	rep(i, 1, n)
	{
		int k; cin >> k;
		rep(j, 1, k)
		{
			int a; cin >> a;
			--a;
			++x[a];
		}
	}
	int res = 0;
	for (int cnt : x)
	{
		if (cnt == n)++res;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
#木の根を求める
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

n, m = map(int,input().split())
bridge = [list(map(lambda x:x-1,list(map(int,input().split())))) for i in range(m)]
par = [i for i in range(n)]
rank = [0] * n
size = [1] * n
res = []
inc = n*(n-1)//2
res.append(inc)
bridge.reverse()
for pair in bridge:
    if same(pair[0],pair[1]):
        unite(pair[0],pair[1])
        res.append(inc)
    else:
        inc -= (size[find(pair[0])] * size[find(pair[1])])
        res.append(inc)
        unite(pair[0],pair[1])

res.reverse()
for ans in res[1:]:
    print(ans)

Measured memory_bytes: 32196
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
 
int dp[1<<26];
 
int main(){
	string s;
	cin>>s;
	int n = s.size();
	fill(dp, dp+(1<<26), INF);
	dp[0] = 0;
	int a = 0;
	rep(i, n){
		int c = s[i]-'a';
		a ^= 1<<c;
		//dp[a]++;
		rep(j, 26){
			int a2 = a^(1<<j);
			chmin(dp[a], dp[a2]+1);
		}
	}
	cout<<max(dp[a], 1)<<endl;
	return 0;
}

Measured memory_bytes: 262788
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
  string S;
  cin >> S;
  if (S[S.size()-1] == 's')
  	std::cout << S << "es" << std::endl;
  else  
  	std::cout << S << "s" << std::endl;
  return 0;
}

Measured memory_bytes: 3624
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> a;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];

	cout << a+a*a+a*a*a << endl;
	return 0;
}


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

const int A = 100, B = 1900;

int pow[ 10 ] = { 1, 2, 4, 8, 16, 32, 64 };

int main(){
	int N, M;
	cin >> N >> M;
	cout << ( ( N - M ) * A + ( M * B ) ) * pow[ M ] << endl;
}

Measured memory_bytes: 256
//bigraph
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<limits>
#include<utility>

//#define c11
#ifdef c11
#include<unordered_set>
#include<unordered_map>
#endif

using namespace std;
typedef long long ll;
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define initz(x) memset(x,0,sizeof(x))
#define initn1(x) memset(x,-1,sizeof(x))
#define initm(x) memset(x,0x3f,sizeof(x))
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define fore(i, l, r) for(int i = (int) l; i <= (int) r; ++i)
#define rforn(i, n) for(int i = (int) n - 1; i>= 0; --i)
#define fi first
#define se second

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 120;
const int MAX_M = 1010;

typedef pair<ll, ll> P;


vector<int> e[1010];
bool checked[1010];
int match[1010];
int n1;

int n, m;
int d[110][110];

int p[1010], t[1010];

bool dfs(int u) {
    for(vector<int>::iterator it = e[u].begin(); it != e[u].end(); ++it) {
        int v = *it;
        if (!checked[v]) {
            checked[v] = 1;
            int w = match[v];
            if (w < 0 || dfs(w)) {
                match[v] = u;
                return true;
            }
        }
    }
    return false;
}

int hungarin() {
    initn1(match);
    int ans = 0;
    forn(i, n1) {
        initz(checked);
        if (dfs(i)) ans++;
    }
    return ans;
}
void floyd(int n) {
    forn(k, n) {
        forn(i, n) {
            forn(j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
//---------------------------------------------
// YOUR CODE
    while (scanf("%d%d%d", &n, &m, &n1) != EOF && n) {
        memset(d, 0x3f, sizeof(d));
        for (int i = 0; i < n; ++i) d[i][i] = 0;
        for (int i = 0; i < m; ++i) {
            int u, v, c;
            scanf("%d%d%d", &u, &v, &c);
            d[u][v] = d[v][u] = c;
        }
        floyd(n);
        for (int i = 0; i < n1; ++i) {
            scanf("%d%d", &p[i], &t[i]);
            e[i].clear();
        }
        for (int i = 0; i < n1; ++i) {
            for (int j = 0; j < n1; ++j) {
                if (i == j) continue;
                if (t[i] + d[p[i]][p[j]] <= t[j]) {
                    e[i].push_back(j);
                }
            }
        }
        printf("%d\n", n1 - hungarin());
    }
//---------------------------------------------
#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}



Measured memory_bytes: 7508
s = input()
t = input()
S = len(s)
T = len(t)

ans = []
for i in range(S):
    if S - i >= T:
        tmp = list(s)
        cnt = 0
        for j in range(T):
            if s[i + j] == t[j] or s[i + j] == "?":
                cnt += 1
                tmp[i + j] = t[j]
            if cnt == T:
                ans.append("".join(tmp).replace("?", "a"))

if len(ans) > 0:
    print(min(ans))
else:
    print("UNRESTORABLE")

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

def dfs(cur):
    if int(cur) > n:
        return 0
    
    if all([cur.count(c) for c in '753']):
        ret = 1
    else:
        ret = 0
    
    for i in '753':    
        ret +=dfs(str(cur)+i)

    return ret 
    
print(dfs('0'))

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

#define int long long
#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()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#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())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
//    ios::sync_with_stdio(false);
//    cout.setf(ios::fixed, ios::floatfield);
//    cout.precision(10);
//    cin.tie(0);

    int n;
    cin >> n;
    string s1,s2;

    string r;
    int state=0;
    while(r!="end"){
        if(r=="T"){
            if(state<=3){
                state=0;
            }else{
                state=4;
            }
        }else if(r=="F"){
            if(state==3){
                s1.pop_back();
                s2.pop_back();
            }
            state++;
        }
        switch (state){
            case 0:
                s1+=".";
                s2+=".";
                break;
            case 1:
                s1.back()='.';
                s2.back()='#';
                break;
            case 2:
                s1.back()='#';
                s2.back()='.';
                break;
            case 3:
                s1.back()='#';
                s2.back()='#';
                break;
            case 4:
                s1.insert(0,".");
                s2.insert(0,".");
                break;
            case 5:
                s1.front()='.';
                s2.front()='#';
                break;
            case 6:
                s1.front()='#';
                s2.front()='.';
                break;
            case 7:
                s1.front()='#';
                s2.front()='#';
                break;
        }
        printf("%s\n%s\n", s1.c_str(), s2.c_str());
        fflush(stdout);
        cin >> r;
    }
    
    return 0;
}

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

int main() {
  int A[4];
  
  string s; cin >> s;
  for (int i = 0; i < s.size(); i++) A[i] = s[i] - '0';
  
  int sum = 0;
  char op[3];
  
  for (int i = 0; i < 8; ++i) {
    sum = A[0];
    for (int j = 0; j < 3; ++j) {
      if (i & (1 << j)) {
        op[j] = '+';
        sum += A[j + 1];
      } else {
        op[j] = '-';
        sum -= A[j + 1];
      }
    }
    if (sum == 7) break;
  }
  
  for (int i = 0; i < 3; ++i) cout << A[i] << op[i];
  cout << A[3] << '=' << 7;
}

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

int main()
{
    string s;
    cin>>s;
    if(s=="AAA" || s=="BBB")
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int N, i;
	cin >> N >> i;
	
	// 解法
	int ans = N-i+1;
	printf("%lld\n", ans); // lld としないとオーバーフローする
}
 


Measured memory_bytes: 256
N,Q=map(int,input().split())
edge=[[] for _ in range(N)]
cnt=[0]*N
for _ in range(N-1):
  a,b=map(int,input().split())
  edge[a-1]+=(b-1),
  edge[b-1]+=(a-1),
for _ in range(Q):
  p,x=map(int,input().split())
  cnt[p-1]+=x
done=[False]*N
done[0]=True
stack=[0]
while stack:
  par=stack.pop()
  for child in edge[par]:
    if not done[child]:
      done[child]=True
      cnt[child]+=cnt[par]
      stack.append(child)
print(*cnt)


Measured memory_bytes: 55856
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int n = 0;
	public static void main(String[] args) throws Exception{
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			n = Integer.parseInt(br.readLine());
			String re;
			if(n == 3 || n == 5 || n == 7) re = "YES";
			else re = "NO";
			System.out.println(re);
		}

	}

}

Measured memory_bytes: 20948
using System;

namespace moff4 {
    class MainClass {
        //const int max = 1000000000;
        public static void Main(string[] args) {

            // 以下の2文が加わるだけです！
            //var exStdIn = new System.IO.StreamReader("stdin.txt");
            //System.Console.SetIn(exStdIn);

            var str = System.Console.ReadLine();
            var n = int.Parse(str);

            int i = n;
            while (true) {
                if (i % 2 == 0 && i % n == 0) {
                    Console.WriteLine(i);
                    return;
                }
                i+=n;
            }
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,X,T,ans,a;
  scanf("%d %d %d",&N,&X,&T);
  a=N/X;
  if(N%X!=0) a++;
  ans=T*a;
  printf("%d",ans);
  return 0;
}



Measured memory_bytes: 1732
#include <cmath>
#include <iostream>
#include <vector>
typedef std::vector <int> vi;
vi PRIMES;
vi prime(int n){
    vi s,p;
    int i,j,x,h;
    for (i=1;i<=n;i+=2) s.push_back(i);
	h=s.size();
    s[0]=0;
    for (i=1;i<int(pow(n,0.5)+1)+1;i++){
		x=s[i];
        if (x) for (j=i+x;j<h;j+=x) s[j]=0;
	}
	s[0]=2;
	for (i=0;i<h;i++) if(s[i]!=0) p.push_back(s[i]);
	return p;
}
int main(void){
	int n,s,i;
	PRIMES=prime(105000);
	while (true){
		std::cin>>n; if (n==0) break;
		s=0;
		for (i=0;i<n;i++) s+=PRIMES[i];
		std::cout<<s<<"\n";
	}
} 

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

int d;
vector<int> c(26);
vector<vector<int>> s;
vector<int> t, now;
vector<int> last(26, -1);
ll best = 0;

ll score(){
    ll res = 0;
    rep(i,26)last[i] = -1;
    rep(i,d){
        res += s[i][t[i]];
        last[t[i]] = i;
        rep(j,26) res -= c[j] * (i - last[j]);
    }
    return res;
}

int main(){
    auto start = std::chrono::system_clock::now();      // 計測スタート時刻を保存
    random_device seed;
    mt19937 mt(seed());
    uniform_int_distribution<int> rnd1(0,25);

    cin >> d;
    uniform_int_distribution<int> rnd2(0,d-1);

    rep(i,26) cin >> c[i];
    s.resize(d);
    rep(i,d)s[i].resize(26);
    rep(i,d)rep(j,26) cin >> s[i][j];
    t.resize(d);
    rep(i,d)t[i] = rnd1(mt);
    best = score();
    // vecprint(t);
    while(true){
        auto end = std::chrono::system_clock::now();       // 計測終了時刻を保存
        auto dur = end - start;        // 要した時間を計算
        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
        if(msec>=1900) break;

        int day = rnd2(mt);
        int con = rnd1(mt);
        int old = t[day];
        t[day] = con;
        ll now_s = score();
        if(best < now_s) best = now_s;
        else t[day] = old;
    }

    // cout << score() << endl;
    rep(i,d)cout << t[i]+1 << endl;

    return 0;
}

Measured memory_bytes: 3696
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, a[101010], b[101010];
vector<int> v;
LL ans;
int main(){
    INIT;
    cin >> n;
    REP(i, n){
        cin >> a[i] >> b[i];
        ans -= b[i];
        v.emplace_back(a[i] + b[i]);
    }
    sort(ALL(v));
    reverse(ALL(v));
    REP(i, n){
        if(i%2 == 0)ans += v[i];
    }
    cout << ans << endl;
}


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

using namespace std;

const int MaxN = 200005;

int n;
pair<int, int> a[MaxN];
multiset<int> s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    if (n < 2)
    {
        cout << 0;
        return 0;
    }
    int Low = 1e9, High = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first >> a[i].second;
        if (a[i].first > a[i].second)
        {
            swap(a[i].first, a[i].second);
        }
        Low = min(Low, a[i].first);
        High = max(High, a[i].second);
    }
    int RedMin = Low, RedMax = 0;
    int BlueMin = 1e9, Bluemax = High;
    for (int i = 1; i <= n; i++)
    {
        RedMax = max(RedMax, a[i].first);
        BlueMin = min(BlueMin, a[i].second);
    }
    long long Res = 1LL * (RedMax - RedMin) * (Bluemax - BlueMin);
    sort(a + 1, a + n + 1);
    Res = min(Res, 1LL * (High - Low) * (a[n].first - a[1].first));
    s.clear();
    for (int i = 1; i <= n; i++)
    {
        s.insert(a[i].first);
    }
    for (int i = 1; i <= n; i++)
    {
        s.erase(s.find(a[i].first));
        s.insert(a[i].second);
        Res = min(Res, 1LL * (High - Low) * (*s.rbegin() - *s.begin()));
    }
    cout << Res;
    return 0;
}


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

const int INF = 1<<29;

int main(){
    int n, m;
    int a[1000], b[1000], c[1000];
    int d[100][100];

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }

    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            if(i == j)  d[i][j] = 0;
            else        d[i][j] = INF;
        }
    }

    for(int i = 0; i < m; i++){
        d[a[i]][b[i]] = d[b[i]][a[i]] = min(d[a[i]][b[i]], c[i]);
    }

    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(d[i][k] == INF || d[k][j] == INF)    continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = m;
    for(int i = 0; i < m; i++){
        bool use = false;
        for(int s = 0; s < n; s++){
            if(d[s][b[i]] == d[s][a[i]] + c[i]) use = true;
        }
        if(use) ans--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = list(map(int, input().split()))
s = input()

able = True
turn = []
ptr = n
searched = 0
while ptr != 0:
  goto = 0
  for i in range(1+searched, m+1):
    if ptr - i == 0:
      goto = i
      break
    elif s[ptr-i] == '0':
      goto = i
  if goto == 0:
    able = False
    break
  else:
    turn.append(goto)
    ptr -= goto
    searched = m - goto
#  print ('GOTO=' + str(goto), 'PTR=' + str(ptr))

if able:
  while len(turn):
    print(turn.pop())
else:
  print(-1)

Measured memory_bytes: 4720
#include <bits/stdc++.h>
/*#define fatafat 
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);*/
#define int long long
#define MOD ((long long)(1e9) + 7)
#define excl(i, a, b) for (int i = a; i < b; i++)
#define incl(i, a, b) for (int i = a; i <= b; i++)
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define PII pair<int, int>

using namespace std;

int binexp(int a, int b) {
  if (b) {
    if (b % 2)
      return a * binexp(a * a, b / 2);
    return binexp(a * a, b / 2);
  }
  return 1;
}

int modexp(int a, int b, int m) {
  if (b) {
    if (b % 2)
      return (a * modexp((a * a) % m, b / 2, m)) % m;
    return modexp((a * a) % m, b / 2, m);
  }
  return 1;
}

int mygcd(int a, int b) {
  if (b == 0)
    return a;
  return mygcd(b, a % b);
}

int euclidgcd, euclidx, euclidy;

void exteuclid(int a, int b) {
  if (b == 0) {
    euclidgcd = a;
    euclidx = 1;
    euclidy = 0;
  } else {
    exteuclid(b, a % b);
    int temp = euclidx;
    euclidx = euclidy;
    euclidy = temp - euclidy * (a / b);
  }
}

int modinv(int a, int m) {
  exteuclid(a, m);
  return (euclidx % m + m) % m;
}

int pmodinv(int a, int m) { return modexp(a, m - 2, m); }

bool checkprime(int a) {
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0)
      return false;
  return true;
}

vector<bool> seive(int n) {
  vector<bool> ret(n + 1, true);
  ret[0] = ret[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (ret[i])
      for (int j = i * i; j <= n; j += i)
        ret[j] = false;
  return ret;
}

vector<bool> seivelims(int l, int r) {
  vector<bool> ret(r - l + 1, true);
  for (int i = 2; i * i <= r; i++) {
    for (int j = max(i * i, ((l + i - 1) / i) * i); j <= r; j += i) {
      ret[j - l] = false;
    }
  }
  return ret;
}

vector<int> rootnfact(int n) {
  vector<int> ret;
  for (long i = 2; i * i <= n; i++)
    while (n % i == 0) {
      ret.push_back(i);
      n /= i;
    }
  if (n != 1)
    ret.push_back(n);
  return ret;
}

vector<int> prelognfact(int n) {
  vector<int> minprime(n + 1, 0);
  minprime[0] = minprime[1] = 0;
  for (int i = 2; i * i <= n; i++) {
    if (minprime[i] == 0) {
      for (int j = i * i; j <= n; j += i) {
        if (minprime[j] == 0)
          minprime[j] = i;
      }
    }
  }
  for (int i = 2; i <= n; i++)
    if (minprime[i] == 0)
      minprime[i] = i;
  return minprime;
}

vector<int> lognfact(int n, vector<int> minprime) {
  vector<int> ret;
  while (n != 1) {
    ret.push_back(minprime[n]);
    n /= minprime[n];
  }
  return ret;
}

int temp, temp1, temp2;

signed main() 
{ 
    //fatafat; 
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int max=-1,cnt=0;
    bool found=false;
    for(int i=0;i<n;i++)
    {
        found=false;
        for(int j=0;j<i;j++)
        {
            if(arr[j]>arr[i])
            {
                found=true;
                break;
            }
        }
        if(!found)
            cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 256
n = int(input())
t_scr = 0
h_scr = 0
for _ in range(n):
    t_crd,h_crd = input().split()
    if t_crd>h_crd:
        t_scr += 3
    elif t_crd<h_crd:
        h_scr += 3
    else:
        t_scr += 1
        h_scr += 1
print(t_scr,h_scr)


Measured memory_bytes: 5596
def calc(n):
	cnt_2=0
	cnt_5=0
	while n%2==0:
		n/=2
		cnt_2+=1

	while n%5==0:
		n/=5
		cnt_5+=1

	return cnt_2,cnt_5


while True:
	N=input()
	if N==0: quit()
	
	t2=0
	t5=0
	for i in range(N,0,-1):
		x,y=calc(i)
		t2+=x
		t5+=y
	print min(t2, t5)



Measured memory_bytes: 5088
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Multiple Gift
	var X, Y int
	fmt.Scanf("%d %d", &X, &Y)

	var A int
	for i := 1; ; i++ {
		A = X * int(math.Pow(2, float64(i-1)))

		if A == Y {
			fmt.Println(i)
			break
		} else if A > Y {
			fmt.Println(i - 1)
			break
		}
	}
}


Measured memory_bytes: 1840
import collections
N = int(input())
C = collections.Counter([input()[0] for _ in range(N)]).most_common()
CC = {c[0]:c[1] for c in C if c[1] != 0 and c[0] in ['M','A','R','C','H']}
count = 0
s = []
for k1,v1 in CC.items():
    for k2,v2 in CC.items():
        for k3,v3 in CC.items():
            key = ''.join(sorted([k1,k2,k3]))
            if k1 != k2 and k2 != k3 and k1 != k3 and key not in s:
                s.append(key)
                count += v1*v2*v3
print(count)

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    //cin >> n;
    //n >> x >> y;
    cin >> s;
  for(int i=0;i<s.size()-1;i++){
  if(s[i]==s[i+1]){
    cout <<"Bad";
    return 0;
  }
  }
  
  cout << "Good";
}

Measured memory_bytes: 3644