akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int main(void){
  int n;
  int a[100];
  int ans=100000000,mi=1000,ma=-1000;

  scanf("%d",&n);

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

  for(int i=mi;i<=ma;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum += (a[j]-i)*(a[j]-i);
    }
    ans = min(sum,ans);
  }

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

  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D,E,F;
    cin >>A >>B >>C >>D >>E >>F;
    int AA,BB,CC,DD;
    int W=A*100,S=0,w=0,s=0;
    for (int a=0;(AA=100*a*A)<=F;a++){
        for(int b=0;(BB=100*b*B)<=F-AA;b++){
            for(int c=0;(CC=c*C)<=F-AA-BB;c++){
                for (int d=0;(DD=d*D)<=F-AA-BB-CC;d++){
                    w=AA+BB;
                    s=CC+DD;
                    if(w+s<=F and s <= (a*A+b*B)*E  ){
                        
                        if ((w+s)*S <(W+S)*s){
                            W=w;
                            S=s;
                        }
                    }
                }
            }
        }
    }
    cout <<S+W << " " <<S <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		HashMap<Long, Long> hm = new HashMap<Long, Long>();
		for(int i = 0; i < n; i++){
		    long a = sc.nextLong();
		    hm.put(a, hm.getOrDefault(a, 0L)+1);
		}
		long result = 0;
		for(Long key : hm.keySet()){
		    result += key*hm.get(key);
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++){
		    long b = sc.nextLong();
		    long c = sc.nextLong();
		    hm.put(c, hm.getOrDefault(c, 0L)+hm.getOrDefault(b, 0L));
		    result += (c-b)*hm.getOrDefault(b, 0L);
		    hm.remove(b);
		    System.out.println(result);
		}
		
		// 計算
		//long result = 0;
		
		// 出力
		//System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 54692
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    int x;
    cin>>x;


    bool prime_flag;
    do{
        prime_flag=true;
        for(int i=2;i*i<=x;i++){
            if(x%i==0){
                x++;
                prime_flag=false;
                break;
            }
        }
    }while(prime_flag==false);

 
    cout<<x<<endl;
    return 0;
}  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
https://abc059.contest.atcoder.jp/tasks/arc072_a
WA
"""
import sys
from sys import stdin
input = stdin.readline


def check_sign(n):
    if n > 0:
        return 1
    elif n < 0:
        return -1
    else:
        return 0


def solve(A):
    p_ans = 0
    n_ans = 0
    i_ans = 0

    # 最初をプラス側に振った場合の解
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        p_ans += 1
        total += 1
        prev_sign = 1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            p_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            p_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    # 最初をマイナス側に振った場合の解
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        n_ans += 1
        total -= 1
        prev_sign = -1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            n_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            n_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    # 反転させてからスタートする
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        i_ans += 1
        total += 1
        prev_sign = 1
    else:
        i_ans += (abs(total) + 1)
        if prev_sign > 0:
            prev_sign = -1
            total = -1
        else:
            prev_sign = 1
            total = 1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            i_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            i_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    return min(p_ans, n_ans, i_ans)


def main(args):
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main()
{
    int N, D, count;
    long long temp, x, y;
    cin >> N >> D;

    count = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> x >> y;
        temp = x * x + y * y;
        if (D >= sqrt(temp))
        {
            count++;
        }
    }
    cout << count << endl;
    return (0);
}


Measured memory_bytes: 3648
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
#define MAX 100003
ll power(ll a, ll b) 
{
    ll res=1LL;
    while(b>0){
        if(b&1LL) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res%mod;
}
string add_one(string s)
{
    s="0"+s;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='0') {
            s[i]='1';
            break;
        }
        else s[i]='0';
    }
    return s;
}
int main()
{
    string s;
     cin>>s;
     s=add_one(s);
     
     ll cnt=0;
     ll ans=0;
     for(int i=0;i<s.size();i++){
         if(s[i]=='1') {
             ll left=s.size()-i-1;
             ll val=(power(2,cnt) * power(3,left))%mod ;
             ans=(ans+val)%mod;
             cnt++;
         }
     }
     ans%=mod;
     cout<<(ans)%mod<<endl;
}

Measured memory_bytes: 512
N,K=gets.split.map(&:to_i)
d=gets.split.map{|e|e.chomp}
ans=N
while(true)
    c=ans.to_s
    f=true
    (c.size).times do |i| 
        K.times do |j|
            f=false if c[i]==d[j]
        end
    end
    break if f
    ans+=1
end
puts ans

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx_r[] = {0,1,0,-1};
static const int ty_r[] = {-1,0,1,0};

static const int tx_l[] = {0,-1,0,1};
static const int ty_l[] = {-1,0,1,0};

class PosInfo {
public:
  int Rin_x;
  int Rin_y;
  int Len_x;
  int Len_y;
  PosInfo(int a,int b,int c,int d) : Rin_x(a),Rin_y(b),Len_x(c),Len_y(d) {}
};

bool visited[51][51][51][51];
char stage_Len[51][51];
char stage_Rin[51][51];

bool can_reach;
int W,H;

int main(){

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

    for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
	for(int y2=0;y2<H;y2++){
	  for(int x2=0;x2<W;x2++){
	    visited[x][y][x2][y2] = false;
	  }
	}
      }
    }

    can_reach = false;
    
    int Rin_start_x = 0;
    int Rin_start_y = 0;
    int Len_start_x = 0;
    int Len_start_y = 0;
 
    for(int y=0;y<H;y++){
      string str_Len,str_Rin;
      cin >> str_Len >> str_Rin;
      
      // cout << str_Len << endl;
      // cout << str_Rin << endl;

      for(int x=0;x<W;x++){
	stage_Len[y][x] = str_Len[x];
	stage_Rin[y][x] = str_Rin[x];

	if(str_Len[x] == 'L'){
	  Len_start_x = x;
	  Len_start_y = y;
	}
	if(str_Rin[x] == 'R'){
	  Rin_start_x = x;
	  Rin_start_y = y;
	}
      }
    }
    
    queue<PosInfo> que;
    que.push(PosInfo(Rin_start_x,Rin_start_y,Len_start_x,Len_start_y));
    visited[Rin_start_x][Rin_start_y][Len_start_x][Len_start_y] = true;
    
    while(!que.empty()){
      PosInfo pi = que.front();
      que.pop();

      for(int i=0;i<4;i++){
	int Rin_dx = pi.Rin_x + tx_r[i];
	int Rin_dy = pi.Rin_y + ty_r[i];

	int Len_dx = pi.Len_x + tx_l[i];
	int Len_dy = pi.Len_y + ty_l[i];

	if(Rin_dx < 0 || Rin_dx >= W || Rin_dy < 0 || Rin_dy >= H){
	  Rin_dy = pi.Rin_y;
	  Rin_dx = pi.Rin_x;
	}
	else if(stage_Rin[Rin_dy][Rin_dx] == '#'){
	  Rin_dy = pi.Rin_y;
	  Rin_dx = pi.Rin_x;
	}

	if(Len_dx < 0 || Len_dx >= W || Len_dy < 0 || Len_dy >= H){
	  Len_dy = pi.Len_y;
	  Len_dx = pi.Len_x;
	}
	else if(stage_Len[Len_dy][Len_dx] == '#'){
	  Len_dy = pi.Len_y;
	  Len_dx = pi.Len_x;
	}

	if(visited[Rin_dx][Rin_dy][Len_dx][Len_dy]){
	  continue;
	}

	if(stage_Len[Len_dy][Len_dx] == '%'
	   && stage_Rin[Rin_dy][Rin_dx] == '%'){
	  can_reach = true;
	  break;
	}

	if(stage_Len[Len_dy][Len_dx] != '%'
	   && stage_Rin[Rin_dy][Rin_dx] != '%'){
	  visited[Rin_dx][Rin_dy][Len_dx][Len_dy] = true;
	  que.push(PosInfo(Rin_dx,Rin_dy,Len_dx,Len_dy));
	}
      }
    }

    printf("%s\n",can_reach ? "Yes" : "No");
  }
}

Measured memory_bytes: 8628
import numpy as np
def solve(a, b, x):
    if a < b:
        if x < a*a*b/2:
            h = 2*x / (a*b)
            theta = np.arctan(b/h)
        else:
            h = 2*(a*a*b - x) / (a*a)
            theta = np.arctan(h/a)
    else:
        if x < a*a*b/2:
            h = 2*x / (a*b)
            theta = np.arctan(b/h)
        else:
            h = 2*(a*a*b - x) / (a*a)
            theta = np.arctan(h/a)
    return theta / np.pi * 180

a, b, x = map(int, input().split())
print(solve(a, b, x))

Measured memory_bytes: 12504
#include <bits/stdc++.h>
          
#define pb push_back
#define ll long long
#define f first
#define s second
#define ld long double
#define fa fflush(stdout); 
#define mp make_pair
using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);;                                                      
} 
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};
  
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll big = 1e9;
  
int main() 
{
    data();     
	int d, s;
	double t;
	cin >> d >> t >> s;
	double sek = (double) d / s;
	cout << (t >= sek ? "Yes" : "No");	
}
//21

Measured memory_bytes: 3712
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int m1 = sc.nextInt();
        int d1 = sc.nextInt();
        int m2 = sc.nextInt();
        int d2 = sc.nextInt();
        
        if(m1!=m2){
            System.out.println("1");
        }else{
            System.out.println("0");
        }     
        
   }
}


Measured memory_bytes: 35708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;

  S = '0' + S + '1';

  vector<int> s, g;
  s.push_back(1);
   
  bool flag_1 = (S[1] == '1') ? true : false;
  bool first_1 = (flag_1) ? true : false;
  for (int i = 2; i <= N; i++) {
    if ((S[i] == '1' && flag_1) || (S[i] == '0' && !flag_1)) {
      continue;
    } else if (S[i] == '1') {
      s.push_back(i);
      flag_1 = true;
    } else {
      flag_1 = false;
      if (first_1) {
        first_1 = false;
        continue;
      }
      g.push_back(i-1);
    }
  }

  g.push_back(N);

  int ans = 0;
  rep(i, s.size()) {
    int gx = min(i+K-1, (int)g.size()-1);
    ans = max(ans, g[gx]-s[i]+1);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 888
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func f(s string) int {
	N, _ := strconv.Atoi(s)
	a := 0
	for i := 0; i <= N; i++ {
		sum := 0
		n := i
		for n > 0 {
			sum += n % 10
			n /= 10
		}
		a = max(a, sum)
	}
	return a
}

func solve(s string) int {
	// １桁
	if len(s) == 1 {
		v, _ := strconv.Atoi(s)
		return v
	}
	// ２桁目以降がすべて９
	flg := true
	for i := 1; i < len(s); i++ {
		if s[i] != '9' {
			flg = false
		}
	}
	x := (len(s)-1)*9 + int(s[0]-'0') - 1
	if flg == true {
		x++
	}

	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()

	out(solve(s))

	// for i := 1; i < 10000; i++ {
	// 	s := fmt.Sprintf("%d", i)
	// 	x := solve(s)
	// 	y := f(s)
	// 	if x != y {
	// 		out(s, x, y, "------")
	// 	} else {
	// 		out(s, x, y)
	// 	}
	// }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

ll count_order(ll a,vector<ll> vec1,vector<ll> vec2) {
  ll ans=1;
  bool b=false;
  while(!b) { 
    b=true;
    next_permutation(vec1.begin(),vec1.end());
    rep(i,a) {if(vec1[i]!=vec2[i]) {b=false;break;}}
    if(!b) ans++;
  }
  return ans;
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,p,q,ans=0;cin>>N; string ps,qs;
  vector<ll> P(N,0),Q(N,0);
  rep(i,N) {cin>>p;P[i]=p;ps+=to_string(p);}
  rep(i,N) {cin>>q;Q[i]=q;qs+=to_string(q);}
  p=stoi(ps),q=stoi(qs);
  if(p==q) ans=0;
  else if(p>q) ans=count_order(N,Q,P);
  else ans=count_order(N,P,Q);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

def check(a):
    for i in range(N):
        if a[i] %2 == 0:
            if a[i]%3 != 0 and a[i]%5 != 0:
                return "DENIED"
    return "APPROVED"

print(check(a))


Measured memory_bytes: 2940
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        while(true){
            c = c-b;
            if(c<=0){
                System.out.println("Yes");
                break;
            }
            a = a-d;
            if(a<=0){
                System.out.println("No");
                break;
            }
        }
    }
}

Measured memory_bytes: 35772
n,k = map(int, input().split())

n_list=list(range(n+1))

saisyou=sum(n_list[0:k])
saidai=sum(n_list[n-k+1:n+1])

ans=saidai-saisyou+1

for i in range(k+1,n+2):
    saisyou+=n_list[i-1]
    saidai+=n_list[-(i)]
    ans+=saidai-saisyou+1
    ans%=10**9+7

print(ans)

Measured memory_bytes: 67920
#include<bits/stdc++.h>
using namespace std;
int main() {
  int W, H, N; cin >> W >> H >> N;
  vector<pair<int, int>> xy(N);
  vector<int> a(N);
  vector<vector<bool>> s(W, vector<bool> (H, 0));
  vector<bool> subH(H, 1), subW(W, 1); 
  for(int i = 0; i < N; i++) {
    cin >> xy.at(i).first >> xy.at(i).second >> a.at(i);
  }
  for(int i = 0; i < N; i++) {
    if(a.at(i) == 1) {
      for(int j = 0; j < xy.at(i).first; j++) {
        s.at(j) = subH;
      }
    } else if(a.at(i) == 2) {
      for(int j = xy.at(i).first; j < W; j++) {
        s.at(j) = subH;
      }
    } else if(a.at(i) == 3) {
      for(int j = 0; j < xy.at(i).second; j++) {
        for(int k = 0; k < W; k++) {
          s.at(k).at(j) = 1;
        }
      }
    } else {
      for(int j = xy.at(i).second; j < H; j++) {
        for(int k = 0; k < W; k++) {
          s.at(k).at(j) = 1;
        }
      }
    }
  }
  int count = 0;
  for(int i = 0; i < W; i++) {
    for(int j = 0; j < H; j++) {
      if(!s.at(i).at(j)) {
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{
    public static void Main()
    {
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int N = a[0];
        int M = a[1];
    　　var dic = new Dictionary<long, long>();
        for(int i = 0; i < N; i++)
        {
            int[] b = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
            if(dic.ContainsKey(b[0]))
            {
                dic[b[0]] += b[1];
            }
            else
            {
                dic.Add(b[0], b[1]);
            }
        }
        
        var sortedDic = dic.OrderBy((x) => x.Key);
        
        long count = 0;
        long money = 0;
        foreach(var item in sortedDic)
        {
            
            if(count + item.Value <= M) //その店のドリンクをすべて買い切れる場合
            {
                count += item.Value;
                money += item.Value * item.Key;
            }
            else  //途中でM個に到達してしまう場合
            {
                for(int j = 0; j < item.Value; j++)
                {
                    count++;
                    money += item.Key;
                    if(count == M)
                    {
                        Console.WriteLine(money);
                        return;
                    }
                }
            }
            
            if(count == M)
            {
                Console.WriteLine(money);
                return;
            }
    
        }
    }
}


Measured memory_bytes: 28600
//A - Air Conditioner
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  int n;
  scanf("%d", &n);
  if(n>=30){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1616
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

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

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
int n, m;

vector<vector<int> > es, esrev;

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  es = esrev = vector<vector<int> >(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    es[s].pb(t);
    esrev[t].pb(s);
  }
  return 1;
}

int rem[maxn];

long long cnt[3];

bool fail;

int cnte;

void dfs(int v) {
  cnt[rem[v]] += 1;
  cnte += sz(es[v]);
  for (int u : es[v]) {
    int nrem = (rem[v] + 1) % 3;
    if (rem[u] != -1) {
      if (rem[u] != nrem) {
        fail = 1;
      }
      continue;
    }
    rem[u] = nrem;
    dfs(u);
  }
  for (int u : esrev[v]) {
    int nrem = (rem[v] + 2) % 3;
    if (rem[u] != -1) {
      if (rem[u] != nrem) {
        fail = 1;
      }
      continue;
    }
    rem[u] = nrem;
    dfs(u);
  }
}

void solve() {
  for (int i = 0; i < n; ++i) {
    rem[i] = -1;
  }

  long long res = 0;
  for (int i = 0; i < n; ++i) {
    if (rem[i] != -1) {
      continue;
    }
    memset(cnt, 0, sizeof(cnt));
    fail = 0;
    rem[i] = 0;
    cnte = 0;
    dfs(i);
    if (fail) {
      long long sum = cnt[0] + cnt[1] + cnt[2];
      res += sum * sum;
    } else {
      if (cnt[0] && cnt[1] && cnt[2]) {
        res += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
      } else {
        res += cnte;
      }
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    map<int,int> mii;
    rep(i,n){
        int d;
        cin >> d;
        mii[d]++;
    }
    bool ok = 1;
    int m;
    cin >> m;
    rep(i,m){
        int t;
        cin >> t;
        if(mii[t] == 0) ok = 0;
        else mii[t]--;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 12980
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9+7
#define LINF (long long)4e18

int main(){
    int R; cin >> R;
    if(R < 1200) cout << "ABC" << endl;
    else if(R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}
   

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

using namespace std;

int main()
{
    char s1[10],s2[10],s3[10];
    char c1,c2,c3;
    scanf("%s %s %s",s1,s2,s3);
    c1=s1[0];
    putchar (toupper(c1));
    c2=s2[0];
    putchar (toupper(c2));
    c3=s3[0];
    putchar (toupper(c3));
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;
typedef unsigned long long ULL;
const int N=15;
const ULL B=133333;
int n,m;
char str[N][N];
inline int abs(int x){
	return x>=0?x:-x;
}
void readData(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",str[i]+1);
}
bool use[N];
int match[N];
bool check(){
	static char a[N][N];
	int p=0;
	for(int i=1;i<=n;i++)
		if(use[i]){
			if(i<match[i]){
				p++;
				for(int j=1;j<=m;j++){
					a[p][j]=str[i][j];
					a[n-p+1][j]=str[match[i]][j];
				}
			}
		}
		else{
			for(int j=1;j<=m;j++)
				a[(n+1)>>1][j]=str[i][j];
		}
	static map<ULL,int> sum;
	static ULL f[N],b[N];
	sum.clear();
	for(int j=1;j<=m;j++){
		f[j]=b[j]=0;
		for(int i=1;i<=n;i++)
			f[j]=f[j]*B+(a[i][j]-'a'+1);
		for(int i=n;i>=1;i--)
			b[j]=b[j]*B+(a[i][j]-'a'+1);
		sum[f[j]]++;
	}
	bool useChance=(m&1)?false:true;
	for(int j=1;j<=m;j++)
		if(sum[f[j]]){
			if(f[j]==b[j]){
				int x=sum[f[j]];
				if(x&1){
					if(!useChance)
						useChance=true;
					else
						return false;
				}
				sum[f[j]]=0;
				continue;
			}
			int delta=abs(sum[f[j]]-sum[b[j]]);
			if(delta==1){
				if(!useChance)
					useChance=true;
				else
					return false;
			}
			else if(delta>1)
				return false;
			sum[f[j]]=sum[b[j]]=0;
		}
	return true;
}
bool solve(int x,bool useIdle){
	if(x==n+1)
		return check();
	if(use[x]){
		if(solve(x+1,useIdle))
			return true;
		return false;
	}
	if(!useIdle){
		use[x]=false;
		if(solve(x+1,true))
			return true;
	}
	for(int i=x+1;i<=n;i++)
		if(!use[i]){
			match[x]=i;
			match[i]=x;
			use[x]=use[i]=true;
			if(solve(x+1,useIdle))
				return true;
			use[x]=use[i]=false;
		}
	return false;
}
int main(){
	readData();
	puts(solve(1,(n&1)?false:true)?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
// AtCoderを信じる！！

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int INF = 1 << 27;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    // if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

int64 N, M, X[100000];
queue< pair< int64, int > > p[100000];
int uku = 0;

void del_dfs(int idx, int ptr) {
  while(p[idx].size() && p[idx].front().second <= ptr) {
    int to = p[idx].front().first;
    p[idx].pop();
    ++uku;
    del_dfs(to, ptr);
  }
}

int main() {
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> X[i];

  Edges< int > edges;
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    edges.emplace_back(a, b, c);
  }
  sort(edges.begin(), edges.end(), [](auto a, auto b) {
    return a.cost < b.cost;
  });

  // X[i]とY[i]の連結成分
  UnionFind uf(N);
  vector< int64 > hashed(M);
  for(int i = 0; i < M; i++) {
    auto e = edges[i];
    p[e.src].emplace(e.to, i);
    p[e.to].emplace(e.src, i);

    e.src = uf.find(e.src);
    e.to = uf.find(e.to);
    if(uf.unite(e.src, e.to)) {
      X[e.src] += X[e.to];
    }

    // ここの連結成分をとってくる
    hashed[i] = X[e.src];
  }


  for(int i = M - 1; i >= 0; i--) {
    // それ以下の辺で使用できる連結成分の大きさを計算
    auto &e = edges[i];

    if(hashed[i] >= e.cost) { // 連結可能
      // ここで連結な頂点をすべて連結にする
      del_dfs(e.src, i);
    }
  }

  cout << M - uku / 2 << endl;

}



Measured memory_bytes: 79732
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
 
int main() {
	ll A,B;
	cin >> A >> B;
  ll g = __gcd(A,B);

	int ans = 0;
	for(ll i=2;i*i<=g;i++){
		if(g%i == 0){
			ans++;
			while(g%i==0)g/=i;
		}
	}
	if(g>1) ans++;

	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
def main():

    N, W = map(int, input().split())
    goods = []
    tot_v = 0
    for _ in range(N):
        w, v = map(int, input().split())
        goods.append([w, v])
        tot_v += v
    dp = [[float('inf') for _ in range(tot_v+1)] for _ in range(N+1)]
    dp[0][0] = 0

    max_v = 0
    for i in range(N):
        w, v = goods[i]
        for j in range(tot_v+1):
            if j-v >= 0:
                dp[i+1][j] = min(dp[i][j], dp[i][j-v]+w)
            else:
                dp[i+1][j] = dp[i][j]

            if dp[i+1][j] <= W:
                max_v = max(max_v, j)

    return max_v

if __name__ == '__main__':
    print(main())

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

int getIndex(char s)
{
    switch (s)
    {
        case 'S': return 0;
        case 'H': return 1;
        case 'C': return 2;
        case 'D': return 3;
    }
}

int main()
{
    bool Card[4][14];
    int n, v;
    char s;
    cin >> n;
    for (int i = 0; i != 4; ++i)
    {
        for (int j = 0; j != 14; ++j)
        {
            Card[i][j] = false;
        }
    }
    for (int i = 0; i != n; ++i)
    {
        cin >> s >> v;
        Card[getIndex(s)][v] = true;
    }
    for (int i = 0; i != 4; ++i)
    {
        for (int j = 1; j <= 13; ++j)
        {
            if (!Card[i][j])
            {
                switch (i)
                {
                    case 0: cout << "S " << j << endl; break;
                    case 1: cout << "H " << j << endl; break;
                    case 2: cout << "C " << j << endl; break;
                    case 3: cout << "D " << j << endl; break;
                }
            }
        }
    }
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i=0; i<n; i++){
    cin >>a.at(i);
  }
  long long sum1=a.at(0);
  long long sum2=a.at(0);
  long long op1 = 0;
  long long op2 = 0;
  
  if (sum1<=0){
    sum1=1;
    op1 += -1*a.at(0)+1;
  }
  if (sum2>=0){
    sum2=-1;
    op2 += a.at(0)+1;
  }
  for (int j = 1; j<n; j++){
    if (sum1>0){
      sum1 += a.at(j);
      if (sum1 >= 0){
        op1 += (sum1 + 1);
        sum1 = -1;
      }
    }
    else{
      sum1 +=a.at(j);
      if (sum1<=0){
        op1 += (-1*sum1 + 1) ;
        sum1 =1 ;
      }
    }
    
    if (sum2>0){
      sum2 += a.at(j);
      if (sum2 >= 0){
        op2 += (sum2 + 1);
        sum2 = -1;
      }
    }
    else{
      sum2 +=a.at(j);
      if (sum2<=0){
        op2 += (-1*sum2 + 1) ;
        sum2 =1 ;
      }
    }
  }

  cout << (op1>op2 ? op2:op1) << endl;
}


Measured memory_bytes: 1024
(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1

parent = [-1]*N
depth = [0] * N

def boss(n):
    d = 0
    while parent[n] >= 0:
        n = parent[n]
        d += 1
    return n,d

P = [1]*N
S = (N*(N-1))//2

ans = [0] * M
ans[M-1] = S

#print(A)
#print(B)

for i in range(M-1):
#    print(parent)
    j = M-1-i
    bA, dA = boss(A[j])
    bB, dB = boss(B[j])
#    print(A[j],B[j],bA,bB)
    if bA != bB:
        if depth[bA] < depth[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] = P[bA] + P[bB]
        P[bB] = 0
        depth[bA] = max(depth[bA],depth[bB]+1)
    ans[j-1] = S

for i in range(M):
    print(ans[i])


Measured memory_bytes: 18432
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False for i in range(k+1)]
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=(dp[i-a[j]]^(True))
if dp[k]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 46064
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N; cin >> N;
  vec d(N); rep(i, N) cin >> d[i];

  sort(ALL(d));
  int res = 0;
  int pre = d[0];
  rep(i, N) {
    if(i==0) {res++; continue;}
    if(pre != d[i]) res++;
    pre = d[i];
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	long long d=0;
	string x, y;
	cin >> x >> y;

	for (int i = 0; i <x.size() ; i++) {

		if (x[i] != y[i])
			d++;
	
	}
	
	cout << d;


}

Measured memory_bytes: 3864
for_num = int(input())
nums = input()
nums = nums.split()

count = 0
Tf = True
while Tf:
    count += 1
    for i in range(0,for_num):
        num = int(nums[i])
        if num%2 == 0:
            nums[i] = int(num/2)
            Tf = True
        else:
            Tf = False
            break
print(count-1)

Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;


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

	string s;
	cin >> s;

	string ans = "";
	for (char c : s)
	{
		char a = c + n;
		while (a > 'Z')
		{
			a = 'A' + (a - 'Z' - 1);
		}

		ans += a;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int n,m,v[200005];
int mx=0,cnt=0;
void dfs(int x,int f){
	v[x]=f,cnt++;
	for(int y:g[x])if(!v[y])dfs(y,f);
}
int main() {
	cin>>n>>m;
	for(int i=1,x,y;i<=m;i++)cin>>x>>y,g[x].push_back(y),g[y].push_back(x);
	for(int i=1;i<=n;i++)if(!v[i])cnt=0,dfs(i,i),mx=max(mx,cnt);
	cout<<mx;
	return 0;
}

Measured memory_bytes: 24684
#include <bits/stdc++.h>
//#include<cstdio>
//#include<cstring>
using namespace std;
#define fi first
#define se second
#define pii pair<ll,ll>
#define pll pair<long long ,long long>
#define mp make_pair
typedef long double DB;
typedef long long ll;
const int maxn=3*1e5+15;
const int maxm=10;
const int maxe=20005;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,m;
ll a,b,k;
ll c[maxn];

ll pow_mod(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans;
}

void init(){
    c[0]=1;
    for(int i=1;i<=n;i++){
        c[i]=c[i-1]*(n-i+1)%mod*pow_mod(i,mod-2)%mod;
    }
}

int main(){
    scanf("%d",&n);
    init();
    scanf("%lld%lld%lld",&a,&b,&k);
    ll ans=0;
    for(int i=0;i*a<=k&&i<=n;i++){
        ll lef=k-i*a;
        if(lef%b)continue;
        ll j=lef/b;
        if(j>n)continue;
        ans=(ans+c[j]*c[i]%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;


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

    std::set<int> kagami;
    int N;scanf("%d",&N);
    int tmp;
    for(int i=0;i<N;i++){
        scanf("%d",&tmp);
        kagami.insert(tmp);
    }

    printf("%d\n",kagami.size());

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigDecimal;
 
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
double x=0;
double y=0;
double rad=Math.PI/2;
while(sc.hasNext()){
String[] s=sc.next().split(",");
int dis=Integer.parseInt(s[0]);
x+=dis*Math.cos(rad);
y+=dis*Math.sin(rad);
int deg=Integer.parseInt(s[1]);
rad-=Math.toRadians(deg);
}
BigDecimal a=new BigDecimal(x);
BigDecimal b=new BigDecimal(y);
a=a.setScale(0,BigDecimal.ROUND_DOWN);
b=b.setScale(0,BigDecimal.ROUND_DOWN);
System.out.println(a);
System.out.println(b);
}
}

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

from fractions import gcd

n = int(input())
a = [int(i) for i in readline().split()]


ans = 0
now = 1
for i in a:
    if i == now:
        now += 1
    else:
        ans += 1

if now != 1:
    print(ans)
else:
    print(-1)


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

int main(){
    string s,t;cin>>s>>t;
    bool ok=true;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            ok=false;
        }
    }

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

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

int main(){
	int n;
	cin >> n;
	map<int,int> mp;
	rep(i,n){
		int a;
		cin >> a;
		mp[a]++;
	}
	int ans = 0;
	for(auto m: mp){
		if(m.second % 2 == 1) ans++;
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4864
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let lr: Vec<(i64, i64)> = (0..n).map(|_| (sc.read(), sc.read())).collect::<Vec<_>>();
    let inv = lr.iter().map(|&(l, r)| (-r, -l)).collect();

    let ans1 = solve(lr);
    let ans2 = solve(inv);
    println!("{}", cmp::max(ans1, ans2));
}

fn solve(lr: Vec<(i64, i64)>) -> i64 {
    let n = lr.len();
    let mut left = vec![];
    let mut right = vec![];
    for (i, &(l, r)) in lr.iter().enumerate() {
        left.push((l, i));
        right.push((r, i));
    }
    left.sort();
    right.sort();

    let mut cur = 0;
    let mut ans = 0;
    let mut left = left.into_iter().rev().peekable();
    let mut right = right.into_iter().peekable();
    let mut used = vec![false; n];
    while left.peek().is_some() || right.peek().is_some() {
        while let Some((_, i)) = left.next() {
            if used[i] {
                continue;
            }
            let (l, r) = lr[i];
            if cur < l {
                ans += l - cur;
                cur = l;
            } else if r < cur {
                ans += cur - r;
                cur = r;
            }
            used[i] = true;
            break;
        }
        while let Some((_, i)) = right.next() {
            if used[i] {
                continue;
            }
            let (l, r) = lr[i];
            if cur < l {
                ans += l - cur;
                cur = l;
            } else if r < cur {
                ans += cur - r;
                cur = r;
            }
            used[i] = true;
            break;
        }
    }
    ans + cur.abs()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
#include <string>
 
using namespace std;
using namespace std::chrono; 
 
 
 
//c++ templte for help...........................................................
 
//#define deb(x) cout<<#x<<" "<<x<<endl;/* for debuging  printing variable with name*/
//#define debb(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;										
//#define debbb(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;			
 
//typedef long long ll;
//typedef unsigned long long ull;
	
 
//for loop
//#define fo(i,n) for(int i=0;i<(ll)n;i++)
//#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
//template<typename T>
//void printV(T vec){
	//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//cout<<endl;
	//}
	
 
//#define modulo 1000000007
//const int INF=1e9+5;
 
//iterate map
//template<typename T>
//void itR(T map){
	 //for(auto itr=map.begin();itr!=map.end();itr++){
				//debb(itr->first,itr->second)
			//}
	//cout<<endl;
//}
 
 
 
//c++ template for help........................................................

int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	cout<<setprecision(50);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	 // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO 
	 // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
	 // greedy ma jadatr exceptional case check kr ke dekh lo
	 
	 // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND KRO
	 // DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT 
	 // DP BHI WO LEETCODE WALE MATRIX KA QUESTION KI TARAH HA
	 // CONSTRAIN WILL BE THE DIMENSION OF DP
	 // DP MA STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO
	 // OBJECT KO CHOOSE KIA YA NAE KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA
	 // KYA KYA CHEJ IMPORTANT HA WO STATE BN JYAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2 WALE PROBLEM MA KIA THA
	 

	 
	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		string s,t;
		cin>>s>>t;
		
		t.pop_back();
		if(s==t) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		






	//}
	
	return 0;
}


Measured memory_bytes: 3600
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のLを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L


N = int(input())
S_raw = list(map(int, input().split()))

S_raw.sort()
k = 1
S = [1]
for i in range(1, len(S_raw)):
    if S_raw[i] != S_raw[i-1]:
        k += 1
    S.append(k)

bit = Bit(S[-1] + 1)
for s in S:
    bit.add(s, 1)
slimes = [S[-1]]
for t in range(N):
    slimes_new = []
    for sl in slimes:
        sl_new = bit.bisect_minus(sl, 1)
        if sl_new == 0:
            print('No')
            exit()
        slimes_new.append(sl_new)
        bit.add(sl_new, -1)
    slimes.extend(slimes_new)

print('Yes')


Measured memory_bytes: 119280
#include <bits/stdc++.h>
//#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  bool allA = true;
  bool allB = true;
  for (int i=0; i < 3; i++) {
    if (S[i] == 'B')
      allA = false;
    if (S[i] == 'A')
      allB = false;
  }
  if (allA || allB) {
	cout << "No";
  }
  else 	cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#A1 ~ Aiまでの和 O(logN)
def BIT_query(BIT,idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(BIT,idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return


alps = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())
s = list(input())
char_hd_d = {}
for alp in alps:
    char_hd_d[alp] = [0]*(n+1)

for i, si in enumerate(s):
    BIT_update(char_hd_d[si], i+1, 1)

q = int(input())
ansl = []
for _ in range(q):
    command, a, b = input().split()
    if command == '1':
        i = int(a)
        c = b
        i_char = s[i-1]
        BIT_update(char_hd_d[i_char], i, -1)
        BIT_update(char_hd_d[c], i, 1)
        s[i-1] = c 
    else:
        l,r = int(a),int(b)
        cnt = 0
        for alp in alps:
            if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
                cnt += 1
        ansl.append(cnt)

for a in ansl:
    print(a)            

Measured memory_bytes: 207396
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    string S;
    cin >> S;
    set<char> chars;
    for (const char ch : S)
    {
        if (chars.find(ch) != chars.end())
        {
            cout << "no" << endl;
            return 0;
        }
        chars.insert(ch);
    }
    cout << "yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
bool a[50][100];
bool b[50][100];
int main(){
    int A,B;
    cin >> A >> B;
    A--,B--;
    rep(i,50){
        rep(j,49){
            if(A==0)break;
            if(i%2){
                a[i][j*2+1] = true;
                A--;
                if(A==0)break;
            }
        }
        if(A==0)break;
    }
    rep(i,50){
        rep(j,49){
            if(B==0)break;
            if(i%2){
                b[i][j*2+1] = true;
                B--;
                if(B==0)break;
            }
        }
        if(B==0)break;
    }
    cout << "100 100\n";
    rep(i,50){
        rep(j,100){
            if(a[i][j]){
                cout << '.';
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
    rep(i,50){
        rep(j,100){
            if(!b[i][j]){
                cout << '.';
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
}

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

using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>Ans(N + 1);
	for (int m = 1;m<=sqrt(N) ;++m) {
		for (int i = 1; i <= sqrt(N); ++i) {
			for (int j = 1; j <= sqrt(N); ++j) {
				int num = m * m + i * i + j * j + i * j+i * m + j * m;
				if (num <= N ) {
					Ans[num]++;
				}
			}
		}
	}
	for (int n = 1;n<=N;++n) {
		cout << Ans[n]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3596