akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int N;
vector<int> adj[10005];
vector<int> ans(10005);
int id;

void dfs(int now, int from, vector<int> &c){

    for(int i=0; i<adj[now].size(); i++){
        int to = adj[now][i];
        if(to == from) continue;
        dfs(to, now, c);
    }

    ans[now] = c.back();
    c.pop_back();

}

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

    for(int i=0; i<N-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }

    int sum = 0;
    for(int i=0; i<N; i++) { cin >> c[i]; sum += c[i]; }
    sort(c.begin(), c.end(), greater<int>());
    sum -= c[0];

    int root = 0;
    for(int i=0; i<N; i++) if(adj[i].size() == 1) {
        root = i;
        break;
    }

    id = 0;
    dfs(root,-1, c);
    cout << sum << endl;
    for(int i=0; i<N; i++){
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    //cout << adj[0][0] << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &b[i]);
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &c[i]);
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    long int ab[n], bc[n];
    
    for(int i = 0; i < n; i++){
        ab[i] = lower_bound(a, a + n, b[i]) - a;
        bc[i] = lower_bound(b, b + n, c[i]) - b;
    }

    long int ans = 0;
    long int before = 0;
    for(int i = 0; i < n; i++){
        if (i == 0){
            for(int j = 0; j < bc[i]; j++) before += ab[j];
        }
        else{
            for(int j = bc[i-1]; j < bc[i]; j++) before += ab[j];
        }
        ans += before;
    }
    printf("%ld\n", ans);
}


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

typedef long long ll;

const int Maxn = 303;
const ll Inf = 1000000000000000000ll;

int n, k;
int H[Maxn];
ll dp[Maxn][Maxn][Maxn];

int main()
{
    fill((ll*)dp, (ll*)dp + Maxn * Maxn * Maxn, Inf);
    dp[1][0][0] = 0;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &H[i]);
        for (int j = 0; j < i; j++)
            for (int u = 0; u <= k; u++) if (dp[i][j][u] < Inf) {
                if (u < k) dp[i + 1][j][u + 1] = min(dp[i + 1][j][u + 1], dp[i][j][u]);
                ll add = max(0, H[i] - H[j]);
                dp[i + 1][i][u] = min(dp[i + 1][i][u], dp[i][j][u] + add);
            }
    }
    ll res = Inf;
    for (int j = 0; j <= n; j++)
        for (int u = 0; u <= k; u++)
            res = min(res, dp[n + 1][j][u]);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 217600
h, w, k = map(int, input().split())
dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1

fb_dic = {}
def fb(n):
  if n < 0:
    print("error")
    return -1
  if n == 0:
    return 1
  if n == 1:
    return 1
  if n in fb_dic:
    return fb_dic[n]
  ret = fb(n - 1) + fb(n - 2)
  fb_dic[n] = ret
  return ret

for y in range(1, h + 1):
  for x in range(w):
    if x - 1 >= 0:
      dp[y][x] += dp[y - 1][x - 1] * fb(x - 1) * fb(w - x - 1)
    if x + 1 <= w - 1:
      dp[y][x] += dp[y - 1][x + 1] * fb(x) * fb(w - x - 2)
    dp[y][x] += dp[y - 1][x] * fb(x) * fb(w - x - 1)
    dp[y][x] %= 1000000007


print(dp[h][k - 1])

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

using namespace std;

typedef long long	ll;

int main(){
	ll n;

	scanf("%lld", &n);

	ll sum = 0LL;

	for(ll i = 1LL ; i <= n ; i++){
		if(i % 3LL ==0LL || i % 5LL == 0LL) continue;

		sum += i;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

string dijkstra(vector<vector<pair<int,int>>>& G, vector<int>& ref, int A, int H, int M){
    const int INF = (1<<30);
  
  priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>, greater<pair<pair<int,int>,int>>> Q;
  vector<vector<int>> dis(G.size(), vector<int>(M+1, INF));
  Q.push(make_pair(make_pair(0,M),A));
  dis[A][M] = 0;

  while(!Q.empty()){
    pair<pair<int,int>,int> P = Q.top(); Q.pop();
    int now = P.second, min = P.first.second, d = P.first.first;

    if(dis[now][min] < d) continue;
    
    if(now == H) return to_string(d);

    for(pair<int,int> next : G[now]){
      if(ref[now]){
        for(int i = min; i <= M; i++){
          if(i-next.second < 0) continue;
          if(dis[next.first][i-next.second] > d + next.second + i - min) {
            dis[next.first][i-next.second] = d + next.second + i - min;
            Q.push(make_pair(make_pair(d + next.second + i - min, i-next.second),next.first));
          }
        }
      } else {
        if(min-next.second < 0) continue;
        if(dis[next.first][min-next.second] > d + next.second) {
          dis[next.first][min-next.second] = d + next.second;
          Q.push(make_pair(make_pair(d + next.second,min-next.second),next.first));
        }
      }
    }
  }
  
  
  return "Help!";
}
signed main(){
   cin.tie(NULL);
   ios::sync_with_stdio(false);

  while(true){
    int N, M, L, K, A, H;
    vector<vector<pair<int,int>>> G;
    vector<int> ref;

    cin>>N>>M>>L>>K>>A>>H;

    if(!N) break;
    
    G.resize(N);
    ref.resize(N);
   
    for(int i = 0; i < L; i++){
      int r;
      cin>>r;
      ref[r] = true;
    }
    
    ref[A] = ref[H] = true; 
    
    for(int i = 0; i < K; i++){
      int X, Y, T;
      cin>>X>>Y>>T;

      G[X].push_back(make_pair(Y, T));
      G[Y].push_back(make_pair(X, T));
    }
    
    cout<<dijkstra(G, ref, A, H, M)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	ll n;
	cin >> n;
	ll sum = (n * (n + 1)) / 2;
	ll i;
	for (i = 1;i <= n;i++)
		if (i % 3 == 0 || i % 5 == 0)
			sum -= i;
	cout << sum << '\n';
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void){
	char trump[4][13] = {};
	char design[4] = {'S', 'H', 'C', 'D'};
	int n, i, j;

	scanf("%d", &n);
	getchar();
	for(i = 0; i < n; i++){
		char d;
		int r;

		scanf("%c %d", &d, &r);
		getchar();
		trump[(d-65) % 6][r-1] = 1;
	}

	for(i = 0; i < sizeof(trump)/sizeof(*trump); i++)
		for(j = 0; j < sizeof(*trump); j++)
			if(!trump[i][j])
				printf("%c %d\n", design[i], j+1);
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  st s;
  cin >> s;
  if(s.size() % 2 == 0){
    bool check = 1;
    rep(i, 0, s.size() / 2){
      if(!(s.at(i * 2) == 'h' && s.at(i * 2 + 1) == 'i')) check = 0; 
    }
    if(check){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a=n/1000,b=n/100%10,c=n%100/10,d=n%10;
	if(a==b && a==c)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(a==b && a==c && a==d)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(b==c && b==d)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(sc.hasNext()){
			new Main();
		}
	}
	public Main() {
		new aoj0175().doIt();
	}
	class aoj0175{
		void doIt() {
			while(true){
				int n = sc.nextInt();
				if(n==-1)break;
	            System.out.println(Integer.toString(n,4));
			}
		}
	}
}

Measured memory_bytes: 23476
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

ll read() {
	ll X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

int main() {
	ll n=read(),c=2*(n/11); n%=11;
	if (1<=n&&n<=6) ++c;
	if (7<=n&&n<=10) c+=2;
	printf("%lld\n",c);
	return 0;
}

Measured memory_bytes: 3720
// Crt. 2019-12-17  19:57:45
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 104
using namespace std;

int n, a[N], num[N];

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);

    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);

    int mi = (a[1] + 1) / 2;
    num[mi] = a[1] % 2 + 1;
    for (int i = a[1]; i > mi; --i)
        num[i] = 2;

    for (int i = 1; i <= n; ++i)
        --num[a[i]];

    for (int i = a[1]; i >= mi; --i)
        if (num[i] > 0) return puts("Impossible"), 0;

    for (int i = 1; i <= mi; ++i)
        if (num[i] < 0) return puts("Impossible"), 0;

    puts("Possible");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s,t;
    cin>>s>>t;
    int ans=t.length();
    for(int i=0;i<=(s.length()-t.length());++i){
        int diff = 0;
        for(int j=0;j<t.length();++j){
            if(t[j]!=s[i+j]){
                diff++;
            }
        }
        ans=min(ans,diff);
    }
    cout<<ans;
    return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long n; scan(n);
      LI xs(n); for(long &x : xs) scan(x);
      LI ys(112345, 0);
      for(long x : xs) ys[x] += 1;
      long z = 0;
      for(long y : ys) z += std::max((long)0, y-1);
      long res = n - (z+1)/2*2;
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
vector<int> E[160000];
bool used[160000];
int H,W;
string S[400];
void dfs(int x,vector<int> &w,vector<int> &b){
    used[x]=1;
    if(S[x/W][x%W]=='#') b.pb(x);
    else w.pb(x);
    rep(i,0,sz(E[x])){
        if(!used[E[x][i]]){
            dfs(E[x][i],w,b);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W;
    rep(i,0,H){
        cin>>S[i];
    }
    rep(i,0,H){
        rep(j,0,W-1){
            if(S[i][j]!=S[i][j+1]){
                E[W*i+j].pb(W*i+j+1);
                E[W*i+j+1].pb(W*i+j);
            }
        }
    }
    rep(i,0,H-1){
        rep(j,0,W){
            if(S[i][j]!=S[i+1][j]){
                E[W*i+j].pb(W*(i+1)+j);
                E[W*(i+1)+j].pb(W*i+j);
            }
        }
    }
    ll ans=0;
    rep(i,0,H*W){
        if(!used[i]){
            vector<int> w;
            vector<int> b;
            dfs(i,w,b);
            ans+=ll(sz(w))*sz(b);
        }
    }
    cout <<ans<<"\n";
}


Measured memory_bytes: 20212
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

int main() {
	int n;
	std::cin >> n;

	std::vector<std::vector<int>> g(n);

	for (int i = 0; i < n - 1; i++) {
		int u, v;
		std::cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	std::vector<int> dp(n);

	std::function<void(int, int)> dfs = [&](int u, int p) {
		for (int v : g[u]) {
			if (v != p) {
				dfs(v, u);
				dp[u] ^= dp[v] + 1;
			}
		}
	};

	dfs(0, -1);

	puts(dp[0] != 0 ? "Alice" : "Bob");
}

Measured memory_bytes: 15488
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]

int main(){
    map<string,int> mp;
    int n; cin >> n;
    rep(i,n){
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep(i,m){
        string s; cin >> s;
        mp[s]--;
    }
    int ans=0;
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        ans=max(ans,itr->se);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{};

int main(){
	int n=ci(), m=ci();
	printf("%d\n",n*(n-1)/2+m*(m-1)/2);
	return 0;
}


Measured memory_bytes: 128
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    S = kwargs["S"]
    res = len(collections.Counter(S))
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    kwargs["n"] = [int(i) for i in cin][0]
    #kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    kwargs["S"] = []
    for i in range(kwargs["n"]):
        cin = input().split()
        s = cin[0]
        #a = cin
        #a = [int(i) for i in cin][0]
        #a = [int(i) for i in cin]
        kwargs["S"].append(s)

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 60356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

#define N 100005
ll n;
vector<ll>e[N];
ll p[N];
vector<ll>chi[N];
ll dp[N][2];
bool used[N];

void dfs(ll c){
    ll answ=1,ansb=1;
    for(auto x:chi[c]){
        dfs(x);
        answ=mod(answ*mod(dp[x][0]+dp[x][1]));
        ansb=mod(ansb*dp[x][0]);
    }
    dp[c][0]=answ;dp[c][1]=ansb;
}

int main(){
    cin>>n;
    rep(i,0,n-2){
        ll x,y;cin>>x>>y;
        x--;y--;
        e[x].pb(y);e[y].pb(x);
    }
    rep(i,0,n-1)p[i]=-1;p[0]=-2;
    queue<ll>q;q.push(0);
    while(!q.empty()){
        ll t=q.front();q.pop();
        for(auto x:e[t]){
            if(p[x]!=-1)continue;
            p[x]=t;
            chi[t].pb(x);
            q.push(x);
        }
    }
    /*rep(i,0,n-1){
        cout<<i<<":";
        for(auto x:chi[i])cout<<x<<" ";cout<<endl;
    }*/
    
    dfs(0);
    /*rep(i,0,n-1){
        cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    }*/

    cout<<mod(dp[0][0]+dp[0][1])<<endl;
    
    return 0;
}


Measured memory_bytes: 20480
s = input()
x,y = map(int,input().split())
cur_x = 0
cur_y = 0
L_x = []
L_y = []
s += 'K'
temp = 0
dirc = 'yoko'
for i in range(len(s)):
    if s[i] == 'F':
        temp += 1
    elif s[i] == 'T':
        if temp == 0:
            if dirc == 'yoko':
                dirc = 'tate'
            else:
                dirc = 'yoko'
        else:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
    else:
        if temp != 0:
            if dirc == 'yoko':
                L_x.append(temp)
                temp = 0
                dirc = 'tate'
            else:
                L_y.append(temp)
                temp = 0
                dirc = 'yoko'
dp_x = [[False]*8001 for i in range(len(L_x)+1)]
dp_y = [[False]*8001 for i in range(len(L_y)+1)]
dp_x[0][0] = True
dp_y[0][0] = True
if s[0] != 'F':
    for i in range(1,len(L_x)+1):
        for j in range(8001):
            if j+L_x[i-1] <= 8000:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])] or dp_x[i-1][j+L_x[i-1]]
            else:
                dp_x[i][j] = dp_x[i-1][abs(j-L_x[i-1])]
    for i in range(1,len(L_y)+1):
        for j in range(8001):
            if j+L_y[i-1] <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
            else:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
    if dp_x[len(L_x)][abs(x)] == True and dp_y[len(L_y)][abs(y)] == True:
        print('Yes')
    else:
        print('No')
else:
    for i in range(2,len(L_x)+1):
        for j in range(8001):
            if j+L_x[i-1] <= 8000 and abs(j-L_x[i-1]) <= 8000:
                dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])] or dp_x[i-2][j+L_x[i-1]]
            elif abs(j-L_x[i-1]) <= 8000:
                dp_x[i-1][j] = dp_x[i-2][abs(j-L_x[i-1])]
    for i in range(1,len(L_y)+1):
        for j in range(8001):
            if j+L_y[i-1] <= 8000 and abs(j-L_y[i-1]) <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])] or dp_y[i-1][j+L_y[i-1]]
            elif abs(j-L_y[i-1]) <= 8000:
                dp_y[i][j] = dp_y[i-1][abs(j-L_y[i-1])]
    if abs(x-L_x[0]) <= 8000:
        if dp_x[len(L_x)-1][abs(x-L_x[0])] == True and dp_y[len(L_y)][abs(y)] == True:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 285960
#include<stdio.h>

int main ()
{
	int A,B,C,D,P,yen[1];
	
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	scanf("%d",&P);
	
	
	yen[0] = P * A;
	
	if(P <= C){
		yen[1] = B;
	}
	else{
		yen[1] = B + (P - C) * D;
	}
	
	if(yen[0] <= yen[1]){
		printf("%d\n",yen[0]);
	}
	else{
		printf("%d\n",yen[1]);
	}
	
	return 0;
}

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

// 10min
int main(void){
    int n = 0; 
    int p[21];
    int ans = 0;

    scanf("%d", &n);

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

    for(int i = 1; i < n - 1; i++){
        if(p[i] > p[i - 1] && p[i] < p[i + 1]){
            ans++;
        }else if(p[i] < p[i - 1] && p[i] > p[i + 1]){
            ans++;
        }
    }

    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

void piyo(int& a, int& b, int& c, int& d) {
	int tmp = a;
	a = b;
	b = c;
	c = d;
	d = tmp;
}

void hoge(vector<int>& a, char c) {
	switch (c) {
	case 'W': piyo(a[0], a[2], a[5], a[3]); break;
	case 'S': piyo(a[0], a[4], a[5], a[1]); break;
	case 'N': piyo(a[0], a[1], a[5], a[4]); break;
	case 'E': piyo(a[0], a[3], a[5], a[2]); break;
	}
}

int main() {
	vector<int> a(6);
	for (int i = 0; i < 6; i++) cin >> a[i];
	int q; cin >> q;
	while (q--) {
		int x, y; cin >> x >> y;
		while (!(a[0] == x && a[1] == y)) {
			if (rand() % 2) hoge(a, 'N');
			else hoge(a, 'E');
		}
		cout << a[2] << endl;
	}
}

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

int main() {
  int N,S;
  cin>>N>>S;
  int64_t Q=998244353;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(S+1));
  dp.at(0).at(0)=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=S;j++){
      if(j>=p.at(i-1)){
        dp.at(i).at(j)=(dp.at(i-1).at(j)*2+dp.at(i-1).at(j-p.at(i-1)))%Q;
      }
      else{
        dp.at(i).at(j)=(dp.at(i-1).at(j)*2)%Q;
      }
    }
  }
  cout<<dp.at(N).at(S)<<endl;
  
}

Measured memory_bytes: 73664
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 100000
using namespace std;
typedef long long LL;
int n,m;
LL k;
LL x[MAXN+5];
int ord[MAXN+5];
int ord2[MAXN+5];
LL ans[MAXN+5],fin[MAXN+5];
bool vis[MAXN+5];
vector<int> ned;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x[i]),ord[i]=i;
		ans[i]=x[i]-x[i-1];
	}
	scanf("%d %lld",&m,&k);
	int p;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&p);
		swap(ord[p],ord[p+1]);
	}
	for(int i=1;i<=n;i++)
	{
		p=i;
		ned.clear();
		while(vis[p]==false)
		{
			vis[p]=true;
			ned.push_back(p);
			p=ord[p];
		}
		for(int j=0;j<(int)ned.size();j++)
			ord2[ned[j]]=ned[(1LL*j+1LL*k)%(LL)ned.size()];
	}
	for(int i=1;i<=n;i++)
		fin[i]=ans[ord2[i]];
	LL sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=fin[i];
		printf("%lld.0\n",sum);
	}
	return 0;
}

Measured memory_bytes: 5240
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,x,y=map(int,input().split())

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))
d=dijkstra(g,directed=False).astype(int)

ans_l=np.bincount(d.ravel(), minlength=n)//2

print(*ans_l[1:], sep='\n')

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

int nrs[100010];
int main() {
	int N, M; cin >> N >> M;
	for(int i=0; i<M; ++i){
	    int a, b;
	    cin >> a >> b;
	    if(nrs[a]==0) nrs[a]=b;
	    else nrs[a]=min(nrs[a], b);
	}
	int ans=0, lin=1e9;
	for(int i=1; i<N; ++i){
	    if(nrs[i]>0) lin=min(lin, nrs[i]);
	    if(i+1==lin){
	        ++ans;
	        lin=1e9;
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<int> s(m),c(m);
	for(int i=0;i<m;i++){
		cin >> s[i] >> c[i];
		s[i]=n-s[i];
	}
	if(n==1&&(m==0||(m==1&&s[0]==0&&c[0]==0))){
		cout << 0 << endl;
		return 0;
	}
	for(int i=0;i<1000;i++){
		if(pow(10,n)>i&&pow(10,n-1)<=i){
			bool ok=1;
			for(int j=0;j<m;j++){
				if(i/(int)pow(10,s[j])%10!=c[j])ok=0;
			}
			if(ok){
				cout << i << endl;
				return 0; 
			}
		}
	}
	cout << -1 << endl;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll x;
  cin >> x;
  
  for (ll a = 0; a <= 6208; a++) {
    for (ll b = -6208; b <= 6208; b++) {
      if ((ll)pow(a, 5) - (ll)pow(b, 5) == x) {
        cout << a << " " << b << '\n';
        return 0;
      }
      if ((ll)pow(a, 5) <= 1000000000 && (ll)pow(b, 5) <= 1000000000 && (ll)pow(a, 5) + (ll)pow(b, 5) == x) {
        cout << a << " " << -b << '\n';
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4200
#include <bits/stdc++.h>
#define LIMIT 511

using namespace std;

typedef long long ll;

int n, q;
int v[300002], w[300002];

int DP[600][100002];
int DPMAX[600][100002];
pair<int, int> sumBIT[600];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &v[i], &w[i]);
    }

    for(int i=1; i<=n && i<=LIMIT; i++){
        for(int j=0; j<=100000; j++){
            DP[i][j] = DP[i/2][j];
        }
        for(int j=0; j<=100000 - w[i]; j++){
            DP[i][j+w[i]] = max(DP[i][j+w[i]], DP[i/2][j] + v[i]);
        }
        DPMAX[i][0] = DP[i][0];
        for(int j=1; j<=100000; j++){
            DPMAX[i][j] = max(DPMAX[i][j-1], DP[i][j]);
        }
    }

    scanf("%d", &q);

    while(q--){
        int x, L;
        scanf("%d %d", &x, &L);
        if(x <= LIMIT) printf("%d\n", DPMAX[x][L]);
        else{
            vector<pair<int, int> > additional;
            int tmpS, tmpMax;

            while(x > LIMIT){
                additional.push_back(make_pair(v[x], w[x]));
                x/=2;
            }
            tmpS = (int)additional.size();
            tmpMax = 1<<tmpS;

            int tmp, ret = DPMAX[x][L];

            sumBIT[0] = make_pair(0, 0);
            for(int i=1; i<tmpMax; i++){
                tmp = __builtin_ctz(i);
                sumBIT[i] = make_pair(sumBIT[i - (1<<tmp)].first + additional[tmp].first,
                                      sumBIT[i - (1<<tmp)].second + additional[tmp].second);
                if(sumBIT[i].second > L) continue;
                ret = max(ret, DPMAX[x][L-sumBIT[i].second] + sumBIT[i].first);
            }

            printf("%d\n", ret);
        }
    }
}


Measured memory_bytes: 405092
n,q = map(int,input().split())
s = input()


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]


for i in range(q):
    l, r = map(int,input().split())
    print(t[r-1] - t[l-1])


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

struct segtree{
    int size;
    vector<int> dat;
    int init = 0;

    segtree (int N) {
        size = 1;
        while (size < N) size *= 2;
        dat = vector<int>(2*size-1, 0);
    }

    int op(int a, int b) {
        return a|b;
    }

    void update(int i, int x) { 
        i += size-1;
        dat[i] = x;
        while (i > 0) {
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
        return;
    }

    ll query(int a, int b) {
        return query(a, b, 0, 0, size);
    }

    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init;
        if (a <= l && r <= b) return dat[k];
        ll lv, rv;
        lv = query(a, b, 2*k+1, l, (l+r)/2);
        rv = query(a, b, 2*k+2, (l+r)/2, r);
        return op(lv, rv);
    }
};

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    segtree st(N+2);
    for (int i = 0; i < N; i++) {
        int n = S[i] - 'a';
        st.update(i, (1 << n));
    }
    int Q;
    cin >> Q;
    for (int z = 0; z < Q; z++) {
        int op;
        cin >> op;
        if (op == 1) {
            int i;
            char c;
            cin >> i >> c;
            int n = c - 'a';
            st.update(i-1, (1 << n));
        }else if (op == 2) {
            int l, r;
            cin >> l >> r,
            cout << __builtin_popcount(st.query(l-1, r)) << endl;
        }
    }
    return 0;
}

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

int main(){
    int h,w,i,j;
    while(cin >> h >> w){
        if(h == 0 && w == 0) break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i == 0 || i == h - 1 || j == 0 || j == w - 1) {
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3056
#include<cstdio>

int main(){
	char a[4][5];
	char b[5][4];
	int d = 2;
	int x = 0, y = 0;
	for(int i = 0; i < 4; i++){
		scanf("%c%c%c%c\n", &a[0][i], &a[1][i], &a[2][i], &a[3][i]);
		scanf("%c%c%c%c%c\n", &b[0][i], &b[1][i], &b[2][i], &b[3][i], &b[4][i]);
	}
	scanf("%c%c%c%c", &a[0][4], &a[1][4], &a[2][4], &a[3][4]);

	while(d){
		if(d == 2){
			if(y && b[x][y-1] - '0'){
				d = 1;
				y--;
				printf("U");
			}else if(x == 4){
				d = 3;
			}else if(a[x][y] - '0'){
				x++;
				printf("R");
			}else{
				d = 3;
			}
		}
		if(d == 3){
			if(x - 4 && a[x][y] - '0'){
				d = 2;
				x++;
				printf("R");
			}else if(y == 4){
				d = 4;
			}else if(b[x][y] - '0'){
				y++;
				printf("D");
			}else{
				d = 4;
			}
		}
		if(d == 4){
			if(y - 4 && b[x][y] - '0'){
				d = 3;
				y++;
				printf("D");
			}else if(x == 0){
				if(y == 0){
					printf("\n");
					return 0;
				}
				d = 1;
			}else if(a[x-1][y] - '0'){
				x--;
				printf("L");
			}else{
				d = 1;
			}
		}
		if(d == 1){
			if(x && a[x-1][y] - '0'){
				d = 4;
				x--;
				printf("L");
			}else if(y == 0){
				if(x == 0){
					printf("\n");
					return 0;
				}
				d = 2;
			}else if(b[x][y-1] - '0'){
				y--;
				printf("U");
			}else{
				d = 2;
			}
		}
	}
}

Measured memory_bytes: 936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt();

		int limitCount10000 = (y / 10000) + 1;
		int limitCount5000 = (y / 5000) + 1;
		int limitCount1000 = (y / 1000) + 1;

		for (int i = 0; i < limitCount1000; i++) {
			if (i > n) {
				break;
			}
			for (int j = 0; j < limitCount5000; j++) {
				if (i + j > n) {
					break;
				}
				int k = n - (i + j);
				if (i * 1000 + j * 5000 + k * 10000 == y) {
					System.out.println (k + " " + j + " " + i);
					return;
				}
			}
		}
		System.out.println(-1 + " " + -1 + " " + -1);
	}
}


Measured memory_bytes: 23636
# input
x1, y1, x2, y2 = map(int, input().split())

x3 = y1 - y2 + x2
y3 = x2 - x1 + y2
x4 = y1 - y2 + x1
y4 = x2 - x1 + y1
print(x3, y3, x4, y4)

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

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

int main(){

  while(1){
    int x,y,s;
    cin>>x>>y>>s;
    if(x==0)break;
    int res=0;
    repl(a,1,s)repl(b,1,s){
      int prea=(100+x)*a/100;
      int preb=(100+x)*b/100;
      if(prea+preb==s)res=max(res,((100+y)*a/100)+((100+y)*b/100));
    }
    cout<<res<<endl;
  }

  return 0;
}



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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N, M;
int p[100010];
int x, y;
vector<int> graph[100010];
bool used[100010];

set<int> st;
set<int> nums;

/*==================================================*/
/*function*/
void dfs(int node){
    used[node] = true;

    st.insert(node);
    nums.insert(p[node]);

    REP(j,0,graph[node].size()){
        if(!used[graph[node][j]]) dfs(graph[node][j]);
    }

    return;
}
/*==================================================*/

int main() {
    cin>>N>>M;
    REP(i,0,N) cin>>p[i], p[i]--;
    REP(j,0,M) {
        cin>>x>>y;
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }

    int ans = 0;

    REP(i,0,N){
        if(used[i]) continue;

        st.clear();
        nums.clear();

        dfs(i);

        auto it = st.begin();
        while(it != st.end()){
            if(nums.find(*it) != nums.end()) ans++;
            it++;
        }
        
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 17536
#include <stdio.h>

using namespace std;

const int MAX_N = 300;
int A[MAX_N][MAX_N];

int main() {

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

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            scanf("%d", &A[i][j]);
        }
    }

    if (N == 1) {
        printf("0\n");
        return 0;
    }

    if (N == 2) {
        printf("%d\n", A[0][1]);
        return 0;
    }

    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (A[i][k] + A[k][j] < A[i][j]) {
                    printf("-1\n");
                    return 0;
                }
            }
        }
    }

    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (A[i][k] > 0 && A[k][j] > 0 && A[i][j] > 0 && A[i][k] + A[k][j] == A[i][j]) {
                    A[i][j] = 0;
                }
            }
        }
    }

    long ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            ans += A[i][j];
        }
    }

    printf("%ld\n", ans / 2);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, bool> vis;
int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0, a; i < n; i++){
        cin >> a;
        if (vis[a]){
            cout << "NO";
            return 0;
        }
        vis[a] = 1;
    }
    cout << "YES";
    return 0;
}

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

class Main {

    int m = 0, n = 0;
    int[] w = null;
    
    boolean IsStorable( int width ) {

	int row = 0, c = 0, i = 0;

	while ( i < n ) {
	    if ( c + w[i] <= width ) {
		c += w[i];
		++i;
	    }
	    else if ( ++row < m ) c = 0;
	    else return false;
	}

	return true;
    }

    void solve(){

	Scanner sc = new Scanner(System.in);

	while ( true ) {

	    m = sc.nextInt();
	    n = sc.nextInt();
	    if ( m == 0 && n == 0 ) break;
	    
	    w = new int[n];
	    for ( int i=0; i<n; ++i ) w[i] = sc.nextInt();

	    int minw = 1, maxw = 1500000;
	    if ( !IsStorable( maxw ) ) System.out.println("NA");

	    while ( maxw > minw ) {
		int mid = (maxw + minw)/2;
		if ( IsStorable(mid) ) maxw = mid;
		else                   minw = mid + 1;
	    }

	    System.out.println( minw );
	}
    }

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



Measured memory_bytes: 29456
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine();
        var b = Console.ReadLine();
        var c = Console.ReadLine();

        int count = 0;
        for (int i = 0; i < n; i++)
        {
            var aa = a[i];
            var bb = b[i];
            var cc = c[i];

            if (aa != bb && aa != cc && bb != cc)
            {
                count += 2;
            }
            else
            {
                if (!(aa == bb && aa == cc))
                {
                    count++;
                }
            }
        }

        Console.WriteLine(count);
    }
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

int main() {
	int N;
	cin >> N;
	
	vector< lint > p(N + 1, 0);
	for_(i,2,N+1) {
		if (p[i] == 1) {
			for (int j = 2 * i; j <= N; j += i) p[j] = -1;
		}
	}
	
	for_(x,2,N+1) {
		int y = x;
		for_(i,2,N+1) {
			while (p[i] >= 0 && y % i == 0) {
				y /= i;
				++p[i];
			}
		}
	}
	
	lint ans = 1, MOD = (lint)1e9 + 7;
	for_(i,2,N+1) {
		ans *= (p[i] + 1);
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define R(a) int a;cin>>a;
#define deb(x) cout<<#x<<" "<<x<<endl;
#define mod 1000000007
#define f_arr(n) for(int i=0;i<n;i++)
#define r_arr(n) for(int i=n-1;i>=0;i--)
#define pb push_back
#define all(x) x.begin(),x.end()
#define inf 1e18
#warning uncomment the #define int line before submitting
#define int long long int
using namespace std;

#ifndef ONLINE_JUDGE
template<typename T>    
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

void test_case()
{
  R(n);
  vector<int> a(n+1);
  for(int &x : a){
    cin>>x;
  }
  sort(all(a));
  trace(a);
  int answer=0;
  for(int i=1;i<n;i++){
    answer+=a[n-(i/2)];
    trace(i/2);
  }
  cout<<answer;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int t=1;
    // cin>>t;
    while(t--)
    {
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


Measured memory_bytes: 4700
def show_ary a,n
  for i in 0..n-1
    print " " unless i == 0
    print a[i]
  end
  print "\n"
end

n = gets.to_i
a = gets.split.map {|s| s.to_i}
show_ary a,n
for i in 1..n-1
  k = a[i]
  j = i-1
  while j >= 0 && a[j] > k
    a[j+1] = a[j]
    j -= 1
  end
  a[j+1] = k
  show_ary a,n
end

Measured memory_bytes: 6108
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    int size = S.size();
    int c0 = 0;
    int c1 = 0;
    rep(i, 0, size){
        if (S[i] == '0')c0++;
        if (S[i] == '1')c1++;
    }
    if (c0 >= c1){
        cout << c1 * 2 << endl;
    }
    else{
        cout << c0 * 2 << endl;
    }

    return 0;
}

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

int main() {
    string s;
    cin >> s;

    vector<long long> a(s.size()+1, 0);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
    }
    for (int i = s.size()-1; i >= 0; i--) {
        if (s[i] == '>') a[i] = max (a[i], a[i+1]+1);
    }
    long long ans = accumulate (a.begin(), a.end(), 0LL);
    cout << ans << endl;
}


Measured memory_bytes: 7728
//

/*
    __          ____  ________       
   / /   ____  / __ \/_  __/ /_  ___ 
  / /   / __ \/ / / / / / / __ \/ _ \
 / /___/ /_/ / /_/ / / / / / / /  __/
/_____/\____/_____/ /_/ /_/ /_/\___/ 
                                     
                                     */

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

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

#define endl "\n"
#define mp make_pair
#define pb push_back

const long long p = 29, mod = 941083981;

string str, rstr;
ll h[200005], rh[200005], deg[200005], n;
ll result = 0, used[256];

int main() {
	int l, r, mid, len, mx, mx1 = 0;
	bool flag;

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> str;

	rstr = str;
	reverse(rstr.begin(), rstr.end());

	deg[0] = 1;
	h[0] = str[0] - 'a' + 1;
	rh[str.size() - 1] = str[str.size() - 1] - 'a' + 1;

	for (int i = 1; i <= str.size(); i++)
		deg[i] = (deg[i - 1] * p) % mod;

	for (int i = 1; i < str.size(); i++) {
		h[i] = (h[i - 1] * p + (str[i] - 'a' + 1)) % mod;
		rh[str.size() - i - 1] = (rh[str.size() - i] * p + (str[str.size() - i - 1] - 'a' + 1)) % mod;
	}

	n = str.size();
	result = n * (n - 1) / 2 + 1;

	for (int i = 0; i < str.size(); i++)
		used[str[i]]++;

	for (int i = 0; i < 256; i++)
		result -= used[i] * (used[i] - 1) / 2;

	cout << result << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;




int main()
{
    
    int N;
    string S;
    ll mod = 1000000007;
    
    cin >> N >> S;
    
    vector<vector<ll>> dp(27,vector<ll>(26, 0));
    
    rep(i,N) dp[0][S[i]-'a']++;
    
    int nn = 0;
    rep(i,26) if(dp[0][i] != 0) nn++;
    

    ll ans = 0;
    for (int i = 1; i <= nn; i++) {
        if(i==1) dp[i][i-1] = dp[i-1][i-1];
        else dp[i][i-1] = (dp[i-1][i-2]*dp[0][i-1])%mod;
        for (int j = i; j < 26; j++) {
            if(i==1) dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod;
            else dp[i][j] = (dp[i][j-1])%mod + (dp[i-1][j-1]*dp[0][j])%mod;
            dp[i][j] %= mod;
        }
        ans += dp[i][25];
        ans %= mod;
    }
    
    cout << ans << endl;
    /*
    rep(i,27){
        rep(j,26) cout << dp[i][j] << " ";
        cout << endl;
    }
     */
    return 0;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

const int MAXN = 1e5 + 5;
int n, t[MAXN], x[MAXN], y[MAXN];
int curT, curX, curY;
bool ans = true;

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	}

	int curX = 0, curY = 0, curT = 0;
	for(int i = 0; i < n; ++i){
		int dist = abs(curX-x[i])+abs(curY-y[i]);
		if(t[i]-curT >= dist && (t[i]-curT-dist)%2 == 0){
			curT = t[i];
			curX = x[i]; curY = y[i];
		}else{
			ans = false;
		}
	}
	if(ans)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

long q,a,n,d,kq;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>q;
	while(q--){
		cin>>n>>d;
		a=d^127;
		if(n%2==0) kq=a+(n-1)*127;
		else if(n%2==1) kq=2*127+d+(n-3)*127;
		if(n==1) kq=d;
		cout<<kq<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
int main()
{
    char S[3];
    char T[3];
    cin >> S;
    cin >> T;

    int result = 0;
    for (int i=0; i<3; i++) {
        if (S[i]==T[i]) {
            result++;
        }
    }
    cout << result;

    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = (1ll << 60);

int main(){
  int n, m;
  ll l;
  cin >> n >> m >> l;
  
  vector<vector<ll>> road(n, vector<ll>(n, INF));
  for(int i = 0; i < n; i++) road[i][i] = 0;
  for(int i = 0; i < m; i++){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    
    road[a - 1][b - 1] = road[b - 1][a - 1] = c;
  }
  
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
      }
    }
  }
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == j) road[i][j] = 0;
      else if(road[i][j] <= l) road[i][j] = 1;
      else road[i][j] = INF;
    }
  }
  
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
      }
    }
  }
  
  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int s, t;
    cin >> s >> t;
    ll r = road[s - 1][t - 1];
    cout << (r == INF ? -1 : r - 1) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main()
{
	int i,j;
	
	for(i=1;i<10;i++)
	{
		for(j=1;j<10;j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	
    return 0;
}

Measured memory_bytes: 524
import sys
a,b,c,d=map(int, input().split())

if(b<=c or d<=a):
    print("0")
    sys.exit()
if(a<=c):
    if(b<d):
        print(b-c)
    else:
        print(d-c)
else:
    if(d<b):
        print(d-a)
    else:
        print(b-a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  lld a, b, c;
  char d;
  cin >> a >> b >> d >> c;
  cout << (a * (b * 100 + c) / 100) << "\n";
}

Measured memory_bytes: 3624