akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#include<math.h>

int main() {
  long long int x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  if(k <= x/d) {
    cout << abs(x) - abs(k*d) << endl;
    return 0;
  } else {
    long long int md = x % d;
    long long int div = x / d;
    if((k-div)%2 == 0) {
      cout << md << endl;
    } else {
      cout << d - md << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
use std::fmt::Write;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let ax = read_vec::<usize>();

    let mut v = vec![0; n];

    for (i, &a) in ax.iter().enumerate() {
        v[a-1] = i + 1;
    }

    let mut ans = String::new();

    write!(ans, "{}", v[0]).unwrap();
    

    for i in v.iter().skip(1) {
        write!(ans, " {}", i).unwrap();
    }

    println!("{}", ans);
}

Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    string n;
    cin >> n;

    if (n.at(n.size() - 1) == '3')
    {
        cout << "bon" << endl;
    }
    else if ((n.at(n.size() - 1) == '0') || (n.at(n.size() - 1) == '1') || (n.at(n.size() - 1) == '6') || (n.at(n.size() - 1) == '8'))
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    string s;
    cin1(s);
    s.erase(7,1);
    s.erase(4,1);
    lli x = atoi(s.c_str());
    if (x <= 20190430)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;


}


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

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

    // 答えを格納するための変数
    int ares = -1, bres = -1, cres = -1;

    // 全探索
    for (int a = 0; a <= N; ++a) {
        // a + b が N 以下の範囲で
        for (int b = 0; a + b <= N; ++b) {
            int c = N - a - b;
            if (10000 * a + 5000 * b + 1000 * c == Y) {
                ares = a;
                bres = b;
                cres = c;
            }
        }
    }
    cout << ares << " " << bres << " " << cres << endl;
}

Measured memory_bytes: 3480
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2e5+5;
int a[N];
ll n,k;
int cnt=0;
int vis[N];
int flag=0;
void dfs(int now){
//	de(now);
	if(vis[now]&&flag==0){
		flag=1;
		int d=cnt+1-vis[now];
		k%=d;
		while(k<cnt+1){
			k+=d;
		}
	}
//	de(k);
	vis[now]=++cnt;
	if(cnt==k){
		printf("%d",now);
		exit(0);
	}
	dfs(a[now]);
}
int main()
{
	
	scanf("%lld%lld",&n,&k);
	k++;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	dfs(1);
}


Measured memory_bytes: 5388
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	ll h, w, x, y;
	cin >> w >> h >> x >> y;
	bool judge;
	long double ans;
	if (h%2==0&&w%2==0) {
		ans = h * w / 2;
		if (w == 2 * x && h == 2 * y)judge = true;
	}
	else {
		judge = false;
		ans = h * w;
		ans /= 2;
	}
	cout << ans << " " <<judge<< endl;
	return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

map<int,int> mp;
void factorize(int n){
    int x = n;
    for(int i=2;i<=n;i++){
        while(x%i == 0){
            mp[i]++;
            x/=i;
        }
    }
    if(x != 1)mp[x]++;
}

int rec(map<int,int>::iterator p,int sub){
    if(p == mp.end()){
        if(sub == 1)return 1;
        else return 0;
    }
    int res = 0;
    for(int i=1;i<=p->second+1;i++){
        if(sub % i != 0)continue;
        res += rec(++p,sub/i);
        p--;
    }
    return res;
}
signed main(){
    gearup;
    ll n;cin>>n;
    for(int i=2;i<=n;i++){
        factorize(i);
    }
    //for(auto m:mp)cout << m.first << " " << m.second << endl;
    ll res = rec(mp.begin(),75);
    out(res);
}

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

int main()
{
    int n;
    cin >> n;
    int array[n];
    for (int i = 0; i < n; i++)
    {
        cin >> array[i];
    }

    int min = array[0];
    int max = array[0];
    long sum = 0;

    for (int i = 0; i < n; i++)
    {
        if (array[i] > max)
        {
            max = array[i];
        }
        else if (min > array[i])
        {
            min = array[i];
        }
        
        sum += array[i];
    }

    cout << min << " " << max << " " << sum << endl;
}


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

int Min(int a,int b,int c){
  return min(a,min(b,c));
}

int main(){
  string X,Y;
  cin>>X>>Y;
  vector<vector<int> > v(X.size()+1,vector<int>(Y.size()+1,0));
  for(int i=0;i<=X.size();i++) v[i][0]=i;
  for(int i=0;i<=Y.size();i++) v[0][i]=i;
  for(int i=0;i<X.size();i++){
    for(int j=0;j<Y.size();j++){
      v[i+1][j+1] = Min(v[i][j]+(X[i]!=Y[j]),v[i+1][j]+1,v[i][j+1]+1);
      
    }
  }
  cout<<v[X.size()][Y.size()]<<endl;
  return 0;
}

Measured memory_bytes: 4964
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void LCS( string s1, string s2, int m, int n )
{
   int L[m+1][n+1];

   /* Following steps build L[m+1][n+1] in bottom up fashion. Note
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (s1[i-1] == s2[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }

   // Following code is used to print LCS
   int index = L[m][n];

   // Create a character array to store the lcs string
   char lcs[index+1];
   lcs[index] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (s1[i-1] == s2[j-1])
      {
          lcs[index-1] = s1[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }

   // Print the lcs
   cout << lcs<<endl;
}

/* Driver program to test above function */
int main()
{
  string s1,s2;
  cin>>s1>>s2;
  int m = s1.size();
  int n = s2.size();
  LCS(s1,s2, m, n);
  return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

// namespace
using namespace std;
namespace mp = boost::multiprecision;

// types
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
using mpi = mp::cpp_int;
using mpf = mp::number<mp::cpp_dec_float<1024>>;

// consts
int MOD = 1000000007;  // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a


ll solve(ll n, ll k, ll i, vector<ll> &v, const vector<ll> &a) {
    if (n - i < k) return numeric_limits<ll>::max();
    if (i == n) {  // k should be zero
        ll m = a[v[0]];
        ll j = 0;
        for (; j < v[0]; ++j) m = max(m, a[j]);
        ll ret = 0;
        for (const auto &ix: v) {
            ret += max(static_cast<ll>(0), m - a[ix]);
            for (; j < ix; ++j) m = max(m, a[j]);
            m = max(m + 1, a[ix] + 1);
        }
        return ret;
    }

    ll ret = numeric_limits<ll>::max();
    if (k > 0) {
        v.push_back(i);
        ret = min(ret, solve(n, k - 1, i + 1, v, a));
        v.pop_back();
    }
    ret = min(ret, solve(n, k, i + 1, v, a));
    return ret;
}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) cin >> a[i];

    vector<ll> v;
    ll ans = solve(n, k, 0, v, a);
    cout << ans << endl;
    return 0;
}


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

int main(){
  long double W,H,x,y;
  cin>>W>>H>>x>>y;
  cout<<fixed<<setprecision(1)<<W*H/2.0<<' ';
  if(W==x*2 && H==y*2)
    cout<<1<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 256
d={}
for i in range(int(input())+1):
  for j in d:
    while i>j-1 and i%j<1: d[j]+=1; i//=j
  if i>1: d[i]=2
a=1
for v in d.values(): a=a*v%(10**9+7)
print(a)

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

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
  ll n;
  cin >> n;
  
  map< ll, int > r;
  r = prime_factor(n);
  
  int c = 0;
  for(auto p : r) {
    int l = p.second;
    int k = 1;
    for(int i=1;i<=l;i++){
      if( k*(k+1)/2 == i ){
        c++;
        k++;
      }
    }
    
  }
  cout << c << endl;
  return 0;
  
}



Measured memory_bytes: 3608
#include<stdio.h>
int n,A[20];

int search(int i,int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  int res = search(i+1,m)||search(i+1,m-A[i]);
  return res;
}
      
int main(){
  int q,m,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(search(0,m))
      printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2108
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt = 0;
        for (char s : sc.next().toCharArray()) {
            if (s == '1') cnt++;
        }
        System.out.println(cnt);
    }

}


Measured memory_bytes: 21972
#include<stdio.h>
#include<stdlib.h>
#define N 100001
#define B -1

typedef struct{
  int parent;
  int left;
  int right;
} Tree;

Tree T[N];

int sibilings(int);
int degree(int);
int depth_c(int);
int hight(int);
void print(int);

main(){
  int i,j,p,l,r,n;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    T[i].parent = B;
    T[i].left = B;
    T[i].right = B;
  }
  for(i=0; i<n; i++){
    scanf("%d%d%d",&p,&l,&r);
    T[l].parent = p;
    T[r].parent = p;
    T[p].left = l;
    T[p].right = r;
   }
  for(i=0; i<n; i++){
    print(i);
   }
  return 0;
}

int sibilings(int a){
  if(T[a].parent == B){
    return -1;
  }
  else if(T[T[a].parent].left == a){
    return T[T[a].parent].right;
  }
  else return T[T[a].parent].left;
}

int degree(int b){
  if(T[b].left ==B && T[b].right == B){
    return 0;
  }
  else if(T[b].left !=B && T[b].right != B){
    return 2;
  }
  else 
    return 1;
}

int depth_c(int c){
  int count = 0;
  if(T[c].parent == B){
    return 0;
  }
  else{
    count = depth_c(T[c].parent) + 1;
    return count;
  }
}

int hight(int e){
  int lh = 0, rh = 0;
  if(T[e].left != B){
    lh = hight(T[e].left) + 1;
  }
   if(T[e].right != B){
    rh = hight(T[e].right) + 1;
  }
   if(lh < rh){
     return rh;
   }
   else
     return lh;
}

void print(int f){
  printf("node %d: parent = %d, sibling = %d, degree = %d, ",f, T[f].parent, sibilings(f),degree(f));
  printf("depth = %d, height = %d, ",depth_c(f),hight(f));
  if(T[f].parent == B){
    printf("root\n");
  }
  else if(T[f].left == B && T[f].right == B){
    printf("leaf\n");
  }
  else 
    printf("internal node\n");
}

Measured memory_bytes: 612
import numpy as np

N = int(input())

address_list = []
for i in range(N):
    x, y = map(int, input().split())
    address_list.append([x, y])
    
distance_list = np.zeros([N, N])
for l in range(N):
    for m in range(N):
        x_1 = address_list[l][0]
        y_1 = address_list[l][1]
        x_2 = address_list[m][0]
        y_2 = address_list[m][1]
                              
        distance_list[l][m] = np.sqrt((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2)
        
ans = distance_list.sum() / N
print(ans)

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

int main()
{
    int H, N, Ai;
    cin >> H >> N;
    while(N>0 && H>0)
    {
        cin >> Ai;
        H-=Ai;
        N--;
    }
    if(H<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

class Main{
	static char tiles[][];
	static String dstrs[][];
	static String max_str;

	public static void main(String args[]){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			while(true){
				// 縦と横を取得
				String strs[] = br.readLine().split(" ");
				int w = Integer.parseInt(strs[0]);
				if(w == 0) return;
				int h = Integer.parseInt(strs[1]);
				max_str = "0";


				// 配列を初期化
				tiles = new char[h][w];
				dstrs = new String[h][w];
				//System.out.println(h + " " + w);

				// 入力を配列に詰めていく
				for(int y = 0; y < h; y++){
					String str = br.readLine();
					for(int x = 0; x < w; x++){
						tiles[y][x] = str.charAt(x);
					}
				}
				//printMatrix(tiles);

				for(int y = 0; y < h; y++){
					for(int x = 0; x < w; x++){
						dp(x, y);
					}
				}
				//printMatrix(dstrs);
				System.out.println(max_str);
			}
		}catch(Exception e){
			System.err.print(e);
		}
	}

	static void dp(int x, int y){
		//System.out.println("計算: (" + x + ", " + y + ")");
		char target = tiles[y][x];
		if('0' <= target && target <= '9'){
			// 端だったらそのまま投入
			if(x == 0 && y == 0){
				dstrs[y][x] = "" + target;
			}else if(x == 0){
				dstrs[y][x] = dstrs[y-1][x] + target;
			}else if(y == 0){
				dstrs[y][x] = dstrs[y][x-1] + target;
			}else{
				dstrs[y][x] = max(dstrs[y-1][x], dstrs[y][x-1]) + target;
			}
			if(dstrs[y][x].equals("0")){
				dstrs[y][x] = "";
				return;
			}
			max_str = max(dstrs[y][x], max_str);
		}else{
			dstrs[y][x] = "";
		}
	}

	static String max(String str1, String str2){
		//System.out.println("大小比較: " + str1 + "\t" + str2);
		if(str1.length() == 0) return str2;
		if(str2.length() == 0) return str1;

		int length1 = str1.length();
		int length2 = str2.length();
		if(length1 > length2){
			return str1;
		}else if(length1 < length2){
			return str2;
		}
		BigInteger num1 = new BigInteger(str1);
		BigInteger num2 = new BigInteger(str2);
		if(num1.compareTo(num2) == 1){
			return str1;
		}else if(num1.compareTo(num2) == -1){
			return str2;
		}
		return str1;
	}

	static void printMatrix(char matrix[][]){
		for(int i = 0; i < matrix.length; i++){
			for(int j = 0; j < matrix[i].length; j++){
				System.out.print(matrix[i][j] + "\t");
			}
			System.out.println();
		}
	}

	static void printMatrix(String matrix[][]){
		for(int i = 0; i < matrix.length; i++){
			for(int j = 0; j < matrix[i].length; j++){
				System.out.print(matrix[i][j] + "\t");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 75892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, Q;
    cin >> N >> Q;
    using P = pair<ll, string>;

    queue<P> q;
    rep(i, N){
        string s;
        ll t;
        cin >> s >> t;
        q.emplace(t, s);
    }

    ll T = 0;
    while(!q.empty()){
        string s;
        ll t;
        tie(t, s) = q.front(), q.pop();
        if(t<=Q){
            T += t;
            cout << s << " " << T << '\n';
        }
        else{
            T += Q;
            t -= Q;
            q.emplace(t, s);
        }
    }
}


Measured memory_bytes: 6368
#include <iostream>
#include <stdint.h>
#include <vector>
#include <utility>

using namespace std;

int main()
{
  uint32_t N;
  cin >> N;
  vector<uint64_t> A;
  A.reserve(N);
  
  for (int ii=0; ii<N; ++ii) {
    uint64_t a;
    cin >> a;
    A.push_back(a);
  }

  uint64_t count = 0;

  vector<uint64_t> fl(N,1);

  uint64_t l=0,r=0;
  uint64_t DPXOR, DPSUM;
  DPXOR = DPSUM = A[0];

  bool check_prev, check_now;
  
  while ( r < N ) {
    check_now = (DPXOR==DPSUM);

    if (!check_now && check_prev)
      for (int ll = l; ll < r; ++ll)
	fl[ll] = r-ll;
    
    if (check_now) {
      ++r;
      DPXOR ^= A[r];
      DPSUM += A[r];
    } else {
      DPSUM -= A[l];
      DPXOR ^= A[l];
      ++l;
    }

    check_prev = check_now;
  }

  for (int ll = l; ll < r; ++ll)
    fl[ll] = r-ll;

  for (int l = 0; l<N; ++l)
    count += fl[l];

  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
  ll n,ans=1;
  cin>>n;
  
  vll a(n),b(n+1,0);
  b.at(0)=3;
  rep(i,n)cin>>a.at(i);
  
  rep(i,n){
      ans*=b.at(a.at(i));
      ans%=1000000007;

      b.at(a.at(i))--;
      b.at(a.at(i)+1)++;
  }
   
   
   cout<<ans<<endl;
}



Measured memory_bytes: 4844
import itertools
import math
from functools import reduce

n, k = map(int, input().split())

pattern = 0

for i in range(k, n + 2):
    min = i * (0 + i - 1) // 2
    max = i * (n + n - i + 1) // 2
    pattern += max - min + 1
    
pattern %= 10 ** 9 + 7
    
print(pattern)

Measured memory_bytes: 9616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	string S; cin >> S;
    int cnt = 0;
    for(auto s:S){
        cnt += s-'0';
    }
    printf("%s\n", (cnt%3==0)?"Yes":"No");
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3728
N = int(input())
S = list(map(int, input().split()))
ans = 0
leaf = 1
for i in range(N+1):
    if S[i] > leaf:
        ans = -1
        break
    leaf -= S[i]
    leaf *= 2
if ans == -1:
    print(ans)
else:
    dm = [0]*(N+1)
    dm[0] = 1
    for i in range(1, N+1):
        dm[i] = dm[i-1]*2 - S[i]
    leaf = 0
    for i in range(N, -1, -1):
        ans += min(leaf, dm[i]) + S[i]
        leaf += S[i]
    print(ans)


Measured memory_bytes: 668728
import java.util.*;
public class Main {
    int[][] mapA = new int[5][4];
    int[][] mapB = new int[4][5];
    int x, y, d;
    boolean flag;
    void U(){
        if(flag==true && y>0 && mapB[y-1][x]==1){
            d=0;
            y--;
            flag = false;
            System.out.print("U");
        }
    }
    void R(){
        if(flag==true && x<4 && mapA[y][x]==1){
            d=1;
            x++;
            flag = false;
            System.out.print("R");
        }
    }
    void D(){
        if(flag==true && y<4 && mapB[y][x]==1){
            d=2;
            y++;
            flag = false;
            System.out.print("D");
        }
    }
     
    void L(){
        if(flag==true && x>0 && mapA[y][x-1]==1){
            d=3;
            x--;
            flag = false;
            System.out.print("L");
        }
    }
    void solve(){
        Scanner sc = new Scanner(System.in);
         
        for(int i=0;i<9;i++){
            String s = sc.next();
            if(i%2==0){
                for(int j=0;j<4;j++) mapA[i/2][j] = s.codePointAt(j)-48;
            }else{
                for(int j=0;j<5;j++) mapB[i/2][j] = s.codePointAt(j)-48;
            }
        }
        x = 0;
        y = 0;
        d = 1;
 
        while(true){
            flag = true;
            if(d==0){
                L();
                U();
                R();
                D();
            }else if(d==1){
                U();
                R();
                D();
                L();
            }else if(d==2){
                R();
                D();
                L();
                U();
            }else if(d==3){
                D();
                L();
                U();
                R();
            }
             
            if(x==0 && y==0){
                System.out.println();
                break;
            }
        }
    }
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 15272
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

achievable = True

for i in range(h):
    for j in range(w):
        x = grid[i][j]
        
        if x == '#':
            count = 0
            if i - 1 >= 0 and grid[i - 1][j] == '#':
                count += 1
            if i + 1 < h and grid[i + 1][j] == '#':
                count += 1
            if j - 1 >= 0 and grid[i][j - 1] == '#':
                count += 1
            if j + 1 < w and grid[i][j + 1] == '#':
                count += 1
            
            if count == 0:
                achievable = False
                
print('Yes' if achievable else 'No')

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef vector<int> vi;

const int D = 300, E = 351, MX = 100005;
// Binary Indexed Tree
struct bit {
  vector<int> d; int n, hi;
  vi hist;
  bit() {}
  bit(int mx): n(mx), d(mx), hist(MX), hi(0) {}
  void add(int i, int x=1) {
    for (++i;i<n;i+=i&-i) {
      d[i] += x;
    }
  }
  void add2(int i, int x=1) {
    for (++i;i<n;i+=i&-i) {
      hist[hi++] = i;
      d[i] += x;
    }
  }
  int sum(int i) {
    int x = 0;
    for (++i;i;i-=i&-i) x += d[i];
    return x;
  }
  void rev() {
    d = vi(n);
  }
  void rev2() {
    while (hi--) d[hist[hi]] = 0;
    hi = 0;
  }
};
//
int n, a[MX];
ll dl[E][MX], dr[E][MX];
int main() {
  // preprocess
  scanf("%d",&n);
  rep(i,n) scanf("%d",&a[i]), a[i] = n-a[i];
  bit t(n+2);
  for (int i = 0; i <= n; i += D) {
    int di = i/D;
    ll sum = 0;
    for (int j = i; j < n; ++j) {
      sum += t.sum(a[j]);
      dl[di][j] = sum;
      t.add(a[j]);
    }
    t.rev();
    sum = 0;
    for (int j = i-1; j >= 0; --j) {
      sum += t.sum(n-a[j]);
      dr[di][j] = sum;
      t.add(n-a[j]);
    }
    t.rev();
  }
  // online query
  int q;
  scanf("%d",&q);
  rep(qi,q) {
    int l, r;
    scanf("%d%d",&l,&r);
    --l;
    ll ans = 0;
    if (r-l <= D) {
      for (int i = l; i < r; ++i) {
        ans += t.sum(a[i]);
        t.add2(a[i]);
      }
      t.rev2();
    } else {
      int li = l/D+1, ri = r/D;
      ans += dl[li][r-1];
      ans += dr[ri][l];
      ans -= dl[li][ri*D-1];
      vi p;
      for (int i = li*D-1; i >= l; --i) p.pb(a[i]<<1);
      for (int i = ri*D; i < r; ++i) p.pb(a[i]<<1|1);
      sort(p.begin(), p.end());
      int s = 0;
      rep(i,sz(p)) {
        if (p[i]&1) ans += s;
        else s++;
      }
    }
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 267636
# dp[l][r]=min(区間[l,r]を合成するための最小コスト)
n=int(input())
a=list(map(int,input().split()))
INF=10**15
dp=[[0]*n for i in range(n)]
for i in range(n):
    dp[i][i]=a[i]
# 合成するときの必要経費を構成
for i in range(n-1):
    for j in range(i+1,n):
        dp[i][j]=dp[i][j-1]+a[j]
dp[0][-1]=0
# dp[i][j]=min(dp[i][k]+dp[k+1][j])+必要経費 で斜め(0,1),(1,2),(0,2),(1,3),...の順に見ていく
# ループの書き方に手間取った
for i in range(1,n):
    for j in range(n-i):
        ans=INF
        for k in range(j,i+j):
            ans=min(ans,dp[j][k]+dp[k+1][i+j])
        dp[j][i+j]+=ans
print(dp[0][-1])

Measured memory_bytes: 43244
/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on July 27, 2018, 11:53 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100000
#define INFTY 1000000001

typedef struct{
    char suit;
    int num;
}Poker;
/*
 * 
 */

Poker Left[MAX_SIZE/2 + 2], Right[MAX_SIZE/2 + 2];
int count = 0;

void merge(Poker A[], int left, int mid, int right);
void mergeSort(Poker A[], int left, int right);
void quickSort(Poker A[], int left, int right);
int partition(Poker A[], int left, int right);

int main(int argc, char** argv) {
    Poker A[MAX_SIZE], B[MAX_SIZE];
    int  n, temp, stability = 1;
    char C[11];
    
    scanf("%d", &n);
    for (int ix = 0; ix < n; ++ix) 
    {
        scanf("%s %d", C, &temp);
        A[ix].suit = C[0];
        B[ix].suit = C[0];
        A[ix].num = temp;
        B[ix].num = temp;
    }
    
    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);
    
    for (int k = 0; k < n; ++k) if (A[k].suit != B[k].suit) stability = 0;
    
    if (stability == 1) printf("Stable\n");
    else { printf("Not stable\n"); }
    
    for (int kx = 0; kx < n; ++kx) printf("%c %d\n", B[kx].suit, B[kx].num);
    
    return (EXIT_SUCCESS);
}

void quickSort(Poker A[], int left, int right)
{
    if (left < right)
    {
        int mid = partition(A, left, right);
        quickSort(A, left, mid-1);
        quickSort(A, mid+1, right);
    }
}
int partition(Poker A[], int left, int right)
{
    Poker temp;
    int x = A[right].num;
    int i = left-1;
    for (int j = left; j < right; ++j)
    {
        if (A[j].num <= x)
        {
            i = i + 1;
//            strcmp(temp.suit , A[i].suit);
//            temp.num = A[i].num;
//            strcmp(A[i].suit, A[j].suit);
//            A[i].num = A[j].num;
//            strcmp(A[j].suit, temp.suit);
//            A[j].num = temp.num;
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
//    strcmp(temp.suit , A[i+1].suit);
//    temp.num = A[i+1].num;
//    strcmp(A[i+1].suit, A[right].suit);
//    A[i+1].num = A[right].num;
//    strcmp(A[right].suit, temp.suit);
//    A[right].num = temp.num;
    temp = A[i+1];
    A[i+1] = A[right];
    A[right] = temp;
    
    return i+1;        
}

void merge(Poker A[], int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; ++i) Left[i] = A[left + i];
    for (int j = 0; j < n2; ++j) Right[j] = A[mid + j];
    Left[n1].num = INFTY;
    Right[n2].num = INFTY;
    int i = 0, j = 0;
    for (int k = left; k < right; ++k)
    {
        if (Left[i].num <= Right[j].num)
        {
            A[k] = Left[i];
            i = i + 1;
        }
        else 
        { 
            A[k] = Right[j]; 
            j = j + 1;
        }
        count++;
    }
}

void mergeSort(Poker A[], int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}






Measured memory_bytes: 4104
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#define inf 0x3f3f3f3f
using namespace std;

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

int prime[1000010];
bool IsPrime[1000010];


void init() {
	memset(prime,inf,sizeof(prime));
	memset(IsPrime,true,sizeof(IsPrime));
	int num=0;
	for(int i=2; i<999999; i++) {
		if(IsPrime[i]) {
			prime[num++]=i;
			if(i<=sqrt(999999)) {
				for(int j=i*i; j<999999; j=j+i) {
					IsPrime[j]=false;
				}
			}
		}
	}
}
int main() {

	int x;
	init();
	while(scanf("%d",&x)!=EOF) {
		printf("%d\n",upper_bound(prime,prime+999999,x)-prime);
	}

	return 0;
}



Measured memory_bytes: 8064
#pragma GCC optimize(100) //O2ÓÅ»¯£¿

#include<bits/stdc++.h>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 9223372036854775807
#define END(s) {cout<<s;return 0;}
#define CON(s) {cout<<s;continue;}
#define BRE(s) {cout<<s;break;}
#define pb push_back
#define All(a) a.begin(),a.end()  //with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
#define LOCAL_JUDGE 1 //remember to change
using namespace std;

map<long long,int> m;

int main(){
	ios::sync_with_stdio(false);
	long long sum=0,res=0;
	int n;
	cin>>n;
	m[0]=1;
	rep(i,n){
		int x;
		cin>>x;
		sum+=x;
		res+=m[sum];
		m[sum]++;
	}
	cout<<res;
	return 0;
}

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

fn main(){
    let m:i32 = read();
    let mut k:i32 = m;
    let mut sum:i32 = 0;
    while k > 0{
        sum += k % 10;
        k /= 10;
    }
    if(m % sum == 0){
        println!("Yes");
    }
    else{
        print!("No");
    }
}

Measured memory_bytes: 4352
inp = list(input().split())
s = list()

for i in inp:
    if i == "+":
        a = int(s.pop())
        b = int(s.pop())
        s.append(b+a)
    elif i == "-":
        a = int(s.pop())
        b = int(s.pop())
        s.append(b-a)
    elif i == "*":
        a = int(s.pop())
        b = int(s.pop())
        s.append(b*a)
    else:
        s.append(i)

print(s[0])


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

int a[3][100010], v1[100010], v2[100010];
priority_queue<int, vector<int>, greater<int> > q1;
priority_queue<int> q2;
signed main(){
	int n, ans1 = 0, ans2 = 0;
	scanf("%lld", &n);
	for(int j = 0;j < 3;j++){
		for(int i = 1;i <= n;i++){
			scanf("%lld", &a[j][i]);
		}
	}
	for(int i = 1;i <= n;i++){
		q1.push(a[0][i]);
		ans1 += a[0][i];
	}
	for(int i = 1;i <= n;i++){
		q2.push(a[2][i]);
		ans2 += a[2][i];
	}
	
	int ans = ans1-ans2, mx = 0;
	for(int i = 1;i <= n;i++){
		int v = q1.top();
		if(v < a[1][i]){
			q1.pop();
			q1.push(a[1][i]);
			v1[i] = a[1][i]-v;
		}
		v1[i] += v1[i-1];
	}
	for(int i = 1;i <= n;i++){
		int v = q2.top();
		if(v > a[1][n-i+1]){
			q2.pop();
			q2.push(a[1][n-i+1]);
			v2[i] = v-a[1][n-i+1];
		}
		v2[i] += v2[i-1];
	}
	for(int i = 0;i <= n;i++){
		mx = max(mx, v1[i]+v2[n-i]);
	}
	/*for(int i = 0;i <= n;i++)printf("%d ", v1[i]);
	printf("\n");
	for(int i = 0;i <= n;i++)printf("%d ", v2[i]);
	printf("\n");*/
	printf("%lld\n", ans+mx);
	return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define db "knapsack"
#define fi first
#define se second
#define endl '\n'
const int INF = 1e9 + 1;
const int maxN = 1e5 + 2;
const int mod = 1e9 + 7;
typedef long long ll;
typedef int Array[maxN];
typedef ll LLArray[maxN];
typedef pair<int, int> PII;
typedef PII PIIArray[maxN];

void docfile()
{
    if (ifstream("FORM.inp"))
    {
        freopen("FORM.inp", "r", stdin);
        freopen("FORM.out", "w", stdout);
    }
    else if (ifstream(db".inp"))
    {
        freopen(db".inp", "r", stdin);
        freopen(db".out", "w", stdout);
    }
}

//-----------------------------------------------------------------------------
int k, x;

void solve()
{
    for(int i = x - k + 1; i <= x + k - 1; i++) cout << i << " ";
}

void input()
{
    cin >> k >> x;
    solve();
}

int main()
{
    docfile();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    input();
}


//-----------------------------------------------------------------------------
/*
template <typename T>
void write (T a)
{
    if (a < 0)
    {
        putchar ('-');
        write (-a);
        return;
    }
    if (a < 10)
    {
        putchar ('0' + a);
        return;
    }
    write (a / 10);
    putchar ((char)('0' + (a % 10)));
}

void read(long long& x)
{
    x = 0;
    int f = 1;
    char ch = getchar();
    while (!isdigit(ch))
        f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch))
        x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}
*/




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define RALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // a*10+7 mod k = 0
    int k;
    cin >> k;
    int a=7,cnt=1;
    while ( 1 ) {
        a%=k;
        if ( cnt>k ) {
            cout << -1 << '\n';
            return 0;
        }
        if ( a%k==0 ) break;
        a=(LL)a*10+7;
        cnt++;
    }
    cout << cnt <<'\n';
    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

char otp[1000000];
int otp_p = 0;


inline void read(int &sum) {
    char ch=getchar();int _sum=0,tf;
    while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    tf=((ch=='-')&&(ch=getchar()));
    while (ch>='0'&&ch<='9') _sum=_sum*10+(ch-48),ch=getchar();
    sum=tf?-_sum:_sum;
}
inline void read(char *c) {
    char ch=getchar();int p=0;
    while (ch==' '||ch=='\n') ch=getchar();
    while (ch!=' '&&ch!='\n'&&ch!=-1) {*c=ch;ch=getchar();++c;}
    *c='\0';
}
inline void print(int k) {
    char num_s[16];int i = 0;
    if (k<0){*(otp+otp_p)='-';k=-k;++otp_p;}
    while (k) {*(num_s+i)='0'+k%10;k/= 10;++i;}
    while (i) {--i;*(otp+otp_p)=*(num_s+i);++otp_p;}
}
inline void print(string s){
    int j = s.size();otp_p += j;
    for(int i=0;i<j;){*(otp+otp_p-j)=s[i];++i;--j;*(otp+otp_p-i)=s[j];}
}
inline void print(char *c){while (*c!='\0'){*(otp+otp_p)=*c;++c;++otp_p;}}
inline void print() {*(otp+otp_p) = '\0';printf("%s", otp);}


int main() {
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
    int n,k;
    char s[1000];
    read(n);
    read(k);
    read(s);
    *(s+k-1) += 'a'-'A';
    print(s);
    print("\n");
    print();
    return 0;
}

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

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	@SuppressWarnings({ "unused", "unchecked" })
	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			int m = scanner.nextInt();
			int s = scanner.nextInt();
			int g1 = scanner.nextInt();
			int g2 = scanner.nextInt();
			if ((n | m | s | g1 | g2) == 0)
				break;
			s--;
			g1--;
			g2--;
			int[][] g = new int[n][n];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					g[i][j] = i == j ? 0 : INF;

			List<Pair>[] slist = new List[n];
			List<Pair>[] glist = new List[n];
			for (int i = 0; i < n; i++) {
				slist[i] = new ArrayList<Main.Pair>();
				glist[i] = new ArrayList<Main.Pair>();
			}

			while (m-- > 0) {
				int b1 = scanner.nextInt() - 1;
				int b2 = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				slist[b1].add(new Pair(b2, c));
				glist[b2].add(new Pair(b1, c));
			}
			int[] acost = slove(s, slist);
			int[] bcost = slove(g1, glist);
			int[] ccost = slove(g2, glist);

			int ans = INF;
			for (int i = 0; i < n; i++)
				ans = Math.min(ans, acost[i] + bcost[i] + ccost[i]);
			System.out.println(ans);
		}
	}

	private int[] slove(int s, List<Pair>[] lists) {
		PriorityQueue<Pair> pq = new PriorityQueue<Main.Pair>();
		pq.offer(new Pair(s, 0));
		int[] dp = new int[n];
		Arrays.fill(dp, INF);
		dp[s] = 0;
		while (!pq.isEmpty()) {
			Pair p = pq.poll();
			if (dp[p.d] < p.cost)
				continue;
			for (Pair pair : lists[p.d]) {
				int ncost = p.cost+pair.cost;
				if(dp[pair.d]<=ncost)
					continue;
				dp[pair.d] = ncost;
				pq.offer(new Pair(pair.d, ncost));
			}
		}
		return dp;
	}

	int INF = 1 << 29;
	int n;

	class Pair implements Comparable<Pair> {
		int d, cost;

		public Pair(int d, int cost) {
			super();
			this.d = d;
			this.cost = cost;
		}

		@Override
		public String toString() {
			return "Pair [d=" + d + ", cost=" + cost + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return cost - o.cost;
		}

	}
}

Measured memory_bytes: 61672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

vector<long long > point_list;
vector< vector <int> > Vs_list;

void UpdatePoint(int oya,int now)
{
	for (auto ko : Vs_list[now]) {
		if (ko != oya) {
			point_list[ko] += point_list[now];
			UpdatePoint(now, ko);
		}
	}
}

int main()
{
	int N, Q;

	cin >> N >> Q;

	Vs_list = vector< vector <int> >(N);

	int a, b;
	for (int ni = 0; ni < N-1; ni++) {
		cin >> a >> b;
		a--;
		b--;
		Vs_list[a].push_back(b);
		Vs_list[b].push_back(a);
	}

	vector<int> Ps(Q);
	vector<int> Xs(Q);

	int p, x;
	for (int qi = 0; qi < Q; qi++) {
		cin >> p >> x;
		Ps[qi] = p -1;
		Xs[qi] = x;
	}

	point_list = vector<long long>(N,0);
	for (int qi = 0; qi < Q; qi++) {
		point_list[Ps[qi]] += Xs[qi];
	}

	UpdatePoint(0,0);

	for (int ni = 0; ni < N; ni++) {
		cout << point_list[ni] << " ";
	}

	return 0;
}



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

typedef long long ll;
ll w, h, x, y;
int main()
{
	cin >> w >> h >> x >> y;
	printf("%.15f ", w * h / 2.0);
	if (x * 2 == w && y * 2 == h) cout << '1';
	else cout << '0';
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

const int maxn = 105;

int lnode[maxn], rnode[maxn];
int pre_order[maxn], in_order[maxn];
int n;

int build(int pl, int pr, int il, int ir){
	if(il > ir) return -1;
	int root = pre_order[pl];
	int p = il;
	while(in_order[p] != root) p++;
	lnode[root] = build(pl + 1, pl + p - il, il, p - 1);
	rnode[root] = build(pl + p - il + 1, pr, p + 1, ir);
	return root;
}


void post_order(int now, int &first) {
	if (now == -1) return;
	post_order(lnode[now], first);
	post_order(rnode[now], first);
	if(first) first = 0;
	else printf(" ");
	printf("%d", now);
}

int main(){
	while(~scanf("%d", &n)){
		for(int i = 0; i < n; i ++){
			scanf("%d", &pre_order[i]);
		}

		for(int i = 0; i < n; i ++){
			scanf("%d", &in_order[i]);
		}
		int first = 1;
		build(0, n - 1, 0, n - 1);
		post_order(pre_order[0], first);
		puts("");
	}		
	return 0;
}


Measured memory_bytes: 2740
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>
#include<stack>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

void dfs(vector<string> &status, string s, llong len){
    if(s.size()==len){
        status.push_back(s);
        return;
    }
    dfs(status, s+"1", len);
    dfs(status, s+"0", len);
}

int main(){
    llong H,W,K;
    cin >> H >> W >> K;
    vector<string> Map(H);
    for(int i=0; i<H; i++){
        cin >> Map[i];
    }
    vector<string> statusH;
    vector<string> statusW;
    vector<string> MapCopy;
    llong ans=0;
    llong cnt_black;
    dfs(statusH, "", H);
    dfs(statusW, "", W);

    for(int i=0; i<statusH.size(); i++){
        for(int j=0; j<statusW.size(); j++){
            MapCopy   = Map;
            cnt_black = 0;
            for(int y=0; y<H; y++){
                if(statusH[i][y]=='1'){
                    for(int a=0; a<W; a++){
                        MapCopy[y][a] = 'O';
                    }
                }   
            }
            for(int x=0; x<W; x++){
                if(statusW[j][x]=='1'){
                    for(int a=0; a<H; a++){
                        MapCopy[a][x] = 'O';
                    }
                }  
            }
            for(int y=0; y<H; y++){
                for(int x=0; x<W; x++){
                    if(MapCopy[y][x]=='#'){
                        cnt_black++;
                    }
                }
            }
            if(cnt_black==K){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3164