akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)


int n;
int a[100];

int main() {
	cin >> n;
	int maxl = -INF;
	int minl = INF;
	int maxpos = 0, minpos = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (maxl < a[i]) {
			maxl = max(maxl, a[i]);
			maxpos = i;
		}
		if (minl > a[i]) {
			minl = min(minl, a[i]);
			minpos = i;
		}
	}
	cout << 2 * n - 1 << endl;
	for (int i = 0; i < n; i++) {
		if (abs(maxl) >= abs(minl)) {
			cout << maxpos + 1 << " " << i + 1 << endl;
		}
		else {
			cout << minpos + 1 << " " << i + 1 << endl;
		}
	}
	if (abs(maxl) >= abs(minl)) {
		for (int i = 1; i < n; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		for (int i = n - 1; i >= 1; i--) {
			cout << i + 1 << " " << i << endl;
		}
	}
	//system("pause");
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


r = I()
print(r ** 2)


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

int main(){
	int n,a,b,c,x;
	while(cin>>n>>a>>b>>c>>x){
		if(n==0&&a==0&&b==0&&c==0&&x==0)break;
		int nr[105];
		for(int i=0;i<n;i++){cin>>nr[i];}
		
		int atar=0;
		int count=0;
		
		while(count<=10001){
			if(x==nr[atar])atar++;
			x=(a*x+b)%c;
			
			if(atar==n)break;
			count++;
			}
			
			if(count>=10001)cout<<"-1"<<endl;
			else cout<<count<<endl;
		}
		return 0;
	}

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

int main(){
  int n;
  cin >> n;
  vector<long long> mon(n+1);
  vector<long long> bra(n);
  for(int i = 0; i < n+1; i++){
    cin >> mon.at(i);
  }
  for (int i = 0; i < n; i++){
    cin >> bra.at(i);
  }
  long long ans = min(bra.at(n-1), mon.at(n));
  long long left = max(0LL, bra.at(n-1) - mon.at(n));
  long long beat;
  for(int i = n-1; i >= 1; i--){
    beat = min(mon.at(i), left+bra.at(i-1));
    ans += beat;
    left = bra.at(i-1) - max(0LL, beat - left);
  }
  ans += min(left, mon.at(0));
  cout << ans << endl;
}
    

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

//ライブラリ始まり (簡潔ver)

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//ライブラリ終わり

//メイン処理
int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  if (X / D > K) {
    cout << X - D * K << endl;
  }
  else {
    if ((X / D) % 2 == K % 2) {
      cout << X % D << endl;
    }
    else {
      cout << D - X % D << endl;
    }
  }
}
    
      

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n,a,b;
    cin>>n>>a>>b;

    int ans=(n/(a+b))*a;

    int x=(n%(a+b));

    ans+=min(x,a);

    cout<<ans;






    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

string dp[20000];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int cost[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    rep(i, m)cin >> a[i];

    rep(i, n + 100)dp[i] = "-";
    dp[0] = "";

    rep(i, n){
        if(dp[i] == "-")continue;
        for(int now : a){
            if(dp[i + cost[now]].size() == dp[i].size() + 1){
                if(dp[i + cost[now]] < dp[i] + to_string(now))dp[i + cost[now]] = dp[i] + to_string(now);
            }
            else if(dp[i + cost[now]].size() < dp[i].size() + 1)dp[i + cost[now]] = dp[i] + to_string(now);
        }
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 27392
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int x; cin>>x;
    int count = x/100;

    if(100*count<=x&&x<=105*count)cout<<1<<endl;
    else cout<<0<<endl;
}

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

int main() {
    cout << fixed << setprecision(15);
    const long double pi = 3.141592653589793;

	int a, b, h ,m;
    cin >> a >> b >> h >> m;
    double hour = (double)h;
    double minute = (double)m;
    
    //長針と短針の0から進んだ角度
    double ar = 2 * pi * ((hour + minute / 60) / 12);
    //長針も分単位で進む
    double br = 2 * pi * (minute / 60);

    //長針と短針の角度の差
    double dif = ar - br;

    //cos(-θ) = cos(θ)だから場合分けは不要

    // if (ar >= br) {
    //     dif = ar - br;
    // } else {
    //     dif = br - ar;
    // }
    // if (dif > pi) {
    //     dif = 2 * pi - dif;
    // }

    double c = a * a + b * b - 2 * a * b * cos(dif);
    cout << sqrt(c) << endl;
}

Measured memory_bytes: 4140
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double

int main()
{
    string s;
    cin>>s;
    map<char,ll> m;
    for(ll i=0;i<4;i++)
    {
        m[s[i]]++;
    }
    map<char,ll>::iterator itr;
    if(m.size()!=2)
    {
        cout<<"No"<<endl;
        return 0;
    }
    ll flag=0;
    for(itr=m.begin();itr!=m.end();++itr)
    {
        if(itr->second!=2)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 256
// ABC173A2
//#include "pch.h"
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
	int n;
	cin >> n;
	int pay = 1000; // 初めに1000円持っていく
	while (pay < n) { 
		pay += 1000; // 足りなかったら、あと1000円持っていく
	}
	cout << pay-n << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define WF(d,v) FOR(k,v){ FOR(i,v){ FOR(j,v) d[i][j]=min(d[i][j],d[[i][k]+d[k][j]) } }
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;
 
 
int main(){
  cin.tie(0), ios::sync_with_stdio(false);

  int n,h,w,sum=0;
  cin >> n >> h >> w;
  FOR(i,n){
    int a,b;
    cin >>a>>b;
    if(a>=h && b >= w) sum++;
  }
  cout <<sum fin;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

int main() {

    int x, a;
    cin >> x >> a;

    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  ll n;
  cin >> n;
  vector<ll > a(5,0);
  vector<ll > t(5,0);
  ll tmpmin;
  REP(i, 5){
    cin >> a[i];
  }
  if(n % a[0] == 0){
    t[0] = n/a[0];
  }else{
    t[0] = n/a[0] + 1;
  }
  tmpmin = a[0];
  for(ll i = 1; i < 5 ; i++){
    tmpmin = a[i];
    a[i] = min(a[i - 1],tmpmin);
  }
  for(ll i = 1; i < 5 ; i++){
    if(a[i] >= a[i - 1]){
      t[i] = t[i - 1];
    }else{
      if(n % a[i] == 0){
	t[i] = n/a[i];
      }else{
	t[i] = n/a[i] + 1;
      }
    }
  }
  // REP(i,5){cout << t[i] << endl;}
  cout << t[4]  + 4<< endl;
  

}


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

using namespace std;

int main(void) {

	string s;

	cin >> s;

	for (int k = 0; k < s.size(); k++) {
		if (s.at(k) == ',')s.at(k) = ' ';
	}
	cout << s << "\n";


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int x,a,b;
   cin>>x>>a>>b;
   if(a>=b)
   {
       cout<<"delicious";
   }
   else if(a+x<b)
   {
       cout<<"dangerous";
   }
   else
    cout<<"safe";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int a[n+1];
    int f[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        f[i]=1<<30;
    }
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
        for(int j=1;j<=k && i-j>=1;j++)
        {
            f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
        }
    }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int n, k;

int arr[100005][3], dp[100005][3];

int recur()
{

    //base case
    dp[n-1][0]=arr[n-1][0];
    dp[n-1][1]=arr[n-1][1];
    dp[n-1][2]=arr[n-1][2];

    for(int i=n-2;i>=0;i--){
        for(int j=0;j<3;j++){
            if(j==0){
                dp[i][j]+=max(dp[i+1][1],dp[i+1][2]);
            }else if(j==1){
                dp[i][j]+=max(dp[i+1][0],dp[i+1][2]);
            }else if(j==2){
                dp[i][j]+=max(dp[i+1][0],dp[i+1][1]);
            }
        }
    }

    return max(dp[0][0],max(dp[0][1],dp[0][2]));


}

signed main()
{
    // system("clear");
    fast
    cin >>n;
    memset(dp, -1, sizeof dp);

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> arr[i][j];
            dp[i][j]=arr[i][j];
        }
    }

    cout << recur();

  

    return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long

const double pi = acos(-1);

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

    int r;
    cin >> r;
    cout << fixed << setprecision(10) << 2 * r * pi << '\n';
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=100005,M=405;

bitset<M>v[M];
bool dead[M];
int n,m,ans;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;i++){
		scanf("%d%d",&x,&y);
		if(dead[x]||dead[y]||(v[x]&v[y]).any()){dead[x]=dead[y]=true;continue;}
		v[x]=v[y]=v[x]|v[y];
		if(v[x][x])dead[x]=true;if(v[y][y])dead[y]=true;
		v[x][y]=1,v[y][x]=1;
	}
	for(int x=1;x<=n;x++)if(!dead[x])for(int y=x+1;y<=n;y++)if(!dead[y])
		if(!v[x][y]&&!v[y][x]&&!(v[x]&v[y]).any())ans++;
	printf("%d\n",ans);
	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());

    int roop = 0; 
    ll sum = 0;
    rep(i,N){
        if(i == 0){
            sum += A[i];
            roop++;
        }else{
            sum += A[i];
            roop++;
            if(roop != N-1){
                sum += A[i];
                roop++;
            }
        }
        if(roop == N-1) break;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

	ll int tc=1;
	while(tc--)
	{
		ll int n;
		cin>>n;
		vector<ll int> v;
	   map<ll int,ll int> m;
		ll int x;
		ll int s=0;
		//ll int flag=0;
		for(ll int i=0;i<n;i++)
		{
			cin>>x;
			s+=x;
			m[x]++;
			v.push_back(x);

		}
		int q;
		cin>>q;
		while(q--)
		{
			ll int a,b;
			cin>>a>>b;
			
			s+=b*m[a]-a*m[a];
			cout<<s<<endl;
			m[b]+=m[a];
			m.erase(a);
		}

	}
}




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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()
#define PI acos(-1)

// code starts
#define MOD1 998244353
#define MOD2 469762049

ll pow(ll n, ll k, ll mod)
{
  ll num = n;
  ll ans = 1;
  ll left = k;
  while(left != 0)
  {
    if(left%2 == 1) ans = ans*num%mod;
    left /= 2;
    num = num*num%mod;
  }
  return ans;
}

ll mod_inv(ll n, ll mod)
{
  return pow(n, mod-2, mod);
}

vector<ll> ntt(vector<ll> f, ll n, ll mod)
{
  if(n == 1)return f;
  else
  {
    vector<ll> f0(n/2);
    vector<ll> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i] = f[2*i];
      f1[i] = f[2*i+1];
    }
    f0 = ntt(f0, n/2, mod);
    f1 = ntt(f1, n/2, mod);
    ll zeta = pow((ll)3, (mod-1)/n, mod);//prepare num;
    ll pow_zeta = 1;
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)]+pow_zeta*f1[i%(n/2)])%mod;
      pow_zeta = pow_zeta*zeta%mod;
    }
    return f;
  }
}

vector<ll> inv_ntt(vector<ll> f, ll n, ll mod, ll nf)
{
  if(n == 1)return f;
  else
  {
    vector<ll> f0(n/2);
    vector<ll> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i] = f[2*i];
      f1[i] = f[2*i+1];
    }
    f0 = inv_ntt(f0, n/2, mod, nf);
    f1 = inv_ntt(f1, n/2, mod, nf);
    ll zeta = mod_inv(pow((ll)3, (mod-1)/n, mod), mod);
    ll pow_zeta = 1;
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)]+pow_zeta*f1[i%(n/2)])%mod;
      pow_zeta = pow_zeta*zeta%mod;
    }
    if(n == nf)
    {
      rep(i,n) f[i] = f[i]*mod_inv(n, mod)%mod;
    }
    return f;
  }
}

vector<ll> NTT(vector<ll> a, vector<ll> b) // a,b: count array
{
  int n = a.size();
  vector<int> ka(n+1, 0);
  vector<int> kb(n+1, 0);
  int i;
  rep(i,n)
  {
    ka[i+1] = a[i];
    kb[i+1] = b[i]; 
  }
  ll n2 = 1;
  while(n2 <= n*2) n2 *= 2;
  vector<ll> g(n2, 0);
  vector<ll> h(n2, 0);
  rep(i,n+1)
  {
    g[i] = ka[i];
    h[i] = kb[i];
  }
  vector<ll> g1(n2, 0);
  vector<ll> h1(n2, 0);
  vector<ll> g2(n2, 0);
  vector<ll> h2(n2, 0);
  g1 = ntt(g, n2, MOD1);
  h1 = ntt(h, n2, MOD1);
  g2 = ntt(g, n2, MOD2);
  h2 = ntt(h, n2, MOD2);
  vector<ll> gh1(n2);
  rep(i,n2) gh1[i] = g1[i]*h1[i]%MOD1;
  vector<ll> gh2(n2);
  rep(i,n2) gh2[i] = g2[i]*h2[i]%MOD2;
  vector<ll> ans1(n2, 0);
  ans1 = inv_ntt(gh1, n2, MOD1, n2);
  vector<ll> ans2(n2, 0);
  ans2 = inv_ntt(gh2, n2, MOD2, n2);
  vector<ll> ans(n*2+1, 0);
  rep(i,n*2+1)
  {
    ll k = (ans2[i]-ans1[i])+(ll)MOD1*MOD2;
    k %= MOD2;
    k = k*mod_inv(MOD1%MOD2, MOD2)%MOD2;
    ans[i] = (k*MOD1+ans1[i])%((ll)MOD1*MOD2);
  }
  return ans;
}

int main()
{
  int n;
  ll m;
  cin >> n >> m;
  vector<int> a(n);
  int i;
  rep(i,n) cin >> a[i];
  int maxs = 0;
  rep(i,n) maxs = max(maxs,a[i]);
  vector<ll> count(maxs,0);
  rep(i,n)
  {
    count[a[i]-1]++;
  }
  vector<ll> vals(maxs*2+1, 0);
  vals = NTT(count,count);
  ll times = 0;
  ll ans = 0;
  ll now = maxs*2;
  while(times < m)
  {
    ll take = min(m-times, (ll)vals[now]);
    times += take;
    ans += take*now;
    now--;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 37164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
 * 0007:Debt Hellの解答
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** \1000未満の繰り上げ計算用 */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000);

    /**
     * n 週間後の借金の残高を出力する。<br>
     * ※n は 100 以下とする。
     * 
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        System.out.println(calcDebt(weeks));
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     * @throws IOException 標準入力読取り失敗時
     */
    private static int getWeeks() throws IOException {
        
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
        
        return Integer.parseInt(bufferedReader.readLine());
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     * @return n週間後の借金額
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }

        return finalDebt;
    }

}

Measured memory_bytes: 16980
import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String args[]) {
        int n = 0;
        int[] arr = null;
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            arr = new int[n];
            for (int i=0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
        }
        int[] dp = new int[n];
        dp[1] = Math.abs(arr[1] - arr[0]);
        for(int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 1] + Math.abs(arr[i] - arr[i -1])
                            , dp[i - 2] + Math.abs(arr[i] - arr[i - 2]));
         
        }
        
        System.out.println(dp[n - 1]);
    }
}

Measured memory_bytes: 50948
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> s(m), c(m);
    REP(i, m){
        cin >> s[i] >> c[i];
        s[i]--;
    }
    ll ans = INF;
    for(ll i = 0; i <= 999; i++){
        string ss = to_string(i);
        if(ss.size() != n) continue;
        bool ok = true;
        REP(j, m){
            if(ss[s[j]] != '0' + c[j]){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, i);
        }
    }
    cout << ((ans != INF)? ans : -1) << endl;
}

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

int main(){
  int n;
  while(cin >> n, n != 0){
    vector<int> v(n);
    for(int i = 0; i < n; i++)cin >> v[i];

    int ans = 1e9;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        ans = min(ans, abs(v[i] - v[j]));
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3032
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll X;
  cin >> X;
  ll ans = 0;
  if (X >= 1800) {
    ans = 1;
  } else if (X >= 1600) {
    ans = 2;
  } else if (X >= 1400) {
    ans = 3;
  } else if (X >= 1200) {
    ans = 4;
  } else if (X >= 1000) {
    ans = 5;
  } else if (X >= 800) {
    ans = 6;
  } else if (X >= 600) {
    ans = 7;
  } else if (X >= 400) {
    ans = 8;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = ll(1e9 + 7);
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long re=1;
void ans(long long s){
	for(int i=0;i<s;++i)re*=2;
	re--;
}
int main(){
	long long a,s=0;
	cin>>a;
	while(a>=1){
		a=a/2;
		s++;
	}
	ans(s);
	cout<<re<<endl;
	return 0;
}

Measured memory_bytes: 256
//B-FROG2_dp
//bottom up 2D
#include<bits/stdc++.h>
#include<climits>
using namespace std;


int mincost(vector<int>h,int n,int k)
{

    vector<int>dp(n+1);

    //basecase
    dp[1]=0;

      for(int i=2;i<=n;i++)
   {    

       dp[i]=INT_MAX;
       for(int j=i-1; j>=1 && j>=(i-k);j--)
       {   
            dp[i]=min(dp[i],(abs(h[i]-h[j])+dp[j]));
       }
   }
   return dp[n];
}
 

int main()
{
    int n,k,p;
    cin>>n>>k;
    vector<int>height(n+1);
    for(int i=1;i<=n;i++)
    {
    cin>>height[i];
    }
    cout<<mincost(height,n,k);
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<pair<int,int> > c(m);
  set<int> S;
  set<int> C;
  rep(i,m){
    cin>>c[i].first>>c[i].second;
  }
  vector<int> ans(100,-1);
  sort(all(c));
  rep(i,m){
    if(S.find(c[i].first)==S.end()){
      ans[c[i].first]=c[i].second;
    }
    if(S.find(c[i].first)!=S.end()){
      if(C.find(c[i].second)==C.end()){
        cout<<-1<<'\n';
        return(0);
      }
    }
    S.insert(c[i].first);
    C.insert(c[i].second);
    
  }
  bool flag=true;
  /*  rep(i,m){
    if(c[i].second==0){
      if(flag2>c[i].first){
        flag2=c[i].first;
      }
    }
    else{
      chmin(flag,c[i].first);
    }
  }
  if(flag2<flag){
    cout<<-1<<'\n';
    return(0);
  }*/
  int si=ans.size();
  REP(i,1,n+1){
    if(ans[i]==0 && i!=n && flag){
      cout<<-1<<'\n';
      return(0);
    }
    if(ans[i]==-1){
      if(!flag || i==n){
        cout<<0;
      }
      else{
        cout<<1;
        flag=false;
      }
    }
    else{
      cout<<ans[i];
      flag=false;
    }
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl; 

//globals
ll const mod = 1e9+7;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 

// CODE STARTS HERE
bool odd(int n){
  int count = 0;
  while(n){
    count++;
    n/=10;
  }
  return count%2 == 1;
}
int main() {
  IOS;

  int n;cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    ans += odd(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using ll = long long;
using namespace std;
int main() {
  	ll n, tmp;
  	vector<ll> v;
  	cin >> n;
  	REP(i, n){
      	cin >> tmp;
      	v.push_back(tmp);
    }
  	ll ct=0;
  	REP(i, n-2){
      	if((v[i] < v[i+1] && v[i+1] < v[i+2]) ||
           (v[i] > v[i+1] && v[i+1] > v[i+2])){
          	ct++;
        }
    }
    
    cout << ct << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   long i,n,j,ans;

   scanf("%ld",&n);
   ans=0;
   for (i=1;i<=n;i++) {
      j=n/i;j=j*i;
      ans+=(i+j)*(j/i)/2;
   }
   printf("%ld\n",ans);
   return 0;
}


Measured memory_bytes: 1692
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx[]= {0,0,1,-1,-1,1,-1,1};
int fy[]= {1,-1,0,0,-1,1,1,-1};
int fx1[]={0,1,1,1,0,-1,-1,-1};
int fy1[]={1,1,0,-1,-1,-1,0,1};*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
 /*   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    cin>>a>>b;
    if((a*500)>=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 

Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map { it.toInt() }
    var (x3, y3, x4, y4) = listOf(0,0,0,0)
    val xDiff = x1 - x2
    val yDiff = y1 - y2
    x3 = x2 + yDiff
    y3 = y2 - xDiff
    x4 = x3 + xDiff
    y4 = y3 + yDiff
    println("%s %s %s %s".format(x3, y3, x4, y4))
}


Measured memory_bytes: 37940
#include<bits/stdc++.h>
using namespace std;
int N,M,Q;
int A[11];
int a[51],b[51],c[51],d[51];
int finalans=0;

void syori(){
  int ans=0;
  for(int i=0;i<Q;i++){
    if(A[b[i]]-A[a[i]]==c[i]){
      ans+=d[i];
    }
  }
  finalans=max(ans,finalans);
}

void tansaku(int count){
  if(count==N){
    syori();
  }else{
    for(int i=A[count];i<=M;i++){
      A[count+1]=i;
      tansaku(count+1);
    }
  }
}


int main(){
  A[0]=1;
  cin >> N >> M >> Q;

  for(int i=0;i<Q;i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  tansaku(0);
  cout << finalans;
}


Measured memory_bytes: 3648
//Divide the Problems

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int o = 0;

bool isMin(int d){
    return d>o;
}

int main (){
    int N, Ans=0;cin >> N;
    vector<int> d(N);
    rep(i,0,N)cin >> d[i];
    sort(range(d));
    cout << d[N/2]-d[N/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
s=[]
t=[]
check=[]
cnt=0
max=0
B=int(input())
s=[input() for i in range(B)]
R=int(input())
t=[input() for i in range(R)]
s.sort()
check=list(set(s))

for i in range(len(check)):
	for j in range(R):
		if check[i]==t[j]:
			cnt+=1
	if max<s.count(check[i])-cnt:
		max=s.count(check[i])-cnt
	cnt=0

print(max)


Measured memory_bytes: 3064
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("mmx,sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	vi a(n), ok(n, 1);
	for(int i = 0; i < n; ++i)  cin >> a[i];
	ok[k - 1] = 1;
	for(int i = k; i < n; ++i) if(a[i] <= a[i - k]) ok[i] = 0;
	for(int i = k; i < n; ++i) cout << (ok[i] ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 4768
import java.io.*;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] order =br.readLine().split(" ");
        int a = Integer.parseInt(order[0]);
        int b = Integer.parseInt(order[1]);
        int c = Integer.parseInt(order[2]);
        
        int n1=0,n2=0,n3=0;
        if(a<b){n1=b;n2=a;}else{n1=a;n2=b;}
        if(n1<c){n3=n1;n1=c;}else{n3=c;}
        if(n2<n3){System.out.println(n2+" "+n3+" "+n1);
        }else{System.out.println(n3+" "+n2+" "+n1);}
        
    }
    
}

Measured memory_bytes: 16892
#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
const ll inf = 1000000007;

int main() {
	int n;
	cin >> n;
	map<string, int> m;
	rep(i, n) {
		string a;
		cin >> a;
		m[a] += 1;
	}

	int max_c = 0;
	for (auto itr = m.begin(); itr != m.end(); itr++) {
		max_c = max(max_c, itr->second);
	}

	for (auto itr = m.begin(); itr != m.end(); itr++) {
		if (max_c== itr->second) {
			cout << itr->first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19160
from collections import deque

h, w = map(int, input().split())
s = []
for i in range(h):
    l = list(input())
    s.append(l)

q = deque()
dh = [1, 0, -1, 0]
dw = [0, 1, 0, -1]
max = 0
for i in range(h):
    for j in range(w):
        dist = [[-1 for m in range(w)] for n in range(h)]
        dist[i][j] = 0
        if s[i][j] == "#":
            continue
        
        q.append((i, j))
        while q:
            sh, sw = q.popleft()
            for k in range(4):
                ah = sh + dh[k]
                aw = sw + dw[k]
                
                if 0<=ah<h and 0<=aw<w:
                    if s[ah][aw] == "#":
                        continue

                    if dist[ah][aw] == -1:
                        q.append((ah, aw))
                        dist[ah][aw] = dist[sh][sw] + 1

                        if dist[ah][aw] > max:
                            max = dist[ah][aw]

print(max)

        


Measured memory_bytes: 3316
a, b, c, x, y = map(int, input().split())
if x>=y:
    print(min(a*x+b*y, 2*c*y+a*(x-y), 2*c*x))
else:
    print(min(a*x+b*y, 2*c*x+b*(y-x), 2*c*y))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[12];
  for(int i = 0;i < 12;i++) cin >> a[i];
  sort(a,a+12);
  if(a[0] == a[3] && a[4] == a[7] && a[8] == a[11]){
    cout << "yes" << endl;
  }
  else cout << "no" << endl;
  return 0;
}

Measured memory_bytes: 3032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int q = sc.nextInt();
		boolean hanten = false;
		StringBuilder sb = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();
		for (int i = 0; i < q; i++) {
			int t = sc.nextInt();
			if (t == 1) {
				hanten = !hanten;
			} else {
				int f = sc.nextInt();
				String c = sc.next();
				if (f == 1) {
					if (hanten) {
						sb2.append(c);
					} else {
						sb.append(c);
					}
				} else {
					if (hanten) {
						sb.append(c);
					} else {
						sb2.append(c);
					}
				}
			}
		}
		sb.reverse().append(s).append(sb2.toString());
		if (hanten) {
			sb.reverse();
		}
		System.out.println(sb.toString());
		sc.close();
	}
}


Measured memory_bytes: 119148
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
ll MOD = 1e9+7;
#define int ll

ll binpow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b%2)
			res = (res*a)%MOD;
		a = (a*a)%MOD;
		b>>=1;
	}
	return res;
}



vector<ll> fact(3e6+5, 1);
vector<ll> ifact(3e6+5, 1);

ll choose(ll a, ll b){
	if(b == 0 || a == b)
		return 1;
	if(b < 0 || b > a)
		return 0;
	return ((fact[a]*ifact[b])%MOD)*ifact[a-b]%MOD;
}
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	ll r1,r2,c2,c1; 
	cin>>r1>>c1>>r2>>c2;
	for(int i = 2; i < 2e6+100; i++){
		fact[i] = (fact[i-1]*i)%MOD;
		ifact[i] = binpow(fact[i], MOD-2);
	}
	ll tot = 0;
	for(int i = r1+1; i <= r2+1; i++){
		ll dist = c2 + i;
		tot = (tot + choose(dist, i)) % MOD;
	}	
	for(int i = r1+1; i <= r2+1; i++){
		ll dist = c1 -1+ i;
		tot = (((tot - choose(dist, i)) % MOD) + MOD)%  MOD ;
		
	}	
	cout<<tot;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define N 100100
#define M 1010

int n,now,ans;
int a[N];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=a[n+1]=0;
	for (int i=1;i<=n+1;i++) ans+=abs(a[i]-now),now=a[i];
	ans+=abs(now);
	for (int i=1;i<=n;i++)
	{
		if ((a[i]-a[i-1])*(a[i+1]-a[i])>=0) printf("%d\n",ans); else
		printf("%d\n",ans-2*min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])));
	}
	return 0;
}

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

bool vis[100005];
pair<int, int> dist[100005];
const int INF = 1e9;

void bfs(vector<vector<int>> graph) {
    dist[0].first = 0;
    vis[0] = true;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto u : graph[v]) {
            if (!vis[u]) {
                vis[u] = true;
                dist[u].first = dist[v].first + 1;
                dist[u].second = v + 1;
                q.push(u);
            }
        }
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> cave(n, vector<int>());
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        cave[u - 1].push_back(v - 1);
        cave[v - 1].push_back(u - 1);
    }
    bfs(cave);
    //cout << "hmm";
    bool possible = true;
    /*for (int i = 0; i < n; ++i) {
        if (!vis[i]) {
            possible = false;
            break;
        }
    }*/
    if (possible) {
        cout << "Yes\n";
        for (int i = 1; i < n; ++i) {
            cout << dist[i].second << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 16308
<?php
list($N,$L) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));

for($i = 0;$i < $N - 1;$i++){
    $sum[] = $a[$i] + $a[$i + 1];
}

if(max($sum) >= $L){
    echo "Possible\n";
    $num = array_search(max($sum),$sum);
    if($num == 0){
        for($i = $N - 1;$i > 0;$i--){
            echo $i ."\n";
        }
    }elseif($num == $N - 1){
        for($i = 1;$i < $N;$i++){
            echo $i ."\n";
        }
    }else{
        for($i = 1;$i < $num + 1;$i++){
            echo $i ."\n";
        }
        for($i = $N - 1;$i > $num;$i--){
            echo $i ."\n";
        }
    }
}else{
    echo "Impossible";
}

Measured memory_bytes: 35912
# -*- coding: utf-8 -*-
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def findRoot(N):
    root = round(math.sqrt(N+1))
    return root

def main():
    N=int(input())  #数値入力 「N」だけの入力のとき
    for i in list(reversed(range(1, findRoot(N)+1))):
        a, b = divmod(N, i)
        if b == 0:
            c = N // a
            print(a+c-2)
            break
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 43380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp9
{
    class Program
    {
        static void MainA(string[] args)
        {
            Console.WriteLine(int.Parse(Console.ReadLine()) < 3200 ? "red" : Console.ReadLine());
        }

        static void Main(string[] args)
        {
            Console.ReadLine();
            Console.WriteLine( 1.0d/   Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Select(x => 1.0d / x).Sum());
                }

    }
}


Measured memory_bytes: 13396
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main()
{
  int H=IN(),W=IN(),K=IN(),A=0,B;char line[7][7];
  rep(i,H)B=scanf("%s",line[i]);
  rep(s,1<<H)
  {
    rep(t,1<<W)
    {
      B=0;rep(i,H){rep(j,W){if((s>>i&1)&&(t>>j&1)){if(line[i][j]=='#')B++;}}}if(B==K)A++;
    }
  }
  return printf("%d\n",A),0;
}

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

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

  int n,k; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());

  int res = 0; //吸収できない境目
  int c = a[0];
  for(int i = 0; i < n-1; i++){
    if(c*2 < a[i+1]) res = i+1;
    c += a[i+1];
  }
  cout << n - res << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int main(){
  string S;
  char C;
  int Q,T,F;
  cin >> S;
  deque<char> ans;
  for(int i=0; i<S.length();i++){
    ans.push_back(S[i]);
  }
  cin >> Q;
  int inv=0;//ans is inversed if inv=odd  
  for(int i=0;i<Q;i++){
    cin >> T;
    if(T==1){
      inv++;
    }
    else if(T==2){
      cin >> F >> C;
      if( (F==1 && inv%2==0) || (F==2 && inv%2==1) ) ans.push_front(C);
      if( (F==1 && inv%2==1) || (F==2 && inv%2==0) ) ans.push_back(C);
    }
  }
  if(inv%2==1){
    for(int i=ans.size()-1; i>=0;i--){
      cout << ans[i];
    }
  }
  else {
    for(int i=0; i<ans.size();i++){
      cout << ans[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 896
def main():
    import sys
    input = sys.stdin.readline

    n, m = map(int, input().split())
    l = 1
    r = n
    if n % 2 == 1:
        for i in range(m):
            print(f"{l} {r}")
            l += 1
            r -= 1
    else:
        flag = True
        for i in range(m):
            if flag and r - l <= n // 2:
                r -= 1
                flag = False
            print(f"{l} {r}")
            l += 1
            r -= 1


main()

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR(i,k,n) for(ll i=(k);(k)<(n)?i<(n):i>(n);(k)<(n)?i+=1:i-=1)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define F first
#define S second
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define sz(a) ll((a).size())
#define all(o) (o).begin(), (o).end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
template<class T> T** arr2D(int n,int m,T init){
    T** mat=new T*[n];
    FOR(i,0,n){
        mat[i]=new T[m];
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
    return mat;
}
template<class T> void initialise(T** mat,T init,int n,int m){
    FOR(i,0,n){
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
}
template<class T> void destroy(T** mat,int n,int m){
    FOR(i,0,n){
        delete[] mat[i];
    }delete[] mat;
}
const int MOD = 1000000007;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }

/////////////////////////////////////////////////////////////////////
void solve(){
    int N,W;
    cin>>N>>W;
    vector<ll> val(N);
    vector<ll> weight(N);
    FOR(i,0,N){
        cin>>weight[i];
        cin>>val[i];
    }
    vector<vector<ll>> max_val(W+1,vector<ll>(2,0));
    int k=0;
    FOR(i,0,N){
        FOR(j,0,W+1){
            int rw=j-weight[i];
            max_val[j][k]=max_val[j][k^1];
            if(rw>=0){
                chmax(max_val[j][k],max_val[rw][k^1]+val[i]);
            }
        }
        k^=1;
    }
    cout<<max_val[W][k^1];
}
int main()
{
    fastio
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ull t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 8720