akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int x,i;
  cin>>x;
    if(x%7==2){
      printf("sat\n");
    }
    else  if(x%7==1){
      printf("fri\n");
    }
    else if(x%7==3){
      printf("sun\n");
    }
    else if(x%7==4){
      printf("mon\n");
    }
    else if(x%7==5){
      printf("tue\n");
    }
    else if(x%7==6){
      printf("wed\n");
    }
    else {
      printf("thu\n");
    }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}


signed main(){
    cout << fixed << setprecision(10);
    intl h,w;
    cin >> h >> w;
    char a[10][10];
    rep(i,10)rep(j,10)a[i][j] = '.';
    repi(i,1,h+1)repi(j,1,w+1)cin >> a[i][j];
    bool f = false;
    bool flag[h+2][w+2];
    m0(flag);
    queue<pii > q;
    q.push(mp(1,1));
    flag[1][1] = true;
    vector<pii > move = {{0,1},{1,0}};
    while(!q.empty()){
        pii p = q.front();
        q.pop();
        if((a[p.first + 1][p.second] == '#')&&(a[p.first][p.second +1] == '#')){
            break;
        }
        for(auto i: move){
            intl fi = p.first + i.first;
            intl se = p.second + i.second;
            if(flag[fi][se])continue;
            if(a[fi][se] == '#'){
                flag[fi][se] = true;
                q.push(mp(fi,se));
            }
            if((fi == h)&&(se == w)){
                f = true;
                break;
            }
        }
        if(f)break;
    }
    bool ans = f;
    if(ans){
        repi(i,1,h+1){
            repi(j,1,w+1){
                //cout << flag[i][j] << " ";
                if((!(flag[i][j]))&&(a[i][j] == '#'))ans = false;
            }
            //cout << endl;
        }
    }
    fp(ans,"Possible","Impossible");
    return 0;
}

Measured memory_bytes: 256
S = list(input())
count = 0
while len(S)>=2:
    #print(len(S))
    #print(S)
    if S[0] == S[-1]:
        del S[0]
        del S[-1]
    else:
        del S[0]
        del S[-1]   
        count += 1
print(count)    

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n), w(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> w[i];
	int r = -1, l = -1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 0)
			r = (r == -1 ? w[i] : min(r, w[i]));
		else
			l = (l == -1 ? w[i] : min(l, w[i]));
	}
	cout << (r == -1 || l == -1 ? 0 : l + r) << endl;

	return 0;
}



Measured memory_bytes: 3112
#include <iostream> 
#include <cstdio>


int main(){



  int a = 0 , b = 0 , d = 0 , r = 0 ;


  double f = 0 ;


  scanf("%d %d",&a,&b);




  d = a / b ;

  r = a % b ;

  f = (double) a / b ;


  printf("%d %d %f\n",d , r , f);


  return 0;


}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

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

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin>>S;
    int x[S.size()];
    rer(i,S.size(),0){
        if(i==S.size()-1){
            if(S[i]=='W') x[i]=1;
            else x[i]=0;
        }
        else{
            x[i]=x[i+1]+(S[i]=='W'?1:0);
        }
    }
    ll ans=0;
    rep(i,0,S.size()){
        if(S[i]=='B'){
            ans+=x[i];
        }
    }
    cout << ans<<"\n";
}



Measured memory_bytes: 1300
import Data.Bool
import qualified Data.Set as S
import Control.Monad

main = do
 [n,m] <- map read . words <$> getLine
 ta <- concat <$> replicateM n getLine
 tb <- concat <$> replicateM m getLine
 let pa = map fst $ filter ((=='#') . snd) $ zip [(h,w) | h<-[0..n-1], w<-[0..n-1]] ta
 let pb = map fst $ filter ((=='#') . snd) $ zip [(h,w) | h<-[0..m-1], w<-[0..m-1]] tb
 let sa = S.fromDistinctAscList pa
 let sb = S.fromDistinctAscList pb
 let d = n - m
 putStrLn $ bool "No" "Yes" (templateMatch d sa sb)

templateMatch d sa sb = any (match sa sb) [(dh,dw) | dh<-[0..d], dw<-[0..d]]

match sa sb (dh,dw) = S.mapMonotonic (move dh dw) sb `S.isSubsetOf` sa

move dh dw (h,w) = (h+dh, w+dw)

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
queue< pair<int,int> > q;
int grid[100][100];
int W, H, _W, _H;

void debug() {
  cout << endl << "-----" << endl;
  for (int i = 0; i < _H; i++) {
    for (int j = 0; j < _W; j++) {
      cout << grid[j][i] << ",";
    }
    cout<<endl;
  }
  cout << "-----" << endl;
}

void bfs() {
  int mx[4] = { 1, 0, -1, 0 };
  int my[4] = { 0, 1, 0, -1 };
  q.push(make_pair(0,0));
  grid[0][0] = 1;
  while (q.size() > 0) {
    pair<int,int> p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    for (int i = 0; i < 4; i++) {
      int _x = x+mx[i], _y = y+my[i];
      if (_x>=_W || _y>=_H || _x<0 || _y<0 || grid[_x][_y] != INF) continue;
      grid[_x][_y] = grid[x][y]+1;
      q.push(make_pair(_x,_y));
    }
  }
}

signed main() {
  while(cin>>W>>H, W+H!=0) {
    _W = W*2-1; _H = H*2-1;
    for (int i = 0; i < _H; i++) {
      for (int j = 0; j < _W; j++) {
        grid[j][i] = INF;
      }
   }
    for (int i = 0; i < _H; i++) {
      int t;
      if (i%2==0) {
        for (int j = 0; j < W-1; j++) {
          cin>>t; if(t==0)continue;
          grid[j*2+1][max(i-1, 0LL)] = -1;
          grid[j*2+1][i] = -1;
          grid[j*2+1][min(i+1, _H-1)] = -1;
          // 0 -> 1
          // 1 -> 3
          // 2 -> 5
          // 3 -> 7
        }
      } else {
        for (int j = 0; j < W; j++) {
          cin>>t; if(t==0)continue;
          grid[max(j*2-1, 0LL)][i] = -1;
          grid[j*2][i] = -1;
          grid[min(j*2+1,_W-1)][i] = -1;
          // 0 -> 0
          // 1 -> 2
          // 2 -> 4
          // 3 -> 6   
        }
      }
    }
    //debug();
    bfs();
    //debug();
    int ans = grid[_W-1][_H-1];
    if (ans == INF) {
      ans = 0;
    } else {
      ans = ans/2+1;
    }
    cout << ans << endl;
  }
}




Measured memory_bytes: 3184
#include<cstdio>
int main(){
    long long q,h,s,d,n;
    scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
    if(2*q<h)h=2*q;
    if(2*h<s)s=2*h;
    if(2*s<d)d=2*s;
    printf("%lld",d*(n/2)+s*(n%2));
    return 0;
}

Measured memory_bytes: 128
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

newXL = sorted([[x-l, x+l] for x, l in XL], key=lambda x:x[1])

previous = 0
total = 1

for i in range(1, N):
  if newXL[i][0] < newXL[previous][1]:
    pass
  else:
    previous = i
    total += 1
    
print(total)

Measured memory_bytes: 76376
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define float double
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	const int N = 100 * 1000 + 5;
	vector <int> A(n), o(N), e(N);
	int mxo = 0, mxe = 0, pe = -1, po = -1;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		if(i % 2 == 0) {
			o[A[i]]++;
			if(mxo < o[A[i]]) {
				mxo = o[A[i]];
				po = A[i];
			}
		}
		else {
			e[A[i]]++;
			if(mxe < e[A[i]]) {
				mxe = e[A[i]];
				pe = A[i];
			}
		}
	}
	if(po == pe) {
		int nxo = 0, nxe = 0;
		for (int i = 0; i < N; i++) {
			if(i != po)
				nxo = max(nxo, o[i]);
			if(i != pe)
				nxe = max(nxe, e[i]);
		}
		cout << min((n + 1) / 2 - mxo + n / 2 - nxe, (n + 1) / 2 - nxo + n / 2 - mxe);
	}
	else {
		cout << (n + 1) / 2 - mxo + n / 2 - mxe;
	}
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
typedef long double lb;
#define ri register int
const lb PI=3.141592653589793238462643383279;
const ll inf=1000000000000000000ll;
const int N=1000005,M=1;
long long qpow(long long a,long long b)
{
	long long s=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		b>>=1;
		s=s*s%M;
	}
	return ans;
}
int n,i,m,ty,x[N],y[N],ans[N],j,flag[N],a[N],e[5],k;
bitset<50005> p[50005],t;
bool f[N];
void dfs(int i)
{
	if(e[1]+e[2]+e[3]<=1)
		return;
	if(i>k)
	{
		for(i=1;i<=m;++i)
			putchar(ans[i]^flag[i]?'v':'^');
		exit(0);
	}
	int tmp[5];
	memcpy(tmp,e,sizeof(tmp));
	e[x[a[i]]]|=e[y[a[i]]];
	e[y[a[i]]]=0;
	ans[a[i]]=0;
	dfs(i+1);
	memcpy(e,tmp,sizeof(tmp));
	e[y[a[i]]]|=e[x[a[i]]];
	e[x[a[i]]]=0;
	ans[a[i]]=1;
	dfs(i+1);
	memcpy(e,tmp,sizeof(tmp));
}
int main()
{
	scanf("%d %d %d",&n,&m,&ty);
	if(ty==2)
	{
		if(n<=2)
		{
			puts("-1");
			return 0;
		}
		for(i=1;i<=m;++i)
		{
			scanf("%d %d",&x[i],&y[i]);
			if(x[i]>y[i])
			{
				flag[i]=1;
				swap(x[i],y[i]);
			}
		}
		e[1]=e[2]=e[3]=1;
		for(i=1;i<=m;++i)
		{
			if((x[i]==1&&y[i]==2)||(x[i]==1&&y[i]==3)||(x[i]==2&&y[i]==3))
				a[++k]=i;
		}
		dfs(1);
		return 0;
	}
	for(i=1;i<=m;++i)
		scanf("%d %d",&x[i],&y[i]);
	for(i=1;i<=n;++i)
		p[i][i]=1;
	for(i=m;i>=1;--i)
		p[x[i]]=p[y[i]]=p[x[i]]|p[y[i]];
	for(i=1;i<=n;++i)
		t[i]=1;
	for(i=1;i<=n;++i)
		t&=p[i];
	if(!t.count())
	{
		puts("-1");
		return 0;
	}
	for(i=1;i<=n;++i)
		if(t[i])
			break;
	f[i]=1;
	for(i=m;i>=1;--i)
		if(f[x[i]])
		{
			f[y[i]]=1;
			ans[i]=1;
		}
		else
		{
			f[x[i]]=f[y[i]];
			ans[i]=0;
		}
	for(i=1;i<=m;++i)
		putchar(ans[i]?'^':'v');
}

Measured memory_bytes: 312704
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)

n=int(input())
dct=defaultdict(list)

for i in range(n-1):
  a,b,c=map(int,input().split())
  dct[a]+=[[b,c]]
  dct[b]+=[[a,c]]


q,k=map(int,input().split())
lk=[0]*(n)

def dfs(v,p,d):
  lk[v-1]=d

  for l in dct[v]:
    if l[0]==p or lk[l[0]-1]!=0:
      continue
    else:
      dfs(l[0],v,d+l[1])
  return

dfs(k,-1,0)



for i in range(q):
  x,y=map(int,input().split())
  print(lk[x-1]+lk[y-1])


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

using namespace std;
long long a, b;
int n;
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a >> b;
        if(a > b){
            swap(a, b);
        }
        if(a == b){
            cout << max(a * 2 - 2, 0ll) << '\n';
        }
        else if(a + 1 == b){
            cout << max(2 * a - 2, 0ll) << '\n';
        }
        else{
            long long c, l = 0, r = 1e9;
            while(r - l > 1){
                long long mid = (r + l) / 2;
                if(mid * mid < a * b){
                    l = mid;
                }
                else{
                    r = mid;
                }
            }
            if(r * r < a * b){
                c = r;
            }
            else{
                c = l;
            }
            if(c * (c + 1) < a * b){
               cout << max(2 * c - 1, 0ll) << '\n';
            }
            else{
                cout << max(2 * c - 2, 0ll) << '\n';
            }
        }
    }
}


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

using namespace std;

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

int main(){

	int data[11];
	int i;

	for (i = 0; i < 10; i++) cin >> data[i];
	qsort(data, 10, sizeof(int), compare_int);
	for (i = 0; i < 3; i++) {
		cout << data[i] << endl;
	}
	cin >> i;
}



Measured memory_bytes: 3112
#include<stdio.h>
int main()
{
	int a,m[100];
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",&m[i]);
	}
	for(int i=a-1;i>-1;i--){
		printf("%d",m[i]);
		if(i!=0)printf(" ");
	}
	printf("\n");
	return 0;
}

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

int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	int l=s.length();
	int n=t.length();
	//	cout<<l<<n<<"\n";
	if(l<n){
		cout<<"0";
		return 0;
	}
	int ss=0;
	int ans=100005;
	int g;
	for(int i=0;i<=l-n;i++){
		ss=0;
		for(int j=0;j<n;j++){
			if(s[i+j]==t[j]){
		  //cout<<s[i+j]<<" "<<t[j]<<"#"<<"\n";
				continue;
			}
			else {
				//cout<<s[i+j]<<" "<<t[j]<<"@"<<"\n";
				ss++;
			}
		}
		//cout<<"----------------"<<"\n";
		//i=g;
		ans=min(ss,ans);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>


int main(void){

  int a[4], b[4], c[4];
  int i, j;
  int hit, blow;

  while(scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3])!=EOF){
    scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
    hit=blow=0;
    
    for(i=0; i<4; i++){
      c[i]=0;
      if(a[i]==b[i]){
	hit++;
	c[i]=1;
      }
    }

    for(i=0; i<4; i++){
      if(c[i]==0){
	for(j=0; j<4; j++){
	  if(a[i]==b[j]){
	    blow++;
	    break;
	  }
	}
      }
    }    


    printf("%d %d\n", hit, blow);

  }


  return(0);
}



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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int K; cin >> K;
    cout << (K / 2) * ((K + 1) / 2);
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A, B) = read!(i64, i64);
    println!("{}", if B % A == 0 { A + B } else { B - A })
}


Measured memory_bytes: 4352
import sys

s = set()
input()

for q in sys.stdin:
    q = q.split()
    if q[0] == '0':
        s.add(q[1])
        print(len(s))
    elif q[0] == '1':
        print(int(q[1] in s))
    else:
        s.discard(q[1])


Measured memory_bytes: 27700
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}


string day[] = { "MON","TUE","WED","THU","FRI","SAT" };
int main() {
	string h;
	cin >> h;

	for (int i = 0; i < 6; ++i) {
		if (day[i] == h) {
			cout << 7 - i - 1;
			return 0;
		}
	}

	cout << 7 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> board(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>board.at(i).at(j);
    }
  }
  vector<int> dx = {1,1,1,0,0,-1,-1,-1};
  vector<int> dy = {1,0,-1,1,-1,1,0,-1};
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(board.at(i).at(j)=='#'){
        continue;
      }
      else{
        int count=0;
        for(int k=0;k<8;k++){
          int X=i+dx.at(k);
          int Y=j+dy.at(k);
          if(X<0 || X>=H){
            continue;
          }
          if(Y<0 || Y>=W){
            continue;
          }
          if(board.at(X).at(Y)=='#'){
            count++;
          }
        }
        board.at(i).at(j)=count+'0';
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<board.at(i).at(j);
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

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

    cout << n << ":";

    int i = 2;
    double l = sqrt(n);
    int ans = 1;
    while(i <= l){
        if(n%i == 0){
            cout << " " << i;
            n = n/i;
            l = sqrt(n);
        } else {
            i++;
        }
    }
    cout << " " << n;
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3100
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine::IO[[Int]]
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,w)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ [(i,wi,vi,j)|(i,[wi,vi])<-zip [1..] wvs,j<-[0..w]] $ \(i,wi,vi,j) ->
        if j< wi then writeArray dp (i,j) =<< readArray dp (i-1,j)
                 else writeArray dp (i,j) =<< max.(+vi) <$> readArray dp (i-1,j-wi) <*> readArray dp (i-1,j)
    readArray dp (n,w)

Measured memory_bytes: 79484
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	ll K;
	cin >> K;
	vll A;
	ll i, j;
	for (i = 0; i < K; i++){
		ll a;
		cin >> a;
		A.push_back(a);
	}
	ll min_N, max_N;
	bool flg = true;
	if (A[K - 1] != 2){
		cout << -1 << endl;
		flg = false;
	}
	else{
		min_N = 2;
		max_N = 3;
		for (i = K - 2; i >= 0; i--){
			ll a = A[i];
			if (min_N / a == max_N / a && min_N % a != 0){
				cout << -1 << endl;
				flg = false;
				break;
			}
			if (min_N % a != 0){
				min_N = a*(min_N / a + 1);
			}
			max_N = a*(max_N / a) + a - 1;
		}
	}
	if (flg){
		cout << min_N << " " << max_N << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll kpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int k;
ll a[maxn];
ll ok(ll t){
	rep(i,0,k) t = t/a[i] * a[i];
	return t;
}
int main()
{
	scanf("%d",&k);
	rep(i,0,k) scanf("%lld",&a[i]);
	ll l = 1, r = 1e18;
	ll ansl = -1,ansr = -1;
	while(l+1<r){
		ll mid = (l+r)/2;
		if(ok(mid)>=2){
			r = mid;
		}
		else l = mid;
	}
	if(ok(l)<2) l++;
	if(ok(l)>2&&ok(r)>2) return printf("-1\n"),0;
	if(ok(l)==2) ansl = l;
	else ansl = r;
	ll tl = l,tr = 1e18;
	while(tl+1<tr){
		ll mid = (tl+tr)/2;
		if(ok(mid)==2){
			tl = mid;
		}
		else tr = mid;
	}
	ansr = tl;
	printf("%lld %lld\n",ansl,ansr);
	return 0;
}





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

using namespace std;

int main() {
    string str; cin >> str;
    int ans = 0, gcnt = 0, pcnt = 0;
    for(char c:str) {
        if( pcnt < gcnt ) {
            ++pcnt;
            ans += (c=='g');
        } else {
            ++gcnt;
            ans -= (c=='p');
        }
    }
    printf("%d\n",ans);
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <limits>
using namespace std;

typedef pair<int,int> vec;

vector<vec> adj[10000];
int d[10000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) d[i]=numeric_limits<int>::max();
    for(int i=0; i<n; i++) {
        int u,k;
        cin>>u>>k;
        adj[u].reserve(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin>>v>>c;
            adj[u].push_back(vec(v,c));
        }
    }
    priority_queue<vec, vector<vec>, greater<vec> >q;
    q.push(vec(0,0));
    d[0]=0;
    while(!q.empty()) {
        vec e=q.top();
        q.pop();
        int id=e.first;
        int cost=e.second;
        if(d[id]<cost) continue;
        for(int i=0, an=adj[id].size(); i<an; i++) {
            int adj_id=adj[id][i].first;
            int adj_cost=adj[id][i].second+cost;
            if(d[adj_id] <= adj_cost) continue;
            d[adj_id]=adj_cost;
            q.push(vec(adj_id, adj_cost));
        }
    }
    for(int i=0; i<n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int n;
	while (cin >> n, n) {
		int cnt[10] = {};
		REP(i, n) {
			int c; scanf("%d", &c);
			cnt[c]++;
		}
		
		REP(i, 10) {
			if (cnt[i] == 0) putchar('-');
			else REP(j, cnt[i]) putchar('*');
			puts(""); 
		}
	}
	return 0;
}

Measured memory_bytes: 3120
import kotlin.math.cos
import kotlin.math.sqrt

fun main(){
    val (a,b, h, m) = readLine()!!.split(" ").map(String::toDouble)

    val angleH = h * 30 + m/60 * 30
    val angleM = m/60 * 360

    val angleHM = if(angleH > angleM){
        angleH - angleM
    }else{
        angleM - angleH
    }

    val distSquareRoot = a*a + b*b - 2*a*b*cos(Math.toRadians(angleHM))
    println(sqrt(distSquareRoot))
}

Measured memory_bytes: 36644
import sys
from sys import stdin
input = stdin.readline

n = int(input())
A =[int(x) for x in input().split()]
q = int(input())
M =[int(x) for x in input().split()]

dp = [[-1 for i in range(2001)] for j in range(21)]

def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1,m):
        dp[i][m] = True
    elif solve (i+1, m-A[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

for m in M:
    if solve(0,m):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5988
#include<bits/stdc++.h>
using namespace std;
int a,b,c,n,ans=0;
int main() {
	cin>>a>>b>>c>>n;
	for(int i=0; i<=a; i++) {
		for(int j=0; j<=b; j++) {
			for(int k=0; k<=c; k++) {
				if(i*500+j*100+k*50==n) ans++;
			}

		}

	}
	cout<<ans;
	return 0;
}

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

int main(void){
	int num;
	std::cin >> num;
	std::vector<int> inputNums;

	int number;
	for(int i = 0; i < num; ++i){
		std::cin >> number;
		inputNums.push_back(number);
	}

	std::vector<long int> countCells(21,0); //init answer vector
	countCells[inputNums[0]] = 1; //add first number
	
	std::vector<long int> bufferCells(21,0); //for sum&dif answer buffer

	for(int j = 1; j < num - 1; ++j){
		for(int k = 0; k <= 20; ++k){
			if(k < inputNums[j]){ //only dif
				bufferCells[k] = countCells[k + inputNums[j]];
			}else if(k > 20 - inputNums[j]){ //only sum
				bufferCells[k] = countCells[k - inputNums[j]];
			}else{ //dif & sum
				bufferCells[k] = countCells[k + inputNums[j]] + countCells[k - inputNums[j]];
			}
		}

		//renew countCells
		for(int l = 0; l <= 20; ++l){
			countCells[l] = bufferCells[l];
		}
	}

	std::cout << countCells[inputNums.back()] << std::endl;

	return 0;
}

Measured memory_bytes: 1216
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
    int input, ans = 0, ans2 = 234, ans3 = 567, flag;
    cin >> input;
 
    vector<int> side(input);
    for (int i = 0; i < input; i++) {
        cin >> side.at(i);
    }
 
    sort(side.begin(), side.end());
    reverse(side.begin(), side.end());
 
    vector<int> num;
    num.push_back(0);
    for (int i = 0; i < input; i++) {
        flag = 0;
        for (int j = i + 1; j < input; j++) {
            for (int k = j + 1; k < input; k++) {
                if (side.at(i) < side.at(j) + side.at(k) && side.at(j) < side.at(k) + side.at(i) && side.at(k) < side.at(i) + side.at(j)) {
                    ans++;
                    ans2+=ans;
                  	ans3+=ans2;
                }
                else {
                    break;
                    flag++;
                }
            }
            if (flag != 0) {
                break;
            }
        }
    }
 
    cout << ans << endl;
 
}


Measured memory_bytes: 3560
use std::io::*;
use std::str::FromStr;

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn bfs(map: &Vec<Vec<usize>>, cn: usize, done: &mut Vec<i64>, hv: &Vec<usize>) {
    if done[cn] == -1 {
        return;
    }
    for i in &map[cn] {
        if hv[cn - 1] <= hv[*i - 1] {
            done[cn] = -1;
            break;
        } else {
            done[*i] = -1;
        }
    }
    if done[cn] == 0 {
        done[cn] = 1;
    }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let hv: Vec<usize> = read_n(n);
    let mut map: Vec<Vec<usize>> = vec![vec![]; n + 1];

    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        map[a].push(b);
        map[b].push(a);
    }

    let mut status: Vec<i64> = vec![0; n + 1];
    status[0] = -1;

    for i in 1..n + 1 {
        bfs(&map, i, &mut status, &hv);
    }
    println!("{:?}", status.iter().filter(|&x| *x == 1).count());
}


Measured memory_bytes: 15656
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = a/b;
		int y = a%b;
		double sum = (double)a / b;
		System.out.format("%d %d %.5f", x,y,sum);
	}
}



Measured memory_bytes: 26388
#!/usr/bin/env python3
import sys
from functools import lru_cache
sys.setrecursionlimit(10**8)

MOD = 998244353  # type: int


def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    DP = [[0]*(S+1) for i in range(N+1)]
    DP[0][0] = 1
    for i in range(1, N+1):
        for wa in range(S+1):
            DP[i][wa] = 2*DP[i-1][wa]
            DP[i][wa] %= MOD
            if 0 <= wa-A[i-1] <= S:
                DP[i][wa] += DP[i-1][wa-A[i-1]]
                DP[i][wa] %= MOD

    print(DP[N][S])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 139948
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  vector<int> divisor(n);
  int count = 0;
  for (i = 1; i <= t[n - 1]; i++) {
    if (t[n - 1] % i == 0) {
      divisor[count] = i;
      count++;
    }
  }
  int result = 0;
  count = 0;
  for (i = 0; i < n; i++) {
    while (t[i] > divisor[count]) {
      count++;
    }
    result += divisor[count] - t[i];
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3544
#include<iostream>

using namespace std;

namespace Original{
    bool isHitachiString( std::string &text ){
        if( text.size() % 2 != 0 ) return false;
        
        for( int i = 0; i < text.size(); i = i + 2 ){
            if( text[i] != 'h' || text[i+1] != 'i' ) return false;
        }
    return true;
    }
}

int main( void ){
    std::string hitachi;
    std::getline( std::cin, hitachi );
    
    if( Original::isHitachiString(hitachi) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll K,A,B;

signed main(){
	cin >> K >> A >> B;
	if(B-A <= 2){
		cout << K+1 << endl;
	}
	else{
		ll n = 1 + K - A;
		if(n%2)n--;
		cout << (1+K-n) + (B-A)*n/2 << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int calc(int a, int aa, int b) {
  if(aa == 0) return a + b;
  else return a - b;
}

char getC(int a) {
  if(a == 0) return '+';
  else return '-';
}

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

  cin >> s;
  int a = s[0] - '0';
  int b = s[1] - '0';
  int c = s[2] - '0';
  int d = s[3] - '0';

  REP(aa, 2) REP(bb, 2) REP(cc, 2) {
    if(calc(calc(calc(a, aa, b), bb, c), cc, d) == 7) {
      cout << a << getC(aa) << b << getC(bb) << c << getC(cc) << d << "=7" << endl;
      return 0;
    }
  }
}


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

int N;
vector<i64> X;

i64 A;
i64 B;

int main(){
  cin >> N >> A >> B;

  X.resize(N);
  rep(i,0,N - 1) cin >> X[i];
  i64 ans = 0;
  rep(i,1,N - 1){
    i64 dif = X[i] - X[i - 1];
    ans += min(dif * A,B);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

bool isprime(long long n)
{
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;
    for (int i = 3; i <= sqrt(n); i += 2)
        if (n % i == 0)
            return false;
    return true;
}

bool is(long long n)
{
    return isprime(n) and isprime((n+1)/2);
}

int main()
{
    ll Q;
    cin >> Q;
    vll l(Q), r(Q);
    rep(i, 0, Q) cin >> l[i] >> r[i];

    ll maxnum = 500000;
    vll check(maxnum);
    vll acc(maxnum+1, 0);
    bool tmp;
    rep(i, 0, maxnum) {
        check[i] = is(i);
    }
    rep(i, 0, maxnum) {
        acc[i+1] = acc[i] + check[i];
    }
    rep(i, 0, Q) {
        cout << acc[r[i] + 1] - acc[l[i]] << endl;
    }
}

Measured memory_bytes: 11776
class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1)

def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n")

if __name__ == "__main__":
    main()


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

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  vector<int> C_W(N);
  vector<int> C_E(N);
  int count = 0;
  for(int i=0;i<N;i++){
    C_W.at(i)=count;
    if(S.at(i)=='W')count++;
  }
  count=0;
  for(int i=N-1;i>-1;i--){
    C_E.at(i)=count;
    if(S.at(i)=='E')count++;
  }
  int ans = N*2;
  for(int i=0;i<N;i++){
    int temp = C_E.at(i)+C_W.at(i);
    if(ans>temp)ans = temp;
  }
  cout<<ans<<endl;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s, t;
    cin>>s>>t;
    int x = 0,i;
    for(i=0;i<3;i++){
        if(s[i]==t[i])
            x++;
    }
    cout<<x;
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    cout << (N - 2) * 180 << endl;

    return 0;
}


Measured memory_bytes: 3648
def main():
    N = [x for x in input().split(' ')]
    #データを格納するための整数型1次元配列
    stack = []
    for i in N:
        # +が入っていた場合
        if i == '+':
            num1 = stack.pop()
            num2 = stack.pop()
            stack.append(num1 + num2)
        # -が入っていた場合
        elif i == '-':
            num2 = stack.pop()
            num1 = stack.pop()
            stack.append(num1 - num2)
        # *が入っていた場合
        elif i == '*':
            num1 = stack.pop()
            num2 = stack.pop()
            stack.append(num1 * num2)
        #算術演算子( + - *)以外が入っていた場合
        else:
            stack.append(int(i))
            
    #表示
    print(stack.pop())
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<sstream>
using namespace std;

double Calc();

int main(int argc,char* argv[]){
  double ans;

  ans=Calc();

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

double Calc(){
  stringstream ss;
  string str;
  stack<double> sdnum;

  getline(cin,str);
  ss<<str;

  for(;;){
    double x1,x2;

    str="";
    ss>>str;
    if(str=="")
      break;

    if(str=="+" || str=="-" || str=="*"){
      x1=sdnum.top();sdnum.pop();
      x2=sdnum.top();sdnum.pop();


      if(str=="+")
	sdnum.push(x2+x1);
      else if(str=="-")
	sdnum.push(x2-x1);
      else
	sdnum.push(x2*x1);
    }
    else{
      stringstream sstmp;
      sstmp<<str;
      sstmp>>x1;
      sdnum.push(x1);
    }

  }
  return sdnum.top();
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	ll sum = 2*(n/2) + 1;
	
	vector<pll> res;
	FOR(i,1,n+1) FOR(j,i+1,n+1) if (i+j != sum) res.eb(i,j);

	cout << sz(res) << endl;
	for (pll p: res) cout << p.xx << " " << p.yy << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  double A=0;
  cin>>N;
  for(int i=0;i<N;i++){
    double x=0;
    string u;
    cin>>x>>u;
    if(u=="JPY")A+=x;
    else A+=x*380000.000;
  }
  cout<<A<<endl;
}


Measured memory_bytes: 3804
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int K;
    cin >> K;

    set<string> f;
    for (int len = 1; len <= K; ++len) {
        for (int i = 0; i + len <= s.size(); ++i) {
            string cur = s.substr(i, len);
            f.insert(cur);
        }
    }

    set<string>::iterator iter = f.begin();;
    for (int i = 0; i < K; ++i) {
        // cout << "i = " << i << ", " << *iter << endl;
        ++iter;
    }

    cout << *(--iter) << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define NIL 2000000001
typedef struct{
  int p,l,r,key; 
}node;

node tree[500001];
queue<int> q[2];

void insert(int key,int i){
  node z={NIL,NIL,NIL,key};
  int x=(i==0?NIL:0),y=NIL;
  while(x!=NIL){
    y=x;
    if(z.key<tree[x].key){
      x=tree[x].l;
    }else{
      x=tree[x].r;
    }
  }
  z.p=y;
  if(y==NIL){
    tree[0]=z;
  }else if(z.key<tree[y].key){
    tree[y].l=i;
  }else {
    tree[y].r=i;
  }
  tree[i]=z;
}

void print(int n=0){
  if(n==NIL)return;
  q[1].push(tree[n].key);
  print(tree[n].l);
  q[0].push(tree[n].key);
  print(tree[n].r);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string a;
    cin>>a;
    if(a[0]=='i'){
      int k;
      cin>>k;
      insert(k,i);
    }else{
      //for(int j=0;j<n;j++)cout<<tree[j].key<<" "<<tree[j].p<<endl;
      print();
      for(int j=0;j<2;j++){
	while(!q[j].empty()){
	  cout<<" "<<q[j].front();
	  q[j].pop();
	}
	cout<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 14664
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
tmp = sum(P[:K])
high = tmp
e = 0
for i in range(1, N-K+1):
    tmp -= P[i-1]
    tmp += P[i+K-1]
    if tmp > high:
        high = tmp
        e = i
exp = 0
for p in P[e:e+K]:
    exp += sum(range(1,p+1)) / p

print(exp)

Measured memory_bytes: 67824
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def resolve():
    k = int(input())
    l = [None] * k ** 2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9308
N = int(input())

divs = []

for i in range(1, int(N**(1/2)+1)):
    if N % i == 0:
        divs.append((i, N//i))

ans = 1000000000007

for i, j in divs:
    ans = min(ans, i-1+j-1)

print(ans)


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

int main() {
  char a,b;
  cin >> a >> b;
  if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')){
    cout << "H" << endl;
  }
  else{
    cout << "D" << endl;
  }
}


Measured memory_bytes: 256