akhauriyash/Code-Regression huggingface dataset:
using System;

namespace TravelingSalesman
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstArgLine = Console.ReadLine().Split(' ');
            var k = int.Parse(firstArgLine[0]);
            var n = int.Parse(firstArgLine[1]);

            var secondArgLine = Console.ReadLine().Split(' ');
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(secondArgLine[i]);
            }
            Array.Sort(a);

            var distMax = k - a[n - 1] + a[0];
            for (int i = 0; i < n - 1; i++)
            {
                if (distMax < (a[i + 1] - a[i])) distMax = a[i + 1] - a[i];
            }

            Console.WriteLine($"{k - distMax}");
        }
    }
}


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

int main() {
    string c;
    cin >> c;

    if (c == "a") {
        cout << "vowel";
    }
    else if (c == "i") {
        cout << "vowel";
    } 
    else if (c == "u") {
        cout << "vowel";
    }
    else if (c == "e") {
        cout << "vowel";
    }
    else if (c == "o") {
        cout << "vowel";
    }
    else {
        cout << "consonant";
    }
}

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

int main(){
	int N;
	cin >> N;
	vector<pair<int,int>> A(N);
	rep(i,N){
		A[i].second = i+1;
		cin >> A[i].first;
	}
	sort(A.begin(),A.end());
	rep(i,N){
		cout << A[i].second << ' ';
	}
	cout << endl;
	return 0;
}

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

int main() {

int N, K; cin >> N >> K;
int d; int A;

vector<int> okashi(N+1);
  
  for(int j=0; j<K; j++){
  cin >> d;  
  for(int i=0; i<d; i++){
   cin >> A;
   okashi.at(A) ++; 
  }
  }
  
  int trick = 0;
  for(int k=1; k<=N; k++){
   if (okashi.at(k)==0) trick++;
  }
  
cout << trick << endl;

}


Measured memory_bytes: 3604
#include <stdio.h>

int main (){
	int t;
	scanf("%d", &t);
	getchar();
	char x[100000];
	scanf("%[^\n]", &x);
	for (int i=0; x[i]!='\0'; i++){
		int result = x[i]+t;
		if (result > 'Z'){
			result-=26;
		}
		printf("%c", result);
	}
	return 0;
}


Measured memory_bytes: 1660
using System;

class Program
{
    static void Main(string[] args)
    {
        var g = new[] { '\0', 'a', 'c', 'a', 'b', 'a', 'b', 'a', 'a', 'b', 'a', 'b', 'a' };
        var xy = Console.ReadLine().Split();
        var x = int.Parse(xy[0]);
        var y = int.Parse(xy[1]);
        Console.WriteLine(g[x] == g[y] ? "Yes" : "No");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long n;
    cin >> n;
    long cnt=0, now=0, total = 0, a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
        while ((now ^ a[i]) != now + a[i]) {
            total += cnt;
            now ^= a[i - cnt];
            cnt--;
        }
        now ^= a[i];
        cnt++;
        if (i == n - 1) total += (cnt + 1) * cnt / 2;
    }
    cout << total << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
	cin >> a >> b;
	cout << 6 - a - b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

template <typename T>
T my_pow_with_mod(T x, T a, T mod = 1e9 + 7);
template <typename T>
void prime_factorization(T n);
template <typename T>
T my_gcd(T a, T b);
template <typename T>
T my_lcm(T a, T b);
template <typename T>
T euler_phi_function(T n);

template <typename T>
T my_pow_with_mod(T x, T a, T mod)
{
    ll ans = 1;
    ll b = x;
    while (a)
    {
        if (a & 1)
            ans *= b;
        ans %= mod;
        a = a >> 1;
        b = b * b;
        b %= mod;
    }
    return ans;
}

template <typename T>
void prime_factorization(T n)
{
    vector<pair<T, T>> a;
    T counter, p;
    T m = sqrt(n) + 1;
    p = n;
    for (T i = 2; i <= m; i++)
    {
        counter = 0;
        while (n % i == 0)
        {
            counter++;
            n /= i;
        }
        if (counter)
            a.push_back(make_pair(i, counter));

        if (n == 1)
            break;
    }
    if (n != 1)
        a.push_back(make_pair(n, 1));

    cout << p << ":";
    for (int i = 0; i < a.size(); i++)
    {
        for (int j = 0; j < a[i].second; j++)
        {
            cout << " " << a[i].first;
        }
    }
    cout << endl;
}

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

template <typename T>
T my_lcm(T a, T b)
{
    T c = my_gcd(a, b);
    return a * b / c;
}

template <typename T>
T euler_phi_function(T n){
    vector<pair<T, T>> a;
    T counter, p;
    T m = sqrt(n) + 1;
    p = n;
    for (T i = 2; i <= m; i++)
    {
        counter = 0;
        while (n % i == 0)
        {
            counter++;
            n /= i;
        }
        if (counter)
            a.push_back(make_pair(i, counter));

        if (n == 1)
            break;
    }
    if (n != 1)
        a.push_back(make_pair(n, 1));

    T ans = 1;
    for (int i = 0; i < a.size(); i++)
    {
        ans *= (pow(a[i].first, a[i].second-1) * (a[i].first - 1) );
    }
    return ans;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    int n, x;
    cin >> n;
    cout << euler_phi_function(n) << endl;
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3284
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef struct{
    int attack;int magic;
}spell;


bool cmp(spell a,spell b){
    return (a.attack*1.0/a.magic)>(b.attack*1.0/b.magic);
}
spell S[1002];
int H;
int N;

int main(){
    cin>>H;
    cin>>N;
    int maxA=10000;
    for(int i=0;i<N;i++){
        cin>>S[i].attack>>S[i].magic;
        maxA=max(S[i].attack,maxA);
    }
    //sort(S,S+N,cmp);
    //long long int res=0;
    int H2=H;
    // while(H2>0){
    //     H2-=S[0].attack;
    //     res+=S[0].magic;
    // }
    // if(H2==0||N==1){
    //     cout<<res<<endl;
    //     return 0;
    // }
    // res-=S[0].magic;
    // H2+=S[0].attack;

    int dp[20002];
    for(int i=0;i<20002;i++){
        dp[i]=inf;
    }
    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=S[i].attack;j<=H2+maxA;j++){
            dp[j]=min(dp[j],dp[j-S[i].attack]+S[i].magic);
        }
    }
    int minres2=inf;
    for(int i=H2;i<=H2+maxA;i++){
        minres2=min(minres2,dp[i]);
    }
    cout<<minres2<<endl;
    return 0;

}

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

// debug macros
#define debug_var_elem(v) << #v << "=" << v << " "
#ifdef DEBUG
#define debug_echo(e) cout << "L" << __LINE__ << ": " << e << endl
#define debug_var(...) cout << "L" << __LINE__ << ": " pp_foreach(debug_var_elem, __VA_ARGS__) << endl
#define debug_ary(ary) cout << "L" << __LINE__ << " [ "; for(auto ele : ary) cout << ele << " "; cout << "]" << endl;
#define debug_time(...) {auto start = clock(); __VA_ARGS__ ;auto end = clock();cout << (double)(end - start) << "ms" << endl;} 
#else
#define debug_echo(e)
#define debug_var(...)
#define debug_ary(ary)
#define debug_time(...)
#endif

// short names
typedef long long ll;
#define down_queue(...) priority_queue<__VA_ARGS__>
#define up_queue(...) priority_queue<__VA_ARGS__, vector<__VA_ARGS__>, greater<__VA_ARGS__>>
#define all(x) x.begin(), x.end()
#define rall(x) x.begin(), x.end(), greater<int>()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(...) make_pair(__VA_ARGS__)
#define pb(...) push_back(__VA_ARGS__)
#define pf(...) push_front(__VA_ARGS__)
vector<int> digit_split(int n){vector<int> result(digit(n));for(int i = 0; n; i++){result[i] = n % 10;n /= 10;}return result;}
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof(from))
#define MOD 1000000007 

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

// math
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
bool is_prime(ll n){switch(n){case 0:case 1: return false;case 2: return true;}if(n % 2 == 0) return false;for(ll i=3;i * i <= n; i += 2)if(n%i == 0) return false;return true;}
string to_qn(ll quaternary, ll from){string result = "";if(!from) return "0";else{while(from){result = (char)((from % quaternary) + '0') + result;from /= quaternary;}return result;}}

int main(){
	int n, m;
	cin >> n >> m;
	int cnt = 0;
	cnt += (n - m) * 100;
	cnt += m * 1900;
  rep(i,m) cnt *= 2;
	cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int countA = 0;
		int countB = 0;
		int a = 0;
		while(true){
			a = N.indexOf("BW",a)+1;
			if (a == 0)break;
			countA++;
		}
		while(true){
			a = N.indexOf("WB",a)+1;
			if (a == 0)break;
			countB++;
		}
		System.out.println(countA+countB);
	}
}


Measured memory_bytes: 25428
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
#include <algorithm>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


void dump(vector<int>& v){
	BOOST_FOREACH(int x,v){
		cout << x << endl;
	}
}

bool is_triangle(int a,int b,int c){
	if(c<a+b){
		return true;
	}
	return false;
}

int main(){
	int n;
	cin >> n;
	
	vector<int> rods;
	int tmp,i=0;
	while(cin >> tmp){
		rods.push_back(tmp);
		i++;
		if(i>=n){
			break;
		}
	}
	sort(rods.begin(),rods.end());
	int count = 0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(is_triangle(rods[i],rods[j],rods[k])){
					count++;
				}
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
n, k, q = [int(x) for x in input().split()]
ary = []
for _ in range(q):
    ary.append(int(input()))
winCounts = [0 for _ in range(n)]
for a in ary:
    winCounts[a-1] += 1
for count in winCounts:
    if k - (q-count) > 0:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 8632
import sys
import numpy as np

def read():
    return sys.stdin.readline().rstrip()

def main():
    n = int(read())
    f = np.array([[int(i) for i in read().split()] for _ in range(n)])
    p = [[int(i) for i in read().split()] for _ in range(n)]
    pf = -float("inf")
    for i in range(1, 2**10):
        t = 0
        g = np.array([i >> j & 1 for j in range(10)])
        for j in range(n):
            t += p[j][(f[j] & g).sum()]
        pf = max(t, pf)
    print(pf)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14300
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000

def solve():
  while True:
    R = int(input())
    if not R:
      break
    w1, h1, x1, y1 = map(int, input().split())
    x1 -= 1
    y1 -= 1
    lst1 = [list(map(int, input().split())) for _ in range(h1)]
    used1 = [[False] * w1 for _ in range(h1)]
  
    w2, h2, x2, y2 = map(int, input().split())
    x2 -= 1
    y2 -= 1
    lst2 = [list(map(int, input().split())) for _ in range(h2)]
    used2 = [[False] * w2 for _ in range(h2)]
  
    def bfs(lst, used, que, w, h):
      v, y, x  = pop(que)
      if y > 0 and not used[y - 1][x]:
        push(que, (lst[y - 1][x], y - 1, x))
        used[y - 1][x] = True
      if h > y + 1 and not used[y + 1][x]:
        push(que, (lst[y + 1][x], y + 1, x))
        used[y + 1][x] = True
      if x > 0 and not used[y][x - 1]:
        push(que, (lst[y][x - 1], y, x - 1))
        used[y][x - 1] = True
      if w > x + 1 and not used[y][x + 1]:
        push(que, (lst[y][x + 1], y, x + 1))
        used[y][x + 1] = True
      return v
  
    def make_dic(lst, w, h, x, y):
      que = [(1, y, x)]
      used = [[False] * w for _ in range(h)]
      used[y][x] = True
      dic = [[0, 0]]
      app = dic.append
      Max = 0
      acc = 0
  
      while que:
        v = bfs(lst, used, que, w, h)
        acc += 1
        if v > Max:
          app([v, acc])
          Max = v
        else:
          dic[-1][1] += 1
      return dic
  
    dic1 = make_dic(lst1, w1, h1, x1, y1)
    dic2 = make_dic(lst2, w2, h2, x2, y2)
  
    end1 = len(dic1)
    end2 = len(dic2)
    ind1 = 0
    ind2 = end2 - 1
    ans = INF
  
    while ind1 < end1 and ind2 > 0:
      r1, sum1 = dic1[ind1]
      r2, sum2 = dic2[ind2]
  
      if sum1 + sum2 < R:
        ind1 += 1
        continue
  
      while ind2 > 0 and sum1 + sum2 >= R:
        ind2 -= 1
        r2, sum2 = dic2[ind2]
  
      if ind2 == 0 and sum1 + sum2 >= R:
        rs = r1 + r2
        if rs < ans:
          ans = rs
        break
  
      else:
        if ind2 < end2 - 1:
          ind2 += 1
        r2 = dic2[ind2][0]
        rs = r1 + r2
        if rs < ans:
          ans = rs
  
      ind1 += 1
    print(ans)
 
solve()


Measured memory_bytes: 61844
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;


int main()
{
	string str;
	cin>>str;
	
	reverse(all(str));
	cout<<str<<endl;
	


	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define endl '\n'
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
long long int gcd(long long int x,long long int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
long long exp(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = exp(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int prime(long long x){
if(x==2)return 1;
else{
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)
            return 0;
    }
}
return 1;
}
//main
int main() {
IOS;
string s;
cin>>s;
int n=s.size();
if(s[n-1]=='s'){
    for(int i=0;i<n;i++)cout<<s[i];
    cout<<"es";
}
else{
    for(int i=0;i<n;i++)cout<<s[i];
    cout<<"s";
}
return 0;
}
//jaeger

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll amari = 1e9+7;

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<char> c;
	for(int i = 0; i < n; i++){
		c.push_back(s[i]);
	}
	sort(c.begin(),c.end());
	c.push_back('1');
	ll sum = 1;
	int tdk = 0;
	for(int i = 0; i < n; i++){
		if(c[i] == c[i + 1])tdk++;
		else{
			sum *= (tdk + 2);
			sum %= int(amari);
			tdk = 0; 
		}
	}
	cout << sum - 1 << endl;
	return 0;
}

Measured memory_bytes: 640
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}//send mod-2 for a^-1 if mod is a prime number

ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll subs(ll a,ll b)
{
    return (((a%mod)-(b%mod)+mod)%mod);
}
ll dv(ll a,ll b)
{
    ll inv=binpow(b,mod-2);
    return mul(a,inv);
}

ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[root1]+=dsu_sz[root2];
    }
    else
    {
         dsu_sz[root2]+=dsu_sz[root1];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}
/*
vector<ll>adj[100005];
bool vis[100005];
ll dist[100005];
void bfs(ll c)
{
  vis[c]=true;
  dist[c]=0;
  q.push(c);
while(!q.empty())
{
    ll x=q.front();
    q.pop();
   
    for(ll i=0;i<adj[x].size();i++)
    {
        ll y=adj[x][i];
        if(!vis[y])
        {
            vis[y]=true;
            dist[y]=dist[x]+1;
            
            q.push(y);
        }
    }
 
}
}
*/

int main()
{
    Fast
 ll n;
 cin>>n;
 vector<pair<ll,ll>>sura;
 for(ll i=0;i<n;i++)
 {
     ll u,v;
     cin>>u>>v;
     sura.push_back({u,v});
 }
 for(ll i=0;i<=n-3;i++)
 {
     if(sura[i].first==sura[i].second &&sura[i+1].first==sura[i+1].second && sura[i+2].first==sura[i+2].second )
     {
         cout<<"Yes"<<endl;
         return 0;
     }
 }
 cout<<"No"<<endl;


}



   
      
    
        



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

int main() {
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0) cout << "Even";
	else cout << "Odd";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

偶奇の判定はabが偶数かどうか、つまり2で割った余りが0か1かで判定できる
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll p[n+1],q[n+1];
	vector<ll> vc;
	for(i=1;i<=n;i++){
		vc.ps(i);
		cin>>p[i];
	}
	for(i=1;i<=n;i++){
		cin>>q[i];
	}

	ll c=0,x=0,y=0;
	do{
		c++;
		ll a=0,b=0;
		for(i=0;i<n;i++){
			if(vc[i]==p[i+1]){
				a++;
			}
			else break;
		}
		for(i=0;i<n;i++){
			if(vc[i]==q[i+1]){
				b++;
			}
			else break;
		}
		if(a==n){
			x=c;
		}
		if(b==n){
			y=c;
		}
	}while(next_permutation(all(vc)));

	cout<<abs(x-y);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	if(s<t)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
// #define m ((l + r) >> 1)

using namespace std;

void setIO(string name) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
}

// using namespace __gnu_pbds;
// using mii = gp_hash_table<int, int>;
// typedef tree<pii, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MN = 1 * 1e3 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n);
    for (int &i : a) cin >> i;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 != 0 && a[i] % 5 != 0) {
                cout << "DENIED\n";
                return 0;
            }
        }
    }
    cout << "APPROVED\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = 1200;

char S[MAXN][MAXN];
int n;

bitset<MAXN> good[MAXN][MAXN];

void solve() {
	cin >> n;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			cin >> S[i][j];
			S[i + n][j] = S[i][j];
			S[i][j + n] = S[i][j];
			S[i + n][j + n] = S[i][j];
		}
	}

	for(int d = 0; d < MAXN; ++d) {
		string diagonal;

		for(int i = 0; i < 2 * n; ++i) {
			for(int j = 0; j < 2 * n; ++j) {
				if(i + j == d) {
					diagonal.push_back(S[i][j]);
				}
			}
		}

		if(!diagonal.empty()) {
			DBG(d);

			DBG(diagonal[d]);
			int sz = len(diagonal);

			for(int l = sz - 1; l >= 0; --l) {
				good[d][l][l] = 1;

				if(l + 1 < sz) {
					good[d][l][l + 1] = (diagonal[l] == diagonal[l + 1]);
				}

				for(int r = l + 2; r < sz; ++r) {
					if(diagonal[l] == diagonal[r]) {
						good[d][l][r] = good[d][l + 1][r - 1];
					}
				}
			}
		}
	}

	int answ = 0;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			int ok = 1;

			for(int d = i + j; d <= i + n - 1 + j + n - 1; ++d) {
				int fst = max(0, d - 2 * n + 1);
				int l = max(i, d - j - n + 1) - fst;
				int r = min(i + n - 1, d - j) - fst;
				assert(l <= r);

				if(!good[d][l][r]) {
					DBG(d); DBG(l); DBG(r);
					ok = 0;
					break;
				}
			}

			answ += ok;
		}
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 213376
#include <iostream>

using namespace std;

int n, res;
int a[105][30];
string str;

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

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 26; ++j)
            if (i == 0)
                a[i][j] = 0;
            else
                a[i][j] = a[i - 1][j];
        a[i][str[i] - 'a']++; 
    }

    for (int i = 1; i < n-1; ++i)
    {
        int tmp, tmp1, tmp2;
        tmp1 = tmp2 = -1;
        tmp = 0;

        for (int j = 0; j < 26; ++j)
        {
            tmp1 = a[i-1][j];
            tmp2 = a[n-1][j] - a[i-1][j];
            if (tmp1 && tmp2)
                ++tmp;
        }

        if (tmp > res)
            res = tmp;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int po[100001]={};
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        int kari;
        scanf("%d",&kari);
        if(kari!=0)po[kari-1]++;
        if(kari!=100000)po[kari+1]++;
        po[kari]++;
    }
    int ans=0;
    for(int i=0;i<=100000;i++)if(po[i]>ans)ans=po[i];
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 512
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh, Dw = map(int, input().split())
Dh -= 1
Dw -= 1
S = [input() for _ in range(H)]

dh = [-1, 0, 0, 1]
dw = [0, 1, -1, 0]

INF = pow(10, 10)
seen = [[INF] * W for _ in range(H)]
seen[Ch][Cw] = 0
q = deque()
q.append([Ch, Cw])

while q:
    th, tw = q.pop()
    for i in range(4):
        nh = th + dh[i]
        nw = tw + dw[i]
        if nh < 0 or nh > H - 1 or nw < 0 or nw > W - 1 or S[nh][nw] == '#' or seen[nh][nw] <= seen[th][tw]:
            continue
        seen[nh][nw] = seen[th][tw]
        q.append([nh, nw])
    for dh2 in range(-2, 3):
        for dw2 in range(-2, 3):
            if dh2 == 0 and dw2 == 0:
                continue
            nh = th + dh2
            nw = tw + dw2
            if nh < 0 or nh > H - 1 or nw < 0 or nw > W - 1 or S[nh][nw] == '#' or seen[nh][nw] <= seen[th][tw] + 1:
                continue
            seen[nh][nw] = seen[th][tw] + 1
            q.appendleft([nh, nw])

if seen[Dh][Dw] is INF:
    print(-1)
else:
    print(seen[Dh][Dw])

Measured memory_bytes: 102312
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


double Main(int N, VI &V)
{
    sort(ALL(V));
    double ave = (V[0] + V[1])/2.0;
    if(N == 2) return ave;
    REP2(i, 2, N) {
        ave = (V[i] + ave)/2.0;
    }
    return ave; 
}

int main(void){
    int N;
    cin >> N;
    VI V(N);
    REP(i, N) cin >> V[i];
    printf("%.12f\n", Main(N, V));
    return 0;
}

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

int x, n;
int not_in(int p[], int num) {
  for (int i = 0; i < n; i++)
  {
    if (num == p[i]) return 0;
  }
  return 1;
}

int main() {
  scanf("%d %d", &x, &n);
  int p[n], a[110];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 1; i <= 110; i++) {
    if (not_in(p, i)) a[i - 1] = i;
    else a[i - 1] = 999;
  }

  int min = 999;
  int min_a;
  for (int i = 0; i < 110; i++) {
    if (abs(x - a[i]) < min) {
      min = abs(x - a[i]);
      min_a = a[i];
    }
  }

  for (int i = 0; i > -100; i--) {
    if (abs(x - i) <= min) {
      min = abs(x - i);
      min_a = i;
    }
  }
  printf("%d", min_a);
  return 0;
}

Measured memory_bytes: 3816
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)           

def main():
    n = int(input())
    a = list(enumerate(map(int,input().split())))
    a.sort(key = lambda x:x[1],reverse = True)

    dp = [[0] * (n + 1) for _ in range(1 + n)]
    for i in range(n + 1):
        for j in range(i + 1,n):
            dp[i][j] = -INF

    for j in range(n):
        i,num = a[j]
        i += 1
        for k in range(j + 2):
            if k == 0:
                dp[j + 1][k] = dp[j][k] + num * abs(i - n + j - k)
            else:
                dp[j + 1][k] = max(dp[j][k - 1] + num * abs(i - k),dp[j][k] + num * abs(i - n + j - k))
            
    print(max(dp[-1]))
if __name__ =='__main__':
    main()  

Measured memory_bytes: 199676
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
}

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

int main() {
	string S;
	int w;
	cin >> S >> w;
	for (int i = 0;i < S.length();i += w) cout << S[i];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

やるだけ
*/

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

int main () {
  long long N;
  cin >> N;
  map<long long, int> A;
  for (long long i = 0; i < N; i++) {
    long long sub;
    cin >> sub;
    A[sub]++;  
  } 
  long long ans = 0;   
  for (auto x = A.begin(); x != A.end(); ++x) {
    if (x->second % 2 == 1) {
      ans++;  
    }    
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
def main():
    N, K = map(int, input().split())

    ans = 0
    for i in range(1,N+1):
        cnt = 0
        tmp = i
        while tmp <= K - 1:
            cnt += 1
            tmp *= 2
        aa = (1 / (2 ** cnt)) * (1 / N)
        ans += aa

    print(ans)


main()

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>

using namespace std;

int solve(const vector<vector<int>> &v_positions,
          const vector<vector<int>> &h_positions, const pair<int, int> &pos) {
  int pos_x = pos.first, pos_y = pos.second;
  const vector<int> &v_pos = v_positions[pos_x], &h_pos = h_positions[pos_y];
  if (binary_search(v_pos.begin(), v_pos.end(), pos_y)) {
    return 0;
  }

  int ans = 0;
  // up
  ans +=
      pos_y - *upper_bound(v_pos.rbegin(), v_pos.rend(), pos_y, greater<int>());

  // down
  ans += *upper_bound(v_pos.begin(), v_pos.end(), pos_y) - pos_y;

  // left
  ans +=
      pos_x - *upper_bound(h_pos.rbegin(), h_pos.rend(), pos_x, greater<int>());

  // right
  ans += *upper_bound(h_pos.begin(), h_pos.end(), pos_x) - pos_x;

  return ans - 3;
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> v_positions(w), h_positions(h);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char ch;
      cin >> ch;
      if (ch == '#') {
        v_positions[j].push_back(i);
        h_positions[i].push_back(j);
      }
    }
  }

  for (int i = 0; i < h; ++i) {
    h_positions[i].push_back(-1);
    h_positions[i].push_back(w);
    sort(h_positions[i].begin(), h_positions[i].end());
  }

  for (int i = 0; i < w; ++i) {
    v_positions[i].push_back(-1);
    v_positions[i].push_back(h);
    sort(v_positions[i].begin(), v_positions[i].end());
  }

  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, solve(v_positions, h_positions, {j, i}));
    }
  }

  cout << ans << '\n';
  return 0;
}

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

string s[110];
int n;
map<string, int> mp;
int main(){
  cin >> n;
  cin >> s[0];
  mp[s[0]]++;

  for(int i = 1;i < n;i++){
    cin >> s[i];
    if(s[i-1][s[i-1].size()-1] != s[i][0] || mp[s[i]] == 1){
      cout << "No" << endl;
      return 0;
    }
    mp[s[i]]++;
  }

  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

cnt = 0
carry = 0
for i in range(N+1):
    #print(carry, B[i], A[i])
    cnt += min(A[i], carry+B[i])
    carry = max(0, B[i]-max(0,A[i]-carry))
    #print(cnt, '\n')

print(cnt)

Measured memory_bytes: 82148
def f(s):
  if len(s) > 1:
    cnt = 1
    ans = int(s)
    for i in range(1,len(s)):
      a, c = f(s[i:])
      ans += int(s[:i]) * c + a
      cnt += c
    return ans, cnt
  else:
    return int(s), 1
  
print(f(input())[0])

Measured memory_bytes: 3060
import sys
 
N = int(input())
infos = [list(map(int, input().rstrip().split(' '))) + [i] for i in range(N)]
infos = sorted(infos, key=lambda x: x[2])[::-1]

if N == 1:
    print(infos[0][0], infos[0][1], infos[0][2])
    sys.exit()

for cy in range(100 + 1):
    for cx in range(100 + 1):
        pseudo_h1 = abs(infos[0][0] - cx) + abs(infos[0][1] - cy) + infos[0][2]
 
        flag_assumpt = True
        for info in infos[1:]:
            pseudo_h2 = abs(info[0] - cx) + abs(info[1] - cy) + info[2]
            
            if info[2] == 0:
                if abs(info[0] - cx) + abs(info[1] - cy) < pseudo_h1:
                    flag_assumpt = False
                    break
                
            elif pseudo_h1 != pseudo_h2:
                flag_assumpt = False
                break
        
        if flag_assumpt:
            print(cx, cy, pseudo_h1)
            sys.exit()

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

int main()
{
    int A;
    int B;
    int C;
    int D;
    int E;
    int F;
    int max;
    int waterV = 0;
    int sugarV = 0;
    int water[10000000];
    int sugar[10000000];
    int ansW = 0;
    int ansS = 0;
    double ansPer = 0.0;
    cin >> A >> B >> C >> D >> E >> F;
    for (int i = 0; 100 * A * i <= F; i++)
    {
        for (int j = 0; (100 * A * i) + (100 * B * j) <= F; j++)
        {
            water[waterV] = (100 * A * i) + (100 * B * j);
            waterV++;
        }
    }

    for (int i = 0; C * i <= F; i++)
    {
        for (int j = 0; (C * i) + (D * j) <= F; j++)
        {
            sugar[sugarV] = (C * i) + (D * j);
            sugarV++;
        }
    }

    for (int i = 0; i < waterV; i++)
    {
        for (int j = 0; j < sugarV; j++)
        {
            if (water[i] + sugar[j] > 0)
            {
                if (water[i] + sugar[j] <= F && sugar[j] <= ((double)water[i] / 100.0) * (double)E && (double)(100 * sugar[j]) / (double)(water[i] + sugar[j]) >= ansPer)
                {
                    ansPer = (double)(100 * sugar[j]) / (double)(water[i] + sugar[j]);
                    ansW = water[i];
                    ansS = sugar[j];
                }
            }
        }
    }

    cout << (ansW + ansS) << ' ' << ansS << endl;
    return 0;
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
  ll n;
  ll ans = 1001001001001;
  cin>>n;
  for(ll i=1; i*i<=n; i++) {
    if(n%i) continue;
    ans = min(ans, (i-1)+(n/i)-1);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  int ans = x;
  for (int i = 0; i < 10; ++i) {
    x = r * x - d;
    cout << x << endl;
  }
  return 0;
}

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

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



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

int main(void){
	int N;
	cin >> N;
	if(N<1200){
		cout << "ABC" << endl;
	}else if(N<2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}


	
	return 0;
}

Measured memory_bytes: 888
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int n;
void dfs(int s) {
    int i;
    bool prime = true;
    for (i = 2; i * i <= s; i++) {
        if (s % i == 0) {
            cout << " " << i;
            prime = false;
            dfs(s/i);
            return;
        }
    }
    if (prime) cout << " " << s;
    return;
}
int main(void) {
    cin >> n;
    cout << n << ":";
    dfs(n);
    cout << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n,a[105],ans;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    fort (i,n)
        cin >> a[i];
    fort (i,n)
        if (a[i]>a[i-1]) ans+=a[i]-a[i-1];
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
int x=0;
int y=0;
scanf("%d %d",&x,&y);
if(x%y==0){printf("%d\n",x+1);}
else if(y%x==0){printf("%d\n",y+1);}
else if(x!=y)
{
	if(x%2==0&&y%2==0)
	{
		if(x%10==0&&y%10==0){printf("%d\n",x+y-9);}
		else if(x%10!=0||y%10!=0){printf("%d\n",x+y-1);}
		else{printf("%d\n",x+y);}
	}
	else if(x%2!=0||y%2!=0){printf("%d\n",x+y);}
}
return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

// newer
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)

// 実験中
void cerrall(const vector<bool>& a){rep(i,a.size()) cerr << i << " " << (a[i]? "True" : "False") << "\n"; cerr << "\n";}
template<class T> void cerrall(const vector<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const set<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const multiset<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T, class U> void cerrall(const vector<pair<T,U>>& a){rep(i,a.size()) cerr << i << " : " << a[i].first << " " << a[i].second << "\n";}
template<class T, class U> void cerrall(const map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}
template<class T, class U> void cerrall(const unordered_map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}


int main(){
    int n,m;cin >> n >> m;
    vi a(m);
    vi keys(m);
    rep(i,m){
        int b;
        cin >> a[i] >> b;
        rep(j,b){
            int ai;cin >> ai;
            --ai;
            keys[i] |= (1<<ai);
        }
    }

    //rep(i,m) cout << "i = " << i << " = " << bitset<12>(keys[i]) << "\n";

    vector<vi> dp(m+1,vi((1<<n)+10,INF));
    dp[0][0] = 0;
    for(int i=0;i<m;++i){
        for(int j=0;j<(1<<n);++j){
            chmin(dp[i+1][j | keys[i]], dp[i][j] + a[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    int ans = dp[m][(1<<n)-1];
    cout << (ans == INF? -1 : ans) << "\n";
}

Measured memory_bytes: 16384
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if ((i + 1) % 2 == 1 && a.at(i) % 2 == 1) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
//============================================================================
// Name        : a
// Date        : Tue Feb 19 22:08:04 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int inf = (int) 1e9 + 7;
void solve() {
    int n; cin >> n;
    vi aa(n + 1, 0), dp(n + 1, inf);
    fori (i, 1, n + 1) {
        cin >> aa[i];
    }

    dp[1] = 0;
    fori (i, 2, n + 1) {
        if (i >= 1) {
            dp[i] = min(dp[i], dp[i - 1] + abs(aa[i] - aa[i - 1]));
        }
        if (i >= 2) {
            dp[i] = min(dp[i], dp[i - 2] + abs(aa[i] - aa[i - 2]));
        }
    }
    output(dp[n]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n; std::cin >> n;
	std::vector<int> is_alive(1 << n); for (auto& a : is_alive) std::cin >> a;
	int count = 0;
	for (auto i = 0; i < is_alive.size(); ++i) {
		if (is_alive[i] == 1) {
			bool is_just = true;
			for (auto j = 0; j < n; ++j) {
				if ((i & (1 << j)) == 0) {
					if (is_alive[i | (1 << j)] != 1) {
						std::cout << -1 << std::endl;
						return 0;
					}
				}
				else {
					if (is_alive[i ^ (1 << j)] == 1) {
						is_just = false;
					}
				}
			}
			if (is_just) ++count;
		}
	}
	std::cout << count << std::endl;
}



Measured memory_bytes: 7064
A,B=[],[]
h,w=map(int,input().split())
for i in range(h):
    a=input()
    if "#" in a:
        A.append(a)
b=""
for i in range(w):
    if "#" not in b:
        B.append(i-1)
    b=""
    for j in range(len(A)):
        b+=A[j][i]
if "#" not in b:
    B.append(w-1)
B.pop(0)
o=0
for i in range(len(A)):
    o=0
    A[i]=list(A[i])
    for j in B:
        A[i].pop(j-o)
        if o==len(B)-1:
            print("".join(A[i]))
        o+=1
if len(B)==0:
    for i in A:
        print("".join(i))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  for(ll i=1;i<10;i++) {
if((i-1)*111<N&&i*111>=N) {
cout<<i*111<<endl;
}
  }
  
}


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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main()
{
    SAM;
    int n;
    cin>>n;
    ll arr[n];
    FOR(i,0,n)
    	cin>>arr[i];

    ll sum=0;
    FOR(i,0,n-1)
    {
    	if(arr[i+1]<arr[i])
    	{
    		sum+=arr[i]-arr[i+1];
    		arr[i+1]=arr[i];
    	}
    }

    

    cout<<sum;
   
    
    return 0;
}




Measured memory_bytes: 5116