akhauriyash/Code-Regression huggingface dataset:
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <ctime>
#include <memory.h>
#include <bitset>
#include <climits>
#include <iomanip>

#define F first
#define S second
#define endl "\n"
#define pb push_back
#define mp make_pair
#define bs 1000000007
#define pi 3.141592653589793
#define y1 kjdfshnvoavaofobiopj
#define ends wieyryrqayreryueyrye
using namespace std;

long long n, found[100010];
bool error;

long long pw(long long a,long long b)
{
     if (b==0)return 1;
     if (b&1)return (a*pw(a,b-1))%bs;
     return pw(a*a%bs,b/2);
}

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

cin>>n;
for(long long i = 0; i < n; i++)
{
    long long xs;  cin>>xs;
    ++found[xs];
}
if(n&1)
{
    if(found[0] != 1)
        error = true;
    for(long long i = 2; i < n; i+=2)
        if(found[i] != 2)
            error = true;
}
else
{
    for(long long i = 1; i < n; i+=2)
        if(found[i] != 2)
            error = true;
}
if(error)
    cout<<0<<endl;
else
    cout<<pw(2, n/2)<<endl;


return 0;}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPalace solver = new BPalace();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPalace {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), t = in.ints() * 1000, a = in.ints() * 1000;
            Long min = Long.MAX_VALUE;
            int index = -1;
            for (int i = 0; i < n; i++) {
                int h = in.ints();
                long abs = Math.abs(a - t + 6 * h);
                if (abs < min) {
                    min = abs;
                    index = i;
                }
            }
            out.println(index + 1);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 22868
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<long long> accum(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        accum[i] = accum[i - 1] + a[i - 1];
    }
    map<long long, long long> cnt;
    for (auto t : accum)
        cnt[t]++;

    long long ans = 0;
    for (auto t : cnt) {
        ans += t.second * (t.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
N=input()
n=int(N)
K=int(input())
import math

l=len(N)

if l==1:
  if K==1:
    print(N)
  else:
    print(0)
else:
  a=[0]*3
  b=[l]*3
  k=0
  for i in range(l):
    if int(N[i])!=0:
      a[k]=int(N[i])
      b[k]=i
      k+=1
    if k==3:
      break
  #print(a,b,l)
  x=0
  for i in range(l-1):
    if K==1:
      x+=9
    elif K==2:
      x+=81*i
    else:
      x+=(729*i*(i-1))//2
  
  if K==1:
    x+=a[0]
  elif K==2:
    x+=(a[0]-1)*9*(l-1)+max([0,(l-b[1]-1)*9])+a[1]
  else:
    x+=((a[0]-1)*81*(l-2)*(l-1))//2
    x+=(81*max([0,(l-b[1]-1)])*max([0,(l-b[1]-2)]))//2
    x+=max([0,(a[1]-1)])*9*max([0,(l-b[1]-1)])
    x+=9*max([0,(l-b[2]-1)])+a[2]
  
  print(x)

Measured memory_bytes: 3064
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 (a % 2 == 1 && b % 2 == 1) {
            System.out.println("Yes");
        } else {

            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23892
N = gets.to_i
h = gets.split.map &:to_i 
dp = Array.new(N+1,1<<31)
dp[0] = 0
(0..N-2).each{|i|
    dp[i+1] = [(h[i+1] - h[i]).abs + dp[i], dp[i+1]].min
    if i + 2 < N
        dp[i+2] = [(h[i+2] - h[i]).abs + dp[i], dp[i+2]].min
    end
}
puts dp[N-1]

Measured memory_bytes: 13316
import java.util.*;
import java.lang.Math;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int number_of_elements = sc.nextInt();
      	int intArray[] = new int[number_of_elements];
      	int index = 0;
      	while(sc.hasNextInt()){
          intArray[index++] = sc.nextInt();
        }
      int dpArray[] = new int[intArray.length];
      int cost = 0;
      int dpArray0=0;
      int dpArray1=Math.abs(intArray[1]-intArray[0]);
      for(int i =2 ;i<dpArray.length;i++){
        int dpArray2 = dpArray1;
      	dpArray1=Math.min(dpArray0+Math.abs(intArray[i]-intArray[i-2]),dpArray1+Math.abs(intArray[i]-intArray[i-1]));
        dpArray0 = dpArray2;
      }
      System.out.println(dpArray1);
	}
}


Measured memory_bytes: 50240
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int r; cin>>r;
    cout << r * r << endl;

    return 0;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  cout << (2 * k * k * k - 3 * k * k * n - 6 * k * k + 3 * k * n - 2 * k + 
           n * n * n + 3 * n * n + 8 * n + 12) / 6 % 1000000007 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
   string s, t;
   cin >> s >> t;
   int n = s.length(), m = t.length();
   int dp[n + 1][m + 1];
   memset(dp, 0, sizeof(dp));
   for(int i = 1;i <= n;++i){
       for(int j = 1;j <= m;++j){
           if(s[i - 1] == t[j - 1]){
               dp[i][j] = dp[i - 1][j - 1] + 1;
           }
           else{
               dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
               
           }
       }
   }
   string ans = "";
   int i = n, j = m;
   while(i >= 1 && j >= 1){
        if(s[i - 1] == t[j - 1]){
            ans += s[i - 1];
            --i;
            --j;
        }
        else if(dp[i - 1][j] > dp[i][j - 1]) --i;
        else --j;
   }
   reverse(ans.begin(), ans.end());
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

void long_search(const string& s, const string& t, const int st_start, vector<string>& dp1, vector<string>& dp2){

  if(st_start+1 <= s.size() + t.size() + 2) long_search(s, t, st_start+1, dp1, dp2);

  int hight = min(st_start+1, (int)s.size());
  for(int s_start=max(0, st_start-(int)t.size()+1); s_start<hight; ++s_start){
    int t_start = st_start-s_start;

    if(s[s_start] == t[t_start]){
      dp2[s_start] = s[s_start] + dp2[s_start+1];
    }else{
      if(dp1[s_start].size() > dp1[s_start+1].size()){
        dp2[s_start] = dp1[s_start];
      }else{
        dp2[s_start] = dp1[s_start+1];
      }
    }
    swap(dp1[s_start], dp2[s_start]);
    /*
    auto tmp = dp2[s_start];
    dp2[s_start] = dp1[s_start];
    dp1[s_start] = tmp;
    */
  }
  swap(dp1[hight], dp2[hight]);

  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string s, t;
  cin >> s >> t;
  if(s.size() > t.size()) swap(s, t);
  vector<string> dp1(s.size()+2, "");
  vector<string> dp2(s.size()+2, "");
  long_search(s, t, 0, dp1, dp2);

  cout << dp1[0] << "\n";

  return 0;
}

Measured memory_bytes: 11008
n = gets.to_i

dp = Array.new(n + 1, 100000)
dp[0] = 0

m = [1]
x = 6
while x <= n do
  m << x
  x *= 6
end
x = 9
while x <= n do
  m << x
  x *= 9
end

(1..n).each do |i|
  m.each do |j|
    if i - j >= 0
      dp[i] = [dp[i], dp[i - j] + 1].min
    end
  end
end

puts dp[n]


Measured memory_bytes: 2556
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define int long long
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld",&n);
	n=n*n;
	printf("%lld\n",n);
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a + b == 0) break;
			int[][] dp = new int[a][b];
			int n = sc.nextInt();
			for(int i = 0; i < n; i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				dp[x - 1][y - 1] = -1;
			}
			dp[0][0] = 1;
			for(int i = 1; i < a; i++) {
				if(dp[i][0] != -1) {
					dp[i][0] = dp[i - 1][0];
				}else {
					dp[i][0] = 0;
				}
			}
			for(int j = 1; j < b; j++) {
				if(dp[0][j] != -1) {
					dp[0][j] = dp[0][j - 1];
				}else {
					dp[0][j] = 0;
				}
			}
			for(int i = 1; i < a; i++) {
				for(int j = 1; j < b; j++) {
					if(dp[i][j] != -1) {
						dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
					}else {
						dp[i][j] = 0;
					}
				}
			}
			
//			for(int i = 0; i < a; i++) {
//				for(int j = 0; j < b; j++) {
//					System.out.print(dp[i][j] + " ");
//				}
//				System.out.println();
//			}
			
			System.out.println(dp[a - 1][b - 1]);
		}
	}

}



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

using namespace std;
typedef long double ld;

int main()
{
  int n, k; cin >> n >> k;
  vector<ld> p(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  ld sum = 0;
  for(int i = 0; i < k; i++) sum += p[i] * (p[i] + 1)/2/p[i];
  ld best = sum;
  for(int i = k; i < n; i++)
  {
    sum += p[i] * (p[i] + 1)/2/p[i];
    sum -= p[i - k] * (p[i - k] + 1)/2/p[i - k];
    best = max(best, sum);
  }
  cout << setprecision(20);
  cout << fixed;
  cout << best;

  return 0;
}

Measured memory_bytes: 3328
import bisect

N = int(input())
P = list(map(int, input().split()))
P_inv = [0]*N

for i in range(N):
    P_inv[P[i] - 1] = i

c = [-1,-1, P_inv[N - 1] ,N,N]
cnt = 0
for i in reversed(range(N - 1)):
    l = bisect.bisect_left(c, P_inv[i])
    cnt += (i + 1) * ((c[l - 1] - c[l - 2]) * (c[l] - P_inv[i]) + (P_inv[i] - c[l - 1]) * (c[l + 1] - c[l]))
    bisect.insort_left(c, P_inv[i])

print(cnt)

Measured memory_bytes: 83972
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  int X=(a+d-1)/d;
  int Y=(c+b-1)/b;
  cout<<(X>=Y?"Yes":"No")<<"\n";
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, M, ans;
    cin >> N >> M;
    vector<vector<int>> jobs(M);
    REP(ll, i, 0, N){
        int a,b;
        cin >> a >> b;
        if (a > M) continue;
        jobs[M-a].push_back(b);
    }
    priority_queue<int> JobList;
    int Day = 0;
    ans = 0;
    while( M > 0 ){
        if ( jobs[M-1].size() > 0 ){
            for ( ll s : jobs[M-1]){
                JobList.push(s);
            }
        }
        if ( JobList.size() > 0 ){
            ans += JobList.top();
            JobList.pop();
        }
        M--;
    }
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 5504
arr = input().split()

n = int(arr[0])
l = int(arr[1])
s = 0
arr2 = []
for i in range(0,n):
  s += l + i
  arr2.append(l + i)
  
minimum = l + n - 1

for i in range(0, n):
  minimum = min(minimum, abs(arr2[i]))
  
print(s-minimum)
                
 


Measured memory_bytes: 9076
s = input()
c1, c2, c3 = False, False, False
#print(c1, c2, c3)
import re
#print(s[2:-1])

if s[0] == "A":
  c1 = True
if s[2:-1].find("C") >= 0:
  c2 = True
if len(re.findall("[a-z]", s)) == len(s)-2:
  c3 = True
#print(c1, c2, c3)
#print(len(re.findall("[a-z]", s)))

if c1 and c2 and c3:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    int a[1000],b[1000],c[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    for(i=0;i<n;i++){
        if((c[i]*c[i])==(a[i]*a[i]+b[i]*b[i])||(a[i]*a[i])==(b[i]*b[i]+c[i]*c[i])||(b[i]*b[i])==(a[i]*a[i]+c[i]*c[i])){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}
 

Measured memory_bytes: 2636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>

int main (){
	int n, k;

	std::cin >> n >> k;

	int count = 0;
	for (size_t i = 0; i < n; i++)
	{
		int a;

		std::cin >> a;

		if (a >= k) {
			count++;
		}
	}

	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 256
/*
	Author: Hamza Hasbi
	Copyrights: "h.hamza" ==> "www.hamzahasbi.me"
	Date: 20/08/2017 12:55:17
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define uld unsigned long double
#define ui unsigned int
#define ud unsigned double
#define uf unsigned float
#define pi 2*acos(0.0)
#define module cin.ignore()
#define rep(i,l,r) for(auto i=l;i<=r;i++)
#define range(x,y) for(auto x:y)
//inline long longlcm(ll a,ll b) {return a*b/__gcd(a,b);}
//inline long long gcd(ll a,ll b) {return 1LL*b == 0 ? a : gcd(1LL*b, a*1LL % b*1LL);}
using namespace std;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin>>s;
	map<char,bool>mp;
	for(auto c:s) mp[c]=true;
	for(char i='a';i<='z';i++) {
		if(!mp[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	
	
	return 0;
}


Measured memory_bytes: 512
n,x,y=map(int,input().split())
mxN=3005
ans=[0]*mxN
x-=1
y-=1
for i in range(n):
    for j in range(i+1,n):
        x1=min(j-i,(abs(i-x)+abs(j-y)+1))
        ans[x1]+=1
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 3444
#create date: 2020-03-18 07:40

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b, k = na()
    for i in range(k):
        b += a//2
        a //= 2
        a, b = b, a
    if k % 2 == 1:
        a, b = b, a
    print(a, b)

if __name__ == "__main__":
    main()

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

int main() {
  int N ,A_i ,c = 30;
  cin >> N;
  
  rep(i,N){
    cin >> A_i;
    
    for(int j = 0; 1; j++){
      if(A_i == (A_i / 2) *2){
        A_i = A_i / 2;
        continue;
      }
      
      else{
        if(c > j){
          c = j;
          break;
        }
        else{
          break;
        }
      }
    }
  }
  
  cout << c << endl;
}


Measured memory_bytes: 3632
n = int(input())
s = input()
mod = 10**9 + 7
car = [0] * 26

for i in range(n):
	car[ord(s[i])-97] += 1

ans = 1
for i in range(26):
	if car[i] == 0:
		continue
	else:
		ans *= (car[i]+1)
		ans %= mod

print(ans - 1)

Measured memory_bytes: 3188
n, m = map(int,(input().split()))
d = []
for i in range(n):
    a, b = map(int,(input().split()))
    d.append([a,b])
d = sorted(d)
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
        if m <= 0:
            break
print(ans)


Measured memory_bytes: 20824
#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))
//-------------------------------------------------------


ll A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	C-=A+B;
	if(C>0 && 4*A*B<C*C) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<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: 256
n, m = map(int, input().split())
p = [int(i) for i in input().split()]
graph = [[] for _ in range(n+1)]
group = [0]*(n+1)
ans = 0
for _ in range(m):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
for i, num in enumerate(p, 1):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i
        space.extend(graph[point])
    ans += group[num] == group[i]
print(ans)

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

const int MAX_N = 200000;
int n, m;
vector<vector<int>> G(MAX_N); //隣接リスト
bool used[MAX_N]; // 訪問済みかどうか

int dfs(int v) {
  used[v] = true;
  
  int d = 1;
  for (int i = 0; i < G[v].size(); i++) {
    int next = G[v][i];
    if (!used[next]) {
      d += dfs(next);
    }
  }
  return d;
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    // 辺を張る
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int d = dfs(i);
    ans = max(ans, d);
  }
  
  cout << ans;
}

Measured memory_bytes: 20400
a = set([1,3,5,7,8,10,12])
b = set([4,6,9,11])
c = set([2])

x,y = input().split()
x = int(x)
y = int(y)

if (((x in a) and (y in a)) or ((x in b) and (y in b)) or ((x in c) and (y in c))):
    print("Yes")
else:
    print("No")


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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> T(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> T[i];
  }
  int M;
  std::cin >> M;
  std::vector<int> P(M);
  std::vector<int> X(M);
  for (int i = 0; i < M; ++i) {
    std::cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; ++i) {
    int time = 0;
    for (int j = 0; j < N; ++j) {
      if ( P[i] - 1 == j ) time += X[i];
      else time += T[j];
    }
    std::cout << time << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll h;
  ll s=0;
  ll l=0;
  for(int i=0;i<n;i++){
    cin >> h;
    if(l<=h)s++;
    l=max(l,h);
  }
  cout << s << endl;

}

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

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

    for (int i = 1; i <= n; i++)
        {
            int x = i;
            if (x % 3 == 0)
            {
                cout << " " << i;
            }
            else
            {
                while (true)
                {
                    if (x % 10 == 3)
                    {
                        cout << " " << i;
                        break;
                    }
                    if ((x /= 10) == 0)
                    {
                        break;
                    }
                }
            }
            
            
        }
        cout << endl;
        return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long POW(long long x,long long n,long long mod){
  long long ans = 1;
  while(n){
    if(n%2)ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}
vector<long long> factorial(2,1);
long long nckmodp(long long n,long long k,long long p){
  if(n < k || n <= 0 || k < 0)return 0;
  while(factorial.size() <= n){
    long long i = factorial.size();
    factorial.push_back(i*factorial[i-1]%p);
  }
  return ((factorial[n]*POW(factorial[k],p-2,p))%p)*POW(factorial[n-k],p-2,p)%p;
}
long long TwelvefoldWay5(long long n,long long k,long long MOD){
  return nckmodp(k,n,MOD);
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << TwelvefoldWay5(n,k,INF) << endl;
}


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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

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

    int ar[n];
    int ex = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> ar[i];
        ex ^= ar[i];
    }

    for (int i = 0; i < n; i++)
        cout << (ex ^ ar[i]) << ' ';
    cout << endl;
}

Measured memory_bytes: 4396
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int main()
{
     
    string x;
    cin >> x ;
    if (x[2] == x[3] && x[4] == x[5])
    cout <<"Yes\n"; 
    else 
    cout <<"No\n"; 
}


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

int e[9][9];
int main(void){
	int N,M;
	cin >> N >> M;

	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;a--;b--;
		// es[a].push_back(b);
		// es[b].push_back(a);
		e[a][b] = e[b][a] = 1;
	}

	vector<int> path(N);
	for(int i=0;i<N;i++)
		path[i] = i;
	
	int cnt = 0;
	do{
		bool ch = true;
		for(int i=0;i<N-1;i++){
			if( e[path[i]][path[i+1]] == 0 )ch = false;
		}
		if(ch)cnt++;
	}while(next_permutation(path.begin()+1,path.end()));
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
int getlessAve(int num)
{
	std::string income_s, income;
	unsigned int ave = 0;
	int peopleN = 0, i, income_i[num];
	std::getline(std::cin, income_s);
	for(i = 0;i < num;i++)
	{
		income = income_s.substr(0, income_s.find_first_of(" "));
		income_s = income_s.substr(income_s.find_first_of(" ")+1, income_s.size());
		income_i[i] = std::stoi(income);
		ave += income_i[i];
	}
	ave /= num;
	for(i = 0;i < num;i++)
	{
		peopleN += ((unsigned int)income_i[i] <= ave?1:0);
	}
	return peopleN;
}

int main()
{
	std::string num;
	int p[50000], i = 0, count = 0;
	while(1)
	{
		std::getline(std::cin, num);
		if(std::stoi(num) == 0)
			break;
		p[count] = getlessAve(std::stoi(num));
		count++;
	}
	for(i = 0;i < count;i++)
		std::cout << p[i] << std::endl;
	return 0;
}





Measured memory_bytes: 3320
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int n, k ;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    int counter = 0;
    for(int i=0; i<n; i++){
        if(v.at(i) >= k){
            counter++;
        }
    }
    cout << counter << endl;
}


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

using namespace std;
 
main()
{
    int n;
    cin >> n;
	
    vector <vector <pair <int, int> > > v(n);
    
	for(int i = 0; i < n; i++) 
	{
        int a;
        cin >> a;
        
		for(int j = 0; j < a; j++) 
		{
            int x, y;
            cin >> x >> y;
            
			v[i].push_back({x - 1, y});
        }
    }
 
    int ans = 0;
    
	for(int bit = 0; bit < (1 << n); bit++) 
	{
        bool ok = true;
        
		for(int i = 0; i < n; i++) 
		{
            if(bit & (1 << i)) 
			{
                for(auto& x : v[i]) 
				{
                    if(((bit & (1 << x.first)) > 0) != x.second)
                        ok = false;
                }
            }
        }
		
        if(ok == true)
            ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << "\n";
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long

void solve()
{
    ll m = 1000000007;
    int H, W;
    cin >> H >> W;
    char arr[H][W];
    ll dp[H+1][W+1] = {0};

    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++) cin >> arr[i][j];

    for(int i = 0; i <= H; i++) dp[i][0] = 0;
    for(int i = 0; i <= W; i++) dp[0][i] = 0;

    dp[1][1] = 1;
    for(int i = 1; i <= H; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            if(i==1 && j==1) continue;

            if(arr[i-1][j-1] == '.')
                dp[i][j] = (dp[i-1][j] % m + dp[i][j-1] % m) % m;
            else
                dp[i][j] = 0;
        }
    }

    cout << dp[H][W];
}

int main()
{
    fastio;
    solve();
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int W,H,K;
char fie[33][33];
char tmp[33][33];

int checkD(int x,int y){
  char c = fie[x][y];
  for(int k=0;k<K;k++){
    int nx = x + k;
    if( nx >= W ) return 0;
    if( fie[nx][y] != c ) return 0;
  }
  int ret = K;
  for(int nx=x+K;nx<W;nx++){
    if( fie[nx][y] != c ) return ret;
    ret++;
  }
  return ret;
}

int del(int k){
  while( true ){
    bool loop = false;
    for(int y=H;y>0;y--){
      for(int x=0;x<W;x++){
        if( !fie[x][y] ){
          fie[x][y] = fie[x][y-1];
          if( fie[x][y] ) loop = true;
          fie[x][y-1] = 0;
        }
      }
    }
    if(!loop) break;
  }
  /*
  for(int y=1;y<=H;y++){
    for(int x=0;x<W;x++){
      cout << (fie[x][y]==0?' ':fie[x][y]);
    }
    cout << endl;
  }
  */
  int sc = 0;
  for(int y=1;y<=H;y++){
    for(int x=0;x<W;x++){
      if( !fie[x][y] ) continue;
      int ck = checkD( x, y );
      if( ck ){
        sc += ( fie[x][y] - '0' ) * ck;
        //        cout << "del " << x <<  " " << ck << endl;
        for(int nx=x;nx<x+ck;nx++) fie[nx][y] = 0;
        x += ck-1;
      }     
    }
  }
  //  cout << "sc : " << sc << endl;
  if( !sc ) return (1<<k)*sc;
  return del(k+1) + (1<<k) * sc;
}

int score(int x,int y){
  for(int i=1;i<=H;i++)
    for(int j=0;j<W;j++)
      fie[j][i] = tmp[j][i];
  //  cout << "score " << x << " " << y << endl;
  fie[x][y] = 0;
  return del( 0 );
}

int main(){
  cin >> H >> W >> K;
  for(int i=1;i<=H;i++)
    for(int j=0;j<W;j++){
      cin >> fie[j][i]; tmp[j][i] = fie[j][i];
    }


  int res = 0;
  for(int i=1;i<=H;i++)
    for(int j=0;j<W;j++)
      res = max( res, score( j, i ) );
  cout << res << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}
#define int long long
inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,m;
bool gi;
int he,to;
int num[100005];
int col[100005],vis[100005];
int h[100005],t[200005],ne[200005],e;
void add(int x,int y){
   t[++e]=y;
   ne[e]=h[x];
   h[x]=e;
}
void dfs1(int x,int ff){
    vis[x]=1; 
	for(int i=h[x];i;i=ne[i]){
	    int v=t[i]; 
		if(v!=ff){
            if(vis[v]){
                he=x;to=v;
                if(col[he]==col[to])gi=1;
            }
            else{
                col[v]=col[x]^1;
                dfs1(v,x);
            }
        }
	 }
}
int num2[100005];
int sum;
long long ans;
void dfs2(int x,int ff){
    for(int i=h[x];i;i=ne[i]){
		int v=t[i];
	    if(v!=ff&&!((x==he&&v==to)||(x==to&&v==he))){
		    dfs2(v,x);
			num2[x]+=num2[v];
			num[x]+=num[v];
		}
	}
}
int stk[100005],top;
signed main () {
#ifndef ONLINE_JUDGE
//file("agc004f");
#endif
    n=read();
	m=read();
	F(i,1,m){
	   int x=read(),y=read();
	   add(x,y);
	   add(y,x);
	}
	col[1]=1;
	dfs1(1,0);
	F(i,1,n){
		if(col[i])num[i]=1;
		else num[i]=-1;
	}
	F(i,1,n)sum+=num[i];
	if(m==n-1){
	  if(sum){
		  puts("-1");
		  return 0;
	  }
	}
	else{
	   if(gi){
	     if(sum%2==1){
			 puts("-1");
		 return 0;
		 }
		 num[he]-=(sum/2);
		 num[to]-=(sum/2);
		 ans+=1ll*abs(sum/2);
	   }
	   else{
	      if(sum){
		     puts("-1");
			 return 0;
		  }
		  num2[he]=1;
		  num2[to]=-1;
	   }
	}
	dfs2(1,0);
	F(i,1,n){
		if(!num2[i])ans+=1ll*abs(num[i]);
	    else{
		  if(num2[i])num[i]=-num[i];
			stk[++top]=num[i];
		}
	}
	stk[++top]=0;
	sort(stk+1,stk+top+1);
	int X=stk[(top+1)/2];
	F(i,1,top)ans+=1ll*abs(stk[i]-X);
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};



int A;
vector<long> a(1000010);
int B;
vector<long> b(1000010);
map<long,int> mpa,mpb;


int main() {
	
	cin >> A;
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	cin >> B;
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}

	for (int i = 0; i < A; i++) {
		mpa[a[i]]++;
	}
	for (int i = 0; i < B; i++) {
		mpb[b[i]]++;
	}

	for (int i = 0; i < B; i++) {
		int x = b[i];
		if (mpb[x] > mpa[x]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	
	return 0;
}


Measured memory_bytes: 40832
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a:u32 = sc.read();
    let b:u32 = sc.read();
    let c:u32 = sc.read();
    let mut counter = 0;
    for i in a..b+1 {
        if c % i == 0 {
            counter = counter + 1;
        }
    }
    println!("{}", counter);
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 5024
import java.io.*;

 public class Main{
	 public static void main(String args[]) throws IOException{
		 BufferedReader bf = new BufferedReader(
				 new InputStreamReader(System.in));
		 int i = 0, j = 0,x;
		 int order[] = new int[10];
		 int exit[] = new int[1000];
		 String str;
		 while((str = bf.readLine()) != null){
			 x = Integer.parseInt(str);
			 if(x != 0){
				 order[i] = x;
				 i++;
			 } else {
				 exit[j] = order[i-1];
				 j++;
				 i--;
			 }
		 }
		 for(int c = 0; c < j; c++){
			 System.out.println(exit[c]);
		 }
	 }
}

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

int main() {
    int X, Y;
    cin >> X >> Y;
    if (Y % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (X >= (Y + 2) / 4 && X <= Y / 2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
N = int(input())

Order = []

for i in range(N+1):
    Order.append(0)

A = list(map(int, input().split()))

for n in range(N):
    i = A[n]
    Order[i] = n + 1

ans = ""

for i in range(1, N+1):
    ans += str(Order[i])
    if i != N + 1:
        ans += " "

print(ans)

Measured memory_bytes: 21276
N = str(input())
N1 = int(N[len(N)-1])

if N1 == 0:
  print('pon')
if N1 == 1:
  print('pon')
if N1 == 2:
  print('hon')
if N1 == 3:
  print('bon')
if N1 == 4:
  print('hon')
if N1 == 5:
  print('hon')
if N1 == 6:
  print('pon')
if N1 == 7:
  print('hon')
if N1 == 8:
  print('pon')
if N1 == 9:
  print('hon')


Measured memory_bytes: 9192
#include <iostream>
#include<cstdio>
using namespace std;
typedef struct day{
    int a,b,c;
}D;
int Max(int a,int b){
    return a>b?a:b;
}
int MM(D d){
    int m=d.a>d.b?d.a:d.b;
    return d.c>m?d.c:m;
}
int main()
{
    int n;
    D t,dp[2];
    cin>>n;
    dp[0].a=dp[0].b=dp[0].c=0;
    while(n--){
        cin>>t.a>>t.b>>t.c;
        dp[1].a=t.a+Max(dp[0].b,dp[0].c);
        dp[1].b=t.b+Max(dp[0].a,dp[0].c);
        dp[1].c=t.c+Max(dp[0].a,dp[0].b);
        dp[0]=dp[1];
    }
    cout<<MM(dp[1])<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    string s;cin>>s;
    ll ans=0;
    rep(i,0,s.size()-1){
        if(s[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;
int dp[3005][3005][5] = {};
int grid[3005][3005] = {};

void solve() {
	int n, m, k;
	cin >> n >> m >> k;

	for (int i = 0; i < k; i++) {
		int r, c, v;
		cin >> r >> c >> v;
		grid[r - 1][c - 1] = v;
	}


	for (int i = n - 1; i >= 0; i--) {
		for (int j = m - 1; j >= 0; j--) {
			for (int g = 0; g <= 3; g++) {
				if (i == n - 1 and j == m - 1 and g and grid[i][j])
					dp[i][j][g] = grid[i][j];
				else {
					if (i != n - 1) {
						if (g)
							dp[i][j][g] = max(dp[i][j][g], dp[i + 1][j][3] + grid[i][j]);
						dp[i][j][g] = max(dp[i][j][g], dp[i + 1][j][g]);
					}
					if (j != m - 1) {
						if (g)
							dp[i][j][g] = max(dp[i][j][g], dp[i][j + 1][g - 1] + grid[i][j]);
						dp[i][j][g] = max(dp[i][j][g], dp[i][j + 1][g]);
					}
				}
			}
		}
	}

	cout << dp[0][0][3] << endl;
}

// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
*/


Measured memory_bytes: 426160
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Map as MP
import Data.Char
import Data.List
import Control.Monad
import Debug.Trace

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    (ys :: VUM.IOVector Int) <- VUM.replicate  (10^5+1) 0
    VU.mapM_ (\x -> VUM.modify ys (+1) x) xs
    res <- VU.forM (VU.fromList [0..10^5]) $ \i -> do
        as <- forM [(max (i-1) 0)..(min (i+1) (10^5))] $ VUM.read ys 
        return $ Data.List.sum as
    print $ VU.maximum res

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

int64_t countP[51], length[51];

int64_t solve(int64_t n, int64_t x) {
    if (x == 0) return 0;
    if (n == 0) return 1;
    if (length[n] == x) return countP[n];

    // x - 1
    int64_t ans = 0;
    if (x <= 1 + length[n - 1]) {
        ans += solve(n - 1, x - 1);
    } else {
        ans += solve(n - 1, length[n - 1]) + 1;
        // x - 2
        ans += solve(n - 1, x - 2 - length[n - 1]);
    }
    return ans;
}

int main() {
    int64_t n, x;
    cin >> n >> x;

    countP[0] = 1;
    length[0] = 1;

    for (int i = 1; i <= n; i++) {
        countP[i] = 1 + countP[i - 1] * 2;
        length[i] = 3 + length[i - 1] * 2;
    }

    cout << solve(n, x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <regex>
using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;



int main()
{
    int X,Y;
    cin>>X>>Y;




    

    cout<<X+Y/2<<endl;
}



Measured memory_bytes: 256
import java.util.*; 
public class Main {

  public static void main(String[] args) {
  
  Scanner sc=new Scanner(System.in);
  int a =sc.nextInt();
  int b =sc.nextInt();
  int c =sc.nextInt();
  System.out.println(a+b+1>=c? b+c:b+a+1+b);
  }
}

Measured memory_bytes: 24020
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

#include <atcoder/mincostflow>

using namespace std;
using namespace atcoder;

const double EPS = 1e-10;
const int64_t INF = 1e9;
typedef long long ll;

const int dx[2] = {0,1}, dy[2] = {1,0};
const int D = 2;

int n, m;
char s[50][60];
int pnum;
int pi[100], pj[100];

bool used[50][50];

void search(int y, int x, int pn, mcf_graph<int,ll> *g)
{
	//printf("search: %d: %d %d\n", pn, y, x);
	//fflush(stdout);
	g->add_edge(pn, pnum + y*m + x, 1, 6000 - (y-pi[pn] + x-pj[pn]));
	used[y][x] = true;
	for (int d = 0; d < D; ++d) {
		int ny = y + dy[d], nx = x + dx[d];
		if (ny >= n || nx >= m) continue;
		if (s[ny][nx] != '#' && !used[ny][nx]) {
			search(ny, nx, pn, g);
		}
	}
}

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

	pnum = 0;
	//int snum = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == 'o') {
				pi[pnum] = i;
				pj[pnum++] = j;
			}
			//if (s[i][j] != '#') ++snum;
		}
	}

	mcf_graph<int, ll> graph(pnum+n*m+2);
	int st = pnum+n*m;
	int en = pnum+n*m+1;

	for (int i = 0; i < pnum; ++i) {
		memset(used, 0, sizeof(used));
		graph.add_edge(st, i, 1, 0);
		search(pi[i], pj[i], i, &graph);
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] != '#') {
				graph.add_edge(pnum + i*m+j, en, 1, 0);
			}
		}
	}

	auto res = graph.flow(st, en);
	//printf("first: %d\n", res.first);
	printf("%lld\n", 6000 * pnum - res.second);

	return 0;
}


Measured memory_bytes: 8124
#include <iostream>
#include <math.h>

using namespace std;

int main(){
	int n;
	double sq;
	cin>>n;
	cout<<n<<":";
	sq = sqrt(n);

	while(1){
		if(n%2) break;
		n /=2;
		cout<<" 2";
	}

	for(int i=3;i<sq;i+=2){
		if(n%i) continue;
		n /= i;
		cout<<" "<<i;
		i -= 2;
	}

	if(n != 1)cout<<" "<<n;

	cout<<endl;
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int n;

int main()
{
    scanf("%d",&n);int ans=0;
    for (int i=1;i<=n;i++)
    {
        int x,k;scanf("%d%d",&x,&k);
        while (x%k>0) x-=((x%k-1)/(x/k+1)+1)*(x/k+1);
        ans^=x/k;
    }
    if (ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}

Measured memory_bytes: 384
#C
n = int(input())
a = []
testimony = [-1]*n
ans = 0
for i in range(n):
    a.append(int(input()))#証言の個数
    l = []
    for j in range(a[i]):
        l.append(list(map(int, input().split())))
    if l != []:
        testimony[i] = l#iの人のa[i]個の証言のリスト
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1 and testimony[n-1-j] != -1:
            for k in range(a[n-1-j]):
                if ((i >> (n - testimony[n-1-j][k][0])) & 1) != testimony[n-1-j][k][1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, str(bin(i)).count('1'))
print(ans)

Measured memory_bytes: 45420
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    vector<bool> vb(1001,0);
    int a,b;
    cin >> a >> b;
    int n;
    cin >> n;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        for(int i = x;i<y;i++)vb[i] = 1;
    }
    //check
    for(int i = a;i<b;i++)if(vb[i] != 0){
        cout << 1 << endl;
        return 0;
    }
    cout << 0 << endl;
    return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  if(k==1){
    cout<<0<<endl;
    return 0;
  }else{
    cout<<n-k<<endl;
    return 0;
  }
  
}


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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }else if(A+B>C+D){
    cout<<"Left"<<endl;
  }else if(A+B<C+D){
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,n,b,i,j,k,l,m,s=0,op=0,w;
	cin>>n>>w;
	vector<pair<ll,ll> > v(n);
	for(i=0;i<n;i++)
	{
		cin>>v[i].first>>v[i].second;
	}

	ll dp[n+1][w+1]={0};
	sort(v.begin(),v.end());

	for(i=0;i<=w;i++) dp[0][i]=0;
	for(i=0;i<=n;i++) dp[i][0]=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=w;j++)
		{
			if(j<v[i-1].first) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],v[i-1].second+dp[i-1][j-v[i-1].first]);		
		}
	}
	cout<<dp[n][w];
}

Measured memory_bytes: 79104
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
  int N;  cin >> N;
  map<string,int> arare;
  for(int i = 0;i < N;i++){
    string s; cin >> s;
    arare[s] = 1;
  }

  int sum = 0;
  for(auto itr = arare.begin();itr != arare.end();itr++){
    sum += (itr->second);
  }

  if(sum == 3)cout << "Three" << endl;
  else cout << "Four" << endl;
}

Measured memory_bytes: 256
n, m, x = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
min = Float::INFINITY
[0, 1].repeated_permutation(n) do |bit|
  ans = 0
  sum = 0
  1.upto(m) do |j|
    sum = 0
    n.times do |i|
      if bit[i] == 1
        sum += a[i][j]
      end
    end
    break if sum < x
  end
  if sum >= x
    n.times do |i|
      if bit[i] == 1
        ans += a[i][0]
      end
    end
    min = ans if min > ans
  end
end
puts (min == Float::INFINITY ? -1 : min)

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
  return 0;
}


Measured memory_bytes: 256