akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define M 750001
#define L 14

char H[M][L];

int getChar(char ch);

long long getKey(char str[]);

int h1(int key);
int h2(int key);

int find(char str[]);

int insert(char str[]);

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ){ H[i][0] = '\0';}

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);

	if ( com[0] == 'i' ){
	    insert(str);
	}
  else {
	    if (find(str)==1){
		printf("yes\n");
	    }
      else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return (1+key%(M-1)); }

int find(char str[]){
    int i;
    long long h;
      /* code */
    for(i=0;;i++){
      h=(h1(getKey(str))+i*h2(getKey(str)))%M;
      if(strcmp(str,H[h])==0){

        return 1;
      }
      if(H[h][0]=='\0'){
        return 0;
      }
    }
    /* your task */
}

int insert(char str[]){
  int i;
  long long h;
    /* code */
  for(i=0;;i++){
    h=(h1(getKey(str))+i*h2(getKey(str)))%M;
    if(strcmp(str,H[h])==0){

      return 1;
    }
    if(H[h][0]=='\0'){
      strcpy(H[h],str);
      return 0;
    }
  }
  /* your task */

}



Measured memory_bytes: 11972
#include <stdio.h>

int	main(void)
{
	int	h = 0;
	int	w = 0;
	int i;
	int j;

	while (1)
	{
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0)
			break ;
		i = 0;
		while (i < h)
		{
			j = 0;
			if (i == 0 || i == (h - 1))
			{
				while (j < w)
				{
					printf("%c", '#');
					j++;
				}
			}
			else
			{
				printf("%c", '#');
				while (j < (w - 2))
				{
					printf("%c", '.');
					j++;
				}
				printf("%c", '#');
			}
			printf("%c", '\n');
			i++;
		}
		printf("%c", '\n');
	}
	return (0);
}




Measured memory_bytes: 2048
#include <stdio.h>

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  int h[n];
  int a[m],b[m];
  int t[n];
  int i;
  i = 0;
  while (i < n)
  {
    scanf("%d",&h[i]);
    t[i] = 0;
    i++;
  }
  i = 0;
  while (i < m)
  {
    scanf("%d%d",&a[i],&b[i]);
    if (h[a[i] - 1] > h[b[i] - 1])
      t[b[i] - 1] -= 1;
    else if (h[a[i] - 1] < h[b[i] - 1])
      t[a[i] - 1] -= 1;
    else
    {
      t[b[i] - 1] -= 1;
      t[a[i] - 1] -= 1;
    }
    i++;
  }
  i = 0;
  int sum;
  sum = 0;
  while (i < n)
  {
    if (t[i] == 0)
    {
      sum += 1;
    }
    i++;
  }
  printf("%d",sum);
}

Measured memory_bytes: 3280
#include<stdio.h>

int main(){
    int N,M,i,j,k,a=0,b=0;
    scanf("%d %d",&N,&M);
    int x[N];
    for(k=1;k<=N;k++){
    	x[k]=0;
    }
    
    for(i=1;i<=M;i++){
        scanf("%d %d",&a,&b);
        x[a]++;
        x[b]++;
    }
    
    for(j=1;j<=N;j++){
        printf("%d\n",x[j]);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int f=2,r=3,u=1,sum=0;
		string s;
		for(int i=0;i<n;i++){
			int nf,nr,nu;
			cin>>s;
			if(s=="North"){
				nr=r;
				nf=7-u;
				nu=f;
			}else if(s=="East"){
				nr=u;
				nf=f;
				nu=7-r;
			}else if(s=="West"){
				nr=7-u;
				nf=f;
				nu=r;
			}else if(s=="South"){
				nr=r;
				nf=u;
				nu=7-f;
			}else if(s=="Right"){
				nr=7-f;
				nf=r;
				nu=u;
			}else{
				nr=f;
				nf=7-r;
				nu=u;
			}
			f=nf;r=nr;u=nu;
			sum+=u;
		}
		cout<<sum+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
char str[100];
int main(){
	scanf("%s",str);
	bool ok=true;
	if(strlen(str)<6)ok=false;
	bool OK=false;
	for(int i=0;str[i];i++){
		if('0'<=str[i]&&str[i]<='9')OK=true;
	}
	if(!OK)ok=false;
	OK=false;
	for(int i=0;str[i];i++){
		if('a'<=str[i]&&str[i]<='z')OK=true;
	}
	if(!OK)ok=false;
	OK=false;
	for(int i=0;str[i];i++){
		if('A'<=str[i]&&str[i]<='Z')OK=true;
	}
	if(!OK)ok=false;
	if(ok)printf("VALID\n");
	else printf("INVALID\n");
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (d == 1) {
		cout << "1" << endl;
	}
	else cout << '0' << endl;
}


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

const int MOD = (int)1e9+7;

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

	long long ans=1;
	for(long long i=1;i*i<=N;i++){
		if(N%i==0)	ans=i;
	}
	long long ans2=N/ans;
	cout << ans-1 + ans2-1 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val Array(h, w) = in.readLine.split("\\s+").map(_.toInt)
    val table = Array.fill(h) {
      in.readLine.split("\\s+").map(_.toInt)
    }

    @inline
    def cursorToXY(cursor: Int): (Int, Int) = {
      (if (cursor / w % 2 == 0) {
        cursor % w
      } else {
        w - 1 - cursor % w
      }, cursor / w)
    }

    val moves = ArrayBuffer.empty[List[Int]]

    for (cursor <- 0 until h * w - 1) {
      val (x, y) = cursorToXY(cursor)
      if (table(y)(x) % 2 == 1) {
        val (nx, ny) = cursorToXY(cursor + 1)
        moves.append(List(y + 1, x + 1, ny + 1, nx + 1))
        table(ny)(nx) += 1
      }
    }

    out.println(moves.length)
    for(move <- moves) {
      out.println(move.mkString(" "))
    }

    out.flush()
  }
}

Measured memory_bytes: 100360
#include <iostream>
#include <stdlib.h>

using namespace std;

int N;
int x[100005];

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> x[i];
	
	int sum = 0;
	for(int i = 0; i <= N; i++){
		sum += abs(x[i] - x[i+1]);
	}
	
	for(int i = 1; i <= N; i++){
		int dif = abs(x[i-1] - x[i]) + abs(x[i] - x[i+1]) - abs(x[i-1] - x[i+1]);
		cout << sum - dif << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int a[101];
int b[101];
int main()
{
    int a1,b1,c,d;
    cin>>a1>>b1>>c>>d;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=a1;i<b1;++i)
    {
        a[i]=1;
    }
    for(int i=c;i<d;++i)
    {
        b[i]=1;
    }
    int k=0;
    for(int i=0;i<=101;i++)
    {
        if(a[i]==1&&b[i]==1)
            {k++;}
    }
    cout<<k<<endl;
}


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

using namespace std;

L n,start,ans=1,realans=1000000;
vector<L>v[100010];
L chk[100010];
L dwn[100010];
L bel[100010];

void dfs1(L x){
	L i;
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			chk[v[x][i]]=1;
			dwn[x]++;
			dfs1(v[x][i]);
			bel[x]|=bel[v[x][i]];
		}
	}
	if(dwn[x]>=2) bel[x]=1;
}

void dfs2(L x,L bury){
	L i,passed=0;
	//printf("%lld %lld\n",x,bury);
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			if(!bel[v[x][i]])
			{
				if(!passed)
				{
					passed=1;
				}
				else
				{
					//printf("*%lld*\n",x);
					ans++;
					bury=0;
				}
			}
			else
			{
				chk[v[x][i]]=1;
				dfs2(v[x][i],1);
				bury=0;
			}
		}
	}
	if(bury) ans++;
}

int main()
{
	srand((int)time(NULL));
	scanf("%lld",&n);
	L i;
	for(i=1;i<n;i++)
	{
		L s,e;
		scanf("%lld %lld",&s,&e);
		s++;
		e++;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	vector<L>starts;
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1) starts.push_back(i);
	}
	L lop=100;
	while(lop--)
	{
		ans=1;
		for(i=1;i<=n;i++)
		{
			chk[i]=dwn[i]=bel[i]=0;
		}
		start=starts[rand()%starts.size()];
		chk[start]=1;
		dfs1(start);
		for(i=1;i<=n;i++)
		{
			chk[i]=0;
		}
		chk[start]=1;
		dfs2(start,0);
		realans=min(realans,ans);
	}
		printf("%lld",realans);
}

Measured memory_bytes: 12800
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum,minv,u,p;
  int M[MAX][MAX];
  int  key[MAX],pi[MAX],vis[MAX];

  scanf("%d", &n);
  
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for(i=0; i<n; i++){
    key[i]=INFTY;
    pi[i]=-1;
    vis[i]=0;
  }
  key[0]=0;

  while(1){
    u=-1;
    minv=INFTY;

    for(i=0; i<n; i++){
      if(key[i] < minv && !vis[i]){
	u=i;
	minv = key[i];
      }
    }

    if(u==-1)
      break;

    vis[u]=1;

    for(i=0; i<n; i++){
      if(M[u][i] < key[i] && !vis[i]){
	key[i] = M[u][i];
	pi[i]=u;
      }
    }
  }



  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) sum += M[i][pi[i]];
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 808
import java.util.*;
public class Main {
static Scanner scan=new Scanner(System.in);
static int id[];
static void connect(int u,int v){
	int i = root(u);
	int j = root(v);
  if(i==j)
		return;
	id[i] = j;
	
}
 
static int root(int i) {
	while(i!=id[i]) {
		i=id[i];
		
	}
	return i;
}
static int connected(int u,int v){
	if( root(u)==root(v))
		return 1;
	else return 0;
}
	public static void main(String[] args) {
	//	int isconetted[]=new int [1000];
		id = new int[1000000];
		for (int i = 0; i < 1000000; i++) id[i] = i;		
int n=scan.nextInt(),Q=scan.nextInt();
int i=0;
while(i!=Q) {
	int q=scan.nextInt();
int u=scan.nextInt();
int v=scan.nextInt();
if(q==0) 
	connect(u, v);
	else if(q==1)
	System.out.println(connected(u, v));
	
i++;
}
/*for(int j=0;j<isconetted.length;j++)
{
System.out.println(isconetted[j]);	
}
	}
*/
}}

Measured memory_bytes: 72084
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a) for(int i=0;i<a;i++)

//int型を受け取ってその桁数を返す
int check_digits(int n, int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum = 0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}


void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }


//提出言語もしっかり確認して…
//問題文を落ち着いて読む！
//型に注意！！
//出力例もちゃんと全部見る！！！！！
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			system("pause");
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			system("pause");
			return 0;
		}
	}

	system("pause");
	return 0;
}


Measured memory_bytes: 3724
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input().strip())
    hl = list(map(int,input().strip().split()))
    cnt=0
    while 1:
        maxh=max(hl)
        if maxh==0:
            break
        t=-1
        for i in range(n):
            if hl[i]>0:
                hl[i]-=1
                if i==0:
                    cnt+=1
                elif (i-1)==t:
                    cnt+=0
                else:
                    cnt+=1
                t=i
    print(cnt)

    return

resolve()

Measured memory_bytes: 52204
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

ll ctoi(char c) {
    return c - 'a';
}

vector<ll> convert(string s) {
    vector<ll> ret(26);
    for (int i = 0; i < s.size(); i++) {
        ret[ctoi(s[i])]++;
    }

    return ret;
}

bool comp(const vi& left, const vi& right) {
    for (int i = left.size()-1; i >= 0; i--) {
        if (left[i] < right[i]) {
            //上の位から見てゆく aaa < abc aaa < aab
            return true;
        }
    }
    return false;
}
int main() {
    int N; cin >> N;
    vector<vector<ll>> vecalph(N, vector<ll>(26));
    rep(i, N) {
        string s; cin >> s;
        vecalph[i] = convert(s);
    }

    sort(ALL(vecalph));
    reverse(ALL(vecalph));

    ll cnt = 0;
    vll table;
    vll temp = vecalph[0];

    for (int i = 0; i < N; i++) {
        if (i < N - 1) {
            if (temp == vecalph[i]) {
                cnt++;
            }
            else {
                table.push_back(cnt);
                temp = vecalph[i];
                cnt = 1;
            }
        }
        else {
            if (temp == vecalph[i]) {
                cnt++;
            }
            table.push_back(cnt);
            cnt = 0;
        }
    }

    ll ans = 0;
    for (int i = 0; i < table.size(); i++) {
        ans += table[i] * (table[i] - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 25592
import itertools
N=int(input())
k=len(str(N-1))
A=(3,5,7)
a=0
X=[]
for j in range(1,k+1):
    X+=list(itertools.product(A,repeat=j))
def nu(li):
    S=''
    for i in li:
        S+=str(i)
    return int(S)
for i in X:
    if (7 in i) and (5 in i) and (3 in i) and nu(i)<=N:
        a+=1
print(a)

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	bool a[4][100000] = {{false, false}, {false, true}, {true, false}, {true, true}};
	for (int i = 2; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			a[j][i] = a[j][i - 1] ^ a[j][i - 2] ^ (s[i - 1] == 'o');
		}
	}
	int k = -1;
	for (int i = 0; i < 4; i++) {
		if ((s[n - 1] == 'o') == (a[i][n - 2] ^ a[i][n - 1] ^ a[i][0]) && (s[0] == 'o') == (a[i][n - 1] ^ a[i][0] ^ a[i][1])) {
			k = i;
			break;
		}
	}
	if (k == -1) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < n; i++) {
			cout << "WS"[a[k][i]];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int LEN = 400;

int main() {
  int N; cin >>N;
  vector<int> v(LEN, -1);
  v[0] = 0;
  REP(z, N){
    int S, L, P; cin >>S >>L >>P;
    REP(i, LEN){
      if(v[i] == -1) continue;
      FOR(t, i + S, min(LEN, i + L + 1)) v[t] = max(v[t], v[i] + P);
    }
  }
  int M; cin >>M;
  vector<int> ws(M);
  bool f = 0;
  REP(i, M){
    int w; cin >>w;
    if(v[w] == -1) f = 1;
    ws[i] = w;
  }
  if(f) cout <<-1 <<endl;
  else REP(i, M) cout <<v[ws[i]] <<endl;
  return 0;
}

Measured memory_bytes: 1200
v[20];char A[9],t[9],s[9],c;
#define I(s)strtol(s,0,10)
int main(a,L,i,j,k){
	for(;scanf("%d%d",&a,&L),L;){
		for(s[L]=0,v[0]=a,k=1;;v[k++]=a){
			sprintf(A,"%%0%dd",L),sprintf(t,A,a);
			for(i=0;i<L;s[i]=t[L-i-1],i++)for(j=1;j<L-i;j++)if(t[j]<t[j-1])c=t[j],t[j]=t[j-1],t[j-1]=c;
			a=I(s)-I(t);
			for(i=0;i<k;i++)if(v[i]==a)break;
			if(i<k){printf("%d %d %d\n",i,a,k-i);break;}
		}
	}
}

Measured memory_bytes: 0
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n,k,MOD=1000000007,t=1;
vvi G;
void dfs(int a,int p,int q){
	(t*=k-q)%=MOD;
	int c=0;
	rep(i,G[a].size())if(G[a][i]-p){
		dfs(G[a][i],a,1+(q>=1)+(c++));
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>k;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1,0);
	cout<<t<<endl;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
const int p=31;
const int m=1e9+7;
typedef long long ll;
typedef int in;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");} 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define int ll
ll pw(ll x,ll r){
	ll ans=1;
	while(r>0){
		if(r%2)ans=(ans*x)%m;
		r/=2;
		x*=x;
		x%=m;
	}
	return(ans%m);
}

in main (){
	
    ll n,ans=0;
    cin>>n;
    if(n<2){
    	cout<<0;
    	return 0;
    }
    ans=pw(10,n);
    ans%=m;
    ans=ans-(2*pw(9,n))+pw(8,n);
    ans=(ans%m +m)%m;
    cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time    
}
    


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    vector<int> p(n+1,0);
    for(int i=1;i<=n;i++) cin >> p[i];
    vector<ll> c(n+1,0);
    for(int i=1;i<=n;i++) cin >> c[i];
    ll res=-(1ll<<60);
    for(int i=1;i<=n;i++)
    {
        vector<int> cycle={i};
        while(p[cycle.back()]!=i) cycle.push_back(p[cycle.back()]);
        int m=cycle.size();
        vector<ll> a;
        for(int x:cycle) a.push_back(c[x]);
        ll sum=0;
        vector<ll> s(m,0);
        for(int j=0;j<min((int)k,m);j++)
        {
            s[j]=a[j];
            if(j>0) s[j]+=s[j-1];
            sum+=a[j];
            res=max(res,sum);
        }
        if(k<m) continue;
        for(int sz=1;sz<=m;sz++) res=max(res,sum*((k-sz)/m)+s[sz-1]);
    }
    cout << res << "\n";
    return 0;
}


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

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

  vector<int> a(n),b(n);
  vector<int> cnt(n + 1);
  rep(i,n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  rep(i,n) {
    cin >> b[i];
    cnt[b[i]]++;
  }

  reverse(b.begin(),b.end());
  rep(i,n + 1) {
    if(cnt[i] > n) {
      cout << "No" << '\n';
      return 0;
    }
  }
  int x = 0;
  int k = 0;
  vector<int> overlap;
  for (int i = 0; i < n; i++) {
    if(a[i] == b[i]) {
      x = a[i];
      overlap.push_back(i);
      k++;
    }
  }
  vector<int> idx;
  for (int i = 0; i < n; i++) {
    if(a[i] != x && b[i] != x) {
      idx.push_back(i);
    }
  }

  for (int i = 0; i < k; i++) {
    swap(b[overlap[i]], b[idx[i]]);
  }

  cout << "Yes" << '\n';
  for (auto it : b) cout << it << " ";

}


Measured memory_bytes: 6916
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
thx
http://pekempey.hatenablog.com/entry/2016/07/18/031412
*/
/*
木なら中心がある。直径が指定されているので
中心を総当りして、各頂点から(半径?)調べる。
中心を指定して直径内の頂点を数える=>範囲外の個数が分かる。
範囲外の個数の最小値を調べる。
*/
vector< vector<int> > gra;
/*
curr:現在地
prev:行き止まり:prev方向には行かない
d:進める残りの距離
*/
int dfs(int curr,int prev,int d){//curr-prev
	if( d < 0 ){
		return 0;
	}
	int res = 1;
	int size = gra[curr].size();
	for(int i=0;i<size;++i){
		int next = gra[curr][i];
		if( next == prev ) continue;
		res += dfs(next,curr,d-1);
	}
	return res;
}
void solve(){
	int N,K;
	cin >> N >> K;
	gra.resize(N);
	for(int i=0;i<N-1;++i){
		int u,v;
		cin >> u >> v;
		--u;--v;
		gra[u].push_back(v);
		gra[v].push_back(u);
	}

	int ans = INF;//消す頂点数の最小値
	if( K%2 == 0 ){//探す直径が偶数:中心は１つ
		for(int i=0;i<N;++i){
			//iを中心として距離K/2までの頂点数
			int res = dfs(i,-1,K/2);
			//全体n-範囲内 = 消す頂点数
			ans = min(ans,N-res );
		}
	}else{//探す直径が奇数:中心は２つ
		for(int u=0;u<N;++u){
			int size = gra[u].size();
			for(int i=0;i<size;++i){
				int v = gra[u][i];
				if( v < u ) continue;
				//uからvへは行かない=uからvの子へいけない
				int res1 = dfs(u,v,(K-1)/2);
				//vからuへは行けない
				int res2 = dfs(v,u,(K-1)/2);
				//u-vの距離1を引いている。
				ans = min(ans,N-res1-res2);
			}
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


int a[3];

int main() {

    rep(i, 3)cin >> a[i];

    int mi = INF;
    mi = min({ a[0] + a[1],a[0] + a[2],a[1] + a[2] });

    cout << mi << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int H, W, i, j;

  while(1) {
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;

    for(i=0;i<H;i++) {
      for(j=0;j<W;j++) {
        if(i==0 || i== H-1 || j==0 || j==W-1) {
          printf("#");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2024
#include <iostream>
#include <algorithm>
using namespace std;
#define NIL -1
struct Node {
	int depth, left, right, parent;
	Node()
	{
		left = right = parent = NIL;
	}
} *node;

void setDepth(int x, int d)
{
	node[x].depth = d;
	if (node[x].left != NIL)
		setDepth(node[x].left, d + 1);
	if (node[x].right != NIL)
		setDepth(node[x].right, d);
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, id, k, root;
	int c, pre;
	cin >> n;
	node = new Node[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> id >> k;
		if (k > 0)
		{
			cin >> c;
			node[id].left = c;
			node[c].parent = id;
			pre = c;
			for (int j = 1; j < k; j++)
			{
				cin >> c;
				node[pre].right = c;
				node[c].parent = id;
				pre = c;
			}
		}
	}
	for (root = 0; root < n; ++root)
		if (node[root].parent == NIL)
			break;

	setDepth(root, 0);

	for (int i = 0; i < n; ++i)
	{
		cout << "node " << i << ": parent = " << node[i].parent << ", depth = " << node[i].depth << ", ";
		if (node[i].parent == NIL)
			cout << "root, ";
		else if (node[i].left == NIL)
			cout << "leaf, ";
		else
			cout << "internal node, ";
		cout << '[';
		if (node[i].left != NIL)
		{
			int j = node[i].left;
			cout << j;
			while (node[j].right != NIL)
			{
				j = node[j].right;
				cout << ", " << j;
			}
		}
		cout << ']' << endl;
	}

	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s, t;
  cin >> s >> t;
  int sn = s.size();
  int tn = t.size();
  vector<vector<int>> v(26);
  rep(i, 0, sn) v[s[i] - 'a'].push_back(i);

  int cur = -1;
  ll ans = 0;
  rep(i, 0, tn) {
    int ind = t[i] - 'a';
    if (v[ind].size() == 0) {
      cout << -1 << endl;
      return 0;
    }

    auto up = upper_bound(v[ind].begin(), v[ind].end(), cur);
    int x = *up;
    int id = up - v[ind].begin();
    if (id == v[ind].size()) {
      up = upper_bound(v[ind].begin(), v[ind].end(), -1);
      x = *up;
      id = up - v[ind].begin();
    }

    if (x <= cur) {
      ans += sn - (cur + 1);
      cur = -1;
    }

    ans += x - cur;
    cur = x;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int x,a;
	cin >> x >> a;
	if(x<a)cout<<0<<endl;
	else cout<<10<<endl;
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int x, y, a, b, c;
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	vii app;
	for (int i = 0; i < a; i++) {
		int p; scanf("%d", &p);
		app.emplace_back(p, 1);
	}
	for (int i = 0; i < b; i++) {
		int p; scanf("%d", &p);
		app.emplace_back(p, 2);
	}
	for (int i = 0; i < c; i++) {
		int p; scanf("%d", &p);
		app.emplace_back(p, 0);
	}

	sort(app.rbegin(), app.rend());

	int total = x + y;
	ll ans = 0;
	for (auto p : app) {
		if (p.second == 0) {
			--total;
			ans += p.first;
		}
		else if (p.second == 1) {
			if (x > 0) {
				--x;
				--total;
				ans += p.first;
			}
		}
		else {
			if (y > 0) {
				--y;
				--total;
				ans += p.first;
			}
		}
		if (total == 0) break;
	}
	printf("%lld\n", ans);
}


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

int main()
{
  int n;
  int cnt[50];
  int moji[5]={5,7,5,7,7};
  
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i < n;i++){
      string str;
      cin >> str;
      cnt[i]=str.size();
    }
    
    int ans=-1;
    for(int i=0;i<n;i++){
      if(ans!=-1)continue;
      int now=0;
      int len=0;
      for(int j=i;j < n;j++){
	len+=cnt[j];
	if(len == moji[now]){
	  now++;
	  len=0;
	}else if(len > moji[now]){
	  break;
	}
	if(now==5){
	  ans=i;
	  break;
	}
      }
    }
    cout << ans+1 << endl;
  }
  return 0;
}


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

int main() {
    int n = 0;
    cin >> n;
    int x = 0; //max amount
    cin >> x;
    int doughnut[n];

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

    int min = doughnut[0];

    for (int i = 0; i < n; i++) {
        if (doughnut[i] < min) min = doughnut[i];
    }

    int num = 0;
    for (int i = 0; i < n; i++) {
        if (x - doughnut[i] < 0) break;

        x -= doughnut[i];
        num++;
    }

    while (x - min >= 0) {
        x -= min;
        num++;
    }
    cout << num << endl;
}



Measured memory_bytes: 256
N, Q = map(int, input().split())
S = " " + input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ans = [0 for _ in range(N+10)]

for i in range(1, N+1):
    if S[i-1:i+1] == "AC":
        ans[i] += 1
    ans[i] += ans[i-1]

for l, r in lr:
    print(ans[r] - ans[l])

Measured memory_bytes: 69592
/**
 * Contest : Social Infrastructure Information System Division, Hitachi Programming Contest 2020
 * Contest URL : https://atcoder.jp/contests/hitachi2020/
 * Problem : C - ThREE
 * Problem URL : https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

// This section is for Policy Based Data Structure, more precisely Ordered Set.
// All Functions of set works here, in addition we have order_of_key() and find_by_order() function. find_by_order() returns iterator
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace __gnu_pbds;
// All unique value
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1;
// For storing multiple occurance of same value we need to use pair. In pair first value is our key and second is useless count variable.
// order_of_key(make_pair(key, 0)) returns first occurance of a value, order_of_key(make_pair(key, INT_MAX)) returns last occurance.
typedef tree<pair<int, int>, null_type, less<pair<int,int> >,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// Policy End


int main() {
	cin.tie (0);
	ios::sync_with_stdio (false);
	int n, a, b;
	cin >> n;
	vector < vector < int > > g (n);
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		a--, b--;
		g[a].push_back (b);
		g[b].push_back (a);
	}
	vector < int > nodes[2];
	std::function<void(int,int,int)> dfs = [&] (int u, int p, int index) {
		nodes[index].push_back (u);
		for (int v : g[u]) {
			if (v != p) {
				dfs (v, u, 1 - index);
			}
		}
	};
	dfs (0, -1, 0);
	int red = 0, blue = 1;
	if (nodes[red].size() > nodes[blue].size()) {
		red = 1, blue = 0;
	}
	int x = n / 3;
	vector < int > p (n);
	vector < int > visited (n + 1);
	if (nodes[red].size() <= x) {
		int current = 3;
		for (int u : nodes[red]) {
			p[u] = current;
			visited[current] = true;
			current += 3;
		}
		current = 1;
		for (int u : nodes[blue]) {
			while (visited[current]) {
				current++;
			}
			p[u] = current;
			visited[current] = true;
			current++;
		}
	} else {
		int one = 1, two = 2, three = 3;
		for (int u : nodes[red]) {
			if (one <= n){
				p[u] = one;
				one += 3;
			} else {
				p[u] = three;
				three += 3;
			}
		}
		for (int v : nodes[blue]) {
			if (two <= n) {
				p[v] = two;
				two += 3;
			} else {
				p[v] = three;
				three += 3;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << p[i] << " ";
	}
	cout << "\n";
	
	return 0;
}



Measured memory_bytes: 23540
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll a;
	string s;
	cin >> a >> s;

	int n = s.size();
	ll b = 0;
	rep(i, n){
		if(s[i] == '.') continue;
		b *= 10;
		b += s[i] - '0';
	}
	
	cout << a * b / 100 << endl;
}


Measured memory_bytes: 3652
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
ll dp[105][N];
ll w[105],v[105];
ll f(ll idx,ll wt)
{
	//cout<<"idx="<<idx<<" wt="<<wt<<"\n";
	if(idx<0)return 0;
	if(dp[idx][wt]!=-1)return dp[idx][wt];
	else
	{
		ll ans=f(idx-1,wt);
		if(w[idx]<=wt)ans=max(ans,f(idx-1,wt-w[idx])+v[idx]);
		return dp[idx][wt]=ans;
	}
	//cout<<"dp["<<idx<<"]["<<wt<<"]="<<dp[idx][wt]
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,wt,i,j,k;
		cin>>n>>wt;

		for(i=0;i<n;i++)cin>>w[i]>>v[i];

		for(i=0;i<105;i++)for(j=0;j<N;j++)dp[i][j]=-1;

		cout<<f(n-1,wt);
	}
	return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  switch(x%7){
  case 0:
    cout << "thu" << endl;
    break;
  case 1:
    cout << "fri" << endl;
    break;
  case 2:
    cout << "sat" << endl;
    break;
  case 3:
    cout << "sun" << endl;
    break;
  case 4:
    cout << "mon" << endl;
    break;
  case 5:
    cout << "tue" << endl;
    break;
  case 6:
    cout << "wed" << endl;
    break;
  }
    return 0;
}


  





Measured memory_bytes: 3084
import math
def update(index,y):
    targ[index] += y
    index = (index - 1) // 2
    while True:
        targ[index] = targ[index*2 + 1] + targ[index*2 + 2]
        if index <= 0:
            break
        index = (index - 1) // 2

def find(ini,end,node,inode,enode):
    #print(ini,end,node,inode,enode)
    if ini > enode or inode > end:
        return 0
    elif (inode >= ini and end >= enode) or inode == enode:
        return targ[node]
    else:
        ininum = find(ini,end,node*2 + 1,inode,(inode+enode)//2)
        endnum = find(ini,end,node*2 + 2,(inode+enode)//2 + 1,enode)
        return ininum + endnum

num,query = (int(n) for n in input().split(' '))
ln = 2 ** math.ceil(math.log2(num)) - 1
if num == 1:
    tail = 2
else:
    tail = 2 ** math.ceil(math.log2(num)) - num
targ = [0] * (ln + num + tail)
for q in range(query):
    #print(targ)
    qtype,temp1,temp2 = (int(n) for n in input().split(' '))
    if qtype == 0:
        update(temp1+ln-1,temp2)
    else:
        print(find(temp1-1,temp2-1,0,0,ln))

Measured memory_bytes: 13048
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

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

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    ll res = 0;
    if (n & 1) {
        ll cur = 0;
        for (int i = 0; i < n / 2; ++i) {
            cur -= 2 * a[i];
        }
        for (int i = n / 2; i < n / 2 + 2; ++i) {
            cur += a[i];
        }
        for (int i = n / 2 + 2; i < n; ++i) {
            cur += 2 * a[i];
        }
        res = max(res, cur);
        cur = 0;
        for (int i = 0; i < n / 2 - 1; ++i) {
            cur -= 2 * a[i];
        }
        for (int i = n / 2 - 1; i < n / 2 + 1; ++i) {
            cur -= a[i];
        }
        for (int i = n / 2 + 1; i < n; ++i) {
            cur += 2 * a[i];
        }
        res = max(res, cur);
    }
    else {
        ll cur = 0;
        for (int i = 0; i < n / 2 - 1; ++i) {
            cur -= 2 * a[i];
        }
        cur = cur - a[n / 2 - 1] + a[n / 2];
        for (int i = n / 2 + 1; i < n; ++i)
            cur += 2 * a[i];
        res = max(res, cur);

    }
    
    cout << res << endl;


}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

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

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
	int n,k;
	cin>>n;
	for(int j=0;j<n;j++){
		cin>>k;
		cout<<"Case "<<j+1<<":"<<endl;
		for(int i=0;i<10;i++){
			k *= k;
			k/=100;
			k%=10000;
			cout<<k<<endl;
		}
	}
  return 0;
}

Measured memory_bytes: 0
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int h1, m1, s1, h2, m2, s2;
  while (cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2) {
    int x1   = h1 * 3600 + m1 * 60 + s1;
    int x2   = h2 * 3600 + m2 * 60 + s2;
    int diff = x2 - x1;
    cout << diff / 3600 << ' ' << diff % 3600 / 60 << ' ' << diff % 60 << endl;
  }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
int main(){
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(S + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= S; j++){
      dp[i + 1][j] = dp[i][j] * 2 % MOD;
    }
    for (int j = 0; j <= S; j++){
      if (j + A[i] <= S){
        dp[i + 1][j + A[i]] += dp[i][j];
        dp[i + 1][j + A[i]] %= MOD;
      }
    }
  }
  cout << dp[N][S] << endl;
}

Measured memory_bytes: 73744
import std.bigint;
import std.stdio;
import core.stdc.stdio;
 
void main() {
	int n,m,r;
	scanf("%d%d%d",&n,&m,&r);
	r -= n*m;
	
	if(r<=0) puts("0");
	else{
		BigInt ans = 1;
		for(int i=1; i<n; i++){
			ans = ans * (i+r) / i;
		}
		writeln(ans);
	}
}

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

int main(){
    long n;
    cin >> n;
    set<string> values;
    string s;
    for (long i = 0; i < n; ++i){
        cin >> s;
        values.insert(s);
    }
    cout << values.size() << endl;
}


Measured memory_bytes: 19120
// AtCoder Beginner Contest 135
// Practice
// A - Harmony
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 1e5 + 15;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 7;
/******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
 
ll pow(ll x, ll n) {
  if (n == 0)
    return 1ll;
  ll temp;
  temp = pow(x, n / 2);
  if (n % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
 
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 
int sum_digit(int val) {
  if (val < 0)
    return -1;
  if (val == 0)
    return 0;
  int ans = 0;
  while (val > 0) {
    ans = ans + val % 10;
    val = val / 10;
  }
  return ans;
}
 
ll count_div(ll l, ll r, ll val) {
  if (l % val == 0)
    return (((r / val) - (l / val)) + 1);
  else
    return ((r / val) - (l / val));
}
 
int powmod(int x, int y, int m) {
  int res = 1;
  // x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    cout << res << endl;
    y = y / 2;
    cout << x << endl;
    x = (x * x) % m;
  }
  // cout << res << endl;
  return res;
}
/******************************************** CODE STARTS FROM HERE *************************************************/ 
 
int main()
{
  fastIO;
  int N;
  cin >> N;
  vector < int > P(N);
  for(int i = 0 ; i < N ; i++) cin >> P[i];
  vector < int > temp = P;
  sort(temp.begin() , temp.end());
  int cnt = 0;
  for(int i = 0 ; i < N ; i++)
  {
    if(temp[i] != P[i]) cnt++;
  }
  if(cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			HashSet<Integer> list = new HashSet<>();
			for (int i = 0; i < n; i++) {
				if (!list.add(sc.nextInt())) {
					System.out.println("NO");
					return;
				}
			}
			System.out.println("YES");
		}
	}
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int N;
P dot[55];

double dist(double x, double y) {
    double res = 0;
    rep(i, N) {
        res = max(res, (dot[i].first - x) * (dot[i].first - x) + (dot[i].second - y) * (dot[i].second - y));
    }
    return sqrt(res);
}

double f(double x) {
    double l = 0, r = INF;
    rep(i, 100) {
        double y1 = (l * 2 + r) / 3;
        double y2 = (l + r * 2) / 3;
        if (dist(x, y1) < dist(x, y2)) {
            r = y2;
        } else {
            l = y1;
        }
    }
    return dist(x, l);
}

int main(){
    cin >> N;

    rep(i, N) {
        int x, y;
        cin >> x >> y;
        dot[i] = P(x, y);
    }

    double l = 0, r = INF;
    rep(i, 100) {
        double x1 = (l * 2 + r) / 3;
        double x2 = (l + r * 2) / 3;
        if (f(x1) < f(x2)) {
            r = x2;
        } else {
            l = x1;
        }
    }

    printf("%.10f\n", f(l));
}

Measured memory_bytes: 256