akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <atomic>
#include <thread>
#include <mutex>
#include <string>
#include <string.h>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define P std::pair<int,int> 
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, c, d[35][35], e[510][510];
vector<int> vec1[3];
vector<P> vec2[3];
signed main() {
	cin >> n >> c;
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++)cin >> d[i][j];
	}
	rep(i, n) {
		rep(j, n) {
			cin >> e[i][j];
			vec1[(i + j) % 3].push_back(e[i][j]);
		}
	}
	rep(i, 3) {
		for (int j = 1; j <= c; j++) {
			int cnt = 0;
			for (int k : vec1[i])cnt += d[k][j];
			vec2[i].push_back({ cnt,j });
		}
	}
	int ans = INF;
	rep(i, c) {
		rep(j, c) {
			if (vec2[0][i].second == vec2[1][j].second)continue;
			rep(k, c) {
				if (vec2[0][i].second == vec2[2][k].second)continue;
				if (vec2[1][j].second == vec2[2][k].second)continue;
				ans = min(ans, vec2[0][i].first + vec2[1][j].first + vec2[2][k].first);
			}
		}
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 4388
a, b, k = map(int, input().split())

if k <= a:
    a = a - k
    print(a, b)
else:
    k = k - a
    a = 0

    if k == 0:
        pass
    elif k >= b:
        b = 0
    else:
        b = b - k

    print(a, b)


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int impN = int.Parse(Console.ReadLine());
            int[] mochis = new int[impN];
            for (int i = 0; i < impN; i++)
            {
                mochis[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(mochis);
            int[] mochisD= mochis.Distinct().ToArray();
            Console.Write(mochisD.Length);


            //System.Threading.Thread.Sleep(1000);
        }
    }
}


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

int main() {
    string n;
    cin>>n;
    if (n[0]=='9'||n[1]=='9') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main()
{
	char S[3];
	char T[3];
	int ans = 0;

	for (int i = 0; i < 3; i++) {
		cin >> S[i];
	}

	for (int i = 0; i < 3; i++) {
		cin >> T[i];
		if (S[i] == T[i]) {
			ans++;
		}
	}

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

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

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

int main(void) {
    int k, s, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> k >> s;
    REP(x, k + 1) {
        REP(y, k + 1) {
            int z = s - x - y;
            if (0 <= z && z <= k) {
                ans++;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
# ALDS1_11_D Connected Components
import sys
import queue


sys.setrecursionlimit(1000000)

def check(adj, foot_print):
    n = len(foot_print)
    que = queue.Queue()
    num = 0
    for i in range(n):
        if foot_print[i] == 0:
            num += 1
            que.put(i)
            foot_print[i] = num
            bfs(adj, que, foot_print, num)


def bfs(adj, que, foot_print, num):
    if not que.empty():
        now = que.get()
        for i in adj[now]:
            if foot_print[i] == 0:
                foot_print[i] = num
                que.put(i)
        bfs(adj, que, foot_print, num)
    else:
        return


def main():
    n, m = map(int, sys.stdin.readline().strip().split())
    adj_list = [[] for _ in range(n)]
    for i in range(m):
        s, t = map(int, sys.stdin.readline().strip().split())
        adj_list[s].append(t)
        adj_list[t].append(s)

    foot_print = [0] * n
    check(adj_list, foot_print)

    q = int(input())
    for i in range(q):
        s, t = map(int, sys.stdin.readline().strip().split())
        if foot_print[s] == foot_print[t]:
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    main()



Measured memory_bytes: 122636
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define M 10001
int main()
{
  bool isPrime[M]={false,false};
  for(int i=2;i<M;i++)isPrime[i]=true;
  for(int i=2;i<M;i++)for(int j=i+i;j<M;j+=i)isPrime[j]=false;

  vector<int>sum;
  sum.push_back(0);
  for(int i=2;i<M;i++)if(isPrime[i])sum.push_back( i+sum.back() );

  int n;
  while(cin>>n,n){
    int count=0;
    for(vector<int>::iterator it=sum.begin();it!=sum.end();it++){
      if( binary_search(it, sum.end(), *it + n) ) count++;
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1248
n = int(input())
t = [int(input()) for _ in [0]*n]

if n==1:
  print(t[0])
  exit()
  
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

def lcm(x, y):
  return x * y // gcd (x, y)

ans = lcm(t[0],t[1])
if n>=3:
  for i in range(2,n):
    ans = lcm(ans,t[i])
    
print(ans)    

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 

int n,k,a[100005],f[100005];

int main(void){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	memset(f,0x3f,sizeof(f));
	f[1]=0;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++)
		if(i-j<=0)continue;
		else
		f[i]=min(f[i],abs(a[i]-a[i-j])+f[i-j]);
	}
	printf("%d",f[n]);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n, m, x;
	cin >> n >> m >> x;
  	vector<int> c(n);
  	vector<int> a(n*m);
  	vector<long> total(4100);
  	vector<long> skill(4100*m);
  	rep(i, n) {
      	cin >> c[i];
    	rep(j, m) {
        	cin >> a[i*m+j];
        }
    }
  	rep(k, (int)pow(2.0, n)) {
       rep(l, 13) {
         	if((k>>l) > 0 && ((k>>l) & 1) == 1) {
               	total[k] += c[l];
            	rep(i, m) {
                	skill[k*m + i] += a[l*m + i];
                }
            }
       }
     
       rep(i, m) {
         if(skill[k*m + i] < x) {
           	total[k] = -1;
         }
      }
    }
  	long mim = 1000000000;
    rep(k, (int)pow(2.0, n)) {
      	if(total[k] > 0)
    		mim = min(mim, total[k]);
    }
	if(mim == 1000000000)
      	mim = -1;
  	cout << mim << endl;
}


Measured memory_bytes: 4144
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
char s[101],i,j,k;
while(scanf("%s",s)>0){
for(i=0,k=strlen(s);i<k;i++)
{
	if(s[i]=='@')
	{
		for(j=0;j<s[i+1]-'0';j++)putchar(s[i+2]);
		i+=2;
	}
	else
		putchar(s[i]);
}
putchar('\n');
}return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int x[100005];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	int ans=abs(x[k-1]-x[0])+min(abs(x[0]),abs(x[k-1]));
	for(int i=1;i+k-1<n;i++){
		ans=min(ans,abs(x[k+i-1]-x[i])+min(abs(x[i]),abs(x[k+i-1])));
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair

int main() {
	ll n, a[114514] = {},ans = 1;
	cin >> n;
	REP(i, n) {
		ll b;
		cin >> b;
		a[b]++;
	}
	if (n % 2 == 0) {
		REP(i, n / 2) {
			if (a[i * 2 + 1] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	else {
		if(a[0] != 1) {
			cout << 0 << endl;
			return 0;
		}
		REPO(i, n / 2) {
			if (a[i * 2] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	REP(i, n / 2) {
		ans *= 2;
		if (ans > 1000000007) ans %= 1000000007;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1152
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val n = sc.next

    n.map { c => if (c == '9') '1' else '9'}.toString
  }
}


Measured memory_bytes: 25792
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    /*vector<int> v = {1, 2, 3, 4};
    map<vector<int> , int> m;
    do{
		m[v] = 1;
	}while(next_permutation(all(v)));
	for (auto it : m) {
		 int sum = 0;
		 vector<int> ret = it.f;
		 for (int i = 0; i < (int)ret.size(); i++){
			  sum += v[i] % ret[i]; 
			}	 
		  m[it.f] = sum;
		}
	for (auto it : m){
	  print(it.f);
	  cout << " ";
	  cout << it.s << endl;	
	}*/
	int n;
	cin >> n;
	int ret = n;
	ret *= (n - 1);
	ret /= 2;
	cout << ret << endl;	
 }

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define Ifor(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dfor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Ifoz(i, a) Ifor(i, 0, a)
#define Dfoz(i, a) Dfor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
vii seg;
vi f;
int n;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	cin >> n;
	int x, l;
	Ifoz(i, n) {
		cin >> x >> l;
		seg.pb({x - l, x + l});
	}
	sort(all(seg));
	f.assign(n, 0);
	f[n - 1] = 1;
	Dfoz(i, n - 1) {
		f[i] = f[i + 1];
		auto itr = lower_bound(all(seg), ii(seg[i].second, seg[i].second)); 
		if (itr == seg.end()) continue;
		int k = int(itr - begin(seg));
		ckmax(f[i], 1 + f[k]);
	}
	cout << f[0] << '\n';
}



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

int main(){
  int n;
  cin >> n;
  vector<int> ans(0);
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    if(i == 0 || x <= ans[ans.size()-1]){
      ans.push_back(x);
      continue;
    }
    int l=-1, r=ans.size()-1;
    while(l+1 < r){
      int mid = (l+r)/2;
      if(ans[mid] >= x) l = mid;
      else r = mid;
    }
    ans[r] = x;
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 892
n, m = map(int, input().split())
s = input()
dp = [0] * (n+1)
r = n

for i in range(n-1, -1, -1):
    if s[i] == '1':
        dp[i] = -1
        continue
    while(r > i + m):r -= 1
    while(dp[r] == -1): r-= 1
    if i == r:
        print(-1)
        exit(0)
    dp[i] = dp[r] + 1

now = 0
ans = []
for i in range(n+1):
    if dp[i] == -1: continue
    if dp[i] != dp[now]:
        ans.append(i-now)
        now = i

print(*ans)

Measured memory_bytes: 10224
/*
 * @author : ashish1610
 */
#include <bits/stdc++.h>
using namespace std;
#define ll	long long int
#define MOD	1000000007
int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (h / 2) * (a + b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
  int h, w, i, j;
  string s[105];
  
  cin >> h >> w;
  for(i = 0; i < h; i++){
	  cin >> s[i];
  }
  
  for(i = -1; i <= h; i++){
	if(i == -1 || i == h){
		for(j = -1; j <= w; j++){
			cout << "#";
		}
	}
	else{
		cout << "#" << s[i] << "#";
	}
	cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public class T{
		int a,b,c;
		T(int a,int b,int c){
			this.a = a;
			this.b = b;
			this.c = c;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int s = sc.nextInt()-1;
		int t = sc.nextInt()-1;
		ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();
		for(int i = 0 ; i < N ; i++)
			g.add(new ArrayList<Integer>());
		for(int i = 0 ; i < M ; i++){
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			g.get(a).add(b);
			g.get(b).add(a);
		}
		ArrayDeque<Integer> Q = new ArrayDeque<Integer>();
		int[] shortest1 = new int[N+1];
		int[] shortest2 = new int[N+1];
		
		int[] counter1 = new int[N+1];
		int[] counter2 = new int[N+1];
		
		Arrays.fill(shortest1,N);
		Arrays.fill(shortest2,N);
		Q.offer(s);
		shortest1[s] = 0;
		while( Q.size() > 0 ){
			int q = Q.poll();
			counter1[shortest1[q]]++;
			//System.out.println(q+1+" "+shortest1[q]);
			for( int to : g.get(q) ){
				if( shortest1[to] == N ){
					shortest1[to] = shortest1[q] + 1;
					Q.offer(to);
				}
			}
		}
		Q.offer(t);
		shortest2[t] = 0;
		while( Q.size() > 0 ){
			int q = Q.poll();
			counter2[shortest2[q]]++;
			//System.out.println(q+1+" "+shortest2[q]);
			for( int to : g.get(q) ){
				if( shortest2[to] == N ){
					shortest2[to] = shortest2[q] + 1;
					Q.offer(to);
				}
			}
		}
		//System.out.println("");

		int maximum = shortest1[t];
		long ans = 0;
		//for(int i = 0 ; i <= maximum ; i++){
		//	System.out.println(i+" "+counter[i]);
		//}
		for(int i = 0 ; i+2 <= maximum ; i++){

			ans += (long) counter1[i] * counter2[maximum-(i+2)];
		}
		System.out.println(ans);
		return;
	}
}

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

int main(int argc, char const *argv[])
{
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(v.begin(), v.end());
	ll ans = 0;

	for (int i = 0; i < k; ++i)
		ans += v[i];
	
	cout << ans;

	return 0;
}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll rec(string s){

  int idx = -1;
  VLL arr;
  int lv = 0;
  rep(i,s.size()){

    if(s[i] == '['){
      if(lv == 0) idx = i;
      lv--;
    }
    if(s[i] == ']'){
      lv++;
      if(lv == 0){
        arr.push_back(rec(s.substr(idx+1,i - (idx+1) )));
      }
    }
  }
  //cout << "rec" << s << ' ';
  if(arr.size() == 0){
    ll res = toInt(s);
    res = (res / 2) + 1;
    //cout << "return " << res << endl;
    return res;
  }else{
    ll res = 0;
    sort(all(arr));
    rep(i,(arr.size()/2) + 1){
      res += arr[i];
    }
    //cout << "return " << res << endl;

    return res;
  }
}

int main(){
  int n;
  cin >> n;
  string s;
  rep(i,n){
    cin >> s;
    cout << rec(s.substr(1,s.size()-2)) << endl;
  }
  return 0;
}



Measured memory_bytes: 3284
sa = raw_input()
sb = raw_input()
sc = raw_input()

class Person:
    def __init__(self, name, cards):
        self.name = name
        self.cards = cards

a = Person('A', sa)
b = Person('B', sb)
c = Person('C', sc)

turn = a
while turn.cards:
    if turn.cards[0] == 'a':
        turn.cards = turn.cards.replace('a', '', 1)
        turn = a
    elif turn.cards[0] == 'b':
        turn.cards = turn.cards.replace('b', '',1)
        turn = b
    elif turn.cards[0] == 'c':
        turn.cards = turn.cards.replace('c', '', 1)
        turn = c
print turn.name

Measured memory_bytes: 2692
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long r, g, b;
  cin >> r >> g >> b;
  long gb = g * 10 + b;
  if (gb % 4 == 0) puts("YES");
  else puts("NO");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int main()
{
  int n, a[N], i, j, judge, count=0;

  scanf("%d",&n);

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

  for(i=0; i<n; i++){
    judge = 0;
    if(a[i] == 2) judge = 0;

    else if(a[i] < 2 || a[i]%2 == 0) judge = 1;
    
    j = 3;
    while(j <= sqrt(a[i])){
      if(a[i]%j == 0){
	judge = 1;
	break;
      }
      j = j+2;
    }

    if(judge == 0) count++;
  }
  
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N; cin >> N;
    vector<int> x(N);
    rep(i, 0, N ) cin >> x[i];
    int ans = 1e9;
    rep(p, 0, 101){
        int cnt = 0;
        rep(i, 0, N){
            cnt += (p - x[i]) * (p - x[i]);
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int x=0,mx=0;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x++;
      mx=max(x,mx);
    }
    else{
      x--;
    }
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
int n,m;
cin>>n>>m;
vector<int> cnt(m,0);
for(int i=0; i<n; i++)
{
int k; cin>>k;
for(int j=0; j<k; j++)
{
    int a; cin>>a; --a;
    ++cnt[a];
}
}
int ans=0;
REP(i,m){
    if(cnt[i]==n) ++ans;
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  if ("YAKI" <= S and S < "YAKJ") puts("Yes");
  else puts("No");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  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 int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;

int solve(ll n){
    int a = 0;
    while(n % 2 == 0){
        a++;
        n /= 2;
    }
    return a;
}

int main()
{
    ll n, ans = 0;
    cin >> n;
    vector<ll> v(n);
    rep(i, n){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        ans += solve(v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
		
		int count = 0;
		
		if(n != 0 && k != 0){
			count = n-k+1;
		}
	
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 11092
import java.util.Scanner;


public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n;
		long y;
		n = scan.nextInt();
		y = 1;
		for (int i = n; i > 1; i--) {
			y *= i;
		}
		System.out.println(y);
	}

}

Measured memory_bytes: 17156
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static class State implements Comparable<State> {
		long a;
		State(long a){
			this.a = a;
		}
		public int compareTo(State s) {
			if(a > s.a) {
				return -1;
			}
			return 1;
		}
	}

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

    		int X = sc.nextInt();
    		int Y = sc.nextInt();
    		int Z = sc.nextInt();
    		long K = sc.nextLong();
    		long[] A = new long[X];
    		long[] B = new long[Y];
    		long[] C = new long[Z];
    		for(int i=0; i<X; i++) {
    			A[i] = sc.nextLong();
    		}
    		for(int i=0; i<Y; i++) {
    			B[i] = sc.nextLong();
    		}
    		for(int i=0; i<Z; i++) {
    			C[i] = sc.nextLong();
    		}
    		Arrays.sort(A);
    		Arrays.sort(B);
    		Arrays.sort(C);
    		PriorityQueue<State> pq = new PriorityQueue<State>();
    		for(int a=X-1; a>=0; a--) {
    			for(int b=Y-1; b>=0; b--) {
    				for(int c=Z-1; c>=0; c--) {
    					if((X-a)*(Y-b)*(Z-c)>K) break;
    					pq.add(new State(A[a]+B[b]+C[c]));
    				}
    			}
    		}
    		for(int i=0; i<K; i++) {
    			System.out.println(pq.remove().a);
    		}
    	}
    }
}


Measured memory_bytes: 35184
import math

A, B = map(int, input().split())

min_price_A = A * 12.5
max_price_A = min_price_A + 12

min_price_B = B * 10
max_price_B = min_price_B + 9

if min_price_A <= min_price_B:
    if max_price_A >= min_price_B:
        print(int(min_price_B))
    else:
        print(-1)
else:
    if max_price_B >= min_price_A:
        print(math.ceil(min_price_A))
    else:
        print(-1)


Measured memory_bytes: 3060
N = gets.to_i
a = N.times.map{gets.to_i}
hash = Hash.new(0)
sum = 0
N.times do |i|
  if hash[a[i]] == 0
    hash[a[i]] = 1
    sum += 1
  else
    hash[a[i]] = 0
    sum -= 1
  end
end
puts sum


Measured memory_bytes: 19884
#import <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, char **argv) {
  int N, M;
  scanf("%d %d", &N, &M);
  int items[N];
  int i = 0;
  int sum = 0;
  for(i=0; i<N; i++) {
    int x;
    scanf("%d", &x);
    items[i] = x;
    sum += x;
  }
  int count = 0;
  for(i=0; i<N; i++) {
    if (items[i] >= (double)sum / (4.0 * M)) {
      count ++;
    }
  }
  printf("%s", count >= M ? "Yes" : "No");
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    int N;
    ll D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(X[i]*X[i] + Y[i]*Y[i] <= D*D){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6424
package main
  
import (
    "fmt"
)

var m [][]int

const mod = int(1e9 + 7)

func main() {
    m = make([][]int, 2005)
    for i := range m {
        m[i] = make([]int, 2005)
    }
    var n, k int
    fmt.Scan(&n, &k)
    for i := 1; i <= k; i++ {
        b := com(k-1, i-1)
        r := com(n-k+1, i)
        fmt.Println((b * r) % mod)
    }
}

func com(n, r int) int {
    if r > n {
        return 0
    }
    if r == 0 || r == n {
        return 1
    } else if r == 1 {
        return n
    }
    if m[n][r] > 0 {
        return m[n][r]
    }
    a := com(n-1, r-1) % mod
    b := com(n-1, r) % mod
    c := (a + b) % mod
    m[n][r] = c
    return c
}


Measured memory_bytes: 21888
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[][][] = new int[4][3][10];
		int b, f, r;
		for( b=0; b<4; b++ ){
			for( f=0; f<3; f++ ){
				for( r=0; r<10; r++ ){
					a[b][f][r] = 0;
				}
			}
		}
		for( int i=0; i<n; i++ ){
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			a[b-1][f-1][r-1] += sc.nextInt();
			
		}
		for( b=0; b<4; b++ ){
			for( f=0; f<3; f++ ){
				for( r=0; r<10; r++ ){
					System.out.print( " " + a[b][f][r] );
				}
				System.out.println();
			}
			if( b != 3 ){
				System.out.println( "####################");
			}
		}
	}
}

Measured memory_bytes: 21208
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second

int par[100010], Rank[100010], chain[100010] = { 0 };


void init(int n) {
	for (int i = 0;i <= n;i++)par[i] = i, Rank[i] = 0;
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (Rank[x] < Rank[y])par[x] = y;
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	int n, m, p[100010], ans = 0;
	cin >> n >> m;
	for (int i = 1;i <= n;i++) {
		cin >> p[i];
	}
	init(100005);
	for (int i = 0;i < m;i++) {
		int x, y;
		cin >> x >> y;
		unite(x, y);
	}
	for (int i = 1;i <= n;i++) {
		if (same(i, p[i]))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,p;
		cin>>k>>p;
		if(k%p!=0){
		   cout<<k%p<<endl;
		}
		else{
			cout<<p<<endl;
		}	  
	}
}		



Measured memory_bytes: 3104
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split(" ");
    //文字列から10進数に変換するときはparseIntを使います
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    //出力
    var r = -1
    if (a < 10 && b < 10) {
        r = a * b        
    }
    console.log('%d', r);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int d, l;
	cin >> d >> l;
	
	cout << (d / l) + (d % l) << endl;
 
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((ll)(1e15))
#define pi (2*acos(0))
#define M ((int)(1e9 + 7))
#define NN ((int)(305))
#define N ((int)(1e5 + 5))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long lu;

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

int a[N];

int main()
{
    int n;
    scanf("%d",&n);
    ll sum = 0;
    for(int i = 0; i<n; i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    sort(a,a+n);
    int ans = 1;
    sum -= a[n-1];
    for(int i = n-2; i>=0; i--){
        if(sum*2<a[i+1]) break;
        ans++;
        sum -= a[i];
    }

    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

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

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int s = 0;
    int a[5];
    for( int i = 0; i < 5; ++i ) {
        cin >> a[i];

    }
    int m = 0;
    for( int i = 0; i < 5; ++i ) {
        if( a[i] % 10 != 0 ) s += ( a[i] / 10 + 1 ) * 10;
        else s += a[i] / 10 * 10;
        if( a[i] % 10 != 0 )m = max( m, 10 - a[i] % 10);
    }
    cout << s - m << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  ll a[5] = {};
  rep(i, N) {
    string name; cin >> name;
    if (name[0]=='M') a[0]++;
    else if (name[0]=='A') a[1]++;
    else if (name[0]=='R') a[2]++;
    else if (name[0]=='C') a[3]++;
    else if (name[0]=='H') a[4]++;
  }

  ll result = 0;
  for(int i=0; i<5; i++) {
    for(int j=i+1; j<5; j++){
      for(int k=j+1; k<5; k++) result += a[i]*a[j]*a[k];
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  string s;
  cin >> s;

  int a = 0;
  vector<int> ans(s.size(), 0);
  for (int i = 0 ; i < s.size(); i++) {
    if (s[i] == 'R') {
      a++;
    } else {
      ans[i] += a/2;
      ans[i-1] += a-a/2;
      a = 0;
    }
  }

  a = 0;
  for (int i = s.size() - 1 ; i >= 0; i--) {
    if (s[i] == 'L') {
      a++;
    } else {
      ans[i] += a/2;
      ans[i+1] += a-a/2;
      a = 0;
    }
  }

  for (int x : ans) {
    cout << x << " ";
  }
  cout << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 1488
#include <stdio.h>

int main(void)
{
char a[5000];
int i,total=0;
while(1){
gets(a);
if(a[0]=='0')break;
for(i=0;a[i]>='0'&&a[i]<='9';i++)
{
	total=total+a[i]-'0';
}

printf("%d\n",total);
total=0;

}
return 0;
}

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    vector<pair<ll,ll> >v;
    vector<int>o;
    int n;
    cin >> n;
    f(n){
        o.pb(i);
        ll add1,add2;
        cin >> add1 >> add2;
        v.pb({add1,add2});
    }
    double sum = 0;
    int cnt = 0;
    do{
        cnt++;
        for(int i = 1 ; i < n ; i ++){
            ll dx = v[o[i]].F - v[o[i-1]].F;
            ll dy = v[o[i]].S - v[o[i-1]].S;
            sum += sqrt(dx*dx+dy*dy);
        }
    }while(next_permutation(o.begin(),o.end()));
    cout << fixed << setprecision(10) << sum / cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

struct UnionFind{
	vector<int> par;

	UnionFind(int N) : par(N){
		for(int i=0; i<N; i++)par[i]=i;
	}

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

	void unite(int x, int y){
		x=root(x);
		y=root(y);
		if(x==y)return;
		par[x]=y;
	}

	bool same(int x, int y){
		return root(x)==root(y);
	}
};

int main(void){
	int n,m;
	cin >> n >> m;
	UnionFind tree(n);
	int x,y;
	vector<int> a(n);
	for(int i=0; i<n; i++)cin >> a[i];
	for(int i=0; i<m; i++){
		cin >> x >> y;
		tree.unite(x-1,y-1);
	}
	int ans=0;
	for(int i=0; i<n; i++){
		if(tree.same(i,a[i]-1))ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    if(n%2 == 0)
    printf("%.6f\n",(double)1/2);
    else{
        printf("%.6f\n",(double)((n/2)+1)/n);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=500010;
int n,q,x,j,l,r;
char ss[N],c[2];
int a[N];
int t[N<<2];
int tr(int x){
	//printf("x=%d\n",x);
	int ans=0;
	while(x){
		if(x%2) ans++;
		x=x>>1;
	}
	return ans;
}
void updt(int rt,int l,int r,int i,int a){
	if(l>i||r<i) return;
	if(l==r){
	    t[rt]=1<<a;
	    return;
	}
	int mid=(l+r)>>1;
	updt(rt<<1,l,mid,i,a);
	updt((rt<<1)+1,mid+1,r,i,a);
	t[rt]=t[rt<<1]|t[(rt<<1)+1];
}
int qry(int rt,int l,int r,int ql,int qr){
	//printf("rt=%d,l=%d,r=%d,ql=%d,qr=%d\n",rt,l,r,ql,qr);
	if(l>qr||r<ql) return 0;
	if(l==r||(l==ql&&r==qr)) return t[rt];
	int mid=(l+r)>>1;
	if(mid+1<=ql) return qry((rt<<1)+1,mid+1,r,ql,qr);
	if(mid>=qr) return qry(rt<<1,l,mid,ql,qr);
	return qry((rt<<1)+1,mid+1,r,mid+1,qr)|qry(rt<<1,l,mid,ql,mid);
}
int main()
{
	scanf("%d%s%d",&n,ss,&q);
	for(int i=1;i<=n;++i){
		a[i]=ss[i-1]-'a';
		updt(1,1,n,i,a[i]);
	}
	for(int i=1;i<=q;++i){
		scanf("%d",&x);
		if(x==1){
			scanf("%d%s",&j,c);
			updt(1,1,n,j,(int)(c[0]-'a'));
		}
		else{
			scanf("%d%d",&l,&r);
			printf("%d\n",tr(qry(1,1,n,l,r)));
		}
	}
}

Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int main(){
    int n,m;
    char flag;
    int cnt[50][3]{0};
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>flag;
            switch (flag) {
                case 'W':
                    ++cnt[i][0];
                    break;
                case 'B':
                    ++cnt[i][1];
                    break;
                case 'R':
                    ++cnt[i][2];
            }
        }
    }
    
    int sum=n*m;
    int w,b,r;
    w=0;
    for (int i=0;i<n-2;++i) {
        b=0;
        w+=cnt[i][1]+cnt[i][2];
        for (int j=i+1;j<n-1;++j) {
            r=0;
            b+=cnt[j][0]+cnt[j][2];
            for (int k=j+1;k<n;++k) {
                r+=cnt[k][0]+cnt[k][1];
            }
            sum=min(sum,w+b+r);
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int num;
string line;
map<int, int> m1, m2;

int main()
{
	while (getline(cin, line))
	{
		if (line == "") break;
		sscanf(line.c_str(), "%d", &num);
		m1[num]++;
	}

	while (getline(cin, line))
	{
		sscanf(line.c_str(), "%d", &num);
		m2[num]++;
	}

	for (map<int, int>::iterator it=m2.begin(); it!=m2.end(); it++)
	{
		if (m1[it->first] > 0)
		{
			cout << it->first << " " << m1[it->first] + it->second << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1240
A,B,AB,AX,BY = map(int,input().split())

a = min(A+B, 2*AB)
if AX <= BY:
    ans = a * AX + (BY - AX) * min(B, 2*AB)
else:
    ans = a * BY + (AX - BY) * min(A, 2*AB)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
int n,a[2005],b[2005],c[2005],ans;
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(reg int i=1;i<=n;i++)cin>>a[i];
    for(reg int i=1;i<=n;i++)cin>>b[i];
    for(reg int i=1;i<=n-1;i++)cin>>c[i];
    a[0]=-2;
    for(reg int i=1;i<=n;i++)
	{
        ans+=b[a[i]];
        if(a[i]==a[i-1]+1)ans+=c[a[i-1]];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
lis = stdin.readline().rstrip().split()
a = int(lis[0])
b = int(lis[1])
c = int(lis[2])

if a == 5 or a == 7:
    if a == 5:
        if b == 5 and c ==7:
            print("YES")
        elif b == 7 and c ==5:
            print("YES")
        else:
            print("NO")

    elif a == 7:
        if b == 5 and c == 5:
            print("YES")
        else:
            print("NO")
else:
    print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline LL Read()
{
	LL x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, e_cnt = 1, p[MAXN << 1], v[MAXN << 1], hed[MAXN], siz[MAXN];
LL cur, a[MAXN], val[MAXN];

inline void Addedge(int x, int y)
{
	e_cnt ++, p[e_cnt] = y, v[e_cnt] = hed[x], hed[x] = e_cnt;
	e_cnt ++, p[e_cnt] = x, v[e_cnt] = hed[y], hed[y] = e_cnt;
}

inline void DFS(int x, int par)
{
	siz[x] = 1;
	for (int i = hed[x]; i; i = v[i])
		if (p[i] ^ par)
		{
			DFS(p[i], x);
			if (siz[p[i]] << 1 ^ n)
				val[i >> 1] = (a[x] - a[p[i]]) / ((siz[p[i]] << 1) - n);
			siz[x] += siz[p[i]];
		}
}

inline void Cal(int x, int par)
{
	siz[x] = 1;
	for (int i = hed[x]; i; i = v[i])
		if (p[i] ^ par)
			Cal(p[i], x), cur += siz[p[i]] * val[i >> 1], siz[x] += siz[p[i]];
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i < n; i ++)
		Addedge(Read(), Read());
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	DFS(1, 0);
	for (int i = 1; i < n; i ++)
		if (!val[i])
		{
			int u = p[i << 1], v = p[i << 1 | 1];
			Cal(u, v), Cal(v, u);
			val[i] = (a[u] - cur) / siz[v];
		}
	for (int i = 1; i < n; i ++)
		printf("%lld\n", val[i]);
	return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  ll a,b,n,x;
  cin>>a>>b>>n;
  string s="No";
  
  rep(i,0,a+1){
    rep(j,0,b+1){
      x=i*b+j*a-2*i*j;
      if(x==n) s="Yes";
    }
  }
  co(s);
    
  return 0;
}

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

using namespace std; 
int main()
{
int a,b,w;
cin>>w>>a>>b;
if(a>=0 && b>=0 && w>=0){
	 if(b>a+w){
	
	cout<<b-(a+w);}
	else if(a>b+w)
	{
		cout<<a-(b+w);
	}
	else
	{
		 cout<<"0";
	}



}

} 

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

int main(int argc, char const* argv[])
{
    unsigned n;
    std::cin >> n;
    while (n!=0) {
        double sum{};
        double sigma{};
        double m{};
        std::vector<int> ss;
        for (int i = 0; i < n; i++) {
            int s;
            std::cin >> s;
            ss.push_back(s);
        }
        sum = 0.;
        for (auto&& s : ss) {
            sum += s;
        }
        m = sum / n;
        for (auto&& s : ss) {
            sigma += (s - m) * (s - m);
        }
        std::cout << std::fixed <<std::setprecision(8) << std::sqrt(sigma/n) << std::endl;
        std::cin >> n;
    }

    return 0;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    ll a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

using namespace std;

int N;
vector<int> p;
int main () {
  cin >> N;
  int pi;
  for (int i = 0; i < N; i++) {
    cin >> pi;
    p.push_back(pi);
  }
  int cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    if(p[i] == i + 1) {
      swap(p[i], p[i + 1]);
      cnt += 1;
    }
  }
  if(p[N - 1] == N) {
    cnt += 1;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 892
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long n,N,i,x,Q,p,l,r,last,j;
long long a[100008],b[100008];
long long q[100008][60][2];
long long ans[100008];
int main()
{
	scanf("%lld %lld",&N,&Q);
	a[n=1]=N;
	for(i=1;i<=Q;i++)
	{
		scanf("%lld",&x);
		while(a[n]>=x)n--;
		a[++n]=x;
	}
	q[1][0][1]=a[1];
	for(i=2;i<=n;i++)
	{
		p=a[i];last=i-1;
		while(p>=a[1])
		{
			l=1;r=last;
			while(l!=r)
			{
				if(a[(l+r+1)/2]<=p)l=(l+r+1)/2;
				else r=(l+r+1)/2-1;
			}
			q[i][++q[i][0][0]][0]=l;
			q[i][q[i][0][0]][1]=p/a[l];
			p=p%a[l];last=l;
		}
		q[i][0][1]=p;
	}
	b[n]=1; 
	for(i=n;i>=1;i--)
	{
		for(j=1;j<=q[i][0][0];j++)
		  b[q[i][j][0]]+=q[i][j][1]*b[i];
		ans[q[i][0][1]]+=b[i];
	}
	for(i=N;i>=1;i--)
	  ans[i]+=ans[i+1];
	for(i=1;i<=N;i++)
	  printf("%lld\n",ans[i]); 
	return 0;
} 
/*
10 10
9
13
18
8
10
10
9
19
22
27
 
8
9
19
22
27
*/

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

int main() {
  int S,W;
  cin>>S>>W;
  if(S<=W) cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
}

Measured memory_bytes: 3560
X, N = map(int, input().split())
try:
  p=set(map(int, input().split()))
except Exception:
  p=set()
i = 0
while 1: 
  ans = X - i
  if ans not in p:
    print(ans)
    break
  ans = X + i
  if ans not in p:
    print(ans)
    break
  i = i + 1

Measured memory_bytes: 9188