akhauriyash/Code-Regression huggingface dataset:
from collections import deque
h,w=map(int,input().split())
meiro=[]
for i in range(h):
	tmp=input()
	meiro.append([tmp[i] for i in range(w)])



def bfs(sh,sw,meiro):
	que=deque([[sh,sw]])
	dist=[[-1 for _ in range(w)] for _ in range(h)]
	dist[sh][sw]=0

	while True:
		if que == deque([]):
			tmpmax=0
			for di in dist:
				tmptmpmax=max(di)
				if tmptmpmax>tmpmax:
					tmpmax=tmptmpmax
			return tmpmax
		
		
		check=que.popleft()
		hnow=check[0]
		wnow=check[1]
		
		dnow=dist[hnow][wnow]
		
		hnext=hnow-1
		wnext=wnow
		if 0 < hnow:
			if dist[hnext][wnext]==-1 and meiro[hnext][wnext] == ".":
				que.append([hnext,wnext])
				dist[hnext][wnext]=dnow+1
		
		hnext=hnow+1
		wnext=wnow
		if h-1 > hnow:
			if dist[hnext][wnext]==-1 and meiro[hnext][wnext] == ".":
				que.append([hnext,wnext])
				dist[hnext][wnext]=dnow+1
		
		hnext=hnow
		wnext=wnow-1
		if 0 < wnow:
			if dist[hnext][wnext]==-1 and meiro[hnext][wnext] == ".":
				que.append([hnext,wnext])
				dist[hnext][wnext]=dnow+1
		
		hnext=hnow
		wnext=wnow+1
		if w-1 > wnow:
			if dist[hnext][wnext]==-1 and meiro[hnext][wnext] == ".":
				que.append([hnext,wnext])
				dist[hnext][wnext]=dnow+1

roadlist=[]
for i in range(h):
	for j in range(w):
		if meiro[i][j] == ".":
			roadlist.append([i,j])

amax=0
for start in roadlist:
	tmp=bfs(start[0],start[1],meiro)
	if tmp > amax:
		amax = tmp

print(amax)




Measured memory_bytes: 3444
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 

#define int             long long

 
void anmol()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 
//const int N = 1e6 + 5 ;
 //int a[N], nums2[N] , freq[N];


int32_t main(){

  anmol();
    
  int n;
  cin>>n;

  int a[n+1] ={0};


  for(int i =1; i<=n; i++){
      
      for(int j =i; j<=n; j+=i){


        a[j]++;
      }



  } 


  int sum =0;


  for(int i =1; i<=n; i++){

    sum+=i*a[i];
  }

cout<<sum<<endl;

 
}










  
 






   

  
  

   
   





  










 
 





  



 
 
    

  
 
 
 
 
 


 

   

 
 



  
  












 
 





  



 
 
    

  































 
 



  
  












 
 





  



 
 
    

  
 
 
 
 
 


 

   

 
 



  
  












 
 





  



 
 
    

  


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

int main(void){
    int a,b,k;
    cin >> a >> b >> k;
    int i = a;
    while(i<=b){
        if(i < a+k || i > b-k){
            cout << i << endl;
        }
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>
#include<array>
#include<stdio.h>
#include<cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
ll LLINF = 1e15;
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

int col[] = {1,0,-1,0,1,1,-1,-1};
int row[] = {0,1,0,-1,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};


int n;

vvll dp(3005,vll(3005,-1));

vll nums(3005);

ll getSol(int i , int j, bool f)
{
    if(i == j)
    {
        if(f)
            return nums[i];

        return -nums[i];
    }

    if(dp[i][j] != -1)
        return dp[i][j];

   ll ans;
   if(f)
        ans = max(nums[i]+getSol(i+1,j,!f), nums[j]+ getSol(i,j-1,!f));
   else
        ans = min(getSol(i+1,j,!f)-nums[i], getSol(i, j-1,!f)-nums[j]);

   return dp[i][j] = ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios::sync_with_stdio(0);
    //cin.tie(0);

    cin >> n;

    for(int i = 0 ; i < n; ++i)
        cin >> nums[i];

    cout << getSol(0,n-1,1);

    return 0;
}


Measured memory_bytes: 74464
#!/usr/local/bin/python3
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    w,h,x,y = f()

    print(w*h/2, end = ' ' )

    if 2*x == w and 2*y == h:
        print(1)
    else:
        print(0)


solve()


Measured memory_bytes: 2940
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int W, H, N;
	cin >> W >> H >> N;
	int l = 0, r = W, d = 0, u = H;
	rep(i, N) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1 && x > l) l = x;
		else if (a == 2 && x < r) r = x;
		else if (a == 3 && y > d) d = y;
		else if (a == 4 && y < u) u = y;
	}
	cout << max(r - l, 0) * max(u - d, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 0x1fffffffffffffff;

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    for(ll& i : h) cin >> i;
    vector<ll> dp(n, INF);
    dp[0] = 0;
    for(ll i = 0; i < n - 1; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[n - 1] << endl;
}


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

int main(){
    int N;
    cin >> N;
    for (int i=0; i<N; i++){
        string S;
        cin >> S;
        if (S == "Y"){
            cout << "Four" << endl;
            break;
        } 
        else if (i == N-1){
            cout << "Three" << endl;
        }
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
vector<int> V;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		V.push_back(A[i]);
	}
	sort(ALL(V));
	
	FOR(i,N) {
		if(A[i]<=V[N/2-1]) cout<<V[N/2]<<endl;
		else cout<<V[N/2-1]<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

void bfs(vector<vector<int>> &vec,vector<int> &visited,int index)
{
    visited[index]=1;
    queue<int> q;
    q.push(index);
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        for(int i=0;i<vec[temp].size();++i)
        {
            if(!visited[vec[temp][i]])
            {
                visited[vec[temp][i]]=1;
                q.push(vec[temp][i]);
            }
        }
    }
}

int main() {
	int n,m;
	cin>>n>>m;
	vector<vector<int>> vec(n);
	for(int i=0;i<m;++i)
	{
	    int temp1,temp2,temp3;
	    cin>>temp1>>temp2>>temp3;
	    vec[temp1-1].push_back(temp2-1);
	    vec[temp2-1].push_back(temp1-1);
	}
	int count=0;
	vector<int> visited(n,0);
	for(int i=0;i<n;++i)
	{
	    if(!visited[i])
	    {
	        count++;
	        bfs(vec,visited,i);
	    }
	}
	cout<<count<<endl;
}


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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i,h){
        cin >> a.at(i);
    }
    // 上1行
    rep(i,w+2) cout << '#';
    cout << endl;

    rep(i,h){
        cout << '#' << a.at(i) << '#' << endl;
    }
    // 下1行
    rep(i,w+2) cout << '#';
    cout << endl;

    return 0;
    
}

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

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<int> > s(M);
    vector<int> k();
    for(int i=0;i<M;i++){
        int k;
        cin>>k;
        s[i].resize(k);
        for(int j=0;j<k;j++){
            int tmp;
            cin>>tmp;
            s[i][j] = --tmp;
        }
    }
    vector<int> p(M);
    for(int i=0;i<M;i++){
        cin>>p[i];
    }
    int ans=0;
    for(int i=0;i<(1<<N);i++){
        bool ok = true;
        for(int j=0;j<M;j++){
            int cnt = 0;
            for(int k=0;k<s[j].size();k++){
                int x = s[j][k];
                if((i>>x)&1){
                    cnt++;
                }
            }
            cnt%=2;
            if(cnt!=p[j]){
                ok = false;
            }
        }
        if(ok)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
# 2020/01/27
# AtCoder Beginner Contest 075 - B

# Input
h, w = map(int, input().split())
slist = list()

# Make Initial Map
edge_s = ""
for i in range(w + 2):
    edge_s = edge_s + "."

# Top
slist.append(edge_s)

# Middle
for i in range(h):
    slist.append("." + input() + ".")

# Bottom
slist.append(edge_s)


# Make Answer Map
for i in range(1, h + 1):
    a_row = ""
    for j in range(1, w + 1):
        bcnt = 0
        if slist[i][j] == "#":
            a_row = a_row + "#"
        else:
            for k in range(i-1, i+2):
                for l in range(j-1, j+2):
                    if k == i and l == j:
                        continue
                    if slist[k][l] == "#":
                        bcnt = bcnt + 1
            a_row = a_row + str(bcnt)
    print(a_row)


Measured memory_bytes: 3064
import scala.io.Source.stdin

object Main {
  def sumNum(i: Iterator[String]): Vector[BigInt] = {
    def loop(limit: Int, v: Vector[BigInt] = Vector()): Vector[BigInt] =
      if (limit > 0) loop(limit - 1, v :+ (BigInt(i.next) + BigInt(i.next))) else v

    loop(i.next.toInt)
  }

  def main(args: Array[String]): Unit = {
    val input = stdin.getLines
    sumNum(input).foreach(a => if (a.toString.length <= 80) println(a) else println("overflow"))
  }
}

Measured memory_bytes: 43668
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    
    if(N / 100 == 1){
        cout << 9;
    }
    else{
        cout << 1;
    }
    if((N % 100) / 10 == 1){
        cout << 9;
    }
    else{
        cout << 1;
    }
    if(N % 10 == 1){
        cout << 9 << endl;
    }
    else{
        cout << 1 << endl;
    }
    
}


Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		sc.close();

		long happy = 0;

		happy = happy + (x / 500) * 1000;

		x = x % 500;

		happy = happy + (x / 5) * 5;

		print(happy);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 21716
import sys
X = int(input())

lis = [100, 101, 102, 103, 104, 105]

for item in lis:
    if X % item == 0:
        print(1)
        sys.exit()

if X >= 2000:
    print(1)
    sys.exit()

for x in range(1, 20):
    if 100 * x <= X <= 105 * x:
        print(1)
        sys.exit()
print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fill(x,v) memset(x, v, sizeof(x))
#define PI (ld)acos(-1)
#define endl '\n'
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl; 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define IO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const ld eps=(ld)1e-9;
const ll inf=(ll)1e9;
const ll mod=(ll)1e9+7;

void solve(){
	int n,W,w,v;
	cin>>n>>W;
	vector<vector<ll>>dp(2,vector<ll>(W+1,0));
	int t=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>w>>v;
		for (int j = 0; j <=W; ++j)
		{
			dp[t][j]=max(dp[!t][j],(j>=w?dp[!t][j-w]+v:0));
		}
		t=(!t);

	}
	cout<<dp[!t][W];
}

int main(){fio;
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}
return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
  
int main(){
  //入力
  int A,B,K;
  //int型で約2.1*10^9が最大値からok、又KはAとBの平均値からこれもok
  scanf("%d %d", &A,&B);

  //計算
  K = (A+B)/2;
  //A,Bは相異なる整数から、A-KとB-Kの符号が一致する事はない。
  //よってA<Bとすれば、A<K<Bであり、K=A+B/2となる。
  //よってKが整数の時にこれを出力すれば良い。

  //出力
  if((A+B)%2 == 0){
    printf("%d", K);
  }else{
    printf("IMPOSSIBLE");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define maxn 105000
using namespace std;
typedef long long ll;
const int inf=1e9;
int n;
ll a[100500],b[100500],c[100500];
ll X,Y;
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%lld",&a[i]);
	rep(i,1,n) scanf("%lld",&b[i]);
	rep(i,1,n) {
		c[i]=b[i]-a[i];
		X+=c[i];
		if (b[i]>a[i]) Y+=(b[i]-a[i])/2+(b[i]-a[i])%2;
	}
	if (X>=Y) puts("Yes");
	else puts("No");
	return 0;
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define stringtovector(s, v) {for (int i = 0; i < (s).size(); ++i) v.push_back(s[i]);};
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
const int mod = 1000000007;

int summ_of_digits(ll x) {
    x = abs(x);
    string s = to_string(x);
    ll c = 0;
    for (int i = 0; i < s.length(); i++) {
        c += ((ll)s[i] - (ll)'0');
    }
    return c;
}

int main() {
    int n,m;
    cin >> n >> m;
    cout << n * n - m;
}





Measured memory_bytes: 3624
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <functional>
#define all(x) (x).begin(),(x).end()

ll cnt[5] = {};
ll sum = 0;
void recursive_comb(int *indexes, int s, int rest, function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
    int n;
    cin >> n;
    string s[n];
    //int cnt[5] = {};
    for (int i = 0; i < n; i++){
        cin >> s[i];
        if (s[i][0] == 'M'){
            cnt[0]++;
        } else if (s[i][0] == 'A'){
            cnt[1]++;
        } else if (s[i][0] == 'R'){
            cnt[2]++;
        } else if (s[i][0] == 'C'){
            cnt[3]++;
        } else if (s[i][0] == 'H'){
            cnt[4]++;
        }
    }

    foreach_comb(5, 3, [](int *indexes) {
        sum += cnt[indexes[0]] * cnt[indexes[1]] * cnt[indexes[2]];
        //cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] << endl;
    });
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6144
// 隣接リストによる連結成分の判断
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;

    while (!S.empty()) {
        int u = S.top(); S.pop();
        for(int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (color[v] == NIL) {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor() {
    int id = 1;
    for(int i = 0; i < n; i++) color[i] = NIL;
    for(int u = 0; u < n; u++) {
        if (color[u] == NIL)
            dfs(u, id++);
    }
}

int main() {

    int s, t, m, q;

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for(int i = 0; i < q; i++) {
        cin >> s >> t;
        if (color[s] == color[t]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
 
   return 0;
}


Measured memory_bytes: 9020
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b%a==0){
		System.out.println(a+b);
		}else{
			System.out.println(b-a);
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, m;
  cin >> a >> b >> c >> d;
  m = max({a, b, c});
  for(int i = 0; i < d; i++) {
    m *= 2;
  }
  cout << a + b + c - max({a, b, c}) +  m << endl;
  return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int32 k;
  cin >> k;
  int32 n = s.size();
  REP(i,n-1){
    if(s[i] == 'a')continue;
    int32 need = 'z' - s[i] + 1;
    if(need <= k){
      s[i] = 'a';
      k -= need;
    }
  }
  s[n-1] = (s[n-1] - 'a' + k) % 26 + 'a';
  ANS(s);
  return 0;
}

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

int main() {
	vector<char> c;
	c.resize(5);

	int a, b, num, aa, cun = 0;
	cin >> a >> b;
	num = b - a;


	for (int i = 0; i <= num; i++) {
		aa = a + i;
		c[0] = aa % 10;
		aa /= 10;
		c[1] = aa % 10;
		aa /= 10;
		c[2] = aa % 10;
		aa /= 10;
		c[3] = aa % 10;
		aa /= 10;
		c[4] = aa % 10;
		if (c[0] == c[4] && c[1] == c[3]) {
			cun++;
		}
	}

	cout << cun << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
    ll x=0,w=0;char ch=getchar();
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w?-x:x;
}
bool com(ll x,ll y){return x>y;}
ll n,a[100005];
int main()
{
    n=read();
	for(reg ll i=1;i<=n;++i)
		a[i]=read();
	sort(a+1,a+1+n,com);
	for(reg ll i=1;i<=n;++i)
	{
		if(i+1>a[i+1])
		{
			ll j=i+1,an=0;
			while(a[j]==i)an++,j++;
			an%=2;
			if(an||((a[i]-i)&1))puts("First");
			else puts("Second");
			return 0;
		}
	}
}


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

int main(void) {
    int N; cin >> N;
    ll sum=0;
    for(int i=1; i<=N; i++)  {
        if(i%3 != 0 && i%5 !=0) sum+=i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;

int main() {
	string w;
	cin >> w;
	map<char, int> map;
	vector<char> word;

	for(char c : w) {
		if(map.count(c)) {
			map.at(c)++;
		} else {
			map[c] = 1;
			word.push_back(c);
		}
	}

	string ans = "Yes";
	for(char c : word) {
		if(map.at(c) % 2 != 0) ans = "No";
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[100001],b[100001];
int a1,a2,b1,b2;
int main(){
    cin>>n;
    for(int i=0,x,y;i<n;i+=2){
        cin>>x>>y;
        a[x]++;
        b[y]++;
    }
    for(int i=1;i<100001;i++){
        if(a[i]>=a[a1]){
            a2=a1;
            a1=i;
        }else if(a[i]>a[a2])a2=i;
        if(b[i]>=b[b1]){
            b2=b1;
            b1=i;
        }else if(b[i]>b[b2])b2=i;
    }
    if(a1!=b1)cout<<n-a[a1]-b[b1];
    else cout<<n-max(a[a1]+b[b2],a[a2]+b[b1]);
    return 0;
}

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

public class Main {

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException exp) {
                    throw new RuntimeException(exp);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {    //throws FileNotFoundException {
        InputStream inputStream = System.in;    //new FileInputStream("input.txt");
        OutputStream outputStream = System.out; //new FileOutputStream("output.txt");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task newTask = new Task();
        newTask.solve(in, out);

        out.close();
    }

    private static class Task {
        //.constant
        private final int INF = Integer.MAX_VALUE;
        private final int MOD = (int)1e9 + 7;

        //.data

        //.code
        public void solve(InputReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();

            for (int i = s.length() - t.length(); i >= 0; --i) {
                String sub = s.substring(i, i + t.length());
                boolean flag = true;
                for (int j = 0; j < t.length(); ++j) {
                    if (t.charAt(j) != sub.charAt(j) && sub.charAt(j) != '?') {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    StringBuilder ans = new StringBuilder();
                    for (int j = 0; j < i; ++j) {
                        ans.append((s.charAt(j) == '?') ? 'a' : s.charAt(j));
                    }
                    ans.append(t);
                    for (int j = i + t.length(); j < s.length(); ++j) {
                        ans.append((s.charAt(j) == '?') ? 'a' : s.charAt(j));
                    }
                    out.println(ans);
                    return;
                }
            }

            out.println("UNRESTORABLE");

        }//end

    }

}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long answer = 0;
  long N,D;
  long x,y;
  cin >> N >> D;
  for(int i = 0; i < N; i++){
    cin >> x >> y;
    if(x * x + y * y <= D * D){
      answer++;
    }
  }
  cout << answer << endl;
}

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

int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int buf[5];
	buf[0]=a;
	buf[1]=b;
	buf[2]=c;
	buf[3]=d;
	buf[4]=e;
	int res=0;
	int tmp[5];
	for(int i=0;i<5;i++)tmp[i]=buf[i];
	for(int i=0;i<5;i++){
		while(1){
			if(tmp[i]>10){
				tmp[i]%=10;
				//cout<<tmp[i];
			}else{
				//cout<<tmp[i];
				tmp[i]=10-tmp[i];
				if(tmp[i]==10)tmp[i]=0;
				//cout<<tmp[i]<<endl;
				break;
			}
		}
	}
	sort(tmp,tmp+5);
	//res+=tmp[4];
	//cout<<tmp[4]<<endl;
	for(int i=0;i<5;i++){
		while(1){
			if(buf[i]%10!=0){
				buf[i]++;
			}else{
				break;
			}
		}
	}
	for(int i=0;i<5;i++)res+=buf[i];
	res-=tmp[4];
	cout<<res<<endl;
}


Measured memory_bytes: 256
//! Framework <https://github.com/vain0x/procon>

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

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let X = scan.word::<i64>();
    let N = scan.word::<usize>();
    let p = scan.list::<i64>(N).into_iter().collect::<HashSet<_>>();

    let mut d = 0;
    let y = loop {
        if !p.contains(&(X- d)) {
            break X - d;
        }

        if !p.contains(&(X + d)) {
            break X + d;
        }
        d += 1;
    };

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


Measured memory_bytes: 2200
n = gets.chomp.to_i
plist = gets.chomp.split.collect{ |item| item.to_i}

result = 0
(n-2).times do |i|
  pl = plist[i]
  pc = plist[i+1]
  pr = plist[i+2]
  if pl < pc && pc < pr
    result += 1
  elsif pr < pc && pc < pl
    result += 1
  end
end

puts result

Measured memory_bytes: 1788
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,x,y,ans;
void solve()
{
    cin>>n;set<ll>st;
    for(int i=0;i<=n;i++)
    {ll a;cin>>a;
    st.insert(a);
    }
    ll temp=*st.begin();
    for(auto &it:st)
    {
        if(it==temp)    continue;
       ll  diff=it-temp;
        if(ans==0)
            ans=diff;
        else
            ans=__gcd(diff,ans);
        temp=it;
    }
    debug(ans);
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

int N;
bool ada = false;

int main (){
    cin >> N;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j ==N) {
                ada = true;
            }
        }
    }
    if(ada) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
//indi

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

const int MAXN = 200 + 10;
const int MOD = 998244353;

struct TPoint
{
	long long x, y;
};

long long CrossProduct(TPoint A, TPoint B, TPoint C)
{
	return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}

int n;
long long twomod[MAXN];
long long C[MAXN][MAXN];
long long arr[MAXN];
TPoint p[MAXN];
int used[MAXN];
int redu[MAXN];

void Work()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i ++)
		scanf("%lld%lld", &p[i].x, &p[i].y);
	twomod[0] = 1;
	for (int i = 1; i <= n; i ++)
		twomod[i] = (twomod[i - 1] + twomod[i - 1]) % MOD;
	C[0][0] = 1;
	for (int i = 1; i <= n; i ++)
	{
		C[i][0] = 1;
		for (int j = 1; j <= i; j ++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
	}

	for (int tt = 3; tt <= n; tt ++)
	{
		arr[tt] = 0;
		for (int i = 3; i <= tt; i ++)
			arr[tt] = (arr[tt] + C[tt][i]) % MOD;
	}

	long long ans = arr[n];
	
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < n; j ++) if (i != j)
		{
			long long c = 2;
			for (int k = 0; k < n; k ++) if (i != k && j != k)
				if (CrossProduct(p[i], p[j], p[k]) == 0)
					c ++;
			//printf("%d %d %d\n", i, j, c);
			redu[c] ++;
		}

	for (int c = 3; c <= n; c ++)
	{
		if (redu[c] == 0) continue;
		long long times = redu[c] / (c * (c - 1));
		ans -= (arr[c] * times) % MOD;
		ans += MOD;
		ans %= MOD;
	}

	printf("%lld\n", ans);
}

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
 
#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

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

    ll n,m;
    cin >> n >> m;
    vector<int> h(n);
    set<int> ans;
    set<int> history;//道があるかどうか
    set<int> out;
    rep(i,n){
        cin >> h[i];
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;

        history.insert(a); 
        history.insert(b);

        if(h[a-1] > h[b-1]){ 
    if(!out.count(a-1)) ans.insert(a-1);
    out.insert(b-1);
    if(ans.count(b-1)){
        ans.erase(b-1);
    }
}else if(h[b-1] > h[a-1]){
    if(!out.count(b-1))ans.insert(b-1);
    out.insert(a-1);
    if(ans.count(a-1)){
        ans.erase(a-1);
    }
}else if(h[a-1] == h[b-1]){ // 以下追加分
    out.insert(a-1);
    if(ans.count(a-1)){
        ans.erase(a-1);
    }
    out.insert(b-1);
    if(ans.count(b-1)){
        ans.erase(b-1);
    }
}
    }
    int number;
    number = n - history.size();//道がない展望台の個数
    cout << number + ans.size() << endl;

    cout << endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vb = vector<bool>;
using vbb = vector<vb>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

int h, w;

void dfs(int y, int x, const vs &f, vbb &seen, ll &W, ll &B) {
  seen[y][x] = true;
  if(f[y][x] == '#') B++;
  else W++;
  rep(i,4) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
    if(seen[ny][nx] || f[y][x] == f[ny][nx]) continue;
    dfs(ny, nx, f, seen, W, B);
  }
  return;
}

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

  cin >> h >> w;
  vs f(h);
  rep(i,h) cin >> f[i];

  vector<vector<bool>> seen(h,vector<bool>(w));
  ll ans = 0;
  rep(i,h) {
    rep(j,w) {
      if(!seen[i][j]) {
        ll W = 0, B = 0;
        dfs(i,j,f,seen,W,B);
        ans += W*B;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n,x,y,ans; cin>>n;
    
    x = n/500;
    y = (n%500)/5;
    
    ans = 1000*x + 5*y;
    
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import fractions
A, B, C, D = map(int, input().split())

B_C = B // C
B_D = B // D
B_CD = B // ((C * D) // fractions.gcd(C, D))

B_count = B - B_C - B_D + B_CD

A_C = (A - 1) // C
A_D = (A - 1) // D
A_CD = (A - 1) // ((C * D) // fractions.gcd(C, D))

A_count = (A - 1) - A_C - A_D + A_CD

print(B_count - A_count)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int k;
    cin>>k;
    ll sum = 0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int p=1;p<=k;p++)
            {
                sum += (__gcd(i,__gcd(j,p)));
            }
        }
    }
    cout<<sum;
    return 0;
}


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

int gcd(int a,int b){
	if(a==0)
	return b;
	if(b==0)
	return a;
	if(a==b)
	return a;
	if(a>b)
	return gcd(a-b,b);
	return gcd(a,b-a);
}

int GCD(int a,int b){
	if(a==0)
	return b;
	if(b==0)
	return a;
	if(a==b)
	return a;
	return GCD(b,a%b);
}

int main(){
	ll a,b;
	cin>>a>>b;
	if((a+b)%2==0){
		cout<<(a+b)/2<<endl;
		
	}
	else
	cout<<"IMPOSSIBLE"<<endl;
}

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll d[n],c[n];
    ll sum =0;
    for(int i=0;i<n;i++){
        cin>>d[i]>>c[i];
        sum += c[i];
    }
    ll now = d[0];
    c[0]--;
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll cnt=0;
        ll tmp = now;
        ll t=0;
        while(true){
            t++;
            tmp += d[i];
            while(tmp>=10){
                cnt++;
                tmp = (tmp/10) + tmp%10;
            }
            if(now == tmp) break;
        }
        ll ret = c[i]/t;
        ans += cnt * ret;
        c[i] %= t;
        for(int j=0;j<c[i];j++){
            now += d[i];
            while(now>=10){
                now = (now/10) + now%10;
                ans++;
            }
        }
    }
    ans += sum-1;
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n,a,x,y,ans=0;
  cin >> n;
  vector<vector<pair<int,int>>> v(n);
  rep(i,n){
     cin>>a;
     rep(j,a){
        cin>>x>>y;
        v[i].push_back(make_pair(x-1,y)); 
     } 
  }
  rep(i,pow(2,n)){
     bitset<15> b(i);
     int f=0;
     rep(j,n){
        if(b.test(j))
          rep(k,v[j].size())
            if(b[v[j][k].first]!=v[j][k].second){
               f =1;
               break;
            }
        if(f)
           break;
     }
     if(!f) 
     ans=max(ans,(int)b.count());
  }
  cout<<ans;
  return 0;
}

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

struct Point{ int t, p;};

int T[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
	       {0, 0, 300, 500, 600, 700, 1350, 1650},
	       {0, 6, 0, 350, 450, 600, 1150, 1500},
	       {0, 13, 7, 0, 250, 400, 1000, 1350},
	       {0, 18, 12, 5, 0, 250, 850, 1300},
	       {0, 23, 17, 10, 5, 0, 600, 1150},
	       {0, 43, 37, 30, 25, 20, 0, 500},
	       {0, 58, 52, 45, 40, 35, 15,0}};

main(){
    Point s, d;
    int cost, h, m;
    while(1){
	cin >> s.p;
	if ( s.p == 0 ) break;
	cin >> h >> m; s.t = h*60 + m;
	cin >> d.p;
	cin >> h >> m; d.t = h*60 + m;
	cost = T[s.p][d.p];
	if ( 1050 <= s.t && s.t <= 1170 ||
	     1050 <= d.t && d.t <= 1170 ){
	    if ( T[d.p][s.p] <= 40 ) cost /=  2;
	}
	if ( cost % 50 ) cost += 25;
	cout << cost << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,d[100];
    cin>>n;
    for(int i=0;i<n;i++) cin>>d[i];
    long long sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum;
}


Measured memory_bytes: 256
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    #複数行の「1 2 3 4」型の入力を一配列に
    #x = sorted([list(map(int, input().split())) for _ in range(n)])
    #ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  x=[[0 for _ in range(n)] for _ in range(n)]
    n=int(input())
    a = list(map(int,input().split()))
    cnt=0
    index=0
    while index<n:
        if a[index]==index+1:
            cnt+=1
            index+=2
        else:
            index+=1
    print(cnt)
       
main()

Measured memory_bytes: 52332
#include <bits/stdc++.h>
using namespace std;
using Vi = vector<int>;
using VVi = vector<Vi>;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)

void solve() {
  int N;
  cin >> N;
  VVi g(N, Vi(N, -1));
  rep(i, 0, N) {
    int a;
    cin >> a;
    rep(j, 0, a) {
      int x, y;
      cin >> x >> y;
      g[i][--x] = y;
    }
  }

  int ans = 0;
  for (int b = 0; b < (1 << N); b++) {
    bitset<15> bs(b);
    bool ok = true;
    rep(i, 0, N) {
      if (bs.test(i)) {
        rep(j, 0, N) {
          if (g[i][j] == -1) continue;
          if (g[i][j] != bs.test(j)) ok = false;
        }
      }
    }
    if (ok) ans = max(ans, (int)bs.count());
  }
  cout << ans << endl;
}

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

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	string S; cin >> S;
	auto is_palindrome = [&](string T) -> bool {
		return T == string(T.rbegin(), T.rend());
	};
	int N = int(S.size());
	int M = (N-1) / 2;
	if (is_palindrome(S) && is_palindrome(S.substr(0, M)) && is_palindrome(S.substr(N-M, M))) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
 
namespace Sample
{
  // 拡張クラス
  static class Sample
  {
    static void Main()
    {
      string s = Console.ReadLine();
      string t = Console.ReadLine();
      
      string[] sarr =  s.MySplit(1);
      string[] tarr =  t.MySplit(1);

      int score = tarr.Length;

      for(int i=0; i<=(sarr.Length-tarr.Length); i++){
          int subcount = 0;
          for(int j=0; j<tarr.Length; j++){
              if(!sarr[i+j].Equals(tarr[j])){
                  subcount++;
              }
          }
          if (subcount < score) {
              score = subcount;
          }
    
        }
        Console.WriteLine(Convert.ToString(score));
    }  
    
    // 拡張メソッド
    static string[] MySplit(this string str, int count) {
      var list = new List<string>();
      int length = (int)Math.Ceiling((double)str.Length / count);
      
      for(int i = 0; i < length; i++) {
        int start = count * i;
        if(str.Length <= start) {
          break;
        }
        if(str.Length < start + count) {
          list.Add(str.Substring(start));
        } else {
          list.Add(str.Substring(start, count));
        }
      }
      
      return list.ToArray();
    }
  }
}

Measured memory_bytes: 26144
#include<bits/stdc++.h>
#define SIZE 2000005
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


// 二項係数計算
long long C(long long  n){
    if (n < 2) return 0;
    //if (n < 0) return 0;
    return (n*(n-1))/2;
}
//status unsolved
int main(){
    //make();
    int n;
    cin>>n;
    long long A[n];
    long long cnt[n+1]={};
    //long long r[n+1];
    rep(i,n)
    {
        cin>>A[i];
        cnt[A[i]]++;
    }
    long long ans=0;
    
    rep2(i,n){
        ans+=C(cnt[i]);
    }
    //rep(i,n)r[A[i]]=C(cnt[A[i]]-1);
    rep(i,n){
        cout<<ans-(cnt[A[i]]-1)<<endl;
    }

    return 0;

}
/*


*/


Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>

#define U1 unsigned char
#define S1 char
#define	S4 int
#define S8 long

#define TRUE					(1)
#define FALSE					(0)

#define MAX_NUM_SHOP			(100000)      /* 最大店舗数 */
#define MAX_NUM_DEST			(10000)       /* 最大宅配先数 */
#define FIRST_BRANCH_SHOP_IDX	(1)           /* 本店に右回りの距離が最も近い支店のインデックス */
#define NEXT_SHOP				(1)           /* 隣接する店 */

/* qsort用比較関数 */
int comp(const void* vd_ap_var1, const void* vd_ap_var2)
{
	return *(S8*)vd_ap_var1 - *(S8*)vd_ap_var2;
}

S4 main()
{
	/* 変数宣言 */
	S8 s8_t_length;						/* 道の長さ */
	S4 s4_t_numShop;					/* 店舗数 */
	S4 s4_t_shopIndex;					/* 店舗位置インデックス */
	S8 s8_tp_shop[MAX_NUM_SHOP + 1];	/* 店舗位置 */
	S4 s4_t_numDest;					/* 宅配先数*/
	S4 s4_t_destIndex;					/* 宅配先位置インデックス */
	S8 s8_tp_dest[MAX_NUM_DEST + 1];	/* 宅配先位置 */
	U1 u1_t_delimiter;					/* scanfで\nを捨てるための変数 */
	S8 s8_t_sumDistance;				/* 店舗から配達先までの距離の総和 */
	S8 s8_t_distanceBefore;				/* 配達先の直前の店舗からの距離 */
	S8 s8_t_distanceAfter;				/* 配達先の直後の店舗からの距離 */
	U1 u1_t_isEndCalc;					/* 計算終了フラグ */

	u1_t_isEndCalc = (U1)FALSE;

	while (u1_t_isEndCalc != (U1)TRUE)
	{
		/* 終了が入力される可能性があるのはデータセットの初めのデータのみ */
		scanf("%ld%c", &s8_t_length, &u1_t_delimiter);
		if (s8_t_length == (S8)0)	/* 0が入力されたら終了 */
		{
			u1_t_isEndCalc = (U1)TRUE;
		}
		else
		{
			scanf("%d%c", &s4_t_numShop, &u1_t_delimiter);
			scanf("%d%c", &s4_t_numDest, &u1_t_delimiter);

			/* 店舗位置入力 */
			s8_tp_shop[0] = (S8)0;	/* 本店 */
			for (s4_t_shopIndex = (S4)FIRST_BRANCH_SHOP_IDX; s4_t_shopIndex < s4_t_numShop; s4_t_shopIndex++)
			{
				scanf("%ld%c", &s8_tp_shop[s4_t_shopIndex], &u1_t_delimiter);
			}
			/* 本店から右回りの距離が最も遠い配達先の計算のために使用する値を設定 */
			s8_tp_shop[s4_t_numShop] = s8_t_length;

			/* 計算高速化のため店舗位置を本店から右回りの距離順にソート */
			qsort(&s8_tp_shop[0], s4_t_numShop, sizeof(S8), comp);

			/* 配達位置入力 */
			for (s4_t_destIndex = (S4)0; s4_t_destIndex < s4_t_numDest; s4_t_destIndex++)
			{
				scanf("%ld%c", &s8_tp_dest[s4_t_destIndex], &u1_t_delimiter);
			}

			/* 計算高速化のため配達位置を本店から右回りの距離順にソート */
			qsort(&s8_tp_dest[0], s4_t_numDest, sizeof(S8), comp);

			/* 店舗から配達先の最短距離を計算 */
			s8_t_sumDistance = (S8)0;
			s4_t_shopIndex = (S8)FIRST_BRANCH_SHOP_IDX;	/* 本店の位置が、配達先の位置を超えることは無い */
			s4_t_destIndex = (S4)0;
			while ((s4_t_shopIndex < s4_t_numShop + (S4)NEXT_SHOP) &&  /* 本店から右回りの距離が最も遠い配達先も計算するため+1 */
				(s4_t_destIndex < s4_t_numDest))
			{
				/* 配達先に隣接する店舗の場合 */
				if (s8_tp_shop[s4_t_shopIndex] >= s8_tp_dest[s4_t_destIndex])
				{
					s8_t_distanceBefore = s8_tp_dest[s4_t_destIndex] - s8_tp_shop[s4_t_shopIndex - (S4)NEXT_SHOP];
					s8_t_distanceAfter = s8_tp_shop[s4_t_shopIndex] - s8_tp_dest[s4_t_destIndex];

					/* 配達先から近い方の店舗までの距離を加算 */
					if (s8_t_distanceBefore >= s8_t_distanceAfter)
					{
						s8_t_sumDistance += s8_t_distanceAfter;
					}
					else
					{
						s8_t_sumDistance += s8_t_distanceBefore;
					}

					/* 次の配達先が同じ店舗に隣接しているか確認 */
					s4_t_destIndex++;
				}
				else
				{
					/* 次の店舗が配達先に隣接しているか確認 */
					s4_t_shopIndex++;
				}
			}
			printf("%ld\n", s8_t_sumDistance);
		}
	}

	return((S4)0);
}
 


Measured memory_bytes: 3240
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1<<30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define UP(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
using ll = long long;
using Pll = pair<ll,ll>;
using Pii = pair<int,int>;
using Pdd = pair<double,double>;
using dcomplex = complex<double>;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;for(ll i=1;i<=a;i++)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}
ll nbit(ll n){ll ret=0;while(n){n&=n-1;++ret;} return ret;}
double inf() {return std::numeric_limits<double>::infinity();}

ll K;
deque<pair<ll,ll>> q;

int main(int argc, char const *argv[]) {
  cin >> K;
  vector<ll> dist(K,INF);
  ll ans = INF;
  dist[0] = 0;
  q.push_back(make_pair(0,0));
  while(q.size()>0) {
    auto x = q.front(); q.pop_front();
    if(x.second > dist[x.first]) continue;
    REP(i,10) {
      ll u = (x.first*10 + i) % K;
      ll v = x.second+i;
      if(u==0 && v>0) ans=min(ans,v);
      if(v < dist[u]) {
        dist[u] = v;
        if(i==0) q.push_front(make_pair(u, dist[u]));
        else q.push_back(make_pair(u,dist[u]));
      }
    }
  }
  // priv(dist);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6272
#include <iostream>

using namespace std;

int main()
{
    int n, t[101], sum, m, p, x;
    cin >> n;
    sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> p >> x;
        cout << sum - t[p - 1] + x << endl;
    }
    return 0;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;

void input() {
  IN(N);
}

void solve() {
  int cnt = 0;
  REP(i, N) {
    ll num = i+1;
    ll tmp;
    IN(tmp);
    if (tmp != num) {
      cnt++;
    }
  }
  if (cnt == 2 || cnt == 0) {
    PRINT("YES");
  } else {
    PRINT("NO");
  }
}

int main(void){
  input();
  solve();
}


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

//read_code(drken)
int h,w;
vector<string> a;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    cin>>h>>w;
    a.resize(h);
    rep(i,h)cin>>a[i];
    vector<vector<int>>dist(h,vector<int>(w,-1));
    using pint = pair<int,int>;
    queue<pint>que;
    rep(i,h)rep(j,w)if(a[i][j]=='#'){
        dist[i][j]=0;
        que.push(pint(i,j));
    }
    
    while(!que.empty()){
        auto cur = que.front();
        que.pop();
        rep(i,4){
            int nx = cur.first + dx[i];
            int ny = cur.second + dy[i];
            if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
            if(dist[nx][ny]==-1){
                dist[nx][ny]= dist[cur.first][cur.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }
    
    int ans = 0;
    rep(i,h)rep(j,w)ans=max(ans, dist[i][j]);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17172