akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long int 

vector<int> g[100005];
int vis[100005];
stack<int> stk;
ll dist[100005];

void dfs(int i)
{
    vis[i]=1;

    int len=g[i].size(),j;
    for(j=0;j<len;j++)
    {
        int p = g[i][j];
        if(vis[p]==0)
        {
            dfs(p);
        }
    }
    stk.push(i);

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,m,i;
    cin >> n >> m;
    
    for(i=0;i<m;i++)
    {
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
    }

    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }

    while(!stk.empty())
    {
        int temp=stk.top();

        // cout << temp << " ";
        for(i=0;i<g[temp].size();i++)
        {
            if(dist[g[temp][i]]<dist[temp]+1)
            {
                dist[g[temp][i]]=dist[temp]+1;
            }
        }
        stk.pop();
    }
    cout << '\n';

    // cout << max_element(dist+1,dist+n+1) << '\n';
    ll max=dist[1];

    for(i=1;i<=n;i++)
    {
        if(dist[i]>max)
        {
            max=dist[i];
        }
    }


    cout << max << '\n';

    return 0;
}

Measured memory_bytes: 9344
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	private static final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;

main(){
  cin>>n;
  if(n%10==9||n/10==9){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}


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

int main() {
    std::string in_str;
    std::cin >> in_str;

    long len = in_str.length();
    long h_len = len / 2;

    long c = 0;
    for (long i = 0; i < h_len; i++) {
        c += (in_str[i] != in_str[len-i-1]);
    }
    std::cout << c << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  int INF = INT_MAX;
  // ll mod = 998244353;
  // lld PI = 3.141592653;







  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      int n;
      cin>>n;
      int cnt = 0;
      bool ok = false;
      for (int i = 0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if (a==b){
          cnt++;
        }else{
          cnt = 0;
        }
        if (cnt>=3) ok = true;
      }
      if (ok)
        cout<<"Yes\n";
      else
        cout<<"No\n";

}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, D; cin >> N >> D;
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    ll x, y; cin >> x >> y;
    if (x*x + y*y <= D*D) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>

using namespace std;
#define ll long long
const int maxn = 1e5 + 100;
struct node {
	int to, cost;
	node (){}
	node(int t, int c) {
		to = t;
		cost = c;
	}
};
vector < node > e[maxn];

int fa[maxn][20];
ll dis[maxn];

void dfs(int x, int pre) {
	for (auto i : e[x]) {
		if (i.to != pre) {
			dis[i.to] = dis[x] + i.cost;
			dfs(i.to, x);
		}
	}
}

int main() {
	int n;
	scanf("%d", &n);
	int u, v, w;

	for (int i = 1; i < n; i++) {
		scanf("%d %d %d", &u, &v, &w);
		e[u].push_back(node(v, w));
		e[v].push_back(node(u, w));

		

	}
	int q, k;
		scanf("%d %d", &q, &k);
		dis[k] = 0;
		dfs(k, -1);
		while (q--) {
			scanf("%d %d", &u, &v);
			printf("%lld\n", dis[u] + dis[v]);
		}
	

	//system("pause");
	return 0;
}

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

int main() {
    long n,d,c;
  	c=0;
    scanf("%ld %ld",&n,&d);
    long x[200000],y[200000];
    for (int i=0;i<n;i++) {
        scanf("%ld %ld",&x[i],&y[i]);
    }
    for (int i=0;i<n;i++) {
        if (x[i]*x[i]+y[i]*y[i]<=d*d) c++; 
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 4808
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << (H - h) * (W - w) << endl;

    return 0;
}

Measured memory_bytes: 256
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    N, K = LI()
    n = int(N**0.5)
    C = [] # N//j=indexとなるjの個数
    L = [0]*(2*int(n)) # N//indexの解 =>要りません。。
    for i in range(1,n+1):
        now = N//i - N//(i+1)
        C.append(now)
    for i in range(1,n+1):
        if N//i==i:
            continue
        C.append(1)
    C.reverse()
    #print(C)
    n = len(C)
    #for i in range(1,n+1):
    #    L[i-1] = N//i
    #for i in range(n):
    #    L[i+n] = n - i
    #L.reverse()
    #print(L)
    dp = [[0]*(n) for _ in range(K)]

    for i in range(n):
        dp[0][i] = C[i]
    #print(dp[0])
    for i in range(K-1):
        S = 0
        for j in range(n):
            S += dp[i][j]
            S %= mod
            dp[i+1][n-j-1] = S*C[n-j-1] %mod
    #print(dp)
    ans = 0
    for s in dp[-1]:
        ans += s
        ans %= mod
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 136892
import math

a, b, C = map(float, input().split(' '))

rad = math.radians(C)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))

S = a*b*math.sin(rad)*1/2
L = a+b+c
h = abs(b*math.sin(rad))

print('{:.5f} {:.5f} {:.5f}'.format(S, L, h))

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<int> nums; //0が1の桁、1が2の桁となっているため注意(答えは末端から出力する)
    bool isPlus = true;
    while (N)
    {
        if (abs(N) % 2)
        {
            nums.push_back(1);
            if (isPlus)
            {
                N -= 1;
            }
            else
            {
                N += 1;
            }
        }
        else
        {
            nums.push_back(0);
        }
        isPlus = !isPlus;
        N /= 2;
    }
    for (int i = nums.size() - 1; i >= 0; i--)
    {
        cout << nums.at(i);
    }
    if(nums.size() == 0)
    {
        cout << 0;
    }
    cout << endl;
    return 0;
}


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

using namespace std;

const int max_n = 100111, mod = 1000000007;

int n, m, f[max_n], dp[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    while (m--) {
        int x;
        scanf("%d", &x);
        f[x] = 1;
    }
    dp[0] = 1;
    dp[1] = 1 - f[1];
    for (int i = 2; i <= n; ++i) {
        dp[i] = (1 - f[i]) * (dp[i - 1] + dp[i - 2]) % mod;
    }
    printf("%d\n", dp[n]);
    return 0;
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    long n = sc.nextLong();

    long sum = 0;
    long upperbound = (long) Math.ceil(Math.sqrt(n));

    
    Set<Long> added = new HashSet<>();
    
    for (long x1 = 1; x1 <= upperbound; x1++) {
      if (n % x1 == 0) {
        long m1 = n / x1 - 1;
        if (!added.contains(m1)) {
          if (m1 > 1 && n % m1 != 0 && x1 < m1) {
            sum += m1;
            added.add(m1);
          }
        }
        long x2 = m1 + 1;
        long m2 = x1 - 1;
        if (!added.contains(m2)) {
          if (m2 > 1 && n % m2 != 0 && x2 < m2) {
            sum += m2;
            added.add(m2);
          }
        }
      }
    }
    /**
    for (long i = 1; i <= n; i++) {
      if (n / i == n % i) {
        sum += i;
      }
    }*/
    os.println(sum);
  }
}

Measured memory_bytes: 24756
#include<stdio.h>
int main(void){
  int a[10],i,top1=0,top2=0,top3=0;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
    if(a[i]>top1){
      top3 = top2;
      top2 = top1;
      top1 = a[i];
    }
    else if(top1>=a[i]&&a[i]>=top2){
      top3 = top2;
      top2 = a[i];
    }
    else if(top2>a[i]&&a[i]>=top3){
      top3 = a[i];
    }
  }
  printf("%d\n%d\n%d\n",top1,top2,top3);
  return(0);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  double l; cin>>l;
  double ans=(l/3)*(l/3)*(l/3);

  cout<<fixed<<setprecision(10)<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] U = new long[n];
		long[] V = new long[n];
		for(int i=0;i<n;i++) {
			long x = in.nextLong();
			long y = in.nextLong();
			U[i] = x + y + (1L<<31);
			V[i] = x - y + (1L<<31);
		}
		in.close();
		long mod2 = U[0] % 2;
		boolean sameMod = true;
		for(int i=1;i<n;i++) {
			if(U[i]%2!=mod2) {
				sameMod = false;
				break;
			}
		}
		if(sameMod) {
			if(mod2==1) {
				long[] d = new long[31];
				System.out.println(31);
				
				String arms = "";
				for(int i=0;i<31;i++) {
					d[i] = 1L<<i;
					arms += d[i];
					arms += " ";
				}
				System.out.println(arms);
				
				for(int i=0;i<n;i++) {
					U[i] = (U[i] - 1)/2;
					V[i] = (V[i] - 1)/2;
					
					String ans = "";
					for(int j=0;j<31;j++) {
						long u = (U[i]>>j)&1;
						long v = (V[i]>>j)&1;
						if(u==1 && v==1) ans += "R";
						else if(u==0 && v==1) ans += "D";
						else if(u==1 && v==0) ans += "U";
						else if(u==0 && v==0) ans += "L";
					}
					System.out.println(ans);
				}
			}else {
				long[] d = new long[31];
				System.out.println(32);
				
				String arms = "";
				for(int i=0;i<31;i++) {
					d[i] = 1L<<i;
					arms += d[i];
					arms += " ";
				}
				arms += "1";
				System.out.println(arms);
				
				for(int i=0;i<n;i++) {
					U[i] = U[i]/2;
					V[i] = V[i]/2;
					
					String ans = "";
					for(int j=0;j<31;j++) {
						long u = (U[i]>>j)&1;
						long v = (V[i]>>j)&1;
						if(u==1 && v==1) ans += "R";
						else if(u==0 && v==1) ans += "D";
						else if(u==1 && v==0) ans += "U";
						else if(u==0 && v==0) ans += "L";
					}
					ans += "L";
					System.out.println(ans);
				}
			}
			
		}else {
			System.out.println(-1);
		}

	}

}


Measured memory_bytes: 34668
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <sstream>
#include <iomanip>
#define REP(i,n,s) for (int i = (s);i < (int)( n ); i++)
#define REP0(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
using namespace std;

ll i,j;
const int MOD = 1000000000 + 7;

int main(){
    int n;
    ll ans=0;
   
    cin>>n;
    

    REP(i,n,1){
        ans+=(n-1)/i;
    }
    


    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3524
require "matrix"
while gets
    x1, y1, x2, y2, xq, yq = $_.split(",").map &:to_f
    s = Vector[x1, y1]
    u = Vector[x2-x1, y2-y1]
    v = Vector[xq-x1, yq-y1]
    h = u * u.inner_product(v) / u.r**2
    printf("%.7f %.7f\n", *(s + h * 2 - v).to_a)
end

Measured memory_bytes: 6432
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    string b;cin>>b;
    REP(i,b.size()){
        if(b[i]=='A') cout<<'T';
        if(b[i]=='C') cout<<'G';
        if(b[i]=='G') cout<<'C';
        if(b[i]=='T') cout<<'A';
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            int f = int.Parse(Console.ReadLine());
            int[] nums = Console.ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();

            bool b = false;

            for(var i = nums[0]; i <= nums[1]; i++) {
                if(i % f == 0) {
                    b = true;
                    break;
                }
            }

            if (b) {
                Console.Write("OK");
            } else {
                Console.Write("NG");
            }
        }
    }
}

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

#define rep(i,n) for(int i = 0;i < (int)(n);i++)
int main(void){
    // Your code here!
    cout << fixed << setprecision(5);
    int a,b,d,r;
    cin >> a >> b;
    double f;
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    cout << d << " " << r << " " << (double)f << endl;
}



Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long start=1;
		for (int i=1;i<=N;i++) {
			start=(start*i)%1000000007l;
		}
		System.out.println(start);
	}
}

Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main()
{

	int H,W;
	bool pattern=true;
	
	while( true ) {
		cin>>H>>W;	
		if( 0==H && 0==W ) { break; }
		for( int i=0; i<H; i++ ) {
			pattern = (0==i%2)? true: false;
			for( int j=0; j<W; j++ ) {
				if( pattern ) {
					cout <<"#"; 
					pattern=!pattern;
				} else {
					cout <<"."; 
					pattern=!pattern;
				}
			}
			cout <<endl;  
		}
		cout <<endl; 
	}
	
    return 0;
}

Measured memory_bytes: 1152
import sys
readline = sys.stdin.readline

G = 10**10
lai = 0
def Decimal(x):
    global lai
    a = x.strip().split('.')
    if len(a) == 1 or all([ai == '0' for ai in a[1]]):
        lai += 1
        return int(a[0])*G
        
    lf = len(a[1])
    i, f = map(int, a)
    return (i*10**(lf) + f)*10**(10-lf)
    
    
N = int(readline())
A = [Decimal(readline()) for _ in range(N)]

H = 200
geta = 100
Grid = [[0]*H for _ in range(H)]
i25 = []


for af in A:
    i2 = -10
    i5 = -10
    while af%2 == 0:
        af //= 2
        i2 += 1
    while af%5 == 0:
        af //= 5
        i5 += 1
    i25.append((i2, i5)) 


for i2, i5 in i25:
    Grid[geta+i2][geta+i5] += 1

for i in range(geta+90, geta-90, -1):
    for j in range(geta+90, geta-90, -1):
        Grid[i][j] += Grid[i][j+1]

for j in range(geta+90, geta-90, -1):
    for i in range(geta+90, geta-90, -1):
        Grid[i][j] += Grid[i+1][j]


ans = 0
for i2, i5 in i25:
    ans += Grid[geta-i2][geta-i5]
    #print(i2, i5, Grid[geta-i2][geta-i5])
print((ans-lai)//2)


Measured memory_bytes: 98536
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,j,n,score[50][2],order[50],frame,first,last,pin,str,spa;

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int main(){
	while(scanf("%d",&n)*n){
		for(i=0;i<n;i++){
			scanf("%d",&score[i][0]);

			frame=1;score[i][1]=0;last=2;first=-1;
			while(frame<10+last){
				scanf("%d",&pin);
				score[i][1]+=pin*(1+(str+1)/2+spa);

				if(str>0)str-=(str+1)/2;
				spa=0;
				if(frame>9)frame++;
				if(first<0 && pin==10){
					if(frame<10){str+=2;if(frame<10)frame++;}
					else last=3;
				}
				else{
					if(first<0)first=pin;
					else{
						if(first+pin==10){
							if(frame<10)spa=1;
							else last=3;
						}
						first=-1;
						if(frame<10)frame++;
					}
				}
			}

			order[i]=i;
			for(j=i;j>0;j--){
				if(score[i][1]>score[order[j-1]][1] || (score[i][1]==score[order[j-1]][1] && score[i][0]<score[order[j-1]][0])){
					swap(&order[j],&order[j-1]);
				}
			}
		}
		for(i=0;i<n;i++)printf("%d %d\n",score[order[i]][0],score[order[i]][1]);
	}
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

LL sum[90005];

int main() {
    std::ios::sync_with_stdio(false);
    int h, w, d;
    map<int, pair<int, int>> m;
    cin >> h >> w >> d;
    inc(i, 0, h){
        inc(j, 0, w){
            int a;cin >> a;
            m[a] = pair<int, int>{i, j};
        }
    }
    inc(i, 1, h*w+1){
        if(i+d <= h*w){
            int ci = m[i].fi;
            int cj = m[i].se;

            int ni = m[i+d].fi;
            int nj = m[i+d].se;

            sum[i+d] = sum[i] + abs(ci-ni) + abs(cj-nj);
            //cout << ci << " " << cj << " " << ni << " " << nj << " " << sum[i] << endl;
        }
    }

    int q;cin >> q;
    inc(i, 0, q){
        int l, r;cin >> l >> r;
        printf("%lld\n", sum[r]-sum[l]);
    }
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int S, W;
  cin >> S >> W;
  if (W >= S) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	while(cin >> n >> m) {
		int pos = 0;
		for(int i = 0; i < m; i++) {
			int x;
          	cin >> x;
			pos += x;
		}
		cout << (pos > n ? -1 : n - pos) << endl;
	}
	return 0;	
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,ans=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int r,l;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    string s,t;
    cin>>s>>t;

    int ans=0;

    for(int i=0;i<s.length();i++) {
        if(s[i]!=t[i]) {
            ans++;
        }
    }
    cout<<ans<<endl;
}




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

int main() {
    int64_t n, k;
    cin >> n >> k;
    int64_t ans = 0;
    vector<pair<int, int>> ab(n);
    for (auto& e : ab) cin >> e.first >> e.second;
    sort(begin(ab), end(ab));
    int64_t c = 0;
    for (auto& e : ab) {
        c += e.second;
        if (ans == 0 && c >= k) ans = e.first;
    }
    cout << ans << endl;
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							 \
			cout.tie(0);
#define PI 3.141592654

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll& x, ll v) { x = (x + v) % MOD; if (x < 0) x += MOD; }
ll f[500005];
ll kCn(ll k, ll n) { if (k > n) return 0; if (k < 0) return 0; if (n < 0) return 0; return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

void test_case() {

}

const int mxN = 1e5 + 1;


int main() {
	fastio;
	ll n, m;
	cin >> n >> m;	

	f[0] = 1;
	for (int i = 1; i <= 500001; ++i)
		f[i] = (f[i - 1] * i) % MOD;

	ll ans = 0;
	ll cur = 1;
	for (int i = 0; i < n + 1; ++i) {
		ll temp = cur * kCn(i, n) * kCn(n - i, m - i);
		temp %= MOD;
		temp *= f[n - i];
		ans += temp;
		ans %= MOD;
		cur = -cur;
	}

	ans = ans * kCn(n, m);
	ans %= MOD;
	ans *= f[n];
	ans %= MOD;
	while (ans < 0)
		ans += MOD;
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 7572
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int k; cin >> k;
	int a, b; cin >> a >> b;
	for (int i = k; i <= b; i += k) {
		if (i >= a && i <= b) {
			cout << "OK" << endl;
			return;
		}
	}
	cout << "NG" << endl;
	return;
}

int main() {
	solve();
  return 0;
}

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

int main()
{
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if (10 % p == 0)
    {
        // 2,5
        ll ans = 0;
        rep(r, n)
        {
            if ((s[r] - '0') % p == 0) {
                ans += r + 1;
             }
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> d(n + 1);
    int ten = 1;
	for (int i = n - 1; i >= 0; --i)
    {
        int a = (s[i] - '0') * ten % p;
        d[i] = (d[i + 1] + a) % p;
        ten *= 10;
        ten %= p;
    }

    vector<int> cnt(p);
    ll ans = 0; 
    for (int i = n; i >= 0; --i)
    {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    deque<ll> b;
    bool is_rev = false;

    for (ll i = 0; i < N; i++) {
        if (is_rev) {
            b.emplace_front(A[i]);
        }
        else {
            b.emplace_back(A[i]);
        }
        is_rev ^= true;
    }

    if (is_rev) {
        for (ll i = N - 1; i >= 0; i--) {
            cout << b[i] << " ";
        }
        cout << "\n";
    }
    else {
        for (ll i = 0; i < N; i++) {
            cout << b[i] << " ";
        }
        cout << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 6352
#include<stdio.h>
#include<math.h>
int main ()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if((x+y)%2==0)
    {
        printf("%d\n",(x+y)/2);
    }
    else printf("IMPOSSIBLE\n");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	vector<string> c(3);
	for(int i=0; i<c.size(); i++)
		cin >> c[i];

	for(int i=0; i<c.size(); i++)
		cout << c[i][i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>

#include <cmath>
#include <string>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

long h[200000][3];
long dp[200000][3];

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

	int n;
	cin >> n;

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

	dp[0][0] = dp[0][1] = dp[0][2] = 0;
	for (int i = 1; i < n+1; i++) {
		dp[i][0] = h[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = h[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = h[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));

	return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = n / 3;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    int N = S.size();
    vector<pair<char,int>> suzu;
    suzu.emplace_back(S[0],1);
    for(int i=1; i<N; i++){
        if(suzu.back().first == S[i]){
            suzu.back().second++;
        }else{
            suzu.emplace_back(S[i],1);
        }
    }
    if(suzu.size() == 1){
        cout << N << "\n";
        return 0;
    }
    deque<int> deq;
    for(int i=0; i<suzu.size(); i++){
        deq.emplace_back(suzu[i].second);
    }
    int ans = inf;
    while(deq.size() > 1){
        if(deq.front() <= deq.back()){
            chmin(ans,N-deq.front());
            int a;
            a = deq.front();
            deq.pop_front();
            deq.front() += a;
        }else{
            chmin(ans,N-deq.back());
            int a;
            a = deq.back();
            deq.pop_back();
            deq.back() += a;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL limit=1e5;
 int imos[30][limit*2+2];

int main(){
  int N,C;
  cin >> N >> C;
  for(int i=0;i<C;i++)
    for(int j=0;j<limit*2+2;j++)
      imos[i][j]=0;
  for(int i=0;i<N;i++){
    int s,t,c;
    cin >> s >> t >> c;
    imos[c-1][s*2-1]++;
    imos[c-1][t*2]--;
  }
  int st=0,ans=0;
  for(int i=0;i<C;i++){
    for(int j=0;j<limit*2+2;j++){
      if(imos[i][j]==1&&imos[i][j+1]==-1){
	imos[i][j]=0;
	imos[i][j+1]=0;
      }
    }
  }
  for(int i=0;i<limit*2+2;i++){
    for(int j=0;j<C;j++){
      st+=imos[j][i];
    }
    ans=max(st,ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 23680
L = int(input())
A = [int(input()) for _ in range(L)]

dp = [0] * 5
for a in A :
  ndp = [0] * 5
  ndp[0] = dp[0] + a
  ndp[1] = min(dp[0:2]) + a % 2
  ndp[2] = min(dp[0:3]) + (a + 1) % 2
  ndp[3] = min(dp[0:4]) + a % 2
  ndp[4] = min(dp[0:5]) + a
  
  if a == 0 : 
    ndp[1] += 2
    ndp[3] += 2
    
  dp = ndp
  
print(min(dp))

Measured memory_bytes: 59480
import collections

N, K = map(int, input().split(" "))
inputLines = [input() for i in range(N)]
arrayInfo = collections.Counter()
for inputLine in inputLines:
    a, b = map(int, inputLine.split(" "))
    arrayInfo[a] += b
now = 0
for key, value in sorted(arrayInfo.items()):
    now += value
    if K <= now:
        print(key)
        break


Measured memory_bytes: 22012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define SENTINEL 2000000000
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

ll L[MAX/2+2],R[MAX/2+2];
ll cnt;
void merge(ll A[],ll n,ll left,ll mid ,ll right){
    ll n1 = mid   - left;
    ll n2 = right - mid;
    REP(i,n1)L[i] = A[left+i];
    REP(i,n2)R[i] = A[mid+i];
    L[n1] = R[n2] = SENTINEL;
    ll i = 0,j = 0;
    REP2(k,left,right){
        cnt++;
        if(L[i]<=R[j]){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}
void mergeSort(ll A[],ll n,ll left,ll right){
    if(left+1<right){
        ll mid = (left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    ll A[MAX],n;
    cnt = 0;
    cin >> n;
    REP(i,n){cin>>A[i];}
    mergeSort(A,n,0,n);
    REP(i,n){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


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

struct Point {double x, y;};
struct Square {double left, right, top, bottom;};

bool include(const Square& s, const Point& p) {
  return s.left <= p.x && p.x <= s.right && s.bottom <= p.y && p.y <= s.top;
}

bool ok(const vector<Point>& point, double d) {
  Square A = {point.front().x, point.front().x + d, 0, 0};
  Square B = {point.back().x - d, point.back().x, 0, 0};
  double lowA = 1e9, highA = -1e9;
  double lowB = 1e9, highB = -1e9;
  for(const auto& p: point) {
    if(p.x <= A.right) {
      lowA = std::min(lowA, p.y);
      highA = std::max(highA, p.y);
    }
    if(B.left <= p.x) {
      lowB = std::min(lowB, p.y);
      highB = std::max(highB, p.y);
    }
  }
  A.top = highA;    A.bottom = highA - d;
  B.top = lowB + d; B.bottom = lowB;
  if(all_of(begin(point), end(point), [&](const Point& p){return include(A, p) || include(B, p);})) return true;
  A.top = lowA + d; A.bottom = lowA;
  B.top = highB;    B.bottom = highB - d;
  if(all_of(begin(point), end(point), [&](const Point& p){return include(A, p) || include(B, p);})) return true;
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<Point> point(N);
  for(auto& p: point) cin >> p.x >> p.y;
  for(auto& p: point) p = {p.x / sqrt(2) - p.y / sqrt(2), p.x / sqrt(2) + p.y / sqrt(2)};
  sort(begin(point), end(point), [](const Point& lhs, const Point& rhs){return lhs.x < rhs.x;});
  double low = 0, high = 3e5;
  while(1e-1 < high - low) {
    double middle = (low + high) / 2.0;
    ok(point, middle) ? (high = middle) : (low = middle);
  }
  cout << int(high * sqrt(2)) << endl;
}

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

#define MOD 1000000007
#define ll long long int
#define floop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()


int solve(){
 
    string a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=0;i<a.length();i++){
      if(a[i]!=b[i])cnt++;
    }
    cout<<cnt<<endl;

return 0;
}

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

    ll t; t=1;
    //cin>>t;

    while(t--)
       solve();
    return 0;
}

Measured memory_bytes: 3796
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
using namespace std;

static const int N = 100;
int G[N][N] = { {} };
int n, t = 0;
int detected_t[N] = {};
int finished_t[N] = {}; 

void depthFirstSearch(int ix) {
	if (!detected_t[ix - 1]) {
		detected_t[ix - 1] = ++t;
		for (int j = 0; G[ix - 1][j]; j++) {
			depthFirstSearch(G[ix - 1][j]);
		}
		if (!finished_t[ix - 1]) finished_t[ix - 1] = ++t;
	}
}

void myCheck() {
	for (int i = 0; i < n; i++) {
		cout << "index " << i + 1 << " : ";
		for (int j = 0; G[i][j]; j++) {
		if (j) cout << " ";
		cout << G[i][j];
		}
		cout << " time " << detected_t[i] << ", " << finished_t[i] << endl;
	}
}

int main() {
	int ix, deg;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ix >> deg;
		for (int j = 0; j < deg; j++) cin >> G[ix - 1][j];
	}

	for (int i = 0; i < n; i++) depthFirstSearch(i+1);
	//myCheck();

	for (int i = 0; i < n; i++) cout << i + 1 << " " << detected_t[i] << " " << finished_t[i] << endl;

	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int mod = 1000000007;
long long dp[100005];

int main() {
  long long a,b,c,d;
  cin >> a >>b >> c >> d;
  
  long long kou = c*d/__gcd(c,d);
  
  long long resa,resb,resc; 
    
  resa = b/c -(a-1)/c;
  resb = b/d -(a-1)/d;
  resc = b/kou -(a-1)/kou;
  long long res = resa + resb -resc;
  
  
  
  cout << b-a+1 -res << endl;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, K;

int main() {
	scanf("%lld %lld", &N, &K);
	ll cnt = 0;
	for(int i = max(K - N + 1, -1000000ll); i < K; i++) {
		printf("%d ", i);
	}
	for(int i = K; i <= min(1000000ll, K + N - 1); i++) {
		printf("%d ", i);
	}
	// printf("%lld\n", cn/t);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
from collections import Counter
N=int(input())
A=list(input().split())

c=Counter(A)

v=list(c.values())



def map_all(es):
    return all([e == es[0] for e in es[1:]]) if es else False
ans=map_all(v)

if v[0]==1 and ans==True:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 39884
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	int N;
	cin>>N;
	int a[MAX+1];
	rep1(i,N)cin>>a[i];
	
	int now=1;
	int ans=0;
	bool pos=false;
	rep(i,N){
		ans++;
		now=a[now];
		if(now==2){
		pos=true;
		break;
		}
	}
	if(!pos)cout<<-1<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include<iostream>
using namespace std;

int main()
{
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

  	double x_2 = pow(x2 - x1, 2.0);
  	double y_2 = pow(y2 - y1, 2.0);
  
  	printf("%lf\n", sqrt(x_2 + y_2));

    return 0;
}


Measured memory_bytes: 3228
mod = 10**9 + 7
n = int(input())
s1 = input()
s2 = input()

if s1[0] == s2[0]:
    idx = 1
    ans = 3
    tate = 1
else:
    idx = 2
    ans = 6
    tate = 0

while idx < n:
    if s1[idx] == s2[idx]:
        if tate:
            ans *= 2
            ans %= mod
        tate = 1
        idx += 1
    else:
        if tate:
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        tate = 0
        idx += 2

print(ans)

Measured memory_bytes: 61924
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.util.TreeSet;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final String s = fs.next();
        final int K = fs.nextInt();

        TreeSet<String> ts =
            new TreeSet<String>();

        for (int i = 0; i < s.length(); i++) {
            for (int j = i + 1; j < i + K + 1; j++) {
                if (s.length() < j) break;
                ts.add(s.substring(i, j));
            }
        }

        int k = 1;
        for (String a : ts) {
            if (k == K) {
                System.out.println(a);
                break;
            }
            k++;
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 24276
N = int(input())
S = input()

Wlist = [0]*(N+1) 
Elist = [0]*(N+1) 

for i in range(1,N+1):
    if S[i-1] == 'W':
        Wlist[i] = Wlist[i-1] + 1
    else:
        Wlist[i] = Wlist[i-1]
        
    if S[i-1] == 'E':
        Elist[i] = Elist[i-1] + 1
    else:
        Elist[i] = Elist[i-1]

ans = []

for i in range(1,N+1):
    ans.append((Elist[-1] - Elist[i]) + (Wlist[i-1]))
    
print(min(ans))

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

string word[] = {
    "dream", "dreamer", "erase", "eraser",
};

int main()
{
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; i++) {
        reverse(word[i].begin(), word[i].end());
    }

    int match_len;
    for (int p = 0; p < s.length(); p += match_len) {
        match_len = 0;
        for (int i = 0; i < 4; i++) {
            if (s.substr(p, word[i].length()) == word[i]) {
                match_len = word[i].length();
            }
        }
        if (match_len == 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

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

int main(void){
    vector<int> nums(3);
    cin >> nums[0];
    cin >> nums[1];
    cin >> nums[2];
    
    sort(nums.begin(),nums.end());
    
    printf("%d %d %d\n", nums[0],nums[1],nums[2]);
}


Measured memory_bytes: 3256
#include<iostream>
#include <string>
//#include <algorithm>　//ソート
//#include <set>
using namespace std;
int main()
{
  int i, j, f;
    string s;
  f=0;
    cin >> s;
  
  for(i=0; i<s.length(); i++){
    if((i+1)%2==1){
     if(s[i]=='R'|| s[i]=='U'||s[i]=='D')
       f=0;
     else {
       f=1;
       break;
     }
    }
    else{ 
     if(s[i]=='L'|| s[i]=='U'||s[i]=='D')
       f=0;
     else{
      f=1;
       break;
     }
    }
  }
  

  if(f==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

    //s.length(); //長さ
    //s.substr(i, k); //i番目以降k文字を抽出して得られる文字列
    //s.find(t);  //sの中に文字列tがあればその先頭のアドレスを返す．なければs.nopsを返却
    //s.replace(i, k, t); //i番目以降k文字を文字列tで置換する．tを空文字列にすれば削除の動作
    //s.insert(i, t); //i番目の文字の前に文字列tを挿入

    //sort(a.begin(), a.end(),);  //昇順ソート
    //sort(a.begin(), a.end(), greater<int>());   //降順ソート
    //swap(a, b); //値を交換する
    //min(a, b);  //小さい方
    //max(a, b);  //大きい方

    //binary_search(vc.begin(), vc.end(), x); //trueかfalseを返す
    //lower_bound(vc.begin(), vc.end(), x);   //x以上の値が初めて現れる位置のイテレータを返す
    //upper_bound(vc.begin(), vc.end(), x);   //xより大きい値が初めて現れる位置のイテレータを返す




    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for (int i = 0; i <= a; ++i) {
    int _x = x - i * 500;
    if (_x < 0) break;
    for (int j = 0; j <= b; ++j) {
      int __x = _x - j * 100;
      if (__x < 0) break;
      if (__x / 50 <= c) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256