akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e12;
int KnapSack_ByValues(vector< pair< int,int > > &item, int n,int w)
{
    ll sum = 0;
    for(int i=1;i<=n;i++) sum += item[i].first;
    vector< vector< ll > > DP(sum+1,vector< ll > (n+1,INF));
    for(int i=0;i<=n;i++)DP[0][i] = 0;
    for(int i=1;i<=sum;i++){    //for each i-th value the best answer lies in the n-th column.
        for(int j = 1;j<=n;j++){
            if(i < item[j].first){
                DP[i][j] = min(DP[i][j-1],(ll)item[j].second);
            }
            else{
                DP[i][j] = min(DP[i-item[j].first][j-1]+ (ll)item[j].second,DP[i][j-1]);//choosing or not choosing j-th item. if not chosen then till now the best answer is at (i,j-1).
            }
        }
    }
    int ans;
    for(int i=1;i<=sum;i++){
        if(DP[i][n] <= (ll)w) ans = i;
    }
    return ans;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,w;
    cin >> n >> w;
    vector<  pair< int,int > > item(n+1);
    for(int i=1;i<=n;i++){
        cin >> item[i].second >> item[i].first;
    }
    int ans = KnapSack_ByValues(item,n,w);
    cout << ans << endl;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll n, k, a[100000], b[100000];
	vector< pair<ll, ll> > vec;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		vec.pb(make_pair(a[i], b[i]));
	}
	sort(ALL(vec));
	ll elem = 0;
	for (int i = 0; i < n; i++) {
		elem += vec[i].second;
		if(elem >= k){
			cout << vec[i].first << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      
      long c = a * b;
      
      if((c % 2) == 0){
          System.out.println("Even");
      }else if((c % 2) != 0){
          System.out.println("Odd");
      }
    }
}


Measured memory_bytes: 26964
fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let s: String = std::io::Read::bytes(stdin.lock())
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().expect("error")
}

fn main() {
    let n: u32 = input();
    let i: u32 = input();
    println!("{}", n - i + 1);
}

Measured memory_bytes: 4352
N = int(input())
K = int(input())

keta = len(str(N))
dp = [[[0] * 2 for _ in range(4)] for _ in range(keta+1)]

dp[0][0][0] = 1
dp[0][1][0] = 0
dp[0][2][0] = 0
dp[0][3][0] = 0
dp[0][0][1] = 0
dp[0][1][1] = 0
dp[0][2][1] = 0
dp[0][3][1] = 0

for i in range(1, keta+1):
    n = int(str(N)[i-1])
    if n == 0:
        # 桁，0でない数字の数，未満フラグ
        dp[i][0][0] = dp[i-1][0][0]
        dp[i][1][0] = dp[i-1][1][0]
        dp[i][2][0] = dp[i-1][2][0]
        dp[i][3][0] = dp[i-1][3][0]
        
        dp[i][0][1] = dp[i-1][0][1]
        dp[i][1][1] = dp[i-1][1][1] + dp[i-1][0][1]*9
        dp[i][2][1] = dp[i-1][2][1] + dp[i-1][1][1]*9
        dp[i][3][1] = dp[i-1][3][1] + dp[i-1][2][1]*9
    elif n != 0:
        dp[i][0][0] = 0
        dp[i][1][0] = dp[i-1][0][0]
        dp[i][2][0] = dp[i-1][1][0]
        dp[i][3][0] = dp[i-1][2][0]
        
        dp[i][0][1] = dp[i-1][0][0] + dp[i-1][0][1]
        dp[i][1][1] = (dp[i-1][1][0]+dp[i-1][1][1]) \
                     + dp[i-1][0][0]*(n-1) + dp[i-1][0][1]*9
        dp[i][2][1] = (dp[i-1][2][0]+dp[i-1][2][1]) \
                     + dp[i-1][1][0]*(n-1) + dp[i-1][1][1]*9
        dp[i][3][1] = (dp[i-1][3][0]+dp[i-1][3][1]) \
                     + dp[i-1][2][0]*(n-1) + dp[i-1][2][1]*9
print(sum(dp[keta][K]))

Measured memory_bytes: 9340
#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 N;
    cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

string s, t, u;
int a, b;

int main(){


    cin >> s >> t >> a >> b >> u;

    if(u == s){
        a = a - 1;
    } else if(u == t){
        b = b - 1;
    }

    cout << a << " " << b;





}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

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

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

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

    sort(b.begin(),b.end());

    for(int i=0; i<n; i++){
        if(b[n-1] == a[i]){
            cout << b[n-2] << endl;
        }else{
            cout << b[n-1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
ll ans[100050];
using namespace std;
int main()
{
    ll n, k, a, b;
    //vector<int> ans;
    sl(n);
    sl(k);
    while(n--){
        cin >> a >> b;
        ans[a] += b;
    }
    int i = 1;
    while(k > 0){
        k -= ans[i];
        ++i;
    }
    cout << i-1 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int parent(int x){return x/2;}
int leftchild(int x){return 2*x;}
int rightchild(int x){return 2*x + 1;}
int main()
{
	int h,a[300];
	cin>>h;
	for(int i=1;i<=h;++i)cin>>a[i];
	for(int i=1;i<=h;++i){
		cout<<"node "<<i<<": key = "<<a[i]<<", ";
		if(parent(i) >= 1)cout<<"parent key = "<<a[parent(i)]<<", ";
		if(leftchild(i) <= h)cout<<"left key = "<<a[leftchild(i)]<<", ";
		if(rightchild(i) <= h)cout<<"right key = "<<a[rightchild(i)]<<", ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
import math
import sys
sys.setrecursionlimit(10000000)
Q = int(input())
l_r = [list(map(int, input().split())) for _ in range(Q)]

prime = []
def isprime(n):
    if n in prime:
        return True
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    
    return True


def like(x):
    if isprime(x) and isprime((x+1)//2):
        return True
    
    return False

x_dict = {1:0}
def count_like(x):
    if x in x_dict:
        return x_dict[x]
    x_dict[x] = count_like(x-1) + like(x)
    return x_dict[x]

for i in range(Q):
    print(count_like(l_r[i][1]) - count_like(l_r[i][0]) + int(like(l_r[i][0])))


Measured memory_bytes: 116304
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,300000){
	bool flg = true;
	for(int j=0;j<primes.size()&&primes[j]*primes[j]<=i;j++){
	    if(i % primes[j] == 0){
		flg = false;
		break;
	    }
	}
	if(flg){
	    primes.PB(i);
	}
    }

    while(true){
	int n;
	cin >> n;
	if(n==0) break;
	int s = upper_bound(ALL(primes),n) - primes.begin();
	int t = upper_bound(ALL(primes),2*n) - primes.begin();
	cout << t-s << endl;
    }

    return 0;
}

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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int cnt_a, cnt_c;
  cnt_a = (c%b == 0) ? c/b : c/b+1;
  cnt_c = (a%d == 0) ? a/d : a/d+1;
  if(cnt_a <= cnt_c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a == b) System.out.println(c);
		if (b == c) System.out.println(a);
		if (a == c) System.out.println(b);

		sc.close();

	}

}


Measured memory_bytes: 35748
S = list(input())
C = list(set(S))

ans = float("inf")
for c in C:
    cnt_max, cnt = 0, 0
    for s in S:
        if s == c:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
        else:
            cnt += 1
    cnt_max = max(cnt_max, cnt)
    ans = min(ans, cnt_max)

print(ans)

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code


int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	map<LL,LL> mp;
	for (int i = 2; i <= n; i++) {
		int m = i;
		for (int j = 2; j <= m; j++) {
			if (m%j==0) {
				mp[j]++;
				m/=j;
				j--;
			}
		}
	}
	LL ans = 1;
	for (auto&& var : mp) {
		ans *= (var.second+1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int n;
    cin>>n;int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 3648
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n+1):
    c = 10**5
    t = 10**5
    y = 0
    if x + i not in p:
        c = x+i
        y += 1
    if x - i not in p:
        t = x-i
        y += 1
    if y:
        print(min(t,c))
        exit()

Measured memory_bytes: 9196
def selectionSort(A,N):
    c = 0
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if(i!=minj):
            t = A[i]
            A[i] = A[minj]
            A[minj] = t
            c+=1

    a = [str(i) for i in A]
    print(" ".join(a))
    print(c)

if __name__=="__main__":
    n = int(input())
    l = [int(x) for x in input().split()]
    selectionSort(l,n)


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

ans = [-1]*N

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] not in (-1, c):
        print(-1)
        exit()
    ans[s-1] = c

if ans[0] == -1:
    if N == 1:
        ans[0] = 0
    else:
        ans[0] = 1

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0

if N != 1 and ans[0] == 0:
    print(-1)
    exit()

print(*ans, sep='')


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>
#include <ios>
#include <iomanip>

#define INF 200000000
#define MOD 1000000007
//#define int long long int
#define ll long long int

using namespace std;

ll gcd(ll a,ll b )
{
    if(b == 0) return a;
    return gcd(b ,a%b);
}

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    //sort(a.begin(), a.end());
    //int tmp, ans = a[0];
    for (int i = 0; i<n-1; i++)
    {
        a[i+1] = gcd(a[i],a[i+1]);
    }
    cout << a[n-1] << endl;
    return 0;
}


Measured memory_bytes: 892
n = gets.chomp.to_i
first_arr = gets.chomp.split(' ').map(&:to_i)
second_arr = gets.chomp.split(' ').map(&:to_i)
a,b = [0,0]

arr = []

for i in 1..n do  
  arr << i
end

arr.permutation.to_a.each_with_index do |arr_item, index|
  a = index if arr_item == first_arr
  b = index if arr_item == second_arr
end

print (a-b).abs


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

const int M = 200005;

int main() {
    int N, W, H;
    cin >> N >> W >> H;
    vector<int> imos_x(M), imos_y(M);
    for(int i = 0; i < N; ++i) {
        int x, y, w;
        cin >> x >> y >> w;
        imos_x[max(0, x - w)]++, imos_x[x + w]--;
        imos_y[max(0, y - w)]++, imos_y[y + w]--;
    }
    for(int i = 0; i < M; ++i) imos_x[i + 1] += imos_x[i];
    for(int i = 0; i < M; ++i) imos_y[i + 1] += imos_y[i];
    bool ok_x = true, ok_y = true;
    for(int i = 0; i < W; ++i) if(!imos_x[i]) ok_x = false;
    for(int i = 0; i < H; ++i) if(!imos_y[i]) ok_y = false;
    cout << (ok_x || ok_y ? "Yes" : "No") << '\n';
    return 0;
}



Measured memory_bytes: 4416
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;


namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var W = cin.nextLong();
            var H = cin.nextLong();
            var x = cin.nextLong();
            var y = cin.nextLong();

            var ans = (W * H) / 2.0;
            var ans2 = "";
            if(x + x == W && y + y == H)
            {
                ans2 = "1";
            }
            else
            {
                ans2 = "0";
            }
            Console.WriteLine(ans + " " + ans2);
        }

        // 最小公倍数
        static long Lcm(long a, long b)
        {
            return a * (b / Gcd(a, b));
        }

        // 最大公約数
        static long Gcd(long a, long b)
        {
            if (a < b)
                return Gcd(b, a);
            long d = 0;
            do
            {
                d = a % b;
                a = b;
                b = d;
            } while (d != 0);
            return a;
        }
    }

    class Point
    {
        public int x { get; set; }
        public int y { get; set; }
    }


    class Scanner
    {
        string[] s;
        int i;

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

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

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

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

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

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

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


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

Measured memory_bytes: 11092
n,k=map(int,input().split())
ans=0
def f(x,y):return (x+y)*(y+1-x)//2
for i in range(k,n+2):
  ans+=f(n-i+1,n)+1-f(0,i-1)
  ans%=int(1e9+7)
print(ans)

Measured memory_bytes: 78992
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int n,m,i,j,a[105],sum;
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();m=read();
   	for(i=1;i<=m;i++){
   		a[i]=read();
   		if(a[i]&1)
   			sum++;
   	}
   	if(n==1){
   		pus(1,2);
   		pus(1,2);
   		pus(1,2);
   		return 0;
   	}
   	if(sum>=3){
   		printf("Impossible\n");
		return 0;
	}
	if(m==1){
		pus(a[1],2);
		pus(2,2);
		pus(1,1);
		pus(a[1]-1,2);
		return 0;
	}
	for(i=1;i<=m;i++)
		if(a[i]&1){
			if(a[1]&1)
				swap(a[i],a[m]);
			else
				swap(a[1],a[i]);
		}
	for(i=1;i<=m;i++)
		pus(a[i],1);
	cout<<endl;
	if(a[1]==1)
		n=2;
	else
		n=1;
	a[1]--;
	a[m]++;
	pus(m-n+1,2);
	for(i=n;i<=m;i++)
		pus(a[i],1);
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
s=input()
x,y=map(int,input().split())
s=s+'T'
dp=[[] for i in range(2)]
t=0
buf=0
for j in range(len(s)):
    if s[j]=='T':
        break

for i in range(j,len(s)):
    if s[i]=='F':
        buf+=1
    else:
        if buf!=0:
            dp[t].append(buf)
            buf=0
        t=1-t
#print(s)  
#print(dp)
xb=1<<(len(s)+j)
yb=1<<(len(s))

for i in range(len(dp[0])):
    xb=(xb<<dp[0][i])|(xb>>dp[0][i])
if xb & 1<<(len(s)+x)==0:
    print('No')
    sys.exit()
for i in range(len(dp[1])):
    yb=(yb<<dp[1][i])|(yb>>dp[1][i])

if yb & 1<<(len(s)+y)==0:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 39408
#include<stdio.h>

int selectionsort( int a[] , int n );

int main( void ){
	
	int n;
	scanf( "%d" , &n );
	
	int a[n];
	int i;
	int c;
	
	for( i = 0; i < n; i++ ){
		scanf( "%d" , &a[i] );
	}
	
	c = selectionsort( a , n );
	
	for( i = 0; i < n; i++ ){
		if( i > 0 ){ printf( " " ); } 
		printf( "%d" , a[i] );
	}
	
	printf( "\n" );
	printf( "%d\n" , c );
	
	return 0;
}

int selectionsort( int a[] , int n ){
	
	int temp;
	int i , j;
	int min;
	int c = 0;
	
	for( i = 0; i <= n - 1; i++ ){
		
		min = i;
		
		for( j = i; j <= n - 1; j++ ){
			
			if( a[j] < a[min] ){
				min = j;
			}
		}
			
		temp = a[i];
		a[i] = a[min];
		a[min] = temp;
		
		if( i != min ){ c++; }
	}
	return c;
}


Measured memory_bytes: 2140
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    if(N[0] == '7' || N[1] == '7' || N[2] == '7'){
        print("Yes");
    }else{
        print("No");
    }

}

Measured memory_bytes: 3652
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	A=[II() for _ in range(n)]

	#print(A)

	now=0
	cnt=1
	ans=-1
	for i in range(n+5):
		now=A[now]-1
		if now==1:
			ans=cnt
			break
		elif now==0:
			break
		else:
			cnt+=1
	print(ans)




if __name__ == "__main__":
	main()


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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn 100000+5

//structure

//declaration
int n, a, b;
int dis[2][maxn];
vector<int> g[maxn];
//functions

void dfs(int now, int fa, int t)
{
    dis[t][now] = dis[t][fa]+1;

    for(auto i : g[now])
    {
        if(i != fa)
        {
            dfs(i, now, t);
        }
    }
}

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	scanf("%d", &n);
	scanf("%d %d", &a, &b);

	//init
	REP(i, 0, n)
		g[i].clear();

	int x, y;

	for(int i = 0; i < n-1; i++)
	{
		scanf("%d %d", &x, &y);

		g[x].EB(y);
		g[y].EB(x);
	}	

    dis[0][0] = dis[1][0] = -1;

	dfs(a, 0, 0);
    dfs(b, 0, 1);

    int ans = 0;

    // REP(i, 1, n)
    // {
    //     cout << dis[0][i] << ' ';
    // }
    // cout << endl;

    // REP(i, 1, n)
    // {
    //     cout << dis[1][i] << ' ';
    // }
    // cout << endl;

    REP(i, 1, n)
    {
        if(dis[0][i] < dis[1][i])
            ans = max(ans, dis[1][i]-1);
    }

    printf("%d\n", ans);

	// return 0;
}

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

int n, x, y, z, ans, f[1 << 15], a[100100], c[20];
vector<int> o;

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		scanf("%d%d%d", &x, &y, &z);
		a[x] ^= z, a[y] ^= z;
	}
	for(int i = 0; i < n; i++)
		c[a[i]]++;
	for(int i = 1; i <= 15; i++) {
		ans += c[i] / 2;
//		printf("%d %d\n", i, c[i]);
		if(c[i] & 1) o.push_back(i);
	}
	f[0] = 0;
	for(int i = 1; i < (1 << o.size()); i++) {
		int x = 0, k = 0;
		for(int j = 0; j < o.size(); j++)
			if(i & (1 << j)) x ^= o[j], k++;
		f[i] = x ? 19260817 : k - 1;
//		if(i == 7) printf("%d\n", (1 << o.size()) - 1);
		for(int j = i - (i & -i); j; j = (i - (i & -i)) & (j - 1))
			f[i] = min(f[i], f[j] + f[j ^ i]);
	}
	printf("%d\n", f[(1 << o.size()) - 1] + ans);
	return 0;
}

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

# 1以上N以下で、Kで割った余りが0,1,...,K-1となる個数
l = [0] * K
for i in range(1, N + 1):
    l[i % K] += 1

ans = 0

# aをKで割った余りは0,1,...,K-1
for ai in range(K):
    # bをKで割った余り...(a+b)%K==0から   cをKで割った余り...(a+c)%K==0から
    # ai = 0の時にK-aiがKとなって「余り」として不適なので%をかける
    bi = (K - ai) % K
    ci = (K - ai) % K
    # (b+c)%K==0を満たせば良い
    if (bi + ci) % K == 0:
        ans += l[ai] * l[bi] * l[ci]
print(ans)


Measured memory_bytes: 10428
A, B, C = map(int, input().split())
K = int(input())
r, g, b = A, B, C
cnt = 0
while(r >= g):
    cnt += 1
    g *= 2
while(g >= b):
    cnt += 1
    b *= 2
if cnt <= K:
    print("Yes")
else:
    print("No")    
    

Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {

	int N, W;
	cin >> N >> W;
	vector<int> w(N + 1);
	w[0] = 1000000;
	for (int i = 0; i < N; i++) {
		cin >> w[i + 1];
	}
	sort(w.begin(), w.end());
	reverse(w.begin(), w.end());
	vector<vector<int> > dp(N + 1, vector<int>(W + 1, 0));
	vector<vector<int> > ndp(N + 1, vector<int>(W + 1, 0));
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= W; k++) {
				ndp[j][k] = 0;
			}
		}
		for (int j = 0; j < i; j++) {
			for (int k = 0; k <= W; k++) {
				if (k + w[i] <= W) {
					ndp[j][k + w[i]] = (ndp[j][k + w[i]] + dp[j][k]) % MOD;
				}
				ndp[i][k] = (ndp[i][k] + dp[j][k]) % MOD;
			}
		}
		swap(dp, ndp);
	}
	int res = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = max((int)0, W - w[i] + 1); j <= W; j++) {
			res = (res + dp[i][j]) % MOD;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 34252
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADodecagon solver = new ADodecagon();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADodecagon {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long r = in.nextInt();
            out.println(3 * r * r);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,W;
    cin>>n>>W;
    ll w[n],v[n];
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][W+1];
    for(int j=0;j<=W;j++)
        dp[0][j]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(j==0)
                dp[i][j]=0;
            else if(w[i-1]<=j)
                dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W];
    return 0;
}    

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


const ll MOD3 = 998244353;

// 二項係数nCk mod pの計算-------------------------------------
const int MAX = 510000;
const int MOD2 = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD2;
        inv[i] = MOD2 - inv[MOD2%i] * (MOD2 / i) % MOD2;
        finv[i] = finv[i - 1] * inv[i] % MOD2;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD2) % MOD2;
}

int main() {
  // 前処理:O(n)
  COMinit();

  int N,M,K; cin >>N >>M >>K;
  // 隣接を許さない塗り方は M * (M-1) * (M-1) * ... * (M-1) = M * (M-1)^(N-1)
  // 隣接が1つの塗り方は M * (M-1) * ... * (M-1) * 1 * (N-1)C1 = M * (M-1)^(N-2) * (N-1)C1
  // 隣接が2つの塗り方は M * (M-1) * ... * (M-1) * 1 * 1 * (N-1)C2 = M * (M-1)^(N-3) * (N-1)C2
  // 隣接がiつの塗り方は M * (M-1)^(N-i-1) * (N-1)Ci
  // 但し 0 <= i <= K
  // これを足してったらええやん
  ll res = 0;
  ll m1 = power((ll)M-1, (ll)N-K-1, MOD3);
  for (int i=K; i>=0; i--){
    res += (ll)M * m1 % MOD3 * COM(N-1, i) % MOD3;
    res %= MOD3;
    m1 = (m1 * (M-1)) % MOD3;
  }
  cout <<res <<endl;
}

Measured memory_bytes: 15580
#include<stdio.h>
int main () {
	char s[51];
	int n, k;
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	for(int i = 0; i < n; ++i){
		if(i + 1 == k){
			s[i] += 32;
		}
	}
	puts(s);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
X = list(map(int, input().split()))

minX = min(X)
maxX = max(X)
if minX==maxX:
    print(0)
    quit()

HP = []
for p in range(minX, maxX):
    hp = 0
    for x in X:
        hp += (x-p)**2
    HP.append(hp)

print(min(HP))
    

Measured memory_bytes: 9084
#include <stdio.h>

int main(){
    int x[5];
    int i;
    
    for(i = 0; i < 5; i++){
        scanf("%d",&x[i]);
    }

    for(i = 0; i < 5; i++){
        if(x[i] == 0)
            break;
    }

    printf("%d\n", i + 1);
    return 0;
}

Measured memory_bytes: 1724
#include "bits/stdc++.h"
using namespace std;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		string N;
		cin >> N;
		bool f = N.find_first_of( '7' ) != string::npos;
		cout << (f ? "Yes" : "No") <<  endl;
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define foR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define fors(i, n, s) for (int i = 0; i < (int)(n); i += s)
#define foRs(i, a, b, s) for (int i = (int)(a); i < (int)(b); i += s)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define foRr(i, a, b) for (int i = (int)(a) - 1; i >= (int)(b); --i)

#define prnt(a) cout << (a)
#define prntl(a) cout << (a) << endl
#define in insert
#define rem remove
#define er erase

#define linf ((ll) 1e9)
#define inf ((int) 1e5)
#define otherinf 555555

#define mod 1000000007

int main()
{
	ll n, m;
	cin >> n >> m;
	vvl pic(n, vl(n, -1));
	vvl temp(m, vl(m, -1));

	forn(i, n)
	{
		string ln;
		cin >> ln;
		int j = 0;

		for(char c : ln)
		{
			if(c == '#')
				pic[i][j] = 0;
			else
				pic[i][j] = 1;
			j++;
		}
	}
	forn(i, m)
	{
		string ln;
		cin >> ln;
		int j = 0;

		for(char c : ln)
		{
			if(c == '#')
				temp[i][j] = 0;
			else
				temp[i][j] = 1;
			j++;
		}
	}

	forn(i,n-m+1)
	{
		forn(j, n-m+1)
		{
			bool fits = true;
			forn(x, m)
			{
				forn(y, m)
				{
					if(pic[i+x][j+y] != temp[x][y])
					{
						fits = false;
						break;
					}
				}
				if(!fits)
					break;
			}
			if(fits)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";


	return 0;
}

Measured memory_bytes: 256
S = list(input())
N = len(S)
dp = [[0]*13 for i in range(N+1)]
dp[0][0]=1
p = 10**9+7

for i in range(1,N+1):
    X = S[N-i]
    if X=="?":
        for X in range(10):
            Y = (X*pow(10,i-1,13))%13
            for j in range(13):
                if 0<=Y+j<=12:
                    Z = Y+j
                else:
                    Z = Y+j-13
                dp[i][Z] = (dp[i][Z]+dp[i-1][j])%p
    else:
        X = int(X)
        Y = (X*pow(10,i-1,13))%13
        for j in range(13):
            if 0<=Y+j<13:
                Z = Y+j
            else:
                Z = Y+j-13
            dp[i][Z] = dp[i-1][j]
#print(*dp,sep='\n')
print(dp[-1][5])

Measured memory_bytes: 101484
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define pi acos(-1)
#define eps 1e-10
#define mem(x) memset(x,0,sizeof(x))
#define si(n) scanf("%d",&n)
#define _for(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define __for(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD)
{ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

const int inf=0x3f3f3f3f;
const int MAX=1000005;
const int MOD=1e9+7;
struct node{
int x,y;
};
node a[1000],b[1000];
int n;
int line[1000][1000],sum,used[1000],boy[1000];
int Find(int x)
{
    //cout<<2<<" "<<n<<endl;
    for(int i=1;i<=n;i++)//遍历所有被选者
    {
       //cout<<i<<endl;
       if(line[x][i]==1&&used[i]==0)
       {//如果 x对i有好感且在这一个递归选取阶段没有被选取（哪怕是暂时选取，新的递归可能会换）
          used[i]=1;//标记被选取
          if(boy[i]==0||Find(boy[i]))//如果被选者没有归属或他的归属着可以调换（他的归属者可以选择其它被选者）
          {
             boy[i]=x;//将归属定为 x
             return 1;
          }
       }
    }
    return 0;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&b[i].x,&b[i].y);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i].x<b[j].x&&a[i].y<b[j].y){
                     line[i][j]=1;
                    //line[j+n][i]=1;
            }
        }
    }
    sum=0;
    for(int i=1;i<=n;i++)
    {
        //cout<<1<<" "<<i<<endl;
        //cout<<Find(i)<<endl;
        memset(used,0,sizeof(used));//每次都要清 0
        if(Find(i)) sum++;//找到一对就记录
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)

int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.size ()<= K) {
		cout << S;
	}
	else {
		int i;
		for (int i = 0; i < K;i++) {
			cout << S[i];
		}
		cout << "...";
	}
	return 0;
}

Measured memory_bytes: 3624
import itertools as it

n,a,b,c = map(int, input().split())

if a+b+c==0:
  print('Yes' if n==0 else 'No'),exit(0)

if a+b+c==1:
  res = []
  for _ in range(n):
    s = input()
    if s == 'AB':
      if a+b==0:print('No'),exit(0)
      if a < b:
        res.append('A')
        a,b = a+1,b-1
      else:
        res.append('B')
        a,b = a-1,b+1
    elif s == 'AC':
      if a+c==0:print('No'),exit(0)
      if a < c:
        res.append('A')
        a,c = a+1,c-1
      else:
        res.append('C')
        a,c = a-1,c+1
    elif s == 'BC':
      if c+b==0:print('No'),exit(0)
      if c < b:
        res.append('C')
        c,b = c+1,b-1
      else:
        res.append('B')
        c,b = c-1,b+1
  print('Yes'),print('\n'.join(res)),exit(0)


if a+b+c==2:
  ops = [input() for _ in range(n)]
  opt = iter(ops); next(opt)
  res = []
  for s,t in it.zip_longest(ops, opt):
    if s == 'AB':
      if a+b==0:print('No'),exit(0)
      if a==0:
        res.append('A')
        a,b = a+1,b-1
      elif b==0:
        res.append('B')
        a,b = a-1,b+1
      else:
        if t=='AC':
          res.append('A')
          a,b = a+1,b-1
        else:
          res.append('B')
          a,b = a-1,b+1
    elif s == 'AC':
      if a+c==0:print('No'),exit(0)
      if a==0:
        res.append('A')
        a,c = a+1,c-1
      elif c==0:
        res.append('C')
        a,c = a-1,c+1
      else:
        if t=='AB':
          res.append('A')
          a,c = a+1,c-1
        else:
          res.append('C')
          a,c = a-1,c+1
    elif s == 'BC':
      if c+b==0:print('No'),exit(0)
      if c==0:
        res.append('C')
        c,b = c+1,b-1
      elif b==0:
        res.append('B')
        c,b = c-1,b+1
      else:
        if t=='AC':
          res.append('C')
          c,b = c+1,b-1
        else:
          res.append('B')
          c,b = c-1,b+1
  print('Yes'),print('\n'.join(res)),exit(0)


s = input()
if  s == 'AB' and a+b==0 or\
    s == 'AC' and a+c==0 or\
    s == 'BC' and c+b==0 :
  print('No'),exit(0)

print('Yes')
for s in it.chain([s], (input() for _ in range(n-1))):
  if s == 'AB':
    if a < b:
      print('A')
      a,b = a+1,b-1
    else:
      print('B')
      a,b = a-1,b+1
  elif s == 'AC':
    if a < c:
      print('A')
      a,c = a+1,c-1
    else:
      print('C')
      a,c = a-1,c+1
  elif s == 'BC':
    if c < b:
      print('C')
      c,b = c+1,b-1
    else:
      print('B')
      c,b = c-1,b+1


Measured memory_bytes: 17440
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val n = read().toList()
    println(if(n.contains('9')) "Yes" else "No")
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define str string
#define vl vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}
ll dp[100000];
ll arr[100000];
void dpfunc(ll index, ll n)
{
    if(index==n-1)
    {
        dp[index]=0;
        return;
    }
    else if(index==n-2)
    {
        dp[index]=abs(arr[index+1]-arr[index]);
        return;
    }
    else
    {
        ll val1;
        if(dp[index+1]==-1)
            dpfunc(index+1,n);
        val1=dp[index+1];
        ll val2;
        if(dp[index+2]==-1)
            dpfunc(index+2,n);
        val2=dp[index+2];
        dp[index]=min(abs(arr[index+1]-arr[index])+val1,abs(arr[index+2]-arr[index])+val2);
        return;
    }
    return;
}
signed main() 
{
    fast_cin();
    ll n;
    cin>>n;
    For(i,0,n)
    {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    dpfunc(0,n);
    cout<<dp[0]<<endl;
    return 0;
}

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

int main() {
  int A,B;
  string s;
  cin>>A>>B>>s;
  bool f=false;
  if(s.at(A)!='-')
    f = true;
  for(int i=0;i<A;i++){
      if(s.at(i)=='-'){
        f=true;
        break;
    }
  }
  for(int i=A+1;i<s.size();i++){
      if(s.at(i)=='-'){
        f=true;
        break;
    }
  }
  if(f)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;    
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int lcm(int a, int b) {
    return a * (b / gcd(a, b));
}

int main() {
    int n, a, ans = 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        ans = lcm(ans, a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3088
var
	n,i,j:Longint;
	sto,ma,m,ans,vv:real;
	v,t:array[0..100]of real;
begin
	read(n);
	for i:=0 to n-1 do read(t[i]);
	for i:=0 to n-1 do read(v[i]);
	for i:=0 to n-1 do begin
		sto:=v[i+1];
		ma:=0;
		for j:=n-1 downto i+1 do begin
			if ma+t[j]>v[j] then ma:=v[j] else ma:=ma+t[j];
		end;
		v[i+1]:=ma;
		if v[i]<=v[i+1] then begin
			if v[i]-vv<=t[i] then begin
				ans:=ans+(v[i]-vv)*(v[i]+vv)/2+(t[i]-v[i]+vv)*v[i];
				vv:=v[i];
			end else begin
				ans:=ans+t[i]*(vv*2+t[i])/2;
				vv:=vv+t[i];
			end;
		end else begin
			if v[i+1]-vv>t[i] then begin
				ans:=ans+t[i]*(vv*2+t[i])/2;
				vv:=vv+t[i];
			end else if v[i]-vv+v[i]-v[i+1]<=t[i]then begin
				ans:=ans+(v[i]-vv)*(v[i]+vv)/2+(v[i]-v[i+1])*(v[i]+v[i+1])/2+(t[i]-v[i]+vv-v[i]+v[i+1])*v[i];
				vv:=v[i+1];
			end else begin
				m:=(t[i]+vv+v[i+1])/2;
				ans:=ans+(m-vv)*(m+vv)/2+(m-v[i+1])*(m+v[i+1])/2;
				vv:=v[i+1];
			end;
		end;
		v[i+1]:=sto;
	end;
	writeln(ans:0:9);
end.


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,l;
    string s;
    cin>>n>>l;
    ll arr[n];
    for(i=0;i<n;i++) arr[i]=l+(i+1)-1;
    ll mn=INT_MAX,val;
    for(i=0;i<n;i++)
    {
        if(abs(arr[i])<mn)
        {
            mn=abs(arr[i]);
            val=arr[i];
        }
    }
    ll sum=0;
    for(i=0;i<n;i++) sum+=arr[i];
    sum-=val;
    cout<<sum;
    
}

Measured memory_bytes: 3572