akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
// const int inf = 1e9;
const int inf = 2e9;
const int mod = 1e9 + 7;

struct Range {
    int l, r; // [l, r)
    int no;
    Range(){}
    Range(int _l, int _r, int _no) : l(_l), r(_r), no(_no) {}
    bool operator<( const Range& right ) const {
        if (l != right.l) return l < right.l;
        if (r != right.r) return r < right.r;
        return no < right.no;
    }
    void print() {
        cout << l << " " << r << " " << no << endl;
    }
};

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

    int n;
    while (cin >> n, n) {
        set<Range> st;
        st.insert(Range(-inf, 0, -1));
        st.insert(Range(inf - 1, inf, -1));

        rep(i, n) {
            char mode;
            cin >> mode;
            if (mode == 'W') {
                int no, len;
                cin >> no >> len;
                for (auto it = st.begin(); next(it) != st.end() && len > 0; it++) {
                    int len_here = min(len, next(it)->l - it->r);
                    if (len_here > 0) {
                        it = st.insert(Range(it->r, it->r + len_here, no)).first;
                        len -= len_here;
                    }
                }
            } else if (mode == 'D') {
                int no;
                cin >> no;
                for (auto it = st.begin(); it != st.end(); ) {
                    if (it->no == no) {
                        it = st.erase(it);
                    } else {
                        it++;
                    }
                }
            } else if (mode == 'R') {
                int pos;
                cin >> pos;
                auto it = st.upper_bound(Range(pos, inf, inf));
                it--;
                cout << (pos < it->r ? it->no : -1) << endl;
            }

        }

        // end of data
        cout << endl;

    }

}

Measured memory_bytes: 3324
S = input()

humi = 1
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] not in ['R', 'U', 'D']:
            humi *= 0
            break
    if i % 2 == 1:
        if S[i] not in ['L', 'U', 'D']:     
            humi *= 0
            break
if humi == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#ifdef _WIN32
#include <vector>
#include<set>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#else
#include <bits/stdc++.h>
#endif
using namespace std;

int main() {
	char* S = new char[100];
	cin >> S;
	int N = strlen(S);
	int N2 = (N - 1) / 2;
	int flag = 1;
	int N4 = (N2 - (N2 % 2)) / 2;

	if (N == 3) {
		if (S[0] != S[2]) {
			flag = 0;
		}
	}
	else {
		for (int i = 0; i <= N4; i++) {
//			cout << S[i] << "," << S[N2 - 1 - i] << "," << S[i + N2 + 1] << "," << S[N - 1 - i] << endl;
			if (S[i] != S[N2 - 1 - i] || S[i] != S[i + N2 + 1] || S[i] != S[N - 1 - i]) {
				flag = 0;
			}
		}
	}

	if (flag == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main(){
int N;
cin >> N;
  int T,A;
    cin >>T>>A;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >>H.at(i);
  }
  double kion,sa,min_sa=1000000.0;
  int ans;
  for(int i=0;i<N;i++){
    kion=T-H.at(i)*0.006;
    sa=abs(A-kion);
    
    if(sa < min_sa){
      ans=i;
      min_sa=sa;
    }
    //cout << "sa="<< sa << "ans="<< ans << endl;
    //cout << H.at(i) <<endl;
  }
  
  cout << ans+1 << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i,j,ch=0;
	scanf("%d",&n);
	if(n>=1&&n<=100)
	{
		for(i=1; i<=9; i++)
		{
			for(j=1; j<=9; j++)
			{
				if(i*j==n)
				{
					ch++;
					break;
				}
			}
				if(ch==1)
					break;
		}
		if(ch==1)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
n = int(input())
A = [int(i) for i in sys.stdin.readlines()]
h = 0
G =[]
while n >= 3*h+1:
	G.append(3*h+1)
	h = 3*h+1
for i in range(len(G)//2):
	G[i],G[-1-i] =G[-1-i],G[i]
cnt = 0
m = len(G)
def c_function(A,g,n):
	c = 0	
	for i in range(g,n):
		v = A[i]
		j = i-g			
		while j >= 0 and 		A[j]>v:
			A[j+g] = A[j]
			j = j-g
			c +=1
		A[j+g]=v
	return c

for k in range(m):
	g = G[k]
	cnt += c_function(A,g,n)	

print(m)
print(" ".join(map(str,G)))
print(cnt)
for i in range(n):
	print(A[i])


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

int main(){
    string str;
    while(getline(cin, str), str != "."){
        stack<char> kakko;
        int i;
        for(i=0; i<str.size(); ++i){
            if(str[i] == '(' || str[i] == '[') kakko.push(str[i]);
            if(str[i] == ')' || str[i] == ']'){
                if(kakko.size() == 0) break;
                else{
                    if((kakko.top()=='(')?str[i]==')':str[i]==']') kakko.pop();
                    else break;
                }
            }
        }
        cout << ((i==str.size()&&kakko.size()==0)?"yes":"no") << endl;
    }
    return 0;
}

Measured memory_bytes: 904
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		Integer[] aary = new Integer[a];
		Integer[] bary = new Integer[b];
		Integer[] cary = new Integer[c];
		for(int i=0; i<a; i++){
			aary[i] = sc.nextInt();
		}
		for(int i=0; i<b; i++){
			bary[i] = sc.nextInt();
		}
		for(int i=0; i<c; i++){
			cary[i] = sc.nextInt();
		}
		Arrays.sort(aary, Comparator.reverseOrder());
		Arrays.sort(bary, Comparator.reverseOrder());
		Arrays.sort(cary, Comparator.reverseOrder());
		Integer[] aresult = new Integer[x];
		Integer[] bresult = new Integer[y];
		for(int i=0; i<x; i++){
			aresult[i] = aary[i];
		}
		for(int i=0; i<y; i++){
			bresult[i] = bary[i];
		}
		List<Integer> list = new ArrayList<Integer>(Arrays.asList(aresult));
		List<Integer> list2 = new ArrayList<Integer>(Arrays.asList(bresult));
		list.addAll(list2);
		Collections.sort(list);
		int ccount = 0;
		for(int i=0; i<list.size(); i++){
			if(ccount != cary.length && list.get(i)<cary[ccount]){
				list.set(i, cary[ccount]);
				ccount++;
			} else {
				break;
			}
		}
		long result = 0;
		for(int i=0; i<list.size(); i++){
			result += list.get(i);
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 101824
#include <stdio.h>

#define WIDTH 12
#define HEIGHT 12

void delIsland( int, int );

char field[ WIDTH ][ HEIGHT ];
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int main( void ) {
	int x, y, island;

	do {
		for ( y = 0; y < HEIGHT; y++ ) {
			for ( x = 0; x < WIDTH; x++ )
				field[ x ][ y ] = getchar();
			getchar();
		}

		island = 0;
		for ( x = 0; x < WIDTH; x++ )
			for ( y = 0; y < HEIGHT; y++ )
				if ( field[ x ][ y ] == '1' ) {
					delIsland( x, y );

					island++;
				}

		printf( "%d\n", island );
	} while ( getchar() != EOF );

	return 0;
}

void delIsland( int x, int y ) {
	int i;

	field[ x ][ y ] = '0';

	for ( i = 0; i < 4; i++ ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( nx >= 0 && nx < WIDTH && ny >= 0 && ny < HEIGHT && field[ nx ][ ny ] == '1' )
			delIsland( nx, ny );
	}
}

Measured memory_bytes: 524
n = int(input())
a = [int(x) for x in input().split()]

c = 0

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if a[j] < a[minj]:
            minj = j
    if minj != i:
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp
        c += 1

print(" ".join([str(x) for x in a]))
print(c)

Measured memory_bytes: 7748
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>

using namespace std;

int main()
{
    string n;
    cin >> n;
    for(char c : n)
    {
        if(c=='1') cout << '9';
        else if(c=='9') cout << '1';
        else cout << c;
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let (a, b) = (read::<usize>() - 1, read::<usize>() - 1);
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut used = vec![0; n];
    let mut zero: i64 = 0;
    let mut nibu: i64 = 0;
    let mut not_nibu: i64 = 0;
    for i in 0..n {
        if used[i] == 0 {
            if graph[i].len() == 0 {
                zero += 1;
                continue;
            }
            let mut que: VecDeque<usize> = VecDeque::new();
            que.push_back(i);
            let mut nibu_check = true;
            used[i] = 1;
            while !que.is_empty() {
                let q = que.pop_front().unwrap();
                for j in &graph[q] {
                    if used[*j] == 0 {
                        used[*j] = if used[q] == 1 { 2 } else { 1 };
                        que.push_back(*j);
                    }
                    if used[*j] == used[q] {
                        nibu_check = false;
                    }
                }
            }
            if nibu_check {
                nibu += 1;
            } else {
                not_nibu += 1;
            }
        }
    }
    let ans: i64 = zero * zero
        + zero * (n as i64 - zero) * 2
        + nibu * nibu * 2
        + not_nibu * nibu * 2
        + not_nibu * not_nibu;
    println!("{}", ans);
}

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


Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n){ cout<<"Yes"; return 0; }
    }
  }
  cout<<"No";

}


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


class contest
{
		static void Main(string[] args)
		{
			var num = int.Parse(Console.ReadLine());
            var input = new List<int>();

            var dicSorted = new Dictionary<int, int>();
            var dicOriginal = new Dictionary<int, int>();
            int count = 0;

            for (int i = 0; i < num; i++) input.Add(int.Parse(Console.ReadLine()));//dic.Add(int.Parse(Console.ReadLine()),i);
            List<int> clone = new List<int>(input);
            clone.Sort();

            for (int i = 0; i < num; i++) dicOriginal.Add(input[i], i);
            for (int i = 0; i < num; i++) dicSorted.Add(clone[i], i);


            for(int i =0; i< num; i+=2)
            {
                if (dicOriginal[input[i]] % 2 != dicSorted[input[i]] % 2) count++;
            }

            Console.WriteLine(count);     
		}
}

Measured memory_bytes: 18776
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s, s_copy;
  int n, i, a;
  while(1){
    cin >> s;
    if(s == "-") break;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
      scanf("%d", &a);
      s_copy = s.substr(0, a);
      s.erase(0, a);
      s.insert(s.size(), s_copy);
    }
    cout << s << endl;
  }
}


Measured memory_bytes: 3240
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 100004

typedef long long ll;

ll X,Y,Z;
ll max(ll a,ll b){
    if(a>b) return a;
    else return b;
}

ll min(ll a,ll b){
    if(a<b) return a;
    else return b;
}

/*qsort(array,num_of_index,sizeof(ll),compare_int); */
 ll compare_int(const void *a,const void *b){
     return *(ll*) a - *(ll *) b; 
 } 
 
ll b_search(ll* array,ll left,ll right,ll key){
    ll mid = left - (right - left)/2;
     if( right - left == 1){
         if(array[mid]==key)
             return mid;
          else
               return -1;
     }
     if(array[mid]==key)
         return mid;
     else if(array[mid]>key)
         b_search(array,left,mid,key);
     else if(array[mid]<key)
         b_search(array,mid,right,key);
}

ll check(ll ans){
    if(Y*ans + Z*(ans + 1) <= X) return 1;
    else return 0;
}

 ll upper_bound(ll  *array,ll left,ll right){
     if(right-left==1)
         return left;
     ll mid = left + (right - left)/2;
     if(check(mid))
         return upper_bound(array,mid,right);
     else
         return upper_bound(array,left,mid);
 }


ll main(){
    scanf("%lld %lld %lld",&X,&Y,&Z);
    ll num[MAX];
    for(ll i=1;i<MAX;i++)
        num[i] = i;
    printf("%lld",upper_bound(num,1,MAX));
}


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

const string day[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
const int da[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main(void){
  int m, d;
  while(cin >> m >> d, m | d){
    while(1){
      m--;
      if(m > 0){
        d += da[m];
      }else{
        break;
      }
    }
    cout << day[d%7] << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<int> ans(n);
    rep(i,n){
        if(i%2==0) ans[0]+=a[i];
        else ans[0]-=a[i];
    }

    for(int i=1;i<n;i++){
        if(i==n-1) ans[i]=2*a[n-1]-ans[0];
        else ans[i]=2*a[i-1]-ans[i-1];
    }
    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}

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

namespace abc_167b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');
            int one = int.Parse(S[0]);
            int zero = int.Parse(S[1]);
            int minone = int.Parse(S[2]);
            int kazu = int.Parse(S[3]);
            
            if(kazu <= one)
            {
                Console.WriteLine(kazu);
            }
            else if(one < kazu && (kazu - one) <= zero)
            {
                Console.WriteLine(one);
            }
            else
            {
                Console.WriteLine(one*2 - kazu + zero);
            }

            Console.Read();
        }
    }
}


Measured memory_bytes: 27472
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  if(n%2){
    puts("No");
    return 0;
  }
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[i+n/2]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;

int main()
{
    int k,s;
    in k>>s;
    int ans=0;
    for(int a=0;a<=k;a++)
    {
        for(int b=0;b<=k;b++)
        {
            int c=s-a-b;
            if(0<=c && c<=k)ans++;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[128];
    int len;
    int i;
    
    scanf("%s", s);
    len = strlen(s);
    for (i = 0; i + 8 < len; ++i) putchar(s[i]);
    puts("");
    
    return 0;
}


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

using namespace std;
int main(){
  int n, k, ans;
  cin >> n >> k;

  if(n > 12){
    ans = k;
  }
  else if(n < 6){
    ans = 0;
  }
  else{
    ans = k / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define se second

using namespace std;

const int MAXN = 2e5 + 7, MOD = 1e9 + 7;

int main() 
{
//	freopen("test.inp","r",stdin);
//	freopen("BAILAM.OUT","w",stdout);	
	io;
	int n;
	cin >> n;
	ll res = 0;
	for (int i = 1; i <= n; ++i) res += 1LL*i*(i + 1) / 2;
	
	for (int i = 1; i < n; ++i)
	{
		int u, v;
		cin >> u >> v;
		if (u < v) swap(u, v);
		res -= 1LL*v*(n - u + 1);
	}
		
	cout << res;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n;
  cin >> n;
  vector<ld> prob(n+1, 0.0); // prob[i] is the probability of having i heads
  prob[0] = 1.0;
  ld pi;
  forx(i, n) {
    cin >> pi;
    vector<ld> nprob(n+1, 0.0);
    forx(j, n+1) {
      if (prob[j] > 0) {
        nprob[j] += prob[j] * (1 - pi);
        if (j+1 < n+1) {
          nprob[j+1] += prob[j] * pi;
        }
      }
    }
    /*
    cerr << "nprob:";
    for(ld l : nprob) {
      cerr << " " << l;
    } cerr << nl;
    */
    nprob.swap(prob);
  }
  //sum probability of heads > n / t;
  ld ans = 0;
  //cerr << "# coins = " << n << nl;
  int low = (n-1)/2+1;
  //cerr << "at least " << low << " coins" << nl;
  for(int i = low; i < n+1; ++i) {
    ans += prob[i];
  }
  cout << fixed << setprecision(11) << ans << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 384
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "YES"; } string_type do_falsename() const { return "NO"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n = 4;
  vector<ll> cnt(4, 0);
  rep(i, 3) {
    ll a, b; cin >> a >> b; --a, --b;
    cnt[a]++;
    cnt[b]++;
  }
  sort(all(cnt));
  cout << (cnt == vector<ll>({1, 1, 2, 2})) << endl;
}


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

int main(){
    int H,W,K;
    cin>>H>>W>>K;
    int A[H][W];
    rep(i,H)rep(j,W){
        char s;
        cin>>s;
        if(s=='.')A[i][j]=0;
        else if(s=='#')A[i][j]=1;
    }
    int ans=0;
    for(int bit1=0;bit1<(1<<H);bit1++){
        for(int bit2=0;bit2<(1<<W);bit2++){
            int B[H][W];
            int cnt=0;
            rep(i,H)rep(j,W)B[i][j]=A[i][j];
            rep(i,H){
                if(bit1&(1<<i)){
                    rep(j,W)B[i][j]=0;
                }
            }
            rep(i,W){
                if(bit2&(1<<i)){
                    rep(j,H)B[j][i]=0;
                }
            }
            rep(i,H)rep(j,W)cnt+=B[i][j];
            if(cnt==K)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int c = (int)count( S.begin(), S.end(), 'o' );
	cout << 700 + 100*c << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int mood(int a, int b){
    if (a % b == 0) return b;
    else return a % b;
}

int main() {
    int nn, m; cin >> nn >> m;
    int n = 2 * m + 1;
    int le = (n - 1) / 2;
    if (m % 2 == 0) le++;
    vector<P> ans(m);
    rep(i,le/2){
        ans[i].first = 1 + i;
        ans[i].second = le + 1 - ans[i].first;
    }
    repp(i,m,le/2){
        ans[i].first = le + 1 + i - le/2;
        ans[i].second = n + le + 1 - ans[i].first;
    }
    rep(i,m) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 3820
n = gets.to_i
s = gets.chomp.chars


cost_tmp = s.count(".")

ans = cost_tmp

for num in 1..(s.size) do
  # numからすべて#、num-1からすべて.
  if s[num - 1] == "#"
    cost_tmp += 1
  else
    cost_tmp -= 1
  end
  if cost_tmp < ans
    ans = cost_tmp
  end
end
puts ans.to_s

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

int main(){
	int n,x;
	cin >> n;
	for(int i=1;i<=n;i++){
		if(i%3==0){
			cout << " " << i;
		}else{
			x=i;
			while(x>0){
				if(x%10==3){
					cout << " " << i;
					break;
				}else{
					x = x/10;
				}
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 1164
import java.util._

object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val string = scanner.nextLine
    val revString = string.reverse
    if (string != revString) {
      println("No")
      return
    }

    val firstHalf = string.substring((string.length - 1) / 2 + 1)
    if (firstHalf != firstHalf.reverse) {
      println("No")
      return
    }

    val secondHalf = string.substring((string.length - 1) / 2 + 1, string.length)
    if (secondHalf != secondHalf.reverse) {
      println("No")
      return
    }

    println("Yes")
  }
}


Measured memory_bytes: 27216
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int ans = 0;
    int f = 0;
    rep(i,0,s.size()){
        if(s[i]=='R'){
            f++;
        }else{
            chmax(ans,f);
            f = 0;
        }
    }
    cout << max(ans,f) << endl;
}

Measured memory_bytes: 3612
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

N, K, Q = map(int, input().split())
A = []
for i in range(Q):
    a = int(input())
    A.append(a)

P = [K-Q] * N
for i in range(Q):
    P[A[i]-1] += 1

for c in P:
    print('Yes' if c > 0 else 'No')


Measured memory_bytes: 10472
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pint pair<int,int>

const int MAX_N = 5000; //多めに見積もる
const int INF = (1LL<<60)-1;

int dat[2*MAX_N],n;

void init(int a){
  n = 1LL;
  
  while( n < a ){ n *= 2;} 
  
  for(int i = 0; i < 2*MAX_N; i++){ dat[i] = INF;}
  //INF初期化
}

void update(int k, int a){
  
  k += n-1;
  dat[k] = a;
  
  while( k > 0 ){
    k = (k-1)/2;
    dat[k] = min(dat[2*k+1],dat[2*k+2]);
  }
}

int find(int a,int b, int k, int l, int r){
  if( r <= a || b <= l ){ return INF;}
  if( a <= l && r <= b){ return dat[k];}
  else{
    int v1 = find(a,b,2*k+1,l,(l+r)/2);
    int v2 = find(a,b,2*k+2,(l+r)/2,r);
  
  
  return min(v1,v2);
  
  }
}

int N,x;

signed main(void){ 
  
  cin >> N >> x;
  
  init(N+1);
  
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    update(i,a);
  }
  
  int ans = INF;
  
  for(int k = 0; k < N; k++){  //何回回転するかを決めうち
    
    int res = 0;
    
    for(int i = 0; i < N; i++){ 
    
     if( i-k >= 0 ){
      
       res += find(i-k,i+1,0,0,n);
      
    //min{A[i],A[i-1],,, A[i-k]のうちの最小値をセグでもとめる
       
     }
     else{
       
       int r1 = find(0,i+1,0,0,n);
       // A[0],,,A[i]の最小値と、
       int r2 = find(i-k+N,N,0,0,n);
       // A[i-k+N],,, A[N-1]の最小値を求め
       
       res += min(r1,r2); //より小さい方を取る
     }
    }
    
     ans = min(ans, res+k*x);
    
  }
  
  cout << ans << endl;
  
  return 0;
}
    


Measured memory_bytes: 384
N, M = map(int,input().split())
P = [list(map(int,input().split())) for _ in range(M)]
P.sort()
q = -1
ans = ("IMPOSSIBLE")
for i in range (M):
    if P[i][0] == 1:
        p = P[i][1]
        if q < 0:
            if i > 0:
                q = i - 1
            else:
                q = 0
        for j in range(q, M):
            if P[j][0] == p:
                if P[j][1] == N:
                    ans = ("POSSIBLE")
                    break
            elif P[j][0] > p:
                if q >= 0:
                    q = j - 1
                else:
                    q = 0
                break
    else:
        break
print(ans)

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

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

int main(){
    int H,W;
    cin>>H>>W;
    char G[H][W];
    int cnt=0;
    rep(i,H){
        rep(j,W){
            cin>>G[i][j];
            if(G[i][j]=='#')cnt++;
        }
    }

    int dist[H][W];
    rep(i,H)rep(j,W)dist[i][j]=-1;
    queue<pair<int,int>> que; 

    dist[0][0]=0;
    que.push(pair<int,int>(0,0));

    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();

        rep(i,4){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<0||nx>H-1||ny<0||ny>W-1)continue;
            if(G[nx][ny]=='#')continue;
            if(dist[nx][ny]!=-1)continue;
            dist[nx][ny]=dist[x][y]+1;
            que.push(pair<int,int>(nx,ny));
        }
    }

    if(dist[H-1][W-1]==-1){
        cout<<-1<<endl;
        return 0;
    }

    else{
        cout<<H*W - dist[H-1][W-1] - cnt -1<<endl;
        return 0;
    }

}

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

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

  if (a > b)
  {
    tmp = a;
    a = b;
    b = tmp;
  }

  if (b > c)
  {
    tmp = b;
    b = c;
    c = tmp;
  }

  if (a > b)
  {
    tmp = a;
    a = b;
    b = tmp;
  }

  cout << a << " " << b << " " << c << endl;

  return 0;
}



Measured memory_bytes: 3112
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int n;
	cin>>n;
	int *h = new int[n];
	rep(i,n) cin>>h[i];
	ll ans = 0;
	for(int i = 0; i < n; i++){
		bool ok = true;
		for(int j = 0; j < i; j++){
			if( h[j] > h[i]){
				ok = false;
				break;
			}
		}
		if( ok == true) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,l,i;
cin>>n>>l;
string  s;
vector<string>v;
for(i=0;  i<n;  i++)
{
cin>>s;
v . push_back(s);
}
sort(v.begin(), v.end());
for(i=0; i<n; i++)
cout<<v[i];
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;cin>>s;
  char st;
  int cnt;
  for (int i=0; i<4;i++) {
    cnt =0;
    st = s[i];
    for (int j=0;j<4;j++){
      if (st == s[j]) cnt++;
    }
    if (cnt != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <regex>
#include <cmath>
using namespace std;

int main(){
    string s;
    cin >> s;
    int a;
    for(int i = 0;i < s.size();i++){
        if(s[i] ==  'x'){
            a++;
        }
    }
    if(a >= 8){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    
    
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

template<typename T>
T lcm(T a, T b){
  return a * b / gcd(a, b);
}
int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double S = W * H / 2;
    if(W == x + x and H == y + y){
        cout << setprecision(10) << S << endl << '1' << endl;
    }else{
        cout << setprecision(10) << S << endl << '0' << endl;
    }
}

Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool cyclic(int x){
    string s = to_string(x);
    if(s[0] == s[4] && s[1] == s[3]) return true;
    else return false;
}

int main(){
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for(int i=A; i<=B; i++){
        if(cyclic(i)) ans ++;
    }    
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<bool>> g(n, vector<bool>(n, false));
    int u, k;
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        int v;
        for (int j = 0; j < k; j++){
            cin >> v;
            v--;
            g[u][v] = true;
        }
    }
    vector<int> color(n, 0);
    vector<int> min_distance(n, -1);
    queue<int> bfs;
    bfs.push(0);
    min_distance[0] = 0;
    color[0]++;
    while (bfs.size()){
        int u = bfs.front();
        bfs.pop();
        for (int i = 0; i < n; i++){
            if (g[u][i] && color[i] == 0){
                bfs.push(i);
                color[i]++;
                min_distance[i] = min_distance[u] + 1;
            }
        }
        color[u]++;
    }

    for (int i = 0; i < n; i++){
        cout << i + 1 << ' ' << min_distance[i] << endl;
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;

  int dx = x2-x1, dy = y2-y1;
  int x3, y3, x4, y4;
  x3 = x2 - dy; y3 = y2 + dx;
  x4 = x3 - dx; y4 = y3 - dy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    int ans = INT_MAX;
    for (int i = 0; i <= 100; i++) {
        int r = 0;
        for (auto x: X) {
            r += (i-x)*(i-x);
        }
        ans = min(ans, r);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    int ret = 0;
    while(n > 1){
        n = (n+2) / 3;
        ++ ret;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def readln(ch):
    _res = list(map(int,str(input()).split(ch)))
    return _res

s = readln(' ')
n,k = s[0],s[1]
a = [0 for i in range(0,n+1)]
a[1:] = readln(' ')
s = a[:]
r = a[:]
for i in range(1,n+1):
    s[i] = s[i-1] + s[i]
    if r[i] > 0:
        r[i] = r[i-1] + r[i]
    else:
        r[i] = r[i-1]

ans = 0
for i in range(k,n+1):
    ans = max(ans,r[n] - (r[i] - r[i-k]) + max(0,s[i] - s[i-k]))

print(ans)


Measured memory_bytes: 16532
#include <bits/stdc++.h>
 using namespace std;
#define FIO              ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define int              long long
#define mod              1000000007
#define eps              1e-9
#define setbits          __builtin_popcount
#define gcd              __gcd
#define rep(i,a,b)       for(int i=a;i<=b;i++)
#define repr(i,b,a)      for(int i=b;i>=a;i--)
#define forn(i,n)        for(int i=0;i<n;i++)
#define all(a)           a.begin(), a.end()
#define pb               push_back
#define endl             "\n"
#define ff               first
#define ss               second
#define asort(c)         sort(all(c)) 
#define lbpos(x,v)       (int)(lower_bound(all(v),x)-v.begin())
#define ubpos(x,v)       (int)(upper_bound(all(v),x)-v.begin())
#define PI               3.14159265358979323846
 using vi = vector<int>;
 using ii = pair<int,int>;
 using vii = vector<ii>;
 using ld = long double;
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1)
{std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1,typename... Args>void ZZ(const char* names,Arg1&& arg1,
 Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
clock_t time_p=clock();
void timer()
{
  time_p=clock()-time_p;
  cerr<<"Execution Time: "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";
}


int32_t main()
{
  FIO;
 
  int n,asum=0,bsum=0,turn=1;
  cin>>n;

  vii ab(n);
  vi a(n),b(n);
  forn(i,n)
  {
    cin>>a[i]>>b[i];
    ab[i].ff=a[i]+b[i];
    ab[i].ss=i;
  }

  asort(ab);
  reverse(all(ab));
  forn(i,n)
  {
    if(turn)
    {
      asum+=a[ab[i].ss];
      turn^=1;
    }
    else
    {
      bsum+=b[ab[i].ss];
      turn^=1;
    }
  }
  cout<<asum-bsum;

  timer();
  return 0; 
}   


Measured memory_bytes: 3456
n = int(input())
s = input()

def addleave(p):
    for i in range(1, n-1):
        if s[i]=="o":
            if p[i]=="S":
                p += "S" if p[i-1]=="S" else "W"
            else:
                p += "W" if p[i-1]=="S" else "S"
        else:
            if p[i]=="S":
                p += "W" if p[i-1]=="S" else "S"
            else:
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    result = addleave("SS")
    if check(result):
        return result
    result = addleave("SW")
    if check(result):
        return result
    result = addleave("WS")
    if check(result):
        return result
    result = addleave("WW")
    if check(result):
        return result
    return -1

def check(res):
    res = res + res + res
    flag = True
    for i in range(n):
        if res[n + i - 1] == res[n + i + 1] and res[n + i]=="S" and s[i]=="o":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="S" and s[i]=="x":
            pass
        elif res[n + i - 1] == res[n + i + 1] and res[n + i]=="W" and s[i]=="x":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="W" and s[i]=="o":
            pass
        else:
            flag = False
    return flag
print(solve())

Measured memory_bytes: 3916
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int a[200];
    for(int i = 0; i < N; ++i) cin >> a[i];
    int cnt = 0;
    while(true){
        bool notDevided = false;
        for(int i = 0; i < N; ++i){
            if(a[i] % 2 != 0){
                notDevided = true;
                break;
            }else{
                a[i] /= 2;
            }
        }
        if(notDevided == false)
            cnt++;
        else
            break;
    }
    cout << cnt << 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++)

int main()
{
  int x,y;
  string ans;
  
  cin >> x >> y;
  
  ans="No";
  if (y % 2 ==0 && y >= x*2)
  {
    if ((4*x - y)/2 >= 0)
      ans="Yes";
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int inf=1e9+7;
const int mod=1e9+7;

//const int maxn=

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int a[4]={0,1,1,1};
    
    for(int i=0,x;i<2;i++)
    {
    	cin>>x;
    	a[x]--;
	}
	
	for(int i=1;i<=3;i++)
		if(a[i]==1)
			return cout<<i<<endl,0;
    
    return 0;
}

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



int main(){
  int K;
  cin>>K;
  K--;
  
  
  int digitIndexStart=0;
  int digitIndexEnd=8;
  
  vector<long long int> A;
  for(int i=0;i<9;i++){
    A.push_back(i+1);
  }
  
  for(int a=0;a<100000;a++){
    for(int i=digitIndexStart;i<=digitIndexEnd;i++){

      ll temp=A[i];
      int enddigit=temp%10;//下一桁の値
      if(enddigit==0){
        A.push_back(temp*10);
        A.push_back(temp*10+1);
      }else if(enddigit==9){
        A.push_back(temp*10+8);
        A.push_back(temp*10+9);
      }else{
         A.push_back(temp*10+enddigit-1);
        A.push_back(temp*10+enddigit);
        A.push_back(temp*10+enddigit+1);
      }
    }
    digitIndexStart=digitIndexEnd+1;
    digitIndexEnd=A.size()-1;

    if(digitIndexEnd>K)break;
  }
    
  
  long long int ans=A[K];
  cout<<ans<<endl;


}


Measured memory_bytes: 2420
#include<iostream>
#include<climits>
#include<vector>
using namespace std;

#define ll long long 

const int N=100001;
vector<ll>g[N];
ll dp[N];

ll solve(ll src)
{
	if(dp[src]!=-1)
	{
		return(dp[src]);
	}
	ll ans=INT_MIN;
	for(auto x:g[src])
	{
		ans=max(ans,solve(x));
	}
	if(ans==INT_MIN)
	{
		return(0);
	}
	return(dp[src]=ans+1);
}

int main()
{
	ll i;
	ll n,m,x,y;
	cin>>n>>m;
	for(i=0;i<=N;i++)
    {
      dp[i]=-1;
    }
    ll ans=0;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		g[x].push_back(y);
	}
	for(i=1;i<=n;i++)
	{
		if(dp[i]==-1)
		{
			ans=max(ans,solve(i));
		}
		else
		{
			ans=max(ans,dp[i]);
		}
	}
	cout<<ans<<"\n";
}

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

int main() {
  int N;
  cin >> N;
  vector<int> hs(N);
  rep(i, N) cin >> hs[i];
  vector<int> dp(N);
  dp[0] = 0;
  dp[1] = abs(hs[0] - hs[1]);
  rep(i, N-2) {
    int cost1 = abs(hs[i+2]-hs[i+1]);
    int cost2 = abs(hs[i+2]-hs[i]);
    dp[i+2] = min(dp[i+1]+cost1, dp[i]+cost2);
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
  int n,mnv,mxv,i;
  int a[200000];
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }

  mnv = a[0];
  mxv = a[1]-a[0];
  for(i=1;i<n;i++)
  {
    if((a[i]-mnv)>mxv)mxv=(a[i]-mnv);
    if(mnv>a[i])mnv=a[i];
  }

  printf("%d\n",mxv);
  return 0;
}


Measured memory_bytes: 2632
#include <iostream>

using namespace std;

int main()
{
    int n, v[10];
    char c;
    cin >> n;
    v[0] = v[1] = v[2] = v[3] = 0;
    while(n--)
    {
        cin >> c;
        if(c == 'P')
            v[0] = 1;
        else if(c == 'W')
            v[1] = 1;
        else if(c == 'G')
            v[2] = 1;
        else
            v[3] = 1;
    }
    n = 0;
    for(int i = 0; i < 4; i++)
        if(v[i] == 1)
            n++;
    if(n == 4)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}


Measured memory_bytes: 256
def leap? y
    leap = false
    leap = true if y % 4 == 0
    leap = false if y % 100 == 0
    leap = true if y % 400 == 0
    leap
end

def countdays y, m, d
    arr = [[31,29,31,30,31,30,31,31,30,31,30,31], [31,28,31,30,31,30,31,31,30,31,30,31]]
    sum = 0
    1.upto(y - 1){|i| sum += (leap?(i)) ? 366 : 365}
    1.upto(m - 1){|i| sum += (leap?(y)) ? arr[0][i - 1] : arr[1][i - 1]}
    1.upto(d){sum += 1}
    sum
end

meiji_firstday = countdays(1868, 9, 8)
taisho_firstday = countdays(1912, 7, 30)
showa_firstday = countdays(1926, 12, 25)
heisei_firstday = countdays(1989, 1, 8)
gengos = {"meiji"=>1867, "taisho"=>1911, "showa"=>1925, "heisei"=>1988}

while line = gets
    y, m, d = line.chomp.split.map(&:to_i)
    days = countdays(y, m, d)
    result, gengo = nil, nil
    if days < meiji_firstday
        result = "pre-meiji"
    elsif days < taisho_firstday
        gengo = "meiji"
    elsif days < showa_firstday
        gengo = "taisho"
    elsif days < heisei_firstday
        gengo = "showa"
    else
        gengo = "heisei"
    end
    y -= gengos[gengo] if gengo
    result = "#{gengo} #{y} #{m} #{d}" if result.nil?
    puts result
end


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

using namespace std;

typedef long long ll;

int main(){
  ll a,b,n;
  cin>>n>>a>>b;
  ll mx=(n-1)*b+a,mn=(n-1)*a+b;
  ll ans=mx-mn+1;
  if(ans<0)ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from functools import reduce
from operator import mul
import math

def nCr(n, r):
    r = min(r, n-r)
    upper = reduce(mul, range(n, n-r, -1), 1)
    lower = reduce(mul, range(r, 0, -1), 1)
    return upper // lower


def oddCaseK(n, k):
    cand = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand += 1
    
    number_of_possibles = 0
    if cand >= 1:
        number_of_possibles += cand
    if cand >= 2:
        number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
    if cand >= 3:
        number_of_possibles += nCr(cand, 3) * math.factorial(3)
    
    return number_of_possibles

    

def evenCaseK(n, k):
    cand1 = 0
    cand2 = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand1 += 1
        elif x % k == k // 2:
            cand2 += 1
    
    number_of_possibles = 0
    number_of_possibles = 0
    if cand1 >= 1:
        number_of_possibles += cand1
    if cand1 >= 2:
        number_of_possibles += nCr(cand1, 2) * nCr(2, 1) * 3
    if cand1 >= 3:
        number_of_possibles += nCr(cand1, 3) * math.factorial(3)

    if cand2 >= 1:
        number_of_possibles += cand2
    if cand2 >= 2:
        number_of_possibles += nCr(cand2, 2) * nCr(2, 1) * 3
    if cand2 >= 3:
        number_of_possibles += nCr(cand2, 3) * math.factorial(3)

    return number_of_possibles


def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    if k % 2 == 0:
        ans = evenCaseK(n, k)
    else:
        ans = oddCaseK(n, k)
    
    print(ans)



if __name__ == "__main__":
    main()





Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int ans = 0;
long long n;
void dfs(long long x,bool a, bool b, bool c){
    if(x > n) return;
    if(a && b && c) ans ++;
    dfs(10*x + 3,true,b,c);
    dfs(10*x + 5,a,true,c);
    dfs(10*x + 7,a,b,true);

}

int main(){
    cin >> n;
    dfs(0,false,false,false);
    cout << ans << endl;

}

Measured memory_bytes: 3600