akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    int a=n,sum=0;
    while(a>0){
        sum+=a%10;
        a/=10;
    }
    Yes(n%sum==0);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
var n,i,t,x,y,ans:longint;
begin
  read(n,x);
  for i:=2 to n do
  begin
    read(y);
    case t of
      0:if x>y then t:=1 else
        if x<y then t:=2;
      1:if x<y then
        begin
          t:=0;
          inc(ans);
        end;
      2:if x>y then
        begin
          t:=0;
          inc(ans);
        end;
    end;
    x:=y;
  end;
  writeln(ans+1);
end.

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define MOD 1000000007
#define yn(f) cout << (f ? "Yes" : "No") << endl;
#define YN(f) cout << (f ? "YES" : "NO") << endl;

int x;
set<int> s;
map<int,int> m;

signed main() {
    cin >> x;
    int now = 0;
    while(true) {
        int hoge = now*now*now*now*now;
        if (s.count(hoge-x)) {
            cout << now << " " << m[hoge-x] << endl;
            return 0;
        }
        s.insert(hoge);
        s.insert(-hoge);
        m[hoge] = now;
        m[-hoge] = -now;
        now++;
    }
}




Measured memory_bytes: 3612
#include <iostream>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, K, Q; in(N); in(K); in(Q);

  int A[N];
  rep(i, N) A[i] = 0;
  rep(i, Q) {
    int a; in(a);
    ++A[a-1];
  }
  rep(i, N) {
    if (K+A[i]-Q <= 0) out("No");
    else out("Yes");
  }

  return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int64_t s = a.at(0);
    for (int i = 1; i < n; i++) {
        s ^= a.at(i);
    }
    for (int i = 0; i < n; i++) {
        int64_t x = s ^ a.at(i);
        cout << x << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4852
#include <stdio.h>

int main()
{
	int H,W; //height and width
	int i,j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  char c='A';
  int co =0;
  for(int i=0;i<s.size();i++){
    if(s[i]<=c){
      co++;
    }
    c=s[i];
    // cout << co << endl;
  }
  cout << co << endl;
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
 
int N;
int a[200000];
int b[200000];
 
int main() {
    cin >> N;
    rep(i, N) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b+N);
    rep(i, N) {
        if(a[i]<=b[N/2-1]) cout << b[N/2] << endl;
        else cout << b[N/2-1] << endl;
    }
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <math.h>

int main(void)
{
	double xa, ya, ra;
	double xb, yb, rb;
	double d;
	int n;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
		
		d = sqrt(pow(xa - xb, 2) + pow(ya - yb, 2));
		
		if (d > ra + rb){
			printf("0\n");
		}
		else if (ra > rb && d < ra - rb){
			printf("2\n");
		}
		else if (ra < rb && d < rb - ra){
			printf("-2\n");
		}
		else {
			printf("1\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 616
#include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define USE1(T) template <typename T> inline
#define USE2(T, U) template <typename T, typename U> inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
template<typename T> using vec = std::vector<T>;
template<typename T> using withi = std::pair<T, int>;
using ll = long long;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=withi<T>)vec<U>zipi(const vec<T>&x,int s=0){int N=x.size();vec<U>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int N = in();
  rep(i, N) {
    auto ord = in<string>();
    auto msg = in<string>();
    int L = msg.size();

    reverse(ALL(ord));
    for (char c : ord) {
      if (c == 'J') { msg = msg.substr(L - 1, 1) + msg.substr(0, L - 1); }
      if (c == 'C') { msg = msg.substr(1, L - 1) + msg.substr(0, 1); }
      if (c == 'E') {
        if (L % 2 == 0) {
          msg = msg.substr(L / 2, L / 2) + msg.substr(0, L / 2);
        } else {
          msg = msg.substr(L / 2 + 1, L / 2) + msg.substr(L / 2, 1) + msg.substr(0, L / 2);
        }
      }
      if (c == 'A') { reverse(ALL(msg)); }
      if (c == 'P') {
        for (char& m : msg) {
          if (isdigit(m)) { m = (m - '0' + 9) % 10 + '0'; }
        }
      }
      if (c == 'M') {
        for (char& m : msg) {
          if (isdigit(m)) { m = (m - '0' + 1) % 10 + '0'; }
        }
      }
    }
    pr(msg);
  }
  return 0;
}

Measured memory_bytes: 3216
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        String find = sc.next();
        int n = sc.nextInt();
        int count = 0;

        for(int i=0; i<n; i++){
            String ring = sc.next();
            ring += ring;
            if(ring.contains(find)) count++;
        }

        System.out.println(count);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 17332
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

n = inp()
dp = [[0] * 3 for i in range(n+1)]
for i in range(n):
    work = inpl()
    for j in range(3):
        option = [dp[i][k] + work[k] for k in range(3) if j != k]
        dp[i + 1][j] = max(option)
print(max(dp[n]))

Measured memory_bytes: 57448
s=str(input());a=["A","K","I","H","A","B","A","R"]
if s=="AKIHABARA":
    print("YES")
elif "K" not in s or "I" not in s or "H" not in s or "B" not in s or "R" not in s:
    print("NO")
else:
    s=list(s)
    for i in range(len(a)):
        if s[i]!=a[i]:
           s.insert(i,"A")
        #print(s,a,i)
        if s==a or s==["A","K","I","H","A","B","A","R","A"]:
            print("YES")
            break
        else:
            pass
    else:
         print("NO")

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>num(N);
	int ans = 0;
	for (int n = 0;n<N;++n) {
		cin >> num[n];
		if (0 == n%2) {
			if (1 == num[n]%2){
				++ans;
			}
		}
	}
	cout << ans <<  endl;
	return 0;
}

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

using namespace std;
const long long INF=1e9+7;
long long n, a[100009];
long long dp[100009];

int main(){
  cin >> n;
  fill(dp, dp+n+1, INF);
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=n-1;i>=0;i--){
    *upper_bound(dp, dp+n, a[i])=a[i];
  }
  for(int i=0;i<=n;i++){
    if(dp[i]==INF){
      cout << i << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 5156
N = int(input())
AList = list(map(int, input().split()))
sumFee = 0

# 全てを回った時の料金を求める
sumFee += abs(AList[0])
for i in range(1, N):
  sumFee += abs(AList[i] - AList[i - 1])
sumFee += abs(AList[N-1])

# Iを抜かした時の料金を求める
for i in range(N):
  low_i = abs(AList[i] - AList[i-1]) if i != 0 else abs(AList[0])
  high_i = abs(AList[i + 1] - AList[i]) if i != N - 1 else abs(AList[N-1])
  if i == 0 :
    mix_i = abs(AList[i + 1])
  elif i == N - 1 :
    mix_i = abs(AList[i - 1])
  else:
    mix_i = abs(AList[i + 1] - AList[i - 1])
  
  print(sumFee - low_i - high_i + mix_i)


Measured memory_bytes: 14048
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 100005;

int n;

struct Perm
{
	int p[MAXN];
	
	Perm()
	{
		for (int i = 1;i <= n;i++)
			p[i] = i;
	}
	
	Perm operator * (const Perm &a)const
	{
		Perm res;
		for (int i = 1;i <= n;i++)
			res.p[i] = p[a.p[i]];
		return res;
	}
}trans;

int m;

ll K;
ll a[MAXN];
ll b[MAXN];

Perm power(Perm a,ll b)
{
	Perm res;
	while (b)
	{
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		scanf("%lld",&a[i]);
	for (int i = 1;i < n;i++)
		b[i] = a[i + 1] - a[i];
	n--;
	for (int i = 1;i <= n;i++)
		trans.p[i] = i;
	scanf("%d%lld",&m,&K);
	for (int x,i = 1;i <= m;i++)
	{
		scanf("%d",&x);
		swap(trans.p[x],trans.p[x - 1]);
	}
	trans = power(trans,K);
	for (int i = 1;i <= n;i++)
		a[i + 1] = a[i] + b[trans.p[i]];
	n++;
	for (int i = 1;i <= n;i++)
		printf("%lld\n",a[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

from itertools import combinations


def solve():
    n = II()
    D = LI()

    ans = 0
    for i in combinations(D, 2):
        # print(i)
        x, y = i
        ans += x * y
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
	int a,b;
	char c[2],c2;
	int sum;
	
	scanf("%d",&a);
	sum=a;
	while(1)	{
		scanf("%s",c);
		c2=c[0];
		if(c2=='=')	{
			break;
		}
		else {
			scanf(" %d",&a);
			if(c2=='+')	{
				sum+=a;
			}
			if(c2=='-')	{
				sum-=a;
			}
			if(c2=='*')	{
				sum*=a;
			}
			if(c2=='/')	{
				sum/=a;
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    SCIN(s,t);
    int x=stoi(s+t);
    flag=false;
    for(int i=1;i*i<=x;i++){
        if(i*i==x){flag=true;break;}
    }
    printf(flag?"Yes":"No");
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int a,b;cin>>a>>b;
    if(a+b==15)cout<<"+"<<endl;
    else if(a*b==15)cout<<"*"<<endl;
    else cout<<"x"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N;
	cin >> N;
	map<long long, int> mp;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		mp[a]++;
	}

	int count = 0;
	for (auto x : mp) {
		if (x.second % 2 == 1)++count;
	}

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

Measured memory_bytes: 9668
#include <iostream>
#include <algorithm>
#include <string>
#include "bits/stdc++.h"
using namespace std;

int main() 
{
    int n, count=0;
    cin >> n;
    string st_i ;
    for(int i=1; i<n+1; i++) {
        st_i = to_string(i);
        if(st_i.length()%2 == 1) {
            count++;
        }
    }
    cout << count << endl; 
}

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

	string s;
	cin >> s;

	sort(all(s));

	if (s[0] == s[1] and s[1] != s[2] and s[2] == s[3]) cout << "Yes\n";
	else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    initial_n = gets.chomp.to_i
    n = initial_n

    r_sum = 0
    while 0 < n
      n, r = n.divmod(10)
      r_sum += r
    end

    if initial_n % r_sum == 0
      puts "Yes"
    else
      puts "No"
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	Pi st,en,at;
	int ans=0;
	cin >>st.F>>st.S>>en.F>>en.S;
	at=st;
	P dis=mp(en.F-st.F,en.S-st.S);
	if(dis.F >0){
		rep(i,dis.F){
			cout<<"R";
		}
	}else{
		rep(i,-dis.F){
			cout<<"L";
		}
	}
	if(dis.S>0){
		rep(i, dis.S)
		{
			cout << "U";
		}
	}
	else
	{
		rep(i, -dis.S)
		{
			cout << "D";
		}
	}
	///---------------//
	if (dis.F > 0)
	{
		rep(i, dis.F)
		{
			cout << "L";
		}
	}
	else
	{
		rep(i, -dis.F)
		{
			cout << "R";
		}
	}
	if (dis.S > 0)
	{
		rep(i, dis.S)
		{
			cout << "D";
		}
	}
	else
	{
		rep(i, -dis.S)
		{
			cout << "U";
		}
	}
	//--------------hald-----------//
	if(dis.S >0){
		cout<<"D";
	}else{
		cout<<"U";
	}
	if (dis.F > 0)
	{	
		rep(i, dis.F+1)
		{
			cout << "R";
		}
	}
	else
	{
		rep(i, -dis.F+1)
		{
			cout << "L";
		}
	}
	if (dis.S > 0)
	{
		rep(i, dis.S+1)
		{
			cout << "U";
		}
	}
	else
	{
		rep(i, -dis.S+1)
		{
			cout << "D";
		}
	}
	if(dis.F>0){
		cout<<"L";
	}else{
		cout<<"R";
	}
	///---------------//
	if(dis.S >0){
		cout<<"U";
	}else{
		cout<<"D";
	}
	if (dis.F > 0)
	{
		rep(i, dis.F+1)
		{
			cout << "L";
		}
	}
	else
	{
		rep(i, -dis.F+1)
		{
			cout << "R";
		}
	}
	if (dis.S > 0)
	{
		rep(i, dis.S+1)
		{
			cout << "D";
		}
	}
	else
	{
		rep(i, -dis.S+1)
		{
			cout << "U";
		}
	}
	if(dis.F>0){
		cout<<"R"<<endl;
	}else{
		cout<<"L"<<endl;
	}
}

Measured memory_bytes: 3596
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x:i128 = read();
    let mut k:i128 = read();
    let d:i128 = read();
    let mut x = x.abs();
    if x >= d * k {
        println!("{}", x - d * k);
    } else {
        let y = x / d;
        x -= d*y;
        if x <= (x-d).abs() {
            k -= y;
        } else {
            x -= d;
            k = k - y - 1;
        }
        if k % 2 == 0 {
            println!("{}", x.abs());
        } else {
            println!("{}", min((x - d).abs(), (x + d).abs()));
        }
    }
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,s = -1,col[700] = {};
	bool ise[700][700] = {};
	vector<int> G[800];
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].pb(b);
		G[b].pb(a);
		ise[a][b] = true;
		ise[b][a] = true;
	}
	for(int i = 0;i < n;i++){
		if(G[i].size() != n - 1) s = i;
	}
	if(s == -1){
		cout << (n / 2) * (n / 2 - 1) / 2 + ((n + 1) / 2) * ((n + 1) / 2 - 1) / 2<< endl;
		return 0;
	}
	queue<int> que;
	col[s] = 1;
	que.push(s);
	bitset<700> bit;
	bit.set(0);
	for(int t = 1;;t++){
		while(!que.empty()){
			int v = que.front();que.pop();
			for(int i = 0;i < n;i++){
				if(i != v && !ise[i][v]){
					if(!col[i]){
						col[i] = ((col[v] == t) ? -t : t);
						que.push(i);
					}else if(col[i] == col[v]){
						cout << -1 << endl;
						return 0;
					}
				}
			}
		}
		int cnt1 = 0,cnt2 = 0,cnt3 = 0;
		s = -1;
		for(int i = 0;i < n;i++){
			if(col[i] == t) cnt1++;
			else if(col[i] == -t) cnt2++;
			else if(!col[i]){
				if(G[i].size() != n - 1) s = i;
				cnt3++;
			}
		}
		bit = (bit << cnt1) | (bit << cnt2);
		if(s == -1){
			for(int i = 0;i < cnt3;i++) bit |= (bit << 1);
			break;
		}
		que.push(s);
		col[s] = t + 1;
	}
	for(int i = n / 2;i >= 0;i--){
		if(bit[i]){
			cout << i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define F first
#define S second
#include<unordered_map>
using namespace std;
typedef long long ll;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=3e5+9;
ll x,y;
ll gcd(ll x,ll y){
    if(x<y)swap(x,y);
    if(y==0)return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x/gcd(x,y)*y;
}
int main(){
    cin>>x>>y;
    if(x==y||y==1||x%y==0){
        puts("-1");
        return 0;
    }
    cout<<x<<endl;
}


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

int n,L,T,a[N],b[N],p[N],ans[N];
bool cmp(int x,int y){
	return (x-b[1]+L)%L<(y-b[1]+L)%L;
}
int main(){
	scanf("%d%d%d",&n,&L,&T);
	int i,x,y;
	for (i=1; i<=n; i++) scanf("%d%d",&a[i],&p[i]);
	for (i=1; i<=n; i++)
		if (p[i]==1) b[i]=(a[i]+T)%L;
		else b[i]=((a[i]-T)%L+L)%L;
	if (n>1) sort(b+2,b+n+1,cmp);
	T<<=1;
	if (p[1]==1){
		for (i=2,x=1; i<=n; i++) if (p[i]==2){
			y=(a[i]-a[1]+L)%L;
			if (T>y) x=(x+1+(T-y-1)/L)%n;
		}
	} else{
		for (i=2,x=1; i<=n; i++) if (p[i]==1){
			y=(a[1]-a[i]+L)%L;
			if (T>=y) x=(x-1-(T-y)/L)%n;
		}
		x=(x+n)%n;
	}
	if (!x) x=n;
	for (i=1; i<=n; i++,x=x%n+1) ans[x]=b[i];
	for (i=1; i<=n; i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
#include<string.h>
int main()
{int n;
scanf("%d",&n);
	long long int a[200050],b[200050];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)
	{
	  scanf("%lld",&a[i]);
	  b[a[i]]++;
	  }
	long long int s=0;
	for(int i=1;i<=n;i++)
	{   
		s+=b[i]*(b[i]-1)/2;
	}
	for(int i=1;i<=n;i++)
	{long long int c=0;
		if(b[a[i]]>1)
		{
			c=b[a[i]]*(b[a[i]]-1)/2-(b[a[i]]-1)*(b[a[i]]-2)/2;
		}
		long long int p=s-c;
		printf("%lld",p);
		if(i!=n)printf("\n");
	}
}

Measured memory_bytes: 5632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	A := nextInt()
	B := nextInt()

	min := int(1e18)
	for i := 1009; 0 < i; i-- {
		tax8 := int(float64(i) * 0.08)
		tax10 := int(float64(i) * 0.1)
		if tax8 == A && tax10 == B {
			min = i
		}
	}
	if min == int(1e18) {
		fmt.Println(-1)
	} else {
		fmt.Println(min)
	}
}


Measured memory_bytes: 640
import sys

a,b=map(int,input().split())
if(a>=b):
    manyC="."
    fewC="#"
    many=a
    few=b
else:
    many=b
    few=a
    manyC="#"
    fewC="."
h,w=97,97
outp=[[(fewC)for j in range(w)]for i in range(h)]
for i in range(many):
    if((i//25)==0):y=0
    elif((i//25)==1):y=3
    else:y=4*(i//25)-1
    if((i%25)==0):x=1
    elif((i%25)==1):x=3
    else:x=4*(i%25)-1
    outp[y][x]=manyC
for j in range(few-1):
    if(j==0):
        outp[1][0]=manyC
        outp[1][1]=manyC
    elif(j//25==0):
        x=j*4-1
        outp[1][x]=manyC
        outp[1][x+1]=manyC
        if(j!=24):
            outp[1][x+2]=manyC
            outp[0][x+2]=manyC
    else:
        y=4*(j//25)-1
        if(j%25==0):
            outp[y][0]=manyC
            outp[y+1][1]=manyC
            outp[y+2][1]=manyC
            outp[y+2][0]=manyC
        else:
            x=4*(j%25)-1
            outp[y][x+1]=manyC
            outp[y+1][x]=manyC
            outp[y+2][x]=manyC
            outp[y+2][x+1]=manyC
            if((j%25)!=24):
                outp[y][x+2]=manyC
                outp[y+1][x+2]=manyC
                outp[y+2][x+2]=manyC
print(h,w)
for i in range(h):
    print("".join(outp[i]))

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

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

    bool judge = false;
    if ( abs(c-a) <=d ) judge = true;
    if (abs(a-b) <= d && abs(c-b) <= d) judge = true;

    if(judge) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  int f=0;
  for(int i=0;i<n;i++){
  cin >> s;
  if(s=="Y")f=1;
  }
  if(f==1)cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   int a[5] = {0};
   string march = "MARCH";
   rep (i, n) {
      string s;
      cin >> s;
      auto p = march.find(s[0]);
      if (p == string::npos) continue;
      a[p]++;
   }

   ll sum = 0;
   rep (i, 5) {
      repp (j, i+1, 5) {
         repp (k, j+1, 5) {
            sum += 1LL *  a[i] * a[j] * a[k];
         }
      }
   }
   cout << sum << endl;

   return 0;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18;
const int INF = 1e9;
const double EPS = 0.000000001;
struct edge {ll to, cost; };
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pC(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<P> c;
  REP(i, m){
    int a, b;
    cin >> a >> b;
    c.emplace_back(a, b);
  }
  sort(ALL(c), [&](P x, P y){
    return x.snd < y.snd;
  });
  int ans = 0;
  int d = -1;
  REP(i, c.size()){
    if(c[i].fst <= d) continue;
    else {
      ans++;
      d = c[i].snd - 1;
    }
  }
  out(ans);

  return 0;
}


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

int main()
{
    int x, y;
    cin >> x >> y;

    bool is_ok = false;

    for (int i = 0; i <= x; ++i)
    {
        if (i * 2 + (x - i) * 4 == y)
            is_ok = true;
    }
    if (is_ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;
using ll = long long;

ll fact[100010];

void init(ll p){
    fact[0] = 1;
    for(ll i=1;i<sizeof(fact)/sizeof(ll);i++){
        fact[i] = fact[i-1] * i % p;
    }
}

ll extgcd(ll a, ll b, ll& x, ll& y){
    ll d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b)*x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x%m) % m;
}

ll mod_fact(ll n, ll p, ll& e){
    e = 0;
    if(n == 0) return 1;

    ll res = mod_fact(n/p, p, e);
    e += n/p;

    if(n/p % 2 != 0) return res * (p-fact[n%p]) % p;
    return res * fact[n%p] % p;
}

ll mod_comb(ll n, ll k,  ll p){
    if(n < 0 || k < 0 || n < k) return 0;
    ll e1, e2, e3;
    ll a1 = mod_fact(n, p, e1);
    ll a2 = mod_fact(k, p, e2);
    ll a3 = mod_fact(n-k, p, e3);
    if(e1 > e2+e3) return 0;
    return a1*mod_inv(a2*a3 % p, p) % p;
}


int main(void){
    init(1000000007);
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    int x=0,y=0;
    for(int i=1;i<=n+1;i++){
        int p;
        cin >> p;
        if(a[p]){
            x = a[p];
            y = i;
        }
        a[p] = i;
    }
    
    for(ll k=1; k<=n+1;k++)
    {
        ll a = mod_comb(n+1, k, 1000000007);
        ll b = mod_comb(x-1 + n+1-y, k-1, 1000000007);
        cout << (a - b + 1000000007)%1000000007 << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

template<typename T>
T gcd(T a, T b) {
  if(a < b) swap(a,b);
    
  if(b == 0) return a;
  return gcd(b, a % b);
}


int main(){
  cout << setprecision(10);

  ll K; cin >> K;

  ll ans = 0;
  for(ll i = 1; i <= K; i++){ 
    for(ll j = i; j <= K; j++){ 
      for(ll k = j; k <= K; k++){ 

        ll tmp = gcd(i, gcd(j,k));
        if(i == j && j == k){
          ans += tmp;
        } else if(i == j || j == k){
          ans += tmp * 3;
        } else { 
          ans += tmp * 6;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	ll A, B; cin >> A >> B;
	cout << 6 - (A + B) << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
ruisekiwa = [0]*(N+1)
now = 0
minimum = 10**10
for i in range(N):
  now += A[i]
  ruisekiwa[i+1] = now
for i in range(N-1):
  snuke = ruisekiwa[i+1]
  arai = ruisekiwa[N]-snuke
  K = abs(snuke-arai)
  if K < minimum:
    minimum = K
print(minimum)

Measured memory_bytes: 24824
#include"bits/stdc++.h"
using namespace std;
int N,M,mx;
string t,s[110];
map< string,int > mp;
int main(){
    cin>>N ;
    for (int i=0;i<N;++i) cin>>s[i],mp[s[i]]++;
  //  for(int i=0;i<N;++i){
 //       cout<<mp[s[i]]<<" ";
 // }
    cin>>M;
    while(M--) cin>>t,mp[t]--;
  //  cout<<mp[t]<<" ";
    for (int i=0;i<N;++i) mx=max(mx,mp[s[i]]);
    cout << mx ;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	cout<<count(s.begin(),s.end(),'1')<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int a;
  int b;
  cin >> a >> b;
  if (a < b) {
    cout << "a" << " < " << "b" << endl;
  }else if (a > b){
    cout << "a" << " > " << "b" << endl;
  }else if (a == b){
    cout << "a" << " == " << "b" << endl;
  }
  return 0;
}



Measured memory_bytes: 3116
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		List<Integer>[] es = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			es[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			es[a].add(b);
			es[b].add(a);
		}

		long[] dp = new long[n];
		for (int i = 0; i < q; i++) {
			int v = sc.nextInt() - 1;
			int x = sc.nextInt();
			dp[v] += x;
		}

		Queue<int[]> queue = new LinkedList<>();
		queue.offer(new int[]{0, -1});
		while (!queue.isEmpty()) {
			int[] x = queue.poll();
			if (x[1] >= 0) dp[x[0]] += dp[x[1]];

			for (Integer e : es[x[0]]) {
				if (e != x[1]) {
					queue.offer(new int[]{e, x[0]});
				}
			}
		}

		for (int i = 0; i < dp.length; i++) {
			System.out.print(dp[i]);
			System.out.print(" ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 210512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

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

    vector<int> p(m);
    vector<string> s(m);
    REP(i,m){
        cin>>p[i]>>s[i];
    }

    vector<bool> judge(n);
    vector<int> wa(n);
    int numC=0,penalty=0;

    REP(i,m){
        if(judge[p[i]-1]){
            continue;
        }else{
            if(s[i]=="AC"){
                numC++;
                penalty+=wa[p[i]-1];
                judge[p[i]-1]=true;
            }else{
                wa[p[i]-1]++;
            }
        }
    }

    cout<<numC<<" "<<penalty<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define dmp make_pair
typedef pair<int,int> P;
typedef pair<int, P> PP;
const int inf = 1e9;
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)

int a[1002][1002], b[1002][1002];
int dy[] = {-1, 0, 0, 1}, dx[] = {0, -1, 1, 0};
priority_queue<PP, vector<PP>, greater<PP> > q;
int main(){
	int h, w, ans = 0;
	scanf("%d%d", &h, &w);
	fill((int*)a, (int*)(a+1002), inf);
	rrep(i,h)rrep(j,w)scanf("%d", &a[i][j]);
	rrep(y,h)rrep(x,w){
		int f = 0;
		rep(i,4)if(a[y][x] < a[y+dy[i]][x+dx[i]])f++;
		if(f == 4)b[y][x] = a[y][x];
		q.push(dmp(a[y][x], P(y, x)));
	}
	
	while(!q.empty()){
		PP p = q.top();q.pop();
		int y = p.se.fi, x = p.se.se;
		if(b[y][x] == -1)ans++;
		for(int i = 0;i < 4;i++){
			int yy = y+dy[i], xx = x+dx[i];
			int f = (a[y][x] < a[yy][xx]);
			if(f && b[yy][xx] == 0){
				b[yy][xx] = b[y][x];
			}else if(f && b[y][x] != b[yy][xx] && b[yy][xx] != -1){
				b[yy][xx] = -1;
			}
		}
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 22584
#include <iostream>
#include <map>
#include <string>

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::map<std::string, long> m;
  for (int i = 0; i < q; ++i) {
    int c;
    std::string key;
    std::cin >> c >> key;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      m[key] = x;
      break;
    case 1:
      if (m.find(key) != m.end())
        std::cout << m.at(key) << std::endl;
      else
        std::cout << 0 << std::endl;
      break;
    case 2:
      m.erase(key);
      break;
    }
  }
}



Measured memory_bytes: 27684
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())
uf = UnionFind(N+1)

P = [int(i) for i in input().split()]

for i in range(M):
    x, y = map(int, input().split())
    uf.Unite(x, y)

ans = 0
for i in range(1, N+1):
    if uf.isSameGroup(i, P[i-1]):
        ans += 1
print(ans)


Measured memory_bytes: 93424
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
 
inline int read(){
	char ch = getchar(); int x = 0, op = 1;
	while (ch < '0' || '9' < ch) { if (ch == '-') op = -1; ch = getchar(); }
	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); }
	return op * x;
}
const int maxn = 100009;
LL n, s[maxn], t, res1, res2, op;
 
int main(){
	n = read();
	for (LL i=1; i<=n; i++) s[i] = s[i-1] + read();
	op = 1; t = 0;
	for (LL i=1; i<=n; i++){
		if (op == 1 && (s[i]+t) <= 0){
			res1 += 1 - (s[i]+t);
			t = 1 - s[i];
		}
		if (op == -1 && (s[i]+t) >= 0){
			res1 += (s[i]+t) + 1;
			t = -s[i] - 1;
		}
		op = -op;
	}
	op = -1; t = 0;
	for (LL i=1; i<=n; i++){
		if (op == 1 && (s[i]+t) <= 0){
			res2 += 1 - (s[i]+t);
			t = 1 - s[i];
		}
		if (op == -1 && (s[i]+t) >= 0){
			res2 += (s[i]+t) + 1;
			t = -s[i] - 1;
		}
		op = -op;
	}
	printf("%lld\n", min(res1, res2));
	return 0;
}

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

int main(void)
{
	int i,j;
	int h,w;
	
	while(1)
	{
		cin >> h >> w;
		
		if((h == 0) && (w == 0))
			break;
		for(i = 0; i < h; i++)
		{
			for(j = 0; j < w; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;

int main() {
	long N, K;
	cin >> N >> K;
	if (K%N == 0) {
		show(N + K);
}
	else {
		show(K - N);
	}



	return 0;

}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
n=int(input())
a=[int(x) for x in input().split()]
ma=max(a)
memo=[0]*ma

def gcd(a,b):#最大公約数
  while b!=0:
    a,b=b,a%b
  return a

for i in a:
  memo[i-1]+=1

pair=True
for i in range(2,ma+1):
  cnt=0
  for j in range(i,ma+1,i):
    if 0<memo[j-1]:
      cnt+=1
  if 1<cnt:
    pair=False


g=a[0]
for i in range(1,n):
  g=gcd(g,a[i])

if pair == False and g==1:
  print("setwise coprime")
elif pair == True and g==1:
  print("pairwise coprime")
else:
  print("not coprime")
    

Measured memory_bytes: 194484
from math import atan, degrees, pi

a, b, x = map(int, input().split())

if x/a >= a*b / 2:
    t_theta = 2*(a*b - x/a) / (a*a)
    theta = degrees(atan(t_theta))
else:
    t_theta = 2 * x / (a * b**2)
    theta = degrees(atan(1 / t_theta))

print(theta)


Measured memory_bytes: 2940
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e4;
std::vector<std::vector<int>> g;
int d[N];
int c[N];

int ans = 0;
int now;

void dfs(int i, int p = -1) {
  d[i] = c[now];
  now--;
  for(auto j : g[i]) if(j != p) {
    dfs(j, i);
  }
}

int n;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  g.resize(n);
  vector<pair<int, int>> v;
  for(int i = 0; i < n - 1; i++) {
    int a, b; std::cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    v.emplace_back(a, b);
  }
  for(int i = 0; i < n; i++) cin >> c[i];
  now = n - 1;
  sort(c, c + n);
  // for(int i = 0; i < n; i++) {
  // }
  dfs(0);
  for(int i = 0; i < n - 1; i++) {
    ans += min(d[v[i].first], d[v[i].second]);
  }
  cout << ans << endl;
  for(int i = 0; i < n; i++) cout << d[i] << " \n"[i == n - 1];
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

vector<string> split(string base, char spl){
  vector<string> result;
  string::size_type pos = 0;
  string::size_type bef = 0;
  base += spl;
  while( (pos = base.find_first_of(spl,bef)) != string::npos ){
    result.push_back(base.substr(bef,pos-bef));
    bef = pos+1;
  }
  return result;
}

int toint(string s){
  return atoi(s.c_str());
}

// year : 2013 ~ 2413 ( 1e7 )
// month : 12
// day : 31
int maya_to_ad[150000];
int ad_to_maya[1000000];
int span;

bool is_uruu(int y){
  return (y%4==0 && (y%100!=0 || y%400==0));
}

int daylist[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

void calc(){
  int y = 2012;
  int m = 12;
  int d = 21;
  REP(i,150000){
    int id = ((y*12)+(m-1))*31+(d-1);
    maya_to_ad[i] = id;
    ad_to_maya[id] = i;
    if(y==2412 && m==12 && d==21) span = i;
    ++d;
    if(d > daylist[m-1]){
      if(m==2 && is_uruu(y) && d==29){
        // do nothing
      }else if(m==12){
        // next year
        ++y;
        m=1;
        d=1;
      }else{
        // next month
        ++m;
        d=1;
      }
    }
  }
}

int main(){
  // mae shori
  // 400 years
  calc();
  // input
  while(true){
    string s;
    cin>>s;
    if(s=="#")break;
    vector<string> input = split(s,'.');
    if(input.size()==3){
      // year.month.day
      int year = toint(input[0]);
      int month = toint(input[1]);
      int day = toint(input[2]);
      int yeardown = (year-2013)/400;
      year -= yeardown * 400;
      int id = ((year*12)+(month-1))*31+(day-1);
      // over flow
      ll maya = ad_to_maya[id];
      maya += (ll)yeardown * (ll)span;
      maya %= 1872000;
      int ki = maya%20; maya/=20;
      int w = maya%18;  maya/=18;
      int t = maya%20;  maya/=20;
      int ka = maya%20; maya/=20;
      int b = maya;
      printf("%d.%d.%d.%d.%d\n",b,ka,t,w,ki);
    }else{
      // b.ka.t.w.ki
      int b = toint(input[0]);
      int ka = toint(input[1]);
      int t = toint(input[2]);
      int w = toint(input[3]);
      int ki = toint(input[4]);
      int id = ((((b*20)+ka)*20+t)*18+w)*20+ki;
      int yearadd = id/span;
      id %= span;
      int ad = maya_to_ad[id];
      int day = 1+ad%31;    ad/=31;
      int month = 1+ad%12;  ad/=12;
      int year = ad + yearadd*400;
      printf("%d.%d.%d\n",year,month,day);
    }
  }
  return 0;
}

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

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007

using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second > right.second;
}

int main() {
    int a,b,c;
    cin >> a;
    cout << a*a;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	int ans = m;
	rep(i,n-m+1){
		int cnt = 0;
		rep(j,m){
			if(s[i+j] != t[j]) ++cnt;
		}
		chmin(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3660
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val n = readLine()?.toInt() ?: return
    val a = longList()
    val b = longList().sorted()
    val c = longList().sorted()
    val bc = Array(n + 1) { 0L }
    var t = 0L

    var s = 0L
    (n - 1).downTo(0).forEach {
        val bb = b[it]
        val u = c.upperBound(bb)
        s += n - u
        bc[it] = s
    }
    repeat(n) {
        val aa = a[it]
        val i = b.upperBound(aa)
        t += bc[i]
    }
    println(t.toString())
}

fun <T : Comparable<T>> List<T>.upperBound(e: T): Int {
    val index = binarySearch(e, Comparator { x, y -> if (x > y) 1 else -1 })
    return if (index >= 0) {
        index
    } else {
        -(index + 1)
    }
}



Measured memory_bytes: 71924