akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Map<String, Boolean> map = new HashMap<String, Boolean>();
        String line = br.readLine();
        while(line != null){
            String[] xs = line.split(" ");
            if(xs[0].equals("insert")){
                map.put(xs[1], true);
            }else if(xs[0].equals("find")){
                System.out.println(map.containsKey(xs[1]) ? "yes" : "no");
            }
            line = br.readLine();
        }
    }
}


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

int main(){
  int N;
  cin >> N;
  
  int t[N+1];
  int x[N+1];
  int y[N+1];
  
  t[0] = 0;x[0] = 0; y[0] = 0; 
  
  for (int i=1;i<N+1;i++){
    cin >> t[i] >> x[i] >> y[i] ;}
  
  for (int i=1;i<N+1;i++){
    int dt = t[i] -t[i-1];
    int dx = abs(x[i] - x[i-1]);
    int dy = abs(y[i] - y[i-1]);
 
    if (dx > dt) {
      cout << "No"; goto Exit;}
    else if(dy > dt -dx || (dt - dx -dy)%2 != 0){
      cout << "No"; goto Exit;}
    
  }
  
  cout << "Yes";
  
  Exit: ;
  
}

Measured memory_bytes: 1408
s = input()
t = input()

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s2 = s[:i] + t + s[i+len(t):]
        s2 = s2.replace('?','a')
        ans.append(s2)



if len(ans) > 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, ta, tb, tc, cnt;
    cin >> a >> b >> c;
    cnt = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && cnt > -1) {
        ta = b / 2 + c / 2;
        tb = a / 2 + c / 2;
        tc = a / 2 + b / 2;
        a = ta;
        b = tb;
        c = tc;
        cnt += 1;
        if (a == b && b == c) { cnt = -1; }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let ab: String = read();
    let ab: Vec<usize> = ab.split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let a: usize = ab[0];
    let b: usize = ab[1];

    let min = std::cmp::min(&a, &b);
    let max = std::cmp::max(a, b);
    let min_char = min.to_string();
    let mut ans: String = min_char.to_string();
    for i in 1..max {
        ans += &min_char;
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int main()
{
	int s = 0;
	int n,q;
	int a,b;
	char c[100001];
	int k[100001];
	memset(k,0,sizeof(k));
	scanf("%d %d",&n,&q);
	scanf("%s",c);
	for(int i = 0;i < n;i++){
		if(c[i] == 'C' && c[i - 1] == 'A') s++;
		k[i] = s;
	}
	for(int i = 0;i < q;i++){
		scanf("%d %d",&a,&b);
		printf("%d\n",k[b - 1] - k[a - 1]);
	}
	return 0;
}

Measured memory_bytes: 1280
import Data.List
import qualified Data.ByteString.Char8 as BS
main = do
  BS.getLine
  as <- sort . map (read . BS.unpack) . BS.words <$> BS.getLine :: IO [Int]
  if (odd $ length as) && (head as == 0) && (check 2 (tail as))
     then print $ solve (length as `div` 2)
  else if (even $ length as) && (check 1 as)
     then print $ solve (length as `div` 2)
  else 
     print 0

check :: Int -> [Int] -> Bool
check _ [] = True
check n (x:y:xs) 
  | x==n && y==n = check (n+2) xs
  | otherwise = False

solve :: Int -> Int
solve 0 = 1
solve 1 = 2 `mod` (10^9+7)
solve n = 2 * solve (n-1) `mod` (10^9+7)

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

using namespace std;

int main()
{
	int n, k, q;
	cin >> n >> k >> q;

	vector<int> a(n, 0);

	for (int i = 0; i < q; i++) {
		int kkkk;
		cin >> kkkk;
		a[kkkk-1]++;
	}

	for (int i = 0; i < n; i++) {
		if (k + a[i] - q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1024
from collections import deque

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]
lines = [[] for _ in range(N+1)]
for a, b in ab:
    lines[a].append(b)
    
q = deque([1])
color = [0]*(N+1)
while q:
    x = q.popleft()
    c = 1
    for y in lines[x]:
        if c == color[x]:
            c += 1
        color[y] = c
        c += 1
        q.append(y)
print (max(color))
for i in range(N-1):
    print (color[ab[i][1]])

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N, M;
int a[MAX], b[MAX], ans[MAX];

class union_find
{
	int *par, *nume;
	int _size, _setnum;

public:
	union_find(){
		par = nume = NULL;
	}
	
	union_find(int x){
		par = nume = NULL;
		resize(x);
	}
	
	~union_find(){
		clear();
	}
	
	void clear(){
		_size = _setnum = 0;
		delete par;
		delete nume;
		par = nume = NULL;
	}
	
	void init(){
		_setnum = _size;
		for(int i = 0; i < _size; i++){
			par[i] = i;
			nume[i] = 1;
		}
	}
	
	void resize(int x){
		clear();
		
		_size = x;
		
		par = new int[x];
		nume = new int[x];
		
		init();
	}

	int find(int x){
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
	
		if(x == y)return;
		
		_setnum--;
		
		if(nume[x] > nume[y]) std::swap(x,y);
		
		par[x] = y;
		nume[y] += nume[x];
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	int numel(int x){
		return nume[find(x)];
	}
	
	int size(){
		return _size;
	}
	
	int setnum(){
		return _setnum;
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int temp;
	
	cin>>N>>M;
	
	union_find uf(N+2);
	temp = N*(N-1)/2;
	
	for(int i = 0; i < M; i++){
		cin>>a[i]>>b[i];
	}
	
	for(int i = M-1, c = 0; i >= 0; i--){
		ans[i] = temp-c;
		if(!uf.same(a[i],b[i])){
			int d = uf.numel(a[i]), e = uf.numel(b[i]), f;
			f = d+e;
			// cout<<i<<" "<<d<<" "<<e<<" "<<f<<endl;
			d = d*(d-1)/2;
			e = e*(e-1)/2;
			f = f*(f-1)/2;
			// cout<<i<<" "<<d<<" "<<e<<" "<<f<<endl;
			c += f-d-e;
			uf.unite(a[i],b[i]);
		}
		
	}
	
	for(int i = 0; i < M; i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main() {
	cin>>a;
	b=a;
	int j=a.size();
	for(int i=0; i<a.size(); i++)
		a[--j]=b[i];
	for(int i=0; i<a.size(); i++) {
		if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
		else if(a[i]=='p') a[i]='q';
		else if(a[i]=='q') a[i]='p';
	}
	if(a==b)
	cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    char A,B;
    cin >> A >> B;
    if(A==B){
        cout << "=" << endl;
    }
    else if(A=='A'){
        cout << "<" << endl;
    }
    else if(B=='A'){
        cout << ">" << endl;
    }
    else if(A=='F'){
        cout << '>' << endl;
    }
    else if(B=='F'){
        cout << '<' << endl;
    }
    else if(A=='B' && B!='A'){
        cout << "<" << endl;
    }
    else if(A!='A' && B=='B'){
        cout << ">" << endl;
    }
    else if(A=='E'){
        cout << ">" << endl;
    }
    else if(B=='E'){
        cout << "<" << endl;
    }
    else if(A=='C' && B== 'D'){
        cout << "<" << endl;
    }
    else if(A=='D' && B=='C'){
        cout << ">" << endl;
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,n,A[251];

  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);
  for(i=1;i<=n;i++){
    printf("node %d: key = %d,",i,A[i]);
    
    //pare
    if(i!=1){
      printf(" parent key = %d,",A[i/2]);
    }
    
    
    if(i*2<=n)printf(" left key = %d,",A[i*2]);
    if(i*2+1<=n)printf(" right key = %d,",A[i*2+1]);
    printf(" \n");
  }
  return 0;
}



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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	string s;
	map<string,int> mp;
	int mx=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>s;
		++mp[s];
		mx=max(mx,mp[s]);
	}
	for (auto i = mp.begin(); i != mp.end(); ++i)
	{
		if (i->second==mx)
		{
			cout<<i->first<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 25216
W, a, b = map(int, input().split())
#print(W, a, b)

if W + a < b:
    print(b - (W + a))
elif a <= b <= W+a:
    print("0")
elif a <= b+W <= a+W:
    print("0")
elif W + b < a:
    print(a - (W + b))


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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> c(n),s(n),f(n);
    for(int i = 0; i < n-1; i++){
        std::cin >> c[i] >> s[i] >> f[i];
    }
    std::vector<int> ans(n);
    for(int i = 0; i < n-1; i++){
        ans[i] = s[i] + c[i];
        for(int j = i + 1; j < n-1; j++){
            //まだ出発していなかったら
            if(ans[i] < s[j]){
                ans[i] += (s[j] - ans[i]) + c[j];
            }else{
                int next = f[j] - (ans[i] % f[j]);
                if(ans[i] % f[j] == 0)next = 0;
                //std::cerr << j << "//" << next << std::endl;
                ans[i] += next + c[j];
            }
        }
    }
    for(int i = 0; i < n; i++)std::cout << ans[i] << std::endl;
}

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

int main()
{
    int numa, numb;
    int group[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    cin >> numa >> numb;
    if(group[numa]==group[numb]){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

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

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

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

  int  p = n;
  while(!is_prime(p))p++;

  cout << p << endl;
  
  return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T>
T gcd(T n, T m){
    if (n>m) return gcd(m,n);
    else if(n==0) return m;
    else return gcd(m-n*(m/n), n);
}

int main(){
    int n;
    cin >> n;
    int m = n/2;
    if (n % 2 == 0) cout << (float)m/n << endl;
    else cout << (float)(m+1)/n << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int x;
	cin>>x;
	int ans=0;
	for(int i=1;i<=40;++i){
		for(int j=2;j<=10;++j){
			if(pow(i,j)<=x)
				ans=max(ans,int(pow(i,j)));
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<pair<ll,ll>> work(n);
  for(int i = 0;i < n;i++){
    ll a,b;
    cin >> a >> b;
    work[i] = make_pair(a,b);
  }
  sort(work.begin(),work.end());
  ll res = 0;
  priority_queue<ll> que;
  ll now = 0;
  for(int i = m;i >= 0;i--){
    while(1){
      if(now > n - 1)break;
      if(work[now].first + i > m)break;
      que.push(work[now].second);
      now++;
    }
   // cout << i << " que" << que.size() << endl;
    if(!que.empty()){
      ll today = que.top();
      res += today;
      //cout << today << endl;
      //cout << i << " " << today << endl;
      que.pop();
    }
    //if(now >= n - 1)break;
  }
  cout << res << endl;
}

Measured memory_bytes: 2936
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n,m;
    int ans[3];
    
    cin >> n >> m;
    
    REP(i,n)ans[i]=-1;

    REP(i,m)
    {
        int s,c;
        cin>>s>>c;s--;
        if(s==0&&c==0&&n!=1)
        {
            cout<<-1<<endl;
            return 0;
        }
        // cout <<s << c<<endl;
        // cout << ans[s] << " " << c <<endl;
        if(ans[s] != -1&&ans[s] != c)
        {
            cout<<-1<<endl;
            return 0;
        }
        ans[s]=c;
    }
    REP(i,n)
    {
        if(ans[i]==-1)
        {
            if(i==0)
            {
                if(n!=1)cout<<1;
                else cout<<0;
            }else cout<<0;
        }else
        {
            cout<<ans[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC060_A_Shiritori
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			string a = input[0];
			string b = input[1];
			string c = input[2];

			if (a.Substring(a.Length - 1, 1) == b.Substring(0, 1))
			{
				if (b.Substring(b.Length - 1, 1) == c.Substring(0, 1))
				{
					Console.WriteLine("YES");
					return;
				}	
			}
			Console.WriteLine("NO");
		}
	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i, N) { cin >> A[i]; }
    rep(i, N) { cin >> B[i]; }

    ll sumA = 0;
    ll sumB = 0;
    rep(i, N) {
        sumA += A[i];
        sumB += B[i];
    }

    if (sumA < sumB) {
        cout << "-1" << endl;
        return 0;
    }

    vector<ll> D(N);
    rep(i, N) { D[i] = A[i] - B[i]; }

    sort(D.begin(), D.end(), greater<ll>());

    ll cnt = 0;
    ll diff = 0;
    for (ll i = N - 1; i >= 0; i--) {
        if (D[i] < 0) {
            diff += D[i];
            cnt++;
        } else {
            break;
        }
    }

    // cout << "diff:" << diff << endl;
    // cout << "cnt:" << cnt << endl;

    for (ll i = 0; i < N; i++) {
        if (D[i] > 0 && diff < 0) {
            diff += D[i];
            cnt++;
        } else {
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int digitsum(int m){
    int a=0;
    while(m>0){
        a+=m%10;
        m/=10;
    }
    return a;
}
int main(){
    int n; cin>>n;
    if(n%digitsum(n))
        cout<<"No";
    else cout<<"Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int m[10][1024][350];
int search(int n, int s, int p){
  if(n > 10 || n < 1 || s < 0 || s >= 350) return 0;
  if(n == 1){
    if(s > 9) return 0;
    if((p & (1 << s)) == 0) return 1;
    else return 0;
  }
  if(m[n-1][p][s] >= 0) return m[n-1][p][s];
  int r = 0;
  for(int j = min(s/n,9); j >= 0; j--){
    if((p & (1 << j)) == 0) {
      r += search(n-1, s - n * j, (p | 1 << j));
    }
  }
  m[n-1][p][s] = r;
  return r;
}
int main()
{
  int n,s;
  memset(m,-1,sizeof(m));
  while(cin >> n >> s){
    cout << search(n,s,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int H,W;
char c[52][52];
int l[52][52];
queue<int> X;
queue<int> Y;

int main() {
	scanf("%d%d",&H,&W);
	for (int i = 0; i < H; i++) {
		scanf("%s", c[i]);
	}
	l[0][0] = 1;
	X.push(0); Y.push(0);
	int count = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W;j++) {
			l[i][j] = 100000;
			if (c[i][j]=='#') {
				count++;
			}
		}
	}
	l[0][0] = 1;
	while (!X.empty()) {
		int x = X.front(); X.pop();
		int y = Y.front(); Y.pop();
		int dx[4] = {1,-1,0,0};
		int dy[4] = {0,0,1,-1};
		for (int i = 0; i < 4;i++) {
			if (0<= x + dx[i] && x + dx[i]<=H-1 && 0<= y + dy[i] && y + dy[i] <=W-1) {
				if (c[x + dx[i]][y + dy[i]] == '.') {
					if (l[x + dx[i]][y + dy[i]] > l[x][y] + 1) {
						if (l[x + dx[i]][y + dy[i]] == 100000) {
							X.push(x + dx[i]);
							Y.push(y + dy[i]);
						}
						l[x + dx[i]][y + dy[i]] = l[x][y] + 1;
					}
				}
			}
		}
	}

	if (l[H - 1][W - 1]>=100000) {
		printf("-1\n");
	}
	else {
		printf("%d\n", H*W - count - l[H - 1][W - 1]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long P = 200003;
const double PI = acos(-1);
long long modpow(long long a, long long b, long long M){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= M;
		}
		a *= a;
		a %= M;
		b /= 2;
	}
	return ans;
}
vector<complex<double>> fft(vector<complex<double>> A, bool inv){
	int N = A.size();
	int M = 0;
	for (int i = 1; i < N; i *= 2){
		M++;
	}
	for (int i = 0; i < N; i++){
		int j = 0;
		for (int k = 0; k < M; k++){
			if ((i >> k) & 1){
				j |= 1 << (M - 1 - k);
			}
		}
		if (i < j){
			swap(A[i], A[j]);
		}
	}
	for (int i = 1; i < N; i *= 2){
		for (int j = 0; j < i; j++){
			complex<double> z = polar((double) 1, (2 * PI) / (i * 2) * j * (inv ? -1 : 1));
			for (int k = 0; k < N; k += i * 2){
				complex<double> s = A[j + k];
				complex<double> t = A[j + k + i] * z;
				A[j + k] = s + t;
				A[j + k + i] = s - t;
			}
		}
	}
	if (inv){
		for (int i = 0; i < N; i++){
			A[i] /= N;
		}
	}
	return A;
}
vector<long long> convolution(vector<long long> A, vector<long long> B){
	int deg = A.size() + B.size() - 1;
	int N = 1;
	while (N < deg){
		N *= 2;
	}
	vector<complex<double>> A2(N);
	for (int i = 0; i < A.size(); i++){
		A2[i] = A[i];
	}
	while (A2.size() < N){
		A2.push_back(0);
	}
	vector<complex<double>> B2(N);
	for (int i = 0; i < B.size(); i++){
		B2[i] = B[i];
	}
	while (B2.size() < N){
		B2.push_back(0);
	}
	vector<complex<double>> a = fft(A2, false);
	vector<complex<double>> b = fft(B2, false);
	vector<complex<double>> c(N);
	for (int i = 0; i < N; i++){
		c[i] = a[i] * b[i];
	}
	c = fft(c, true);
	vector<long long> ans(deg);
	for (int i = 0; i < deg; i++){
		ans[i] = c[i].real() + 0.5;
	}
	return ans;
}
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> B;
  for (int i = 0; i < N; i++){
    if (A[i] > 0){
      B.push_back(A[i]);
    }
  }
  N = B.size();
  vector<int> cnt(P, 0);
  for (int i = 0; i < N; i++){
    cnt[B[i]]++;
  }
  vector<long long> pow(P, 1);
  for (int i = 1; i < P; i++){
    pow[i] = pow[i - 1] * 2 % P;
  }
  vector<int> log(P);
  for (int i = 0; i < P - 1; i++){
    log[pow[i]] = i;
  }
  vector<long long> f(P - 1, 0);
  for (int i = 0; i < N; i++){
    f[log[B[i]]]++;
  }
  vector<long long> g = convolution(f, f);
  vector<long long> f2(P - 1, 0);
  for (int i = 0; i < g.size(); i++){
    f2[i % (P - 1)] += g[i];
  }
  long long ans = 0;
  for (int i = 0; i < P - 1; i++){
    ans += pow[i] * f2[i];
  }
  for (int i = 0; i < N; i++){
    ans -= B[i] * B[i] % P;
  }
  assert(ans % 2 == 0);
  ans /= 2;
  cout << ans << endl;
}

Measured memory_bytes: 63028
#data????§???????[y???][x???]??§??????

if __name__ == "__main__":
    while 1:
        w,h = list(map(int,input().strip().split()))
        if w == h == 0:break
        data = []
        data = []
        for _ in range(h):data.append(list(input()))
        visited = []
        for i in range(h):
            if '@'in data[i]:stack= [(i,data[i].index('@'))]
        count = 0
        while len(stack) !=0:
            y,x= stack.pop()
            count +=1
            if y-1 >= 0 and not (y-1,x)in visited and data[y -1][x] == '.':
                visited.append((y-1,x))
                stack.append((y-1,x))
            if x -1 >= 0 and not (y,x-1)in visited and data[y][x-1] == '.':
                visited.append((y,x-1))
                stack.append((y,x-1))
            if y +1 < h and not (y+1,x)in visited and data[y +1][x] == '.':
                visited.append((y+1,x))
                stack.append((y+1,x))
            if x + 1 < w and not (y,x+1)in visited and data[y][x +1] == '.':
                visited.append((y,x+1))
                stack.append((y,x+1))

        print(count)

Measured memory_bytes: 7708
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    ll l = 0;
    ll r = h[N - 1] / B + 100;
    while(r - l > 1){
        ll m = (l + r)/2;
        auto tmp = h;
        for (int i = 0; i < N; ++i) {
            tmp[i] -= m * B;
        }
        ll count = 0;
        for (int i = 0; i < N; ++i) {
            if(tmp[i] <= 0){
                continue;
            }
            count += tmp[i] / (A-B);
            if(tmp[i] % (A - B) != 0){
                count++;
            }
        }
        if(count <= m){
            r = m;
        }else{
            l = m;
        }
    }
    auto tmp = h;
    for (int i = 0; i < N; ++i) {
        tmp[i] -= l * B;
    }
    ll count = 0;
    for (int i = 0; i < N; ++i) {
        if(tmp[i] <= 0){
            continue;
        }
        count += tmp[i] / (A-B);
        if(tmp[i] % (A - B) != 0){
            count++;
        }
    }
    if(count <= l){
        cout << l << endl;
    }else{
        cout << r << endl;
    }


}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int n;
vector<string> ns[200];
map<string, int> gs;
set<string> vis;

int visit(int at) {
    if(vis.find(ns[at][0])!=vis.end()) return 0;
    vis.insert(ns[at][0]);
    int ans = 0;
    for(int i=1; i<(int)ns[at].size(); i++) {
        if(gs.find(ns[at][i])!=gs.end()) ans += visit(gs[ns[at][i]]);
        else if(vis.find(ns[at][i])==vis.end()) {
            ans += 1;
            vis.insert(ns[at][i]);
        }
    }
    return ans;
}

int main() {
    for(;;) {
        string s;
        getline(cin, s);
        n = atoi(s.c_str());
        if(n==0) return 0;
        gs.clear();
        vis.clear();
        rep(k, n) {
            getline(cin, s);
            ns[k].clear();
            int pre = 0;
            rep(i, s.size()) if(s[i]==':' || s[i]==',' || s[i]=='.') {
                ns[k].push_back(s.substr(pre, i-pre));
                pre = i+1;
            }
            gs[ns[k][0]] = k;
        }
        printf("%d\n", visit(0));
    }
}

Measured memory_bytes: 0
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
//#define N 500055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a,b;
signed main(){
	n=read();a=read();b=read();
	if (abs(a-b)&1) puts("Borys");
	else puts("Alice");
	return 0;
}


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

class Card{
    public:
    char name;
    int value;
    void set_name(char n) { name = n; }
    void set_value(int v) { value = v; }
};

void printAll(std::vector<Card> cards){
    int N = cards.size();
    for (int i = 0; i < (N-1); i++) {
        std::cout << cards[i].name << cards[i].value << ' ';
    }
    std::cout << cards[N-1].name << cards[N-1].value << std::endl;
}

std::vector<Card> bubbleSort(std::vector<Card> cards) {
    int N = cards.size();
    Card tmp;
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (cards[j].value < cards[j-1].value) {
                tmp = cards[j];
                cards[j] = cards[j-1];
                cards[j-1] = tmp;
            }
        }
    }
    return(cards);
}

std::vector<Card> selectionSort(std::vector<Card> cards) {
    int N = cards.size(), mini;
    Card tmp;
    for (int i = 0; i < N; i++) {
        mini = i;
        for (int j = i; j < N; j++) {
            if (cards[j].value < cards[mini].value) {
                mini = j;
            }
        }
        if (mini != i) {
            tmp = cards[i];
            cards[i] = cards[mini];
            cards[mini] = tmp;
        }
    }
    return(cards);
}

std::string isStable(std::vector<Card> orig, std::vector<Card> sorted) {
    int N = orig.size(), value;
    std::vector<char> orig_names, sorted_names;
    for (int i = 0; i < N; i++) {
        value = orig[i].value;
        orig_names.clear();
        sorted_names.clear();

        for (int j = 0; j < N; j++) {
            if(orig[j].value == value) {
                orig_names.push_back(orig[j].name);
            }
            if(sorted[j].value == value) {
                sorted_names.push_back(sorted[j].name);
            }
        }

        for(int k = 0; k < orig_names.size(); k++) {
            if (orig_names[k] != sorted_names[k]) {
                return("Not stable");
            }
        }
    }
    return("Stable");
}

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main()
{
    int N;
    std::cin >> N;
    Card tmp;
    std::vector<Card> cards(N);

    for (int i = 0; i < N; i++) {
        std::string input;
        std::cin >> input;
        tmp.set_name(input[0]);
        tmp.set_value(ctoi(input[1]));
        cards[i] = tmp;
    }

    std::vector<Card> bubble = bubbleSort(cards);
    printAll(bubble);
    std::cout << isStable(cards, bubble) << std::endl;
    std::vector<Card> selection = selectionSort(cards);
    printAll(selection);
    std::cout << isStable(cards, selection) << std::endl;

}


Measured memory_bytes: 3180
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    ans=0
    S=[0]*(N+2)
    for i in range(N+1):
        S[i+1]=S[i]+(i)
    
    
    for i in range(K,N+2):#i個選ぶ
        m=S[i]
        M=S[-1]-S[-1-i]
        ans+=(M-m+1)%mod
        ans%=mod
    print(ans)
        

main()


Measured memory_bytes: 65672
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

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

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<char>> vec(n, vector<char>(m));
    unordered_map<int, int> rcnt, colcnt;
    int tot = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> vec[i][j];
        if (vec[i][j] == '#') {
          rcnt[i]++;
          colcnt[j]++;
          tot++;
        }
      }
    }
    int a = 0, b = 0;
    int ans = 0;
    for (; a < (1 << n); a++) {
      b = 0;
      for (; b < (1 << m); b++) {
        int cnt = tot;
        vector<vector<char>> t(vec);
        for (int i = 0; i < n; i++) {
          if (a & (1 << i)) {
            for (int j = 0; j < m; j++) {
              if (t[i][j] == '#') {
                t[i][j] = '.';
                cnt--;
              }
            }
          }
        }
        for (int j = 0; j < m; j++) {
          if (b & (1 << j)) {
            for (int i = 0; i < n; i++) {
              if (t[i][j] == '#') {
                t[i][j] = '.';
                cnt--;
              }
            }
          }
        }
        if (cnt == k) ans++;
      }
    }
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 3652
D,G=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(D)]

ans=float('inf')
for i in range(2**D):
  score=0
  b=0
  cnt=0
  for j in range(D):
    if ((i>>j)&1):
      score+=100*(j+1)*pc[j][0]+pc[j][1]
      cnt+=pc[j][0]
    else:
      b=j
  for k in range(pc[b][0]):
    if score>=G and cnt<ans:
      ans=cnt
    score+=(b+1)*100
    cnt+=1
print(ans)


Measured memory_bytes: 3064
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    A = tuple(iim())

    d1 = dict()
    for ai in A:
        if ai in d1:
            d1[ai] += 1
        else:
            d1[ai] = 1

    aa = []
    cnt = 0
    d2 = dict()
    for k, v in d1.items():
        v = v * (v-1) // 2
        cnt += v
        d2[k] = v

    for ak in A:
        ans = 0
        v = d1[ak] - 1
        v = v * (v-1) // 2
        aa.append(cnt-d2[ak]+v)
    print(*aa, sep="\n")


if __name__ == "__main__":
    resolve()


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<long long int> counter(5);
  for(int i=0;i<N;i++) {
    cin >> S[i];
    if(S[i][0] == 'M') counter[0]++;
    else if(S[i][0] == 'A') counter[1]++;
    else if(S[i][0] == 'R') counter[2]++;
    else if(S[i][0] == 'C') counter[3]++;
    else if(S[i][0] == 'H') counter[4]++;
  }

  long long int total = 0;
    for(int i=0;i<counter.size();i++) {
      for(int j=i+1;j<counter.size();j++) {
        for(int k=j+1;k<counter.size();k++) {
          total += counter[i] * counter[j] * counter[k];
        }
      }
    }

    cout << total << endl;
}

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

using namespace std;

int main(){
	int s1, s2, s3;

	cin >> s1 >> s2 >> s3;

	vector<int> v;
	v.push_back(s1);
	v.push_back(s2);
	v.push_back(s3);

	int i = 0;
	int j = 0;

	for(auto m : v)	{
		if(m == 5){
			i++;
		}
		if(m == 7){
			j++;
		}
	}
	if((i == 2) && j == 1){
		cout << "YES";
	}
	else{
		cout << "NO";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N, C;
    cin >> N >> C;
    ll x[MAX], v[MAX];
    ll s[MAX]={};
    ll r[MAX]={};
    ll si[MAX]={};
    ll ssi[MAX]={};
    ll i;
    
    x[0]=0; v[0]=0;
    for(i=1; i<=N; i++) cin >> x[i] >> v[i];
    x[N+1]=C; v[N+1]=0;
    
    for(i=1; i<=N; i++) s[i]=s[i-1]+v[i];
    for(i=N; i>=1; i--) r[i]=r[i+1]+v[i];
    
    ll mx=0, mi=0;
    for(i=1; i<=N; i++) {
        if(s[i]-x[i]>mx) {
            mx=s[i]-x[i];
            mi=i;
        }
        si[i]=mi;
    }
    
    mx=0; mi=0;
    for(i=1; i<=N; i++) {
        if(s[i]-x[i]*2>mx) {
            mx=s[i]-x[i]*2;
            mi=i;
        }
        ssi[i]=mi;
    }
    
    ll ans=0;
    for(ll b=1; b<=N+1; b++) {
        chmax(ans, s[ssi[b-1]]-x[ssi[b-1]]*2+r[b]-(C-x[b]));
        chmax(ans, s[si[b-1]]-x[si[b-1]]+r[b]-(C-x[b])*2);
    }
    pt(ans);
}





Measured memory_bytes: 4992
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);

int mod9(int A) {
    int tmp = 0;
    while (A > 0) {
        tmp += A % 10;
        A /= 10;
    }
    return tmp;
}

//番号ズレ注意！！
int main() {
    int N, x;
    cin >> N >> x;
    int a[N];
    REP(i, N) {
        cin >> a[i];
    }
    sort(a, a + N);
    int ans = 0;
    REP(i, N) {
        if (a[i] > x) { break; }
        if (i == N - 1 && x != a[i]) { break; }
        ans += 1;
        x -= a[i];
    }
    print(ans);
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

MAX = 1000000
s = [1] * MAX
s[0] = 0
s[1] = 0

start = 2
while True:
    pmb = 0
    for i in range(start, MAX):
        if s[i] == 1:
            pmb = i
            break
   
    if pmb == 0:
        break

    for i in range(pmb ** 2, MAX, pmb):
        s[i] = 0

    start += 1
    
while True:
    try:
        n = int(input())
        
        c = 0
        for i in range(2, n + 1):
            if s[i] == 1:
                c += 1
        print(c)

    except EOFError:
        break


Measured memory_bytes: 13188
x,y = map(int,input().split())
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(input()))

    except:
        break;
s=0
for i in range(x):
  for j in range(y):
    if  ((listA[i][j]=='#')&(listA[i][j]!=listA[max(0,i-1)][j])&(listA[i][j]!=listA[min(x-1,i+1)][j])&
    (listA[i][j]!=listA[i][max(0,j-1)])&(listA[i][j]!=listA[i][min(y-1,j+1)])):
      s+=1
if s==0:
  print('Yes')
else:
  print('No')
      

Measured memory_bytes: 3064
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7

dp = [[0] * (M + 1) for i in range(N + 1)]
dp_sum = [[0] * (M + 1) for i in range(N + 1)]

dp[0][0] = 1
for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        if s == t:
            dp[i][j] = dp_sum[i - 1][j - 1] + 1
            dp[i][j] %= MOD
        dp_sum[i][j] = dp_sum[i - 1][j] + dp_sum[i][j - 1] - dp_sum[i - 1][j - 1] + dp[i][j]
        dp_sum[i][j] %= MOD

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD

print(ans % MOD)


Measured memory_bytes: 105308
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VV dp(s.size() + 1, V(13));
    dp[0][0] = 1;
    rep(i, s.size())
    {
        rep(j, 13)
        {
            if (s[i] == '?')
            {
                rep(k, 10)
                {
                    ll g=(j*10 + k)%13;
                    dp[i + 1][g] += dp[i][j];
                    if(dp[i + 1][g]>=MOD)dp[i + 1][g]-=MOD;
                }
            }
            else
            {
                ll g=(j * 10 + (s[i] - '0'))%13;
                dp[i + 1][g] += dp[i][j];
                if(dp[i + 1][g]>=MOD)dp[i + 1][g]-=MOD;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
}


Measured memory_bytes: 13632
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;


int main()
{

	int count ;
	int a, b, c, maxs;

	cin >> count;

	for (int i = 0; i < count; i++)
	{
		cin >> a >> b >> c;

		maxs = max({ a, b, c });

		if (maxs == a)
		{
			if (maxs == sqrt(b * b + c * c))
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else if (maxs == b)
		{
			if (maxs == sqrt(a * a + c * c))
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else if(maxs == c)
		{
			if (maxs == sqrt(a * a + b * b))
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
	}


}

Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long a,b,temp;
  cin >> a >> b;
  while(a>0&&b>0){
    if(a<b){
      temp = b;
      b = a;
      a = temp;
      //cout << a << " " << b << endl;
    }
    if(a%b==0){
      cout << b << endl;
      break;
    }
    else{
      a %= b;
      temp = b;
      b = a;
      a = temp;
      //cout << a << " " << b << endl;
    }
  }
}


Measured memory_bytes: 3088
import Data.List

main :: IO()
main = do
    getLine
    ls <- map read . words <$> getLine
    print $ nijouhou ls

nijouhou :: [Int] -> Int
nijouhou ls = 
    let sortLs = sort ls
        minNum = head sortLs
        maxNum = last sortLs
    in minimum [ sum [(x - n)^2 | x <- sortLs] | n <- [minNum .. maxNum]]


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

using namespace std;

int main(void)
{
	int length;
	string str;

	//input string
	//stringに">>"演算子で入力しても空白で止まってしまうため，getline関数を使う
	getline(cin, str);

	length = str.length();
	for(int i = 0; i < length; i++)
	{
		//取得した文字が小文字のアルファベット
		if( ('a' <= str[i]) && (str[i] <= 'z') )
		{
			//大文字に変換して更新
			str[i] -= 0x20;
		}
		//取得した文字が大文字のアルファベット
		else if( ('A' <= str[i]) && (str[i] <= 'Z') )
		{
			//小文字に変換して更新
			str[i] += 0x20;
		}
		else{}
	}
	
	cout << str << endl;

	return 0;
}



Measured memory_bytes: 3172
#include <stdio.h>

int main(void)
{
	int m = 100000;
	int n;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		m += (m * 5 / 100);
		if ((m % 1000 < 1000) && (m % 1000 > 0)){
			m -= m % 1000;
			m += 1000;
		}
	}
	
	printf("%d\n", m);
	
	return (0);
}

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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n+1);
rep(i, n+1){
  cin >> a[i];
}
vector<ll> aa(n+1);
aa[n]=a[n];
rep(i,n)aa[n-i-1]=aa[n-i]+a[n-i-1];
aa[0]=1;

rep(i,n){
  if(aa[i]-a[i]<=0){cout << -1 << endl;return 0;}
  else if((aa[i]-a[i])*2<a[i+1]){cout << -1 << endl;return 0;}
  else aa[i+1]=min(aa[i+1],(aa[i]-a[i])*2);
}
if(a[n]!=aa[n]){cout << -1 << endl;return 0;}
for(auto r:aa)ans+=r;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); i++)
 
int main() {
  int a,b;
  cin>>a>>b;
  char c[a],d[b],e;
  string ans="Yes";
  rep(i,a){
    cin>>c[i];
    if(c[i]<'0'||c[i]>'9'){
      ans="No";
      break;
    }
  }
  cin>>e;
  if(e!='-'){
    ans="No";
  }
  rep(i,b){
    cin>>c[i];
    if(c[i]<'0'||c[i]>'9'){
      ans="No";
      break;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  string s;
  cin >> s;
  string X = "";
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='0'){
      X +='0';
    }
    else if(s.at(i)=='1'){
      X +='1';
    }
    else{
      if(X.size()!=0){
      X.erase(X.size()-1);
      }
    }
  }
      cout << X << endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

vi Solve(ll n) {
  if (n == 0) exit(0);
  if (n == 1) return vi(0, 0);
  vi a = Solve(n / 2);
  a.push_back(a.size());
  if (n % 2) {
    reverse(a.begin(), a.end());
    a.push_back(a.size());
    reverse(a.begin(), a.end());
  }
  return a;
}

int main()
{
  ll n;
  cin >> n;
  vi result = Solve(n);

  int m = result.size();
  for (int i = 0; i < m ; ++i) result.push_back(i);
  result.push_back(m);
  result.push_back(m);
  cout << result.size() << endl;
  for (int i = 0; i < result.size(); ++i) {
    if (i) cout << " ";
    cout << result[i] + 1;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3508
##### 解けた #####

N=int(input())
S=input()
maxx=0 # xの最大値
x=0 # xの初期値

for s in S:
    if s=="I": # "I"の場合は増やす
        x+=1
    elif s=="D": # "D"の場合は減らす
        x-=1

    if x>maxx: # 最大値を上回ったら更新
        maxx=x
    
print(maxx)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric> 
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1e9 + 5;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
///////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int n;
vector<int> h(N);
vector<int> dp(N);

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
    dp[0] = 0, dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; ++i) dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));

    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

#define S second
#define F first
#define all(a) a.begin() , a.end()
#define pb push_back 
#define DBG cout<<"debug\n";

typedef long long ll;

const int N = 2 * 1e5 + 10;
const ll inf = 9e18 + 9; 

ll res;
ll a[N];


void solve(){
    char a;
    cin>>a;
    cout<<++a<<"\n";
}

int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256