akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.1415926535
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 3e6;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    int dp[12][10];
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < 10; ++i)
        dp[0][i] = 1;
    for (int l = 1; l < 12; ++l)
    {
        for (int c = 0; c < 10; ++c)
        {
            for (int pr = max(0ll, c - 1); pr <= min(9ll, c + 1); ++pr)
                dp[l][c] += dp[l - 1][pr];
        }
    }
    int k;
    cin >> k, --k;
    int len = 0;
    for (; len < 12; ++len)
    {
        int sum = 0;
        for (int i = 1; i < 10; ++i)
        {
            sum += dp[len][i];
        }
        if (k < sum)
            break;
        k -= sum;
    }
    int dec = 0, pre = -1;
    while (len >= 0)
    {
        for (int i = pre == -1 ? 1 : max(0ll, pre - 1); i < pre == -1 ? 10 : min(10ll, pre + 2); ++i)
        {
            if (dp[len][i] > k)
            {
                pre = i;
                cout << i;
                break;
            }
            k -= dp[len][i];
        }
        --len;
        dec = 1;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int QBs;
	int i,n;
	
	QBs = 100000;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		QBs = QBs *1.05;
		if(QBs % 1000 != 0){
			QBs = QBs - QBs%1000;
			QBs = QBs + 1000;
		}
	}
	printf("%d\n",QBs);
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	//cin >> a >> b;
	scanf("%*d%d%d", &a, &b);
	if ((b - a - 1) & 1)
	{
		cout << "Alice";
	}
	else
	{
		cout << "Borys";
	}
	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 S[] = sc.next().split("");
    List<String> list = Arrays.asList(S);
    
    String[] alphabets = { "a", "b", "c", "d", "e", 
                          "f", "g", "h", "i", "j", 
                          "k", "l", "m", "n", "o", "p",
                          "q", "r", "s", "t", "u", 
                          "v", "w", "x", "y", "z"};
    String ans = "None";
    for(String s : alphabets) {
      if (list.indexOf(s) == -1) {//if not appeared
        ans = s;
        break;
      }
    }
    System.out.println(ans);
  }
}
    
    

Measured memory_bytes: 46140
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair <int,int> P;

int main(){
  int n,d,m;
  while(cin>>n>>d>>m){
    vector <P> S[110];

    for(int i=0,k;i<n;i++){
      cin>>k;
      S[i].resize(k);
      for(int j=0;j<k;j++)cin>>S[i][j].f>>S[i][j].s;
    }
    
    int dp[1000]={};
    for(int i=0,I;i<d;i++){
      cin>>I;
      for(int j=0;j<S[I].size();j++)
	for(int k=m;k>=0;k--){
	  if(k-S[I][j].s<0)break;
	  dp[k]=max(dp[k-S[I][j].s]+S[I][j].f,dp[k]);
	}
    }

    int cost=0,ans=0;
    for(int j=0;j<=m;j++)if(ans<dp[j])ans=dp[j],cost=j;
    cout <<ans<<" "<<cost<<endl;
  }
  return 0;
}

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

int main() {
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        int sum=500*a+100*b+50*c;
        if(sum==X){
          ans++;
        }
      }
    }
  }
 cout<<ans<<endl;
}


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

int main(){
	long long a, b, c, d, ans, bc, ad, bd,ac;
	cin >> a >> b >> c >> d;
	bc = b * c;
	ac = a * c;
	ad = a * d;
	bd = b * d;
	ans = bc;
	if (ac > ans) {
		ans = ac;
	}
	if (ad > ans) {
		ans = ad;
	}
	if (bd > ans) {
		ans = bd;
	}
	cout << ans;
	return 0;

}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
  int a,b,max;
  scanf("%d %d",&a,&b);
  int add=a+b;
  int sub=a-b;
  int mul=a*b;
  if(add>sub){
    max=add;
  }else{
    max=sub;
  }
  if(max<mul){
    max=mul;
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int s[6];
int c[6];
int main(void) {
    int n, m;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; i++) {
        scanf("%d %d", &s[i], &c[i]);
    }

    int ans[3] = {-1, -1, -1};
    for (int i = 0; i < m; i++) {
        if (ans[s[i]-1] == -1) {
            ans[s[i]-1] = c[i];
        } else if (ans[s[i]-1] == c[i]) {
            // 
        } else {
            printf("-1");
            return 0;
        }
    }
    if ((n == 2 && ans[0] == 0) || (n == 3 && ans[0] == 0)) {
        printf("-1");
        return 0;
    }
    int ansi = 0;
    for (int i = 0; i < n; i++) {
        int k;
        if (n > 1 && i == 0 && ans[i] == -1) {
            k = 1;
        } else if (n > 1 && i == 1 && ans[0] == -1 && ans[i] == -1) {
            k = 0;
        } else if (ans[i] == -1) {
            k = 0;
        } else {
            k = ans[i];
        }
        ansi *= 10;
        ansi += k;
    }
    printf("%d", ansi);
    return 0;
}

Measured memory_bytes: 128
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

S = input()
N = len(S)

h = 2019
dp = [0]*h

ans = 0
for i in range(1, N+1):
    nextDp = [0]*h
    now = int(S[i-1])

    nextDp[now] += 1
    for k in range(h):
        n = (k * 10 + now) % h
        nextDp[n] += dp[k]

    ans += nextDp[0]
    dp = nextDp

print(ans)


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

const int N = 2005;
const int mod = 1e9 + 7;

int dp[N][N], sum[N][N];
int s[N], t[N];

int main(){
	int n, m;
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n; i++) scanf("%d",&s[i]);
	for (int i = 1; i <= m; i++) scanf("%d",&t[i]);
	dp[0][0] = sum[0][0] = 1;
	for (int i = 1; i <= n; i++) sum[i][0] = 1;
	for (int i = 1; i <= m; i++) sum[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (s[i] == t[j]) dp[i][j] = sum[i - 1][j - 1];
			sum[i][j] = (sum[i - 1][j] + sum[i][j - 1]) % mod;
			sum[i][j] = (sum[i][j] - sum[i - 1][j - 1] + mod) % mod;
			sum[i][j] = (sum[i][j] + dp[i][j]) % mod;
		}
	}
	printf("%d\n", sum[n][m]);
	return 0;
} 

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    bool is_res = true;
    if(s[0] != 'A')is_res = false;
    bool is_c = false;
    for(int i=2;i<s.size()-1;i++){
        if(s[i] == 'C'){
            if(is_c)is_res = false;
            is_c = true;
        }
    }
    if(is_c == false)is_res = false;
    vector<char> c(s.size());
    rep(i,s.size())c[i]=s[i];
    sort(all(c));
    //printf("%d %d",c[1],c[2]);
    if(c[2]-'0'<='Z'-'0')is_res = false;
    cout << (is_res?"AC":"WA") << endl;
}


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

class Combination {
  public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 800000;
  class LookupTable {
    public:
    long long factorial_[n_];
    long long inverse_[n_];
    long long finverse_[n_];
  };
  LookupTable lt{};
  constexpr long long Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) % mod_;
  }
  private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};

Combination C;

int main() {
  int X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << "\n";
    return 0;
  }

  int n = (X + Y) / 3;
  long long ans = C.Get(n, X - n);

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vi cnt(n,0);
    rep(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C'){
            cnt[i]=cnt[i-1]+1;
        }
        else{
            cnt[i]=cnt[i-1];
        }
    }
    rep(i,0,q){
        ll l,r;
        cin>>l>>r;
        l--; r--;
        ll res=cnt[r]-cnt[l];
        cout<<res<<endl;
    }
    return 0;
}




Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        int a; cin>>a;
        a--;
        v[a] = i;
    }

    for(int i=0; i<n; i++){
        cout << v[i]+1 << " \n"[i == n-1];
    }

    return 0;
}

Measured memory_bytes: 1280
def main():
    n = int(input())
    h = list(map(int,input().split()))
    dp = [0] * n
    dp[1] = abs(h[0]-h[1])
    for i in range(2, n):
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
    print(dp[n-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 13980
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "101" => "2",
    "000" => "0",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: String
    }

    let ans = s.chars().filter(|&c| c == '1').count();
    ans.to_string()
}


Measured memory_bytes: 4352
n ,l = map(int, input().split())
apple = []
for i in range(n):
    apple.append(l + i)

min_num = 10 ** 5
sum_num = sum(apple)
ans = 0
for i in range(n):
    tmp = abs(sum_num - (sum_num - apple[i]))
    if tmp < min_num:
        min_num = min(tmp, min_num)
        flag = apple[i]
        ans = sum_num - apple[i]

print(ans)

Measured memory_bytes: 9192
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;

template <class T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;

const int N = (int)(1e6 + 5);
const int M = (int)(1e9 + 7);
const int INF = (int)(1e18 + 9);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int t[N];
int sc[N];

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  for (int i = 1; i <= q; ++i) {
    int x;
    cin >> x;
    ++sc[1];
    sc[x]--;
    sc[x + 1]++;
  }
  for (int i = 1; i <= n; ++i)
    sc[i] += sc[i - 1];
  for (int i = 1; i <= n; ++i) {
    if (k - sc[i] <= 0)
      cout << "No\n";
    else
      cout << "Yes\n";
  }
  return 0;
}


Measured memory_bytes: 1408
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  h,w,i,j,count,x,y,m,n,c,a,b,min,r,g:Integer;
  s:array of integer;
  s1,s2,s3:string;
  sw:char;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(r);
    Read(g);
    Readln(b);

    if StrToInt(IntToStr(r)+IntToStr(g)+IntToStr(b)) mod 4 = 0 then
      Writeln('YES')
    else
      Writeln('NO');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

int main(){
  string S;
  cin >> S;
  
  if(S == "MON"){
    cout << "6" << endl;
  }
  if(S == "TUE"){
    cout << "5" << endl;
  }
  if(S == "WED"){
    cout << "4" << endl;
  }
  if(S == "THU"){
    cout << "3" << endl;
  }
  if(S == "FRI"){
    cout << "2" << endl;
  }
  if(S == "SAT"){
    cout << "1" << endl;
  }
  if(S == "SUN"){
    cout << "7" << endl;
  }
}

Measured memory_bytes: 256
l=[]
x=list(input())
for i in x:
  if i=='S':
    l.append(i)
  elif len(l)>0:
    a=l.pop()
    if a=='S':
      pass
    else:
      l.append('T')
      l.append('T')
  else:
    l.append(i)
print(len(l))

Measured memory_bytes: 6436
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    int c=0;
    while(i<n && j>=0 && i<j){
        while (i<n && s[i]=='R')    i++;
        while (j>=0 && s[j]=='W')   j--;
        if (i<n && j>=0 && i<j){
            swap(s[i],s[j]);
            c++;
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3744
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var a=new int[3][];
		for(int i = 0;i<3;i++) {
			a[i]=sc.Ia;
		}
		int n=sc.I;
		for(int i = 0;i<n;i++) {
			var e=sc.I;
			for(int j = 0;j<3;j++) {
				for(int k = 0;k<3;k++) {
					if(a[j][k]==e){
						a[j][k]=-1;
					}
				}
			}
		}
		var ans="No";
		for(int i = 0;i<3;i++) {
			if(a[i].Sum()==-3){ans="Yes";}
			if(a[0][i]+a[1][i]+a[2][i]==-3){ans="Yes";}
		}
		if(a[0][0]+a[1][1]+a[2][2]==-3){ans="Yes";}
		if(a[2][0]+a[1][1]+a[0][2]==-3){ans="Yes";}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13396
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int SZ = 200000;
class UF {
public:
	int P[SZ + 1], saidai;
	UF() : P(), saidai() {
		saidai = -1;
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		if (P[a] < saidai) saidai = P[a];
		P[b] = a;
		return true;
	}
} uf;

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

	int N = getint(), M = getint();

	rep(i, M) {
		uf.unite(getint(), getint());
	}

	printf("%d\n", -uf.saidai);


	Would you please return 0;
}

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

int64_t MOD = 1000000000 + 7;

int64_t f1(int x) {
  if(x == 0) {
    return 1;
  }
  else {
    int64_t ans = f1(x / 2) * f1(x / 2);
    ans %= MOD;
    if(x % 2 == 1) {
      ans *= 3;
      ans %= MOD;
    }
    return ans;
  }
}

int64_t f2(int x) {
  if(x == 0) {
    return 1;
  }
  else {
    int64_t ans = f2(x / 2) * f2(x / 2);
    ans %= MOD;
    if(x % 2 == 1) {
      ans *= 2;
      ans %= MOD;
    }
    return ans;
  }
}
  
    
int main() {
  string L;
  cin >> L;
  int64_t ans = 0;
  int64_t keep = 1;
  for(int i = 0; i < L.size() - 1; i++) {
    if(i == 0) {
      ans += 1;
      keep *= 3;
    }
    else {
      ans += keep;
      ans %= MOD;
      keep *= 3;
      keep %= MOD;
    }
  }
  int count = 0;
  for(int i = 1; i < L.size(); i++) {
    if(L.at(i) == '1') {
      ans += (f1(L.size() - i - 1) * f2(count)) % MOD;
      ans %= MOD;
      count += 1;
    }
  }
  ans += f2(count);
  ans %= MOD;
  ans *= 2;
  ans %= MOD;
  ans += 1;
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  int A = 0;
  
    for(int i = 0; i < N; i++) {
      char S;
      cin >> S;
      
      bool a = S == 'Y';
      
      if(a) {
        A += 4;
        break;
      }
    }
  if(A == 4) {
  cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    x = [(i, _x) for i, _x in enumerate(x)]
    x = sorted(x, key=lambda x: x[1])
    ans = [(_x[0], x[mid][1]) if i < mid else (_x[0], x[mid - 1][1]) for i, _x in enumerate(x)]
    ans = sorted(ans, key=lambda x: x[0])
    return "\n".join([str(_x) for i, _x in ans])


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 64832
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, a[109];
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N, greater<int>());
	int ret = 0;
	for (int i = 0; i < N; i++) ret += a[i] * (i & 1 ? -1 : 1);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   string s[3];
           rep(i,0,3)cin>>s[i];
           rep(i,0,3)cout<<s[i][0];
           cout<<endl;
}

Measured memory_bytes: 3620
//  Copyright 2019 Nikita Golikov

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  std::vector<std::vector<int>> s(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    s[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  std::vector<int> p(m);
  for (int& x : p) {
    cin >> x;
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    bool ok = true;
    for (int i = 0; i < m; i++) {
      int res = 0;
      for (int x : s[i]) {
        res ^= (mask >> x) & 1;
      }
      ok &= res == p[i];
    }
    ans += ok;
  }
  cout << ans << "\n";
  return 0;
}


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

vector<ll> f(ll cnt_r, ll cnt_l) {
	vector<ll> a;
	rep(i, cnt_r-1) {
		a.push_back(0);
	} 
	a.push_back((cnt_r + 1) / 2 + cnt_l / 2);
	a.push_back(cnt_r / 2 + (cnt_l + 1) / 2);
	rep(i, cnt_l-1) {
		a.push_back(0);
	}
	return a;
}

int main() {
	string s;
	cin >> s;
	ll n = s.length();
	bool l_start = false;
	bool l_end = false;
	ll cnt_r = 0;
	ll cnt_l = 0;
	ll cnt_idx = 0;
	vector<ll> ans;
	rep(i,n) {
		if (s[i] == 'R') {
			if (i > 0 && s[i-1] == 'L') {
				vector<ll> a = f(cnt_r, cnt_l);
				rep(j,cnt_r+cnt_l) {
					ans.push_back(a[j]);
				}
				cnt_r = 1;
				cnt_l = 0;
			}
			else {
				cnt_r++;
			}
		}
		else {
				cnt_l++;
		}
		//cout << cnt_r << " " << cnt_l << endl;
	}
	vector<ll> a = f(cnt_r, cnt_l);
	rep(j,cnt_r+cnt_l) {
		ans.push_back(a[j]);
	}
	rep(i,n) {
		cout << ans[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 2676
#include<iostream>
#include<cmath>
using namespace std;
 
int main(){
  int k;
  cin>>k;
  long long int ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
          int n=min(j,l);
          int max=1;
        for(int m=1;m<=min(i,n);m++){
          if(i%m==0&&(j%m==0&&l%m==0)){
            if(m>max){max=m;}
          }
          
        }
        ans=ans+max;
      }
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
void solve(){
    int N; cin>>N;
    int res=0;
    for(int i=1;i<=N;i++){
        int digits=0;
        int temp = i;
        while(temp){
            temp/=10;
            digits++;
        }
        if(digits & 1) res++;
    }

    cout << res;



}


int main(){
   solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <ctime>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <unordered_map>

#define INF 0x3f3f3f3f
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=0;i--)
#define rep2(i, n) for(ll i=1;i<=n;i++)
#define pb(x) push_back(x)
#define clint(x, n) memset(x,n,sizeof(x))
#define mp make_pair
#define fi first
#define se second
#define IO std::ios::sync_with_stdio(false)
#define ull unsigned long long
#define ud long double
#define pii pair<int,int>
using namespace std;
const int maxn = 1e6 + 5;
const ll inf = 100000000;
const int mod = 998244353;
const int MAX = 123123;
const int N = 1005;

inline int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

ll max(ll a, ll b) {
    if (a > b) return a;
    return b;
}

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

int a[40], b[40], c[40];
ll dp[40 + 1][400 + 1][400 + 1];

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    rep(i,n) cin >> a[i] >> b[i] >> c[i];
    rep(i,41) rep(j,401) rep(k,401) dp[i][j][k]=inf;
    dp[0][0][0] = 0;
    for (int i = 0; i < n; ++i)
        for (int ca = 0; ca < 400 + 1; ++ca)
            for (int cb = 0; cb < 400 + 1; ++cb) {
                if (dp[i][ca][cb] == inf) continue;
                dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
            }
    int ans = inf;
    for (int ca = 1; ca < 401; ++ca) {
        for (int cb = 1; cb < 401; ++cb) {
            if (ca * mb == cb * ma) ans = min(ans, dp[n][ca][cb]);
        }
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

char s[101][101];
int need[10];

void calc(int n, int m) {
	if (n > m) swap(n, m);
	if (n == 0) return;
	if (n == 1) {
		need[2] += m / 2, need[1] += m & 1;
		return;
	}
	need[4] += n / 2;
	if (n & 1) need[2]++;
	need[4] += (m - 2) / 2;
	if (m & 1) need[2]++;
	calc(n - 2, m - 2);
	return;
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, m; cin >> n >> m;
	REPU(i, 0, n) cin >> s[i];
	vector<int> cnt(26, 0);
	REPU(i, 0, n) REPU(j, 0, m) {
		cnt[s[i][j] - 'a']++;
	}
	calc(n, m);
	int tot = 0;
	REPU(i, 0, 26) {
		tot += cnt[i] / 4;
		cnt[i] &= 3;
	}
	bool ok(true);
	if (tot >= need[4]) tot -= need[4], tot *= 2;
	else ok = false;
	REPU(i, 0, 26) {
		tot += cnt[i] / 2;
	}
	if (tot < need[2]) ok = false;
	puts(ok ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

long long int f(long long int x, vector<long long int> a); //x未満のものを数える

int main(){
    int n;
    long long int k;
    cin >> n >> k;
    vector<long long int> a(n);
    for (int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    long long int left = -1e18, right = 1e18;
    while (left+1 < right){
        long long int x = (left+right) / 2;
        if(f(x,a) >= k) right = x;
        else left = x;
    }
    cout << left;

    return 0;
}

long long int f(long long int x, vector<long long int> a){
    long long int total = 0;
    int n = a.size();
    for (int i=0;i<n;i++){
        if (a[i] >= 0){
            int l = -1, r = n;
            while(l+1<r){
                int c = (l+r)/2;
                if (a[c]*a[i] < x) l = c;
                else r = c;
            }
            total += r;
        } else {
            int l = -1, r = n;
            while(l+1<r){
                int c = (l+r)/2;
                if (a[c]*a[i] < x) r = c;
                else l = c;
            }
            total += n-r;
        }
        
        
    }
    for (int i=0;i<n;i++){
            if (a[i]*a[i] < x) total--;
        } 
    total = total / 2;
    return total;
}

//Sum accumulate(v.begin(),v.end(),0);
//Sort sort(v.begin(),v.end())
//Power pow(base, e)
//Min min = *std::min_element(vec.begin(), vec.end());
//Max max = *std::max_element(vec.begin(), vec.end());


Measured memory_bytes: 3428
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
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")
}
 
 
//main function
fn main() {
    let n:usize = read();
    let m:i32 = read();
    let mut a: Vec<i32> = Vec::with_capacity(n);
    unsafe{
	a.set_len(n);
    }
    let mut sum:i32 = 0;
    for i in 0..n{
	let number:i32 = read();
	a[i] = number;
	sum+=number;
    }
    let mut count:i32 = 0;
    let mut kei:i32 = sum/(4*m);
    if sum%(4*m)!=0 {
	kei+=1;
    }
    for i in 0..n{
	if a[i] >= kei {
	    count+=1;
	}
    }
    if count >= m{
	println!("Yes");
    }else{
	println!("No");
    }
}


Measured memory_bytes: 4352
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

int N, M;
int g[51][51] = { 0 };
int e[51][2] = { 0 };
int skip;
char visited[51] = { 0 };

void dfs(int pos) {
	for (int j = 0; j < N; j++) {
		if (g[pos][j]) {
			if (e[skip][0] == pos && e[skip][1] == j || e[skip][0] == j && e[skip][1] == pos ) continue;
			if (!visited[j]) {
				visited[j] = 1;
				dfs(j);
			}
		}
	}
}

signed main() {
	cin >> N >> M;


	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		g[a - 1][b - 1]++;
		g[b - 1][a - 1]++;
		e[i][0] = a - 1;
		e[i][1] = b - 1;
	}
	int ans = 0;
	for (int n = 0; n < M; n++) {
		int t = 0;
		skip = n;
		visited[0] = 1;
		dfs(0);
		for (int i = 0; i < N; i++) {
			if (!visited[i]) t = 1;
			else visited[i] = 0;
		}
		ans += t;
	}

	cout << ans NL;

	return 0;

}



Measured memory_bytes: 256
object Main {
    def main(args: Array[String]) {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val m = sc.nextInt
        var arr = new Array[Int](m)
        var arr2 = new Array[Int](m - 1)
        for (i <- 0 to m - 1) {
            val k = sc.nextInt
            arr(i) = k
        }
        arr = arr.sorted

        for (i <- 1 to m - 1) {
            arr2(i - 1) = abs(arr(i) - arr(i - 1))
        }

        arr2 = arr2.sorted

        val k = m - n
        var ans = 0
        for (i <- 0 to k - 1) {
            ans += arr2(i)
        }

        println(ans)
    }

    def printArray(arr: Array[Int]) {
        for (i <- 0 to arr.length - 1) {
            println(arr(i))
        }
    }

    def swap(arr: Array[Int], i: Int, j: Int) {
        val tmp = arr(i)
        arr(i) = arr(j)
        arr(j) = tmp
    }

    def abs(a: Int): Int = if (a > 0) a else -a

    def sort(arr: Array[Int]) {
        for (i <- 0 to arr.length - 1) {
            var min = i
            for (j <- i to arr.length - 1) {
                if (arr(j) < arr(min)) {
                    min = j
                }
            }
            swap(arr, i, min)
        }
    }
}

Measured memory_bytes: 55116
#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int, int>
#define fst first
#define snd second
#define pub push_back
#define vi vector<int>
#define ll long long

using namespace std;

const ll md = 998244353;

ll n, s, ar[3001] = {}, dp[3001][3001] = {};

inline ll pw(ll b, ll e)
{
	ll t = 1;
	while (e)
	{
		if (e & 1) {t *= b; t %= md;}
		b *= b; b %= md; e >>= 1;
	}
	return t;
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	for (int i = 0; i < n; i++) {cin >> ar[i];}
	ll inv2 = pw(2, md - 2);
	dp[0][0] = pw(2, n);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= s; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if (j >= ar[i - 1])
			{
				dp[i][j] += (inv2 * dp[i - 1][j - ar[i - 1]]) % md;
				dp[i][j] %= md;
			}
		}
	}
	cout << dp[n][s] << "\n";
	return 0;
}

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


int main() {
  int A,B;
  
  cin>>A>>B;
  
  if(A==1){
    if(B==2){
      cout<<3<<endl;
    }else{
      cout<<2<<endl;
    }
  }else if(A==2){
    if(B==1){
      cout<<3<<endl;
    }else{
      cout<<1<<endl;
    }
  }else{
    if(B==1){
      cout<<2<<endl;
    }else{
      cout<<1<<endl;
    }
  }
  
  
}





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

#define precise(n,k) fixed<<setprecision(k)<<n

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n ;
    

    cin >> n;

    if(n <= 999) {
        cout << "ABC"<<endl;
    } else {
        cout << "ABD" << endl;
    }
   
 
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long n = stdIn.nextLong();
		
		long max = 1;
		
		for(long i = 1; i*i <= n; i++) {
			if(n % i == 0) {
				max = i;
			}
			
		}
		
		long katahou = n / max;
		
		long ans = max + katahou - 2;
		
		System.out.println(ans);
		
		
		
	}

}


Measured memory_bytes: 23892
import numpy as np

N = int(input())
H = [ int(s) for s in str(input()).split()]
dp = np.full(10**5 + 10, np.inf)

def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = min(res, rec(i-1) + abs(H[i] -H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    
    dp[i] = res
    return res

def main3():
    print(int(rec(N-1)))

def main2():
    dp = np.full(10**5 + 10, np.inf)
    dp[0] = 0
    
    for i in range(0, N):
        if i+1 < N:
            dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1]))
        if i+2 < N:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2]))
    
    print(int(dp[N-1]))
    
if __name__ == '__main__':
    main2()

Measured memory_bytes: 38568
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <iterator>
#include <algorithm>
#define RANGELOOP(begin,end) for(int i=begin; i<end; i++)
#define LOOP(end) for(int i=0; i<end; i++)

int main() {
    char b;
    std::cin >> b;
    if (b == 'A')
        std::cout << 'T';
    else if (b == 'T')
        std::cout << 'A';
    else if (b == 'C')
        std::cout << 'G';
    else if (b == 'G')
        std::cout << 'C';
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	if(n >= k) n %= k;
	if(n > abs(n-k)) n = abs(n-k);
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)



const int MAX_V = 1e5;
const int INF   = 1e9;

struct edge{
    int to, cost;
};

int V; // ノード数の指定が必要
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();


        int v = p.second;
        if(d[v] < p.first) continue;

        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}



int main(){

    int h, w; cin >> h >> w;

    string mat[h];
    rep(i, h){
        cin >> mat[i];
    }

    int cntwhite = 0;
    rep(i, h){
        rep(j, w){
            if(mat[i][j] == '.'){
                cntwhite++;
            }
        }
    }

    queue<P> que;
    que.push({0, 0});

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

    rep(i, h){
        rep(j, w){
            if(mat[i][j] == '#') continue;

            rep(dir, 4){
                int inext = i + dx[dir];
                int jnext = j + dy[dir];

                if(inext < 0 || inext >= h) continue;
                if(jnext < 0 || jnext >= w) continue;
                if(mat[inext][jnext] == '#') continue;
            
                G[i*w + j].push_back({inext*w + jnext, 1});
            }
        }
    }

    // rep(i, h*w){
    //     rep(v, G[i].size()){
    //         cout << i << " " << G[i][v].to << " " << G[i][v].cost << endl;
    //     }
    // }

    V = h*w + 1;
    dijkstra(0);

    // rep(i, h*w){
    //     if(d[i] >= 0 && d[i] < 10){
    //         cout << 0;
    //     }
    //     cout << (d[i] == 1e9 ? -1 : d[i]) << " ";
    //     if((i+1) % w == 0){
    //         cout << endl;
    //     }
    // }

    if(d[h*w-1] == INF){
        cout << -1;
    }
    else{

    cout << cntwhite - d[h*w-1] - 1;
    }

    return 0;
}

Measured memory_bytes: 2688
from math import ceil
from fractions import Fraction
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
tka, aok = 1, 1

for ta in TA:
    t, a = ta
    time = int(ceil(max((Fraction(tka, t), Fraction(aok, a)))))
    tka, aok = time * t, time * a
print(tka+aok)


Measured memory_bytes: 5344
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

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;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string N;
  int K;
  cin >> N >> K;
  static ll dp[110][2][110];
  int L = N.size();
  dp[0][0][0] = 1;
  for (int i = 0; i < L; i++)
  {
    const int di = N[i] - '0';
    for (int j = 0; j < 2; j++)
    {
      for (int k = 0; k < 110; k++)
      {
        for (int d = 0; d <= (j ? 9 : di); d++)
        {
          if (d == 0)
            dp[i + 1][j || (d < di)][k] += dp[i][j][k];
          else
            dp[i + 1][j || (d < di)][k + 1] += dp[i][j][k];
        }
      }
    }
  }
  cout << dp[L][1][K] + dp[L][0][K] << endl;
  return 0;
}

// 桁DP 0でない数字を何個持つかを保持する
// dp[決定した桁数][N未満確定か][0以外の数字が出た数] := i桁決めた時に0でない数がj個である．


Measured memory_bytes: 384
import itertools
import numpy as np
import math

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

if p == q:
  print(0)
  exit()

lis = [x+1 for x in range(n)]

p_list = itertools.permutations(lis)

a, b = 0, 0
f_a, f_b = False, False
i = 0

for one_case in p_list:
  if list(one_case) == p:
    a = i
    i += 1
    f_a = True
  elif list(one_case) == q:
    b = i
    i += 1
    f_b = True
  else:
    i += 1
  if f_a and f_b:
    break
print(abs(a-b))

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

int main (){

  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a == b || b == c || c == d){
     cout << "Bad" << endl;
  }
  else {
     cout << "Good" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        x: i64,
        n: usize,
        ps: [i64; n],
    }
    let mut diff_min = std::i64::MAX;
    let mut ans = -1;
    for i in x - 200..x + 200 {
        if ps.iter().find(|p| **p == i).is_none() {
            if diff_min > (x - i).abs() {
                diff_min = (x - i).abs();
                ans = i;
            }
        }
    }
    println!("{}", ans);
}


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

long long func(long long X){
  return log10(X)+1;
}
    
int main() {
  long long min_F=100000000;
  long long N;
  cin >> N;
  double C=sqrt(N);
  for(int i=1;i<=C;i++){
    if(N%i!=0){
      continue;
    }
    long long A=max((long long)i,N/i);
    long long F=func(A);
    min_F=min(min_F,F);
  }
  cout << min_F << endl;
} 

Measured memory_bytes: 512