akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <functional>
#include <ios>
#include <iomanip>
using namespace std;

typedef long long ll;
const ll InF = 1e15;

int main() {
  int N,M;
  cin>>N>>M;
  vector< pair<int, ll> > orgs(M);
  map<int, vector<ll> > mp;
  for (int i = 0; i < M; i++) {
    int p; cin>>p;
    ll y; cin>>y;
    orgs[i].first = p;
    orgs[i].second = y;
    mp[p].push_back(y);
  }
  for (int i = 1; i <= N; i++) {
    sort(mp[i].begin(),mp[i].end());
  }
  for (int i = 0; i < M; i++) {
    int tmp = orgs[i].first;
    ll key = orgs[i].second;
    int j = distance(mp[tmp].begin(),lower_bound(mp[tmp].begin(),mp[tmp].end(),key));
    cout<<setfill('0')<<right<<setw(6)<<tmp;
    cout<<setfill('0')<<right<<setw(6)<<j+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e5 + 5 ;
int main()
{
	ios::sync_with_stdio(false) ;
    cin.tie(0) ;
    int n , m ;
    cin >> n >> m ;
    if(n == m)  cout << "Yes\n" ;
    else  cout << "No\n" ;
    return 0 ;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, A, B;
    std::cin >> N >> A >> B;

    auto diff = std::abs(A - B);

    if (diff % 2 == 0) {
        std::cout << "Alice" << std::endl;
    }
    else {
        std::cout << "Borys" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
long long func(long long r, long long l) {
	long long dp[65][3][3][3] = {};
	dp[60][0][0][0] = 1;
	for (long long i = 60; i >= 1; --i) {
		REP(q, 3) {
			REP(j, 3) {
				REP(t, 3) {
					long long now_A = q * 2;
					if ((r & (1LL << (i - 1LL))) != 0) {
						now_A++;
					}
					long long now_C = j * 2;
					if ((l & (1LL << (i - 1LL))) != 0) {
						now_C--;
					}
					long long D = t * 2;
					//not taken as Y
					if (now_C >= 0) {
						dp[i - 1][min(2LL, now_A)][min(2LL, now_C)][min(D,2LL)] += dp[i][q][j][t];
						dp[i - 1][min(2LL, now_A)][min(2LL, now_C)][min(D,2LL)] %= MAX_MOD;
					}
					//Taken as Y,but not for X
					if (now_C >= 0 && now_A >= 1&& D>= 1) {
						dp[i - 1][min(2LL, now_A - 1)][min(2LL, now_C)][min(D-1LL,2LL)] += dp[i][q][j][t];
						dp[i - 1][min(2LL, now_A - 1)][min(2LL, now_C)][min(D-1LL,2LL)] %= MAX_MOD;
					}
					//Taken as X,Y
					if (now_A >= 1) {
						dp[i - 1][min(2LL, now_A - 1)][min(2LL, now_C + 1)][min(D+1LL,2LL)] += dp[i][q][j][t];
						dp[i - 1][min(2LL, now_A - 1)][min(2LL, now_C + 1)][min(D+1LL,2LL)] %= MAX_MOD;
					}
				}
			}
		}
	}
	long long ans = 0;
	REP(i, 3) {
		REP(q, 3) {
			REP(t, 2) {
				ans += dp[0][i][q][t+1];
				ans %= MAX_MOD;
			}
		}
	}
	return ans;
}
int main() {
	long long l, r;
	cin >> l >> r;
	cout << func(r, l)%MAX_MOD << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

int Z_algorithm(string &S, vector<int>& A){
	A.assign(S.size(), 0);
	
	A[0] = S.size();
	
	for(int i = 1, j = 0; i < S.size();){
		while(i+j < S.size() && S[j] == S[i+j]) ++j;
		
		A[i] = j;
		
		if(j == 0) { ++i; continue;}
		
		int k = 1;
		
		while(i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
		
		i += k; j -= k;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int NUM = 26;
	int N, ans = 0;
	vector<vector<int>> a,b;
	string S, T;
	
	cin>>N;
	cin>>S;
	
	for(int i = 0; i < N; i++){
		vector<int> A;
		
		Z_algorithm(S, A);
		
		for(int j = 0; j < S.size(); j++){
			ans = max(ans, min(j, A[j]));
		}
		
		S.erase(S.begin());
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#define N 101
#define INF 500001 
int n;

int A[N][N];
int color[N];
int d[N];

void dijkstra(int root) {
    d[root] = 0;

    while(true) {
        int added = -1;
        int minw = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] == 0 && d[i] < minw) {
                added = i;
                minw = d[i];
            }
        }

        if (added == -1) {
            break;
        }

        color[added] = 1;
        for (int i = 0; i < n; i++) {
            if (color[i] == 0 && (d[added] + A[added][i]) < d[i]) {
                d[i] = d[added] + A[added][i];
            }
        }
    }
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            A[i][j] = INF;
        }
    }

    int w;
    int node;
    int k;
    int ad;
    for (int i = 0; i < n; i++) {
        color[i] = 0;
        d[i] = INF;

        cin >> node >> k;
        for (int j = 0; j < k; j++) {
            cin >> ad >> w;
            A[i][ad] = w;
        }
    }

    dijkstra(0);

    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	for(int i=0;i<b.length();i++) cout<<a[i]<<b[i];
	if(a.length()-b.length()==1) cout<<a[a.length()-1];
	return 0;
}

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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), B(N), memo(N); // memoには，A_i+B_iの値を格納
  for (int i=0; i<N; i++) {
    cin >> A[i] >> B[i];
    memo[i] = A[i]+B[i];
  }
  sort(memo.begin(), memo.end());
  reverse(memo.begin(), memo.end());
  ll ans = 0LL;
  for (int i=0; i<N; i+=2) ans += memo[i];
  ans -= accumulate(B.begin(), B.end(), 0LL);
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define vec vector
#define sz(c) int(c.size())
#define FOR(i, a, b) for (int i = a; i < (b); ++i)
#define DOWN(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define cerr2 cerr << __func__ << ":" << __LINE__ << ": "
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vec<int> vi;
#define y1 y123
#define fmax fmax123

int const MAXCOORD = (int) 1e8;
int const MAXN = (int) 2e5 + 10;

int x1, y1, x2, y2;
int n;
int x[MAXN];
int y[MAXN];
int fmax[MAXN];

void update(int pos, int val) {
  for (int i = pos; i < MAXN; i |= i + 1) {
    fmax[i] = max(fmax[i], val);
  }
}

int getmax(int pos = MAXN - 1) {
  int res = 0;
  for (int i = pos; i >= 0; i &= i + 1, --i) {
    res = max(res, fmax[i]);
  }
  return res;
}

int main() {
  cin.tie(0);
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(false);
  
  cin >> x1 >> y1 >> x2 >> y2;
  bool flip_x = x1 > x2;
  bool flip_y = y1 > y2;

  if (flip_x) {
    x1 = MAXCOORD - x1;
    x2 = MAXCOORD - x2;
  }
  if (flip_y) {
    y1 = MAXCOORD - y1;
    y2 = MAXCOORD - y2;
  }

  cin >> n;
  FOR(i, 0, n) {
    cin >> x[i] >> y[i];
    if (flip_x) {
      x[i] = MAXCOORD - x[i];
    }
    if (flip_y) {
      y[i] = MAXCOORD - y[i];
    }
  }

  vec<int> xs(x, x + n);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  map<int,int> posx;
  FOR(i, 0, sz(xs)) {
    posx[xs[i]] = i;
  }

  vec<pii> pts;
  pts.reserve(n);
  FOR(i, 0, n) {
    if (x[i] >= x1 && x[i] <= x2 && y[i] >= y1 && y[i] <= y2) {
      pts.emplace_back(y[i], x[i]);
    }
  }
  sort(pts.begin(), pts.end());

  for (pii pt : pts) {
    int i = posx[pt.second];
    update(i, getmax(i) + 1);
  }
  
  int count = getmax();
  
  double res = 100.0 * (x2 - x1 + y2 - y1) - count * (20 - 5 * M_PI);
  if (min(x2 - x1, y2 - y1) + 1 == count) {
    res += 5 * M_PI;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 14336
#include<stdio.h>
#include<stdlib.h>
int main(void){

  int a[100000]={};
  int getSum[100000]={};
  int i=0;  
  int time=0;
  int b,x,s,t,n,q,d;

  scanf("%d %d",&n,&q);
  if(1>n||n>100000||1>q||q>100000){
  printf("Too Large\n");
  exit(0);
  }


  while(i<q){
    i++;
   scanf("%d",&b);

   if(b==0){
   scanf("%d",&d);
   scanf("%d",&x);
   if(d>n||x>1000){
   printf("Too Large\n");
   exit(0);
   }

   a[d] += x;
   }
 
   else if(b==1){
     time++;
   scanf("%d",&s);
   scanf("%d",&t);
   
   if(s>n||t>n){
   printf("Too Large\n");
   exit(0);
   }

   for(s;s<=t;s++){
     getSum[time] += a[s];
   }

   }


  }

  i=0;

  while(i<time){
    ++i;
    printf("%d\n",getSum[i]);

  }
  


}

Measured memory_bytes: 2616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n;
    cin >> n;
    ll ans = 0, s = 1;
    REP(d,10){
        s *= 3;
        REP(mask,s){
            ll x = 0, t = 1, m = mask;
            int c = 0;
            REP(i,d+1){
                if (m % 3 == 0) x += t * 3, c |= 1;
                else if (m % 3 == 1) x += t * 5, c |= 2;
                else x += t * 7, c |= 4;
                t *= 10;
                m /= 3;
            }
            if (x <= n && c == 7){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	d = readline() |> parseInt
	c = readline() |> split |> parseMap
	a = zeros(Int,d,26)
	for i in 1:d
		a[i,:] = readline() |> split |> parseMap
	end
	l = zeros(Int,26)
	v = 0
	for i in 1:d
		t = readline() |> parseInt
		v += a[i,t]
		l[t] = i
		for j in 1:26
			v -= c[j]*(i-l[j])
		end
		println(v)
	end
end

main()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

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

const int mn=39;

int n;
char s[mn];

unordered_map<size_t,int> h;
hash<string> hs;

string t;
inline size_t gethash(string &s){
    return hs(s);
}

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif

    scanf("%d",&n);
    scanf("%s",s);

    ll ans=0;

    for(int i=0;i<(1<<n);i++){
        t.clear();
        for(int j=0;j<n;j++){
            if ((1<<j)&i) t+=s[j];
        }
        for(int j=n-1;j>=0;j--){
            if (((1<<j)&i)==0) t+=toupper(s[j]);
        }
        h[gethash(t)]++;
    }

    reverse(s,s+n*2);
    for(int i=0;i<(1<<n);i++){
        t.clear();
        for(int j=0;j<n;j++){
            if ((1<<j)&i) t+=s[j];
        }
        for(int j=n-1;j>=0;j--){
            if (((1<<j)&i)==0) t+=toupper(s[j]);
        }
        ans+=h[gethash(t)];
    }
    printf("%lld\n",ans);

    return 0;
}



Measured memory_bytes: 28788
import java.util.Scanner;
public class Main{

   public static void main(String[] args){
      new Main().solve();
   }

   public void solve(){
      Scanner scanner = new Scanner(System.in);
      long x = scanner.nextLong();
      long y = scanner.nextLong();
      long btnCount = 0;
      if(Math.abs(x) == Math.abs(y)){
        btnCount = 1;
      }else if(Math.abs(x) > Math.abs(y)){
         if(x >= 0){
            btnCount = Math.abs(x)-Math.abs(y);
            if(y > 0) btnCount += 2;
            else btnCount += 1;
         }else{
            if(y > 0) btnCount = Math.abs(x)-y+1;
            else btnCount = y-x;
         }
      }else{
         if(x >= 0){
            if(y >= 0) btnCount = y-x;
            else btnCount = Math.abs(y)-x+1;
         }else{
            if(y >= 0) btnCount = y-Math.abs(x)+1;
            else btnCount = x-y+2;
         }
      }
      System.out.println(btnCount);
   }
}


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

nums = input().rstrip().split(' ')

even_num = []
for i in range(N):
    if int(nums[i]) % 2 == 0:
        even_num.append(int(nums[i]))

count = 0
for j in range(len(even_num)):
    if int(even_num[j]) % 3 == 0 or int(even_num[j]) % 5 == 0:
        count += 1

if count == len(even_num):
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
import java.util.*;

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

    int n = sc.nextInt();
    String s = sc.next();
    String s1 = " ";
    String s2 = " ";
    int ans = 0;

    for(int v1 = 0; v1 < 10; v1++){
      int p1 = 0;
      for(int i = 0; i < n; i++){
        if(s.charAt(i) == v1 + '0'){
          s1 = s.substring(i + 1);
          p1 = 1;
          break;
        }
      }
      if(p1 == 0){
        continue;
      }
      for(int v2 = 0; v2 < 10; v2++){
        int p2 = 0;
        for(int i = 0; i < s1.length(); i++){
          if(s1.charAt(i) == v2 + '0'){
            s2 = s1.substring(i + 1);
            p2 = 1;
            break;
          }
        }
        if(p2 == 0){
          continue;
        }
        for(int v3 = 0; v3 < 10; v3++){
          for(int i = 0; i < s2.length(); i++){
            if(s2.charAt(i) == v3 + '0'){
              ans += 1;
              break;
            }
          }
        }
      }
    }


    System.out.println(ans);
  }
}


Measured memory_bytes: 28372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    
    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    
    unsigned long int len = s.length();
    
    int c_counter = 0;
    for (int i = 2; i <= len - 2; i++) {
        if (s[i] == 'C') c_counter++;
    }
    if (c_counter != 1) {
        cout << "WA" << endl;
        return 0;
    }
    
    for (int i = 0; i < len; i++) {
        if (s[i] != 'A' && s[i] != 'C' && !('a' <= s[i] && s[i] <= 'z') ) {
            cout << "WA" << endl;
            return 0;
        }
    }
    
    cout << "AC" << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  bool exp[1005];
  memset(exp,false,sizeof(exp));
  int x;
  cin >> x;
  exp[1]=true;
  for(int i=2;i<=31;i++)
    {
      int tmp=i;
      while(tmp*i<=1000)
	{
	  tmp*=i;
	  exp[tmp]=true;
	}
    }

  for(int i=x;i>=0;i--)
    {
      if(exp[i]==true)
	{
	  cout << i << endl;
	  return 0;
	}
    }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll a,b;cin>>a>>b;
    if (b>=a) cout<<a<<endl;
    else if (a==1) cout<<1<<endl;
    else cout<<a-1<<endl;
    return 0;
}


Measured memory_bytes: 3572
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,e,sum=0,p; cin>>n;
    rep(i,n){
        sum+=i+1;
        if(sum>=n){
            p=i+1;
            break;
        }
    }
    e=sum-n;
    rep(i,p){
        if(e==i+1) continue;
        printf("%d\n",i+1);
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int prime[10000];
	bool num[110000]; for(int i=0;i<110000;i++) num[i]=false;
	num[0]=num[1]=true;
	for(int i=2;i<110000;i++)
	{
		if(num[i]==true) continue;
		for(int j=i*2;j<110000;j+=i) num[j]=true;
	}
	int pnt=0;
	for(int i=0;i<110000;i++)
	{
		if(num[i]==false) prime[pnt++]=i;
		if(pnt>=10000) break;
	}
	//以上が素数の列挙
	int n;
	while(1)
	{
		cin >> n ; if(n==0) break;
		int sum=0;
		for(int i=0;i<n;i++) sum+=prime[i];
		cout << sum << '\n' ;
	}
}

Measured memory_bytes: 1304
#include<iostream>
#include<vector>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
ll h[100000];
ll a, b;
bool good[100000];
ll n, m;

int main() {
    cin >> n >> m;
    for (ll i = 0; i < n; i++) {
        cin >> h[i];
        good[i] = true;
    }
    for (ll i = 0; i < m; i++) {
        cin >> a >> b;
        if (h[a - 1] > h[b - 1]) {
            good[b - 1] = false;
        } else if (h[a - 1] < h[b - 1]) {
            good[a - 1] = false;
        } else {
            good[a - 1] = false;
            good[b - 1] = false;
        }
    }
    ll count = 0;
    for (ll i = 0; i < n; i++) {
        if (good[i]) {
            count++;
        }
    }
    cout << count << endl;
}


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

int main()
{
    string str, ring;
    int n, sum = 0;

    cin >> str;
    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> ring;
        bool judge = false;
        for( int j = 0; j < 20; j++ )
        {
            string key = "";
            for( int k = 0; k < str.size(); k++ )
                key += ring[(j+k)%10];
            if( str == key )
                judge = true;
        }
        if( judge == true )
            sum++;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>
int main(void)
{
	int S,T,ST,a,b,c,d,e,f,g,h;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	scanf("%d %d %d %d",&e,&f,&g,&h);
	S=a+b+c+d;
	T=e+f+g+h;
	if(S<T){
		printf("%d\n",T);
	}
	else{
		printf("%d\n",S);
	}
	return 0;
}

Measured memory_bytes: 1020
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		if (i % 2 == 1) { ++ans; }
	}

	cout << setprecision(20) << (double)ans / (double)n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#define N 201000
#define int long long
typedef long long ll;
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
}
using namespace std;
const int inf = 1e18;
inline void MAX(ll &a, ll b) {
  if (b > a)  a = b;
}
int A, B, C, n;
ll ans = -inf, tmp;
struct node {
  int a, b;
}nd[N];
bool cmp(const node &a, const node &b) {
  return a.a - a.b > b.a - b.b;
}
ll f[N];
priority_queue<int, vector<int>, greater<int> > q;
inline void work() {
  ll res = 0;
  for (int i = 1; i <= A; ++i) {
    q.push(nd[i].a); res += nd[i].a;
  }
  f[A] = res;
  for (int i = A + 1; i <= n; ++i) {
    int a = nd[i].a;
    if (q.top() < a)  res -= q.top(), q.pop(), q.push(a), res += a;
    f[i] = res;
  }
  while (!q.empty())  q.pop();
  res = 0;
  for (int i = n; i > n - B; --i) q.push(nd[i].b), res += nd[i].b;
  MAX(ans, res + f[n - B]);
  for (int i = n - B; i > A; --i) {
    int b = nd[i].b;
    if (q.top() < b)  res -= q.top(), q.pop(), q.push(b), res += b;
    MAX(ans, res + f[i - 1]);
  }
  printf("%lld\n", ans + tmp);
}
signed main() {
  read(A), read(B), read(C);
  n = A + B + C;
  for (int i = 1; i <= n; ++i) {
    int a, b, c; read(a), read(b), read(c);
    tmp += c;
    nd[i] = (node){a - c, b - c};
  }
  sort(nd + 1, nd + 1 + n, cmp);
  work();
  return 0;
}

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

int f(vector<vector<int>> &cum, bitset<16> b, int k)
{
    int h = cum.size();
    int w = cum.front().size();
    vector<vector<int>> x(b.count() + 1, vector<int>(w, 0));
    int prev = -1;
    int idx = 0;
    int ret = b.count();
    for (int i = 0; i < 16; i++)
    {
        if (b[i])
        {
            for (int j = 1; j < w; j++)
            {
                x[idx][j] = cum[i + 1][j] - cum[prev + 1][j];
            }
            prev = i;
            idx++;
        }
    }
    for (int i = 1; i < w; i++)
    {
        x.back()[i] = cum.back()[i] - cum[prev + 1][i];
    }

    // cout << endl;
    // for (auto y : x)
    // {
    //     for (auto z : y)
    //     {
    //         cout << z << " ";
    //     }
    //     cout << endl;
    // }

    int start = 0;
    while (start < w)
    {
        int l = start;
        int r = w - 1;
        bool flag = true;
        for (int i = 0; i < x.size(); i++)
        {
            if (x[i][r] - x[i][l] > k)
            {
                flag = false;
            }
        }
        if (flag)
        {
            break;
        }
        while (r - l > 1)
        {
            int c = (l + r) / 2;
            flag = true;
            for (int i = 0; i < x.size(); i++)
            {
                if (x[i][c] - x[i][start] > k)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                l = c;
            }
            else
            {
                r = c;
            }
        }
        if (l == start)
        {
            return h * w;
        }
        if (l == w - 1)
        {
            break;
        }
        ret++;
        // cout << "start: " << start << endl;
        // cout << "l: " << l << endl;
        start = l;
    }
    return ret;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<int>> choco(H, vector<int>(W));
    string S;
    for (int i = 0; i < H; i++)
    {
        cin >> S;
        for (int j = 0; j < W; j++)
        {
            choco[i][j] = S[j] - '0';
        }
    }

    vector<vector<int>> cum(H + 1, vector<int>(W + 1, 0));
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            cum[i][j] = cum[i - 1][j] + cum[i][j - 1] - cum[i - 1][j - 1] + choco[i - 1][j - 1];
        }
    }

    int ans = H + W - 2;
    // ans = min(ans, f(cum, bitset<16>(0), K));
    for (int i = 0; i < (1 << (H - 1)); i++)
    {
        bitset<16> b(i);
        // cout << i << " " << f(cum, b, K) << endl;
        ans = min(ans, f(cum, b, K));
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N, M = map(int,input().split())

L_max = 0
R_min = 100000
flag = False
for i in range(M):
    L, R = map(int,input().split())
    if R_min >= L:        
        if L_max <= L:
            L_max = L
    
        if R_min >= R:
            R_min = R
    else:
        flag = True

if flag:
    print(0)
else:
    print(R_min-L_max+1)

Measured memory_bytes: 48872
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
using ll=long long;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  vector<int> cnt(1000111);
  for(int i:a){
    if(cnt[i]!=0){
      cnt[i]=2;
      continue;
    }
    for(int j=i;j<1000111;j+=i)cnt[j]++;
  }
  int ans=0;
  for(int i:a){
    if(cnt[i]==1)ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 8016
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll kai(vector<ll> A, ll key) {
	ll an = 0;
	rep(i, A.size()) {
		an += (A.at(i) - 1) / key;
	}
	return an;
}
using Graph = vector<vector<int>>;
ll k = 0;
// 深さ優先探索
vector<bool> seen;
void dfs(const Graph& G, int v) {
    k++;
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;
    ll an = 0;
    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    rep(i, N) {
        if (seen[i] == true)continue;
        else {
            dfs(G, i);
            an = max(an, k);
            k = 0;
        }
    }
    cout << an << endl;
}




Measured memory_bytes: 23496
#[allow(unused_imports)]
use std::char::*;
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;

fn main() {
    let n: i32 = read();
    println!("{}", if n%2 == 0 {n/2-1} else {n/2});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    int total=0,ex=0;
    for(int i=0;i<N;i++){
        int p;cin>>p;
        total+=p;ex=max(ex,p);
    }
    cout<<total-ex/2<<endl;
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
int n;
int main(){
    n = read();
    cout << n + n * n + n * n * n << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define cerr                                                                   \
  if (true)                                                                    \
  cerr
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> a) {
  vll v(100100, 0);

  REP(i, N) {
    v[a[i]]++;
    v[a[i] - 1]++;
    v[a[i] + 1]++;
  }

  ll ans = 0;
  REP(i, v.size()) {
    ans = max(ans, v[i]);
    // if (ans == v[i])
    // cerr << i << ":" << ans << endl;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> a(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> a[i];
    a[i]++;
  }
  solve(N, a);
  return 0;
}


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

long long int min_ans(vector<long long int>v , long long int n , long long int k)
{
	long long int height[n];
	
	height[0]=0;
	
	for(long long int i=1;i<=k && i<n;i++)
	{
		long long int update= abs(v[i]-v[i-1]) + height[i-1];
		for(long long int j=2;j<=i;j++)
		{
			update = min(update , abs(v[i]-v[i-j])+height[i-j]);	
		}
		height[i] = update ;	
		}
	
	
	for(long long int i=k;i<n;i++)
	{
		long long int update= abs(v[i]-v[i-1]) + height[i-1];
		for(long long int j=2;j<=k;j++)
		{
			update=min(update, abs(v[i]-v[i-j]) + height[i-j]);
		}
		
		height[i] = update ;
	}
	
	return height[n-1];
}

int main()
{
	long long int n,k;
	cin>>n>>k;
	
	vector<long long int>v(n);
	
	for(long long int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	
	cout<<min_ans(v,n,k);
	
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(){
        while(1){
                int t, n;
                scanf("%d", &t);
                if(t==0) break;
                scanf("%d", &n);

                int sm = 0, i;
                for(i=0; i<n; i++){
                        int s, f;
                        scanf("%d %d", &s, &f);
                        sm += f - s;
                }
                if(sm-t<0) printf("%d\n", t-sm);
                else puts("OK");
        }
        return 0;
}


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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	ll w,h,x,y;
	cin>>w>>h>>x>>y;
	if (2*x==w&&2*y==h){
		cout<<(ld)(w*h)/2<<" "<<"1";
	}
	else {
		cout<<(ld)(w*h)/2<<" "<<"0";
	}
	return 0;
}

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


int main() {
  int A, B;
  cin >> A >> B;
  int ab = A + B;
  if (ab % 2 == 0){
    cout << ab / 2 << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef complex<double> P;
namespace std{
  bool operator < (const P &a,const P &b){
    return ( a.real()==b.real() ? a.imag() < b.imag() : a.real() < b.real() );
  }
};
 
P getCrossPointCC(P p1,double r1,P p2,double r2){
  double cA = (r1*r1+norm(p1-p2)-r2*r2) / (2.0*r1*abs(p1-p2));
  return p1+(p2-p1)/abs(p1-p2)*r1*P(cA,sqrt(1.0-cA*cA));
}
 
int n;
P p1,p2;
double px,py,r1,r2;
 
int main(){
   
  cin>>px>>py>>r1;
  p1=P(px,py);
  cin>>px>>py>>r2;
  p2=P(px,py);
   
  P A=getCrossPointCC(p1,r1,p2,r2);
  P B=getCrossPointCC(p2,r2,p1,r1);
  P a=min(A,B),b=max(A,B);
  printf("%.9f %.9f %.9f %.9f\n",a.real(),a.imag(),b.real(),b.imag());
  return 0;
}

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


int main() {
  int n, d;
  cin >> n >> d;
  cout << (n + 2 * d) / (2 * d + 1);
  return 0;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

const INF int = 2*1e9 + 1

type Point struct {
	X, Y int
}

func abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}

func dist(p1, p2 Point) int {
	return abs(p1.X-p2.X) + abs(p1.Y-p2.Y)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	min_minus := INF
	min_plus := INF
	max_minus := -INF
	max_plus := -INF
	var min_minus_xy, min_plus_xy, max_minus_xy, max_plus_xy Point
	N := nextInt()

	for i := 0; i < N; i++ {
		x, y := nextInt(), nextInt()

		if x-y < min_minus {
			min_minus = x - y
			min_minus_xy = Point{x, y}
		}
		if x-y > max_minus {
			max_minus = x - y
			max_minus_xy = Point{x, y}
		}
		if x+y < min_plus {
			min_plus = x + y
			min_plus_xy = Point{x, y}
		}
		if x+y > max_plus {
			max_plus = x + y
			max_plus_xy = Point{x, y}
		}
	}

	fmt.Println(max(dist(max_minus_xy, min_minus_xy), dist(max_plus_xy, min_plus_xy)))
}


Measured memory_bytes: 6180
#include <iostream>
#define lli long long int
using namespace std;

int main()
{
    lli n, k, count = 0;
    cin >> n >> k;
    lli h[n];
    for(lli i = 0; i < n; i++)
    {
        cin >> h[i];
        if(h[i] >= k)
            count++;
    }
    cout << count << endl; 
    return 0;
}


Measured memory_bytes: 1024
import numpy as np

def dice():
    n, k = map(int, input().split())
    p = np.asarray(list(map(int, input().split())))
    pp = np.zeros(n)
    for i in range(n):
      pp[i] = p[i]*(p[i]+1)/(2*p[i])
    ans = sum(pp[0:k]) 
    tmp = sum(pp[0:k])
    for i in range(1, n-k+1):
        tmp = tmp - pp[i-1] + pp[i+k-1]
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == '__main__':
    dice()

Measured memory_bytes: 33964
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  string S,T; cin>>S>>T;
  if(S.compare(0,S.size(),T,0,S.size()) == 0 && S.size()+1==T.size()) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define min(x,y) ((x)<(y)?(x):(y))
#define INF 100000000
int n,m;
int A[200][200],B[200][200];
int dp[2][200];
int main(void){
    while(1){
        scanf("%d%d",&n,&m);
        if(n+m==0) break;
        rep(i,n) {
            rep(j,n){
                if(i==j) A[i][j]=B[i][j]=0;
                else A[i][j]=B[i][j]=INF;
            }
        }
        rep(i,m){
            int a,b,c; char d[3];
            scanf("%d%d%d%s",&a,&b,&c,d); //printf("%s\n",d);
            a--; b--;
            if(d[0]=='L') A[a][b]=A[b][a]=min(A[a][b],c);
            else B[a][b]=B[b][a]=min(B[a][b],c);
        }
        rep(k,n){
            rep(i,n){
                rep(j,n){
                    A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
                    B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
                }
            }
        }
        int R;
        scanf("%d",&R);
        int prev; scanf("%d",&prev); prev--;
        rep(i,2) rep(j,n) dp[i][j]=INF;
        dp[1][prev]=0;
        for(int i=1;i<R;i++){
            int cur; scanf("%d",&cur); cur--;
            rep(j,n){
                rep(k,n){
                    if(j!=k)
                        dp[(i+1)&1][j]=min(dp[(i+1)&1][j],dp[i&1][k]+
                                           A[prev][k]+B[k][j]+A[j][cur]);
                    else dp[(i+1)&1][j]=min(dp[(i+1)&1][j],
                                            dp[i&1][j]+A[prev][cur]);
                }
            }
            rep(j,n) dp[i&1][j]=INF;
            prev=cur;
        }
        int mi=INF;
        rep(i,n) mi=min(mi,dp[R&1][i]);
        printf("%d\n",mi);
    }
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count = 0, max_count = -1, max_N = -1;
  cin >> N;
  for(int i=1; i<N+1; i++){
    count = 0;
    int j = i;
    while(j%2 == 0){
      j = j/2;
      count++;
    }
    if(count > max_count){
      max_count = count;
      max_N = i;
    }
  }
  
  cout << max_N << endl;
}

Measured memory_bytes: 3596
import java.math.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args){
    BigInteger MOD = new BigInteger("1000000007");
    BigInteger ten = new BigInteger("10");
    BigInteger nine = new BigInteger("9");
    BigInteger eight = new BigInteger("8");

    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    BigInteger all = BigInteger.ONE;
    BigInteger non0 = BigInteger.ONE;
    BigInteger non9 = BigInteger.ONE;
    BigInteger non09 = BigInteger.ONE;
    for (int i = 0; i < n; i++) {
      all = all.multiply(ten).remainder(MOD);
      non0 = non0.multiply(nine).remainder(MOD);
      non9 = non9.multiply(nine).remainder(MOD);
      non09 = non09.multiply(eight).remainder(MOD);
    }
    System.out.println(sub(all, non0.add(non9).remainder(MOD), MOD).add(non09).remainder(MOD));
  }
  static BigInteger sub(BigInteger a, BigInteger b, BigInteger mod) {
    BigInteger result = a.subtract(b);
    if (result.compareTo(BigInteger.ZERO) < 0) {
      return result.add(mod);
    } else {
      return result;
    }
  }
}


Measured memory_bytes: 47116
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int n,x;
  scanf("%d%d",&n,&x);
  int a[n+1];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int ans=0;
  
  for(int i=0;i<n;i++){
    int min=1000000000;
    int h=0;
    for(int j=0;j<n;j++){
      if(a[j]<min){
        chmin(&min,a[j]);
        h=j;
      }
    }
    if(x<min){
      break;
    }else{
      ans++;
      x-=a[h];
      a[h]=1000000000;
    }
  }
  if(x==0){
    printf("%d\n",ans);
  }else if(ans-1<0){
    printf("0\n");
  }else if(ans==n){
    printf("%d\n",ans-1);
  }else{
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 1696
import sys
import fractions
from functools import reduce
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
flgs = [False for i in range(n)]
tmp = [0 for i in range(n)]
for i in range(m):
    p, s = stdin.readline().split()
    p = int(p)
    if flgs[p-1] is False:
        if s == 'WA':
            tmp[p-1] += 1
        else:
            flgs[p-1] = 1
wa = 0
ac = 0
for i in range(n):
    if flgs[i]:
        ac += 1
        wa += tmp[i]
print(ac, wa)


Measured memory_bytes: 6864
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i / 60 - h*60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl; 
   
   return 0;
}


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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int f = 0;
    
    for(int i = 0; i < k; i++){
        if(b <= a){
            b *= 2;
        }else if(b > a && c <= b){
            c *= 2;
        }
        if(b > a && c > b){
            f = 1;
            break;
        }
    }
    if(f == 0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}


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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> vec(26, 0);
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    ++vec[c - 'a'];
  }

  ll ans = 1;
  for (int i = 0; i < 26; ++i)
    ans = (ans * (vec[i] + 1) ) % 1000000007;
  cout << ans - 1 << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int ma = -1e9, mi = 1e9;
    long long sum = 0;
    while (n--) {
        int x;
        cin >> x;
        ma = max(ma, x);
        mi = min(mi, x);
        sum += x;
    }
    cout << mi << " " << ma << " " << sum << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    string s; cin >> s;
    int a = 0, b = 0, c = 0;
    rep(i,3){
      if(s[i]=='a') a = 1;
      if(s[i]=='b') b = 1;
      if(s[i]=='c') c = 1;
    }

    if(a&&b&&c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256