akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int cal(string &s,int &i){
  int res=0;
  while(1){
    if(isdigit(s[i]))res=s[i++]-'0';
    else if(s[i]=='('){res=cal(s,++i);}
    else if(s[i]=='+')res+=cal(s,++i);
    else if(s[i]=='-')res-=cal(s,++i);
    else break;
  }
  return res;
}

int calc(string s){
  vector<int> v;
  for(int i=0;i<s.size();i++){
    int n = (int)v.size()-1;
    if(s[i]=='+')v.push_back(0);
    if(s[i]=='-')v.push_back(1);
    if(s[i]=='(')v.push_back(0),v.push_back(0);
    if(s[i]==')'){
      if(v.size()<3)continue;
      v[n-2]+=v[n-1]? -v[n]:v[n];
      v.pop_back(),v.pop_back();
    }

    if(isdigit(s[i])){
      int num=s[i]-'0';
      if(v.size()>=2){
	v[n-1]+=v[n]? -num:num;
	v.pop_back();
      }
      else v.push_back(num);
    }
  }
  return v[0];
}

map<string,int> mem[2];
int dfs(string s,int f){
  if(s.size()==1) return s[0]-'0';
  if(mem[f].count(s))return mem[f][s];

  int j=0;  
  int n=s.size(),res=calc(s),d=-1;
  for(int i=0;i<n;i++) d+=(s[i]=='+'||s[i]=='-');
  
  for(int i=0,c=0,cnt=0;i<n;i++,cnt++,d--){
    while(i<n){
      while(s[i]=='('||s[i]==')')c+=(s[i]=='(')-(s[i]==')'),i++;
      if(s[i]=='+'||s[i]=='-') break;
      i++;
    }
    if(i>=n||(cnt&&s[i-2]=='(')||(d&&s[i+2]==')'))continue;
    string a=s.substr(0,i),b=s.substr(i+1,n-i-1);
    int t=c,ch=s[i];
    while(t--)a+=')',b='('+b;
    int mxa=dfs(a,0),mna=dfs(a,1);
    int mxb=dfs(b,0),mnb=dfs(b,1);
    if(f==0&&ch=='+') res=max(res, mxa+mxb);
    if(f==0&&ch=='-') res=max(res, mxa-mnb);
    if(f==1&&ch=='+') res=min(res, mna+mnb);
    if(f==1&&ch=='-') res=min(res, mna-mxb);
  }
  return mem[f][s]=res;
}

int main(){
  string S;
  cin>>S;
  cout <<dfs(S,0)<<endl;
  return 0;
}

Measured memory_bytes: 4844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace ABC_prac
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = ReadInts();
            int n = cin[0];
            int y = cin[1];
            int ans = 0;

            for (int a = 0; a <= n; a++)
            {
                for (int b = 0; b <= n; b++)
                {
                    int c = n - a - b;
                    if (10000*a+5000*b+1000*c==y && c>=0)
                    {
                        WriteLine("{0} {1} {2}", a,b,c);
                        Read();

                        return;
                    }
                }
            }

            WriteLine("-1 -1 -1");
            //WriteLine("{0}", ans);

            Read();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        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: 13268
N=int(input())

list=[]
ac=0
wa=0
re=0
tlc=0

for i in range(N):
 list.append(input())

for i in range(N):
 if list[i]=="AC":
  ac+=1
 elif list[i]=="WA":
  wa+=1
 elif list[i]=="RE":
  re+=1
 else:
  tlc+=1

print("AC  x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tlc))
print("RE x "+str(re))

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int a,b,c;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> a >> b >> c;
  if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
    cout << "0\n";
  }else{
    cout << min({a*b, a*c, b*c}) << "\n";
  }
}


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

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int answer=A*X+B*Y;
    int upper=max(X,Y);
    for(int i=1;i<=upper;i++){
        int x=X-i,y=Y-i;
        if(X-i<0) x=0;
        if(Y-i<0) y=0;
        int sum=A*x+B*y+C*(2*i);
        answer=min(answer,sum);
    }
    cout << answer << endl;
    return 0;

}

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

using namespace std;
#define int int64_t

bool check_palindrome(string s) {
    string r = s;
    reverse(r.begin(), r.end());
    return (r == s);
}

int32_t main() {
    string s;
    cin >> s;
    int n = s.size();
    if(check_palindrome(s) and check_palindrome(string(s.begin(), s.begin() + (n - 1) / 2)) and check_palindrome(string(s.rbegin(), s.rbegin() + (n - 1) / 2)))
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
string a,b;
int main()
{
    cin>>a>>b;
    for(register int i=0;i<a.length();i++)
    {
        if(a[i]!=b[3-i-1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long s = sc.nextLong();
    long mod = s % ((long)Math.pow(10, 9));
    long x3 = (long)Math.pow(10, 9) - mod;
    if(mod == 0) x3 = 0;
    long y3 = (s + x3) / (long)(Math.pow(10, 9));
    long x1 = 0;
    long y1 = 0;
    long x2 = (long)Math.pow(10, 9);
    long y2 = 1;
    System.out.println(x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3);
  }
}

Measured memory_bytes: 23508
#include <iostream>

using namespace std;

int N;
long long A[100000];
long long ans[100000];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    long long sum = 0;
    for(int i=0;i<N;i++) sum += A[i];
    int m = N / 2;
    long long bsum = 0;
    for(int i=0;i<m;i++) bsum += A[1+2*i];
    bsum *= 2;
    ans[0] = sum - bsum;
    for(int i=1;i<N;i++){
        ans[i] = (A[i-1] - ans[i-1]/2) * 2;
    }
    for(int i=0;i<N;i++){
        cout << ans[i];
        if(i != N-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			
			int n = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt();
			int g1 = sc.nextInt();
			int g2 = sc.nextInt();
			
			if(n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0){
				break;
			}
			
			int[][] street = new int[n + 1][n + 1];
			int x;
			int y;
			int cost;
			
			for(int i = 1; i < n + 1; i++){
				for(int j = 1; j < n + 1; j++){
					street[j][i] = Integer.MAX_VALUE/10;
				}
			}
			
			for(int i = 0; i < m ; i++){
				x = sc.nextInt();
				y = sc.nextInt();
				cost = sc.nextInt();
				street[x][y] = cost;
				
			}
			
			for(int i = 1; i < n + 1; i++){
				street[i][i] = 0;
				for(int j = 1; j < n + 1; j++){
					for(int k = 1; k < n + 1; k++){
						street[j][k] = Math.min(street[j][k], street[j][i] + street[i][k]);
					}
				}
			}
			int sum = Integer.MAX_VALUE;
			for(int i = 1; i < n + 1; i++){
				sum = Math.min(sum , street[s][i] + street[i][g1] + street[i][g2]);
			}

			System.out.println(sum);
			
		}
		
	}

}

Measured memory_bytes: 13000
#include <stdio.h>
#include <string.h>
char s[200010];
int main(){
	int i,n;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++)
		if(s[i]=='?')s[i]='D';
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 1812
import java.util.Scanner;

public class Main {

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

		if (a == 1) {
			a = 14;
		}
		if ( b == 1) {
			b = 14;
		}
		if (a > b) {
			System.out.println("Alice");
		} else if (a < b) {
			System.out.println("Bob");
		} else {
			System.out.println("Draw");
		}
	}
}


Measured memory_bytes: 35564
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if x in a and y in a:
  print('Yes')
elif x in b and y in b:
  print('Yes')
elif x in c and y in c:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

const int dx[]={1,0,-1,0};
const int dy[]={0,-1,0,1};
bool judge(int i,int j,int h,int w)
{
  if(i<0||i>=h||j<0||j>=w) return false;
  else return true;
}

int main()
{
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(auto&& e: s) 
  {
    cin>>e;
  }
  int ans=0;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if(s[i][j]=='#') continue;
      vector<vector<int>> num_field(h,vector<int>(w,-1));
      num_field[i][j]=0;
      queue<pair<int,int>> next_point;
      next_point.push(make_pair(i,j));
      while(!next_point.empty())
      {
        int x=next_point.front().first;
        int y=next_point.front().second;
        next_point.pop();
        for (int k = 0; k < 4; ++k)
        {
          int nx=x+dx[k],ny=y+dy[k];
          if(judge(nx,ny,h,w)&&num_field[nx][ny]==-1&&s[nx][ny]=='.')
          {
            next_point.push(make_pair(nx,ny));
            num_field[nx][ny]=1+num_field[x][y];
          }
        }
      }
      for (int x = 0; x < h; ++x)
      {
        for (int y = 0; y < w; ++y)
        {
          ans=(num_field[x][y]>ans)?num_field[x][y]:ans;
        }
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
vector<int> G[MAXN];
int par[MAXN], sz1[MAXN], sz2[MAXN];
bool visit[MAXN];

int find(int x) {
    return x == par[x] ? x : par[x] = find(par[x]);
}

void merge(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     sz1[x] += sz1[y];
     sz2[x] += sz2[y];
     par[y] = x;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < MAXN; i++) {
        par[i] = i;
        sz2[i] = 1;
    }

    for (int i = 0; i < N; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        G[x].push_back(y);
    }
    for (int i = 0; i < MAXN; i++) {
        for (int j = 1; j < (int)G[i].size(); j++) {
            merge(G[i][0], G[i][j]);
        }
        if (!G[i].empty()) sz1[find(G[i][0])]++;
    }
    LL ans = 0;
    for (int i = 0; i < MAXN; i++) {
        int tmp = find(i);
        if (visit[tmp]) continue;
        visit[tmp] = 1;
        ans += (LL)sz1[tmp] * sz2[tmp];
    }
    printf("%lld\n", ans - N);

    return 0;
}


Measured memory_bytes: 6144
#include<stdio.h>

int main(void){
  int x[5];
  scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]);
  int i;
  for(i=0;i<5;i++){
   if(x[i]==0){
     break;
   }
  }
 printf("%d",i+1);
 return 0; 
}

Measured memory_bytes: 1712
// AtCoder Beginner Contest 096 - Problem D: Five, Five Everywhere (https://atcoder.jp/contests/abc096/tasks/abc096_d) 
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MAX { 10000010 };

vector<ll> ps, qs;
bitset<MAX> sieve;

void precomp()
{
    sieve.set();
    ps.push_back(2);
    ps.push_back(3);

    for (ll i = 5, step = 2; i * i < MAX; i += step, step = 6 - step)
    {
        if (sieve[i])
        {
            ps.push_back(i);

            for (ll j = i * i; j < MAX; j += 2*i)
                sieve[j] = false;
        }
    }

    for (auto p : ps)
        if (p % 5 == 2)
            qs.push_back(p);
}

vector<ll> solve(int N)
{
    vector<ll> ans(qs.begin(), qs.begin() + N);

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int N;
    cin >> N;

    auto ans = solve(N);

    for (int i = 0; i < N; ++i)
        cout << ans[i] << (i + 1 == N ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 1536
from collections import defaultdict
from collections import deque

N, M = map(int, input().split())

chg = 10**6
G = defaultdict(set)
for _ in range(M):
    p, q, c = map(int, input().split())
    # 無向グラフ
    G[p].add(p+chg*c)
    G[p+chg*c].add(p)
    G[q].add(q+chg*c)
    G[q+chg*c].add(q)
    G[p+chg*c].add(q+chg*c)
    G[q+chg*c].add(p+chg*c)


dist = defaultdict(lambda: 10**11)
dist[1] = 0

que = deque([1])

while que:
    ci = que.popleft()

    for ni in G[ci]:
        if dist[ni] == 10**11:
            if ci >= chg and ni >= chg:
                dist[ni] = dist[ci]
                que.appendleft(ni)
            else:
                dist[ni] = dist[ci]+1
                que.append(ni)


if dist[N] < 10**11:
    print(dist[N]//2)
else:
    print(-1)


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

using namespace std;

const int64_t INF = INT64_C(1) << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }
  vector<int64_t> C(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  int64_t res = -INF;
  for (int i = 0; i < N; i++) {
    int cur = i, cnt = 0;
    int64_t tot = 0;
    while (true) {
      tot += C[cur];
      cur = P[cur];
      cnt++;
      if (cur == i) break;
    }
    int c = 0;
    int64_t t = 0;
    while (true) {
      c++;
      t += C[cur];
      if (c > K) break;
      int n = (K - c) / cnt;
      res = max(res, t + max(INT64_C(0), tot) * n);
      cur = P[cur];
      if (cur == i) break;
    }
  }
  cout << res << '\n';
  return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A == B) {
    cout << A + B << endl;
  } else if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }
}

Measured memory_bytes: 256
S = input()
T = input()

count = 0

for i in range(3):
    if(S[i] == T[i]):
        count += 1
        
if(count == 0):
    print(0)
elif(count == 1):
    print(1)
elif(count == 2):
    print(2)
else:
    print(3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;


signed main(){
    IOS();
    int n,q; cin>>n>>q;
    vector<ll> lens = {n};
    for (ll i = 0; i<q; ++i) {
        ll x; cin>>x;
        while (SZ(lens) && lens.back() >= x) lens.pop_back();
        lens.pb(x);
    }
    q = SZ(lens);
//    for (ll x : lens) bug(x);
    vector<ll> numat(q);
//    map<ll, ll> mp;
    numat.back() = 1;
    vector<ll> ret(n+1);
    for (int i = q-1; i>=0; --i) {
        if (numat[i] == 0) continue;
        ll me = lens[i];
        while (me > lens[0]) {
            int tt = lower_bound(ALL(lens), me) - lens.begin()-1;
            bug(tt,lens[tt]);
            numat[tt] += numat[i] * (ll)(me / lens[tt]);
            me = me % lens[tt];
        }
        if (me) ret[me-1] += numat[i];
    }
    for (int i = n; i>=0; --i) {
        if (i!=n) ret[i] += ret[i+1];
    }
    for (int i = 0; i<n; ++i) {
        cout<<ret[i]<<endl;
    }
}


Measured memory_bytes: 4212
N = gets.to_i
info = []
for i in 0..3
  floor = []
  for j in 0 ..2
    floor << Array.new(10,0)
  end
  info << floor
end

N.times {
  b,f,r,v =  gets.split().map { |e|e.to_i  }
  info[b-1][f-1][r-1] += v
}

count = 0
for dormitory in info
  for floor in dormitory
    string = " " + floor.join(" ")
    puts string
  end
  count += 1
  puts "####################" if count != 4
end

Measured memory_bytes: 6116
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long z = sc.nextLong();
    long w = sc.nextLong();
    long[] a = new long[n];
    for(int i=0;i<n;i++)a[i]=sc.nextLong();
    if(n==1)System.out.println(Math.abs(a[0]-w));
    else System.out.println(Math.max(Math.abs(a[n-1]-w),Math.abs(a[n-1]-a[n-2])));
  }
}

Measured memory_bytes: 25684
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

 
/*
プライオリティキュー
https://cpprefjp.github.io/reference/queue/priority_queue.html
数を追加する .push
最小の値を得る .top
最小の値を取り出す .pop O(log n)

逆順に解く
最大値をとるところから順に操作していく
*/
priority_queue<ll> zen;
priority_queue<ll,vector<ll>, greater<ll>> kou;
vector<ll> a,b;
ll b_sum = 0;

int main() {
	// 入力
    ll Q;cin>>Q;
    ll zensum = 0;
    ll kousum = 0;
    // printf("Q: %lld\n", Q);
    REP(i,Q){
        ll tmp;
        cin>>tmp;
        if (tmp==1){// f(x)の更新
            // printf("query = 1\n");
            ll a_tmp, b_tmp;cin>>a_tmp>>b_tmp;
            a.pb(a_tmp);b.pb(b_tmp);b_sum+=b_tmp;
            
            if (zen.size()==0){
                zen.push(a_tmp);zensum += a_tmp; // 前半に追加
            }
            else if (a_tmp>zen.top()){//aが前半の最大値より大きい
                kou.push(a_tmp);kousum += a_tmp; // 後半に追加
            }
            else{
                zen.push(a_tmp);zensum += a_tmp; // 前半に追加
            }
            if (zen.size()<kou.size()){// 後半が前半より多い
                zen.push(kou.top());zensum += kou.top(); // 後半の最小値を前半へ
                kousum -= kou.top();kou.pop();
            }
            if (zen.size()>=kou.size()+2){ // 前半が後半より2多い
                kou.push(zen.top());kousum += zen.top();
                zensum -= zen.top();zen.pop();
            }
            // printf("zen size: %i, kou size: %i\n", zen.size(), kou.size());
            // if (zen.size()>0) printf("zen top :%lld\n", zen.top());
            // if (kou.size()>0) printf("kou top :%lld\n", kou.top());
        }
        else{// f(x)の最小値の出力
            // printf("query = 2\n");
            ll x = zen.top();
            ll ans = (x*zen.size()-zensum) + (kousum-x*kou.size()) + b_sum;
            // REP(i,a.size()){
            //     ans += abs(a[i]-x);
            // }
            // printf("x: %lld. min: %lld\n", x, ans);
            printf("%lld %lld\n", x, ans);
        }
        // printf("zen %lld\n", zen.top());
    }
}


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

int main()
{
    string s,y;
    y="x";
    cin>>s;
    for(int i=0; i<s.length(); i++){
        s[i]=tolower(s[i]);
        s.replace(i,1,y);
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

lint pow_mod(lint base,lint expo) { 
   lint ret = 1;
   for(;expo;) { 
      if(expo&1)  ret = (ret*base)%MOD; 

      expo = (expo>>1);
      base = (base*base)%MOD;
   }
   return ret;
}

/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
  float r;
  cin >> r;

  cout << M_PI * 2 * r << endl;
}

int main(){   
  
    // freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);

 solve();

 return 0;
}


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



int main(int argc, char const *argv[]){

string s;
cin >> s;


    if (s == "AAA" || s == "BBB")
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;    
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 36

typedef struct{
  char a;
  int b;
}Tru;

main(){

  int i,j,n,e,min;
  Tru c[N],d[N],s,t;

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

  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(c[j].b<c[j-1].b){
	s=c[j];
	c[j]=c[j-1];
	c[j-1]=s;
      }
    }
  }
  for(i=0;i<n-1;i++){
    printf("%c%d ",c[i].a,c[i].b);
  }
  printf("%c%d\n",c[n-1].a,c[n-1].b);
  printf("Stable\n");

 for(i=0;i<n;i++){
   min=i;
   for(j=i;j<n;j++){
     if(d[j].b<d[min].b){ 
	min=j;
      }    
    }
    if(i!=min){
    t=d[i];
    d[i]=d[min];
    d[min]=t;
    }
 }

 for(i=0;i<n-1;i++){
     printf("%c%d ",d[i].a,d[i].b);
 }
  printf("%c%d\n",d[n-1].a,d[n-1].b);
  for(i=0;i<n;i++){
    if(c[i].a!=d[i].a){ 
      e=0; break;
    }
    else if(c[i].a==d[i].a) e=1;
  }
  if(e==0)  printf("Not stable\n");
  else if(e==1)  printf("Stable\n");
  return 0;
}

Measured memory_bytes: 608
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
ll power(ll a, ll b)
{
    if(b<0) return 0;
    ll res=1LL;
    while(b>0)
    {
        if(b&1LL) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res%mod;
}
ll doo(ll x)
{
    x%=mod;
    x=(x-1+mod)%mod;
    return x;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map<pair<ll,ll>,ll> mp;
    ll val;
    ll n; cin>>n;
    // ll ans=0;
    ll cnt=0;
    for(int i=1;i<=n;i++){
        ll a,b,x,y; cin>>a>>b;
        if(a==0 && b==0)  {cnt++; continue; }
        ll gcd=__gcd(abs(a),abs(b));
        mp[{a/gcd,b/gcd}]++;
    }
    ll ans=1LL;ll x,y;
    map<pair<ll,ll>,ll> vis;
    // cout<<mp.size()<<endl;
    for(auto i: mp){
        
        if(vis.count(i.first)) continue;
        if(i.second==0 )  continue;
        // cout<<i.first.first<< " "<<i.first.second<<" "<<i.second<<endl;
        ll c=0;
        ll a=i.first.first; ll b=i.first.second;
        if((a<0 && b>0) || (a>0 && b<0)){
            pair<ll,ll> pp;
            x=abs(a); y=abs(b);
            pp={y,x};
            c+=mp[pp];
            mp[pp]=0;
            pp={-y,-x};
            c+=mp[pp];
             mp[pp]=0;
            //  cout<<c<<endl;
            val=(power(2,c)+power(2,mp[{-x,y}]+ mp[{x,-y}]))%mod;  // only take either side
            mp[{-x,y}]=0;
            mp[{x,-y}]=0;
            val=doo(val);    // subtract 1 as we subtract 2 times empty set 
            ans=(ans*val)%mod;
        }
        if((a>=0 && b>=0) || (a<=0 && b<=0))
        {
            pair<ll,ll> pp;
            x=abs(a); y=abs(b);
            // x/=gcd; y/=gcd;
            pp={-y,x};
             c+=mp[pp]; mp[pp]=0;
            pp={y,-x};
            c+=mp[pp]; mp[pp]=0;
            
           val=(power(2,c)+power(2,mp[{x,y}]+mp[{-x,-y}]))%mod;
           mp[{x,y}]=0; mp[{-x,-y}]=0;
            val=doo(val);
            ans=(ans*val)%mod;
        }
        // cout<<val<<endl;
    }
    ans=doo(ans);
    ans=(ans+cnt)%mod;
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int alice = 0, bob = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    for(int i = 0; i < n; ++i) {
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
L = list(input())
n = len(L)
mod = 10**9+7
 
dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 1
 
for i,c in enumerate(L):
    if c == '1':
        dp[i+1][0] = dp[i][0]*2%mod
        dp[i+1][1] = (dp[i][0]+dp[i][1]*3)%mod
    else:
        dp[i+1][0] = dp[i][0]%mod
        dp[i+1][1] = dp[i][1]*3%mod
print(sum(dp[-1])%mod)


Measured memory_bytes: 58104
from collections import deque
s = input()
q = int(input())
hanten = 0
ans = deque(s)
for _ in range(q):
    a = list(input().split())
    if a[0] == "1":
        hanten += 1
    else:
        if hanten % 2 == 0:
            if a[1] == "1":
                ans.appendleft(a[2])
            if a[1] == "2":
                ans.append(a[2])
        else:
            if a[1] == "1":
                ans.append(a[2])
            if a[1] == "2":
                ans.appendleft(a[2])
if hanten % 2 == 0:
    print(*ans, sep="")
else:
    ans.reverse()
    print(*ans, sep="")


Measured memory_bytes: 82480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		final double M_ADD = 360.0/60.0;
		final double H_ADD = M_ADD/12.0;
		final double alert = 30.0;
		final double safe = 90.0;
		
		//while(true){
			int n = Integer.parseInt(in.readLine());
			for(int i= 0; i < n;i++){
				String[] ss = in.readLine().split(":");
				double t = Double.parseDouble(ss[1]);
				double h = Double.parseDouble(ss[0]) * 60.0+ t;
				double ans = Math.abs(t*M_ADD-h*H_ADD);
				if(ans > 180){
					ans=360-ans;
				}
				if(ans < alert){
					System.out.println("alert");
				}
				else if(ans >= safe){
					System.out.println("safe");
				}
				else{
					System.out.println("warning");
				}
				
			}
		//}
		
	}
	

}

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

ll findpow(ll a,ll b){
    ll cnt=0,i,j;
    while(a>1){
        a=a/b;
        cnt++;
    }
    return cnt;
}

int main(){
    ll i,j,k,sum=0,flag=0,t,m,n,a,b,c,x,y;
 // string s1,s2,s;
   cin>>x>>y>>a>>b>>c;
   ll A[a],B[b],C[c];
   for(i=0;i<a;i++){
       cin>>A[i];
   }
   for(i=0;i<b;i++){
       cin>>B[i];
   }
   for(i=0;i<c;i++){
       cin>>C[i];
   }
   sort(A,A+a,greater<ll>());
   sort(B,B+b,greater<ll>());
   sort(C,C+c,greater<ll>());  
   vector <int> v;
   for(i=0;i<x;i++){
       v.push_back(A[i]);
   }
   for(i=0;i<y;i++){
       v.push_back(B[i]);
   }
   for(i=0;i<c;i++){
       v.push_back(C[i]);
   }
   sort(v.begin(),v.end(),greater<int>());
   for(i=0;i<x+y;i++){
      sum+=v[i];
   }
   
   cout<<sum<<endl;
   
   
       
    
	return 0;
}

Measured memory_bytes: 4724
# AOJ 1003: Extraordinary Girl II
# Python3 2018.7.4 bal4u

tbl = ["", "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", \
       "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"]

while True:
	try: s = input().strip()
	except: break
	ans, i = '', 0
	while i < len(s):
		c = s[i]
		w, d, i = 0, int(c), i+1
		while i < len(s) and s[i] == c: i, w = i+1, w+1
		if d == 0: ans += ' '*w
		else: ans += tbl[d][w%len(tbl[d])]
	print(ans)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
int main() {
  vec a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(all(a));
  ll div1=a[1]-a[0],div2=a[2]-a[1];
  if(div1%2==0&&div2%2==0){
    putout(div1/2+div2);
  }
  if(div1%2==1&&div2%2==0){
    putout(1+div2+(1+div1)/2);
  }
  if(div1%2==0&&div2%2==1){
    putout(div1/2+div2);
  }
  if(div1%2==1&&div2%2==1){
    putout(1+(1+div1)/2+div2);
  }
  
  
  
  
  
  
}


Measured memory_bytes: 256
// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)s.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}

int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll A (n);
mpll mp;
F (i,0,n,1) {cin>>A[i]; ++mp[A[i]];}
ll q; cin>>q;
ll sum = 0;
F (i,0,n,1) sum+=A[i];
F (i,0,q,1) {
	ll a , b; cin>>a>>b;
	sum=sum-mp[a]*a+mp[a]*b;
	mp[b]+=mp[a];
	mp.erase(a);
	cout<<sum<<endl;
}

return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/

Measured memory_bytes: 7956
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int N,K;
  int ret=0;
  int temp_K,i;
  
  cin >> N >> K;

  i=0;
  while(1){
    temp_K=pow(K,i);
    if(N/temp_K==0) break;
    i++;
    ret++;
  }

  cout << ret << endl;
  
  return 0;
}


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

int y[2],m[2],d[2];

int t[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int calc(int y,int m,int d){
  int cnt=(y-1)/4-(y-1)/100+(y-1)/400;
  int res = y*365;
  res=res+cnt+1-365;


  if(y%4==0&&(y%100!=0||y%400==0))t[2]++;
  int cnt2=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=(i==m?d-1:t[i]);j++){
      cnt2++;
    }
  }
  if(y%4==0&&(y%100!=0||y%400==0))t[2]--;

  return res+cnt2;
}


int main(){
  int a,b;
  while(cin>>y[0]>>m[0]>>d[0]>>y[1]>>m[1]>>d[1]){
    if(y[0]<0||m[0]<0||d[0]<0||y[1]<0||m[1]<0||d[1]<0)break;
    a=calc(y[0],m[0],d[0]);
    b=calc(y[1],m[1],d[1]);
    cout<<b-a<<endl;
  }

}

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

int main()
{
  int a,b,c;
  char str[100];
  while( scanf("%d%d",&a,&b) != EOF){
  c=sprintf(str,"%d",a+b);
  printf("%d\n",c);
  }
  return 0;
  }

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
int main(){
    string s,t,u; cin >> s >> t;
    int a,b; cin >> a >> b;
    cin >> u;
    if(s==u) cout << a-1 << " " << b;
    else cout << a <<" "<< b-1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}



signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n,m;
  cin>>n>>m;
  vector<T> A(n);
  for(Int i=0;i<n;i++){
    Int x,y,z;
    cin>>x>>y>>z;
    A[i] = T(x,y,z);
  }
    

  const Int N = 1010;
  auto calc=[&](Int a,Int b,Int c){
    vector<vector<Int> > dp(N, vector<Int>(N,-INF));
    dp[0][0] = 0;
    for(Int i=0;i<n;i++)
      for(Int j=0;j<=m;j++){
	Int x,y,z; tie(x, y, z) = A[i];
	Int score = x * a + y * b + z * c;
	Max(dp[i+1][j], dp[i][j]);
	if(j + 1 <= m) Max(dp[i+1][j+1], dp[i][j] + score);
      }
    return dp[n][m];
  };

  Int ans = -INF;
  for(Int i=-1;i<2;i++)
    for(Int j=-1;j<2;j++)
      for(Int k=-1;k<2;k++){
	if(i == 0 || j == 0 || k == 0) continue;
	Max(ans, calc(i,j,k));
      }
  
  cout<<ans<<endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,d,a;
    cin >> n >> d >> a;
    vector<pair<ll,ll>> xh(n);
    for(ll i = 0; i < n; i++) {
        cin >> xh[i].first >> xh[i].second;
    }
    sort(xh.begin(),xh.end());
    for(int i = 0; i < n; i++) {
        xh[i].second = (xh[i].second + a-1)/a;
    }

//    for(int i = 0; i < n; i++) {
//        cout << xh[i].first << " " << xh[i].second << "\n";
//    }
    queue<pair<ll,ll>> q;
    ll now=0;
    ll ans=0;
    for(ll i = 0; i < n; i++) {

        if(!q.empty()) {
            while(q.front().first<xh[i].first && !q.empty()) {
                now-=q.front().second;
                q.pop();
            }
        }

        if(xh[i].second>now){
            q.push(make_pair(xh[i].first+2*d,xh[i].second-now));
            ans+=xh[i].second-now;
            now=xh[i].second;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 7948
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long N = in.nextInt();
            long K = in.nextInt();

            long count = 0;
            for (long a = 1; a <= N; a++) {
                {
                    long b = (K * a - a) % K;
                    if (b == 0) {
                        b = K;
                    }
                    long c = (K * b - b) % K;
                    if (c == 0) {
                        c = K;
                    }
                    if ((c + a) % K != 0) {
                        continue;
                    }
                    count += ((N - b) / K + 1) * ((N - c) / K + 1);
                }
            }

            System.out.println(count);
        }
    }
}


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

using namespace std;

const int Nmax = 1e6;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int dp[Nmax][2];
char s[Nmax];

int main()
{/**
    #ifndef ONLINE_JUDGE
        ifstream cin("test.in");
        ofstream cout("test.out");
    #endif // ONLINE_JUDGE
*/

    cin >> (s + 1);

    for(int i = 1; i <= strlen(s + 1); i++)
        if(s[i] == '?') s[i] = 'D';

    cout << s + 1;
    return 0;
}


Measured memory_bytes: 3796
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make(map[int]int)
	sum := 0
	for i := 0; i < n; i++ {
		input := nextInt()
		a[input]++
		sum += input
	}
	q := nextInt()
	ans := make([]string, q)
	for i := 0; i < q; i++ {
		b := nextInt()
		c := nextInt()
		sum += (c - b) * a[b]
		a[c] += a[b]
		a[b] = 0
		ans[i] = strconv.Itoa(sum)
	}
	for _, str := range ans {
		fmt.Println(str)
	}
	return
}


Measured memory_bytes: 11912
const  MAXN = 100000;
var n: longint;
      a, f, g: array[0..MAXN] of longint;

procedure Nhap;
var i: longint;
begin
        readln(n);
        for i:= 1 to n do read(a[i]);
end;

procedure QT;
var i: longint;
begin
        f[0]:= 0;
        g[n+1]:= 0;  ///Phan tu dung canh
        for i:= 1 to n do f[i]:= f[i-1] + abs(a[i] - a[i-1]);
        for i:= n downto 1 do
                g[i]:= g[i+1] + abs(a[i+1] - a[i]);
        for i:= 1 to n do
                writeln(f[i-1] + g[i+1] + abs(a[i+1]-a[i-1]));
end;

BEGIN
        Nhap;
        QT;
END.


Measured memory_bytes: 2304
n, a, b = map(int, input().split())
ls = [int(input()) for _ in range(n)]


def check(k):
    return sum([(x - k * b + a - b - 1) // (a - b)
                for x in ls if x - k * b > 0]) <= k


m = max(ls)
lo = (m + a - 1) // a
hi = (m + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if check(mi):
        hi = mi
    else:
        lo = mi
if check(lo):
    print(lo)
else:
    print(hi)

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

int main(){
    const double pi = 3.1415926535;
    double r; cin >> r;
    printf("%.20lf\n", 2*pi*r);

    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int d[k];

    for( int i = 0; i < k; ++i ) cin >> d[i];
    
    bool flg = false;
    while( !flg ) {
        int tmp = n;
        bool tmpflg = true;
        while( tmp > 0 ) {
            int dig = tmp % 10;
            bool digflg = true;
            for( int i = 0; i < k; ++i ) {
                if( dig == d[i] ) {
                    digflg = false;
                    break;

                }
            }
            if( !digflg ) {
                tmpflg = false;
                break;
            }
            tmp /= 10;
        }
        if( tmpflg ) {
            cout << n << endl;
            flg = true;
        }
        ++n;
    }
    return 0;
}



Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt

  def next(s: String, max: Char): Unit = {
    if (s.size == N) println(s)
    else {
      ('a' to (max + 1).toChar).foreach {c =>
        next(s + c, max max c)
      }
    }
  }

  next("a", 'a')
}


Measured memory_bytes: 58592
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
s = arr_data[1][0]

#print(n, s)

x = 0

maxdata = x

for v in s:
    
#    print(v)
    
    if v == "D":
        
        x -= 1
        
    elif v == "I":
        
        x += 1
        
    maxdata = x if maxdata<x else maxdata
    
    
print(maxdata)

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

int main(){
  int n; cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      sum += d.at(i) * d.at(j);
    }
  }
  
  cout << sum << endl;
  
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using sl = stack<ll>;
using ql = queue<ll>;

const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};


void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vl a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    float D, T, S;
    cin >> D >> T >> S;
    if(D/T <= S){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3724
from operator import itemgetter
n=int(input())
y,s=list(),list()
for i in range(1,n+1):
	S=input().split()
	S[1]=int(S[1])
	S.append(i)
	s.append(S)
y=sorted(s,key=itemgetter(0))
for i in range(n):
	for j in range(1,n):
		if((y[j-1][0]==y[j][0])&(y[j-1][1]<y[j][1])): y[j-1],y[j]=y[j],y[j-1]
for i in range(n):
	print(y[i][2])

Measured memory_bytes: 3064
import sys
from collections import defaultdict

n, m = map(int, input().split())
ac = 0
wa = defaultdict(lambda: 0)
already = set()
for line in sys.stdin:
    y, z = line.strip().split()
    y = int(y)
    if y in already:
        continue
    if z == 'AC':
        ac += 1
        already.add(y)
    else:
        wa[y] += 1
    
print(ac, sum(wa[i] for i in already))

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

int main() {
	int N;
	cin >> N;
	int T, A;
	cin >> T >> A;
	double min = 100000.0;
	int min_id = 0;
	for (int i = 0; i < N; i++) {
		int H;
		cin >> H;
		double dif = abs(T - 0.006 * H - A);
		if (dif < min) {
			min = dif;
			min_id = i+1;
		}
	}
	cout << min_id;
}

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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int D = A + B;
    if (D >= C)
    {
        cout << C + B << endl;
    }
    else
    {
        cout << D + B + 1<< endl;
    }
}

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

int main(){
    
    std::string s;
    int m, h;
    std::string s_tmp;
    while(std::cin >> s){
        if(s=="-") break;
        std::cin >> m;
        while(m--){
            std::cin >> h;
            std::rotate(s.begin(), s.begin()+h, s.end());
        }
        std::cout << s << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3224