akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;


    List<int>[] es;
    bool[] used;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        es = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i = 0; i < M; i++)
        {
            A[i] = cin.nextInt() - 1;
            B[i] = cin.nextInt() - 1;
            es[A[i]].Add(B[i]);
            es[B[i]].Add(A[i]);
        }
        l = new List<int>();
        used = new bool[N];

        l = new List<int>();
        bfs(0);
        l.Reverse();
        List<int> L2 = new List<int>(l);
        L2.RemoveAt(L2.Count - 1);
        l = new List<int>();

        bfs(0);
        Console.WriteLine(L2.Count + l.Count);
        foreach (var item in L2)
        {
            Console.Write(item + " ");
        }
        foreach (var item in l)
        {
            Console.Write(item + " ");
        }
        Console.WriteLine();
    }

    void bfs(int a)
    {
        while (true)
        {
            int NE = -1;
            used[a] = true;
            l.Add(a + 1);
            foreach (var next in es[a])
            {
                if (used[next]) continue;
                NE = next;
                break;
            }
            if (NE == -1) break;
            a = NE;
        }
    }

    List<int> l;
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 28044
def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default


list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
list3 = list(map(int, input().split()))
N = int(input())
num_list = [int(input()) for _ in range(N)]

list1.extend(list2)
list1.extend(list3)
hit_list = [0] * 9

for num in num_list:
    res = my_index(list1, num)
    if res != -1:
        hit_list[res] += 1

if (hit_list[0] > 0 and hit_list[1] > 0 and hit_list[2] > 0) or (
        hit_list[3] > 0 and hit_list[4] > 0 and hit_list[5] > 0) or (
        hit_list[6] > 0 and hit_list[7] > 0 and hit_list[8] > 0):
    print('Yes')
elif (hit_list[0] > 0 and hit_list[3] > 0 and hit_list[6] > 0) or (
        hit_list[1] > 0 and hit_list[4] > 0 and hit_list[7] > 0) or (
        hit_list[2] > 0 and hit_list[5] > 0 and hit_list[8] > 0):
    print('Yes')
elif (hit_list[0] > 0 and hit_list[4] > 0 and hit_list[8] > 0) or (
        hit_list[2] > 0 and hit_list[4] > 0 and hit_list[6] > 0):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    bool flag = true;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        if (A % 2)
            continue;
        if ((A % 3) && (A % 5))
            flag = false;
    }

    cout << (flag ? "APPROVED" : "DENIED") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n,p; cin>>n>>p;
if((n+1)/2>=p){
cout << "YES" << endl;}
else
cout << "NO" << endl;}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n,m;
    cin>>n>>m;
    V<int> a(m),b(m);
    V<int> c(n,0);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        c[a[i]]++;
        c[b[i]]++;
    }
    bool ok=1;
    rep(i,n){
        if(c[i]%2==1) ok=0;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算の際にオーバーフローに注意せよ！(適切にmodをとれ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
*/

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
int main() 
{
	string s;
	cin >> s;
	vector <char> v(s.size());
	for(int i = 0; i < s.size(); ++i) {
		v[i]= s[i];
	}
	int q, x, y = 0;
	cin >> q;
	char ch;
	bool ok = 1;
	while(q--) {
		cin >> x;
		if(x == 1) {
			ok = !ok;
		} else {
			cin >> x >> ch;
			if(x == 1) {
				if(ok) {
					v.insert(v.begin(), ch);
				} else {
					v.push_back(ch);
				}	
			} 
			else {
				if(ok) {
					v.push_back(ch);
				} else {
					v.insert(v.begin(), ch);
				}
			}
		}
	}
	if(!ok) {
		for(int i = v.size()-1; i >= 0; --i) {
			cout << v[i];
		} cout << endl;
		return 0;
	}
	for(auto i : v) {
		cout << i;
	} cout << endl;
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> vec(2 * a);
  for (int i = 0; i < 2 * a; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int ans = 0;
  for (int i = 1; i < 2 * a; i += 2) ans += vec[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
//2018-03-25
//LZYeah
//
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Forr(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
inline void File()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
inline void read(ll &x)
{
	ll p=1;
	x=0;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
#define N (100000+10)
ll n;
ll a[N],sum[N],tot;
int main()
{
//	File();
	read(n);
	For(i,1,n)read(a[i]),sum[i]=abs(a[i]-a[i-1]),tot+=sum[i];
	sum[n+1]=abs(a[n]),tot+=sum[n+1];
	For(i,1,n)printf("%lld\n",tot-sum[i]-sum[i+1]+abs(a[i+1]-a[i-1]));
	return 0;
}


Measured memory_bytes: 2816
s = int(input())
a = [s]
ans = 1
n = s
while 1:
    if n%2 == 0:
        n = n//2
    else:
        n = n*3 + 1
    if n in a: 
        ans += 1
        break
    a.append(n)
    ans += 1

print(ans)




Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define INF 1e15
#define NASH 1e9+7
#define MAXN 200005
using namespace std;
ll n,m,s,a[MAXN],cnt;
int main(){
    cin>>n>>m;
    for (int i=0; i<n; i++){
        cin>>a[i];
        s+=a[i];
    }
    for (int i=0; i<n; i++)
        if (4*a[i]*m>=s) cnt++;
    if (cnt>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}
/*
*/

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p;
  for(int i=0;i<n;i++){
    int tmp;
	cin>>tmp;
      p.push_back(tmp);
  }
  sort(p.begin(),p.end());
  int ans = 0;
  for(int i = 0;i<k;i++){
    ans+=p.at(i);
  }
  cout<<ans<<endl;
}
    
	

Measured memory_bytes: 3624
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int WW = scan.nextInt();
	    int HH = scan.nextInt();
	    int xx = scan.nextInt();
	    int yy = scan.nextInt();
	    int rr = scan.nextInt();

		if ((WW >= xx + rr) && (HH >= yy + rr)&&(0 <= xx - rr)&&(0 <= yy - rr)) {
	    	System.out.println( "Yes" );
		}
	    else {
	    	System.out.println( "No" );
		}

	}

}

Measured memory_bytes: 26276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
char *s = new char[N];
int a[N];
#define MOD 1'000'000'007LL;

int main(){
	int n; scanf("%d%s", &n, s+1);
	s[0] = s[2*n+1] = 'W';
	a[0] = 1;
	FOR(i, 1, 2*n+2){
		int x = s[i-1] == s[i] ? 0 : 1;
		int y = a[i-1] == -1 ? 1 : 0;
		a[i] = x == y ? -1 : 1;
		// DEBUG("%d-%d-", x, y);
		DEBUG("%d ", a[i]);
	}
	DEBUG("\n");
	if(a[2*n+1] != -1) return printf("0\n"), 0;
	ll ans = 1;
	int x = 0;
	FOR(i, 1, 2*n+1) {
		if(a[i] == -1){
			DEBUG("%d ", x);
			ans = ans * max(x, 0) % MOD;
		}
		x += a[i];
	}
	if(x != 0) ans = 0;
	REP(i, n) ans = ans * (i+1) % MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

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

const int N = (int)1e5 + 1;

int ce[N], co[N];

int main() {
  int n;
  cin >> n;
  int e[n/2], o[n/2];
  rep(i, n/2) {
    cin >> e[i] >> o[i];
  }

  rep(i, n/2) {
    ce[e[i]]++;
    co[o[i]]++;
  }

  int me1 = 0, ie, me2, mo1 = 0, io, mo2;
  rep(i, N) {
    if(me1 <= ce[i]) {
      me2 = me1;
      me1 = ce[i];
      ie = i;
    } else if (me2 <= ce[i]) {
      me2 = ce[i];
    }
    if(mo1 <= co[i]) {
      mo2 = mo1;
      mo1 = co[i];
      io = i;
    } else if (mo2 <= co[i]) {
      mo2 = co[i];
    }
  }

  int res;
  if(ie != io) res = n - (me1 + mo1);
  else res = n - max(me1 + mo2, me2 + mo1);

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] s1 = sc.nextLine().split(" ");
    String[] s2 = sc.nextLine().split(" ");
    int[][] m = new int[2][N];
    for(int i = 0; i < N; i++){
      m[0][i] = Integer.parseInt(s1[i]);
      m[1][i] = Integer.parseInt(s2[i]);
    }
    
    int max = 0;
    for(int i = 0; i < N; i++){
      int n = 0;
      int s = 0;
      for(int j = 0; j < N; j++){
        n += m[s][j];
        if(j == i){
          s++;
          n += m[s][j];
        }
      }
      if(n > max){
        max = n;
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21844
#B - ... (Triple Dots)

K = int(input())
S = input()
lis = []

if len(S) <= K:
    print(S)
elif len(S) > K:
    for i in range(K):
        lis.append(S[i])
    lis.append("...")
for i in lis:
    print(i, end ="")

Measured memory_bytes: 9104
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int x,n;cin>>x>>n;
    dump(x,n);
    vector<ll> p(n);

    vec<int> e(105);
    rep(i, n) {
        cin>>p[i];
        e[p[i]]++;
    }
    dump(p);

    int d = 1e9;
    int ans = -1;
    rep(y, 0, 105){
        if (e[y]==0){
            if (abs(y-x) < d){
                ans = y;
                d = abs(y-x);
            }
        }
    }
    cout << ans << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


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

#define MAX 100

int main(void)
{
  int H, W;
  char tile[MAX][MAX];

  while (1) {
    
    int x = 0, y = 0;

    for(int i = 0 ; i < MAX ; i++) {
      for(int j = 0 ; j < MAX ; j++) {
	tile[i][j] = '.';
      }
    }
    
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    
    for(int i = 0 ; i < H ; i++) {
      for(int j = 0 ; j < W ; j++) {
	cin >> tile[i][j];
      }
    }
    
    int cal=0, sum=0;
    cal = H * W;

    //for(int i = 0 ; i < H ; i++) {
    //for(int j = 0 ; j < W ; j++) {
    while(tile[x][y] != '.') {
      if(tile[x][y] == '>') y++, sum++; 
      else if(tile[x][y] == '<') y--, sum++;
      else if(tile[x][y] == '^') x--, sum++;
      else if(tile[x][y] == 'v') x++, sum++;
      if(sum > cal) break;
      //cout << "x = " << x << endl << "y = " << y << endl;
    }
    if(sum <= cal) cout << y << ' ' << x << endl;
    else cout << "LOOP" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	static int cheak(int a,int b,int i) {
		int sum=0;
		if(i==0) {
			if(a==0)sum = b;
			else if(b==0)sum = a;
			else sum = a+b;
		}
		else if(i==1) {
			if(a==0)sum = -b;
			else if(b==0)sum = a;
			else sum = a-b;
		}
		return sum;
	}
	static String print(int c) {
		String s = "";
		if(c==0)return s = "+";
		if(c==1)return s = "-";
		return s;
	}
	public static void main(String[] args) {
		
		try(Scanner sc = new Scanner(System.in)){
			String str = sc.next();
			String[] strArray = str.split("");
			int[] s = new int[4];
			int[][][] sum = new int[2][2][2];
			int flag = 0;
			String w="",q="",r="";
			
			for(int i=0;i<4;i++) {
				s[i] = Integer.parseInt(strArray[i]);
			}
			
			
			for(int i=0;i<2;i++) {
				int sumi = cheak(s[0],s[1],i);
				for(int j=0;j<2;j++) {
					int sumj = cheak(sumi,s[2],j);
					for(int k=0;k<2;k++) {
							sum[i][j][k] = cheak(sumj,s[3],k);
							if(sum[i][j][k] == 7) {
								w = print(i);q = print(j);r = print(k);
								flag = 1;
								break;
							}
					}
					if(flag == 1) break;
				}
				if(flag == 1) break;
			}
			
			System.out.print(s[0]+w+s[1]+q+s[2]+r+s[3]+"=7");
		}
	}
}



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

ll a,b,c,n,m;
ll ans=100000000000;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>a>>b;
  cout<<a*b;

  return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
int n,a[200000],m1=0,t=1,m2=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if (m1<a[i])
			m1=a[i],t=1;
		else if (m1==a[i])
			t++;
	}
	if (t==1){
		for (int i=0;i<n;i++)
			if (a[i]!=m1)
				m2=max(m2,a[i]);
	}
	for (int i=0;i<n;i++){
		if (a[i]!=m1)
			cout<<m1<<"\n";
		else {
			if (t==1)
				cout<<m2<<"\n";
			else 
				cout<<m1<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 2432
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int min[] = new int[n];
    int max[] = new int[n];
    for (int i = 0; i < n; i++) {
      min[i] = Integer.parseInt(sc.next());
      max[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(min);
    Arrays.sort(max);
    if (n % 2 == 1) {
      pw.println(
        (int) median(max) - (int) median(min) + 1
      );
    } else {
      pw.println((int) ((median(max) - median(min)) * 2) + 1);
    }
  }

  static double median(int sorted[]) {
    if (sorted.length % 2 == 1) {
      return sorted[sorted.length / 2];
    }
    return (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2d;
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	int N;

	cin >> N;

	int im = (N+1) / 2;
	cout << (double) im / N << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	char a, b;
	while(cin >> a >> b) {
		if(a > b)
			cout << ">" << endl;
		else if(a < b)
			cout << "<" << endl;
		else
			cout << "=" << endl; 
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b=0,mini=2000000,c=0,d=0;
    string str;
    cin >> a;
    cin >> str;
    for(int i=0;i<a;i++){
        if(str[i]=='#'){
            b++;
        }
    }
    if(b>0) mini=min(mini,c+b);
    for(int i=a-1;i>=0;i--){
        if(b==0) break;
        if(str[i]=='.'){
            c++;
        }else{
            b--;
            mini=min(mini,c+b);
        }
    }
    if(mini==2000000) mini=0;
    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(){
	int w, n;
	cin >> w;
	cin >> n;
	cin.ignore();
	
	vector<int> v(w);
	for(int i = 1; i <= v.size(); i++){
		v[i - 1] = i;
	}

	int a, b, c;
	string buf;
	for(int i = 0; i < n; i++){
		getline(cin, buf);
//		cin >> buf;
		sscanf(buf.c_str(), "%d, %d", &a, &b);
		c = v[a - 1];
		v[a - 1] = v[b - 1];
		v[b - 1] = c;
	}
	for(int& i : v){
		cout << i << endl;
	}
}

Measured memory_bytes: 3232
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn divisor(n: usize) -> Vec<usize> {
    let mut res = Vec::new();
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            res.push(i);
            if i != n / i {
                res.push(n / i);
            }
        }
        i += 1;
    }
    res.sort();
    res
}

fn solve() {
    input! {
        a: u64,
        b: u64
    }

    let gcd_num = gcd(a, b) as usize;

    let mut divides = divisor(gcd_num);

    let mut disjoints = divides.clone();

    for i in divides.into_iter().skip(1) {
        disjoints = disjoints
            .into_iter()
            .filter(|&x| x == i || x % i != 0)
            .collect();
    }

    println!("{:?}", disjoints.len());
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet
// 最大公約数
fn gcd(a: u64, b: u64) -> u64 {
    let mut aa: u64 = if a > b { a } else { b };
    let mut bb: u64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// 最小公倍数
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}


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

namespace id_0641cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = vs[0];
            var a = vs[1];
            var b = vs[2];
            var c = vs[3];
            var d = vs[4];
            var moneyOfXSet = n % a == 0 ? n / a * b : (n / a + 1) * b;
            var moneyOfYSet = n % c == 0 ? n / c * d : (n / c + 1) * d;
            Console.WriteLine(Math.Min(moneyOfXSet, moneyOfYSet));

        }
    }
}



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

int main(){
 	int k;
  	cin>>k;
  	string s;
  	cin>>s;
  	
  	if(s.length()<=k){
  	    cout<<s<<endl;
  	}
  	else{
  	    for(int i=0;i<k;i++){
  	        cout<<s[i];
  	    }
  	    cout<<"..."<<endl;
  	}
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int N, W;
  cin >> N >> W;
  vector<vector<ll>> dp(N+1, vector<ll> (W+1, 0));
  // w, v
  vector<pair<int, int>> items(N+1);
  rep(i, 1, N+1) {
    cin >> items[i].first >> items[i].second;
  }

  ll ans = 0;

  rep(i, 1, N+1) {
    rep(j, 0, W+1) {
      if (j+items[i].first <= W) {
        dp[i][j+items[i].first] = max(dp[i - 1][j+items[i].first], dp[i-1][j] + items[i].second);
      }
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
    }
  }

  rep(i, 1, W+1) {
    ans = max(ans, dp[N][i]);
  }

  cout << ans << endl;
};


Measured memory_bytes: 80256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b; cin >> a >> b;
    int s[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    cout << ((s[a] == s[b]) ? "Yes":"No") <<endl; return 0;
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	
	int n, k;
	cin >> n >> k;
	
	ll ans = 1;
	ll pat = n / k;//(k % 2 == 0 ? k / 2 : k);
	ans = pat * pat * pat;
	if(k % 2 == 0){
		ll aa = n * 2 / k - pat;
		ans += aa * aa * aa;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

[N, A, B, C, D] = [int(i) for i in input().split()]

S = input()

# '#'が2連続あれば移動不可能
minimum = min([A, B])
maximum = max([C, D])
S_split = S[minimum-1:maximum].split('.')

max_length = 0
for s in S_split:
    if len(s) > max_length:
        max_length = len(s)

if max_length >= 2:
    print('No')
    sys.exit()

# ここまでくればBは必ず目的地に到着可能

# もしC<DだったらAも必ず到着可能
if C < D:
    print('Yes')
    sys.exit()

# もしC>Dだったら、Dの手前が'#'もしくはDの奥が'#'の場合はAはほぼ到達不可能
if S[D-2] == '#' or S[D] == '#':
    # もしS[B-1]からS[D-1]の間に'...'があれば、もしくは[A, B, .]であればAは到達可能
    if '...' in S[B-2:D]:
        print('Yes')
        sys.exit()
    elif A + 1 == B and S[B] == '.':
        print('Yes')
        sys.exit()
    print('No')
    sys.exit()

print('Yes')

Measured memory_bytes: 4728
#include <stdio.h>

int main(void){
    int N, A, B,min;

    scanf("%d%d%d",&N,&A,&B);
    if(1<=N && N <=20 && 1 <= A && A<=50 && 1<=B && B <=50){
        if(N*A > B){
            min = B;
            printf("%d", min);
        }else{
            min = N*A;
            printf("%d", min);
        }
    }else{
        return 0;
    }
   
}

Measured memory_bytes: 128
#include <stdio.h>

static void disp_hit(char *s, char *t);

int main(void){
  char a[4];
  char b[4];
  scanf("%s", a);
  scanf("%s", b);
  disp_hit(a, b);

  return 0;
}

static void disp_hit(char *s, char *t){
  int i =0;
  int result = 0;
  for (i =0;s[i]!='\0';i++){
    if(s[i] == t[i]){
      result++;
    }
  }
  printf("%d", result);

}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

#define REP(i, n) for(int i = 0; i < int(n); ++i)
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define IN(a, x, b) (a <= x && x < b)

constexpr int INFINT = 1 << 30;

int dy4[] = { -1,0,1,0 };
int dx4[] = { 0,1,0,-1 };

signed main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (h == 0 && w == 0) break;

		vector<vector<int>> a(h - 1, vector<int>(w)), b(h, vector<int>(w - 1));
		{
			int p = 0, q = 0;
			bool isP = true;
			while (p < h || q < h - 1) {
				if (isP) {
					REP(j, w - 1) cin >> b[p][j];
					++p;
				}
				else {
					REP(j, w) cin >> a[q][j];
					++q;
				}
				isP = !isP;
			}
		}

		vector<vector<int>> dist(h, vector<int>(w, INFINT));
		dist[0][0] = 1;

		using P = pair<int, int>;
		queue<P> que({P(0, 0)});
		while (!que.empty()) {
			P now = que.front(); que.pop();
			REP(d, 4) {
				int dy = now.first + dy4[d];
				int dx = now.second + dx4[d];
				if (!IN(0, dy, h) || !IN(0, dx, w)) continue;

				if (dy4[d] == 0) {
					int mi = min(now.second, dx);
					if (b[dy][mi]) continue;
				}
				else {
					int mi = min(now.first, dy);
					if (a[mi][dx]) continue;
				}

				if (dist[dy][dx] > dist[now.first][now.second] + 1) {
					dist[dy][dx] = dist[now.first][now.second] + 1;
					que.push(P(dy, dx));
				}
			}
		}

		int ans = 0;
		if (dist[h - 1][w - 1] != INFINT) ans = dist[h - 1][w - 1];
		cout << ans << endl;
	}
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCorder
{
    public static class Program
    {
        static public void Main(string[] args)
        {
            int output = 1;
            int input1 = int.Parse(Console.ReadLine());
            int[] input2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int mini = input2[0];

            for (int i = 1; i <= (input1 - 1); i++)
            {
                if (mini > input2[i])
                {
                    output = output+1;
                    mini = input2[i];
                }

            }
            Console.WriteLine(output.ToString());
        }
    }
}




Measured memory_bytes: 35676
#include<stdio.h>
#include<string.h>
#define LEN 100005

/* 代表任务的结构体 */
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; } /* 返回最小值 */

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    /* 按顺序将所有任务添加至队列 */
    for ( i = 1; i <= n; i++ ) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    /* 模拟 */
    while ( head != tail ) {
        u = dequeue();
        c = min(q, u.t);  /* 执行时间片p或所需时间u.t的处理 */
        u.t -= c;  /* 计算剩余的所需时间 */
        elaps += c;  /* 累计已经经过的时间 */
        if ( u.t > 0 ) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    
    return 0;
}


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

int main() {
    int firstNum, secondNum;
    cin >> firstNum >> secondNum;
    int multiplyTotal = firstNum * secondNum;

    if ((multiplyTotal % 2) == 0){
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}

Measured memory_bytes: 3624
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 998244353
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,K=LI()
FACT=FLIST(N+M+1)
FINV=[]
for i in FACT: FINV.append(INV(i))
if N == 1:
    print(M)
    exit()
if M == 1:
    if N - 1 == K: print(M)
    else: print(0)
    exit()

res = 0
def ncr(n, r):
    res = 1
    res *= FACT[n]
    res *= FINV[n-r]
    res %= DVSR
    res *= FINV[r]
    res %= DVSR
    return res

for k in range(K+1):
    v = ncr(N-1, k)*M
    v %= DVSR
    v *= POW(M-1, N-1-k)
    v %= DVSR
    res += v

print(res%DVSR)


Measured memory_bytes: 103148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //   freopen("output.txt", "w", stdout);
    //     //  freopen("error.txt", "w", stderr);
    // #endif
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3648
// D - Friend Suggestions
// UnionFinde version
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

class UnionFind{
	vector<int> parent_or_size;// <0: root&-(size), >=0: parent number
	public:
	UnionFind(int n): parent_or_size(n,-1) {}
	int root(int v){
		if(parent_or_size[v] < 0) return v;//root
		return parent_or_size[v] = root(parent_or_size[v]);//path compression
	}
	bool unite(int v, int u){
		int large_root = root(v), small_root = root(u);
		if(large_root == small_root) return false;// same root: no execute
		if(size(large_root) < size(small_root)) swap(large_root, small_root);
		parent_or_size[large_root] += parent_or_size[small_root];// large_root <- small_root unite
		parent_or_size[small_root] = large_root;
		return true;// executed
	}
	bool same(int v, int u){return root(v)==root(u);}//v & u the same set
	int size(int v){return -parent_or_size[root(v)];}// -(-size)
};

int main(){
	int N,M,K; cin>>N>>M>>K;
	UnionFind uf(N);
	vi C(N+1);//count: friend, block
	int s,t;
	rp(i,0,M){
		cin>>s>>t; s--; t--;
		uf.unite(s,t);
		C[s]++; C[t]++;
	}
	rp(i,0,K){
		cin>>s>>t; s--; t--;
		if(uf.same(s,t)) C[s]++, C[t]++;
	}
	rp(i,0,N) cout<< uf.size(i)-C[i]-1 <<" ";
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include <ext/rope>

#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)    __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)       __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)       __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define PI   M_PI
#define endl "\n"
#define sc   scanf
#define pf   printf

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep1(i,n)       for(int i = 0; i < n; i++)
#define rep2(a,b)       for(int i = a; i <= b; i++)
#define rep3(a,b,c)     for(int i = a; i <= b; i+=c)
#define irep(a,b,c)     for(int i = b; i >=a; i-=c)
#define repit(it,type)  for(it = type.begin(); it != type.end(); it++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_cxx;

int main()
{
     IOS
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int cnt=0;
    int i;
    string s1,s2;

    cin>>s1>>s2;

    for(i = 0; i < s1.size(); i++)
    {
         if(s1[i]!=s2[i])
          cnt++;
    }
    cout<<cnt;

     return 0;
}



Measured memory_bytes: 3784
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
if n == 3 or n == 5 or n == 7:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()
#define MOD 998244353

int main(){
	int N;
	cin >> N;
	vector<pair<int, int>> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i].second;
	}
	for (int i = 0;i < N;i++) {
		cin >> A[i].first;
	}
	sort(all(A));

	vector<int> B(N), C(N);
	for (int i = 0;i < N;i++) {
		B[i] = A[i].first;
		C[i] = A[i].second;
	}

	for (int i = 0;i < N;i++) {
		auto it = lower_bound(all(B), C[i]);
		if (it == B.end()) {
			cout << "No" << endl;
			return 0;
		}
		C[i] = *it;
	}

	vector<int> D = C;
	sort(all(D));
	bool db = 0;
	for (int i = 0;i < N;i++) {
		if (D[i] > B[i]) {
			cout << "No" << endl;
			return 0;
		}
		if (i != 0 && D[i] == D[i - 1])db = 1;
	}
	if (db) {
		cout << "Yes" << endl;
		return 0;
	}
	vector<int> E(N);
	for (int i = 0;i < N;i++) {
		auto it = lower_bound(all(D), C[i]);
		E[i] = it - D.begin();
	}

	int n = 0, next, cnt = 0;
	while (E[n] >= 0) {
		cnt++;
		next = E[n];
		E[n] = -1;
		n = next;
	}
	if (cnt == N)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read() {
	ll x=0; char ch;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x;
}
ll gcd(ll a, ll b) {
	return b==0?a:gcd(b,a%b);
}
ll n, m, x, ok=1, a[100005], s=-1;
ll l=1;
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
		x=read();
		x/=2;
		ll t=x, s1=0;
		while(t%2==0) t/=2, s1++;
		if(s==-1) s=s1;
		l=l/gcd(l,x)*x;
		if(s!=s1||l>m) {
			ok=0;
			break;
		}
	}
	if(!ok) {
		cout<<0;
		return 0;
	}
	cout<<(m-l)/(l*2)+1;
}


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

#define MN 300005
int a[MN], tmp[MN], num[MN];
#define NNN 1001
map<int, int> vis;

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", a + i);
        if (!vis[a[i]]) x = vis[a[i]] = ++cnt;
        else x = vis[a[i]];
        num[x]++;
        tmp[x] = a[i];
    }
    bool ok = true;
    if (n % 3) {
        if (cnt == 1 && tmp[1] == 0) {
            puts("Yes");
        }
        else puts("No");
        return 0;
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i < n / 3; ++i)
        if (a[i] != a[i + 1]) ok = false;
    for (int i = n / 3 + 1; i < n / 3 * 2; ++i)
        if (a[i] != a[i + 1]) ok = false;
    for (int i = n / 3 * 2 + 1; i < n; ++i)
        if (a[i] != a[i + 1]) ok = false;
    int x = a[n / 3], y = a[n / 3 + 1], z = a[n / 3 * 2 + 1];
    if (((x ^ y) ^ z) != 0) ok = false;
    else ok = true;
    puts(ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007LL;

int N;
ll dp[110][4][4][4];

int main ()
{
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                if (i == 0 && j == 2 && k == 1) continue;
                if (i == 0 && j == 1 && k == 2) continue;
                if (i == 2 && j == 0 && k == 1) continue;
                dp[3][i][j][k] = 1LL;
            }
        }
    }

    cin >> N;
    for (int i = 4; i <= N; i++) {
        for (int a = 0; a < 4; a++) {
            for (int b = 0; b < 4; b++) {
                for (int c = 0; c < 4; c++) {
                    for (int d = 0; d < 4; d++) {
                        if (b == 2 && c == 0 && d == 1) continue;
                        if (b == 0 && c == 1 && d == 2) continue;
                        if (b == 0 && c == 2 && d == 1) continue;
                        if (a == 0 && c == 2 && d == 1) continue;
                        if (a == 0 && b == 2 && d == 1) continue;
                        dp[i][b][c][d] += dp[i - 1][a][b][c];
                        dp[i][b][c][d] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                ans += dp[N][i][j][k];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

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

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	int g = a[0];
	for(int i = 1; i < n; ++i) {
		g = gcd(g, a[i]);
	}
	
	if( g > 1 ) {
		cout << "not coprime" << endl;
		return 0;
	}
	
	int maxa = *max_element(a.begin(), a.end());
	vector<int> sieve(maxa + 1);
	
	iota(sieve.begin(), sieve.end(), 0);
	
	for(int i = 2; i * i <= maxa; ++i) {
		if( sieve[i] == i ) {
			for(int j = i * i; j <= maxa; j += i) {
				if( sieve[j] == j ) {
					sieve[j] = i;
				}
			}
		}
	}
	
	vector<int> cnt(maxa + 1, 0);
	for(int i = 0; i < n; ++i) {
		map<int, int> mp;
		int t = a[i];
		
		while( t > 1 ) {
			mp[sieve[t]]++;
			t /= sieve[t];
		}
		
		mp[t]++;
		
		for(auto& v : mp) {
			cnt[v.first]++;
		}
	}
	
	for(int i = 2; i <= maxa; ++i) {
		if( cnt[i] > 1 ) {
			cout << "setwise coprime" << endl;
			return 0;
		}
	}
	
	cout << "pairwise coprime" << endl;
	
	return 0;
}


Measured memory_bytes: 14720
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define INF 1e9
typedef pair<int, int> pi;
int graph[200][200];
int used[200];
int dist[200];
// first:weight, second:key
priority_queue<pi, vector<pi>, greater<pi>> pqueue;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    dist[i] = INF;
    for (int j = 0; j < n; j++) {
      graph[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    int v, c;
    for (int j = 0; j < k; j++) {
      cin >> v;
      cin >> graph[u][v]; 
    }
  }
  
  pqueue.push(make_pair(0,0));
  dist[0] = 0;
  for (int i = 0; i < n; i++) {
    pi p = pqueue.top();
    pqueue.pop();
    int key = p.second;
    if (used[key] == 1) {
      i--;
      continue;
    }
    dist[key] = min(p.first, dist[key]);
    used[key] = 1;
    for (int j = 0; j < n; j++) {
      if (graph[key][j] != -1 && used[j] != 1) {
        int d = graph[key][j] + dist[key];
        pqueue.push(make_pair(d, j));
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << dist[i] << endl;
  }
}




Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M; //M = f(N)
  cin >> N;
  M = 0;
  //v value M
  if (N == 1) {
    cout << "Yes" <<endl;
  }
  else{
  for( int i = 1; i < N; i *=10){
    int m, k; //m:Nの第iの位の数
    k = N / (i * 10);
    m = ((N - k*i*10) / i ) % 10;
    M += m;
    
    //cout << i << ":" << m << endl;
    
  }
  //^ fin value M v check mod
  
    //cout << M << endl;
    
    if ( N % M == 0 ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No"<< endl;
  }
  }
  
}

Measured memory_bytes: 256