akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const int mod = 1e9+7;
const int N = 1e6+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
string s;
vi e[11];
bool ok(string cur) {
    int x0 = cur[0] - '0';
    if(!sz(e[x0])) return false;

    int pos1 = e[x0][0];
    int x1 = cur[1] - '0';
    auto it1 = upper_bound(all(e[x1]),pos1);
    if(it1==e[x1].end()) return false;

    int pos2 = (*it1);
    int x2 = cur[2] - '0';
    auto it2 = upper_bound(all(e[x2]),pos2);
    if(it2==e[x2].end()) return false;

    return true;
}
int main() {
    cin>>n>>s;
    rep(i, 0, sz(s)) e[s[i]-'0'].pb(i);
    int ret = 0;
    rep(i, 0, 1000) {
        string cur = to_string(i);
        while(sz(cur)<3) cur = '0' + cur;
        //de(cur);
        if(ok(cur)) ret++;
    }
    cout<<ret;
    return 0;
}


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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var a = abx[0];
            var b = abx[1];
            var x = abx[2];

            var u = b / x;
            var l = (a + x - 1) / x;

            Console.WriteLine(u - l + 1) ;
        }
    }
}


Measured memory_bytes: 28176
N, W = map(int, input().split())
goods = []
for _ in range(N):
    v, w = map(int, input().split())
    goods.append((v, w))

# i個目までの品物から重さがwを超えないように選んだ時の価値の最大値
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    v, w = goods[i]
    for j in range(W + 1):
        m = 1
        if j >= w:
            dp[i+1][j] = max(dp[i+1][j-w] + v, dp[i][j-w] + v, dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])



Measured memory_bytes: 41892
#include<bits/stdc++.h>
using namespace std;
int n,m,s,i,j,k,p[21][21],ax[5]={0,1,-1,0,0},ay[5]={0,0,0,1,-1},px,py;
bool a[21][21],f[21][21];
struct fun
{
	int x,y;
};
queue<fun> q;
void bfs()
{
	memset(f,1,sizeof(f));
	memset(p,0,sizeof(p));
	q.push((fun){i,j});
	f[i][j]=0;
	while(!q.empty())
	{
		fun l=q.front();
		q.pop();
		for(k=1;k<5;k++)
		{
			px=l.x+ax[k];
			py=l.y+ay[k];
			if(px<=n&&py<=m&&px>0&&py>0&&a[px][py]&&f[px][py]) 
			{
				p[px][py]=p[l.x][l.y]+1;
				s=max(s,p[px][py]);
				q.push((fun){px,py});
				f[px][py]=0;
			}	
		}
	}
}
int main()
{
	char w;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	  {
	  	cin>>w;
	  	if(w=='.') a[i][j]=1;
	  	else a[i][j]=0;
	  }
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	    if(a[i][j]) bfs();
	cout<<s;
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {


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

        int n = sc.nextInt();

        int array[] = new int[n];

        for (int i = 0; i < n - 1; i++) {
            array[sc.nextInt() - 1]++;
        }

        for (int i = 0; i < n; i++) {
            System.out.println(array[i]);
        }

        sc.close();
    }

}

Measured memory_bytes: 61612
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int max1 = a * 10 + b + c;
    int max2 = b * 10 + a + c;
    int max3 = c * 10 + a + b;
    int max12 = max1 > max2 ? max1 : max2;
    int max23 = max2 > max3 ? max2 : max3;
    int max = max12 > max23 ? max12 : max23;
    System.out.println(max);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    sp(10);
    long double n,k;cin>>n>>k;
    vector<long double> p(n);
    rep(i,n){
        cin>>p[i];
        p[i]=(p[i]+1)/2;
    }
    long double res=0;
    long double tmp=0;
    rep(i,k-1)tmp+=p[i];
    rep(i,n){
        if(i<k-1)continue;
        tmp+=p[i];
        chmax(res,tmp);
        tmp-=p[i-k+1];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 6460
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	char a, b, c, _;
	cin >> a >> _ >> _;
	cin >> _ >> b >> _;
	cin >> _ >> _ >> c;
	cout << a << b << c << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == s[i+1]){
      cout << "Bad" << endl;
      return 0;
    } else {
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long int LLI;
int solve(int a, int b)
{
	if( (a + b) % 2 == 0)
		return (a+b)/2;
	else
		return (a+b+1)/2;
}
int main()
{
	int a, b;
	cin >> a >> b;
	cout  << solve(a,b);
	
}

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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;

#define F0R(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define sz (ll)size
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define f first
#define s second

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}


int main() {
	ll N, B;
	cin >> N >> B;

	cout << 3 * (N - __gcd(N, B)) << "\n";
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?)

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

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

  int a = x / 500;
  int b = (x - a * 500) / 5;

  ll ans = (ll)a * 1000 + b * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input(""))
lista=[]
listb=[]

for i in range(n):
    xy=input("").split(" ")
    lista+=[int(xy[0])+int(xy[1])]
    listb+=[int(xy[0])-int(xy[1])]
t=max(lista)-min(lista)
tt=max(listb)-min(listb)
print(max(t,tt))

    

Measured memory_bytes: 24808
W,H,N=map(int,raw_input().split())
X=[0,W]
Y=[0,H]
for _ in xrange(N):
  x,y,a=map(int,raw_input().split())
  if a==1:
    X[0]=max(X[0],x)
  elif a==2:
    X[1]=min(X[1],x)
  elif a==3:
    Y[0]=max(Y[0],y)
  elif a==4:
    Y[1]=min(Y[1],y)
if X[1]<=X[0] or Y[1]<=Y[0]: print 0
else: print (X[1]-X[0])*(Y[1]-Y[0])

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repri(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;
typedef vector<int> VI;
typedef vector<ll> VL;

ull a, b, c, d;
auto mlcm=[](ll p, ll q) {return p*q/__gcd(p,q);};

auto calc(ll x) {
	ll p=x/c;
	ll q=x/d;
	ll r=x/mlcm(c,d);
	return x-p-q+r;
}

void Main() {
	cin >> a >> b >> c >> d;
	cout << calc(b) - calc(a-1) << LF;

	return;
}

int main(){
	FAST;
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    #define ll long long
    int main()
    {
        ll X;
        cin>>X;
        ll Y = 1;
        ll A = 100;
        while(true)
        {
            ll si = A/100;
            A+=si;
            if(A>=X)
                break;
            Y++;
        }
        cout<<Y;
    }


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;

	if(k == 1)
	{
		cout << "0" << "\n";
		return 0;
	}

	if(n < k)
		cout << 1 << "\n";
	else
	{
		cout << n - k << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define SORT(n)         (n.begin(), n.end(), greater<lint>())       
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             10000000000000000
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int v[11];

bool ok(lint n){
    lint m = n;
    while(m){
        lint ld = m % 10;
        m /= 10;
        if(v[ld] == 1) return false;
    }
    return true;
}
int main()
{
    lint n, dig, a;
    cin>>n>>dig;

    REP(i, 0, dig - 1){
        cin>>a;
        v[a] = 1;
    }
    while(true){
        if(ok(n)){
            cout<<n<<endl;
            break;
        }
        //db(n);
        n++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll power(ll a, ll b){
  ll ans = 1;
  if(b%2==0){
    REP(i, b/2){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans;
  }else{
    b = b/2;
    REP(i, b){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans* a;
  }
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
  
 ll n;
 cin>>n;
 vector<ll> v(n);
 ll sum = 0;

 map<ll,ll> m;

 REP(i, n){
     ll x;
     cin>>x;
     v[i] = x;
     sum += x;
     m[x]++;
 }
 ll q;
 cin>>q;
 vector<ll> ans(q);

 REP(i, q){
     ll x, y;
     cin>>x>>y;
     
     decltype(m)::iterator it = m.find(x);
    if (it != m.end()) { // 見つかった
      m[y] += m[x];
      sum -= x*m[x];
      sum+=m[x]*y;
      m.erase(x);
    }
    ans[i] = sum;
 }
REP(i, q) cout<<ans[i]<<endl;

  return 0;
  
}

Measured memory_bytes: 8856
using System;
using System.Linq;

public static class Program
{
  static int n;
  static int[] a;

  public static void Main(string[] args)
  {
    n = int.Parse(Console.ReadLine());
    a = ConvertInputSplitLine();
    int q = int.Parse(Console.ReadLine());
    int[] m = ConvertInputSplitLine();

    for(int i = 0; i < q; i++)
    {
      string answer = ExhaustedSearch(0, m[i]) ? "yes" : "no";
      Console.WriteLine(answer);
    }
  }

  // i番目までの要素を用いて整数mが作れるか
  public static bool ExhaustedSearch(int i, int m)
  {
    // i - 1番目の要素を使った結果、もしくは、i = 0のときに、m = 0になっていれば、mを作れたと判断
    if(m == 0)
    {
      return true;
    }
    if(i >= n)
    {
      return false;
    }

    //  i番目の要素を使わずに、もしくは、使って、i+1番目までの要素でmを作れるかどうか
    return ExhaustedSearch(i + 1, m) || ExhaustedSearch(i + 1, m - a[i]);
  }


  // Util
  public static int[] ConvertInputSplitLine()
  {
    return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
  }
}



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

int SelectSort(int A[],int N){
	int cout=0;
	int minj;
	for(int i=0;i<N-1;i++){
		minj=i;
		for(int j=i;j<N;j++){
			if(A[j]<A[minj]){
				minj=j;
			}
		}
		swap(A[i],A[minj]);
		if(i!=minj)cout++;
	}
return cout;
}

int main(){
	int A[100],N,cout;
	scanf("%d",&N);
	for(int t=0;t<N;t++){
		scanf("%d",&A[t]);
	}
	cout=SelectSort(A,N);

	for(int t=0;t<N;t++){
		if(t)printf(" ");
		printf("%d",A[t]);
	}
	printf("\n");
	printf("%d\n",cout);

return 0;
}


Measured memory_bytes: 3236
import java.util.*;

public class Main {

    static int COUNT = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        HashMap<Integer, ArrayList<Integer>> routes = new HashMap<>();
        for(int i = 0; i < m; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            new ArrayList<Integer>();
            if(routes.containsKey(a)) {
                ArrayList<Integer> list = routes.get(a);
                list.add(b);
                routes.put(a, list);
            } else {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(b);
                routes.put(a, list);
            }
            if(routes.containsKey(b)) {
                ArrayList<Integer> list = routes.get(b);
                list.add(a);
                routes.put(b, list);
            } else {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(a);
                routes.put(b, list);
            }
        }
        boolean[] isVisited = new boolean[n];
        countRoutes(routes, isVisited, 0);
        System.out.println(COUNT);
    }

    static void countRoutes(HashMap<Integer, ArrayList<Integer>> routes, boolean[] isVisited, int current) {
        if(isVisited[current]) {
            return;
        }
        isVisited[current] = true;
        if(isVisitedAll(isVisited)) {
            COUNT++;
            isVisited[current] = false;
            return;
        }
        ArrayList<Integer> nextRoutes = routes.get(current);
        for(int next: nextRoutes) {
            countRoutes(routes, isVisited, next);
        }
        isVisited[current] = false;
        return;
    }

    static boolean isVisitedAll(boolean[] isVisited) {
        for(int i = 0; i < isVisited.length; i++) {
            if(!isVisited[i]) return false;
        }
        return true;
    }
}


Measured memory_bytes: 24148
N, Y = map(int, input().split())
for y in range(9):
    for x in range(N + 1):
        if Y == (10000 * x) + (5000 * y) + (1000 * (N - x - y)) and N >= x + y:
                print(x, y, N - x - y)
                break
        else:
            continue
        break
    else:
        if y == 8:
            print(-1, -1, -1)
        continue
    break


Measured memory_bytes: 3060
import java.io.IOException;
import java.util.*;

/**
 */
class Main {
	final static int N = 10;

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		String lines[] = s.split(" ");
		Map<String, Integer> map = new HashMap<>();
		for (String line : lines) {
			if (map.containsKey(line)) {
				map.put(line, map.get(line) + 1);
			} else {
				map.put(line, 1);
			}
		}
		String mode_str = "";
		int mode_val = 0;
		String long_str = "";
		for (Map.Entry<String, Integer> e : map.entrySet()) {
			if (mode_val < e.getValue()) {
				mode_val = e.getValue();
				mode_str = e.getKey();
			}
			if (long_str.length() < e.getKey().length()) {
				long_str = e.getKey();
			}
		}
		System.out.println(mode_str + " " + long_str);
	}
}

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

int main(){
	int a,b,c,n;
	cin>>a>>b>>c>>n;
	int cnt=0;
	for(int i=0;i<=n/a;i++){
		for(int j=0;j<=n/b;j++){
			int k=n-(i*a)-(j*b);
			if(k%c==0&&k>=0)cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

struct UniTree {
    int *par, *rank, *sz;

    UniTree(int n) {
        par = new int[n];
        rank = new int[n];
        sz = new int[n];
        for(int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int root(int x) {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        }else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            sz[x] += sz[y];
        }
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int siz(int x) {
        return sz[root(x)];
    }
};

bool check(double mid) {
    return true;
}

double bin(double left, double right) {
    while(right - left > 1e-4) {
        double mid = (left + right) / 2;
        if(check(mid)) left = mid;
        else right = mid;
    }
    return left;
}

int main() {
    int n;
    cin >> n;
    int *a = new int[n];
    rep(i, n) cin >> a[i];
    int t = 0;
    ll sum = 0;
    ll ans = 0;
    rep(s, n) {
        while(t < n && (sum ^ a[t]) == sum + a[t]) {
            sum ^= a[t++];
        }
        ans += t - s;
        sum ^= a[s];
        if(s == t) t++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
n, a, b = map(int, input().split())
if n <= 0 or a > b:
    ans = 0
elif n == 1:
    if a == b:
        ans = 1
    else:
        ans = 0
elif n >= 2:
    ans = b * (n-2) - a * (n-2) + 1
print(ans)


Measured memory_bytes: 2940
n , y  = gets.strip.split.map(&:to_i)
_i, _j, _k = -1, -1, -1

(0..n).each do |i| 
  (0..n-i).each do |j| 
    if i * 10000 + j * 5000 + ( n - i - j ) * 1000 == y
    _i, _j, _k = i, j, n - i - j
    end
  end
end

puts "#{_i} #{_j} #{_k}"


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

int main(){
  string b;
  cin >> b;
  if(b == "A")cout << "T" << endl;
  if(b == "T")cout << "A" << endl;
   if(b == "C")cout << "G" << endl;
   if(b == "G")cout << "C" << endl;
}
  

Measured memory_bytes: 256
from collections import Counter

n, p = map(int, input().split())
s = input()

if p == 2 or p == 5:
    d = {2: "02468", 5: "05"}
    ans = 0
    for i, e in enumerate(s, 1):
        if e in d[p]:
            ans += i

    print(ans)

else:
    li = [0]
    power = 1
    for e in s[::-1]:
        power *= 10
        power %= p
        li.append((li[-1] + int(e) * power) % p)

    c = Counter(li)
    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2

    print(ans)


Measured memory_bytes: 12016
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long mod = 1000000007;

void max_self(ll& a, ll b)
{
	a = max(a, b);
}

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n, w;
	cin >> n >> w;
	vector<ll> dp(w + 1);
	for (int i = 0; i < n; i++)
	{
		int cw, cv;
		cin >> cw >> cv;
		for (int wa = w - cw; wa >= 0; wa--)
			max_self(dp[wa + cw], dp[wa] + cv);
	}
	cout << *max_element(all(dp));
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var D = int.Parse(input[0]);
        var T = int.Parse(input[1]);
        var S = int.Parse(input[2]);

        var t = (double)D / S;

        if (t <= T) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

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

int a, b, n;
vector<vector<bool>> g;

int Dfs(int i, int j) {
  if (i > a || j > b)
    return 0;
  if (!g[i][j])
    return 0;
  if (i == a && j == b)
    return 1;
  int res = Dfs(i + 1, j) + Dfs(i, j + 1);
  return res;
}

int main() {
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i)
      cin >> x[i] >> y[i];
    g.resize(a + 1, vector<bool>(b + 1, true));
    for (int i = 0; i < n; ++i)
      g[x[i]][y[i]] = false;
    cout << Dfs(1, 1) << endl;
    g.clear();
  }
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> cnt(100010);
    rep(i, N)
    {
        ll a;
        cin >> a;
        if (a==0) {
            cnt[a]++;
            cnt[a + 1]++;
        }else {
            cnt[a - 1]++;
            cnt[a]++;
            cnt[a + 1]++;
        }
    }

    ll ans = 0;
    for (auto &a : cnt) {
        ans = max(a, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 998244353
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  
  ll DP[C+2][D+2];
  for(int i=0; i<=C+1; ++i){
    for(int j=0; j<=D+1; ++j){
      DP[i][j]=0;
    }
  }
  DP[A][B]=1;
  
  for(int i=B+1; i<=D; ++i){
    DP[A][i]=DP[A][i-1]*A;
    DP[A][i]%=MOD;
  }
  
  for(int i=A+1; i<=C; ++i){
    DP[i][B]=DP[i-1][B]*B;
    DP[i][B]%=MOD;
  }
  
  for(int i=A+1; i<=C; ++i){
    for(int j=B+1; j<=D; ++j){
      DP[i][j]+=DP[i-1][j]*j+DP[i][j-1]*i;
      DP[i][j]-=(i-1)*(j-1)*DP[i-1][j-1];
      DP[i][j]%=MOD;
      if(DP[i][j]<0) DP[i][j]+=MOD;
    }
  }
  
  co(DP[C][D]);
  return 0;
}

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

int main(){
  int K,X;
  int kosu;
  cin >> K >> X;
  if(X-(K-1) < -1000000){
    kosu = X + 1000000 + K;
    for(int i = 0; i<kosu;i++){
      cout << -1000000 + i << " ";
    }
    cout << endl;
  }else if(X + (K-1) > 1000000){
    kosu = 1000000 - X + K;
    for(int i = kosu; i>0;i--){
      cout << 1000000 - i + 1 << " ";
    }
    cout << endl;
  }else{
    for(int i = (-1)*K + 1; i<K ;i++){
      cout << X + i << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<cmath>
#include<cstdlib>
#include<cassert>
#include<climits>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<long long> a(N), b(N), c(M), d(M);
	for (int i = 0; i < N; i++)
		cin >> a[i] >> b[i];
	for (int i = 0; i < M; i++)
		cin >> c[i] >> d[i];
	for (int i = 0; i < N; i++) {
		int ans = -1, min_distance = INT_MAX;
		for (int j = 0; j < M; j++) {
			int distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (distance < min_distance) {
				ans = j + 1;
				min_distance = distance;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
import statistics as st
import math
int(input())
s = list(map(int, input().split()))
md = math.floor(st.mean(s))
mu = md + 1
sd = 0
su = 0
for i in range(0, len(s)):
    sd = sd + (s[i] - md) ** 2
    su = su + (s[i] - mu) ** 2
print(min(sd, su))

Measured memory_bytes: 5148
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n + 1) {}
  void add(int k, T a) {
    for (++k; k < x.size(); k += k & -k) x[k] += a;
  }
  T sum(int k) {
    T s = 0;
    for (; k > 0; k &= k - 1) s += x[k];
    return s;
  }
  int lower_bound(T a) {
    if (a <= 0) return 0;
    int k = x.size() - 1;
    for (int s : {1, 2, 4, 8, 16}) k |= (k >> s);
    for (int p = ++k; p > 0; p >>= 1, k |= p)
      if (k < x.size() && x[k] < a)
        a -= x[k];
      else
        k ^= p;
    return k + 1;
  }
};

struct event_t {
  int l, r, id;
};

int main() {
  int N, M, Q;
  while (cin >> N >> M >> Q) {
    vector<event_t> events;
    for (int i = 0; i < M; i++) {
      int L, R;
      cin >> L >> R;
      --L;
      --R;
      events.push_back({L, R, -1});
    }
    for (int i = 0; i < Q; i++) {
      int p, q;
      cin >> p >> q;
      --p;
      --q;
      events.push_back({p, q, i});
    }
    vector<int> xs;
    for (auto& ev : events) {
      xs.push_back(ev.l);
      xs.push_back(ev.r);
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    for (auto& ev : events) {
      ev.l = lower_bound(xs.begin(), xs.end(), ev.l) - xs.begin();
      ev.r = lower_bound(xs.begin(), xs.end(), ev.r) - xs.begin();
    }
    sort(events.begin(), events.end(), [&](auto& a, auto& b) {
      if (a.r != b.r) return a.r < b.r;
      return a.id < b.id;
    });
    fenwick_tree<int> bit(xs.size());
    vector<int> res(Q);
    for (auto& ev : events) {
      if (ev.id < 0) {
        bit.add(ev.l, 1);
      } else {
        res[ev.id] = bit.sum(ev.r + 1) - bit.sum(ev.l);
      }
    }
    for (int x : res) {
      cout << x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 13036
#include<iostream>
#include<string>
#include<cmath>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <vector>


using namespace std;

int main()
{

  int a[200010];
  int b[200010];
  int n;
  cin>>n;

  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=a[i];
  }

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

  for(int i=1;i<=n;i++){
    if(b[i]<=a[n/2])
      cout<<a[n/2+1]<<endl;
    else{
      cout<<a[n/2]<<endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_048
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Read();
            bool firstWin = false;
            if (s[0] == s[s.Length - 1])
            {//奇数になるほうが負け
                firstWin = s.Length % 2 == 0;
            }
            else
            {
                firstWin = s.Length % 2 == 1;
            }
            if (firstWin)
            {
                Console.WriteLine("First");
            }
            else
            {
                Console.WriteLine("Second");
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n, x;
  cin >> n >> x;
  vi m(n);
  for (int i = 0; i < n; i++) {
    cin >> m.at(i);
    x -= m.at(i);
  }
  sort(m.begin(), m.end());
  cout << n + x / m.at(0) << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	static int[] b = new int [10];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String s = sc.next();
			//if(s.length() == 1) break;
			int[] a = new int[14];
			int[] c = new int[10];
			for(int i = 0; i < s.length(); i++) {
				a[i] = Integer.parseInt(s.substring(i, i + 1));
				c[a[i]]++;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 1; i <= 9; i++) {
				a[13] = i;
				System.arraycopy(c, 0, b, 0, 10);
				b[i]++;
				if(b[i] >= 5) continue;
				flag = false;
				dfs(0);
				if(flag) {
					list.add(i);
				}
			}
			if(list.size() == 0) {
				System.out.println(0);
			}else {
				for(int i = 0; i < list.size(); i++){
					if(i == list.size() - 1) {
						System.out.println(list.get(i));
					}else {
						System.out.printf("%d ", list.get(i));
					}
				}
			}
		}
		sc.close();
	}
	static boolean flag = false;
	static void dfs(int n) {
		if(n == 5) {
			flag = true;
			return;
		}
		if(flag) return;
		if(n == 0) {
			for(int i = 1; i <= 9; i++) {
				if(b[i] >= 2) {
					b[i] -= 2;
					dfs(n + 1);
					b[i] += 2;
				}
			}
		}
		for(int i = 1; i + 2 <= 9; i++) {
			if(b[i] >= 1 && b[i + 1] >= 1 && b[i + 2] >= 1) {
				b[i]--;
				b[i + 1]--;
				b[i + 2]--;
				dfs(n + 1);
				b[i]++;
				b[i + 1]++;
				b[i + 2]++;
			}
		}
		for(int i = 1; i <= 9; i++) {
			if(b[i] >= 3) {
				b[i] -= 3;
				dfs(n + 1);
				b[i] += 3;
			}
		}
	}
}


Measured memory_bytes: 27408
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    int i;
    cin >> s >> t;
    for(i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <string>
#define maxn 200005

using namespace std;
typedef long long ll;
string s;
int n,f[maxn][2];//0: with right length 1; 1: with 2.

int main(){
  ios::sync_with_stdio(false);
  cin >> s;
  n = s.length();
  s += "$#";
  memset(f,0xc0,sizeof(f));
  for(int i = 0;i < n;i++){
    if(i == 0){
      f[0][1] = 1;
      if(s[1] != s[0]) f[0][0] = 1;
    }else if(i == 1){
      f[1][0] = 1;
      if(s[2] != s[1]) f[1][0] = max(f[1][0],f[0][0] + 1);
      f[1][1] = f[0][0] + 1;
      if(s.substr(0,2) != s.substr(2,2))
        f[1][1] = max(f[1][1],1);
    }else{
      f[i][0] = f[i - 2][1] + 1;
      if(s[i] != s[i + 1]) f[i][0] = max(f[i][0],f[i - 1][0] + 1);
      f[i][1] = f[i - 1][0] + 1;
      if(s.substr(i - 1,2) != s.substr(i + 1,2))
        f[i][1] = max(f[i][1],f[i - 2][1] + 1);
    }
  }
  cout << f[n - 1][0] << endl;
  return 0;
}


Measured memory_bytes: 2196
#include <iostream>
#include <vector>
using namespace std;
long long MAX = 1e18;
struct segRMQ{
    long long n;
    vector<long long> dat;
    segRMQ(long long n_){
        n = 1;
        while(n < n_) n *= 2;
        dat.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++) dat[i] = MAX;
    }
    void update(long long k, long long a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    long long query(long long a, long long b, long long k, long long l, long long r){
        if(r <= a || b <= l) return MAX;
        if(a <= l && r <= b) return dat[k];
        else{
            long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};
int main(){
    long long N, x;
    cin >> N >> x;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    segRMQ segK(N);
    long long n = segK.n;
    for(int i = 0; i < N; i++) segK.update(i, a[i]);
    long long ans = MAX;
    for(long long i = 0; i < N; i++){
        long long temp = 0;
        temp += x * i;
        for(long long j = 0; j < N; j++){
            if(j < i){
                temp += min(segK.query(0, j + 1, 0, 0, n), segK.query(N - i + j, N, 0, 0, n));
            }
            else temp += segK.query(j - i, j + 1, 0, 0, n);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

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

int main(){
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x+k-1; i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef pair<int,int> P;
const int INF=100000000;

bool kaibun(string str)
{
	int len=str.size();
	for(int i=0;i<len;i++)
	{
		if(str[i]!=str[len-1-i])return false;
	}
	return true;
}
int main(){
	string s;
	cin>>s;
	int n=s.size();
	if(kaibun(s) && kaibun(s.substr(0,(n-1)/2))
	   && kaibun(s.substr((n+1)/2,(n-1)/2)))
	{
		cout<<"Yes"<<"\n";   
	   
	}
	else cout<<"No"<<"\n";
	return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

def devisors(z):
    r = 0
    for i in range(1, z + 1):
        if z % i == 0:
            r += 1
    return r 

r = 0

for i in range(1, n+1):
    if i % 2 == 1 and devisors(i) == 8:
        r += 1

print(r)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
using namespace std;
int main(){
	int dp[20][20];
	int x,y,n;
	while(true){
	    cin>>n;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				dp[i][j]=0;
		if(n==0)
			break;
		x=(n-1)/2+1,y=(n-1)/2;
		for(int i=0;i<n*n;i++){
			if(dp[x][y]!=0){
				x++;
				y--;
				if(y<0)
					y+=n;
				x%=n,y%=n;
			}
		    dp[x][y]=i+1;
			x++,y++;
			x%=n,y%=n;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				int h=3;
				int k=dp[i][j];
				while(true){
					k/=10;
					if(k==0)
						break;
					h--;
				}
				for(int k=0;k<h;k++)
					cout<<" ";
				cout<<dp[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
long long a[200005];
int cmp(const void *a,const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
	int n,i,j,k;
	long long sum=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++) scanf("%lld",&a[i]);
	qsort(a,n,sizeof(a[0]),cmp);
	for(j=0;j<n-k;j++)
	{
		sum+=a[j];
	}
	printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 3324
/*
    Problem 85
    https://onlinejudge.u-aizu.ac.jp/problems/DSL_1_A
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    vector<int> d;
    DisjointSet () {}
    DisjointSet (int size) {
        d.assign(size, -1);
    }

    int find (int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite (int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same (int x, int y) { return find(x) == find(y); }
    int size (int x) { return -d[find(x)];}
};
/* global variables */
/* function */
/* main */
int main(){
    int N, Q;
    cin >> N >> Q;
    DisjointSet ds = DisjointSet(N);
    for (int i = 0; i < Q; i++) {
        int op, x, y;
        cin >> op >> x >> y;
        if (op==0) ds.unite(x, y);
        else cout << (ds.same(x, y) ? 1 : 0) << '\n';
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> dp(3, 0);
    for (int d = 0; d < n; d++)
    {
        vector<int> ndp(3, 0);
        vector<int> c(3);
        for (int &it : c)
            cin >> it;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i != j)
                {
                    ndp[j] = max(ndp[j], dp[i] + c[j]);
                }
            }
        }
        dp = ndp;
    }
    cout << max({dp[0], dp[1], dp[2]});
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
vector<int> a;
int main()
{
	int n;
	int i;
	scanf("%d",&n);
	a.resize(n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a.begin(),a.end());
	printf("%d\n",a[n-1]-a[0]);
	return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline

N, M = map(int, input().split())
S = list(input())[: -1]
x = N
res = []
s = []
for i in range(N + 1):
  if S[i] == "0": s.append(i)
#print(s)
for _ in range(N):
  if x == 0:
    break
  n = bl(s, x - M)
  #print(n)
  res.append(x - s[n])
  x = s[n]
res.reverse()
if x != 0: print(-1)
else:
  print(" ".join(list(map(str, res))))

Measured memory_bytes: 58360
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  int n, t[100000], x[100000], y[100000];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> t[i] >> x[i] >> y[i];
  }

  for(int i=0; i<n; i++){
    if(i==0){
      if(t[i]<( abs(x[i])+abs(y[i]) ) || (t[i]%2!=0 && (abs(x[i])+abs(y[i]))%2==0 ) 
      || t[i]%2!=0 && (abs(x[i])+abs(y[i]))%2==0 ){
        cout << "No" << endl;
        return 0;
      }
    }
    if(i!=0){
      if((t[i]-t[i-1])<(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])) || ( ( (t[i]-t[i-1])%2==0
      && (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2!=0 ) || ( (t[i]-t[i-1])%2!=0
      && (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2==0 ) ) ){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;


  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int N;
	vector<int> A;
	vector<int> B;
	int tmp;
	cin >> N;
	rep(i,0,N){
		cin >> tmp;
		B.push_back(tmp);
	}
	rep(i,0,N){
		rel(j,B.size(),0){
			if(j+1 == B[j]){
				B.erase(B.begin()+j);
				A.insert(A.begin(),j+1);
				break;
			}
		}
	}
	if(B.empty()){
		rep(i,0,N){
			cout << A[i] << endl;
		}
	}else{
		cout << "-1" << endl;
	}
}

Measured memory_bytes: 256