akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<vector<vector<mint>>> dp(n + 1, vector<vector<mint>>(n + 1, vector<mint>(k + 1, 0)));
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int l = 0; l <= k; ++l) {
                if (l >= 2 * j) {
                    if (j != 0)
                        dp[i][j][l] += dp[i - 1][j - 1][l - 2 * j];
                    dp[i][j][l] += mint(1 + 2 * j) * dp[i - 1][j][l - 2 * j];
                    if (j != n)
                        dp[i][j][l] += mint(j + 1).pow(2) * dp[i - 1][j + 1][l - 2 * j];
                }
            }
        }
    }
    cout << dp[n][0][k] << "\n";
    return 0;
}


Measured memory_bytes: 104064
def main():
    n = int(input())
    a = list(map(int,input().split()))
    d= {}
    for i in range(n):
        if d.get(a[i])==None:
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    s = sum(a)
    q = int(input())
    for i in range(q):
        b,c = map(int,input().split())
        if d.get(b)==None:
            print(s)
        else:
            s += (c-b)*d[b]
            if d.get(c)==None:
                d[c] = d[b]
            else:
                d[c] += d[b]
            d[b] = 0
            print(s)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20680
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N,C;
vector <pair<int,pair<int,int> > > T;





int main()
{

	cin >> N >> C;

	T.resize(N);

	REP(i,N){
		cin >> T[i].second.first;
		cin >> T[i].second.second;
		cin >> T[i].first;
	}

	sort(T.begin(),T.end());

	vector <vector <bool> >ch;
	ch.resize(30);
	REP(i,30){
		ch[i].resize(100001);
		REP(j,100001){
			ch[i][j] = false;
		}
	}
	REP(i,N){
		FOR(j,T[i].second.first,T[i].second.second+1){
			ch[T[i].first-1][j] = true;
		}
	}
	int ans0 = 0;
	REP(i,100001){
		int ans = 0;
		REP(j,30){
			ans += ch[j][i];
		}
		ans0 = max(ans,ans0);
	}
	cout << ans0;
/*	REP(i,2){
		REP(j,20)
			cout << ch[i][j];
		cout << endl;
	}
	*/

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string a, b, c;
  cin >> a >> b >> c;
  bool ok = true;
  if(*a.rbegin() != *b.begin()) ok = false;
  if(*b.rbegin() != *c.begin()) ok = false;


  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

double distance(int xs,int ys,int xg,int yg){
    int ss=(xs-xg)*(xs-xg)+(ys-yg)*(ys-yg);
    return pow(ss,1/2);
}
int main(){
    int n; cin>>n;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    ll ans=0;
    bool flag=true;
    if(n%2==0){
        vector<int> B(n,0);
        rep(i,0,n){
            B[(A[i]-1)/2]++;
        }
        rep(i,0,n/2){
            if(B[i]!=2) flag=false;
        }
        rep(i,n/2,n){
            if(B[i]!=0) flag=false;
        }
        if(flag){
            ans=1;
            rep(i,0,n/2){
                ans*=2;
                ans%=1000000007;
            }
        } 
    }else{
        vector<int> C(n,0);
        rep(i,0,n){
            C[A[i]/2]++;
        }
        rep(i,0,(n+1)/2){
            if(i==0&&C[i]!=1) flag=false;
            else if(i!=0&&C[i]!=2) flag=false;
        }
        rep(i,(n+1)/2,n){
            if(C[i]!=0) flag=false;
        }
        if(flag){
            ans+=1;
            rep(i,0,n/2){
                ans*=2;
                ans%=1000000007;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
/* ABC138-B
   Takatan */

#include<stdio.h>
int main(void){
    int number, i;
    double answer, a;
    answer = 0;

    scanf( "%d" , &number);
    for(i=0; i < number; i++){
        scanf( "%lf" , &a);
        answer += 1 / a; /* 逆数にして加算 */
    }
    answer = 1 / answer; /* 逆数の総和の逆数をとる */
    printf( "%f\n" , answer);
    return 0;
}

Measured memory_bytes: 128
s = input()
t = input()
from collections import defaultdict
from bisect import bisect_left
d = defaultdict(list)
for i, e in enumerate(s):
  d[e].append(i)

for e in t:
  if e not in d:
    print(-1)
    exit()
cur = -1
loop = 0
for e in t:
  idxt = bisect_left(d[e], cur-loop*len(s)+1)
  #print(d[e], idxt)
  if len(d[e])>idxt:
    #print(11, idxt, d[e][idxt])
    idx = d[e][idxt]
    cur = (loop*len(s))+idx
    #print(12, idx)
  else:
    loop += 1
    idxt = bisect_left(d[e], cur-loop*len(s)+1)
    #print(d[e], idxt)
    idx = d[e][idxt]
    cur = (loop*len(s))+idx
  #(idx, loop)
print(cur+1)


Measured memory_bytes: 46172
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
#include <list>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;

int main(){

    int N;
    cin >> N;
    int vvv;

    rep(n,1,N+1){
        int now = 0;
        rep(x,1,101){
            rep(y,1,101){
                rep(z,1,101){
                    vvv = x*x + y*y + z*z + x*y + y*z + z*x;
                    if (vvv == n){
                        now++;
                    }else if (vvv > n){
                        break;
                    }
                }

                if (x*x+y*y+1+x*y+x+y > n){
                    break;
                }
            }

            if (x*x + 1 + 1 + x + 1 + 1 > n) break;
        }

        printf ("%d\n",now);
    }
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

int main()
{
    IOS;
    ll n;
    cin>>n;
    cout<<fixed;
    cout<<setprecision(10)<<((ld)ceil((ld)n/2)/n)<<endl;
    return 0;  
}

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

 
int main() {
    string a,b;
    cin>>a>>b;
    
    //atoiはcharのときとか色々面倒→sringにはsutoiが楽
    int c=stoi(a+b);

    for(int i=0;i*i<=c;i++){
        if(i*i==c){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

}

Measured memory_bytes: 256
#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 N;
	cin >> N;
  vector<string> s(N);
  rep(i,N){
    cin >> s[i];
    sort(all(s[i]));
  }
  sort(all(s));

  ll ans = 0;
  ll c = 0;

  rep(i,N){
    if(i==0) continue;
    if(s[i] == s[i-1]){
      c += 1;
      ans += c;
    } else {
      c = 0;
    }
  }
  cout << ans << endl;
}

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

#define     __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define dbg cout << "dbg\n"
#define nll cout << "\n"
#define ll long long
#define MAX 100002
#define log_size 18
#define MOD 1000000007
#define INF 10000000000
#define ii pair<ll,ll>
#define presion cout << fixed << setprecision(6)



int main(){
	int n;
	cin >> n;
	ll arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];
	int cnt = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			for(int k = j+1; k < n; k++){
				ll a = arr[i], b = arr[j], c = arr[k];
				if(a+b > c && a+c > b && b+c > a && a != b && a != c && b != c){
					///cout << i << " " << j << " " << k << "\n";
					cnt++;
				}
			}
		}
	}
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    string s; cin >> s;
    //reverse(s.begin(),s.end());
    long long dp[100010][14] = {0};
    long long n = s.size();
    dp[0][0] = 1;

    for(long long i = 1; i <= n; i++){
        for(long long j = 0; j < 13; j++){
            if (s[i-1] == '?'){
                for(long long k = 0; k < 10; k++){
                    dp[i][(10*j+k)%13] += dp[i-1][j];
                    dp[i][(10*j+k)%13] %= MOD;
                }
            } else {
                long long k = s[i-1]-'0';
                dp[i][(10*j+k)%13] += dp[i-1][j];
                dp[i][(10*j+k)%13] %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;

}
  



Measured memory_bytes: 11456
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

bool solve(const vector<int>& as, int k, int m) {
    if (m == 0) {
        return true;
    }
    if (m < 0 || k == as.size()) {
        return false;
    }
    return solve(as, k + 1, m - as[k]) || solve(as, k + 1, m);
}

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as) {
        cin >> a;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int m;
        cin >> m;
        if (solve(as, 0, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}

Measured memory_bytes: 1184
#include<stdio.h>
#include<algorithm>
using namespace std;
struct shu
{
    int ax;
    int ay;
};
struct shu sh[105];
bool cmp(shu a,shu b)
{
    if(a.ax!=b.ax)
        return a.ax>b.ax;
    return a.ay>b.ay;
}
struct shu1
{
    int bx;
    int by;
} sh1[105];
bool cmp1(shu1 a,shu1 b)
{
    if(a.bx!=b.bx)
        return a.bx>b.bx;
    return a.by>b.by;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d %d",&sh[i].ax,&sh[i].ay);
    sort(sh,sh+n,cmp);
    for(int i=0; i<n; i++)
        scanf("%d %d",&sh1[i].bx,&sh1[i].by);
    sort(sh1,sh1+n,cmp1);
    int x,y,sum=0,x1=1000000,y1=1000000,flag=0,w;
    for(int i=0; i<n; i++)
    {
        x=sh[i].ax,y=sh[i].ay;
        x1=1000000,y1=1000000;
        flag=0;
        for(int j=0; j<n; j++)
        {
            if(sh1[j].bx>x&&sh1[j].by>y&&sh1[j].by<y1&&sh1[j].bx<x1)
            {
                x1=sh1[j].bx;
                y1=sh1[j].by;
                w=j;
                flag=1;
            }
        }
        if(flag==1)
        {
           // printf("%d %d\n",sh1[w].bx,sh1[w].by);
            sh1[w].bx=-1;
            sh1[w].by=-1;
            sum++;
        }
    }
    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

    vector<int> W(N);
    int tot = 0;

    for(int i = 0; i < N; i++){
        cin >> W[i];
        tot += W[i];
    }

    vector<int> S(N);
    S[0] = W[0];
    int dif = abs(tot - 2*S[0]);

    for(int i = 1; i < N; i++){
        S[i] = S[i-1] + W[i];
        if(dif > abs(tot - 2*S[i])) dif = abs(tot - 2*S[i]);
    }

    cout << dif << endl;

    return 0;
}

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

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<int> even, odd;
		for(int i=0;i<M;i++){
			int t;
			cin >> t;
			if(t%2 == 0) even.push_back(t);
			else odd.push_back(t);
		}
		if(odd.size() > 2){
			cout << "Impossible" << endl;
			continue;
		}
		vector<int> A;
		if(odd.size() >= 1) A.push_back(odd[0]);
		for(int i=0;i<even.size();i++) A.push_back(even[i]);
		if(odd.size() == 2) A.push_back(odd[1]);
		vector<int> B;
		if(A.size() == 1){
			B.push_back(1);
			if(A[0] >= 2) B.push_back(A[0]-1);
		} else {
			if(A[0] >= 2) B.push_back(A[0]-1);
			for(int i=1;i<A.size()-1;i++){
				B.push_back(A[i]);
			}
			B.push_back(A.back()+1);
		}
		cout << A[0];
		for(int i=1;i<A.size();++i) cout << " " << A[i];
		cout << endl;
		cout << B.size() << endl;
		cout << B[0];
		for(int i=1;i<B.size();++i) cout << " " << B[i];
		cout << endl;
	}
}


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


int main() {
    int N, K; cin >> N >> K;
    vector<int> V(N);
    vector<int> W(N);
    for(int i=0; i<N; i++)
        cin >> V[i] >> W[i];

    vector<vector<int>> DP(N+1, vector<int>(K+1));
    
    for(int i=0; i<N; i++){
        for(int j=0; j<K+1; j++){
            if(j >= W[i]) DP[i+1][j] = max(DP[i][j], DP[i][j-W[i]] + V[i]);
            else DP[i+1][j] = DP[i][j];
        }
    }

    cout << DP[N][K] << endl;
    return 0;
}



Measured memory_bytes: 6836
import math
from functools import reduce

def lcm_base(x,y):
	return (x*y)//math.gcd(x,y)

def lcm_list(numbers):
	return reduce(lcm_base, numbers, 1)

n=int(input())
a=list(map(int,input().split()))
b=0
c=lcm_list(a)-1

for A in a:
	b+=c%A

print(b)

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

int main()
{
  int n;
  string s;
  cin >> n >> s ;
  vector<char> data = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                      'I', 'J', 'K', 'L','M', 'N','O','P','Q','R','S','T',
                      'U', 'V','W','X','Y','Z'};

  vector<int> answer ;
  
  for(int i = 0 ; i < s.size() ; i++)
  {
    for(int j = 0; j < 26; j++)
    {
      if(s.at(i) == data.at(j))
      {
        int z = j + n + 1 ;
        if(z > 26)
        {  
          z -= 26;  
        }
        answer.push_back(z) ;
      }
    }
  }

  for(int i = 0 ; i <= s.size() ; i++)
  {
    if(i == s.size())
    {
      cout << endl;
      return 0 ;
    }
    cout << data.at(answer.at(i) - 1) ;
  }

}


Measured memory_bytes: 384
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let num: usize = buf.trim().parse().unwrap();
    let mut buf2 = String::new();
    stdin.read_line(&mut buf2).ok();

    if (num == 1) {
      println!("Yes");
    }
    else {
        let mut previous:usize = 0;
        let mut result = "Yes";
        for (i, num_s) in buf2.split_whitespace().enumerate() {
            let num = usize::from_str(num_s).unwrap();
            
            if (i == 0) {
                previous = num;

                continue;
            }
            else {
                if (previous > num) {
                    result = "No";
                    break;
                }
                else {
                    if (previous == num) {
                        previous = num;
                        continue;
                    }

                    if (previous <= (num - 1)) {
                        previous = num - 1;
                        continue;
                    }

                    result = "No";
                    break;
                }
            }
        }

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

Measured memory_bytes: 6396
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int n=calc(String.valueOf(x).length());
    int[] a=new int[n];
    a[0]=3;a[1]=5;a[2]=7;
    int ins=3;
    for(int i=0;i<n;i++){
      if(ins>=n){
        break;
      }else{
        a[ins  ]=a[i]*10+3;
        a[ins+1]=a[i]*10+5;
        a[ins+2]=a[i]*10+7;
        ins+=3;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++){
      if(check(a[i],x)){
//        System.out.println(a[i]);
        ans++;
      }
    }
    System.out.println(ans);
  }
  static int calc(int digit){
    int pow=1;
    int res=0;
    for(int i=1;i<=digit;i++){
      pow*=3;
      res+=pow;
    }
    return res;
  }
  static boolean check(int a,int x){
    if(a>x){
      return false;
    }else{
      boolean t=false;
      boolean f=false;
      boolean s=false;
      while(a>0){
        if(a%10==3){
          t=true;
        }else if(a%10==5){
          f=true;
        }else if(a%10==7){
          s=true;
        }else{
          System.err.println("!!!");
        }
        a/=10;
      }
      return t&&f&&s;
    }
  }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
 
double dist(int x1, int y1, int x2, int y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * ( y1 - y2));
}
int main() {
    int n;
    cin >> n; 
    vector<int> x(n);
    vector<int> y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    double res = 0.0;
    for (int i = 0; i < n; i++) {
        for ( int j = i + 1; j < n; ++j) {
            res += dist(x[i], y[i], x[j], y[j]);
        }
    }
    printf("%.10lf\n", res * 2 / n);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;
 
template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
 
ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}
 
int main(){
  ll A,B;
  cin>>A>>B;
  ll C=gcd(A,B);
  ll ans=1;
  for(ll i=2;i*i<=C;i++){
    if(C%i==0){
      ans++;
      while(C%i==0){C/=i;}
    }
  }
  if(C!=1){ans++;}
  cout<<ans<<endl;
  
  return 0;
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N; cin >> N;
    int p[N];
    int cnt = 0;
    rep(i, N) cin >> p[i];
    rep(i, N-1){
        if(p[i] == i+1 && p[i+1] == i+2){
            swap(p[i], p[i+1]);
            cnt++;
        }
    }
    rep(i, N){
        if(p[i] == i+1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <ios>
#include <vector>
using namespace std;
int main(void){
  string s;
  cin >> s;

  int n = s.length();

  vector<int>judge(3,0);

  if(s[0] == 'A'){
    judge[0]++;
    s[0] = 'a';
  }

  for(int i=2;i<n - 1;i++){
    if(s[i] == 'C'){
      judge[1]++;
      s[i] = 'c';
    }
  }

  bool small = true;
  for(int i=0;i<n;i++){
    if(s[i] >= 'A' && s[i] <= 'Z')
      small = false;
  }

  if(small){
    judge[2]++;
  }

  /*for(int i=0;i<3;i++){
    cout << judge[i] << endl;
  }*/

  if(judge[0] * judge[1] * judge[2] == 1)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a+b<=c&&4*a*b<(c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

#define ALL(c)         (c).begin(), (c).end()

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

	int N, K;
	cin >> N >> K;

	vector<int> l(N);
	for (auto& v : l) cin >> v;

	sort(ALL(l), greater<int>());
	l.resize(K);
	auto sum = accumulate(ALL(l), 0LL);

	cout << sum << endl;
}

Measured memory_bytes: 256
# 選ぶ数で場合わけすれば良い

N, K = map(int, input().split())
A = list(range(N+1))
M = 10 ** 9 + 7

mini = sum(A[0:K])
most = sum(A[-K:])
# first_count = most -mini + 1
count = most - mini + 1

for i in range(K, N+1):
    most +=  A[-(i+1)]
    mini += A[i]
    count += (most- mini + 1)

print(count % M)

Measured memory_bytes: 67612
import queue
import sys
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
XYZ = []
for _ in range(M):
    XYZ.append(tuple(map(int, input().split())))

G=[[] for _ in range(N+1)]
for el in XYZ:
    G[el[0]].append(el[1])
    G[el[1]].append(el[0])
#print(G)

seen=[False]*(N+1)
todo=queue.Queue()
def bfs(n):
    seen[n]=True
    for nxt in G[n]:
        if seen[nxt]==False:
            bfs(nxt)


cnt=0
for check in range(1, N+1):
    if seen[check]==False:
        cnt+=1
        bfs(check)
print(cnt)


Measured memory_bytes: 113436
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

int modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 


int main() {
	int n;
	cin>>n;
	ll a[n+1];
	ll t=0,s=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
		if(i>1&&i%2==0)
			t+=a[i];
	}
	s=s-(2*t);	
	ll ans[n+1];
	ans[1]=s;
	//cout<<s<<endl;
	for(int i=1;i<n;i++)
	{
		ans[i+1]=2*a[i]-ans[i];

	}
	for(int i=0;i<n;i++)
		cout<<ans[i+1]<<" ";


}


Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
#include <functional>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <set>
#include <queue>
#include <map>
using namespace std;
int main(){
	long long w,h;
	cin>>w>>h;
	long long p[w],q[h];
	deque<long long> pp;
	deque<long long> qq;
	cin>>p[0];
	for(int i=1;i<w;i++){
		cin>>p[i];
		pp.push_back(p[i]);
	}
	cin>>q[0];
	for(int i=1;i<h;i++){
		cin>>q[i];
		qq.push_back(q[i]);
	}
	sort(pp.begin(),pp.end());
	sort(qq.begin(),qq.end());
	long long c=0;
	c=c+p[0]+q[0]+min(p[0],q[0]);
	for(int x=1;x<w;x++){
		c=c+p[x]+min(p[x],q[0]);
	}
	for(int y=1;y<h;y++){
		c=c+q[y]+min(p[0],q[y]);
	}
	long long qc=0;
	for(int x=0;x<w-1;x++){
		st:;
		if(qq[qc]<=pp[x]){
			c=c+(w-x-1)*qq[qc];
			if(qc<h-1){
				qc++;
				goto st;
			}
		}
	}
	long long pc=0;
	for(int y=0;y<h-1;y++){
		st2:;
		if(pp[pc]<qq[y]){
			c=c+(h-y-1)*pp[pc];
			if(pc<w-1){
				pc++;
				goto st2;
			}
		}
	}
	/*for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			if(x>0&&y>0){
				c=c+min(p[x],q[y]);
			}
			else if(x==0&&y>0){
				c=c+q[y]+min(p[x],q[y]);
			}
			else if(x>0&&y==0){
				c=c+p[x]+min(p[x],q[y]);
			}
			else{
				c=c+p[x]+q[y]+min(p[x],q[y]);
			}
		}
	}*/
	cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array = new int[n];

		for(int i=0; i<n; i++) {
			array[i]=sc.nextInt();
		}
		for(int j=0; j<(n-1); j++) {
			System.out.print(array[n-1-j] + " ");
		}
		System.out.println(array[0]);
	}
}


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

int main() {
    string s;
    cin >> s;
    string ans = "Yes";
    if (s == "AAA" || s == "BBB") ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int cnt=1;
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            cnt++;
    }
    cout<<cnt<<'\n';

}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int INF = 1e9;
P inf = P(INF,INF);
P a,b,c;

bool check(P a,P b){
  if(a==inf || b==inf)return false;
  int dx=abs(a.first-b.first);
  int dy=abs(a.second-b.second);
  if(dx==0||dy==0||dx==dy)return true;
  else return false;
}

P calc(int a1,int b1,int c1,int a2,int b2,int c2){
  if(a1==0){
    swap(a1,a2);swap(b1,b2);swap(c1,c2);
  }
  c1*=a1;b1*=a1;a1*=a1;
  c2-=c1*a2;
  b2-=b1*a2;
  a2-=a1*a2;
  int X=c2/b2;
  if(c2%b2!=0){
    return inf;
  }
  int Y=(c1-b1*X)/a1;

  if((c1-b1*X)%a1!=0){
    return inf;
  }

  return P(X,Y);
}

bool excheck(){
  P p;

  p=calc(1,0,b.second,  0,1,a.first);
  if(check(c,p))return true;

  p=calc(1,0,b.second,  1,-1,a.second-a.first);
  if(check(c,p))return true;

  p=calc(1,0,b.second,  1,1,a.second+a.first);
  if(check(c,p))return true;


  p=calc(0,1,b.first,  1,0,a.second);
  if(check(c,p))return true;

  p=calc(0,1,b.first,  1,-1,a.second-a.first);
  if(check(c,p))return true;

  p=calc(0,1,b.first,  1,1,a.second+a.first);
  if(check(c,p))return true;
  

  p=calc(1,-1,b.second-b.first,  1,0,a.second);
  if(check(c,p))return true;

  p=calc(1,-1,b.second-b.first,  0,1,a.first);
  if(check(c,p))return true;

  p=calc(1,-1,b.second-b.first,  1,1,a.second+a.first);
  if(check(c,p))return true;


  p=calc(1,1,b.second+b.first,  1,0,a.second);
  if(check(c,p))return true;

  p=calc(1,1,b.second+b.first,  0,1,a.first);
  if(check(c,p))return true;

  p=calc(1,1,b.second+b.first,  1,-1,a.second-a.first);
  if(check(c,p))return true;


  return false;
}

int solve(){
  if(a==c||b==c)return 0;
  if(check(a,c)&&check(b,c))return 1;
  if(check(a,c)||check(b,c)){
    if(check(a,b) || excheck())return 2;
    else return 3;
  }
  if(check(a,b) || excheck())return 3;
  return 4;

}

int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    cin>>a.first>>a.second;
    cin>>b.first>>b.second;
    cin>>c.first>>c.second;
    cout<<solve()<<endl;
    
    
  }
  return 0;
}

Measured memory_bytes: 1164
numbers = list(input())

for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            s = numbers[0]+op1+numbers[1]+op2+numbers[2]+op3+numbers[3]
            if eval(s) == 7:
                print('{}=7'.format(s))
                exit()

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#include <numeric>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

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

    string str1, str2;
    cin >> str1 >> str2;
    vector<vector<int>> opt_each_str_length(str1.size()+1, vector<int>(str2.size()+1, 0));
    vector<vector<int>> trace_back(opt_each_str_length.size(), vector<int>(opt_each_str_length[0].size(), 9));

    for(int i=1; i<(int)opt_each_str_length.size(); i++){
        for(int j=1; j<(int)opt_each_str_length[i].size(); j++){
            int skew = opt_each_str_length[i-1][j-1];
            if(str1.at(i-1) == str2.at(j-1)) skew++;
            opt_each_str_length[i][j] = max(skew, max(opt_each_str_length[i-1][j], opt_each_str_length[i][j-1]));
            if(opt_each_str_length[i][j] == opt_each_str_length[i-1][j]) trace_back[i][j] = 0;
            else if(opt_each_str_length[i][j] == opt_each_str_length[i][j-1]) trace_back[i][j] = 1;
            else trace_back[i][j] = 2;
        }
    }

    /*
    COUT(opt_each_str_length.back().back());
    cout << "    ";
    for(int i=0; i<(int)str2.size(); i++){
        cout << str2.at(i) << ' ';
    }
    cout << endl;
    for(int i=0; i<(int)opt_each_str_length.size(); i++){
        if(i==0)cout << "  ";
        else cout << str1.at(i-1) << ' ';
        DUMPL(opt_each_str_length[i]);
    }

    cout << "root" << endl;
    cout << "    ";
    for(int i=0; i<(int)str2.size(); i++){
        cout << str2.at(i) << ' ';
    }
    cout << endl;
    for(int i=0; i<(int)trace_back.size(); i++){
        if(i==0)cout << "  ";
        else cout << str1.at(i-1) << ' ';
        DUMPL(trace_back[i]);
    }
    */

    string ans = ""s;
    int str1_count=str1.size(), str2_count=str2.size();
    while(str1_count > 0 && str2_count > 0){
        switch(trace_back[str1_count][str2_count]){
        case 0: 
            str1_count--; break;
        case 1: 
            str2_count--; break;
        case 2: 
            str1_count--;
            str2_count--;
            ans.push_back(str1.at(str1_count));
            break;
        default:
            cout << "バグりました"s << endl;
            break;
        }
    }

    for(auto it=ans.rbegin(); it!=ans.rend(); it++){
        cout << *it;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 70912
N, L = map(int, input().split())
total=0
if L>=0:
    for i in range(N-1):
        L += 1
        total += L

elif N>abs(L):
    for i in range(N):
        total += L
        L += 1

else:
    for i in range(N-1):
        total += L
        L += 1
print(total)

Measured memory_bytes: 3060
N=int(input())
alist=[0]+list(map(int,input().split()))
xlist=list(range(1,N+1))
#print(alist,xlist)

# Ford-Fulkerson algorithm
class FordFulkerson:
  def __init__(self, N):
    self.N = N
    self.G = [[] for i in range(N)]

  def add_edge(self, fr, to, cap):
    forward = [to, cap, None]
    forward[2] = backward = [fr, 0, forward]
    self.G[fr].append(forward)
    self.G[to].append(backward)

  def add_multi_edge(self, v1, v2, cap1, cap2):
    edge1 = [v2, cap1, None]
    edge1[2] = edge2 = [v1, cap2, edge1]
    self.G[v1].append(edge1)
    self.G[v2].append(edge2)

  def dfs(self, v, t, f):
    if v == t:
      return f
    used = self.used
    used[v] = 1
    for e in self.G[v]:
      w, cap, rev = e
      if cap and not used[w]:
        d = self.dfs(w, t, min(f, cap))
        if d:
          e[1] -= d
          rev[1] += d
          return d
    return 0

  def flow(self, s, t):
    flow = 0
    f = INF = 10**9 + 7
    N = self.N 
    while f:
      self.used = [0]*N
      f = self.dfs(s, t, INF)
      flow += f
    return flow

asum_pos=0  
## 点数N、辺数M、始点s、終点t
ff = FordFulkerson(N+2)
for i in range(1,N+1):
  a=alist[i]
  if a<=0:
    ff.add_edge(0,i,-a)
  else:
    ff.add_edge(i,N+1,a)
    asum_pos+=a

for i in range(1,N+1):
  for j in range(2*i,N+1,i):
    ff.add_edge(i,j,float("inf"))

penalty=ff.flow(0,N+1)
print(asum_pos-penalty)

Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            int n = ReadAndParseInt();
            var charTotalArr = new Dictionary<char, long>();
            for(int i=0;i<n;++i)
            {
                string sz  = Console.ReadLine();
                char c = sz[0];
                if( charTotalArr.ContainsKey(c))
                {
                    charTotalArr[c]++;

                }
                else
                {
                    charTotalArr[c] = 1;
                }
            }
            

            string[] compArr =
            {
                "MAR","MAC","MAH","MRC","MRH","MCH","ARC","ARH","RCH","ACH"
            };
            long total = 0;
            foreach(var seach in compArr)
            {
                if (!charTotalArr.ContainsKey(seach[0])) { continue; }
                if (!charTotalArr.ContainsKey(seach[1])) { continue; }
                if (!charTotalArr.ContainsKey(seach[2])) { continue; }
                total += charTotalArr[seach[0]] * charTotalArr[seach[1]] * charTotalArr[seach[2]];
            }
            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 15316
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);

  // solve
  int max_both = min(a, b), min_both = a + b - min(a + b, n);
  printf("%d %d\n", max_both, min_both);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a,b;
    cin>>a>>b;
    if(a=='H'&&b=='H')
    {
        cout<<"H";
    }
    else if(a=='D'&&b=='D')
    {
        cout<<"H";
    }
    else
        cout<<"D";
    

    return 0;
}


Measured memory_bytes: 256
//メモリ数確認したか?
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<math.h>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;

int main()
{
    int n,m;
	int a[1000],b;
	int c[1000];
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		c[i]=0;
	}
	for(int i=0;i<m;i++){
		scanf("%d",&b);
		for(int j=0;j<n;j++){
			if(a[j]<=b){
				c[j]++;
				break;
			}
		}
	}
	int ans,max=-1;
	for(int i=0;i<n;i++){
		if(max<c[i]){
			ans=i;
			max=c[i];
		}
	}
	printf("%d\n",ans+1);
    return 0;
}
//メモリ数確認したか?

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX_N=1e5;

struct Edge{
    int cost,to;
    Edge(int cost,int to):cost(cost),to(to){}
    bool operator<(const Edge& a) const{
        return cost >a.cost;
    }
};
using Graph=vector<Edge>;
Graph G[MAX_N];
int N;
bool used[MAX_N];
int res=0;

int prim(){
    REP(i,N)used[i]=false;
    used[0]=true;
    priority_queue<Edge>q;
    for(auto v:G[0]){
        q.push(v);
    }
    while(q.size()){
        Edge d=q.top();q.pop();
        if(used[d.to])continue;
        res+=d.cost;
      	used[d.to]=true;
        for(auto v:G[d.to]){
            if(!used[v.to])q.push(v);
        }
    }
    return res;
}

signed main(){
    cin>>N;
    vector<pair<int,int>>xdist(N);
    vector<pair<int,int>>ydist(N);
    REP(i,N){
        int x,y;cin>>x>>y;
        xdist[i]=mp(x,i);
        ydist[i]=mp(y,i);
    }
    sort(xdist.rbegin(),xdist.rend());
    sort(ydist.rbegin(),ydist.rend());
    REP(i,N-1){
        int m=xdist[i].second;
        int n=xdist[i+1].second;
        int cost=xdist[i].first-xdist[i+1].first;
        Edge e={cost,n};
        G[m].eb(e);
        e={cost,m};
        G[n].eb(e);
        m=ydist[i].second;
        n=ydist[i+1].second;
        cost=ydist[i].first-ydist[i+1].first;
        e={cost,n};
        G[m].eb(e);
        e={cost,m};
        G[n].eb(e);
    }
    cout<<prim()<<endl;
}

Measured memory_bytes: 16628
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,pair<int,int> > edge[10000];
int UF[100];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);
	b=FIND(b);
	if(a==b)return;
	UF[a]+=UF[b];
	UF[b]=a;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		int b;
		scanf("%d",&b);
		int now=0;
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<b;i++){
			int c,d,e;
			scanf("%d,%d,%d",&c,&d,&e);
			edge[now++]=make_pair(e/100-1,make_pair(c,d));
		}
		std::sort(edge,edge+now);
		int ret=0;
		for(int i=0;i<now;i++){
			if(FIND(edge[i].second.first)!=FIND(edge[i].second.second)){
				UNION(edge[i].second.first,edge[i].second.second);
				ret+=edge[i].first;
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N;
int A[100000];
int X[100001];
int main() {
	cin >> N;
	rep(i, N) cin >> A[i];
	rep(x, 100001) {
		X[x] = 0;
	}
	rep(i, N){
		int a = A[i];
		X[a]++;
		if(a+1 >= 0 && a+1 <= 100000) X[a+1]++;
		if(a-1 >= 0 && a-1 <= 100000) X[a-1]++;
	}
	int ret = 0;
	rep(x, 100001) ret = max(ret, X[x]);
	cout << ret << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int a,b,c;
  cin >> a >> b >> c;

  FOR(i,1,b){
    if(a*i % b == c){
      cout << "YES" << endl;
      exit(0);
    }
  }
  cout << "NO" << endl;

}



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

ll N, K, A[200000];

int main(void) {
  cin >> N >> K;
  REP(i, 0, N) cin >> A[i];

  map<ll, ll> mp;
  REP(i, 0, N) mp[A[i]]++;

  vector<ll> vec;
  for(auto p : mp) vec.push_back(p.second);
  sort(vec.begin(), vec.end());

  ll ans = 0;
  REP(i, 0, vec.size() - K) ans += vec[i];
  cout << ans << endl;
}


Measured memory_bytes: 16500
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

int main() {
	int a, b;
	cin >> a >> b;
	if(b%a == 0){
		cout << a+b << endl;
	}else{
		cout << b-a << endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

    #define MAXN 1000005
    int spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }


    vector<int> gf(int x)
    {
        vector<int> ret;
        while (x != 1)
        {
            ret.push_back(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }
    int BIT[100050];
    void upd(int x) { ++x;  while(x<=MAXN)  {  BIT[x]++;  x+=(x&-x);  } }
    int cal(int x) {  ++x;  int res=0;  while(x>0)  {  res+=BIT[x];  x-=(x&-x);  } return res; }

    ll mod=hell;
    ll pr( ll x , ll y)
    {
        ll ans=1;
        if(y==0) return ans;
        while(y>1)
        {
            if(y&1) ans*=x;
            x*=x;
            y/=2;
            x%=mod;
            ans%=mod;
        }
        ans*=x;
        ans%=mod;
        return ans;
    }
    ll inv(ll n)
    {
        return pr(n,mod-2);
    }
    ll stoi(string s)
    {
        int n=s.size();
        ll k=0; int i;
        rep(i,0,n)
        {
            k+=s[i]-'0';
            k*=10;
        }
        return k/10;
    }
    string to_string(ll n)
    {  if(!n) return "0";
        string s=""; int a,b;
        while(n>0)
        {
            b=n%10;
            s+=(b+'0');
            n/=10;
        }
        reverse(all(s));
        return s;
    }
  ll invvf[1000500],fact[1000500];
  void pre()
  {
      ll i,j,n=1000050;
      fact[0]=1; fact[1]=1;
      rep(i,2,n) {fact[i]=fact[i-1]*i; fact[i]%=hell;}
      invvf[1]=1; invvf[0]=1;
      rep(i,2,n)
      {
          invvf[i]=inv(fact[i]);
      }

  }
 ll ncr(ll n , ll r)
 {
     ll y=fact[n];
     y*=invvf[r];
     y%=hell;
     y*=invvf[n-r];
     y%=hell;
     return y;
 }


int phi(int n) {
    int result = n;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
    void solve()
    {
    long long  i,j=0,r=200,p,q,k=0,d,y=0,n,h=100000000000000,flag=0,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c=0,e,ans=0;
    cin>>p; n=100;
    while(n<p)
    {
        n+=(n/100); y++;
    }
cout<<y;
    }
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
        //sieve();
        //pre();
         // cin>>t;
        solve();
    }


Measured memory_bytes: 3644
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int x, y;
    cin >> x >> y;
    
    if (x == 0) {
        if (y < 0) cout << 1 - y << "\n";
        else cout << y << "\n";
    } else if (y == 0) {
        if (x < 0) cout << -x << "\n";
        else cout << x + 1 << "\n";
    } else if ((x >= 0 && y < 0) || (x < 0 && y >= 0)) {
        cout << 1 + abs(x + y) << "\n";
    } else {
        if (x <= y) cout << y - x << "\n";
        else cout << x - y + 2 << "\n";
    }
    return;
}


Measured memory_bytes: 3668
from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
s=(M//gcd(N,M))
t=(N//gcd(N,M))
SS=[i*s for i in range(N)]
TT=[j*t for j in range(M)]
p,q=0,0
ans=N*s
while True:
    if SS[p]==TT[q]:
        if S[p]!=T[q]:ans=-1
        p+=1
        q+=1
    elif SS[p]>TT[q]:
        q+=1
    else:
        p+=1
    if p==N or q==M:
        break
print(ans)

Measured memory_bytes: 12128