akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1e9;

int main() {
    int n, W;
    cin>>n>>W;
    int w[n];
    int v[n];
    int sum_val = 0;
    for (int i=0; i<n; i++){
        cin>>w[i]>>v[i];
        sum_val +=  v[i];
    }

    //dp[i] is minimum total weight for total value of i
    // answer will be if dp[i] <= W, maximum total values (index i);

    vector<long long int> dp(sum_val+1, INF);
    dp[0] = 0;
    for (int item=0; item<n; item++){
        for (int value_already = sum_val - v[item]; value_already>=0; value_already--){
            dp[value_already+v[item]] = min(dp[value_already+v[item]], w[item]+dp[value_already]); 
        }
    } 
    int ans = 0;
    for (int i=1; i<=sum_val; i++){
        if (dp[i] <= W){
            ans = max(ans, i);    
        }
    }
    cout<<ans;
}




Measured memory_bytes: 1024
//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long long int LL;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define PR(a)           cout<<"("<<a<<")";
#define ED              cout<<'\n';
#define endl            '\n'
#define loop(j,a,n)     for(int j=a;j<=n;j++)
#define loop1(j,a,n)    for(int j=a;j>=n;j--)
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define SC(n)           scanf("%d",&n)
#define PB              push_back
#define MP              make_pair
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007

vector<ll> ind,wt,val,sd;
int n;
ll dp[1123][32234];

bool comp(int i,int j)
{
        return wt[i]+sd[i]> wt[j]+sd[j];
}   

ll solve(int i,int s)
{
    if(s<0) return -1e15;
    if(i==n) return 0;  
    int k=ind[i];
    if(dp[i][s]!=-1) return dp[i][s];
    dp[i][s]= solve(i+1,s);
    if(wt[k]<=s)
    dp[i][s]=max(dp[i][s] ,   val[k]+ solve(i+1, min(sd[k],s-wt[k]) ) );
    return dp[i][s];
}   


int main() 
{
    IO
 

    memset(dp,-1,sizeof(dp));
    cin>>n;
    ind.resize(n);
    wt.resize(n);
    val.resize(n);
    sd.resize(n);

    for(int i=0;i<n;i++)
    {
        ind[i]=i;
        cin>>wt[i]>>sd[i]>>val[i];
    }

    sort(all(ind),comp);


    ll ans=solve(0,21122);

    cout<<ans<<endl;

}




 

Measured memory_bytes: 283136
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair <double, int> PDI;

void print( PDI p )
{
    printf( "%d %.2f\n", p.second, p.first );
}

int main() {
    vector <PDI> big_list(18);
    int bl_index=0;
    for ( int i = 0; i < 3; i++ ) {
        vector <PDI> list( 8 );
        for ( int j = 0; j < 8; j++ ) {
            cin >> list[j].second >> list[j].first;
        }

        sort( list.begin(), list.end() );
        print( list[0] );
        print( list[1] );

        for ( int j = 2; j < 8; j++ ) {
            big_list[bl_index++] = list[j];
        }
    }

    sort( big_list.begin(), big_list.end() );
    print( big_list[0] );
    print( big_list[1] );

    return 0;
}

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

#define int long long

int memo[10];
auto main() -> signed {
    int n;
    cin >> n;
    int ans_min = 0;
    int ans_max = 0;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        if(a >= 3200) ans_max++;
        else {
            if(a<400&&memo[0]==0) {
                ans_min++;
                ans_max++;
                memo[0]++;
            }
            else if(a>=400&&a<800&&memo[1]==0){
                ans_min++;
                ans_max++;
                memo[1]++;
            }
            else if(a>=800&&a<1200&&memo[2]==0) {
                ans_min++;
                ans_max++;
                memo[2]++;
            }
            else if(a>=1200&&a<1600&&memo[3]==0){
                ans_min++;
                ans_max++;
                memo[3]++;
            }
            else if(a>=1600&&a<2000&&memo[4]==0){
                ans_min++;
                ans_max++;
                memo[4]++;
            }
            else if(a>=2000&&a<2400&&memo[5]==0){
                ans_min++;
                ans_max++;
                memo[5]++;
            }
            else if(a>=2400&&a<2800&&memo[6]==0){
                ans_min++;
                ans_max++;
                memo[6]++;
            }
            else if(a>=2800&&a<3200&&memo[7]==0){
                ans_min++;
                ans_max++;
                memo[7]++;
            }
        }
    }
    if(ans_min==0) ans_min = 1;
    cout << ans_min << " " << ans_max << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> s(n);
    for(int i = 0;i < n;i ++){
        cin >> s.at(i);
    }

    sort(s.begin(),s.end());
    int sum = 0;
    for(int i = 0;i < n;i ++) sum += s.at(i);


    vector<vector<int> > dp(n+1,vector<int>(sum+1));
    dp.at(0).at(0) = 1;

    for(int i = 0;i < n;i ++){
        for(int j = 0;j < sum+1;j ++){
            if(dp.at(i).at(j) == 1) {
                dp.at(i+1).at(j) = 1;
                dp.at(i+1).at(j+s.at(i)) = 1;
            }
        }
    }

    for(int i = 10;i < sum+1;i += 10) dp.at(n).at(i) = 0;

    for(int i = sum;i >= 0;i --){
        if(dp.at(n).at(i) == 1){
            cout << i << endl;
            break;
        }
    }
    
}



Measured memory_bytes: 8192
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if (u.equals(s)) {
            a--;
        } else if (u.equals(t)) {
            b--;
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 21204
#include<iostream>
using namespace std;
int t[2001];
int n,sum;
int main(){
	for(int i=0;i<2001;i++){
		if(i<1001)t[i]=i+1;
		else t[i]=2001-i;
	}
	while(cin>>n){
		sum=0;
		for(int i=0;i<2001;i++){
			if(n-i>=0&&n-i<=2000){
				sum=sum+t[i]*t[n-i];
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 998244353;
signed main()
{
    int n, m;
    cin >> n >> m;
    vector<map<int, int> > strings(n), cols(n);
    for (int i=0; i < m; i++){
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        if (x >= y) strings[x][y] = c;
        else cols[y][x] = c;
    }
    int dp[n][2];
    for (int i=0; i < n; i++) for (int j=0; j < 2; j++) dp[i][j] = 0;
    if (strings[0].count(0)){
        int val = strings[0][0];
        dp[0][val] = 1;
    }
    else{
        dp[0][0] = 1, dp[0][1] = 1;
    }
    vector<int> pws;
    pws.push_back(1);
    for (int i=0; i < 1e6; i++) pws.push_back((pws.back()*2)%MOD);
    for (int i=1; i < n; i++){
        for (int j=0; j < 2; j++){
            if (strings[i].count(i) && strings[i][i] != j) continue;
            for (int k=0; k < 2; k++){
                int mn = 1;
                int var = 0, S=0;
                if (strings[i].count(i-1)){
                    var++, S+=strings[i][i-1];
                }
                if (cols[i].count(i-1)){
                    var++, S += cols[i][i-1];
                }
                if (var == 0) mn = 2;
                if (var == 2){
                    if ((S+j+k)%2!=0) mn=0;
                }
                int two = 0;
                set<int> val;
                int tet = k;
                for (auto it = strings[i].begin(); it != strings[i].end(); it++){
                    if ((*it).first >= i-1) break;
                    val.insert((*it).first);
                }
                for (auto it = cols[i].begin(); it != cols[i].end(); it++){
                    if ((*it).first >= i-1) break;
                    val.insert((*it).first);
                }
                two = (i-1) - (val.size());
                //if (i==3 && j==1) cout << mn << endl;
                //if (i==3 && j==1) cout << tet << endl;
                for (auto it = val.begin(); it != val.end(); it++){
                    int V = (*it);
                    bool A = strings[i].count(V), B = cols[i].count(V);
                    if (!(A&&B)){
                        continue;
                    }
                    int x = strings[i][V], y = cols[i][V];
                    if (V != i-2 && (x+y)%2 != 0) mn = 0;
                    if (V == i-2 && (((x+y)%2) != tet%2)) mn = 0;
                }
                mn *= pws[two];
                mn %= MOD;
                dp[i][j] += mn*dp[i-1][k];
                dp[i][j] %= MOD;
            }
        }
    }
//    for (int i=0; i < n; i++) for (int j=0; j < 2; j++){
//        cout << i << " " << j << " " << dp[i][j] << endl;
//    }
    cout << (dp[n-1][0] + dp[n-1][1])%MOD;
    return 0;
}



Measured memory_bytes: 24556
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, C; cin >> N >> M >> C;
  int sum=0;
  int SUM=0;
  vector<int> B(M);
  for (int i=0;i<M;i++){
    cin >> B.at(i);
  }
  vector<vector<int>> A(N,vector<int>(M));
  for (int i=0;i<N;i++){
    for (int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  for (int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      sum+=A.at(i).at(j)*B.at(j);
    }
    if (sum+C>0){
      SUM++;
    }
    sum=0;
  }
  cout << SUM << endl;
}

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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int n, k;
int a[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    k = n - k;
    ForE(i, 1, n){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    int ans = 0;
    ForE(i, 1, k){
        ans += a[i];
    }
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 1792
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    string s;
    cin>>s;

    int start = 0;

    int end = n - 1;


    while(start < end){


        if(s[start] > s[end]){

            swap(s[start]  ,s[end]);
            count++;
            start++, end--;
        }

        else if(s[start] == 'R'){

            start++;
        }

        else{

            end--;
        }
    }

    cout<<count<<endl;


}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 3736
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;

#define rep(i, n) for(ll i = 0, l##_len = (n); i < l##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i <= ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i >= ll(b); --i)
#define loop while(true)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    int N;
    cin >> N;
    int a;
    int count = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a;
        if ((i % 2 == 0) && a % 2) ++count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<math.h>

double gcd(double []);//最大公約数
void lcm(double []);//最小公倍数

int main(void)
{
	double number[3];

	while(scanf("%lf %lf",&number[0],&number[1]) != EOF){
	lcm(number);
	}
   return 0;
}


double gcd(double number[])
{
	double i,a;
   
	if(number[0] < number[1]){
		number[2] = number[0];
		number[0] = number[1];
		number[1] = number[2];
   	}
	while(fmod(number[0],number[1])!=0){
		number[0] = fmod(number[0],number[1]);
		number[2] = number[0];//並び替え//
		number[0] = number[1];
		number[1] = number[2];
	}
	printf("%.0f ",number[1]);
	return number[1];
}

void lcm(double number[])
{
	double a;
	a=number[0] * number[1];
	a/=gcd(number);
	printf("%.0f\n", a);
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

struct uf{
  private:
    vi par, rank, size;
  public:
    uf(i64 n){ init(n); }
    void init(i64 n){
      par.resize(n);
      rank.resize(n,0);
      size.resize(n,1);
      rep(i,n) par[i] = i;
    }
    i64 root(i64 x){
      if(par[x] == x) return x;
      return par[x] = root(par[x]);
    }
    bool same(i64 x, i64 y){ return root(x) == root(y); }
    void unite(i64 x, i64 y){
      x = root(x), y = root(y);
      if(x==y) return;
      if(rank[x]==rank[y]) rank[x]++;
      if(rank[x]<rank[y]) swap(x,y);
      par[y] = x;
      size[x] += size[y];
    }
    i64 num(i64 x){ return size[root(x)]; }
};

void Main()
{
  i64 a,b,c;
  cin >> a >> b >> c;
  if(c-a-b<=0){
    cout << "No" << endl;
    return;
  }
  if(4*a*b<(c-a-b)*(c-a-b))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:2
*Problem:Antennas on Tree
*Date:2018-2-7
*Algorithm:Teacher's dfs (Reading Comperhension)
*Stats:Unknown*/

bool debug=false;

vector<int> nei[100005];
int n,d[100005],deg[100005];

template<typename T> ostream& operator<<(ostream& o,vector<T> vec){
	o<<"{";
	for(int i=0;i<vec.size();i++){
		o<<vec[i]<<" ";
	}
	o<<"}";
	return o;
}

void dfs(int a,int p){
	for(int i=0;i<nei[a].size();i++){
		if(nei[a][i]==p) continue;
		dfs(nei[a][i],a);
	}
	vector<int> T;
	int s=0;
	for(int i=0;i<nei[a].size();i++){
		int x=nei[a][i];
		if(x==p) continue;
		T.push_back(d[x]);
		s+=d[x];
	}
	if(!p){
		int c=0;
		for(int i=0;i<T.size();i++){
			if(!T[i]){
				c++;
			}
		}
		d[a]=s+max(c-1,0);
	}else{
		int c=0;
		for(int i=0;i<T.size();i++){
			if(!T[i]){
				c++;
			}
		}
		d[a]=s+max(c-1,0);
	}
	
	if(debug)cout<<"dfs end:a="<<a<<"d[a]="<<d[a]<<"s="<<s<<"t="<<T<<endl;
}

int main(int argc,char* argv[]){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		int a,b;
		cin>>a>>b;
		a++;b++;
		nei[a].push_back(b);
		nei[b].push_back(a);
		deg[a]++;deg[b]++;
	}
	int mx=0,root=0;
	for(int i=1;i<=n;i++){
		if(deg[i]>mx){
			mx=deg[i];
			root=i;
		}
	}
	
	if(mx<=2){
		cout<<1;
		return 0;
	}
	dfs(root,0);
	cout<<d[root];
	return 0;
}



Measured memory_bytes: 14848
use std::io::*;
use std::str::FromStr;

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: i64 = read();
    let a: i64 = read();
    let b: i64 = read();
    let mut ans = 0;
    ans += (n / (a + b)) * a;
    if n % (a + b) > a {
        ans += a
    } else {
        ans += n % (a + b)
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define PI 3.14159265359
#define PRINT(V) for (auto v : (V)) cout << v << " "
const long long INF = 1LL << 60;
using namespace std;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  double a, b, h,m;
  cin >> a >> b >> h >> m;
  double a1 = 2.0*PI/720.0;
  double a2 = 2.0*PI/60.0;
  cout << setprecision(15) <<double(sqrt(a*a + b*b -2*a*b*cos(m*a2-(60.0*h+m)*a1))) << endl;
return 0;
}

Measured memory_bytes: 4136
n = gets.chomp.to_i
s = gets.chomp

left = ""
right = ""

left_count = 0
s.each_char do |c|
  if c == "("
    left_count += 1
  else # ")"
    if left_count <= 0
      left += "("
    else
      left_count -= 1
    end
  end
end

if left_count > 0
  right = ")" * left_count
end

puts left + s + right


Measured memory_bytes: 14156
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int cnt1 = 0;
    int cnt2 = 0;

    for (int i = 0; i < s.size(); i++) {
        if (i%2==0) {
            if (s[i] != '0')cnt1++;
        }
        else {
            if (s[i] != '1')cnt1++;
        }
    }

    cnt2 = s.size() - cnt1;
    if (cnt1 < cnt2) {
        cout << cnt1<<endl;
    }
    else {
        cout << cnt2 << endl;
    }
    return 0;
}



Measured memory_bytes: 3728
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s;
    string t;
    cin >> s;
    cin >> t;
    int slen = s.length();
    t.erase(slen);
    if(s == t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int n = sz(s);
  vector<char> ans;
  rep(i,n){
    if(s[i] == '0') ans.push_back('0');
    if(s[i] == '1') ans.push_back('1');
    if(s[i] == 'B'){
      if(sz(ans)>0)ans.pop_back();
    }

  }
  for(auto e: ans)cout<<e;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans=[]
i=0
while i<n-1:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
if len(ans) >= 2:
    print(ans[0]*ans[1])    
else:
    print(0)

Measured memory_bytes: 14252
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import numpy as np


def main():
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))
    H = np.array(H)

    cost = np.array([100000] * N)
    cost[0] = 0
    for i in range(1, N):
        cost[i] = min(
            cost[max(i - K, 0): i] + abs(H[i] - H[max(i - K, 0): i]))
        # print(i, cost[i])
    print(cost[N - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 22904
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const double PI=3.1415926535897932;
using namespace std;
typedef long long ll;

int main(void){
    ll n;
    cin>>n;
    string s;
    ll ac=0,wa=0,tle=0,re=0;
    rep(i,n){
        cin>>s;
        if(s=="AC")ac++;
        else if(s=="WA")wa++;
        else if(s=="TLE")tle++;
        else if(s=="RE")re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
// typedef vector<int,vector<int>> vvec;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
// inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
// inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define here  cout<<"Here"<<endl;


//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,K;cin>>N>>K;
  N=N%K;
  N=min(N,abs(N-K));
  print(N);
  
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func min(nums []float64) (float64, int) {
	res := nums[0]
	if res < 0 {
		res = 1000000
	}
	id := 0
	for i := 0; i < len(nums); i++ {
		if res > nums[i] && nums[i] >= 0.0 {
			res = nums[i]
			id = i
		}
	}
	return float64(res), id
}

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}

	for {
		nokori := 0
		for i := 0; i < n; i++ {
			if v[i] > 0 {
				nokori++
			}
		}
		if nokori == 1 {
			break
		}
		min1, id := min(v)
		v[id] = -1.0
		min2, id := min(v)
		v[id] = (min1 + min2) / 2
	}
	for i := 0; i < n; i++ {
		if v[i] > 0 {
			fmt.Println(v[i])
		}
	}
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int a = cin.nextInt();
			int b = cin.nextInt();
			int c = cin.nextInt();

			int ans = (a - b) - ((a - b) / c) * c;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

int main() {
	int n;
	scanf("%d", &n);
	unsigned long long ans = 1;
	const unsigned long long limit = 1e18;
	std::vector<unsigned long long> inputs;
	for (int i = 0; i < n; ++i) {
		unsigned long long tmp;
		scanf("%llu", &tmp);
		if (tmp == 0) {
			printf("0\n");
			return 0;
		}
		inputs.push_back(tmp);
	}
	std::sort(inputs.begin(), inputs.end());
	for (int i = 0; i < n; ++i) {
		//ans *= inputs[i];
		if (ans > limit/inputs[i]) {
			printf("-1\n");
			return 0;
		}
		else 
			ans *= inputs[i];
	}

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

	return 0;
}


Measured memory_bytes: 4320
#include<iostream>
#include<cstdio>

using namespace std;

int main(void){
  char grid[3][3];
  
  while(true){
    for(int i=0;i<3;i++)
      for(int j=0;j<3;j++)
	if(scanf(" %c",&grid[i][j])==EOF)return 0;
    
    if(grid[0][0]=='o'&&grid[1][1]=='o'&&grid[2][2]=='o'){
      cout << 'o' << endl;
      continue;
    }
    if(grid[0][2]=='o' && grid[1][1]=='o' && grid[2][0]=='o'){
      cout << 'o' << endl;
      continue;
    }
    if(grid[0][0]=='x'&&grid[1][1]=='x'&&grid[2][2]=='x'){
      cout << 'x' << endl;
      continue;
    }
    if(grid[0][2]=='x' && grid[1][1]=='x' && grid[2][0]=='x'){
      cout << 'x' << endl;
      continue;
    }

    int fg=0;
    for(int i=0;i<3;i++){
      if(grid[i][0]=='o'&&grid[i][1]=='o'&&grid[i][2]=='o'){
	cout << "o" << endl;
	fg=1;
	break;
      }
      else if(grid[i][0]=='x'&&grid[i][1]=='x'&&grid[i][2]=='x'){
	cout << "x" << endl;
	fg=1;
	break;
      }
      else if(grid[0][i]=='o'&&grid[1][i]=='o'&&grid[2][i]=='o'){
	cout << "o" << endl;
	fg=1;
	break;
      }
      else if(grid[0][i]=='x'&&grid[1][i]=='x'&&grid[2][i]=='x'){
	cout << "x" << endl;
	fg=1;
	break;
      }

    }
    if(!fg)cout << 'd' << endl;
  }
  return 0;
}

Measured memory_bytes: 0
s = input() #sys.stdin.readlineは最後が改行
t = input() #sys.stdin.readlineは最後が改行

n = len(s)

from collections import defaultdict
ds = defaultdict(list)
dt = defaultdict(list)

for i in range(n):
    if s[i] in ds.keys():
        if ds[s[i]] != t[i]:
            print('No')
            exit()
    else:
        ds[s[i]] = t[i]

for i in range(n):
    if t[i] in dt.keys():
        if dt[t[i]] != s[i]:
            print('No')
            exit()
    else:
        dt[t[i]] = s[i]

print('Yes')


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const long long MOD = 998244353;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> D)
{
    if (D[0] != 0)
    {
        cout << 0 << endl;
        return;
    }

    for (int i = 1; i < N; i++)
    {
        if(D[i] == 0){
            cout << 0 << endl;
            return;
        }
    }
    
    map<int, int> tree;

    for (int i = 0; i < N; i++)
    {
        tree[D[i]]++;
    }
    ll ans = 1;

    for (auto &&i : tree)
    {
        if (i.first >= 2)
        {
            if (tree[i.first - 1] == 0)
            {
                cout << 0 << endl;
                return;
            }
            ans = mulMod(ans, powMod(tree[i.first - 1], i.second));
        }
    }
    cout << ans << endl;
}

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


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

string s;
multiset<int> edge[200005];
int memo[200005][2];

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m>>s;
	int a,b;
	for (int i = 0; i < m; ++i)
	{
		cin>>a>>b;
		--a;--b;
		if (edge[a].count(b)>0)
		{
			continue;
		}
		edge[a].insert(b);
		++memo[a][s[b]-'A'];
		if (a!=b)
		{
			edge[b].insert(a);
			++memo[b][s[a]-'A'];
		}
	}
	multiset<int> que;
	for (int i = 0; i < n; ++i)
	{
		if (memo[i][0]==0||memo[i][1]==0)
		{
			que.insert(i);
			while (que.size()>0)
			{
				int now=*que.begin();
				for (auto itr = edge[now].begin(); itr != edge[now].end();)
				{
					int v=*itr;
					itr=edge[now].erase(itr);
					--memo[now][s[v]-'A'];
					edge[v].erase(now);
					--memo[v][s[now]-'A'];
					if (memo[v][0]==0||memo[v][1]==0)
					{
						que.insert(v);
					}
				}
				que.erase(now);
			}
		}
	}
	int f=0;
	for (int i = 0; i < n; ++i)
	{
		if (edge[i].size()>0)
		{
			f=1;
		}
	}
	if (f)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 29188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int a, b; scanf("%d%d", &a, &b);
	int ans = -1;
	REP(i, 1000000){
		if(i * 108 / 100 - i == a && i * 110 / 100 - i == b) {
			ans = i;
			break;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        
        int N = sc.nextInt();
        String S = sc.next();
        
        int def = 0;
        int cost = 0;
        int min_cost = 0;
        
        for(int i=0; i<N; i++){
            String str = String.valueOf(S.charAt(i));
 
            if(str.equals("W")) {
            	cost++;
            }
            
            if(str.equals("E")){
                cost--;
                def++;
            }
 
            if(cost < min_cost) {
            	min_cost = cost;
            }
 
        }
 
        System.out.println(def + min_cost);
        
	}
 
}


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

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> P(N);
    for (int i = 0; i < Q; i++) {
        int a;
        cin >> a;
        a--;
        P[a]++;
    }

    for (int i = 0; i < N; i++) {
        if (P[i] + K - Q > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int n;
vector<vector<int>> alpha(51, vector<int>(26, 0));

int main(void){
    
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        string s; cin >> s;
        for(int j = 0; j < s.size(); ++j) ++alpha[i][s[j] - 'a'];
    }
    
    vector<int> v(26, INT_MAX);
    for(int i = 0; i < n; ++i) for(int j = 0; j < 26; ++j) v[j] = min(v[j], alpha[i][j]);
    
    string s;
    for(int i = 0; i < 26; ++i) for(int j = 0; j < v[i]; ++j) s.push_back('a' + i);
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
($n,$a,$b,$c)=split$",<>;@l=<>;$y=1e9;for$p(0..4**$n){@s=0 x4;$k=-30;$s[$p%4]+=$l[$_],$k+=$p%4&&10,$p/=4for 0..$n;$x=$k+abs($s[1]-$a)+abs($s[2]-$b)+abs($s[3]-$c),$x<$y&&($y=$x),if$s[1]*$s[2]*$s[3]}print$y

Measured memory_bytes: 384
import math

a, b, x = [int(n) for n in input().split()]
v = a**2 * b /2
#print(v, x)

if v == x:
    theta = math.atan(b/a)

elif v > x:
    theta = math.atan(a*(b**2)/(2*x))
elif v < x:
    theta = math.atan(2/a*(b-x/a**2))
    
print(math.degrees(theta))


Measured memory_bytes: 9308
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int main(){
    vector<char> s(19);
    rep(i,19){
        cin >> s[i];
        if(s[i]==',') s[i]=' ';
    }
    rep(i,19) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

vector<ll> ans;
ll dfs(vector<ll> adj[], ll x, ll visited[], ll n)
{
    visited[x] = 1;
    ll child = 1;
    for(ll i=0;i<adj[x].size();i++)
    {
        if(visited[adj[x][i]]==0)
        {
            ll ch = dfs(adj,adj[x][i],visited,n);
            ans.push_back(ch*(n-ch));
            child += ch;
        }
    }
    return child;
}
int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll dp[n] = {};
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i] = min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
        // cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 5124
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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() {
  string S, T;
  cin >> S >> T;
  cout << T << S << endl;
  return 0;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var A = int.Parse(ss[0]);
            var B = int.Parse(ss[1]);
            var C = int.Parse(ss[2]);
            var D = int.Parse(ss[3]);

            var L = A + B;
            var R = C + D;

            if (L == R)
                Console.WriteLine("Balanced");
            else if (L > R)
                Console.WriteLine("Left");
            else
                Console.WriteLine("Right");
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int ans=0;

		if(A==B&&B==C){
			if(A%2==0&&B%2==0&&C%2==0){
				ans = -1;
			}
		}else{

			while(A%2==0&&B%2==0&&C%2==0){
				int a = A;
				int b = B;
				int c = C;
				A=(b+c)/2;
				B=(a+c)/2;
				C=(a+b)/2;
				ans++;
			}


		}

		System.out.println(ans);


	}

}


Measured memory_bytes: 24148
#include <iostream>

using namespace std;

int a[200000];
int b[200000];

int main(){
    int N,n;
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=N-1;i>=0;i--){
        n = i+1;
        b[i] = a[i];
        for(int j=2;j*n<=N;j++){
            b[i] ^= b[j*n-1];
        }
    }
    n = 0;
    for(int i=0;i<N;i++) n += b[i];
    cout << n << endl;
    if(n != 0){
        bool f = false;
        for(int i=0;i<N;i++){
            if(b[i]){
                if(f){
                    cout << " ";
                }
                cout << i+1;
                f = true;
            }
        }
        cout << endl;
    }
    return 0;
}

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


using namespace std;
#define ll long long

int main()
{
	
		string s1,s2;
		cin>>s1>>s2;
		ll l1=s1.length();
		ll l2=s2.length();
		ll dp[l1+1][l2+1];
		for(int i=0;i<=l1;i++)
		{
			for(int j=0;j<=l2;j++)
			{
				if(i==0||j==0)
					dp[i][j]=0;
				else if(s1[i-1]==s2[j-1])
					dp[i][j]=dp[i-1][j-1]+1;
				else
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
		ll index=dp[l1][l2];
		//cout<<index<<endl;
		ll i=l1;
		ll j=l2;
		char lcs[index+1];
		lcs[index]='\0';
		while(i>0 && j>0)
		{
			if(s1[i-1]==s2[j-1])
			{
				lcs[index-1]=s2[j-1];
				//cout<<s1[i-1]<<s2[j-1]<<endl;
				i--;
				j--;
				index--;
			}
			else if(dp[i-1][j]>dp[i][j-1])
				i--;
			else
				j--;

		}
	
			cout<<lcs<<endl;

	
}

Measured memory_bytes: 70656
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

void solve(int n, int m) {
  static char s[110000];
  static char t[110000];
  scanf("%s%s", s, t);

  int g = __gcd(n, m);
  for (int i = 0; i < g; i++) {
    if (s[(n / g) * i] != t[(m / g) * i]) {
      printf("-1\n");
      return;
    }
  }
  printf("%lld\n", (n * 1LL * m) / g);
}

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

  int n, m;

  while (scanf("%d%d", &n, &m) == 2) {
    solve(n, m);
  }

  return 0;
}


Measured memory_bytes: 384