akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc084/tasks/abc084_d

Nmax = 10**5 + 1

def prime_test(n):
    if n == 1:
        return False
    i = 2
    while i*i<=n:
        if n%i:
            i += 1
        else:
            return False
    return True

cum = [0]*Nmax

for n in range(1,Nmax,2):
    cum[n] = cum[n-2] + (prime_test(n) and prime_test((n + 1)/2))

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(cum[r] - cum[l-2])


Measured memory_bytes: 53604
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    cin >> n;
    int cnt = 0;
    bool flag = false;
    REP(i, n) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) {
            cnt++;
            if (cnt >= 3) {
                flag = true;
            }
        } else {
            cnt = 0;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 3640
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, m] <- getIntList
  as <- VB.replicateM n BS.getLine
  bs <- VB.replicateM m BS.getLine

  let check y x = check' y x
        where check' i j
                | i == y + m  = True
                | otherwise =
                  let a = as VB.! i
                      ss = BS.take m $ BS.drop j a
                      b = bs VB.! (i - y)
                  in ss == b && check' (i+1) j

      solve y x | y > n - m = False
                | x > n - m = solve (y+1) 0
                | otherwise = check y x || solve y (x+1)

      ans = if solve 0 0 then "Yes" else "No"

  putStrLn ans

Measured memory_bytes: 508
local mod = 1000000007
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local sum = 0
local fact1 = bmul(500000004, bmul(k, k - 1))
local fact2 = bmul(500000004, bmul(k, k + 1))
for i = 1, n - 1 do
  for j = i + 1, n do
    if a[i] < a[j] then
      sum = (sum + fact1) % mod
    elseif a[j] < a[i] then
      sum = (sum + fact2) % mod
    end
  end
end
print(sum)


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		List<String> abc = new ArrayList<String>();
 		int x = 0;
 		int N = scanner.nextInt();
 		String S = scanner.next();
 		String[] splitArray = S.split("");
 		String str[] = new String[splitArray.length];
 		
 		abc.add("A");
 		abc.add("B");
 		abc.add("C");
 		abc.add("D");
 		abc.add("E");
 		abc.add("F");
 		abc.add("G");
 		abc.add("H");
 		abc.add("I");
 		abc.add("J");
 		abc.add("K");
 		abc.add("L");
 		abc.add("M");
 		abc.add("N");
 		abc.add("O");
 		abc.add("P");
 		abc.add("Q");
 		abc.add("R");
 		abc.add("S");
 		abc.add("T");
 		abc.add("U");
 		abc.add("V");
 		abc.add("W");
 		abc.add("X");
 		abc.add("Y");
 		abc.add("Z");
		 
		for (int i = 0; i < splitArray.length; i++) {
			//System.out.println(splitArray[i]);
		}
		
		for (int i = 0; i < splitArray.length; i++) {
			x = abc.indexOf(splitArray[i]) + N;
			if (x >= 26) {
				x -= 26;
			}
			//System.out.println(x);
			System.out.print(abc.get(x));
		}
	}
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    cout << (N-2)*180 << endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N=1e9+7;
int prime[1000001]={0};
const int m=1000000;
void seive()
{
    prime[1]=1;
    prime[2]=1;
    for(int i=3;i<=m;i+=2)
        prime[i]=1;
    for(int i=2;i*i<=m;i++)
    {
       if(prime[i]==1)
       {
           for(int j=2*i;j<=m;j+=i)
           {
               if(prime[j]==0 || prime[j]==1)
                 prime[j]=i;
           }
       }
    }
    for(int i=2;i<=m;i++)
    {
          if(prime[i]==1)
            prime[i]=i;
    }
}

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    map<int,int>mp;
    seive();
    int flag=0;
    int pf=0;
    int gcd=0;
    for(int i=0;i<n;i++)
    {
        int temp=arr[i];
        gcd=__gcd(gcd,arr[i]);
        while(temp!=1)
        {
            int x = prime[temp];
            mp[x]++;
            if(mp[x]>=2)
            flag=1;

            while(temp%x==0)
            {
               temp=temp/x;
            }
        }
    }
    if(flag==0)
        cout<<"pairwise coprime";
    else if(gcd==1)
        cout<<"setwise coprime";
    else
        cout<<"not coprime";

}


















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

from collections import deque

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    # Get minimum path length with Dijkstra-BFS
    q = deque()
    q.append((0, 0, 1))
    queued = [[False] * w for i in range(h)]
    queued[0][0] = True
    while q:
        i, j, l = q.popleft()
        if (i, j) == (h - 1, w - 1):
            break
        for di, dj in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            i2 = i + di
            j2 = j + dj
            if i2 < 0 or i2 >= h:
                continue
            if j2 < 0 or j2 >= w:
                continue
            if queued[i2][j2]:
                continue
            if s[i2][j2] == "#":
                continue
            q.append((i2, j2, l + 1))
            queued[i2][j2] = True
    else:
        print(-1)
        return

    # (number of white) - (minimum path length)
    num_white = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                num_white += 1
    print(num_white - l)

if __name__ == "__main__":
    main()


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

int main()
{
	int N;
	scanf("%d", &N);
	long double ans{};
	for (int i{}; i < N; i++)
	{
		long double A;
		scanf("%Lf", &A);
		ans += 1 / A;
	}
	printf("%.10Lf\n", 1 / ans);

	return 0;
}

Measured memory_bytes: 256
s = input()
ok = True
ss = ''
# print(s[2:-1])
if s[0] == 'A': 
    if 'C' in s[2:-1]:
        for i in range(len(s)):
            if s[i].isupper():
                ss += s[i]
        if ss == 'AC':
            pass
        else:
            ok = False
    else:
        ok = False
else:
    ok = False

if ok:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 8876
#include<stdio.h>
main(){
  int s=0;
  int H=0;
  int M=0;
  scanf("%d",&s);
  while(s>3599){
    s=s-3600;
    H++;
  }
  while(s>59){
    s=s-60;
    M++;
  }
  printf("%d:%d:%d\n",H,M,s);
  return 0;
}

Measured memory_bytes: 2712
N, M = map(int, input().split())
a = [0 for i in range(M)]
sosu = 10 ** 9 + 7
for i in range(M):
    a[i] = int(input())
seta = list(set(a))
seta.sort()
dp = [0 for i in range(N+1)]
dp[0] = 1
now = 0
for i in range(1, N+1):
    if now <= M-1 and i == seta[now]:
        now += 1
    elif i >= 2:
        dp[i] = (dp[i-2] + dp[i-1]) % sosu
    elif i == 1:
        dp[i] = dp[i-1]
#print(seta)
print(dp[N])

Measured memory_bytes: 13216
#include<bits/stdc++.h>
using namespace std;
void lcs(string s,string r)
{
	int n,m;
	n=s.length();
	m=r.length();
	//cout<<"s="<<s<<" r="<<r<<endl;
	  int a[n+1][m+1];
	for(int i=0;i<=n;i++)
	   a[i][0]=0;
	   for(int i=0;i<=m;i++)
	   a[0][i]=0;
	   for(int i=1;i<=n;i++)
	   {
	   	for(int j=1;j<=m;j++)
	   	{
	   		if(s[i-1]==r[j-1])
	   		{a[i][j]=a[i-1][j-1]+1;//cout<<s<<" "<<r<<endl;cout<<"s[i]="<<s[i-1]<<" r[j]="<<r[j-1]<<endl;
	   		}
	   		else
	   		a[i][j]=max(a[i-1][j],a[i][j-1]);
	   	}
	   }
       int g=n,h=m;
       string dd="";
	   while(g!=0 && h!=0)
       {
           if(s[g-1]==r[h-1])
           {


               dd=s[g-1]+dd;
               g--;h--;
           }
           else if(a[g-1][h] > a[g][h-1])
           {

               g--;
           }
           else
            h--;

       }
       cout<<dd;
}
int main()
{

		string s;
		cin>>s;
		string r;
		cin>>r;
		lcs(s,r);

}


Measured memory_bytes: 35456
s = input()
ans = 0
for i in range(1,len(s)+1): #i文字の文字列について調べる
    for j in range(len(s)-i+1): #j文字目でスタートしたとして
        if all(s[k]=='A' or s[k]=='G' or s[k]=='C' or s[k]=='T' for k in range(j,j+i)):
            ans = i
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//----------------------//

int main() {
	ll q, h, s, d;
	ll n;
	cin >> q >> h >> s >> d;
	cin >> n;
	
	chmin(h, q * 2);
	chmin(s, h * 2);
	chmin(d, 2 * s);
	
	ll cnt = n / 2;
	n -= cnt * 2;
	
	ll ans = cnt * d;
	
	ans += s * n;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
S = input()

T = []

x_list = []

temp = 0
for i in range(len(S)):
    if S[i]!="x":
        T.append(S[i])
        x_list.append(temp)
        temp=0
    else:
        temp+=1
x_list.append(temp)

U = T[::-1]
flag=False
for i in range(len(T)):
    if T[i]!=U[i]:
        flag=True
        break

if flag:
    print(-1)
else:
    count=0
    for i in range(len(x_list)//2):
        count+=abs(x_list[i]-x_list[len(x_list)-1-i])

    print(count)

Measured memory_bytes: 5588
def resolve():
    A, B, C = map(int, input().split())
    K = int(input())
    count = 0
    while A >= B:
        B = B * 2
        count += 1
    while B >= C:
        C = C * 2
        count += 1
    print("Yes" if count <= K else "No")
resolve()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		String t="";
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='1')t+='9';
			else t+="1";
		}
		System.out.println(t);
	}

}


Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n, m; cin >> n >> m;
	VI a(n); REP(i,n) cin >> a[i];
	ll sum=0;
	REP(i,n)sum+=a[i];
	int c=0;
	REP(i,n){
		if(sum<=a[i]*4*m)
			c++;
	}
	if(c>=m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <stack>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100005
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
//template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a, int b, int c){
    int ans = 1;
    while(b){
        if(b&1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

int get(char c){
    if(c == 'R')return 0;
    else if(c == 'G')return 1;
    return 2;
}
char s[3 * N];
int main(){
    int T, m, i, j, k, n, K;
    scanf("%d%s", &n, s);
    m = strlen(s);
    int a[4] = {0}, b[4] = {0};
    a[0] = n;
    ll ans = 1;
    rep(i, 0, m){
        k = get(s[i]);
        b[k]++;
        K = 0;
        rep(j, 0, 3)if(b[j] > b[k])K++;
        b[k]++;
        ans = ans * a[K] % mod;
        a[K]--;
        a[K+1]++;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdlib> 
#include<cstring>
#define rep(i,j,k) for(register int i = j; i <= k; ++i)
#define dow(i,j,k) for(register int i = j; i >= k; --i)
#define ll long long
#define mp make_pair
#define fi first
#define se second 
#define all(x) x.begin(),x.end()
using namespace std;

inline int read() { 
    int s = 0, t = 1; char c = getchar();
    while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
    while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
    return s * t;
}

const int N = 1e5+5;
struct edge{ int to, nxt; } e[N<<1];
int head[N], cnt = 0;
inline void add(int x,int y) { 
	e[++cnt].to = y, e[cnt].nxt = head[x], head[x] = cnt;
	e[++cnt].to = x, e[cnt].nxt = head[y], head[y] = cnt;
} 

ll ans = 0; int u, v, f[N], g[N], A[N], tot = 0, col[N]; bool flag;
#define ez(i,j) for(register int i = head[j]; i; i=e[i].nxt)
#define to e[i].to
inline void dfs(int x,int fa=0) { 
	f[x] = -f[fa];
	ez(i,x) if( to != fa ) { 
		if( col[to] ) {
			u = x, v = to; 
			if( col[to] == col[x] ) flag = 0;
			else flag = 1; 
		} else { 
			col[to] = -col[x];
			dfs(to,x);
		}
	}
} 
inline void dp(int x,int fa=0) { 
	ez(i,x) if( to != fa ) {
		if( x == u && v == to ) continue;
		if( x == v && u == to ) continue; 
		dp(to,x), f[x] += f[to], g[x] += g[to];
	}
}

inline void out() { puts("-1"), exit(0); }

int main() {
	int n = read(), m = read(), fg;
	rep(i,1,m) add(read(),read());
	f[0] = 1, col[1] = 1, dfs(1);
	if( m == n - 1 ) { 
		dp(1);
		if( f[1] ) out();
		rep(i,1,n) ans += abs(f[i]);
	} else if( !flag ) { 
		dp(1);
		if( f[1] % 2 ) out();
		fg = f[1], memset(col,0,sizeof(col)), f[0] = 1, col[1] = 1, dfs(1);
		f[u] -= (fg >> 1), f[v] -= (fg >> 1), ans = abs(fg) >> 1; 
		dp(1);
		rep(i,1,n) ans += abs(f[i]);
	} else { 
		g[u]--, g[v]++;
		dp(1);
		if( f[1] ) out();
		rep(i,1,n) if( !g[i] ) ans += abs(f[i]); else if( g[i] == 1 ) A[++tot] = -f[i]; else A[++tot] = f[i];
		A[++tot] = 0;
		sort(A+1,A+tot+1);
		rep(i,1,tot) ans += abs(A[i]-A[(tot+1)>>1]); 
	} cout<<ans<<endl;
    return 0;
}

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

int main() {
 int N,K,i;
 K = 0 ;
 cin >> N ;
 vector <int> vec(N) ;
  for (int i=0;i<N;i++){
    cin >> vec.at(i);
  //  cout << vec.at(i);
  }

 for (int i=0; i<N ; i++){
    K = vec.at(K);
   // cout << K ;
    if(K == 2){
      cout <<i+1 <<endl;
      break ;
    }
    if (i == N-1)
      cout << -1 << endl;
   K-=1 ;
 }

}
  
      
  
  
 

Measured memory_bytes: 768
def calc(stack, s):
	a = stack.pop()
	b = stack.pop()
	if s=='+':
		stack.append(b+a)
	elif s=='-':
		stack.append(b-a)
	elif s=='*':
		stack.append(b*a)

		

S = list(input().split())

stack = []
for s in S:
	if s in ['+', '-', '*']:
		calc(stack, s)
	else:
		stack.append(int(s))

print(stack[0])


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

namespace ConsoleApp8
{
	class Program
	{
		static void Main(string[] args)
		{
			var count = int.Parse(Console.ReadLine());
			var set = new HashSet<int>();
			for (int i = 0; i < count; i++)
				set.Add(int.Parse(Console.ReadLine()));
			
			Console.WriteLine(set.Count);
		}
	}
}


Measured memory_bytes: 13396
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int w, h, n; scanf("%d %d %d", &w, &h, &n);
	int l = 0, r = w, u = 0, d = h;
	for(int i = 0; i < n; i++){
		int x, y, a; scanf("%d %d %d", &x, &y, &a);
		if(a == 1) l = max(l, x);
		if(a == 2) r = min(r, x);
		if(a == 3) u = max(u, y);
		if(a == 4) d = min(d, y);
	}
	printf("%d\n", max(0, r - l) * max(0, d - u));
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            var s = new int[n];

            for(int i = 0; i< n; i++) {
                s[i] = int.Parse(Console.ReadLine());
            }

            var sum = s.Sum();

            var result = 0L;

            if (sum % 10 != 0) {
                result = sum;
            } else {
                var mins = s.Where(x => x % 10 != 0);

                if (mins.Any()) {
                    result = sum - mins.Min();
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28252
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main() {
	string  s;
	cin >> s;
	rep(i, s.size())
	{
		if (i % 2 == 0)
		{
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 200005;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int X = 11000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    for (int zz = 0; zz < t; zz++)
    {
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt;
    return;
}



Measured memory_bytes: 3888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map> 
#include<algorithm>
#define maxn 200020
#define ll long long
using namespace std;
int n,a[maxn];
map<int,int>mp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),++mp[a[i]];
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=n;i;--i)
	if(mp[a[i]]>0){
		int x=1;
		while(x<=a[i])x<<=1;
		int bi=x-a[i];
		if(mp.count(bi)&&(mp[bi]>(a[i]==bi)))--mp[bi],--mp[a[i]],++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10368
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string MOJI = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var N = int.Parse(Console.ReadLine());
            var inputString = Console.ReadLine().ToArray(); ;
            for(int i = 0; i < inputString.Length; i++)
            {
                var num = MOJI.IndexOf(inputString[i]);
                Console.Write(MOJI[num + N < 26 ? num + N : num + N - 26]);
            }
        }
    }
}

Measured memory_bytes: 13268
a=int(input())
l=[i for i in range(a+1)]
i=1
while 6**i<=a:
    q=6**i
    for x in range(q,a+1):
        l[x]=min(l[x-q]+1,l[x])
    i+=1
i=1
while 9**i<=a:
    q=9**i
    for x in range(q,a+1):
        l[x]=min(l[x-q]+1,l[x])
    i+=1
print(l[a])

Measured memory_bytes: 7064
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define incm(x,y) {x=((x)+(y))%mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j,a[200005],vis[200005],icr[200005],val[200005],vv[200005];
vector<int> bi[200005];
void dfs(int x)
{
	ff(bi[x],it){
		if(!icr[*it])dfs(*it);
	}
	ff(bi[x],it){
		if(!icr[*it])vv[val[*it]]=1;
	}
	for(val[x]=0;vv[val[x]];val[x]++);
	ff(bi[x],it){
		if(!icr[*it])vv[val[*it]]=0;
	}
}
int main()
{
	read(n);
	fz1(i,n){
		read(a[i]);
		bi[a[i]].push_back(i);
	}
	int x=1;
	while(!vis[x]){
		vis[x]=1;x=a[x];
	}
	while(!icr[x]){
		icr[x]=1;x=a[x];
	}
	int mx=-1,mi=0x3f3f3f3f,cnt=0;
	fz1(i,n)if(icr[i]){
		cnt++;
		dfs(i);
		mx=max(mx,val[i]);
		mi=min(mi,val[i]);
	}
	if((cnt&1)&&mi==mx){
		puts("IMPOSSIBLE");
	}
	else{
		puts("POSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 16644
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        int a, b, t;
        cin >> a >> b >> t;
        cout << t / a * b << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];


bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ll t;
    // cin >> t;
    // while(t--)
    // {
    ll n;
    cin >> n;
    ll a[n+5];
    ll arr[n+5] = {0};
    ll x;
    for(ll i = 1; i<=n; i++)
    {
        cin >> x;
        a[i] = x;
        arr[x]++;
    }
    ll sum = 0;
    for(ll i = 1; i<=n; i++)
    {
        sum += (arr[i] * (arr[i] - 1)) / 2;
    }
    // cout << "sum is " << sum << endl;
    for(ll i = 1; i<=n; i++)
    {
        // cout << "a[i] is "<< a[i] << endl;
        // cout <<  "arr[a[i]] is "<< arr[a[i]] << endl;
        // cout <<  "arr[a[i]] - 1 is "<< arr[a[i]] - 1<< endl;
        // cout <<  "arr[a[i]] - 2 is "<< arr[a[i]] - 2<< endl;
        cout << (sum) - ( ( (arr[a[i]] ) * (arr[a[i]] - 1))/2 - ( (arr[a[i]]-1 ) * (arr[a[i]] - 2))/2) << endl;
    }
    return 0;
}   

Measured memory_bytes: 5760
N = int(input())
mod = 5


def prime_sieve_mod(n):
    _sieve = list(range(2, n + 1))
    _sieve.reverse()
    _prime = []
    while _sieve and len(_prime) < N:
        _num = _sieve.pop()
        if _num % mod == 1:
            _prime.append(_num)
        _del = []
        for _i, _v in enumerate(_sieve):
            if _v % _num == 0:
                _del.append(_i)
        _del.reverse()
        for _i in _del:
            del _sieve[_i]
    return _prime


prime_list = prime_sieve_mod(1381)

print(*prime_list)

Measured memory_bytes: 3064
H = int(input())

last_index = H + 1

keys = [None] + list(map(int, input().split()))

for i in range(1, last_index):
    print('node {0}: '.format(i), end = '')
    print('key = {0}, '.format(keys[i]), end = '')
    if i != 1:
        print('parent key = {0}, '.format(keys[i // 2]), end = '')
    left_index = i * 2
    if left_index < last_index:
        print('left key = {0}, '.format(keys[left_index]), end = '')
    right_index = left_index + 1
    if right_index < last_index:
        print('right key = {0}, '.format(keys[right_index]), end = '')
    print('')

Measured memory_bytes: 7804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

double cross(Point a, Point b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

char c;
double x[4], y[4];
Point p[4];

int main(){
	while (cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c >>
		x[2] >> c >> y[2] >> c >> x[3] >> c >> y[3]){
		REP(i, 4)p[i] = { x[i], y[i] };
		if (cross(p[0] - p[2], p[0] - p[1])*cross(p[0] - p[2], p[0] - p[3]) > 0){
			cout << "NO" << endl;
			continue;
		}
		if (cross(p[1] - p[3], p[1] - p[0])*cross(p[1] - p[3], p[1] - p[2]) > 0){
			cout << "NO" << endl;
			continue;
		}
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 3176
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list=new ArrayList<String>();
		//int[] array = new int[1000000000*2];
		int a = sc.nextInt();
		int b = sc.nextInt();
		String a_s = String.valueOf(a);
		String b_s = String.valueOf(b);
		for(int i=0;b-1>i;i++) {
			a_s=a_s+String.valueOf(a);
		}
		for(int i=0;a-1>i;i++) {
			b_s = b_s+String.valueOf(b);
		}
		list.add(a_s);
		list.add(b_s);
		Collections.sort(list);
		System.out.println(list.get(0));

	}
}

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

int main() {
    int a1, a2, a3, a4, b1, b2, b3, b4;
    set<int> setA, setB;
    while (cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4) {
        int hit = 0, blow = 0;
        if (a1 == b1) {
            hit++;
        }
        else {
            setA.insert(a1);
            setB.insert(b1);
        }
        if (a2 == b2) {
            hit++;
        }
        else {
            setA.insert(a2);
            setB.insert(b2);
        }
        if (a3 == b3) {
            hit++;
        }
        else {
            setA.insert(a3);
            setB.insert(b3);
        }
        if (a4 == b4) {
            hit++;
        }
        else {
            setA.insert(a4);
            setB.insert(b4);
        }

        for (int i = 1; i <= 9; ++i) {
            if (setA.count(i) && setB.count(i)) {
                ++blow;
            }
        }

        cout << hit << " " << blow << endl;
        setA.clear();
        setB.clear();
    }
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = INF<ll>;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            if(x-2*i*x <= y-2*j*y){
                ans = min(ans, y-2*j*y-x+2*i*x+i+j);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

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

  ll N; cin >> N;
  ll P; cin >> P;
  string S; cin >> S;

  if (P == 2 || P == 5) {
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
      int x = S[N - 1 - i] - '0';
      if (x % P == 0) ans += (N - i);
    }
    cout << ans << '\n';
    return 0;
  }
  
  vector<ll> d(N + 1, 0), r(P, 0);
  r[0] = 1;
  ll ten = 1;
  for (ll i = 0; i < N; i++) {
    ll x = S[N - 1 - i] - '0';
    d[i + 1] = (d[i] + ten * x) % P;
    ten = ten * 10 % P;
    r[d[i + 1]]++;
  }
  ll ans = 0;
  for (ll i = 0; i < P; i++) {
    ll cnt = r[i];
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2196
# ABC099C - Strange Bank
# DP ver.
def main():
    n = int(input())
    dp = [i for i in range(n + 1)]  # initialize with using only ¥1
    cand = [6 ** i for i in range(1, 7) if 6 ** i <= n]
    cand += [9 ** i for i in range(1, 6) if 9 ** i <= n]
    for i in range(n + 1):
        for j in cand:
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + 1)
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 7064
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int N, M;
  bool x = false;
  cin >> N;
  for( int i = 1; i < 10; i++) {
   M = N % i;
    if(M == 0 && N / i < 10) {
      x = true;
    }
    else {
    }
  }
  if(x) {
      cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
main() {
	int x1 = read(), y1 = read(), x2 = read(), y2 = read();
	int tx = x2, ty = y2;
	tx -= x1, ty -= y1;
	swap(tx, ty); tx = -tx;
	tx += x1; ty += y1;
	int lenx = x2 - x1, leny = y2 - y1;
	printf("%d %d %d %d", tx + lenx, ty + leny, tx, ty);
	return 0;
}
/*
2 2 1
1 1
2 1 1
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define min3(a,b,c) min(min(a,b),c)

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(char *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        int num;
        scanf("%d", &num);
        arr[i] = num;
    }
    return 0;
}

#define NUM_MAX 1400

struct rect {
    int height;
    int pos;
};
static struct rect stack[NUM_MAX+1];
static int idx = 0;

void init_stack(void) { idx=0; }
int is_empty(void) {
    return idx==0;
}

void push(struct rect r) {
    stack[idx++] = r;
}

struct rect pop(void) {
    return stack[--idx];
}

struct rect peek(void) {
    return stack[idx-1];
}

int main(void) {
    int height, width;
    get_int2(&height, &width);
    static char mat[NUM_MAX+1][NUM_MAX+1];
    int i, j;
    for(i = 1; i <= height; i++) {
        fget_array(&mat[i][1], width);
        // 0: dirty, 1: clean(usable)
        for(j = 1; j <= width; j++) mat[i][j] = 1-mat[i][j];
    }

    static int hist[NUM_MAX+2][NUM_MAX+2];
    for(i = 1; i <= height; i++) {
        for(j = 1; j <= width; j++) {
            if(!mat[i][j]) {
                hist[i][j] = 0;
            } else {
                hist[i][j] = hist[i-1][j] + 1;
            }
        }
        hist[i][width+1] = 0;
    }
#ifdef DEBUG
    for(i = 1; i <= height; i++) {
        for(j = 1; j <= width; j++) {
            printf(" %d", hist[i][j]);
        }
        putchar('\n');
    }
#endif

    int ans = 0;
    for(i = 1; i <= height; i++) {
        init_stack();
        for(j = 1; j <= width+1; j++) {
            struct rect cur = {hist[i][j], j};
            while(!is_empty()) {
                struct rect pr = peek();
                if(pr.height < cur.height) break;
#ifdef DEBUG
                printf("(%d, %d) height: %d, width: %d\n", i, j, pr.height, j-pr.pos);
#endif
                ans = max(ans, (j-pr.pos)*pr.height);
                cur.pos = pr.pos; // update smaller
                pop();
            }
            push(cur);
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 11436
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int dp[310][310][610];
int main(){
    int n;
    while(cin>>n,n){
        bool f=true;
        int e[5000]={};
        for(int i=0;i<n;i++){
            ll id,p,q;
            cin>>id>>p>>q;
            e[id]+=p*q;
            if(e[id]>=1000000){
                f=false;
                cout<<id<<endl;
            }
        }
        if(f){
            cout<<"NA"<<endl;
        }
    }
	return 0;
}



Measured memory_bytes: 3088
N,M,K=map(int,input().split())

if K% N==0 or K%M==0:
    print('Yes')
else:
    answers=[]
    for n in range(1,N+1):
        for m in range(1,M+1):
            answer=0
            answer+=n*M+m*N-n*m*2
            answers.append(answer)
    for n in range(1,M+1):
        for m in range(1,N+1):
            answer=0
            answer+=n*N+m*M-n*m*2
            answers.append(answer)
    if K in answers:
        print('Yes')
    else:
        print('No')


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

int main()
{
	int n; cin >> n;
	
	int a;
	int cnt_4 = 0;
	int cnt_2 = 0;
	int cnt_odd = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 4 == 0) cnt_4++;
		else if (a % 2 == 0) cnt_2++;
		else cnt_odd++;
	}

	string ans = "No";

	int tmp = n - (2 * cnt_4 + 1);

	if (n <= 0) {
		ans = "Yes";
	}
	else {

		if (tmp % 2 == 0) {
			if (tmp <= cnt_2) ans = "Yes";
		}
		else {
			if (tmp < cnt_2) ans = "Yes";
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,a,b,c; cin >> n >> a >> b >> c;
    VI l(n); VIin(l);
    int x = 1;
    rep(i,n) x *= 4;
    int ans = INF;
    int y,z;
    int cnt = 0;
    rep(i,x){
        y = i;
        VI lon(3,0);
        rep(j,n){
            z = y % 4;
            if(z > 0) lon[z-1] += l[j] + 10000;
            y /= 4;
        }
        if(lon[0]*lon[1]*lon[2] == 0) continue;
        cnt = ((lon[0] / 10000) + (lon[1] / 10000) + (lon[2] / 10000) - 3) * 10;
        cnt+=abs(lon[0] % 10000 - a) + abs(lon[1] % 10000 - b)+abs(lon[2] % 10000 - c);
        ans = min(ans,cnt);
    }
    ANS;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
ai = [int(i) for i in input().split()]

is_odd = True

if n % 2 == 0:
    is_odd = False

if is_odd == True:
    dp = [[0 for i in range(3)] for j in range(n)]
else:
    dp = [[0 for i in range(2)] for j in range(n)]

if n == 3:
    print(max(ai[0],ai[2],ai[1]))
    exit()
elif n == 2:
    print(max(ai[0],ai[1]))
    exit()
    

if is_odd == True:
    dp[0][0] = ai[0]
    dp[1][1] = ai[1]
    dp[2][0] = ai[0]+ai[2]
    dp[2][2] = ai[2]
    dp[3][1] = max(ai[0]+ai[3],ai[1]+ai[3])    
    for i in range(4,n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
        dp[i][2] = max(dp[i-4][0]+ai[i],dp[i-3][1]+ai[i],dp[i-2][2]+ai[i])
    print(max(dp[n-3][0],dp[n-2][1],dp[n-1][2]))
else:
    dp[0][0] = ai[0]
    dp[1][1] = ai[1]
    dp[2][0] = ai[0]+ai[2]       
    for i in range(n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
    print(max(dp[n-2][0],dp[n-1][1]))



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--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()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
int main() {
    cin>>n;
    int ans = 0;

    FOR(i,1,n+1){
        string tmp;
        tmp = to_string(i);
        if(tmp.size()%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ans := 100
	for a := 1; a < n; a++ {
		v := n - a
		sum := 0
		for v != 0 {
			sum += v % 10
			v /= 10
		}
		v = a
		for v != 0 {
			sum += v % 10
			v /= 10
		}
		if sum < ans {
			ans = sum
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512