akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
class UnionFind{
private:
    int length, numComponent;
    //parent[x]=xの親の番号 ............. xに親が存在する場合,
    //parent[x]=-(xを含む集合の要素数) ... xが親である場合
    int *parent;
    int *rank;
public:
    UnionFind(int l);
    ~UnionFind();
    int root(int x);
    void unite(int x,int y);
    bool isSameTree(int x,int y);
    int sizeOf(int x);
    int component();
};
UnionFind::UnionFind(int l){
    length=l;
    numComponent=l;
    parent=new int[l];
    for(int i=0;i<l;i++)parent[i]=-1;
    rank=new int[l];
    for(int i=0;i<l;i++)rank[i]=0;
}
UnionFind::~UnionFind(){
    delete[] parent;
    delete[] rank;
}
int UnionFind::root(int x){
    if(parent[x]<0)return x;
    return parent[x]=root(parent[x]);
}
void UnionFind::unite(int x,int y){
    int rx=root(x),ry=root(y);
    if(rx!=ry){
        numComponent--;
        if(rank[rx]>rank[ry]){
            parent[rx]+=parent[ry];
            parent[ry]=rx;
        }
        else{
            if(rank[rx]==rank[ry])rank[ry]++;
            parent[ry]+=parent[rx];
            parent[rx]=ry;
        }
    }
}
bool UnionFind::isSameTree(int x,int y){
    return root(x)==root(y);
}
int UnionFind::component(){
    return numComponent;
}
int UnionFind::sizeOf(int x){
    return -parent[root(x)];
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    UnionFind uf(n);
    for(int i=0;i<m;i++){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        uf.unite(x-1,y-1);
    }
    printf("%d\n",uf.component());
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            String strArr[] = br.readLine().split(" ");
            Map<Long, Integer> map = new HashMap<Long, Integer>();
            for (int i = 0; i < n; i++) {
                long temp = Long.parseLong(strArr[i]);
                if (map.containsKey(temp)) {
                    int val = map.get(temp) + 1;
                    map.put(temp, val);
                } else {
                    map.put(temp, 1);
                }
            }
            int count = 0;
            for(Map.Entry<Long, Integer> e : map.entrySet()) {
                long key = e.getKey();
                int val = e.getValue();
                if (val > key) {
                    count += val - key;
                } else if (key > val) {
                    count += val;
                }
            }
            System.out.println(count);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 48348
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = std.nextInt();
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (i == j) {
                    continue;
                }

                sum += d[i] * d[j];
            }
        }

        System.out.println(sum);
    }
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_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)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int a, b, c, d; cin >> a >> b >> c >> d;
    while(true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int dp[4000][4000];

int main() {
	string s, t;

	while (cin >> s >> t) {
		fill(dp[0], dp[s.size()], 0);
		for (int i = 0; i < s.size(); ++i) {
			for (int j = 0; j < t.size(); ++j) {
				if (s[i] == t[j]) {
					if (i - 1 < 0 || j - 1 < 0) {
						dp[i][j] = 1;
					}
					else {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
				}
			}
		}
		cout << *max_element(dp[0], dp[s.size()]) << endl;
	}

	return 0;
}

Measured memory_bytes: 65532
n = int(input())
a = [int(i) for i in input().split()]
s = [0 for i in range(n)]

s[-2] = a[n-1]
for i in range(3, n+1):
  s[-i] = s[-(i-1)] + a[-(i-1)]
  
ans = 0
for i in range(n):
  ans += a[i] * s[i]
  
print(ans % ((10**9)+7))


Measured memory_bytes: 31608
/*
    TOP GUN: MAVERICK!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod=1e9+7ll;
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
struct edge
{
    lli x,y,z,w;
};
bool cmp(edge a,edge b)
{
    if(a.x==b.x)
    {
        return a.y<b.y;
    }
    else
    return a.x<b.x;
}
lli parent[200005];
lli ran[200005];
void make_set(int v) {
    parent[v] = v;
    ran[v] = 0;
}
lli find_set(lli v)
{
if(v==parent[v])
return v;
return parent[v]=find_set(parent[v]);
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (ran[a] < ran[b])
            swap(a, b);
        parent[b] = a;
        if (ran[a] == ran[b])
            ran[a]++;
    }
}
int main()
{
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            sum+=a[i]*a[j];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
inf = 10**15
V = [[] for _ in range(N)]

for _ in range(M):
    A, B, C = map(int, input().split())
    if C>L:continue
    V[A-1].append((B-1, C))
    V[B-1].append((A-1, C))

dists = []
for i in range(N):
    dist = [(inf,inf)] * N
    dist[i] = (0, 0)
    u = [False] * N
    for _ in range(N):
        (charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
        u[j] = True
        for k, next_cost in V[j]:
            if j==k: continue
            c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
            if dist[k] > c:
                dist[k] = c
    dists.append(dist)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = dists[s-1][t-1][0]
    print(ans if ans!=inf else -1)

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

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

struct item
{
    int v, w;
};

int n, W;
vector<item> items;
vector<vector<int>> dp;

int rec_dp(int i, int w)
{
    if (dp[i + 1][w] != -1)
    {
        return dp[i + 1][w];
    }

    int result;
    if (i < 0)
    {
        result = 0;
    }
    else if (w - items[i].w < 0)
    {
        result = rec_dp(i - 1, w);
    }
    else
    {
        result = max(
            rec_dp(i - 1, w),
            rec_dp(i - 1, w - items[i].w) + items[i].v);
    }
    dp[i + 1][w] = result;
    return result;
}

int main()
{
    cin >> n >> W;
    items.resize(n);
    rep(i, n)
    {
        cin >> items[i].v >> items[i].w;
    }

    dp.resize(n + 1);
    rep(i, dp.size())
    {
        rep(j, W + 1)
        {
            dp[i].push_back(-1);
        }
    }
    cout << rec_dp(n - 1, W) << endl;
}


Measured memory_bytes: 7376
#include<stdio.h>
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int a,b;
int main()
{
    scanf("%d %d",&a,&b);
    double ans=(double)a/b;
    printf("%.10lf",ans);
}

Measured memory_bytes: 128
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

num = min(int(str(A-1)[-1]), int(str(B-1)[-1]), int(str(C-1)[-1]), int(str(D-1)[-1]), int(str(E-1)[-1])) + 1
array = [A, B, C, D, E]

result = 0
for i in array:
    result += math.ceil(i/10) * 10

print(result - 10 + num if num != 0 else result + num)


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
  int m,f,r;

  while(true){
    cin >> m >> f >> r;

    if(((m==-1) && (f==-1)) && (r==-1))
      break;

    if(m==-1 || f==-1)
      cout << "F" << endl;
    else if((m+f) >= 80)
      cout << "A" << endl;
    else if((m+f) >= 65)
      cout << "B" << endl;
    else if((m+f) >= 50)
      cout << "C" << endl;
    else if((m+f) >= 30){
      if(r>=50)
	cout << "C" << endl;
      else
	cout << "D" << endl;
    }else
      cout << "F" << endl;
  }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	vi a(n);
	rep(i, n)cin >> a[i];
	vi sum(n + 1);
	rep(i, n)sum[i + 1] = (sum[i] + a[i]) % m;
	map<int, int> mp;
	rep(i, n + 1)mp[sum[i]]++;

	ll ans = 0;
	for (auto x : mp)ans += (ll)x.second * (x.second - 1) / 2;

	cout << ans << endl;

}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
//#include <bits/stdc++.h>
#include <algorithm>

using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> v;
    int N,K;
    cin >> N >> K;
    while(N--)
    {
        int num;
        cin >> num;
        v.push_back(num);
    }
    sort(v.begin(),v.end());
    int sum =0;
    for(int i=0;i<K;i++)
    {
        sum+=v[i];
    }
    cout << sum <<"\n";
    
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
typedef long long LL;
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
LL IN(void)
{
  LL x=0;short f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
LL BinaryModularPower(LL x,LL y,LL mod)
{LL p=x,v=1;while(y){if(y&1){v=(v*p)%mod;}p=(p*p)%mod;y>>=1;}return v;}
int Prime(LL a,LL b,LL x,LL mod)
{
  LL y=BinaryModularPower(a,b,x);
  if(y==1)return 1;
  while(x){if(y+1==mod){return 1;}y=(y*y)%mod;x--;}
  return 0;
}
int main(void)
{
  LL a=0,i=3,p=2,N=IN();
  if(N==1)return puts("0"),0;
  while(p*p<N)
  {
    int count=0;LL y=i>>1,loop=1;
    while(!(N%p)){count++,N/=p;}a+=e[count];
    if(i==3||i==5||i==7||i==11){p++;continue;}
    while(!(y&1)){y>>=1;loop++;}
    if(Prime(2,y,loop,i)&&Prime(3,y,loop,i)&&
       Prime(5,y,loop,i)&&Prime(7,y,loop,i)&&Prime(11,y,loop,i)){p++;}
    i+=2;
  }
  if(N>1){a++;}return printf("%lld\n",a),0;
}

Measured memory_bytes: 1576
import math
H, W = map(int, input().split())
s = []
flag = 0
ans = "No"
for i in range(H):
  s.append(list(input()))
for i in range(H):
  for j in range(W):
    if flag == 0:
      if s[i][j] == "#":
        if s[max(0, i - 1)][j] == "#" or s[i][max(0, j - 1)] == "#" or s[min(H - 1, i + 1)][j] == "#" or s[i][min(W - 1, j + 1)] == "#":
          continue
        else:
          flag += 1
if flag == 0:
  ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int main()
{   long long n,m,k;
    scanf("%lld%lld%lld",&n,&m,&k);
    long long a[n+2],b[m+2];
    a[0]=0;
    b[0]=0;
    scanf("%lld",&a[1]);
    for(int i=2;i<=n;i++){
        long long tmp;
        scanf("%lld",&tmp);
        a[i]=a[i-1]+tmp;
    }
    scanf("%lld",&b[1]);
    for(long long i=2;i<=m;i++){
        long long tmp;
        scanf("%lld",&tmp);
        b[i]=b[i-1]+tmp;
    }
    long long j=m;
    long long ans=0;
    for(int i=0;i<=m;i++){
        if(b[i]<=k){
            ans=i;
            j=i;
        }else{
            break;
        }
    }
    if(a[n]+b[m]<=k){
        printf("%lld",n+m);
        return 0;
    }
    for(long long i=1;i<=n;i++){
        if(a[i]>k)break;
        
        while(a[i]+b[j]>k){
            j--;
        }
            if(i+j>ans&&a[i]+b[j]<=k){
                //printf("i=%lld j=%lld\n",i,j);
                ans=i+j;
            }
    }
    printf("%lld",ans);
    
    return 0;
}


Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long int N;


int main(){
    vector<int> H;

    cin >> N;
    int tmp = 0;
    for(int i = 0;i < N;i++) {
        cin >> tmp;
        H.push_back(tmp);
    }

    for(int i = 0;i < N-1;i++){
        if(i == 0) H[i]--;
        if(H[i] >= H[i+1] && H[i] != H[i-1]){
            H[i]--;
        }
    }

    for(int i = 0;i < N-1;i++){
        if(H[i] - H[i+1] > 0){
            cout << "No" << endl;
            exit(0);
        }
    }

    cout << "Yes" << endl;



    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

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

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int n;
vi a;

map<pii, ll> dp;

ll calc(int i, int m) {
    if(m == 0) return 0LL;
    if(i >= n) return -INF;
    int d = n - i;
    if((d+1)/2 < m) return -INF;
    if(dp.count({i, m})) return dp[{i, m}];
    
    ll ret = max(a[i] + calc(i+2, m-1), calc(i+1, m));

    return dp[{i, m}] = ret;
}

int main(){
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    cout << calc(0, n / 2) << '\n';
    return 0;
}

Measured memory_bytes: 30648
#include <iostream>
using namespace std;
int main()
{
	
	while(true){

		int w;
		int x = 0;
		cin >> w;

		if(w == -1)
			break;

		if(w >= 0 && w <= 10)
			x = 1150;
		
		else if(w > 10 && w <= 20)
			x = 1150 + (w - 10) * 125;

		else if(w > 20 && w <= 30)
			x = 1150 + (w - 20) * 140 + 10 * 125;

		else if(w > 30)
			x = 1150 + (w - 30) * 160 + 10 * 125 + 10 * 140;

		cout << 4280 - x << endl;

	}

	return 0;

}

Measured memory_bytes: 0
import sys
S=input()
li=''.join(S)
S1=len(li)
m=[]

K=int(input())
ans=str(K)
k1=''.join(ans)
k2=len(k1)

for i in range(0,S1):
    if li[i]!='1' and i<K:
        print(li[i])
        sys.exit()

print('1')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

long long dx[]={1,1,0,-1,-1,-1,0,1};
long long dy[]={0,1,1,1,0,-1,-1,-1};
int main(){
  long long h,w;
  int n;
  cin>>h>>w>>n;
  long long a,b;
  long long na,nb;
  map<pair<long long,long long>,int> mp;
  REP(i,n){
    cin>>a>>b;
    a--;b--;
    if(1<=a && a<=h-2 && 1<=b && b<=w-2){
      mp[make_pair(a,b)]++;
    }
    REP(j,8){
      na = a+dx[j];
      nb = b+dy[j];
      if(1<=na && na<=h-2 && 1<=nb && nb<=w-2){
        mp[make_pair(na,nb)]++;
      }
    }
  }
  long long ans[10]={};
  long long ans_sum=0;
  for(auto p:mp){
    if(p.second>0){
      ans[p.second]++;
      ans_sum++;
    }
  }
  ans[0] = (h-2)*(w-2) - ans_sum;
  REP(i,10){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    string s,ans="";
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0'||s[i]=='1'){
            ans.push_back(s[i]);
        }
        if(s[i]=='B'&&ans.size()!=0){
            ans.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

#define INF 1e9
#define min_3(a, b, c) min(a, min(b, c));
typedef long long ll;

int main()
{
  int n, k; cin >> n >> k;
  vector<ll> x(n);
  for(int i = 0; i < n; i++) cin >> x[i];

  int l, r;
  ll t = INF;
  for (l = 0; l < n - k + 1; l++)
  {
    r = l + k - 1;
    ll L2R = abs(x[l]) + abs(x[l] - x[r]);
    ll R2L = abs(x[r]) + abs(x[r] - x[l]);
    t = min_3(L2R, R2L, t);
  }

  cout << t << endl;
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	int* num = new int[N];
	int max = 100;
	for(int i = 0; i < N; i++){
		int count = 0;
		cin >> num[i];
		while(num[i] % 2 == 0){
			count++;
			num[i] /= 2;
		}
		if(count == 0){
			cout << 0;
			return 0;
		}else if(count < max){
			max = count;
		}
	}
		cout << max;
		return 0;

	}


Measured memory_bytes: 256
n,k = map(int,input().split())
s=input()
li=[]
li_z=[]
li_o=[]


    
check="1"
seq=0
for i in s:
    if check!=i:
        check=i
        li.append(seq)
        seq=1
    else:
        seq+=1
        
li.append(seq)

for  i in range(len(li)):
    if i%2==0:
        li_o.append(li[i])
    else:
        li_z.append(li[i])
    
if s[n-1]=="0":
    li_o.append(0)


if len(li_o)<=k:
    print(n)
else:
    m=sum(li_o[0:0+k+1])+sum(li_z[0:0+k])
    tmp=m
    for i in range(1,len(li_o)-k):
        tmp=tmp-li_o[i-1]+li_o[i+k]-li_z[i-1]+li_z[i+k-1]
        m=max(tmp,m)
        
    print(m)

Measured memory_bytes: 5136
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
D = [list(map(int, input().split())) for _ in range(N)]
#= [int(input()) for _ in range(N)]
#= {i:[] for i in range(N)}

zoro = 0

for d1, d2 in D:
    if d1 == d2:
        zoro += 1
    else:
        zoro = 0

    if zoro == 3:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 9172
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i, j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.close();
		sc = null;
		double nbunno1 = 1.0d / n;
		double kaku = 0.0d;
		int kai;
		double[] nibunnno1 = new double[18];
		double ni = 2.0d;
		for(i = 0; i <= 17; i++) {
			ni /= 2.0d;
			nibunnno1[i] = ni;
		}
//		int aa = 0;
		int max;
		if(n >= k) {
			max = k -1;
		} else {
			max = n;
		}
		for(i = 1; i <= max; i++) {
			kai = (int) Math.ceil(Math.log((double)k / i)/Math.log(2));
//			System.out.println(kai); /*  */
//			aa +=  Math.pow(2, 17-kai); 
			kaku += nbunno1 * nibunnno1[kai]; 
		}
//		System.out.println(kaku);
//		System.out.println((double)aa/n/131072);
		if(n >= k) {
			kaku += nbunno1 * (n - k + 1);
		}
//		System.out.println(nbunno1 * (n - k));
//		System.out.println(((double)aa/131072+(double)(n-k))/n);
		System.out.println(kaku);
	}
}


Measured memory_bytes: 21316
# B
n, a, b = map(int, input().split())

if n <= a+b:
    if n >= a:
        print(a)
    elif n < a:
        print(n)
elif n > a+b:
    taba = n//(a+b)
    if n-taba*(a+b) >= a:
        print(taba*a+a)
    elif n-taba*(a+b) < a:
        print(taba*a+n-taba*(a+b))

Measured memory_bytes: 3060
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  dp[i]=float('inf')
  for j in range(1,k+1):
    if i-j>=0:
      dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]) , dp[i])
print(dp[n-1])

Measured memory_bytes: 55392
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define ff fflush(stdout)
using namespace std;
ll tme[100005];
int main () { 
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%lld %lld %lld", &a, &b, &c);
	for (i = 1; i <= a; i++) {
		scanf("%lld", &tme[i]);
	}
	stable_sort(tme + 1, tme + a + 1);
	d = tme[1]; e = 1; f = 0;
	for (i = 2; i <= a; i++) {
		if (tme[i] - d > c || e == b) {
			f++; e = 1; d = tme[i];
		} else {
			e++;
		}
	}
	printf("%lld\n", ++f);
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
    int runner;
    int cnt = 0;
    int cnt2 = 0;
    String time;
    Player pArray[][] = new Player[3][8];
    Player rank[] = new Player[8];
    Player otherArray[] = new Player[18];
	private Scanner sc;
    void doIt(){
        sc = new Scanner(System.in);
        for(int i = 0; i < 3; i++){
        	for(int k = 0; k < 8; k++){
        		runner = sc.nextInt();
        		time = sc.next();
        		pArray[i][k] = new Player(runner,time);
        	}
        }
        for(int i = 0; i < pArray.length; i++){
			Arrays.sort(pArray[i]);
			Arrays.toString(pArray[i]);
			rank[cnt] = pArray[i][0];
			cnt++;
			rank[cnt] = pArray[i][1];
			cnt++;
			for(int k = 2; k < 8; k++){
				otherArray[cnt2] = pArray[i][k];
				cnt2++;
			}
        }
        Arrays.sort(otherArray);
        rank[6] = otherArray[0];
        rank[7] = otherArray[1];
        for(int i = 0; i < rank.length; i++){
        	System.out.println(rank[i].pnumber + " " + rank[i].time);
        }
    }
    class Player implements Comparable<Player>{
        int pnumber;
        String time;
        Player(int pnumber,String time){
            this.pnumber = runner;
            this.time = time;
        }
        @Override
        public String toString(){
        	return pnumber + " " + time;
        }
        @Override
        public int compareTo(Player p){
            return this.time.compareTo(p.time);
        }
    }
    public static void main(String[] args) {
        new Main().doIt();
    }
}

Measured memory_bytes: 26088
using System;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            var hs1 = new HashSet<int>();
            var hs2 = new HashSet<int>();
            for(int i=1; i<=n; i++){
                hs1.Add(i);
            }
            for(int i=0; i<k; i++){
                Console.ReadLine();
                string[] l = Console.ReadLine().Split(' ');
                foreach(string j in l){
                    hs2.Add(int.Parse(j));
                }
            }
            Console.WriteLine(hs1.Count - hs2.Count);
        }
    }
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int h, w, ans = 0;
	cin >> h >> w;
	int d[15][15];
	rep(i, 10) {
		rep(j, 10) {
			if (i == j) d[i][j] = 0;
			else d[i][j] = inf;
		}
	}
	rep(i, 10) {
		rep(j, 10) {
			int a;
			cin >> a;
			d[i][j] = a;
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			int x;
			cin >> x;
			if (x != -1) {
				ans += d[x][1];
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import heapq
INF = 1e7
def main():
    H,W=map(int, input().split())
    sx, sy = map(int, input().split())
    dh, dw = map(int, input().split())
    sx -= 1
    sy -= 1
    S = [input() for _ in range(H)]
    def dijkstra(sx, sy):
        D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
        D[sx][sy] = 0
        PQ = [(0, (sx, sy))]
        heapq.heapify(PQ)
        while PQ: # PQに候補がある限り
            _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    xx, yy = ux+dx, uy+dy
                    if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                        is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                        # neighborでなければコストが1増える
                        if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                            D[xx][yy] = D[ux][uy] + is_not_neighbor
                            heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
        return D
    D = dijkstra(sx, sy)
    if D[dh-1][dw-1] >= INF:
        print(-1)
    else:
        print(D[dh-1][dw-1])
main()

Measured memory_bytes: 121148
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
const ll MOD = 1000000007;
int main(){
  int s,w;cin>>s>>w;
if(s<=w) cout<<"unsafe" <<endl;
else cout<<"safe"<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define vi vector<ll>
#define pi pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;ll arr[n];
int main(void){
    in(k);in(a);in(b);
    if(b>a){
        a = (b+a)-(b=a);
    }
    string ans = "NG";
    for(int i=0;i*k<=1000;i++){
        if(k*i<=a && k*i>=b)
            ans="OK";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
 
int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}
 
int main(){
    char W[11],T[1001];
    int count = 0;
    scanf("%s",W);
    while(true){
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2676
let m_1e9 = int_of_float 1e9 + 7
let ( +^ ) x y = (x + y) mod m_1e9
let ( -^ ) x y = x - y + if x < y then m_1e9 else 0
let ( *^ ) x y = ((x mod m_1e9) * (y mod m_1e9)) mod m_1e9

let rec mod_pow x n =
  if n = 0 then 1
  else let t = mod_pow x (n / 2) in t *^ t *^ if n mod 2 = 0 then 1 else x

let nPr n r = Array.(init r ((-) n) |> fold_left ( *^ ) 1)

let nCr n r = nPr n r *^ mod_pow (nPr r r) (m_1e9 - 2)

let (x, y) = Scanf.sscanf (read_line ()) "%d %d" @@ fun x y -> (x, y)

let () =
  if (x + y) mod 3 <> 0 then print_endline "0"
  else
    let x, y = min x y, max x y in
    let n = (2 * y - x) / 3 in
    let m = (x - n) / 2 in
    Printf.printf "%d\n" @@ if n < 0 || m < 0 then 0 else (nCr (n + m) n)

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

const int MAX = 1e3 + 10;
const int MOD = 1e9 + 7;

char grid[MAX][MAX];
int h, w, dp[MAX][MAX];

inline int add(int a, int b)
{
	int r = a + b;
	if(r >= MOD)
		r -= MOD;
	return r;
}

int dp_solve(int hh, int ww)
{
	if(hh == 0 && ww == 0)
		return 1;
	if(hh < 0 || ww < 0)
		return 0;
	int &ans = dp[hh][ww];
	if(~ans) return ans;
	ans = 0;
	if(grid[hh][ww] == '.')
	{
		ans = add(ans, dp_solve(hh-1, ww));
		ans = add(ans, dp_solve(hh, ww-1));
	}
	return ans;
}

int main()
{
	scanf("%d %d", &h, &w);
	for(int i = 0; i < h; i++)
		scanf("%s", grid[i]);
	memset(dp, -1, sizeof dp);
	printf("%d\n", dp_solve(h-1, w-1));
	return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<bool> b(N, false);
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    if (b.at(i) == false && a.at(i) == a.at(i+1)) {
      ans++;
      b.at(i+1) = true;
    }
  }
  cout << ans << endl;
}

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

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    if(k<=abs(x)/d) cout<<abs(x)-k*d<<endl;
    else{
        ll cnt=abs(x)/d;
        if((k-cnt)%2) cout<<abs(abs(x)%d-d)<<endl;
        else cout<<abs(x)%d<<endl;
    }
    return 0;
}

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

int main()
{
    int n, m, x, sum, ans = INT_MAX;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> rikaido(m);
    bool can, fin = false;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a.at(i).at(j);
        }
    }

    for (int mask = 0; mask < (1 << n); mask++)
    {
        rikaido.assign(m, 0);
        sum = 0;
        for (int i = 0; i < n; i++)
        {
            if (mask & (1 << i))
            {
                for (int j = 0; j < m; j++)
                {
                    rikaido[j] += a.at(i).at(j);
                }
                sum += c[i];
            }
        }
        can = true;
        for (int l = 0; l < m; l++)
        {
            if (x > rikaido[l])
                can = false;
        }
        if (can)
        {
            ans = min(ans, sum);
            fin = true;
        }
    }

    if (fin)
        cout << ans << endl;
    else
        cout << -1 << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int DigitsSum(int k){
    int sum=0;
    while(k>0){
        sum+=k%10; k/=10;
    }
    return sum;
}

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

    int ans=1e9;
    for(int i=1;i<=N/2;i++){
        int sum=DigitsSum(i)+DigitsSum(N-i);
        ans=min(ans,sum);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

signed main(){
    string s;
    cin>>s;
    if(s=="ABC")puts("ARC");
    else puts("ABC");
    return 0;
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double ang_a = (30 * h) + (m / 2);
  double ang_b = 6*m;

  double ang = abs(ang_a - ang_b);
  if (ang > 180)
  {
    ang = 360 - ang;
  }
  
  double rad = (ang / 180) * M_PI;

  double length = sqrt(a*a + b*b - 2*a*b*cos(rad));
  
  cout << fixed << setprecision(12);
  cout << length << endl;
  
  return 0;
}

Measured memory_bytes: 4168
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

string S;
string T;
int ans;

int main(){
	cin >> S >> T;
	for (int i = 0; i < 3; i++){
		if (S[i] == T[i])ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {

			Integer a,b,c;
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			
			if(a.equals(b)){
				System.out.println(c);
				return;
			}
			if(b.equals(c)){
				System.out.println(a);
				return;
			}
			if(a.equals(c)){
				System.out.println(b);
				return;
			}
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
int a ,b = 0;

cin>>a;
int c=a;
while (a!=0)
{
    b+=a%10;
    a=a/10;
}
if (c%b==0)
{
cout<<"Yes";
}
if(c%b!=0)
{
cout<<"No";

}

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int l, r;
  int s=0;
  
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    s += r-l+1;
  }
  
  cout << s <<endl;
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++) {
        if((i+1)%2==1) { cout << s[i];}
        else{continue;}
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 512
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    p = list(map(int, sys.stdin.readline().split()))
    s = sorted(p)

    flag =0
    for i in range(N):
        for j in range(i+1,N):
            l = p[:]
            temp = l[i]
            l[i] = l[j]
            l[j] = temp
            # print("p:",p)
            # print("l:",l)
            if l==s or p==s:
                flag=1
            l = p
            # print("re:",p2)

    if flag==1:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 5584
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        int cL = 0;
        int cR = N + 1;
        for (int i = 0; i < M; i++) {
            int L = in.nextInt();
            int R = in.nextInt();

            cL = Math.max(cL, L);
            cR = Math.min(cR, R);
        }

        if (cR - cL < 0) {
            out.println(0);
        } else if (cR == cL) {
            out.println(1);
        } else {
            out.println(cR - cL + 1);
        }
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

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

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 49152
import java.util.Arrays;

//Darts
public class Main{

	void run(){
		Scanner sc = new Scanner();
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			int[] p = new int[n+1];
			for(int i=0;i<n;i++)p[i]=sc.nextInt();
			int[] a = new int[n*n];
			int N = 0;
			for(int i=0;i<=n;i++)for(int j=0;j<=i;j++)if(p[i]+p[j]<=m)a[N++]=p[i]+p[j];
			Arrays.sort(a);
//			debug(a);
//			int d = m-a[1];
//			int l = 0;
//			int r = a.length-1;
//			debug(r);
//			while(r-l>1){
//				int mid = (l+r)/2;
//				if(a[mid]<=d)l=mid;
//				else r=mid;
//			}
//			System.out.println("L:"+l+" R:"+r);
			int max = 0;
			int s = 0;
			int t = a.length-1;
			while(s<=t){
				if(max==m)break;
				if(a[s]+a[t]<=m){
					max=Math.max(max, a[s]+a[t]);
					s++;
				}
				else t--;
			}
			System.out.println(max);
		}
	}
	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-') return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
	}	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;
ll mods = 998244353;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n;
    int k;
    cin >> n >> k;
    vector<ll> s(k*2);
    ll l,r;
    rep(i,k){
        cin >> l >> r;
        s[i*2] = l;
        s[i*2+1] = r;
    }
    ll sum = 0;
    vector<ll> tb(n+1,0);
    tb[1]=1; tb[2]=-1;
    for(ll i=1;i<=n;i++){
        sum = (tb[i] + sum + mods) % mods;
        rep(j,k){
            l = s[j*2];
            r = s[j*2+1];
            if(i+l<=n) tb[i+l]= (tb[i+l]+sum)%mods;
            if(i+r<n) tb[i+r+1] = (tb[i+r+1]-sum)%mods;
        }
    }
    print(sum);
    return 0;
}

Measured memory_bytes: 4784
def to_n(x,n):
    ans=[]
    if x==0:
        return [0]
    while x>0:
        x-=1
        ans.append(x%n)
        x//=n
    return ans[::-1]

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

    alp=[chr(i) for i in range(97,97+26)]
    m=to_n(n,26)
    ans=[alp[m[i]] for i in range(len(m))]
    print("".join(ans))

if __name__=="__main__":
    main()

Measured memory_bytes: 9152
#include <iostream>
using namespace std;
int main(){
    int a[5];
    cin >> a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    int ans;
    for(int i = 0; i< 5;i++)
    {
        if(a[i] == 0)
        {
        ans = i+1;
        break;
        }
    }
    
    cout << ans << endl;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> a(N, 0);
	int S=0;
	for (int i=0; i<N; i++) {
		cin >>a.at(i);
		a.at(i)*=N;
		S +=a.at(i);
	}
	S /=N;
	int D=10000;
	int I=N;
	for (int i=0; i<N; i++) {
		if (D>abs(S-a.at(i))) {
			D=abs(S-a.at(i));
			I=i;
		}
	}
	cout <<I <<endl;
	return 0;
}



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

namespace _1147
{
    public class Program

    {
        public static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != "0")
            {
                List<int> scores = new List<int>();
                for (int i = 0 ; i < int.Parse(line) ; i++)
                {
                    scores.Add(ReadInt());
                }
                Console.WriteLine(Math.Floor(scores.OrderBy(x => x).Where((x,i) => i != 0 && i != scores.Count-1).Average()));
            }       
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 16284
object App {
    private val outputBuffer = mutableListOf<Any>()

    private var i = 0
    private var inputBuffer = listOf<String>()

    fun next(): String = if (i < inputBuffer.size) {
        inputBuffer[i++]
    } else {
        inputBuffer = readLine()?.split(" ") ?: throw Exception("EOF")
        i = 0
        next()
    }

    fun nextLine(): String {
        i = 0
        inputBuffer = listOf<String>()
        return readLine() ?: throw Exception("EOF")
    }

    fun int() = next().toInt()

    fun long() = next().toLong()

    fun double() = next().toDouble()

    fun writeln(obj: Any) = write("$obj\n")

    fun write(obj: Any) = outputBuffer.add(obj)

    fun write(l: Iterable<Any>, sep: String = " ") = write(l.joinToString(sep))

    fun writeln(l: Iterable<Any>, sep: String = " ") = writeln(l.joinToString(sep))

    fun flush() {
        print(outputBuffer.joinToString(""))
        outputBuffer.clear()
    }
}


inline fun app(body: App.() -> Unit) {
    try {
        App.body()
    }
    finally {
        App.flush()
    }
}


fun main(args: Array<String>) = app {
    val n = int()

    val a = nextLine().split(" ").map {it.toInt()}

    val cnt = MutableList(n) { 0 }

    for (v in a) {
        cnt[v-1]++
    }

    writeln(cnt,"\n")
}


Measured memory_bytes: 69920