akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;


const int sz = 25;
mat memo[sz];
ll g[200][200];
int dp[200][200];
int pre[200][200];

mat mul(const mat &A, const mat &B){
  int n = A.size();
  mat C = A;
  rep(i, n)rep(j, n)rep(k, n){
    if(A[i][k] > 0 && B[k][j] > 0) C[i][j] = max(A[i][k] + B[k][j], C[i][j]);
  }
  return C;
}

void init(int V, int E){
  mat A = mat(V, vec(V, 0));
  int f, t;
  ll c;
  rep(i, E){
    cin >> f >> t >> c;
    A[f][t] = max(A[f][t], c);
    g[f][t] = max(g[f][t], c);
  }
  memo[0] = A;
  rep(i, sz - 1) memo[i+1] = mul(memo[i], memo[i]);
}

void calc(int V, int R, int K){
  rep(i, R)rep(j, V)rep(k, V){
    if(g[j][k] > 0 && (i == 0 || dp[i][j] > 0) && dp[i+1][k] < dp[i][j] + g[j][k]){
      dp[i+1][k] = dp[i][j] + g[j][k];
      pre[i+1][k] = j;
    }
  }

  int v = 0;
  int best = -1;
  rep(i, V) if(dp[R][i] > best){
    v = i;
    best = dp[R][i];
  }
  
  vector<int> res;
  res.push_back(v);
  for(int i = R; i > 0; i--){
    v = pre[i][v];
    res.push_back(v);
  }
  //cout << res.size() << endl;
  reverse(res.begin(), res.end());
  rep(i, res.size()) cout << res[i] << (i == (int)res.size() - 1 ? '\n' : ' ');
}

int main(){
  int V, E, K, i, res = 0;
  cin >> V >> E >> K;
  init(V, E);
  
  mat A;
  bool f = false;
  
  for(i = sz - 1; i >= 0; i--){
    bool ok = false;
    mat B = f ? mul(A, memo[i]) : memo[i];
    rep(j, V)rep(k, V) if(B[j][k] >= K) ok = true;
    if(!ok){
      res += 1 << i;
      A = B;
      f = true;
    }
  }
  
  res++;
  //resは経由する矢印の数
  if(res == (1 << sz)){
    cout << -1 << endl;
  }else {
    cout << res << endl;
    if(res  <= 100) calc(V, res, K);
  }
  
  return 0;
}

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(3e5)+10;
int n,a[maxn];
bool solve(int l,int r) {
	if (l==r) return 1;
	if ((r-l)%2==1) return 0;
	for (int i=l+1;i<=r-1;i+=2)
		if (a[i]!=i) return 0;
	int m1=0,m2=0;
	for (int i=l;i<=r;i+=2)
		if (a[i]<i) {
			if (a[i]<m1) return 0;
			m1=a[i];
		} else {
			if (a[i]<m2) return 0;
			m2=a[i];
		}
	return 1;
}
int main() {
	//freopen("1.txt","r",stdin);
	int mx=0,lst=0;
	read(n);
	for (int i=1;i<=n;i++) {
		read(a[i]);
		mx=max(mx,a[i]);
		if (i==mx) {
			if (!solve(lst+1,i)) {
				printf("No\n"); return 0;
			}
			lst=i;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int>> G;
vector<int> far(int node) {
    vector<int> dist(N), prev(N, -1);
    auto rec = [&](auto&& rec, int n, int p) -> void {
        dist[n] = dist[p] + 1;
        prev[n] = p;
        for (int next : G[n]) if (next != p) {
            rec(rec, next, n);
        }
    };
    rec(rec, node, node);
    vector<int> ans;
    int n = max_element(begin(dist), end(dist)) - begin(dist);
    for (;;) {
        ans.push_back(n);
        if (n == prev[n]) break;
        n = prev[n];
    }
    reverse(begin(ans), end(ans));
    return ans;
}
vector<int> gen(const vector<int> &L) {
    vector<bool> done(N);
    vector<int> ans;
    for (int i = 0; i < L.size(); i++) done[L[i]] = true;
    int n = 1;
    for (int i = 0; i < L.size(); i++) {
        int t = 0;
        for (int m : G[L[i]]) if (!done[m]) {
            t++;
            ans.push_back(n + t);
        }
        ans.push_back(n);
        n += t + 1;
    }
    return ans;
}
int main() {
    cin >> N;
    if (N == 2) {
        cout << "1 2\n";
        return 0;
    }
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, w; cin >> u >> w; u--, w--;
        G[u].push_back(w);
        G[w].push_back(u);
    }
    auto x = far(0);
    auto y = far(x.back());
    vector<bool> visited(N);
    for (int n : y) {
        visited[n] = true;
        for (int next : G[n]) visited[next] = true;
    }
    if (accumulate(begin(visited), end(visited), 0) != N) {
        cout << -1 << endl;
    } else {
        auto ans1 = gen(y);
        reverse(begin(y), end(y));
        auto ans2 = gen(y);
        for (int x : min(ans1, ans2)) {
            cout << x << ' ';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 15300
import math
n=int(input())
la=[]
lb=[]
for i in range(n):
    a,b=map(int,input().split())
    la.append(a)
    lb.append(b)
la=list(reversed(la))
lb=list(reversed(lb))
ans=0
for i in range(n):
    ans+=math.ceil((la[i]+ans)/lb[i])*lb[i]-(la[i]+ans)
print(ans)

Measured memory_bytes: 11864
S = input()

answer = ''
number_of_consecutive_times = 0
maxium_number_of_consecutive_times = 0
for char in S:
    is_included = char in ['A', 'C', 'G', 'T']

    if is_included:
        number_of_consecutive_times += 1
        maxium_number_of_consecutive_times = max(
            number_of_consecutive_times,
            maxium_number_of_consecutive_times,)
    else:
        number_of_consecutive_times = 0

print(maxium_number_of_consecutive_times)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

bool isvalid(string s){
    if(s.size()%2)return false;
    
    if(s.substr(0,s.size()/2) == s.substr(s.size()/2, s.size()/2))return true;
    return false;
}

int main(){
    string s;
    cin>>s;
    
    for(int i = s.size()-1;i>=1;i--){
        if( isvalid( s.substr(0,i) ) ){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vvll a(N, vll(N, 0));
  REP(i,N) REP(j,N) IN(a[i][j]);

  vll dp(1<<N, 0);
  vll dp_copy;
  dp[0] = 1;

  REP(i,N){
    dp_copy = dp;
    REP(j,N){
      if(a[i][j]==0) continue;
      REP(s,1<<N){
        if(s&(1<<j)) continue;
        dp[s|(1<<j)] += dp_copy[s];
        dp[s|(1<<j)] %= MOD;
      }
    }
  }

  OUT(dp[(1<<N)-1]);

  return 0;
}

Measured memory_bytes: 33152
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define soa(arr,n) sort(arr,arr+n)
#define sov(arr) sort(arr.begin(),arr.end())
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    while(t--) {
        int n,x,t;
        cin>>n>>x>>t;
        int c=n/x;
        if(n%x!=0) c++;
        cout<<c*t<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      	Scanner sc = new Scanner(System.in);
     	String s = sc.nextLine();
      	String t = sc.nextLine();
        String t2 = t.substring(0, s.length());
        if(s.equals(t2)) System.out.println("Yes");
        else System.out.println("No");
    }
  
}


Measured memory_bytes: 35744
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int N, L, i;
	string ans;
	cin >> N >> L;
	vector<string> S(N);

	for (i = 0; i < N; i++)
		cin >> S[i];

	sort(S.begin(), S.end());

	for (int i = 0; i < N; i++)
		ans += S[i];

	cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  int len = S.size();
  int hugs = 0;
  for(int i=0; i<len; i++){
    if(S[i] != S[len-(i+1)]){
      S[len-(i+1)] = S[i];
      hugs++;
    }
  }
  cout << hugs << endl;
  return 0;
}

Measured memory_bytes: 384
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for(auto &x : a){
        cin >> x;
        mp[x]++;
    }
    sort(ALL(a));
    uni(a);
    if(SZ(a) == 1){
        if(a[0] == 0){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }else if(SZ(a) == 2){
        if(a[0] == 0 && n % 3 == 0 && mp[0] == n / 3){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }else if(SZ(a) == 3 && n % 3 == 0){
        if((a[0] ^ a[1] ^ a[2]) == 0){
            if(mp[a[0]] == n / 3 && mp[a[1]] == n / 3 && mp[a[2]] == n / 3){
                cout << "Yes";
            }else{
                cout << "No";
            }
        }else{
            cout << "No";
        }
    }else{
        cout << "No";
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

void Main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++)
    {
        cout << s[i] << t[i];
    }
    cout << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

int main(){
	double X, K, D;
	cin >> X >> K >> D;

	if(0>X) X=-X;
	double num, buf1, buf2;
	num = floor(X/D);
	if(num>K){
		printf("%.0lf\n",X-K*D);
		return 0;
	}

	buf1 = abs(X-num*D);
	buf2 = abs(X-(num+1)*D);
	if(buf2>buf1){
		if(floor((K-num)/2)==(K-num)/2){
			printf("%.0lf\n", buf1);
		}else{
			printf("%.0lf\n", buf2);
		}
	}else{
		if(floor((K-num-1)/2)==(K-num-1)/2){
			printf("%.0lf\n", buf2);
		}else{
			printf("%.0lf\n", buf1);
		}
	}
	return 0;
}


Measured memory_bytes: 3900
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false


ll modfac(ll n, ll m) {
	ll res = 1;
	for (ll i = 1; i <= n; i++) {
		res = (res * i) % m;
	}
	return res;
}

int main() {
	const ll MOD = 1000000007;
	ll N;
	cin >> N;
	cout << modfac(N, MOD) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
   
  
  using namespace std;
  int A[100005];
  int B[100005];
  int C[100005];
  int a[100005];
  int b[100005];
  int c[100005];
  void solve()
  { 

    int n;
    cin>>n;
    rep(n)
    {
       cin>>a[i+1]>>b[i+1]>>c[i+1];
       A[i+1]=0;
       B[i+1]=0;
       C[i+1]=0;
    }
    A[1]=a[1];
    B[1]=b[1];
    C[1]=c[1];
    for(int i=2;i<=n;i++)
    {
       
       A[i]=max(A[i],B[i-1]+a[i]);
       A[i]=max(A[i],C[i-1]+a[i]);


       
       B[i]=max(B[i],A[i-1]+b[i]);
       B[i]=max(B[i],C[i-1]+b[i]);

       C[i]=max(C[i],B[i-1]+c[i]);
       C[i]=max(C[i],A[i-1]+c[i]);

       


    }

    cout<<max(A[n],max(B[n],C[n]));
    
    


   
   }

  signed main()
  {
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }


Measured memory_bytes: 4992
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    BigInteger limit = new BigInteger("10").pow(18);
    BigInteger error = new BigInteger("-1");
    int n = sc.nextInt();
    BigInteger result = BigInteger.ONE;
    for (int i = 0; i < n; i++) {
      BigInteger a = new BigInteger(sc.next());
      if (a.compareTo(BigInteger.ZERO) == 0) {
        System.out.println(0);
        return;
      }
      if (result != error) {
        result = result.multiply(a);
        if (result.compareTo(limit) > 0) {
          result = error;
        }        
      }
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 49100
#include<bits/stdc++.h>
#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define Mod 1000000007
typedef unsigned long long LL;
using namespace std;

struct Item
{
	LL a , b;
}a[6];

LL n;

int _ , __;
char c_;
int read()
{
	for (_ = 0,__ = 1,c_ = getchar();!isdigit(c_);c_=getchar())if (c_ == '-')__ = -1;
	for (;isdigit(c_);c_=getchar())_ = (_ << 1) + (_ << 3) + (c_ ^ 48);
	return _ * __;
}

int main()
{
#ifdef hany01
	freopen("test.in" , "r" , stdin);
	freopen("test.out" , "w" , stdout);
#endif
	cin >> a[1].a >> a[2].a >> a[3].a >> a[4].a >> n;
	a[1].b = 1;
	a[2].b = 2;
	a[3].b = 4;
	a[4].b = 8;
	n *= 4;
	LL Ans = 0;
	while (n)
	{
		LL Min = 900000000000 , k;
		For(i , 1 , 4)
			if (Min > a[i].a * a[5 - i].b)
			{
				Min = a[i].a * a[5 - i].b;
				k = i;
			}
		Ans += (n / a[k].b) * a[k].a;
		n %= a[k].b;
		a[k].a = 9000000000000;
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000008
int w[305][305],dist[305][305];
int main()
{
    int n,i,j,k;
    long long ans=0,sum=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            cin>>dist[i][j];
            sum+=dist[i][j];
            //dist[i][j]=w[i][j];
        }
    }
    for(i=0; i<n; i++)
    {
        dist[i][i]=inf;
    }
    for (k = 0; k < n; k++)
    {
        // Pick all vertices as source one by one
        for (i = 0; i < n; i++)
        {
            // Pick all vertices as destination for the
            // above picked source
            for (j = i+1; j < n; j++)
            {
                if (dist[i][k] + dist[k][j] == dist[i][j])
                {
                    if(!w[i][j])
                    {
                        //cout<<dist[i][j]<<endl;
                        ans+=dist[i][j];
                        w[i][j]=1;
                    }
                }
                if (dist[i][k] + dist[k][j] < dist[i][j])
                {
                    dist[i][j] = dist[i][k] + dist[k][j];
                    printf("-1\n");
                    return 0;
                }
            }
        }
    }
    cout<<(sum/2)-ans<<endl;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%s", $input);
list($len, $s, $output) = [strlen($input), 0, 0];

for ($i=0;$i<$len;$i++) {

	if ($input[$i] === "S") $s++;

	if ($input[$i] === "T") ($s === 0) ? $output++ : $s--;
}

echo $output*2;


Measured memory_bytes: 3960
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *W = map(int, read().split())

    ans = INF
    for t in range(1, N):
        ans = min(ans, abs(sum(W[:t]) - sum(W[t:])))

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String arr[] = {"Sunny","Cloudy","Rainy"};
        String word=s.next();
        int j=0;
        for(String i:arr){
            if(i.equals(word)){
                System.out.println(arr[(j+1)%3]);
                break;
            }
            j++;
        }
    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define P pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N=1005,M=2e5+5;
int n,m,x,y;
int d[N];
vector<P>e[N];
vector<int>e2[N];
bool can[M],bz[N],bz2[N];
void cover(int x){
	if(bz2[x])return;
	bz2[x]=1;d[1]=x;
	for(int l=0,r=1;x=d[++l],l<=r;)
		for(P i:e[x])if(!bz2[i.fi])
			bz2[i.fi]=1,d[++r]=i.fi;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	fo(i,1,m){
		cin>>x>>y;
		e[x].pb(P(y,i));
		e2[y].pb(x);
	}
	fo(i,1,n){
		fo(j,1,n)bz2[j]=bz[j]=0;
		d[1]=i;bz[i]=1;
		for(int l=0,r=1;x=d[++l],l<=r;)
			for(int i:e2[x])if(!bz[i])
				bz[i]=1,d[++r]=i;
		bz2[i]=1;
		for(P j:e[i]){
			can[j.se]=bz2[j.fi];
			cover(j.fi);
		}
		fo(j,1,n)bz2[j]=0;
		bz2[i]=1;
		fd(j,0,e[i].size()-1){
			x=e[i][j].fi;
			y=e[i][j].se;
			can[y]|=bz2[x];
			cover(x);
			can[y]=can[y]?(bz[x]?0:1):(bz[x]?1:0);
		}
	}
	fo(i,1,m)printf(can[i]?"diff\n":"same\n");
}

Measured memory_bytes: 5888
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int pay = 1000;
        for(int i = 1;i<=n;i++){
            if(pay*i>=n){
                System.out.println(pay*i-n);
                break;
            }
        }
    }
}

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

int main() {
  int N;
  cin >> N;

  if(N == 0){
    cout << 0 << endl;
    return 0;
  }

  vector<char> vec;
  while(0 != N){
    if(N & 1){
      // odd
      vec.push_back('1');
      if(N < 0){
        N = (N - 1) / -2;
      }
      else{
        N /= -2;
      }
    }
    else{
      vec.push_back('0');
      N /= -2;
    }
  }

  while(!vec.empty()){
    cout << vec.back();
    vec.pop_back();
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import math
N=int(input())
A=list(map(int,input().split()))
flag=True
if N%2==0:
    if 0 in A or len(set(A))!=N//2:flag=False
else:
    if len([0 for a in A if a==0])!=1 or len(set(A))!=N//2+1:flag=False
if flag:print(2**(N//2)%(10**9+7))
else:print(0)

Measured memory_bytes: 13812
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    L = [0] * N
    R = [0] * N
    for i in range(N-1):
        L[i+1] = Math.gcd(L[i], A[i])
    for i in reversed(range(N-1)):
        R[i] = Math.gcd(R[i+1], A[i+1])
    M = [0] * N
    for i in range(N):
        M[i] = Math.gcd(L[i], R[i])
    print(max(M))


if __name__ == "__main__":
    main()


Measured memory_bytes: 64240
import java.util.*;
public class Main{
  public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int K = sc.nextInt();
   int X = sc.nextInt();
    if(500 * K >= X){
		System.out.println("Yes");
    }else System.out.println("No");
  }
}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
#define INF 1e6
using ll=long long;
using namespace std;


vector<int> cost;
void bfs(vector<vector<int>> g)
{
	cost[0]=0;
	queue<int> que;
	que.push(0);
	while(!que.empty())
	{
		int p=que.front();que.pop();
		for(int v : g[p])
		{
			if(cost[v]!=INF) continue;
			cost[v]=cost[p]+1;
			que.push(v);
		}
	}
}
int main()
{
	int N,M;
	cin>>N>>M;
	vector<vector<int>> g(N,vector<int>());
	rep(i,M)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);	
	}
	cost.resize(N,INF);	
	bfs(g);
	if(cost[N-1]==2)
	{
		cout<<"POSSIBLE"<<endl;
	}
	else
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}


Measured memory_bytes: 28024
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define lint long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
/*******source code below********/
int main(void) {
	int N; cin >> N;
	vector<long long> A(N);
	lint min = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		if (A[i] < 0) min++;
	}
	lint sum = 0;
	if (min % 2 == 0) {
		for (int i = 0; i < N; i++) {
			sum += abs(A[i]);
		}
	}
	else {
		vector<lint> B(N);
		for (int i = 0; i < N; i++)
		{
			B[i] = abs(A[i]);
		}
		sort(B.begin(), B.end());
		for (int i = 0; i < N; i++)
		{
			sum += B[i];
		}
		sum -= 2 * B[0];
	}
	/*while (true) {
		bool check = false;
		for (int i = 0; i < N - 1; i++) {
			if ((A[i] + A[i + 1]) < -1 * (A[i] + A[i + 1])) {
				A[i] *= -1;
				A[i + 1] *= -1;
				check = true;
			}
		}
		if (!check) break;
	}*/

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    String[] s = new String[N];
    HashMap<String, Integer> hashMap = new HashMap<>();

    for (int i = 0; i < N; i++) {
      String s_ = sc.next();
      s = s_.split("");
      Arrays.sort(s);
      String s2 = "";
      for (int j = 0; j < s.length; j++) {
        s2 += s[j];
      }
      if (hashMap.containsKey(s2)) {
        Integer v = hashMap.get(s2);
        hashMap.put(s2, v + 1);
      } else {
        hashMap.put(s2, 1);
      }
    }

    sc.close();

    long count = 0;

    for (Integer value : hashMap.values()) {
      if (1 < value) {
        for (int i = 2; i <= value; i++) {
          count += i - 1;  
        }
      }
    }

    System.out.println(count);

  }

}

Measured memory_bytes: 106436
#include <stdio.h>

int main(void)
{
	char str[100];
	char ans[1000];
	int a, b, c;
	
	while (scanf("%s", str) != EOF){
		a = 0;
		while (str[a] != '\0') {
			if (str[a] == '@') {
				b = str[a + 1] - '0';
				a += 2;
				for (c = 0; c < b; c++) {
					printf("%c", str[a]);
				}
			}
			else {
				printf("%c", str[a]);
			}
			a++;
		}
		printf("\n");
	}
	
	return (0);
}	

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vint H(N);
    cin >> H;
    int ans = 0;
    bool flag = true;
    while(flag){
        int st = 0;
        int mini = 100;
        REP(i,N+1){
            if(i == N || H[i] == 0){
                for(int j=st; j<i; j++){
                    H[j] -= mini;
                }
                if(st == i)mini=0;
                ans += mini;
                st = i+1;
                mini = 100;
            }else{
                chmin(mini,H[i]);
            }
        }
        flag = false;
        REP(i,N){
            if(H[i] != 0){
                flag = true;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	
	string s="";
	rep(i,ty-sy)s+="U";
	rep(i,tx-sx)s+="R";
	rep(i,ty-sy)s+="D";
	rep(i,tx-sx)s+="L";
	
	s+="L";
	rep(i,ty-sy+1)s+="U";
	rep(i,tx-sx+1)s+="R";
	s+="D";
	
	s+="R";
	rep(i,ty-sy+1)s+="D";
	rep(i,tx-sx+1)s+="L";
	s+="U";
	
	cout<<s<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

void main() {
    auto N = readln.chomp.to!long;

    long[] F;
    for (long i = 1; i * i <= (N - 1); ++i) {
        if ((N - 1) % i == 0) {
            F ~= i;
            if (i * i != (N - 1)) {
                F ~= (N - 1) / i;
            }
        }
    }
    F.sort();

    long[] G;
    for (long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            G ~= i;
            if (i * i != N) {
                G ~= N / i;
            }
        }
    }
    G.sort();

    long ans = F.length.to!int - 2;
    foreach (g; G) if ((N / g - 1) % g == 0) ans += 1;


    for (long i = 2; i * i <= N; ++i) {
        for (long x = i * i; x <= N; x *= i) {
            if (N % x != 0) continue;
            long y = N / x - 1;
            if (y % i == 0) ans += 1;
        }
    }

    ans.writeln;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll N,Q;
  cin >> N;
  string S;
  cin >> S >> Q;
  vector<set<ll>> vec(26);
  rep(i,26){
    vec[i].insert(INF);
  }
  rep(i,N){
    vec[S[i]-'a'].insert(i);
  }
  rep(i,Q){
    ll q;
    cin >> q;
    if(q==1){
      ll x;
      char c;
      cin >> x >> c;
      x--;
      char d=S[x];
      S[x]=c;
      vec[d-'a'].erase(x);
      vec[c-'a'].insert(x);
    }
    if(q==2){
      ll M,N;
      cin >> M >> N;
      M--;
      ll ans=0;
      rep(z,26){
        if(vec[z].size()==1){
          continue;
        }
        ll e=*vec[z].lower_bound(M);
        ll f=*vec[z].lower_bound(N);
        if(e!=f){
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
}

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

int main(){
    int k,n;
    cin >> k >> n;
    int max=0,fa,a;
    cin >> fa;
    int a_1 = fa;
    rep(i,n-1){
        cin >> a;
        if (max < a-fa){
            max = a-fa;
        }
        fa = a;
    }
    if (k-fa+a_1 > max){
        max = k-fa+a_1;
    }

    cout << k-max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cmath>

using namespace std;

int main() {

	int v;
	while (cin >> v) {
		int sum = 0;
		for(unsigned i = 0; i < 10; ++i) {
			if ((v>>i)&1) {
				sum += pow(2,i);
				cout << pow(2,i);
				if (sum != v) cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 100000+19;

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

    char prev = s[0];
    int ans = 1;
    for(int i = 1;i < s.size();i++) {
        if(s[i] != s[i-1])
            ans++;
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;

    int max = 1;
    string maxstr;
    bool f = false;
    for (int i = 0; i < N; ++i) {
        for (int j = i + max; j < N; ++j) {
            while (S.substr(i, max) == S.substr(j, max) && i + max <= j) {
                f = true;
                if (S.substr(i, max+1) == S.substr(j, max+1) && i + max + 1 <= j) {
                    max++;
                } else {
                    break;
                }
            }
        }
    }
    if (f) {
        cout << max << endl;
        cout << maxstr << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main(){
int N;
vector<int>A(200);

cin >> N;
for(int i =0;i<N;i++){
cin>>A.at(i);
}
int cnt =0;

while(true){
bool odd = false;
for(int i =0;i<N;i++){
if(A.at(i)%2!=0){
odd = true;
}
}
if(odd)break;
for(int i =0;i<N;i++){
A.at(i)/=2;
}
cnt++;
}
cout<<cnt<<endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int h,ans,now=1;

signed main() {
    cin >> h;
    while(h) {
        ans += now;
        h /= 2;
        now *= 2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		int[] waseda = new int[10];
		int[] keio   = new int[10];
		
		for(int r = 0; r < 10; r++) {
			waseda[r] = stdIn.nextInt();
		}
		for(int r = 0; r < 10; r++) {
			keio[r] = stdIn.nextInt();
		}
		Arrays.sort(waseda);
		Arrays.sort(keio);
		int wasedaSum = 0, keioSum = 0;
		for(int r = 9; r >= 7; r--) {
			wasedaSum += waseda[r];
			keioSum   += keio[r];
		}
		System.out.println(wasedaSum + " " + keioSum);
	}
}

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

#define ntest 0

using namespace std;
long long d,t,s;
void solve() {
    cin >> d >> t >> s;
    puts((s*t >= d)?"Yes":"No");
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int x,y,z;
    cin>>x>>y>>z;

    cout<<z<<" "<<x<<" "<<y<<endl;

    return 0;
}





Measured memory_bytes: 256
#!/usr/bin/env ruby

if __FILE__ == $0 then
	n = gets.chomp.to_i
	X = gets.split.map(&:to_i)
	Y = gets.split.map(&:to_i)

	dist = []
	n.times do |i|
		dist += [(X[i]-Y[i]).abs]
	end

	p dist.sum
	p dist.map { |x| x**2 }.sum ** (1.0/2)
	p dist.map { |x| x**3 }.sum ** (1.0/3)
	p dist.max
end



Measured memory_bytes: 6968
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;

int main(){
    int n;cin >> n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int tmp;cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans += max((int)(lower_bound(v.begin(),v.end(),v[i] + v[j])-v.begin())-j-1,(int)0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	map<string, vi> table;
	string s;
	int p;

	while(cin >> s) {
		cin >> p;
		table[s].push_back(p);
	}

	map<string, vi>::iterator it = table.begin();
	while(it != table.end()) {
		cout << (*it).first << endl;
		sort(ALL((*it).second));
		bool flag = false;
		REP(i, (*it).second.size()) {
			if(flag)
				cout << " ";
			cout << (*it).second[i];
			flag = true;
		}
		cout << endl;
		++it;
	}

	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define f first 
#define s second
#define ll long long
#define int long long
const int N = 200005;
 
int32_t main(){
   int n , m , t;
   cin>>n>>m>>t;
  int arr[n];
 int brr[m];
   for(int i = 0;i < n ;i++){
       cin>>arr[i];
   }
   for(int i = 0 ; i< m ;i++){
        cin>>brr[i];
   }
  int pref[n];
  int pref2[m];
  pref[0] = arr[0];
  pref2[0] = brr[0];
  for(int i = 1 ; i < n  ; i++){
       pref[i] = pref[i-1] + arr[i];
  }
  for(int i = 1 ; i < m ; i++){
       pref2[i] = pref2[i-1] + brr[i];
  }
    int temp = t;
    int ans = 0;
  for(int i = 0 ; i< n ;i++){
      if(temp - pref[i] >= 0){
         // cout<<"sum : "<<pref[i]<<" ";
            int x = upper_bound(pref2 , pref2+m , temp-pref[i]) - pref2;
          //  cout<<"index "<<x<<endl;
            ans = max(ans , i+1+x);
      }
     
  }
  for(int i = 0 ; i < m ;i++){
      if(temp - pref2[i] >= 0){
          // cout<<"sum : "<<pref2[i]<<" ";
       int x = upper_bound(pref , pref+n , temp - pref2[i]) - pref;
       //cout<<"index :"<<x<<endl;
       ans = max(ans , i+1 + x);
      }
  }
  cout<<min(ans , n+m)<<endl;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 200003
#define F first
#define S second
#define PB push_back
#define MP make_pair
const ll mod = 1e9+7;
using namespace std;
void code()
{
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll rmoves = min(k, x/d);
	k-=rmoves;
	x-=rmoves*d;
	if(k%2==0)
	{
		cout << x;
	}
	else
	{
		cout << d-x;
	}
}
int main()
{
	SPEED
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	int t = 1;
	while(t--)
	{
		code();//DEBUG
	}
}

Measured memory_bytes: 3660
function main()
    n, m, k = parse.(Int, split(readline()))
    As = parse.(Int, split(readline()))
    Bs = parse.(Int, split(readline()))
    
    A_sum = sum(As)
    ans = 0
    j = 0
    time = A_sum
    for i in n:-1:0
        while j < m && time + Bs[j+1] <= k
            j += 1
      		time += Bs[j]
        end
      	if time <= k
        	ans = max(ans, i+j)
        end
    	if i > 0
    		time -= As[i]
    	end
    end
    
    println(ans)
    
end

main()

Measured memory_bytes: 206300
# ABC169 D
N=int(input())

def factorization(N):
    res=[]
    for i in range(2,int(N**(1/2))+2):
        if not N%i:
            r=0
            while not N%i:
                N//=i
                r+=1
            res.append((i,r))
    if N>1:
        res.append((N,1))
    return res

fact=factorization(N)

res=0
for p,r in fact:
    i=1
    while 1:
        if i*(i+1)//2<= r < (i+1)*(i+2)//2:
            break
        else:
            i+=1
    res+=i
print(res)        

Measured memory_bytes: 63328
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int a;
  int b;
  int h;
  cin >> a;
  cin >> b;
  cin >> h;

  int ans = (a + b) * h / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, k int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &k)

	result := 0
	if k > 0 {
		k -= a
		result += a
		if k < 0 {
			result += k
			k = 0
		}
	}

	if k > 0 {
		k -= b
		if k < 0 {
			k = 0
		}
	}

	if k > 0 {
		k -= c
		result -= c
		if k < 0 {
			result -= k
			k = 0
		}
	}

	fmt.Printf("%d\n", result)
}


Measured memory_bytes: 1816
from functools import lru_cache
import sys
input = sys.stdin.readline

@lru_cache(maxsize=None)
def dfs(a, b, c):
    if (a ^ b) & 1 != c & 1:
        return float('inf')
    if a == 0:
        return 0 if b == c else float('inf')
    return min(2 * dfs(a >> 1, b >> 1, c >> 1), 2 * dfs((a - 1) >> 1, (b + 1) >> 1, c >> 1) + 1)

N = int(input())
A = list(map(int, input().split()))
B = 0
for i in range(2, N):
    B ^= A[i]
ans = dfs(A[0], A[1], B)
print(ans if ans < float('inf') and A[0] > ans else -1)

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){
		int n; cin >> n;
		int A[n];
		int X = 0;
		for(int i = 0; i < n; i++){
			cin >> A[i];
			X ^= A[i];
		}
		for(int i = 0; i < n; i++){
			cout << (X ^ A[i]) << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 5216
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {	
	int n, m;
	cin >> n >> m;
	vector<int>v(m);
	rep(i, 0, m) {
		cin >> v[i];
	}
	
	sort(v.begin(), v.end());

	vector<int> width(m - 1);
	rep(i, 0, m - 1) {
		width[i] = v[i + 1] - v[i];
	}

	sort(width.begin(),width.end());
	reverse(width.begin(), width.end());

	int ans = v[m - 1] - v[0];
	if (n >= m) {
		cout << "0" << endl;
		exit(0);
	}
	else {
		rep(i, 0, n - 1) {
			ans -= width[i];
		}
	}


	cout << ans << endl;


	return 0;

}

Measured memory_bytes: 1024