akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
using namespace std;
const int N = 1e5 + 5;
const ll inf = -1e18;
const int MOD = 1e9 + 7;

ll h[2 * N][23];

bool calc(ll mid, ll cur){
   for(int i = 0; i < 22; i++){
      if(h[cur][i] - h[mid - 1][i] > 1)
         return 0;
   }
   return 1;
}

int main(){
   fast;
   ll n, ans = 0, x;
   cin >> n;
   for(int i = 1; i <= n; i += 1){
      cin >> x;
      for(int j = 0; j < 22; j++){
         if((1LL << j) & x)
            h[i][j] = h[i - 1][j] + 1;
         else
            h[i][j] = h[i - 1][j];
      }
      ll lo = 0, hi = i, mid;
      while(hi - lo > 1){
         mid = (hi + lo) >> 1;
         if(calc(mid, i))
            hi = mid;
         else
            lo = mid;
      }
      ans += i - lo;
   }

   cout << ans;


   return 0;
} 

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

/*
考え方を違えてた問題
円環の最短距離なので、一番長い区間を使わなければよい
末尾に注意
*/

int main() {
    int K, N; cin >> K >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    A.push_back(A.back() + A[0] + K - A.back());

    int max_span = 0;
    for (int i = 0; i < N; i++)
    {
        int span = A[i+1] - A[i];
        // cout << span << endl;
        max_span = max(max_span, span);
    }

    cout << K- max_span << endl;
    
}

Measured memory_bytes: 1920
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, C, res;
  rd(A);
  rd(B);
  rd(C);
  res =max_L(0, C - (A-B));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// {
//   int A, B, C, res;
//   rd(A, B, C);
//   res = max(0, C - (A-B));
//   wt(res);
// }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ans = 0;
		int ansCandidate[] = {1, 2, 4, 8, 16, 32, 64};
		for (int i = 0; i < 7; i++) {
			if (ansCandidate[i] <= n) {
				ans = ansCandidate[i];
			}
		}
		System.out.println(ans);
	}
}


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

using Lint=long long;

void solve()
{
   string s,t; cin>>s>>t;
   int N=s.size(),M=t.size();
   s=' '+s; t=' '+t;
   vector<vector<int>> dp(N+1,vector<int>(M+1));
   for(int i=1;i<=N;i++) for(int j=1;j<=M;j++){
      if(s[i]==t[j]){ dp[i][j]=dp[i-1][j-1]+1; }
      else{ dp[i][j]=max(dp[i-1][j],dp[i][j-1]); }
   }

   string ans;
   int i=N,j=M;
   while(dp[i][j]>0){
      if(s[i]==t[j]){
         ans=s[i]+ans;
         i--; j--;
      }else{
         if(dp[i-1][j]>dp[i][j-1]) i--;
         else j--;
      }
   }
   // cout<<ans<<endl;
   cout<<ans.size()<<endl;
}

int main()
{
   int Q; cin>>Q;
   while(Q--){ solve(); }
   return 0;
}



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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++)
            cin >> A[i][j];
    }
    
    int ans = 10000000;
    for (int i = 0; i < (1 << N); i++) {
        int value = 0;
        vector<int> us(M, 0);
        for (int j = 0; j < N; j++) {
            if ((i >> j) & 1) {
                value += C[j];
                for (int k = 0; k < M; k++)
                    us[k] += A[j][k];
            }
        }
        
        bool flag = true;
        for (int i = 0; i < M; i++) {
            if (us[i] < X) {
                flag = false;
                break;
            }
        }
        if (flag)
            ans = min(ans, value);
    }
    
    if (ans == 10000000)
        cout << -1;
    else
        cout << ans;
}

Measured memory_bytes: 3636
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let mut line: Vec<u32> = read_as_vec();
    line.sort();

    if line[0] == 1 && line[1] == 4 && line[2] == 7&& line[3] == 9{
        println!("YES");
    }else{
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
#include <vector>
#include <cstring>

using namespace std;

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

int dp[200000][3];

void bfs(int s, vvi& vex) {
    dp[s][0] = 0;
    queue <pii> box;
    box.emplace(s, 0);
    
    while(!box.empty()) {
        int rx = box.front().first;
        int rh = box.front().second;
        box.pop();
        
        for(int i : vex[rx])
            if(dp[i][(rh + 1) % 3] == -1) {
                dp[i][(rh + 1) % 3] = (rh + 1) / 3;
                box.emplace(i, rh + 1);
            }
        
    }
    
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m; cin >> n >> m;
    int u, v;
    
    vvi vex(n);
    
    while(m--) {
        cin >> u >> v;
        vex[u - 1].push_back(v - 1);
    }
    
    memset(dp, -1, sizeof dp);
    cin >> u >> v;
    bfs(u - 1, vex);
    
    cout << dp[v - 1][0];
    
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i+=2)
    {
        int cnt=1;
        for(int j=2;j<=i;j++)
        {
            if(i%j==0)
            {
                cnt++;
            }
            if(cnt>8)
                break;
        }
        if(cnt==8)
            ans++;
    }
    cout<<ans<<endl;

}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> T fl(T x, T y) { return x / y; }           //   floor(x / y)
template<typename T> T ce(T x, T y) { return (x + y - 1) / y; } // ceiling(x / y)（x が非負の場合専用）

int n, c[500], s[500], f[500];

int main() {
	cin >> n;
	inc(i, n - 1) { cin >> c[i] >> s[i] >> f[i]; }
	
	inc(i, n) {
		int t = 0;
		incID(j, i, n - 1) {
			setmax(t, s[j]);
			t = s[j] + ce((t - s[j]), f[j]) * f[j] + c[j];
			//cout << t << " -- ";
		}
		cout << t << "\n";
	}
	
	return 0;
}


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

int main() {
	int n = 0;
	cin >> n;
	int change = 0; 
	if (n % 1000 == 0) {
		change = 0;
	} else {
		change = 1000 - n % 1000;
	}
	cout << change;
}


Measured memory_bytes: 3576
n = int(input())
l = []
for i in range(n):
    a, b = map(int, input().split())
    l.append([a, b])
l = l[::-1]
c = 0
for a, b in l:
  a += c
  if a % b != 0:
    c += b - (a % b)
print(c)

Measured memory_bytes: 25000
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
//#include <windows.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
const int INF = 2e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y); swap(x, z);
  cout << x << " " << y << " " << z;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll sum = 0;
    if(A >= K){
        sum += K;
        K = 0;
    }
    else{
        sum += A;
        K -= A;
    }
    if(B >= K){
        K = 0;
    }
    else K -= B;
    sum -= K;
    cout << sum << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


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

int main()
{
	int n, sum = 0, ans = 0;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	sum = round((double)(sum)/n);
	for (int i = 0; i < n; ++i)
		ans += (arr[i]-sum)*(arr[i]-sum);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define sor(v) sort(v.begin(),v.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

char c[1010][1010];

int bfs(P s,P g){
	queue<P1> que;
	bool used[1010][1010]; rep(i,1010)rep(j,1010)used[i][j]=false;
	
	que.push(P1(0,s));
	while(!que.empty()){
		P1 p=que.front(); que.pop();
		if(p.sc==g)return p.fr;
		if(!used[p.sc.fr][p.sc.sc]){
			rep(i,4){
				int nx=p.sc.fr+dre_4[i][0];
				int ny=p.sc.sc+dre_4[i][1];
				
				if(c[nx][ny]!='X'){
					que.push(mp1(p.fr+1,nx,ny));
				}
			}
			used[p.sc.fr][p.sc.sc]=true;
		}
	}
	
	return INF;
}

int main(){
	int h,w,n;
	cin>>h>>w>>n;
	
	rep(i,1010)rep(j,1010)c[i][j]='X';
	rep1(i,h){
		scanf("\n");
		rep1(j,w){
			cin>>c[i][j];
		}
	}
	
	int x[12],y[12];
	
	rep1(i,h)rep1(j,w){
		if(c[i][j]=='S'){
			x[0]=i;
			y[0]=j;
		}
		rep1(k,n){
			if(c[i][j]=='0'+k){
				x[k]=i;
				y[k]=j;
			}
		}
	}
	
	int ret=0;
	rep1(i,n){
		ret+=bfs(P(x[i-1],y[i-1]),P(x[i],y[i]));
	}
	
	cout<<ret<<endl;
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }else if(A+B<C+D){
    cout<<"Right"<<endl;
  }else if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
 }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;/* your task */}
int h2(int key){ return 1 + (key % (M - 1));/* your task */}

int find(char str[]){
    /* your task */
  
  long long key, i, h;
  
  key = getKey(str);
  
  for ( i = 0;; i++){   

    
    h = (h1(key) + i * h2(key)) % M;
    
    if( strcmp(H[h],str) == 0 ){
      
      return 1;
      
    }
    else if ( strlen(H[h]) == 0 ) {
      
      return 0;
      
    }
  }
  return 0;
  

}

int insert(char str[]){
    /* your task */
  
  long long key, i, h;
  
  key = getKey(str);
  
  for ( i = 0; ; i++ ){
    
    h = (h1(key) + i * h2(key)) % M;
    
    if( strcmp(H[h],str) == 0 ) {
      
      return 1;
      
    }
    else if ( strlen(H[h]) == 0 ){
      
      strcpy(H[h], str);
      return 0;
      
    }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    // Your code here!
    string str;

    while(cin>>str && str!="0"){
        int sum=0;
        for(int i=0; i<str.size(); i++){
            sum += str[i]-'0';
        }
        cout<<sum<<endl;
    }
}



Measured memory_bytes: 3192
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

int n;
char s[300005];

int r, g, b;

#define MOD 998244353
#define mul(a, b) (((ll)(a) * (ll)(b)) % MOD)

int main()
{
    scanf("%d", &n);
    scanf("%s", s + 1);
    int remaining = n;
    int ans = 1;
    for (int i = 1; i <= 3 * n; i++) {
        int& cur = (s[i] == 'R' ? r : (s[i] == 'G' ? g : b));
        int& x = (s[i] == 'R' ? g : r);
        int& y = (s[i] == 'B' ? g : b);
        if (x && y) {
            ans = mul(ans, min(x, y));
            x--; y--;
        } else {
            cur++;
            if (cur > max(x, y)) {
                ans = mul(ans, remaining); remaining--;
            } else {
                ans = mul(ans, max(x, y) - cur + 1);
            }
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
m = n // 2 - 1
if n % 2 == 0:
    ans = sum(a[:m]) * -2 - a[m] + a[m+1] + sum(a[m+2:]) * 2
else:
    ans1 = sum(a[:m]) * -2 - (a[m] + a[m+1]) + sum(a[m+2:]) * 2
    ans2 = sum(a[:m+1]) * -2 + (a[m+1] + a[m+2]) + sum(a[m+3:]) * 2
    ans = max(ans1, ans2)
    
print(ans)

Measured memory_bytes: 7512
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*N]

INF = 10**9
dp = [INF]*(3*(10**4))
dp[0] = 0

for i in range(H+1):
    for a,b in AB:
        dp[i+a] = min(dp[i+a],dp[i]+b)
print(min(dp[H:]))

Measured memory_bytes: 43644
import java.math.*;
import java.text.*;
import java.lang.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int n = in.nextInt();
			System.out.println(fact(n));
		}
	}

	private static BigInteger fact(int n){
		if(n==0) return BigInteger.ONE;
		return (new BigInteger(new Integer(n).toString()).multiply(fact(n-1)));
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

struct edge{
	int to,cost,limit;
	edge(int t,int c,int l){
		to=t;cost=c;limit=l;
	}
};

#define INF 1000000

struct Node{
	int now,speed,before;
	double time;
	Node(int n,int s,double t,int bef){
		now=n;speed=s;time=t;before=bef;
	}
};

bool operator < (Node a,Node b){
	return a.time>b.time;
}

int n,m,s,g;

void solve(){
	bool visit[31][31][31];
	memset(visit,false,sizeof(visit));
	vector<vector<edge> > E(n+1);
	cin>>s>>g;
	for(int i=0;i<m;i++){
		int in,out,c,l;
		cin>>in>>out>>c>>l;
		E[in].push_back(edge(out,c,l));
		E[out].push_back(edge(in,c,l));
	}


	priority_queue<Node> Q;
	Q.push(Node(s,0,0.0,s));
	while(!Q.empty()){
		Node t=Q.top(); Q.pop();
		if(visit[t.now][t.before][t.speed]) continue;
		visit[t.now][t.before][t.speed]=true;
		if(t.now==g && t.speed==1){printf("%.12lf\n", t.time );  return;}

		int size=E[t.now].size();
		for(int i=0;i<size;i++){
			int to=E[t.now][i].to;
			if(to==t.before) continue;
			if(E[t.now][i].cost>0){
				if(t.speed>=1 && E[t.now][i].limit>=t.speed){
					Q.push(Node(to,t.speed,t.time+E[t.now][i].cost/(double)t.speed,t.now));
				}

				if(E[t.now][i].limit>=t.speed+1 && !visit[to][t.now][t.speed+1])
					Q.push(Node(to,t.speed+1,t.time+E[t.now][i].cost/(double)(t.speed+1.0),t.now));

				if(t.speed-1>=1 && !visit[to][t.now][t.speed-1] && E[t.now][i].limit>=t.speed-1)
					Q.push(Node(to,t.speed-1,t.time+E[t.now][i].cost/(double)(t.speed-1.0),t.now));
			}
		}
	}
	cout<<"unreachable"<<endl;
}

int main()
{
	while(cin>>n>>m && n!=0)
		solve();
	return 0;
}

Measured memory_bytes: 8372
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  string S, T;
  cin >> S >> T;
  
  vector<int64_t> Ra(26, -1), Rb(26, -1);
  
  bool flag = true;
  for (uint64_t i = 0; i < S.size(); ++i) {
    if (Ra[S[i] - 'a'] < 0) {
      Ra[S[i] - 'a'] = T[i] - 'a';
    } else {
      flag &= Ra[S[i] - 'a'] == T[i] - 'a';
    }
    
    if (Rb[T[i] - 'a'] < 0) {
      Rb[T[i] - 'a'] = S[i] - 'a';
    } else {
      flag &= Rb[T[i] - 'a'] == S[i] - 'a';
    }
  }
  
  cout << (flag ? "Yes" : "No") << endl;
  
  return 0;
}

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

int main()
{
        int x, y;

        while (1) {
                cin >> x >> y;
                if(x==0 && y==0) break;

                if (x<y) {
                        cout << x << " " << y << endl;
                } else {
                        cout << y << " " << x << endl;
                };
        };
        return 0;
}

Measured memory_bytes: 2988
#include<stdio.h>


      int P[41],I[41],Q[41],n,now=0,s;

      int Find(int c)
      {

        int i;

        for(i=0;i<n;i++){
          if(c==I[i])return i;
        }

        return 0;

      }

      void Rec(int l,int r)
      {
        int c,n;

        if(l>=r)return;

        c=P[now++];
        n=Find(c);

        Rec(l,n);
        Rec(n+1,r);

        Q[s++]=c;

      }



      int main()
      {
        int i;

        scanf("%d",&n);

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

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

        Rec(0,n);

        for(i=0;i<n-1;i++){
          printf("%d ",Q[i]);
        }

        printf("%d\n",Q[i]);

      return 0;
      }



Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  if (N % K == 0) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
//起初全都一样大
//进行N次操作后
//每个数都-1
//直到最后全部都是N-1为止
 
//至于前K%N次操作
//前K%N个数 全部是+N-(K%N-1) 
//剩下的数 -K%N
int main(){
	ll K;
	scanf("%lld",&K);
	printf("50\n");
	ll cur=49+K/50LL;
	rep(k,50)printf("%lld%c",k<K%50LL?cur+50LL-(K%50LL-1LL):cur-K%50LL,k==49?'\n':' ');
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
ll h, w, a, b, c, d;
ll kj[200001];
ll ans;
ll keiro;

ll calc(ll x, ll y)
{
	if(y==0)
	{
		return 1;
	}
	else if(y%2==0)
	{
		ll z=calc(x, y/2);
		return (z*z)% MOD;
	}
	else
	{
		return (x*calc(x, y-1))% MOD;
	}
}

int main()
{
	cin >> h >> w >> a >> b;
	c=h-a;
	d=w-b;
	kj[0]=1;
	repp(i, 1, 200001)
	{
		kj[i]=(i*kj[i-1])% MOD;
	}
	ans=0;
	repp(i, 1, c+1)
	{
		keiro=(kj[b+i-2]*kj[h+d-i-1])% MOD;
		keiro=(keiro*calc(kj[b-1], MOD-2))% MOD;
		keiro=(keiro*calc(kj[i-1], MOD-2))% MOD;
		keiro=(keiro*calc(kj[h-i], MOD-2))% MOD;
		keiro=(keiro*calc(kj[d-1], MOD-2))% MOD;
		ans=(ans+keiro)% MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val h = readLine()!!.split(' ').map { it.toInt() }
    val dp = IntArray(n) { Int.MAX_VALUE }
    dp[0] = 0
    for (i in 0 until n) {
        for (j in 1..Math.min(k, n - i - 1)) {
            dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i] - h[i + j]))
        }
    }
    println(dp[n - 1])
}


Measured memory_bytes: 48548
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define DIVCEIL(A,B) ((A+(B-1))/B)
using namespace std;


void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
    vector<vector<int>> connected(N, vector<int>(N, 0));
    for(int i=0; i<M; i++){
        connected[a[i]-1][b[i]-1]++;
        connected[b[i]-1][a[i]-1]++;
    }
    vector<int> ordered(N, 0);
    long long ans=0ll;
    for(int i=0; i<N; i++)ordered[i]=i;
    do{
        int i;
        for(i=0; i<N-1; i++){
            if(!connected[ordered[i]][ordered[i+1]])break;
        }
        if(i==N-1)ans++;
    }while(next_permutation(ordered.begin()+1, ordered.end()));
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, M, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 256
d,g = map(int,input().split())
li = []
ans = []
for i in range(d):
  pc = list(map(int,input().split()))
  li.append(pc)
for bit in range(1<<d):
  problem = 0
  pt = 0
  cnt = 0
  for i in range(d):
    if ((bit >> i) & 1):
      problem += li[i][0]
      pt += 100*(i+1)*li[i][0] + li[i][1]
  if pt >= g:
    ans.append(problem)
  else:
    for j in range(d-1,-1,-1):
      if ((bit >> j) & 1) == 0:
        for k in range(li[j][0]):
          if pt >= g:
            break
          cnt += 1
          problem += 1
          pt += 100*(j+1)
    ans.append(problem)
          
print(min(ans))

Measured memory_bytes: 3064
N = int(input())
S = list(input())
S_number = []
# 変換
for i in range(N):
    if S[i] == '(':
        S_number.append(1)
    else:
        S_number.append(-1)

# print(S, S_number)
for i in range(N):
    if S_number[i] == 1:
        for j in range(i, N):
            if S_number[j] == -1:
                S_number[i] = 0
                S_number[j] = 0
                break
            if j == N-1:
                S_number[i] = 0
                S.append(')')
    # print(S, S_number)

insert_times = abs(sum(S_number))
for _ in range(insert_times):
    S.insert(0, '(')

answer = ''.join(S)
print(answer)


            
                

    

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<string>
 
const int MAX_N=1<<17;
 
using namespace std;
 
int n,bit[MAX_N+1];
 
int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}
 
void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}
 
int main(void){
 
  int q,com,a,b;
 
  cin >> n >> q;
  n++;
  while(q--){
    cin >> com >> a >> b;
    if(com)cout << sum(b)-sum(a-1) << endl;
    else add(a,b);
  }
 
  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary];A - Task Scheduling Problem
            var line = ReadLine();
            var combis = AllCombinations<int>(line, 3, true).ToList();
            int min = int.MaxValue;

            foreach(var tasks in combis)
            {
                int cost = CalcTotalCost(tasks);

                if (cost < min)
                {
                    min = cost;
                }
            }

            Console.WriteLine(min);
        }

        static int CalcTotalCost(List<int> tasks)
        {
            int total = Math.Abs(tasks[1] - tasks[0]);
            total += Math.Abs(tasks[2] - tasks[1]);

            return total;
        }

        static IEnumerable<List<T>> AllCombinations<T>(List<T> source, int n,
                                                       bool isAllowDupication = false)
        {
            //[summary]異なる要素から、n個を選ぶ組み合わせを列挙する
            //"isAllowDupication"を"true"にすると、重複を許可する
            //(重複を許可して、nを要素数と同じにすると、順列を列挙する)

            if (n == 1)
            {
                foreach (var s in source)
                {
                    yield return new List<T> { s };
                }

                yield break;
            }
            else
            {
                for (int i = 0; i < source.Count; i++)
                {
                    List<T> clone;

                    if (isAllowDupication)
                    {
                        //重複を許可する場合は、その要素のみを削除
                        clone = new List<T>(source);
                        clone.RemoveAt(i);
                    }
                    else
                    {
                        //重複を許可しない場合は、自分よりも前の要素はすべて削除
                        clone = new List<T>(source.Skip(i + 1));
                    }

                    //再帰処理
                    var items = AllCombinations(clone, n - 1, isAllowDupication);

                    foreach (var item in items)
                    {
                        item.Insert(0, source[i]);
                        yield return item;
                    }
                }
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13524
s = input()

ans = 0
l = 0
r = len(s) - 1
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        l += 1
        ans += 1
    elif s[r] == 'x':
        r -= 1
        ans += 1
    else:
        ans = -1
        break

print(ans)


Measured memory_bytes: 3316
import java.io.BufferedReader
import java.io.InputStreamReader

const val MOD = 1000000007L
val INV_26 = 26L pow -1

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val k = jin.readLine().toInt()
    val n = jin.readLine().length
    var answer = 0L
    var curr = 26L pow k
    for (j in n..n + k) {
        answer += curr
        curr *= (j + 1 - n).toLong() pow -1
        curr %= MOD
        curr *= INV_26
        curr %= MOD
        curr *= j.toLong()
        curr *= 25L
        curr %= MOD
    }
    println(answer % MOD)
}

val MOD_TOTIENT = (MOD - 1).toInt()

infix fun Long.pow(power: Int): Long {
    var e = power
    e %= MOD_TOTIENT
    if (e < 0) {
        e += MOD_TOTIENT
    }
    if (e == 0 && this == 0L) {
        return this
    }
    var b = this % MOD
    var res = 1L
    while (e > 0) {
        if (e and 1 != 0) {
            res *= b
            res %= MOD
        }
        b *= b
        b %= MOD
        e = e shr 1
    }
    return res
}

Measured memory_bytes: 40240
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 10000, MAXI = 100000, D = 10;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     while (tc--)
//     {
//     	cout << rand()%D + 1 << " " << rand()%D + 1 << " " << rand()%D + 1 << " " << rand()%D + 1;

//     	cout << "\n~\n";
    	
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define mod (int)(1e9+7)
#define N 3005

int dp[N][N];

string s, t;

int n, m;

int MEM(int i, int j)
{
	if(i==0 or j==0)
		return 0;

	if(dp[i][j]!=-1)
		return dp[i][j];

	int ans = 0;
	if(s[i-1]==t[j-1])
		ans = 1 + MEM(i-1, j-1);
	else
		ans = max(MEM(i-1, j), MEM(i, j-1));

	return dp[i][j] = ans;
}


// Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);


   	cin >> s >> t;

   	n = s.size();
   	m = t.size();
   	
   	memset(dp, -1, sizeof dp);

   	MEM(n, m);

   	int i = n, j = m;

   	string lcs = "";
   	
   	while(i>0 and j>0)
   	{
   		if(s[i-1]==t[j-1])
   		{
   			lcs += s[i-1];
   			i--;
   			j--;
   		}
   		else if(dp[i-1][j]>dp[i][j-1])
   			i--;
   		else
   			j--;
   	}

   	reverse(lcs.begin(), lcs.end());

   	cout << lcs;
    
    return 0;
 
} 

Measured memory_bytes: 71040
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back 

int bfs(int s, int t, int c);

vector<vector<int> > g(100001);

int main()
{
    int n;
    cin >> n;
    loop(i, n) {
        int r, k, t;
        cin >> r >> k;
        loop(j, k) {
            cin >> t;
            g[r].pb(t);
        }
    }
    int p;
    cin >> p;
    loop (i, p) {
        int s, d, v;
        cin >> s >> d >> v;
        int ans = bfs(s, d, v);
        if (ans != -1) {
            cout << v-ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

int bfs(int s, int t, int c)
{
    vector<bool> check(100001, false);
    queue<int> fq, nq, sq;
    int cnt = 0;
    fq.push(s);
    if (c == 0) {
        return -1;
    }
    while (1) {
        c--;
        while (!fq.empty()) {
            int pos = fq.front(); fq.pop();
            if (check[pos]) {
                continue;
            } else {
                check[pos] = true;
            }
            //cout << pos << endl;
            if (pos == t) {
                return c;
            }
            for (int i: g[pos]) {
                nq.push(i);
            }
        }
        if (c == 0 || nq.empty()) {
            return -1;
        }
        fq = nq;
        nq = sq;
        //cout << c << "====" << endl;
    }
}

Measured memory_bytes: 4996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main{

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int m = Integer.parseInt(lines[1]);
      int[][] mA = new int[n][m];
      int[]   vb = new int[m];
      int[]   vc = new int[n];

      for(int i = 0; i < n; i++ ) {
        lines = br.readLine().split(" ");
        for( int j = 0; j < m; j++ ) {
          mA[i][j] = Integer.parseInt(lines[j]);
        }
      }
      for( int i = 0; i < m; i++ ) {
        vb[i] = Integer.parseInt(br.readLine());
      }

      StringBuilder result = new StringBuilder();
      for( int i = 0; i < n; i++ ) {
        for( int j = 0; j < m; j++ ){
          vc[i] += mA[i][j] * vb[j];
        }
        result.append(vc[i] + "\n");
      }
      System.out.print(result);
    }
  }
}


Measured memory_bytes: 27436
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define sz(v) (v).size()
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(){
	Fio;
	int t=1;
	//cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for(int i=0; i<n; ++i)
			cin >> a[i];
		sort(all(a));
		reverse(all(a));
		ll ans = a[0], ptr = 1;
		for(int i=1; i<n-1; ++i) {
			ans += a[ptr];
			if(i%2 == 0)
				ptr++;
		}

		cout << ans;
	}

	return 0;
}

Measured memory_bytes: 3976
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, M = MI()
    A = [[None] * N for i in range(N)]
    B = [[None] * M for i in range(M)]

    for i in range(N):
        s = S()
        for j in range(N):
            A[i][j] = s[j]

    for i in range(M):
        s = S()
        for j in range(M):
            B[i][j] = s[j]

    for i in range(N-M+1):
        for j in range(N-M+1):
            f = []
            for m in range(M):
                for n in range(M):
                    f.append(A[i+m][j+n] == B[m][n])

            if all(f):
                print('Yes')
                return

    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 41704
import bisect
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
a = 0
Asum = list(accumulate(A))
x = bisect.bisect_right(Asum, Asum[N-1]/2)
total = Asum[N-1]
if x >= N:
    a = Asum[x-1]
    b = total-Asum[x-1]
    ans = abs(a-b)
if x == 0:
    a = Asum[x]
    b = total-Asum[x]
    ans = abs(a-b)
else:
    a = Asum[x-1]
    b = total-Asum[x-1]
    ans = abs(a-b)
    a = Asum[x]
    b = total-Asum[x]
    ans = min(ans, abs(a-b))
print(ans)


Measured memory_bytes: 31248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int S = sc.nextInt();
		
		sc.close();
		
		String[] hms = new String[3];
		
		for(int i=0; i<2; i++) {
			hms[2-i] = "" + S%60;
			S/=60;
		}
		hms[0] = "" + S;
		
		System.out.println(String.join(":", hms));
		
	}

}

Measured memory_bytes: 26200
#include <iostream>
#include <algorithm>
#include <vector>
#include "string"

using namespace std;

typedef long long ll;

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

    int N;
    cin >> N;

    vector<int> v(N);
    vector<int> c(N);

    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    for (int i = 0; i < N; i++) {
        int c;
        cin >> c;
        v[i] = v[i] - c;
    }

    sort(v.begin(), v.end(), greater<int>());

    int index = 0;
    int sum = 0;
    while (true) {
        if (v[index] > 0) {
            sum += v[index];
            index++;
        } else {
            break;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
e = [[i for i in input().split()] for i in range(n)]

for i in range(n):
    e[i][1]=(-1)*int(e[i][1])
for i in range(n):
    e[i]+=[i+1]
e.sort()
for i in range(n):
    print(e[i][2])
    

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
using namespace std;
string add(string a,string b){
	string c;
	if(a.size()<b.size() || (a.size()>b.size() && a<b))
		swap(a,b);
	a+='0';
	while(b.size()<a.size())
		b+='0';
	for(int i=0;i<a.size();i++){
		int s=a[i]+b[i]-96;
		a[i+1]+=s/10;
		c+=s%10+48;
	}
	return c;
}
string muti(string a,string b){
	string sum[10],c="0";
	if(a.size()<b.size())
		swap(a,b);
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	sum[1]=a;
	for(int i=2;i<=9;i++)
		sum[i]=add(sum[i-1],a);
	for(int i=0;i<b.size();i++){
		string to_add=sum[b[i]-48];
		to_add.insert(0,i,'0');
		c=add(c,to_add);
	}
	reverse(c.begin(),c.end());
	while(c[0]=='0' && c.size()>1)
		c.erase(0,1);
	return c;
}
string number[100010];
int main(){
	int n;
	cin>>n;
	string sum="1";
	for(int i=1;i<=n;i++){
		cin>>number[i];
		if(number[i]=="0"){
			cout<<0;
			return 0;
		}
	}
	for(int i=1;i<=n;i++){
		sum=muti(number[i],sum);
		if(sum.size()>19){
			cout<<-1;
			return 0;
		}
	}
	if(sum.size()==19){
		if(sum[0]>'1'){
			cout<<-1;
			return 0;
		}
		for(int i=1;i<sum.size();i++)
			if(sum[i]>'0'){
				cout<<-1;
				return 0;
			}
	}
	cout<<sum;
	return 0;
}

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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner kb=new Scanner(System.in);
		int a=kb.nextInt(),b=kb.nextInt();
		if(a<b){
			System.out.println("a < b");
		}else if(a==b){
			System.out.println("a == b");
		}else{
			System.out.println("a > b");
		}
		kb.close();
	}

}

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

int A, B, T;
int main(){
    cin >> A >> B >> T;
    int i = 1;
    int num = 0;
    while (true){
        if (A * i > T + 0.5){
            break;
        }
        num += B;
        i += 1;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

//INSERT ABOVE HERE
signed main(){
  Int x,y,z;
  cin>>x>>y>>z;
  Int n=x+y+z;
  vector<Int> a(n),b(n),c(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
  
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0;i<n;i++){
    a[i]-=c[i];
    b[i]-=c[i];
    vp.emplace_back(a[i],b[i]);
  }
  
  auto comp=[](P a,P b){
              return a.first-a.second>b.first-b.second;};
  sort(vp.begin(),vp.end(),comp);

  for(Int i=0;i<n;i++) tie(a[i],b[i])=vp[i];
  
  const Int INF = 1e17;
  vector<Int> dp1(n,-INF),dp2(n,-INF);
  priority_queue<Int> pq;
  
  Int sum=0;
  for(Int i=0;i<x;i++){
    sum+=a[i];
    pq.emplace(-a[i]);
  }
  dp1[x-1]=sum;
  for(Int i=x;i<n;i++){
    sum+=a[i];
    pq.emplace(-a[i]);
    sum+=pq.top();pq.pop();
    dp1[i]=sum;
  }
  
  while(!pq.empty()) pq.pop();
  sum=0;
  for(Int i=n-1;i>=n-y;i--){
    sum+=b[i];
    pq.emplace(-b[i]);
  }
  dp2[n-y]=sum;
  for(Int i=n-y-1;i>=0;i--){
    sum+=b[i];
    pq.emplace(-b[i]);
    sum+=pq.top();pq.pop();
    dp2[i]=sum;
  }
  
  Int ans=-INF;
  for(Int i=x-1;i<n-y;i++)
    chmax(ans,dp1[i]+dp2[i+1]);

  for(Int i=0;i<n;i++) ans+=c[i];
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7536
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int h, w; cin >> h >> w;
  int a[h][w];

  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }

  vector<P> vec;

  rep(i, h) {
    rep(j, w) {
      if ((i & 1) == 0) {
        vec.push_back(P(i, j));
      } else {
        vec.push_back(P(i, w-j-1));
      }
    }
  }

  vector<P> ans;

  int N = h*w;
  rep(k, N) {
    int i = vec.at(k).first;
    int j = vec.at(k).second;
    if (k != N-1 && (a[i][j] & 1) == 1) {
      int i2 = vec.at(k+1).first;
      int j2 = vec.at(k+1).second;
      ans.push_back(P((i<<10)+i2, (j<<10)+j2));
      a[i2][j2]++;
    }
  }

  cout << ans.size() << endl;
  int mask = (1<<10)-1;
  //debugln(mask);
  for(auto e : ans) {
    //debug(e.first); debugln(e.second);
    cout << (e.first>>10)+1 << ' ' << (e.second>>10)+1 << ' ';
    cout << (e.first&mask)+1 << ' ' << (e.second&mask)+1 << endl;
  }

}


Measured memory_bytes: 7024
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=2e5+5;
int n,a[N],b[N],cnt;
bool f[N];
vi ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=n;i>=1;i--)
	{
		int cnt=0;
		for(int j=i+i;j<=n;j+=i)
		{
			cnt+=f[j];
		}
		cnt%=2;
		if(cnt!=a[i])
		{
			f[i]=true;
			ans.pb(i);
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
		cout<<ans[i]<<' ';
	return 0;
}

Measured memory_bytes: 2552
#include<iostream>
using namespace std;
#define L long long int
int main(){
int n,ans=100000;
cin>>n;
while(n--){
	ans*=1.05;
	ans+=ans%1000==0 ? -ans%1000:1000-ans%1000;

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

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

int main(){
    bool flag=true;
    long long ans=0,sum=0;
    long long n;
    cin >>n;
    ans = (n*(n-1))/2;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,res[200007];
pair<int,int> a[200007];
int main(){
  cin >> n;
  for(int i = 1; i<=n; i++) cin >> a[i].first, a[i].second = i;
  sort(a+1,a+n+1);
  int k = 1;
  for(int i = 1; i<=n; i++){
    if(i==(n/2+1)) {
      res[a[i].second] = a[n/2].first;
      // printf("res for %dth is %d\n", a[i].second, a[n/2].first);

    }
    else if(i<(n/2+1)){
      res[a[i].second] = a[n/2+1].first;
      // printf("res for %dth is %d\n", a[i].second, a[n/2+1].first);
    }
    else{
      res[a[i].second] = a[n/2].first;
      // printf("res for %dth is %d\n", a[i].second, a[n/2].first);
    }

  }
  for(int i = 1; i<=n; i++) std::cout << res[i] << '\n';
}


Measured memory_bytes: 4480
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;

int N, K, t, cub[MAX], ans, x;

int main()
{
    optimiza_io
    cin >> N >> K;
    while( K -- ) {
        cin >> t;
        while( t -- ) {
            cin >> x;
            cub[x]++;
        }
    }
    
    for( int i = 1; i <= N; i ++ )
        ans += cub[i] == 0;
    
    cout << ans;
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3652
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for ai in a:
    d[ai] += 1
s = 0
for v in d.values():
    s += v * (v - 1) // 2
c = {}
for k, v in d.items():
    c[k] = s - v * (v - 1) // 2 + max(0, (v - 1) * (v - 2) // 2)
for ai in a:
    print(c[ai])


Measured memory_bytes: 97100
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
  if i == 0:
    ans += min(a, x)
    now_x = x - min(a, x)
    continue
    
  ans += min(a, now_x)
  now_x = x - min(a, now_x)

ans2 = 0
for i, a in enumerate(A[::-1]):
  if i == 0:
    ans2 += min(a, x)
    now_x = x - min(a, x)
    continue
    
  ans2 += min(a, now_x)
  now_x = x - min(a, now_x)

print(sum(A) - max(ans, ans2))

Measured memory_bytes: 19920