akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

 int main(){
     string s;
     int q;
     cin >> s >> q;
     int r = 1;
     for (int k = 0; k < q; k++){
         int a;
         cin >> a;
         if (a == 1){
             r *= -1;
         }
         else{
             int b;
             string c;
             cin >> b >> c;
             if (((-2) * b + 3) * r == 1){
                 s.insert(0, c);
             }
             else{
                 s += c;
             }
         }
     }
     if (r == -1){
         reverse(s.begin(),s.end());
     }
     cout << s << endl;
 }

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

using Graph = vector<vector<int>>;

class Tree {
 public:
  Tree(const auto& G) : N(G.size()), parent(G.size()), depth(G.size()), child(G.size()) {build(G);}
  int solve(auto K) {
    auto res = 0;
    vector<bool> used(N);
    priority_queue<pair<int, int>> q;
    for(auto v=0; v<N; ++v) if(child[v].empty()) q.emplace(depth[v], v);
    used[0] = true;
    while(!q.empty()) {
      int d, v;
      tie(d, v) = q.top();
      q.pop();
      if(used[v]) continue;
      used[v] = true;
      auto del = true;
      auto r = v;
      for(auto i=0; i<K-1; ++i) {
        r = parent[r];
        if(used[r]) {
          del = false;
          break;
        }
        used[r] = true;
      }
      if(used[parent[r]]) del = false;
      if(!del) continue;
      ++res;
      if(!used[parent[r]]) q.emplace(depth[parent[r]], parent[r]);
    }
    return res;
  }
 private:
  void build(const auto& G) {
    function<int(int, int)> dfs = [&](int cur, int pre) {
      parent[cur] = pre;
      depth[cur] = depth[pre] + 1;
      for(auto nex: G[cur]) if(nex != pre) child[cur].emplace_back(dfs(nex, cur));
      return cur;
    };
    dfs(0, 0);
  }
  int N;
  vector<int> parent, depth;
  vector<vector<int>> child;
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(auto& i: A) cin >> i;

  int ans = 0;
  if(A[0] != 1) ++ans;
  Graph G(N);
  for(auto i=1; i<N; ++i) {
    auto u=i, v=A[i]-1;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  cout << ans + Tree(G).solve(K) << endl;
}


Measured memory_bytes: 20224
N, K = map(int, input().split())
h = [i for i in map(int, input().split())]
memo = [0]*N
for i in range(N):
    mini = 10**10
    for j in range(i-min(i, K), i, 1):
        if memo[j] + abs(h[i]-h[j]) < mini:
            mini = memo[j] + abs(h[i]-h[j])
    if i != 0:
        memo[i] = mini
print(memo[N-1])

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (1)
  {
    c -= b;
    if (c <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if (a <= 0)
    {
      cout << "No" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int N, S;

int main()
{
    while ( cin >> N and N > 0) {
        int sum = 0;
        int largest = 0;
        int smallest = 1000;
        for (int i = 0; i < N; i++) {
            cin >> S;
            sum += S;
            if ( S > largest ) largest = S;
            if ( S < smallest ) smallest = S;
        }
        sum = sum - largest - smallest;
        int ave = sum / (N - 2);
        cout << ave << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

int tostate(int a, int b, int c, int k)
{
	int mul;
	int ret = 0;
	
	for(int i = 0, mul = 1; i < k; ++i, mul *= 3)
		ret += ((a >> i) & 1) * 1 * mul;
	for(int i = 0, mul = 1; i < k; ++i, mul *= 3)
		ret += ((b >> i) & 1) * 2 * mul;
		
	return ret;
}

inline int mhb(int x)
{
	for(int i = 31; i >= 0; --i) {
		if(x & (1 << i))
			return 1 << i;
	}
	
	return 0;
}

const int inf = 1000000000;
const int pow3x5 = 3 * 3 * 3 * 3 * 3;
const int pow3x15 = pow3x5 * pow3x5 * pow3x5;
bool visit[pow3x15];

struct node {
	int a, b, c, remain;
	node(int a, int b, int c, int remain) : a(a), b(b), c(c), remain(remain) {}
};

int calc(int a, int b, int c, int remain, int k)
{
	int f = inf;

	queue<node> q;
	
	q.push(node(a, b, c, remain));
	
	while(!q.empty()) {
	
		node cur = q.front();
		q.pop();
	
		if(cur.remain < 0)
			continue;
		
		if(cur.b == 0 && (cur.a == 0 || cur.c == 0)) {
			f = cur.remain;
			break;
		}

		int state = tostate(cur.a, cur.b, cur.c, k);

		if(visit[state])
			continue;
		visit[state] = true;
	
		if(cur.a > cur.b) {
			int move = mhb(cur.a);
			int ta = cur.a - move;
			int tb = cur.b + move;
			int tc = cur.c;
			q.push(node(ta, tb, tc, cur.remain - 1));
		} else {
			int move = mhb(cur.b);
			int ta = cur.a + move;
			int tb = cur.b - move;
			int tc = cur.c;
			q.push(node(ta, tb, tc, cur.remain - 1));
		}
	
		if(cur.b > cur.c) {
			int move = mhb(cur.b);
			int ta = cur.a;
			int tb = cur.b - move;
			int tc = cur.c + move;
			q.push(node(ta, tb, tc, cur.remain - 1));
		} else {
			int move = mhb(cur.c);
			int ta = cur.a;
			int tb = cur.b + move;
			int tc = cur.c - move;
			q.push(node(ta, tb, tc, cur.remain - 1));
		}
	}
	
	int ret = (f != inf ? remain - f : -1);
	
	return ret;
}

int main()
{
	while(true) {
	
		int n, m;
		
		scanf("%d%d", &n, &m);
		if(n == 0)
			break;
			
		fill(visit + 0, visit + pow3x15, false);
		
		int a[3];
		int bita[3] = {0};
		int k = 0;
		
		for(int i = 0; i < 3; ++i) {
			scanf("%d", a + i);
			for(int j = 0; j < a[i]; ++j) {
				int t;
				scanf("%d", &t);
				bita[i] += 1 << (t - 1);
				k = max(k, t);
			}
		}
		
		int ans = calc(bita[0], bita[1], bita[2], m, k);
		
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 15064
#include <iostream>
#include <vector>

using namespace std;
const int INF = 1e9;

int main() {
    int N; cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) cin >> F[i][j];
    }

    vector<vector<int>> P(N, vector<int>(11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 10; j++) cin >> P[i][j];
    }

    int ans = -INF;
    for (int i = 1; i < (1<<10); i++) {// 開く時間帯の決め方のループ
        vector<int> c(N, 0);
        for (int j = 0; j < 10; j++) {// 時間帯のループ
            if (i&(1<<j)) {// 時間帯 j に開いていれば
                for (int k = 0; k < N; k++) {
                    if (F[k][j] == 1) c[k]++;
                }
            }
        }

        // 利益を計算
        int prof = 0;
        for (int k = 0; k < N; k++) {// 店のループ
            prof += P[k][c[k]];
        }

        if (ans < prof) ans = prof;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  vector<int> menu(5);
  vector<int> dev(5);
  int ans=0;
  rep(i,0,5) cin>>menu[i];
  rep(i,0,5){
    dev[i]=10-menu[i]%10;
    if(dev[i]==10) dev[i]=0;
  }
  asort(dev);
  rep(i,0,5) ans+=menu[i]+dev[i];
  cout<<ans-dev[4];
  

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AABCSwap {
public:
	void solve(istream& in, ostream& out) {
        int x,y,z;
        in >> x >> y >> z;
        swap(x,y);
        swap(x,z);
        cout << x << " " <<  y << " " <<  z << endl;
	}
};

int main() {
	AABCSwap solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define repr(i, n) for(ll i = n;i >= 0;i--) // from n to 0
#define Repr(i, r, n) for(ll i = n;i >= r;i--) // from n to r
#define pb push_back
#define MOD 1000000007
#define PI (acos(-1))

bool is_prime(ll a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(ll i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

ll calc(ll n) {
  return 0.5 * n * (n+1);
}

ll min(ll a, ll b) {
  return a > b ? b : a;
}

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  ll duplicate = 0;
  ll tmp_minus = 0;
  ll cont_count = 0;
  Rep(i, 1, s.length()) {
    if(s[i] == s[i-1]) cont_count++;
    else {
      if(s[i-1] == '<') {
        if(cont_count > 0) tmp_minus = (cont_count+1);
        if(cont_count == 0) {
          if(i == s.length()-1) ans++;
          else if(s[i+1] == '<') ans++;
        }
      }
      else {
        if(cont_count > 0) {
          duplicate -= min(tmp_minus, cont_count+1);
        }
        tmp_minus = 0;
      }
      if(cont_count > 0) {
        ans += calc(cont_count+1);
        cont_count = 0;
      }
    }
  }
  if(cont_count > 0) {
    ans += calc(cont_count+1); 
  }
  if(cont_count+1 == s.length()) {
    cout << calc(cont_count+1) << "\n";
    return 0;
  }

  if(s[0] == '>' && s[1] == '<') {
    ans++;
  }
  if(s[s.length()-1] == '<' && s[s.length()-2] == '>') {
    ans++;
  }
  ans += duplicate;
  cout << ans << "\n";
  return 0;
}

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


int main(void){

	int a,b;
	int d,r;
	double f;
	cin >> a >> b;
	d = (int)(a/b);
	r = a%b;
	f = (double)a/b;
	cout << d << " " << r << " " << fixed << setprecision(10) << f << endl; 
	return 0;
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 1000000007;
double dp[3010][3010];
double p[3010];
signed main(){
    ll n;
    cin >> n;
    rep(i,n)cin >> p[i];

    rep(i,n)dp[0][i] = 0;
    dp[0][0] = 1.0;

    for(int i = 1; i <= n;i++){
        for(int j = 0; j <= n;j++){
            if(j == 0){
                dp[i][j] = dp[i-1][j]*(1-p[i-1]);
            }else{
                dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1]; 
            }
        }
    }
    double ans = 0.0;

    rep(i,n/2+1)ans += dp[n][i];
    printf("%0.10lf\n",1.0-ans);

    // rep(i,n){
    //     rep(j,n){
    //         cerr << dp[i][j] << "\t";
    //     }cerr << endl;
    // }


    
      
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f

Measured memory_bytes: 70784
N, M, Q = map(int,input().split())
graph = [[0 for i in range(N+1)] for j in range(N+1)]
for _ in range(M):
    L, R = map(int,input().split())
    graph[L-1][R] += 1

for i in range(N-1,-1,-1):
    for j in range(1,N+1):
        graph[i][j] += graph[i+1][j] + graph[i][j-1] - graph[i+1][j-1]

for _ in range(Q):
    p, q = map(int,input().split())
    print(graph[p-1][q])

Measured memory_bytes: 11144
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String input = ""; // 入力された(H,W)を一時敵に保持しておくための変数
		String[] inputdata = new String[2]; // inputの変数を配列に保持しておくための変数
		int Max = 10000;
		int n = 0; // 入力されたデータ(H, W)の組数をカウントするための変数
		int[][] HW_data = new int[Max][2];
		boolean judge = true;
		String output1 = "#";
		String output2 = ".";

		out: for (int i = 0; i < HW_data.length; i++) {

			input = sc.nextLine();
			inputdata = input.split(" ");
			HW_data[i][0] = Integer.parseInt(inputdata[0]);
			HW_data[i][1] = Integer.parseInt(inputdata[1]);

			if ((HW_data[i][0] == 0) && (HW_data[i][1] == 0)) {
				break out;
			}

			if ((HW_data[i][0] < 1 || HW_data[i][0] > 300)
					|| (HW_data[i][1] < 1 || HW_data[i][1] > 300)) {
				judge = false;
				break out;
			}

			n++;

		}

		if (judge == true) {
			for (int i = 0; i < n; i++) {
				for (int j = 1; j <= HW_data[i][0]; j++) { // 縦H
					for (int k = 1; k <= HW_data[i][1]; k++) { // 横W

						if (j % 2 == 1) {
							if (k % 2 == 1) {
								System.out.print(output1);
							} else {
								System.out.print(output2);
							}
						} else {
							if (k % 2 == 1) {
								System.out.print(output2);
							} else {
								System.out.print(output1);
							}

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

	}

}



Measured memory_bytes: 34824
a,b,k=map(int,input().split())
for i in range(k):
    if(i%2==0):
        if(a%2==1):
            a-=1
        a=a//2
        b+=a
    else:
        if(b%2==1):
            b-=1
        b=b//2
        a+=b
print(a,b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {    
    cin >> a.at(i);
  }
  
  int x = 1;
  
  for (int j = 0; j < N ;j++) {
    x = a.at(x-1);
    
    if (x == 2) {
      cout << j+1 << endl;
      break;
    }
  }
  if (x != 2) {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
M, D = map(int,input().split())
count = 0
for i in range(22, D+1):
    l = [int(x) for x in list(str(i))]
    if l[1] == 0 or l[1] == 1:
        pass
    elif l[0] * l[1] <= M:
        count += 1

print(count)
        

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1e9+7
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    string s,t;
    int cnt=0;
    cin>>s>>t;
    REP(i,3){
        if(s[i]==t[i])cnt++;
    }
    cout<<cnt<<endl;
}




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

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  int ans = 0;
  rep(i,n){
    ans += b[a[i]-1];
    if(a[i]+1 == a[i+1]) ans += c[a[i]-1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int m = Integer.parseInt(sc.next());
            final int f = Integer.parseInt(sc.next());
            final int r = Integer.parseInt(sc.next());
            if(m==-1&&f==-1&&r==-1) break;
            if(m==-1||f==-1) out.println('F');
            else if(m+f>=80) out.println('A');
            else if(m+f>=65) out.println('B');
            else if(m+f>=50) out.println('C');
            else if(m+f<30) out.println('F');
            else if(r>=50) out.println('C');
            else out.println('D');
        }
        out.flush();
    }
}

Measured memory_bytes: 26188
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {

	// Atcoder用のサンプルプログラム
    public static void main(String[] args) throws Exception {
    	//ystem.out.println("Start!!");
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	
    	 String str1 = br.readLine();
    	 String A = str1.split(" ")[0];
    	 String B = str1.split(" ")[1];
    	 int plus = add(A,B);
    	 int minus = subtract(A,B);
    	 int kakeru = multiply(A,B);
    	 
    	 String result=String.valueOf(kakeru);
    	 if (plus >= minus && plus >= kakeru) {
    		 result = String.valueOf(plus);
    	 } else if (minus >= kakeru) {
    		 result = String.valueOf(minus);
    	 }
    	 
    	 System.out.println(result);

    	//System.out.println("End!!");
    }
    
    private static int add(String a, String b) throws Exception{
    	return Integer.parseInt(a) + Integer.parseInt(b);
    }

    private static int subtract(String a, String b) throws Exception {
    	return Integer.parseInt(a) - Integer.parseInt(b);
    }
    
    private static int multiply(String a, String b) throws Exception {
    	return Integer.parseInt(a) * Integer.parseInt(b);
    }
    
    private static int divide(String a, String b) throws Exception {
    	return Integer.parseInt(a) / Integer.parseInt(b);
    }
    
    private static int pow(String a, String b) throws Exception {
    	Double result = Math.pow(Double.parseDouble(a),Double.parseDouble(a));
    	return Integer.parseInt(Double.toString(result));
    }
    
    private static String getBigger(String a, String b) throws Exception {
    	String result = b;
    	if (Integer.parseInt(a) >= Integer.parseInt(b)) {
    		result = a;
    	}
    	return result;
    }
    
    private static double getBigger(double a, double b) throws Exception {
    	double result = b;
    	
    	Double.compare(a, b);
    	if (Double.compare(a, b) > 0) {
    		result = a;
    	}
    	return result;
    }
    // 備忘録
    // int → String  String.valueOf();
    // String → int  Integer.parseInt();
    // BigDecimal → int XXX.intValue();
    // double → BigDecimal new BigDecimal(XXX);
    // setScale BigDecimalの桁まとめ 
    // nBig.setScale(0,BigDecimal.ROUND_DOWN);
    // 絶対値 → Math.abs
    
}

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

int n;
double p[3055];
double dp[6055];
double ndp[6055];

int main() {
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		scanf("%lf", &p[i]);
	}
	
	dp[3000] = 1;
	
	for (int i = 0; i < n; i++) {
		memset(ndp, 0, sizeof(ndp));
		
		for (int j = 0; j <= 6000; j++) {
			// j + 1 = head
			
			ndp[j + 1] += dp[j] * p[i];
			if (j > 0) ndp[j - 1] += dp[j] * (1. - p[i]);
		}
		
		swap(dp, ndp);
	}
	
	double res = 0;
	
	for (int i = 3001; i <= 6000; i++) {
		res += dp[i];
	}
	
	printf("%.10lf\n", res);
}


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

int main(){
    vector<string> sorted;
    int N;
    cin >> N;
    for ( int i = 0; i < N; i ++ ){
        vector<char> temp;
        for ( int j = 0; j < 10; j ++ ){
            char c;
            cin >> c;
            temp.push_back( c );
        }
        sort ( temp.begin(), temp.end() );
        string s = "";
        for ( int j = 0; j < 10; j ++ ){
            s += temp[j];
        }
        sorted.push_back( s );
    }
    sort ( sorted.begin(), sorted.end() );
    ll res = 0;
    ll streak = 1;
    for ( int i = 1; i < N; i ++ ){
        if ( sorted[i] == sorted[i - 1] ) streak ++;
        else{
            res += ( ( streak - 1 ) * streak ) / 2;
            streak = 1;
        }
    }
    res += ( ( streak - 1 ) * streak ) / 2;
    cout << res;
    return 0;
}


Measured memory_bytes: 7284
w,h,n = map(int,input().split())
table = [[1]*h for _ in range(w)]
for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(x):
            for j in range(h):
                table[i][j] = 0
    if a == 2:
        for i in range(x,w):
            for j in range(h):
                table[i][j] = 0
    if a == 3:
        for i in range(w):
            for j in range(y):
                table[i][j] = 0
    if a == 4:
        for i in range(w):
            for j in range(y,h):
                table[i][j] = 0
print(sum(map(sum,table)))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
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; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    ll a, b;
    cin >> a >> b;
    if (a == b) { cout << a << endl; return 0; }
    ll a2 = (a+1)/2, b2 = (b-1)/2;
    ll ans = (b2 + 1 - a2) % 2;
    if (a%2 == 1) {
        ans = a ^ ans;
    }
    if (b%2 == 0) {
        ans ^= b;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;



class Dice {
public:
	int num[6] = { 0,0,0,0,0,0 };
	void setnum(int*);
	void roll(char);
	void dice3(Dice, Dice);
};

void Dice::roll(char c) {
	switch
 (c) {
		int tmp;
	case'N':
		tmp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = tmp;
		break;
	case'S':
		tmp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = tmp;
		break;
	case'E':
		tmp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = tmp;
		break;
	case'W':
		tmp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = tmp;
		break;
	default:
		cout << "invalid char" << endl;
	}
}

void Dice::setnum(int* a) {
	REP(i, 6) {
		num[i] = a[i];
	}
}

bool isSame(Dice d1, Dice d2) {
	int flag = 1;
	REP(i, 6) {
		if (d1.num[i] != d2.num[i]) {
			flag = 0;
		}
	}
	if (flag) return true;
	else return false;
}

void dice3(Dice d1, Dice d2) {
	bool same=false;
	int i = 0, flag0 = 0, flag1 = 0, flag2 = 1;
	int a = d1.num[0], b = d1.num[1];
	REP(i, 6) {
		if (b == d2.num[i]) {
			flag0 = 1;
		}
	}
	if (flag0) {
		REP(i, 3) {
			REP(j, 4) {
				if (isSame(d1, d2)) {
					same = true;
					break;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('E');
			REP(j, 4) {
				if (isSame(d1, d2)) {
					same = true;
					break;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('N');
		}
	}
	if (same) cout << "Yes" << endl;
	else cout << "No" << endl;
}




int main() {
	int a[6], b[6];
	REP(i, 6) {
		int c;
		cin >> c;
		a[i] = c;
	}
	REP(i, 6) {
		int c;
		cin >> c;
		b[i] = c;
	}
	Dice d1, d2;
	d1.setnum(a);
	d2.setnum(b);
	dice3(d1, d2);
	return 0;
}

Measured memory_bytes: 3112
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,a,b = map(int,input().split())
s = input()

kaigai = 0
all = 0

for c in s:
    if c == 'a':
        if all < a + b:
            all += 1
            print('Yes')
        else:
            print('No')
    if c == 'b':
        if all < a + b and kaigai < b:
            all += 1
            kaigai += 1
            print('Yes')
        else:
            print('No')
    if c == 'c':
        print('No')


Measured memory_bytes: 6200
#include<iostream>
#include<vector>

using namespace std;
const long long INF = 1LL << 50;
const long long MAXN = 2020;
long long dist[MAXN];
struct Edge{
    long long u,v;
    long long cost;
    Edge(long long _u = 0, long long _v = 0,long long _cost = 0):u(_u),v(_v),cost(_cost){}
};
vector<Edge> E;
bool bellman_ford(long long start,long long n){
    for(long long i = 1 ; i <= n ; i++)dist[i]=INF;
    dist[start]=0;
    for(long long i = 1 ; i < n ; i++){
        bool flag = false;
        for(long long j = 0 ; j < E.size() ; j++)
        {
            long long u = E[j].u;
            long long v = E[j].v;
            long long cost = E[j].cost;
            if(dist[v]>dist[u]+cost){
                dist[v] =dist[u]+cost;
                flag = true;
            }
        }
        if(!flag)return true;
    }
	long long l=dist[n];
    for(long long j = 0 ; j < E.size() ; j++)
    {
        if(dist[E[j].v]>dist[E[j].u]+E[j].cost)
        {
           dist[E[j].v]=dist[E[j].u]+E[j].cost;
        }
    }
	if(dist[n]!=l)
        return false;
    return true;
}
int main()
{
    long long N,M;
    scanf("%lld%lld",&N,&M);
    for(long long i = 0 ; i < M ; i++)
    {
        long long a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        Edge t;
        t.u = a;
        t.v = b;
        t.cost = -c;
        E.push_back(t);
    }
    if(bellman_ford(1,N))
    {
        if(dist[N]==INF)
             printf("inf");
        else
            printf("%lld",-dist[N]);
    }
    else{
        printf("inf");
    }


    return 0;
}


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

void solve() {
    int n;
    cin >> n;
    vector<int> seq(n);
    rep(i,n) {
        int p;
        cin >> p;
        p--;
        seq[p] = i;
    }

    int ans = 0;
    int cnt = 1;
    rep(i, n-1) {
        if (seq[i] < seq[i+1]) {
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 1;
        }
    }
    ans = max(ans, cnt);

    cout << n - ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n,m;
  cin >> n >> m;
  vector<P> v(m);
  REP(i,m){
    cin >> v.at(i).second >> v.at(i).first;
  }
  SORT(v);
  I t=0;
  I c=0;
  REP(i,m){
    if (c <= v.at(i).second){
      c = v.at(i).first;
      t++;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 1792
# Input X, Y
X, Y = map(int, input().split())

# Calculate prize for "Coding Contest"
prize_code = 0;
if X == 1:
	prize_code = 300000;
elif X == 2:
	prize_code = 200000;
elif X == 3:
	prize_code = 100000;

# Calculate prize for "Robot Maneuver"
prize_device = 0;
if Y == 1:
	prize_device = 300000;
elif Y == 2:
	prize_device = 200000;
elif Y == 3:
	prize_device = 100000;

# Calculate prize for "two victories"
prize_both = 0
if X == 1 and Y == 1:
	prize_both = 400000

# Calculate the sum and print the answer
prize_total = prize_code + prize_device + prize_both
print(prize_total)

Measured memory_bytes: 3064
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
const int MAXN=2e6+10,MOD=1e9+7;
int r1,r2,c1,c2;
struct Combinatorics{
	LL fact[MAXN+1]={1};
	void INIT()
	{
		rb(i,1,MAXN)
			fact[i]=fact[i-1]*i,fact[i]%=MOD;
	}
	LL quick_pow(LL A,LL B){
		if(!B) return 1;
		LL tmp=quick_pow(A,B>>1);
		tmp*=tmp;
		tmp%=MOD;
		if(B&1){
			tmp*=A;
			tmp%=MOD;
		}
		return tmp;
	}
	LL inv(LL A){
		return quick_pow(A,MOD-2);
	}
	LL P(LL A,LL B){
		return  fact[B]*inv(fact[B-A])%MOD;
	} 
	LL C(LL A,LL B){
		return P(A,B)*inv(fact[A])%MOD;
	}
}com;
LL f(int i,int j){
	return com.C(j,i+j);
}
LL g(int i,int j){
	// total in O(n)
	LL Res=0;
	rb(I,0,i){
		Res+=f(I+1,j);
//		cout<<I+1<<" "<<j<<" "<<com.C(2,3)<<endl; 
		Res%=MOD;
	}
//	cout<<Res<<endl;
	return Res;
}
int main(){
	fastio;
	com.INIT();
	cin>>r1>>c1>>r2>>c2;
//	cout<<g(1,1)<<endl;
	cout<<(g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)+MOD+MOD)%MOD; 
	return 0;
}


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

class Main {

    static int linearSearch(int[] a, int x) {
        int pos = 0;
        a[a.length - 1] = x;
        while (a[pos] != x) {
            pos++;
        }
        return pos;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int result = 0;

        int n = Integer.parseInt(br.readLine());
        int[] S = new int[n + 1];
        String[] inputs = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            S[i] = Integer.parseInt(inputs[i]);
        }

        int q = Integer.parseInt(br.readLine());
        String[] inputt = br.readLine().split(" ");
        for (String str : inputt) {
            if (linearSearch(S, Integer.parseInt(str)) != n) {
                result++;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 26548
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
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<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
// gcdも呼ぶ！！！
ll ngcd(vector<ll> a){
    ll d;
    d = a[0];
    for(int i = 1; i < a.size() && d != 1; i++) d = gcd(a[i], d);
    return d;
}
// gcdも呼ぶ！！！
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}
// gcdも呼ぶ！！！
// lcmも呼ぶ！！！
ll nlcm(vector<ll> numbers) {
    ll l;
    l = numbers[0];
    for (ll i = 1; i < numbers.size(); i++) {
        l = lcm(l, numbers[i]);
    }
    return l;
}

int main() {

    
    
    int n;
    cin>>n;
    vll v(n);
    rep(i,n)cin>>v[i];
    fin(nlcm(v));
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b;
    cin >> a >> b;

    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3644
def main():
    n, k = map(int, input().split())
    q = (10 ** 9 + 7)
    ans = 0
    for i in range(k, n + 2):
        ans += (n + 1 - i) * i + 1
        ans %= q
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
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();
    int c = sc.nextInt();
    if((b-a)==(c-b)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 23636
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:String, b:String}
    let s = format!("{}{}", a, b);
    let x = s.parse::<isize>().unwrap();
    let mut is_square = false;
    for i in 1..1000 {
        if x == i * i {
            is_square = true;
            break;
        }
    }
    println! {
        "{}",
        if is_square {
            "Yes"
        }
        else {
            "No"
        }
    }
}


Measured memory_bytes: 4352
#include <stdio.h>


int n, p;
int person[51];
int count = 0;


int calc()
{
  int k1, k2, k3;
  int num = 0;
  int c = p;

  while ( 1 ) {
    if ( c == 0 ) { c = person[num]; person[num] = 0; }
    else { person[num]++; c--; }

    if ( ++num >= n ) { num = 0; }
    if ( c == 1 && is_finish(num) ) { return num; }
  }
}

int is_finish(int num)
{
  int k;

  for ( k = 0; k < n; k++ ) {
    if ( num == k ) { continue; }
    if ( person[k] ) { return 0; }
  }
  return 1;
}

int main(void)
{
  int k1;

  while ( 1 ) {
    scanf("%d %d", &n, &p);
    if ( (n|p) == 0 ) { break; }

    for ( k1 = 0; k1 < 51; k1++ ) { person[k1] = 0; }

    printf("%d\n", calc());
  }

  return 0;
}

Measured memory_bytes: 600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)



int main() {
	int n, k;
	string s;

	cin >> n >> s >> k;

	char c = s[k - 1];

	REP(i, n) {
		if (s[i] == c) {
			cout << c;
		}
		else {
			cout << "*";
		}
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
//When I wrote this, only God and I understood what I was doing
//Now, God only knows :-)
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ch char
#define vc vector
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll n;cin>>n;
  ll a[n+1][3];
  for(int i=0;i<n;i++)
  {
  	for(int j=0;j<3;j++)
  	{
  		cin>>a[i][j];
	  }
  }
  for(int i=1;i<n;i++)
  {
  	a[i][0]=a[i][0]+max(a[i-1][1],a[i-1][2]);
  	a[i][1]=a[i][1]+max(a[i-1][0],a[i-1][2]);
  	a[i][2]=a[i][2]+max(a[i-1][0],a[i-1][1]);
  }
  cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
}


Measured memory_bytes: 2560
import java.util.*;

public class Main{
	public static void main(String[] args) {
	
				Scanner sc = new Scanner(System.in);
				// 整数の入力
				int N = sc.nextInt();
				// スペース区切りの整数の入力
				int K = sc.nextInt();
				int start = 1;
				int temp = start;
				for (int i = 0; i < N; i++) {
					
					temp = Math.min(temp+K, temp*2);
				}
				
				// 出力
				System.out.println(temp);
	
	}
}


Measured memory_bytes: 23764
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

main :: IO ()
main = (mapM_ (sovle . map (read :: String -> Double) . words) . lines) =<< getContents
  where
    rnd x = if abs x < 0.001 then 0.0 else x
    sovle [a,b,c,d,e,f]
      | det /= 0 = printf "%.3f %.3f\n" (rnd (det1/det)) (rnd (det2/det))
      where
        det = a*e - b*d
        det1 = c*e - b*f
        det2 = a*f - c*d


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

int main(){
  long long n, T;
  cin >> n >> T;
  long long ans = 0;
  long long prev = 0;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    ans += min(t - prev, T);
    prev = t;
  }
  cout << ans + T << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,m,a[100005],cnt,ans; 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	forn(i,n)
	{
		cin>>a[i];
		cnt+=a[i];
	}
	forn(i,n)if(a[i]*4*m>=cnt)ans++;
	if(ans>=m)cout<<"Yes";
	else cout<<"No";
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, ll = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      l++;
    }
    if (s[i] == ')') {
      if (l > 0) l--;
      else ll++;
    }
  }
  for (int i = 0; i < ll; i++) cout << "(";
  cout << s;
  for (int i = 0; i < l; i++) cout << ")";
  cout << endl;
  return 0;
}


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

int main() {
  string s; cin>>s;
  int n = s.size();
  int vec[26] ={0};
  for (int i = 0; i < n; i++) {
    vec[s.at(i)-'a']++;
  }
  bool ans=true;
  for (int i = 0; i < 26; i++) {
    if(vec[i]%2) {
      ans=false;
      break;
    }
  }
  if (ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

    vector<int> d(N);
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int half = N / 2;
    int begin = d[half - 1];
    int end = d[half];

    int ans = end - begin;
    cout << ans << endl;
    return (0);
}

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

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)

LL a,b;

int main()
{
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;	
}

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

int n;
int a[200005];
int main() {
  cin >> n;
  a[0] = a[n+1] = 0;
  for(int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for(int i = 1; i <= n+1; i++) {
    ans += abs(a[i] - a[i-1]);
  }
  int tmp = ans;
  for(int i = 1; i <= n; i++) {
    ans = tmp;
    if(a[i-1] > a[i+1]) {
      if(a[i-1] < a[i]) ans -= 2 * abs(a[i-1] - a[i]);
      else if(a[i] <= a[i+1]) ans -= 2 * abs(a[i] - a[i+1]);
    }
    else {
      if(a[i+1] < a[i]) ans -= 2 * abs(a[i] - a[i+1]);
      else if(a[i] <= a[i-1]) ans -= 2 * abs(a[i-1] - a[i]);
    }
    cout << ans << endl;
  }
}
      
  


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

#define int long long

const int N = 16e3 + 10;
int x, y, _dp[2][2 * N + 100], *dp[2];
string s;
vector <int> vec[2];

void fill_dp(int indx) {
	for (int i = -N + 1; i < N; i++)
		dp[1][i] = 0;
	dp[1][0] = 1;
	
	for (int i = 0; i < vec[indx].size(); i++) {
		int now = (i & 1), prv = (now ^ 1), x = vec[indx][i];
		for (int j = -N + 1; j < N; j++) {
			dp[now][j] = 0;
			if (j - x > -N)
				dp[now][j] = dp[prv][j - x];
			if (j + x < N)
				dp[now][j] = max(dp[now][j], dp[prv][j + x]);
		}
	}
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	dp[0] = _dp[0] + N + 50;
	dp[1] = _dp[1] + N + 50;
	
	cin >> s >> x >> y;
	while (s.size() && s.back() == 'T')
		s.pop_back();
	if (!s.size())
		return cout << (!x && !y? "Yes\n": "No\n"), 0;
	
	int tmp = 0, indx = 0;
	while (indx < s.size() && s[indx] == 'F')
		tmp++, indx++;
	
	int last = 0, num = 0;
	for (int i = indx; i < s.size(); i++) {
		if (s[i] == 'T')
			vec[num & 1].push_back(last), last = 0, num++;
		else
			last++;
	}
	vec[num & 1].push_back(last);
	
	fill_dp(0);
	if (!dp[((int)vec[0].size() & 1) ^ 1][x - tmp])
		return cout << "No\n", 0;
	fill_dp(1);
	cout << (dp[((int)vec[1].size() & 1) ^ 1][y]? "Yes\n": "No\n");
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256