akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

struct UF {
	int par[1000];
	UF() { for (int i = 0; i < 1000; i++) par[i] = i; }
	int root(int x) { if (x == par[x]) return x; return par[x] = root(par[x]); }
	void unit(int x, int y) { par[root(x)] = root(y); }
	int isSame(int x, int y) { return root(x) == root(y); }
};

struct Edge {
	int src, dst, cost;
	Edge(int src, int dst, int cost) { this->src = src; this->dst = dst; this->cost = cost; }
	Edge() {}
};
bool operator < (const Edge &e, const Edge &f) {
	return e.cost < f.cost;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int INF = 1e+15;
int n, m, x;
Edges edges;
Graph tree;
UF uf;
int score[1000][1000];

void bfs(int s) {
	int i;
	typedef pair<int, int> P;
	priority_queue<P, vector<P>, greater<P> > que;

	for (i = 0; i < n; i++) score[s][i] = INF;
	que.push(P(0, s)); score[s][s] = 0;
	while (!que.empty()) {
		P now = que.top(); que.pop();
		int cst = now.first;
		int pos = now.second;
		for (i = 0; i < tree[pos].size(); i++) {
			int npos = tree[pos][i].dst;
			int ncst = tree[pos][i].cost; if (ncst < cst) ncst = cst;
			if (score[s][npos] > ncst) {
				score[s][npos] = ncst;
				que.push(P(ncst, npos));
			}
		}
	}
}

int mod = 1000000007;

signed main() {
	int i;
	
	cin >> n >> m >> x;
	for (i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w; u--; v--;
		edges.push_back(Edge(u, v, w));
	}
	sort(edges.begin(), edges.end());
	
	int mst = 0;
	tree.resize(n);
	for (i = 0; i < edges.size(); i++) {
		int u = edges[i].src;
		int v = edges[i].dst;
		if (uf.isSame(u, v)) continue;
		uf.unit(u, v);
		tree[u].push_back(Edge(u, v, edges[i].cost));
		tree[v].push_back(Edge(v, u, edges[i].cost));
		mst += edges[i].cost;
	}
	if (mst > x) { cout << 0 << endl; return 0; }
	
	for (i = 0; i < n; i++) {
		bfs(i);
	}
	
	int cnt1 = 0, cnt2 = 0;
	for (i = 0; i < edges.size(); i++) {
		int u = edges[i].src;
		int v = edges[i].dst;
		int Y = edges[i].cost - score[u][v];
		if (Y < x - mst) { }
		else if (Y == x - mst) { cnt1++; }
		else { cnt2++; }
	}
	if (x == mst) cnt1--;
	
	//2 * cnt1個から1個以上選ぶ * cnt2個から任意に選ぶ
	int ans1 = 1, ans2 = 1;
	for (i = 0; i < cnt1; i++) { ans1 *= 2; ans1 %= mod; } ans1 = (ans1 + mod - 1) % mod;
	for (i = 0; i < cnt2; i++) { ans2 *= 2; ans2 %= mod; }
	int ans = 2 * ans1 % mod * ans2 % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8320
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 1000000007;
	//static long mod =998244353;
	static int[] ans;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res = "";
		long res = 0;



		string str = Console.ReadLine();

		int n = int.Parse(Console.ReadLine());

		if ( str.Length == 1 ) {

			Console.WriteLine(n/2);
			return;
		}

		char ff = str[0];
		long fc = 0;
		for ( int i = 0; i < str.Length; i++ ) {
			if ( ff == str[i] ) { fc++; } else { break; }
		}

		if ( fc == str.Length ) {
			long w = (long)( (long)fc * (long)n ) / 2;
			Console.WriteLine(w);
			return;
		}
		char gg = str[str.Length-1];
		long gc = 0;
		for ( int i = str.Length-1; i >= 0; i-- ) {
			if ( gg == str[i] ) { gc++; } else { break; }
		}

		long d=0;
		for(int i=(int)fc;i<str.Length-gc;i++){
			if(str[i]==str[i+1]){d++;i++;}
		}

		

		long man = 0;
		if ( str[0] == str[str.Length - 1] ) {
			man = ( fc + gc ) / 2;
		} else {
			man = fc / 2 + gc / 2;

		}
		man = (long)man * ( n - 1 );
		d = d * (long)n;
		res = fc / 2 + gc / 2 + (long)d + (long)man;
			Console.WriteLine(res);

		return;

	}




	//	int配列をスペース区切りの文字列に変換
	static string stringBuilderArrayInt(int[] a) {
		StringBuilder sb = new StringBuilder();

		for ( int i = 0; i < a.Length; i++ ) {
			sb.Append(a[i] + " "); 
		}
		if ( sb.Length > 1 ) {
			sb = sb.Remove(sb.Length - 1, 1);
		}
		return sb.ToString(); ;
	}


	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}



}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	string s; cin >> s;
	s[1] = 'R' + 'B' - s[1];
	cout << s;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int w,h,f[100][100];
bool flag,used[100][100];
int xs,ys,xg,yg;
int color;

void dfs(int y,int x)
{
	if(y == yg && x == xg)
	{
		flag = true;
		return;
	}

	rep(i,4)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(0 <= nx && nx < w && 0 <= ny && ny < h && !used[ny][nx])
		{
			if(f[ny][nx] == color)
			{
				used[ny][nx] = true;
				dfs(ny,nx);
			}
		}
	}
	return;
}

int main()
{
	int n;

	while(cin >> w >> h)
	{
		if(w == 0 && h == 0) break;

		cin >> xs >> ys >> xg >> yg;
		cin >> n;

		xs--;
		ys--;
		xg--;
		yg--;

		memset(f,0,sizeof(f));
		rep(i,100) rep(j,100) used[i][j] = false;
		flag = false;
		rep(i,n)
		{
			int c,d,x,y;
			cin >> c >> d >> x >> y;
		
			x--;
			y--;

			if(d == 0)
			{
				rep(j,4) f[y][x+j] = c;
				rep(j,4) f[y+1][x+j] = c;
			}
			else if(d == 1)
			{
				rep(j,4) f[y+j][x] = c;
				rep(j,4) f[y+j][x+1] = c;
			}
		}

		color = f[ys][xs];
		dfs(ys,xs);

		if(flag) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
		return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m1,d1,m2,d2;
    cin>>m1>>d1;
    cin>>m2>>d2;
    if(m1 == 2){
        if(d1<28){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
    }
    else if(m1<=7){
        if(m1%2 == 0){
            if(d1<30){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
        else{
            if(d1<31){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
    }
    else{
        if((m1+1)%2 == 0){
            if(d1<30){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
        else{
            if(d1<31){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    double n_ = (double)n / 1000;
    double d = ceil(n_) - n_;
    cout << d * 1000 << endl;
}

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

int main(){
  int i,j,n,a[1000][1000],max[1000][1000],ans;
  char b;
  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin >> b;
	max[i][j] = 0;
	if(b == '.') a[i][j] = 1;
	else if(b == '*') a[i][j] = 0;
      }
    }

    for(i=0;i<n;i++){
      if(a[0][i] == 1) max[0][i] = 1;
      if(a[i][0] == 1) max[i][0] = 1;
    }

    ans = 0;
    for(i=1;i<n;i++){
      for(j=1;j<n;j++){
	if(a[i][j] == 1){
	  max[i][j] = max[i-1][j-1] + 1;
	  if(max[i][j] > max[i-1][j] + 1) max[i][j] = max[i-1][j] + 1;
	  if(max[i][j] > max[i][j-1] + 1) max[i][j] = max[i][j-1] + 1;
	  if(ans < max[i][j]) ans = max[i][j];
	}
      }
    }

    cout << ans << endl; 

  }
  return 0;
}

Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
#define LL long long 
int n;
LL a[66], x[222], b[66];
char s[222];
void insert(LL x, LL *a){
    for(int i = 60;i >= 0; i--){
        if(x >> i & 1){
            if(!a[i]){
                a[i] = x; 
                break;
            }
            else x ^= a[i];
        }
    }
}
bool check(LL x){
    for(int i = 60;i >= 0; i--){
        if(x >> i & 1)x ^= a[i];
    }
    return x != 0;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%d", &n);
        memset(a, 0, sizeof a);
        memset(b, 0, sizeof b);
        for(int i = 1;i <= n; i++)scanf("%lld", &x[i]);
        scanf("%s", s + 1);
        bool fl = 0;
        for(int i = n;i >= 1; i--){
            if(s[i] == '0')insert(x[i], a);
            else fl |= check(x[i]);
        }
        printf("%d\n", fl);
    }
    return 0;
}


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

using namespace std;

int main () {
	string s;
	cin >> s;
	int ans = 0, cur = 0;
	for (int i = 0;i < s.size ();i ++) {
		if (s[i] == 'T') {
		    int len = 0;
			while (i < s.size () && s[i] == 'T') {
				i ++;
				len ++;
			}
//			cout << cur << ' ' << len << endl;      
			ans += (max (0, len - cur));
			cur -= min (cur, len);
			i --;
		}
		else {
			while (i < s.size () && s[i] == 'S') {
				i ++;
				cur ++;
			}
			i --;
		}
	}
	ans += cur;
	cout << ans;
	return 0;
}

Measured memory_bytes: 644
S = [x for x in input().rstrip()]

if S[0]==S[1] and S[1]!=S[2] and S[2]==S[3]:
    print("Yes")
elif S[0]==S[2] and S[1]!=S[2] and S[1]==S[3]:
    print("Yes")
elif S[0]==S[3] and S[2]!=S[3] and S[1]==S[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int n, a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else if (n == 2) {
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let h = v[0];
	let w = v[1];
	let mut s:Vec<Vec<char>> = Vec::new();
	let mut t:Vec<Vec<i32>> = Vec::new();
	for i in 0..h {
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("");
		let mut v1:Vec<char> = buf.trim().chars().collect();
		s.push(v1);
		t.push(Vec::new());
	}
	for i in 0..h {
		let mut cnt = 0;
		for j in 0..w {
			if s[i as usize][j as usize] == '.' {
				if j > 0 {
					// left
					if s[i as usize][(j-1) as usize] == '#' {
						cnt += 1;
					}
				}
				if i > 0 {
					// above
					if s[(i-1) as usize][j as usize] == '#' {
						cnt += 1;
					}
				}
				if i > 0 && j > 0 {
					// left and above
					if s[(i-1) as usize][(j - 1) as usize] == '#' {
						cnt += 1;
					}
				}
				if i < h-1 && j > 0 {
					// left and below
					if s[(i+1) as usize][(j-1) as usize] == '#' {
						cnt += 1;
					}
				}
				if j < w-1 {
					// right
					if s[i as usize][(j+1) as usize] == '#' {
						cnt += 1;
					}
				}
				if i < h-1 {
					// below
					if s[(i+1) as usize][j as usize] == '#' {
						cnt += 1;
					}
				}
				if i > 0 && j < w - 1 {
					// right and above
					if s[(i-1) as usize][(j + 1) as usize] == '#' {
						cnt += 1;
					}
				}
				if i < h-1 && j < w - 1 {
					// left and below
					if s[(i+1) as usize][(j+1) as usize] == '#' {
						cnt += 1;
					}
				}
				t[i as usize].push(cnt);
			}else{
				t[i as usize].push(-1);
			}
			cnt = 0;
		}
	}
	for i in 0..h {
		for j in 0..w {
			if t[i as usize][j as usize] == -1 {
				print!("#");
			}else{
				print!("{}", t[i as usize][j as usize]);
			}
		}
		println!("");
	}
}

Measured memory_bytes: 4352
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

c = []
for i, x in enumerate(a):
    c.extend([i+1] * x)

C = []
for i in range(H):
    C.append(c[i*W:(i+1)*W])

for i, row in enumerate(C):
    if i % 2 == 1:
        row.reverse()
    print(" ".join(map(str,row)))

Measured memory_bytes: 3572
#include<iostream>
#include<string>
using namespace std;
int main()
{
	bool correct = true;
	int count[26] = { 0, };
	int type = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		count[s[i] - 'A']++;
	}
	for (int i = 0; i < 26; i++) {
		if (count[i] != 0) {
			type++;
			if (count[i] != 2) {
				correct = false; break;
			}
		}
	}
	if (type != 2) {
		correct = false;
	}
	if (correct) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	string s, t;

	cin >> s >> t;
	vector<vector<int>> alp(26);
	for (int i = 0; i < s.size(); i++) {
		alp[s[i] - 'a'].push_back(i + 1);
	}

	ll now = 0;
	ll con = 0;
	bool flag = true;
	for (int i = 0; i < t.size(); i++) {
		if (alp[t[i] - 'a'].empty()) {
			flag = false;
			break;;
		}

		auto id = upper_bound(alp[t[i] - 'a'].begin(), alp[t[i] - 'a'].end(), now);
		if (id == alp[t[i] - 'a'].end()) {
			con++;
			now = alp[t[i] - 'a'][0];
		}
		else{
			now = *id;
		}
	}

	if (flag) {
		cout << con * (ll)s.size() + now << endl;
	}
	else
		cout << -1 << endl;

}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int a[55],b[55],c[55],n,ans;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
		c[i]=a[i]-b[i];
	sort(c+1,c+1+n,cmp);
	for(int i=1;i<=n;i++)
		if(c[i]>0)
			ans+=c[i];
		else
			break;
	cout<<ans;
	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


ll choose2(ll n){
  return n*(n-1)/2;
}

int main() {
  int n;cin>> n;
  vector<int> as(n);
  rep(i,n)cin >> as[i];
  rep(i,n)as[i]--;
  vector<int> c(n);

  rep(i,n)c[as[i]]++;
  ll sum=0;

  rep(i,n){
    sum+=choose2(c[i]);
  }

  rep(i,n){
    ll ans = sum-choose2(c[as[i]]);
    ans+=choose2(c[as[i]]-1);
    cout << ans<< endl;
  }
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int main(void){
int n,a[105];
int dif=1;
int color;
int ans=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
}
color=a[0];

for(int i=1;i<n;i++){
    if(a[i]==color){dif++;}
    else{ans=ans+(dif/2);dif=1;color=a[i];}
}
ans=ans+(dif/2);
printf("%d\n",ans);
} 


Measured memory_bytes: 128
n,m,x=map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]

ans = 1234567890123

for bit in range(1<<n):
    syu = [0]*m
    cost = 0
    for i in range(n):
        if (bit>>i)&1:
            cost += ca[i][0]
            for j in range(1,m+1):
                syu[j-1] += ca[i][j]
    ok = True
    if all(a >= x for a in syu):
        ans = min(ans,cost)
print(ans if ans != 1234567890123 else -1)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

const int MAXN = 110;

int h, w;
int c[MAXN*MAXN];
int n;
int a[MAXN][MAXN];

int main()
{
	
	scanf("%d%d", &h, &w);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &c[i]);
	}
	for (int i = 1, j = 1; i <= h; ++ i)
	{
		vector<int> v;
		for (int j = 1; j <= w; ++ j)
			v.push_back(j);
		if (i%2 == 0)
			reverse(v.begin(), v.end());
		for (auto y : v)
		{
			while (!c[j]) ++ j;
			-- c[j];
			a[i][y] = j;
		}
	}
	for (int i = 1; i <= h; ++ i)
	{
		for (int j = 1; j <= w; ++ j)
			printf("%d ", a[i][j]);
		puts("");
	}
	
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <array>
using ll =long long;
using namespace std;
int main() {
    // const int n_max=2*pow(10,5);
    int n;
    ll x=0,X=0,ans=100000000000000000LL;
    cin >> n;
    vector<ll>a(n);
    for (int i=0;i<n;i++) {
        cin >> a[i];
        X+=a[i];
    }
    for (int i=0;i<n;i++) {
        x+=a[i];
        
        if (i+1<n)ans=min(ans,abs(X-2*x));
    }
    cout << ans << endl;
    return 0;

}

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

int main(){
 int n,x;
 cin >>n >> x;
 vector<int> m(n);
 for(int i=0;i<n;i++){
     cin >> m[i];
 }
 sort(m.begin(),m.end());
 int count = 0;
 for(int k=0;k<n;k++){
     x -= m[k];
     count++;
 }
 while(x >= 0){ 
     x -= m[0];
     count++;
 }
 cout << count-1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//#define long long ll
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	int a[n+1], ans=0;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(a[i]>=k)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
n, m = gets.split.map(&:to_i)

t = Array.new(n + 2, 0)
m.times do 
  l, r = gets.split.map(&:to_i)
  t[l] += 1
  t[r + 1] -= 1
end

c = Array.new(n + 2)
p = 0
t.each_with_index do |x, i|
  p += x
  c[i] = p
end

ans = 0
c.each do |x|
  ans += 1 if x == m
end

puts ans



Measured memory_bytes: 3324
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int isprime(int);
int main(){
  int a,cnt=0,i,j;
  int *num;
  scanf("%d",&a);
  num = (int *)malloc(a * sizeof(int));
  for(i=0;i<a;i++){
    scanf("%d",&num[i]);
    j=isprime(num[i]);
    if(j!=1)continue;
    else cnt++;
  }
  printf("%d\n",cnt);
  free(num);
  return 0;}

int isprime(int x){
  int i=3;
  if(x==2)return 1;
  if(x<2 || x%2==0)return 0;
  while(i<=sqrt(x)){
    if(x%i==0)return 0;
    i+=2;
  }
  return 1;
}



Measured memory_bytes: 2140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int jump = 0;
		int max = 0;
		int h1 = sc.nextInt();
		int h2;
		
		for(int i=0; i<n-1; i++) {
			h2 = sc.nextInt();
			if(h1 >= h2) {
				jump++;
			} else {
				max = Math.max(max, jump);
				jump = 0;
			}
			h1 = h2;
		}
		max = Math.max(max, jump);
		System.out.println(max);

	}

}

Measured memory_bytes: 47420
gets.to_i.times do
    h = {}
    a = gets.scan(/\w|->|<-/)
    h[0] = a.shift
    i = 0
    a.each_slice(2) do |dir, c|
        i += (dir == "->" ? 1 : -1)
        h[i] = c
    end
    puts h.sort.map(&:last).join
end

Measured memory_bytes: 8956
using System;
using System.Text;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            StringBuilder SB = new StringBuilder(S);
            int n = SB.Length;
            n--;
            int cnt = 0;
            for(int i=0;i<n;i++)
            {
                if (i * 2 <= n)
                {
                    if (SB[i] != SB[n - i])
                    {
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 25828
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
    }

    solve(n, m);
}

fn solve(n: usize, m: usize) {
    let mut ans = 0;
    if n > 1 {
        ans += n * (n - 1) / 2;
    }
    if m > 1 {
        ans += m * (m - 1) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N,H,W;
    cin >> N>>H>>W;
    cout << (N-H+1)*(N-W+1) << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

A.sort()
A.reverse()

for i in range(N - 1):
    if A[i] == A[i + 1]:
        A[i + 1] = 0
    else:
        A[i] = 0

A.sort()
A.reverse()
print(A[0] * A[1])


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
const int MAX=2020;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,d; cin >> H >> W >> d;
    vector<vector<char>> ans(H,vector<char>(W));
    if (d&1){
        for (int i=0;i<H;++i)
            for (int j=0;j<W;++j)
                ans[i][j]=((i+j)&1?'R':'Y');
    } else {
        vector<vector<char>> C={{'R','Y'},{'G','B'}};
        vector<vector<char>> rot(MAX,vector<char>(MAX));
        for (int i=0;i<MAX;i+=d){
            for (int j=0;j<MAX;j+=d){
                rot[i][j]=C[(i/d)&1][(j/d)&1];
                for (int k=0;k<d/2&&i+2*k<MAX;++k){
                    for (int l=0;l<d/2&&j+2*l<MAX;++l){
                        rot[i+2*k][j+2*l]=rot[i][j];
                    }
                }
            }
        }
        for (int i=0;i<H;++i){
            for (int j=0;j<W;++j){
                ans[i][j]=rot[i+j+((i+j)&1)][(i-j)+MAX/2+((i+j)&1)];
            }
        }
    }
    for (int i=0;i<H;++i)
        for (int j=0;j<W;++j)
            cout << ans[i][j] << (j+1==W?"\n":"");
}

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

using static Input;
using static Util;
class Program
{
    static string S;
    static void INPUT()
    {
        S = NextString();
    }
    static void OUT()
    {
        var t = S.ToCharArray().Select(__ => __ - '0').ToArray();
        for (var b = 0; b < 8; b++)
        {
            var a = t[0];
            for (var i = 1; i <= 3; i++)
            {
                a += (b >> i-1) % 2 == 0 ? t[i]: -t[i];
            }

            if (a == 7)
            {
                var sb = new StringBuilder();
                sb.Append(t[0]);
                for (var i = 1; i <= 3; i++)
                {
                    sb.Append(
                        (b >> i-1) % 2 == 0 ? "+" : "-"
                    );
                    sb.Append(t[i]);
                }
                sb.Append("=7");
                Console.WriteLine(sb.ToString());
                return;
            }
        }

    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
        S = "1222";
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




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

using namespace std;

const int MAXN = 2e3 + 10;
const int MOD = 1e9 + 7;

// sadkalsdglasdlkas
// asdogfsaldjkgljasdljasdf
// asdfjasljdgfjalsgdjklasdg
// asdkgfasljgflajsdgflasdf4
// alirhgalsidglasdg
#define dadasdsadfaslkjdgkla fsdlkajgdslkhksjahdglka
#define sadfasdf asfdaasgasdgadsgadgfsdafasdgasg
#define fdsagahsdgfhasdfj sdjfahahsdgfjshfad

int n, dp[2 * MAXN][2 * MAXN], go[2 * MAXN][2 * MAXN];
int fac[4 * MAXN];

long long po(long long v, long long u)
{
	return u ? (po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD) : 1;
}

int ente(int i, int j) {
	return (((fac[j] * po(fac[i], MOD - 2)) % MOD) * po(fac[j - i], MOD - 2)) % MOD;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	fac[0] = 1;
	for (int i = 1; i < 4 * MAXN; i++)
		fac[i] = (1ll * fac[i - 1] * i) % MOD;
	cin >> n;
	long long res = 0;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		dp[MAXN - a][MAXN - b]++;
		go[MAXN + a][MAXN + b]++;
		res = (res - ente(2 * a , 2 * (a + b)) + MOD) % MOD;
	}
	for (int i = 1; i < 2 * MAXN; i++)
	{
		for (int j = 1; j < 2 * MAXN; j++)
		{
			dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
			dp[i][j] %= MOD;
			res += 1ll * go[i][j] * dp[i][j];
			res %= MOD;
		}
	}
	cout << (res * (MOD / 2 + 1)) % MOD << endl;
	return 0;
}

Measured memory_bytes: 95872
#include <iostream>
#include <string>

using namespace std;

int N;
string W[100];

int main() {
    cin >> N;
    cin >> W[0];

    bool ret = true;

    for (int i = 1; i < N; i++) {
        cin >> W[i];
        if(W[i - 1][W[i - 1].length() - 1] != W[i][0]) ret = false;
        for (int j = 0; j < i; j++) {
            if(W[i] == W[j]) ret = false;
        }
    }

    if(ret) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int n,k;
    cin >> n >> k;
    if(n%k == 0){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()

int main()
{	
	int n,k;
	cin>>n>>k;
	int ans=1;
	for(int i=1;i<=n;i++)
	{
		if((ans*2)<(ans+k))
		{
			ans*=2;
		}
		else
		{
			ans+=k;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())
    S = [[int(i) for i in readline().split()] for _ in range(M)]
    P = [int(i) for i in readline().split()]

    ans = 0
    A = [[0, 1] for _ in range(N)]
    for pattern in product(*A):
        on = []
        for s in S:
            tmp = 0
            for i in range(s[0]):
                tmp += pattern[s[i+1]-1]
            on.append(tmp % 2)

        if on == P:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        String str = sc.next(); 
        char[] c = str.toCharArray();

        int count = 0;
        int count1 = 0;
        int count2 = 0;

        char right1[] = new char[str.length()];
        for(int i = 0; i <c.length; i=i+2){
            right1[i] = '0';
        }
        for(int i = 1; i <c.length; i=i+2){
            right1[i] = '1';
        }

        char right2[] = new char[str.length()];
        for(int i = 0; i <c.length; i=i+2){
            right2[i] = '1';
        }
        for(int i = 1; i <c.length; i=i+2){
            right2[i] = '0';
        }

        for (int i = 0; i < c.length; i++) {
            if(c[i] != right1[i]){
                count1++;
            }
            if(c[i] != right2[i]){
                count2++;
            }
        }

        count = count1 <= count2 ? count1 : count2;
        System.out.println(count);

    }
}


Measured memory_bytes: 27456
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

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

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<pair<string, pair<int, int>>> loc;
    F0R(i, n)
    {
        string s;
        int x;
        cin >> s >> x;
        loc.pb({s, {-x, i + 1}});
    }
    sort(loc.begin(), loc.end());
    F0R(i, n) cout<< loc[i].s.s << "\n";
    return 0;
}

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


int main(){

    
    int i, j;

    string s, k;


    cin >> s;


    if( s == "keyence" ){

        cout << "YES" << endl;

        return 0;

        }


    for( i = 0 ; i < s.size() ; i = i + 1 ){

         for( j = i + 1 ; j < s.size() ; j = j + 1 ){

              k = "";

              k += s.substr( 0, i );

              k += s.substr( j, s.size() - j );

              if( k == "keyence" ){

                  cout << "YES" << endl;

                  return 0;

                  }

              }

         }


    cout << "NO" << endl;


    return 0;

    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdint.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long int
using namespace std;

int32_t main(){
	double n,a;
	cin>>n;
	double x;
	vector<double> arr(n);
	for(int i=0;i<n;i++)cin>>arr[i];
	sort(all(arr));
	x=arr[0];
	for(int i=1;i<n;i++){
		x=(x+arr[i])/2;
	}
	cout<<x;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
int64 mod = 1000000007;

int64 powmod(int64 x,int64 y){
    int64 res=1;
    for(int64 i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main() {
   int64 n;
   cin >> n;
   int64 ans = 0;
   ans = (powmod(10,n) - powmod(9,n) - powmod(9,n) + powmod(8,n)) % mod;
   ans = (ans+mod) % mod;
   cout << ans << endl;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s=to_string(n);
    int sum=0;
    for(int i=0;i<s.size();i++){
        sum+=s[i]-'0';
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool yes[10];
int dp[10004],ans[10004],sz[10004];
int num[10]={0,2,5,5,4,5,6,3,7,6};
int main(){
	memset (ans,-1,sizeof(ans));
	cin>>n>>m;
	for (int i=0;i<m;i++){
		int a;cin>>a;
		yes[a]=1;
	}
	ans[0]=0;
	for (int i=1;i<=n;i++)
		for (int j=9;j>=1;j--) if (i-num[j]>=0 && yes[j] && ans[i-num[j]]!=-1)
			if (sz[i-num[j]]+1>sz[i]){
				sz[i]=sz[i-num[j]]+1;
				ans[i]=j;
				dp[i]=i-num[j];
			}
	for (int i=n,j=sz[n];j>0;i=dp[i],j--){
		cout<<ans[i];
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int A[2][101] = {0};

int sum(int idx, int i, int j) {
  return A[idx][j] - A[idx][i];
}
int main() {
  int N; scanf("%d", &N);
  for (int a = 0; a < 2; ++a) 
    for (int i = 1; i <= N; ++i) 
      scanf("%d", &A[a][i]), A[a][i] += A[a][i - 1];
  int ans = 0;
  for (int i = 1; i <= N; ++i) ans = max(ans, sum(0, 0, i) + sum(1, i - 1, N));
  printf("%d\n", ans);

}


Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        int X=sc.nextInt();
        int Y=sc.nextInt();
        if(N<=K){
            System.out.println(N*X);
        }else{
            System.out.println(K*X+Y*(N-K));
        }
}
        
        
    }


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
int main()
{
	long long int i,n,p=0,j;
	cin>>n;
	int h[n];
	for(i=0;i<n;i++)
		cin>>h[i];
	if(n==1)
		{
			cout<<"Yes"<<endl;
		}
		
	else
	{
	
		for(i=1;i<n;i++)
		{
			if(h[i]>h[i-1])
				h[i]-=1;
		
		}
		for(i=1;i<n;i++)
			{
				if(h[i]<h[i-1])
					{
						p=1;
						break;
					}
			}
		if(p==0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
}

Measured memory_bytes: 4020
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>
#include<cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int minv(int x, int n) {
  int ans = 1, pr = x;
  while(n) {
    if(1 & n) ans = 1LL * ans * pr % mod;
    n >>= 1;
    pr = 1LL * pr * pr % mod;
  }
  return ans;
}

int solve(int n, int m) {
  int a = 1;
  int b = m-n;

  int i = 2, j = m - n + 2;
  while(i <= n) {
    int ans1 = (j-i)*1LL*b%mod;
    int ans2 = (i-1)*1LL*(a + b)%mod;
    a = b;
    b = (ans1 + ans2) % mod;
    i++;j++;
  }
  return b;
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

 int ans = 0;
 int n, m;
 cin>>n>>m;

 int mf = 1, mnif = 1;
 rep(i, m) mf = 1LL * mf * (i+1) % mod;
 rep(i, m-n) mnif = 1LL * mnif * (i+1) % mod;
 ans = 1LL * mf * minv(mnif, mod-2) % mod;
 ans = ans * 1LL * solve(n, m) % mod;
 cout << ans << endl;

 return 0;
}

//41093363 315 413


Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))

count0, count1 = 0, 0
for i in range(n):
    if a[i]%2  == 0:
        count0 += 1
        if a[i]%3 == 0 or a[i]%5 == 0:
            count1 += 1
            
if count0 == count1:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
import heapq

N,X = map(int,input().split())
m=[]
ans = N
for _ in range(N):
    M = int(input())
    m.append(M)

sum_m = sum(m)
heapq.heapify(m)
min_m = heapq.heappop(m)

A=X-sum_m
while A-min_m >=0:
    A-=min_m
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>


using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    if(1 <= A && A <= 9 && 1 <= B && B <= 9){
        cout << A * B << endl;
    }
    else cout << -1 << endl;
}

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

int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int mx1=0,ind=-1,mx2=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(mx1<a[i])
        {
            mx1=a[i];
            ind=i;
        }
    }    
    for(int i=0;i<n;i++)
    {
        if(mx2<a[i] && ind!=i)
        {
            mx2=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(i!=ind)  cout << mx1 << "\n";
        else    cout << mx2 << "\n";
    }
    return 0;
}

Measured memory_bytes: 2432
using System;
using System.Diagnostics;
using System.IO;

namespace AtCoder.ABC119 {
    class A {
        static void Main() => CustomMain();

        static void Solve() {
            var s = ReadString().Split('/');

            if (int.Parse(s[0]) > 2019) {
                WriteAnswer("TBD");
                return;
            }

            if (int.Parse(s[0]) < 2019) {
                WriteAnswer("Heisei");
                return;
            }

            if (int.Parse(s[1]) <= 4) {
                WriteAnswer("Heisei");
                return;
            }

            WriteAnswer("TBD");
        }

        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }
    }
}

Measured memory_bytes: 11092
n=int(input())
p=list(map(int,input().split()))

judge=[False]*n

for i in range(n):
  if p[i]==i+1:
    judge[i]=True

ans=0

for i in range(n):
  if judge[i]==True:
    ans+=1
    if i!=n-1:
      judge[i+1]=False
      
print(ans)

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

const ll lim=1'000'000'000'000'000'000;

int main(){
   int n; cin>>n;
   vector<ll> a(n);
   rep(i,0,n)cin>>a[i];
   sort(ALL(a));
   __int128_t res=1;
   rep(i,0,n){
      res*=a[i];
      if(res>lim){
         puts("-1");
         return 0;
      }
   } cout<<(ll)res<<endl;
   return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define int long long int
#define endl '\n'
using namespace std;
typedef long long ll;
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 #define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) FOR(i,0,sz(v)-1) cout << v[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define PI 3.14159265358979323846264338327950288419716939937510
const ll inf = 1e9;
const ll cons= 1e16;
const ll MOD = 1e9+7;
const ll N = 2e4 + 1;
const ll m = MOD;
//THIS IS LA LA LA PRODUCTION HOUSE.
//NAUTANKI.
int mod(int x)
{
    if(x<0)return -x;
    else return x;
}
int mex(int a[],int n)
{
	int m=-1;
	int present[n+1]={0};
	FOR(i,1,n)
	{
		present[a[i]]=1;
	}
	FOR(i,0,n)
	{
		if(present[i]==0)
		{
			m=i;break;
		}
	}
	return m;
}
// taro and jiro.
signed main()
{ 
  readb(n,k);
  readarr(a,n);
  int dp[k+1]={0};
  FOR(i,1,k)
  {
  	FOR(j,1,n)
  	{
  		if(i-a[j]<0)break;
  		else
  		{
  		  if(dp[i-a[j]]==0)dp[i]=1;	
  		  else
  		  continue;
		}
	}
  }
  if(dp[k])cout<<"First"<<endl;
  else cout<<"Second"<<endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll d5(ll a){return a*a*a*a*a; }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll x;
	cin >>x;
	
	rep2(i, -6000, 6001) rep2(j, -6000, 6001){
		if( d5(i) - d5(j) == x){
			cout << i <<" "<< j <<"\n";
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int a, b;
	cin >> a >> b;
	int sum = a + b;
	int min = a - b;
	int tms = a * b;
	cout << max(max(sum, min), tms) << endl;
}

Measured memory_bytes: 256
const main = input => {
  const S = input.trim()
  let count = 0
  for (let i = 0; i < S.length; i++) {
    if (S.charAt(i) === '+') {
      count++
    } else {
      count--
    }
  }

  console.log(count)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main(){
  while(1){ 
    cout<<fixed<<setprecision(12);
    int n;
    cin>>n;
    if(n==0)break;
    int s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    double sum1=0;
    for(int i=0;i<n;i++)sum1+=s[i];
    double m=sum1/n;
    double sum2=0;
    for(int i=0;i<n;i++)sum2+=pow(s[i]-m,2);
    double aa=sum2/n;
    cout<<sqrt(aa)<<endl;
  }
  return 0;
}
  
  



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

int main(){
    string s; cin>>s;
    if (s=="Sunny"){
        cout << "Cloudy" << endl;
    } else if (s=="Cloudy"){
        cout << "Rainy" << endl;
    } else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256