akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b) {
	if (b)cout << "Yes";
	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N;
	li P;

	cin >>N;

	li me=INF;
	li cnt=0;

	Rep(i,N){
		cin >>P;
		me=min(me,P);
		if(P==me)cnt++;
	}

	cout<<cnt;
}

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll A, B;

    cin >> A >> B;

    cout << (A >= 13 ? B : (A >= 6 ? B / 2 : 0)) << endl;

    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
kMod = 998244353

# [100, 0, 0]                                                                                                                                                                                                                                 
# [100, 9900, 0]                                                                                                                                                                                                                              
# [100, 19800, 9900*99]                                                                                                                                                                                                                       

# M, M*(M-1)*C(N-1, 1),M*(M-1)^2*C(N-1, 2),M*(M-1)^3*C(N-1,3)                                                                                                                                                                                 

ans = 0
for i in range(N):
    if i == 0:
        acc = M
    else:
        acc *= (M-1)
        acc %= kMod
        acc *= (N-i)
        acc %= kMod
        acc *= pow(i, kMod-2, kMod)
        acc %= kMod
    if i >= N-K-1:
        ans += acc
        ans %= kMod
print(ans)



Measured memory_bytes: 69160
n = int(input())
values = input().split(' ')
for idx in range(0, n):
    values[idx] = int(values[idx])

result = 1
limit = 10**18
if 0 in values:
    result = 0
else:
    for idx in range(0, n):
        result = result * values[idx]
        if result > limit:
            result = -1
            break

print(result)


Measured memory_bytes: 19532
N, A = map(int, input().split())
*X, = map(lambda x:int(x)-A, input().split())

M = 2500
dp = [[0]*(2*M+1) for _ in range(N)]
dp[0][M] += 1
dp[0][X[0]+M] += 1

for i in range(1,N):
    for v in range(-M, M+1):
        dp[i][v+M] += dp[i-1][v+M]
        if -M<=v-X[i]<=M:
            dp[i][v+M] += dp[i-1][v-X[i]+M]

print(dp[-1][M]-1)

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

/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define endl '\n'

/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

void solve() {
	int n, d; cin >> n >> d;
	int ans = 0;
	while (n--) {
		int x, y; cin >> x >> y;
		if ((x * x + y * y) <= d * d)
			ans++;
	}
	cout << ans << endl;
	return ;
}

int32_t main() {

	/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

	//int t;cin>>t;while(t--)
	solve();

	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b < c + d) {
        cout << "Right\n";
    } else if (a + b == c + d) {
        cout << "Balanced\n";
    } else {
        cout << "Left\n";
    }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	if ( abs( a - c ) <= d )
	{
		cout << "Yes" << endl;
	}
	else if ( ( abs( a - b ) <= d ) && ( abs( b - c ) <= d ) )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    VI a(3); REP(i,3) cin >> a[i]; SORT(a);
    if(a[0]==a[1]){out(a[2]);}
    else out(a[0]);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005,E=262144;
const int M=998244353;
int n,m,i,j,dp[105][105];
char c[105][105]; 
int main()
{
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%s",c[i]+1);
	memset(dp,0x7f,sizeof(dp));
	if(c[1][1]=='#')
		dp[1][1]=1;
	else
		dp[1][1]=0;
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
			if(i!=1||j!=1)
				dp[i][j]=min(dp[i-1][j]+(c[i][j]!=c[i-1][j]&&c[i][j]=='#'),dp[i][j-1]+(c[i][j]!=c[i][j-1]&&c[i][j]=='#'));
	cout<<dp[n][m];
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
 public static void main(String[] args){
  Scanner scan = new Scanner(System.in);
  String str = scan.nextLine();
   
  switch(str){
    case "Sunny":
      System.out.println("Cloudy");
      break;
    case "Cloudy":
      System.out.println("Rainy");
      break;
    case "Rainy":
      System.out.println("Sunny");
      break;
  }
 }
  
}

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

bool check(int c[3][3]){
    for(int i=0; i<=c[0][0]; i++){
        int a[3], b[3];
        a[0]=i;
        b[0]=c[0][0]-i;
        a[1]=c[1][0]-b[0];
        a[2]=c[2][0]-b[0];
        b[1]=c[0][1]-a[0];
        b[2]=c[0][2]-a[0];
        for(int x=1; x<3; x++){
            for(int y=1; y<3; y++){
                if(c[x][y] != a[x]+b[y]){
                    return false;
                }
            }
        }
    }
    return true;
}

int main() {
    int c[3][3]={0};
    // in
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            int l;
            cin >> l;
            c[i][j] = l;
        }
    }
    // out
    cout << (check(c) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//作成日：4/20
#import<stdio.h>
#import<objc/Object.h>

int main(){
	//日付を受け取る変数
	int day;
  
  	scanf("%d",&day);
	//条件分岐
	if (day == 25){
	  printf("Christmas");
	}
	else if (day == 24){
 		printf("Christmas Eve");
	}
	else if (day == 23){
		printf("Christmas Eve Eve");
	}
	else{
  		printf("Christmas Eve Eve Eve");
	}
  return 0;
}


Measured memory_bytes: 128
apart = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

rep = int(input())

for i in range(rep):
    lst = list(map(int,input().split()))
    b = lst[0] - 1
    f = lst[1] - 1
    r = lst[2] - 1
    v = lst[3]
    apart[b][f][r] += v

for i,building in enumerate(apart):
    for floor in building:
        for room in floor:
            print(f" {room}",end='')
        print()

    #最後以外は末尾に区切り用の'#'を入れる
    if i < 3:
        print("####################")



Measured memory_bytes: 5632
def main():
    N = int(input())
    XY = [[] for _ in range(N)]
    for i in range(N):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            XY[i].append((x-1, y))

    ans = 0
    for i in range(1, 2**N):
        flag = True
        cnt = 0
        for j in range(N):
            if i>>j & 1:
                cnt += 1
                for x, y in XY[j]:
                    if i>>x & 1 != y:
                        flag = False
                        break
        if flag:
            ans = max(ans, cnt)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl

using namespace std;

int main(void) {

	int A,B;
	int X = 0;


	INPUT(A);
	INPUT(B);

	for(int i = 0 ; i < 2 ; i++){
		X += max(A,B);
		if(A>B){
			A--;
		}else{
			B--;
		}
	}


	OUTPUT(X);

}

Measured memory_bytes: 768
using System;
using System.Globalization;

class program
{
    public static void Main()
    {
        char[] str = Console.ReadLine().ToCharArray();

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] >= 'a' && str[i] <= 'z')
            {
                Console.Write(str[i].ToString().ToUpper());
            }
            else if (str[i] >= 'A' && str[i] <= 'Z')
            {
                Console.Write(str[i].ToString().ToLower());
            }
            else
            {
                Console.Write(str[i]);
            }
        }
        Console.WriteLine();
        
    }
}

Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1087;
ll dp[N][10];
int main()
{
/*
    fill_n(dp[1], 10, 1);
    ll tot = 9;
    int w;
    for (w = 2; w < N && tot < 1e5; ++w) {
        for (int i = 0; i < 10; ++i)
            for (int j = i - 1; j <= i + 1; ++j)
                if (0 <= j && j <= 9)
                    dp[w][i] += dp[w - 1][j];
        for (int i = 1; i <= 9; ++i)
            tot += dp[w][i];
    }
    cerr << w << ' ' << tot;
*/
    vector<ll> v, c(9), d;
    iota(begin(c), end(c), 1);
    v = c;
    int k;
    cin >> k;
    for (int w = 2; v.size() < k; ++w) {
        d.clear();
        for (ll x : c) {
            ll t = x % 10;
            for (int i = t - 1; i <= t + 1; ++i) {
                if (0 <= i && i <= 9) {
                    ll y = x * 10 + i;
                    d.push_back(y);
                    v.push_back(y);
                }
            }
        }
        swap(c, d);
    }
    sort(begin(v), end(v));
    cout << v[k - 1] << endl;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
inline void Yes(bool b = true){cout << (b? "Yes" : "No") << endl;}
inline void YES(bool b = true){cout << (b? "YES" : "NO") << endl;}
inline void err(){cout << -1 << endl;}



const int INF = 1e18;

signed main(){
    int a, b, c; cin >> a >> b >> c;
    Yes(a*a+b*b+c*c-2*a*b-2*b*c-2*c*a > 0 and c-b-a > 0);
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 1000000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

bool vis[MAX + 5];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, i, j, ans = 0;
    string s;
    cin >> n >> s;
    i = 0, j = n - 1;
    while (i < j) {
        while (i < n and s[i] == 'R') {
            ++i;
        }
        while (j >= 0 and s[j] == 'W') {
            --j;
        }
        if (i < j) {
            ans++;
        }
        ++i, --j;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3424
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        if (a.equals("A"))
            {System.out.println("T");}
        else if  (a.equals("G"))
            {System.out.println("C");}
        else if (a.equals("T"))
            {System.out.println("A");}
        else
            {System.out.println("G");}
    }
}





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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

int main() {

    int n; cin >> n;
    int a[100000];
    int ans = 0;
    memset(a,0,sizeof(a));
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }

    for(int i = 1; i <= n; i ++){
        if(a[a[i]] == i){
            ans ++;
        }
    }
    cout << ans/2;

    return 0;
}











Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(int a, int b)
{
	return a > b;
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 1, -1);
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		int t = upper_bound(a.begin(), a.end(), b, comp) - a.begin();
		a[t] = b;
	}

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

	return 0;
}

Measured memory_bytes: 3784
#include<stdio.h>
int main(void){
	int t,n,d,r,i;
	scanf("%d",&t);
	for(i=1;i<=t;i++){
		scanf("%d%d",&n,&d);
		if(n%2){
			printf("%d\n",127*(n-1)+d);
		}
		else{
			printf("%d\n",127*(n-1)+(d^127));
		}
	}
	return 0;
}

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

using namespace std;

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

	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
que=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            que.append((i, j))
            A[i][j]=1
        else:
            A[i][j]=0
d=[(1,0),(0,1),(-1,0),(0,-1)]
count=0
while que:
    h=[]
    for x,y in que:
        for dx,dy in d:
            nx,ny=x+dx,y+dy
            if 0<=nx<H and 0<=ny<W and A[nx][ny]==0:
                A[nx][ny]=1
                h.append((nx,ny))
    que=h
    count+=1
print(count-1)

Measured memory_bytes: 126592
#include <iostream>
#include <stdio.h>

int main() {
	char b;
	scanf("%c", &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";
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend())) 

int main () {

    string a,b;cin>>a>>b;

    int start = a.size()-1;

    while (1) {
        if (start==b.size()-2) {
            cout<<"UNRESTORABLE"<<endl;
            return 0;
        }
        bool ok = true;
        rep(i,b.size()) {
            if (a[start-i]!='?' && a[start-i]!=b[b.size()-1-i]) {
                start--;
                ok=false;
                break;
            }
        }
        if (ok) {
            break;
        }
    }

    rep(i,b.size()) {
        a[start-i]=b[b.size()-1-i];
    }

    rep(i,a.size()) {
        if (a[i]=='?') {
            a[i]='a';
        }
    }

    cout<<a<<endl;

}

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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

int add(int x, int y, int mod = MOD998) {
	return x + y >= mod ? x + y - mod : x + y;
}

int sub(int x, int y, int mod = MOD998) {
	return x - y < 0 ? x - y + mod : x - y;
}

int mul(int x, int y, int mod = MOD998) {
	return 1LL * x * y % mod;
}

int pw(int a, int n, int mod = MOD998) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res = mul(res, a, mod);
		}
		a = mul(a, a, mod);
		n >>= 1;
	}
	return res;
}

int inv(int x, int mod = MOD998) {
	return pw(x, mod - 2, mod);
}

vector<int> get_invs(int upto, int mod = MOD998) {
	vector<int> res(upto + 1);
	res[1] = 1;
	for (int i = 2; i <= upto; i++) {
		res[i] = mod - mul(mod / i, res[mod % i], mod);
	}
	return res;
}

void run() {
	int n, m;
	cin >> n >> m;
	vector<vector<bool>> a(n, vector<bool>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char ch;
			cin >> ch;
			a[i][j] = ch == '.';
		}
	}
	vector<vector<int>> dp(n, vector<int>(m));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!a[i][j]) {
				continue;
			}
			if (i - 1 >= 0) {
				dp[i][j] = add(dp[i][j], dp[i - 1][j], MOD);
			}
			if (j - 1 >= 0) {
				dp[i][j] = add(dp[i][j], dp[i][j - 1], MOD);
			}
		}
	}
	cout << dp[n - 1][m - 1] << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 4352
/**
 *    author        : Saurav Paul 
 *    created       : August 07, 2020 12:16 PM
 *    Problem Name  : E - Knapsack 2
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_e
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

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

    int N , W ;
    cin >> N >> W ;
    int sz = 101 * 1e3 + 10 ;
    const int INF = 1e9 + 90 ;
    vector<int> dp(sz + 1,INF) ;

    dp[0] = 0 ;
    for(int item = 0 ; item < N ;item ++){
        int w , value ;
        cin >> w >> value ;

        for(int val = sz ; val - value >= 0 ; val --){
            if(val-value == 0 or dp[val-value] <= W - w){
                dp[val] = min(dp[val] , dp[val-value] + w) ;
            }
        }
        
    }

    int answer = 0 ;

    for(int i = 1 ; i <= sz ; i++){
        if(dp[i] <= W ) answer = max(answer,i) ;
    }

    cout << answer << endl ;

    return 0 ;
}
/* 3 8 */
/* 3 30 */
/* 4 50 */
/* 5 60 */

/* 30 50 80 90 */
/* 3  4  7  8 */


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = int(1e5) + 7;
const int mod = int(1e9) + 7;
typedef pair<int, int> pii;

int n, k, u, v, root;
ll l[N], r[N], val[N];
vector<int> a[N];

void No() {cout << "No"; exit(0);}

void Check(int u, int par, int d) {
    if(val[u] != (ll)1e18 && (d & 1) != (abs(val[root] - val[u]) & 1)) No();
    for(int v: a[u]) if(v != par) Check(v, u, d + 1);
}

void DFS(int u, int par) {
    for(int v: a[u]) {
       if(v == par) continue;
       DFS(v, u);
       l[u] = max(l[v] - 1, l[u]);
       r[u] = min(r[v] + 1, r[u]);
    }
    if(l[u] > r[u]) No();
}

void GetAns(int u, int par) {
    if(val[u] != (ll)1e18) {
        if(val[u] < l[u] || val[u] > r[u]) No();
    } else {
        if(u == par) val[u] = l[u];
        else {
            if(val[par] + 1 >= l[u] && val[par] + 1 <= r[u]) val[u] = val[par] + 1;
            else if(val[par] - 1 >= l[u] && val[par] - 1 <= r[u]) val[u] = val[par] - 1;
            else No();
        }
    }
    for(int v: a[u]) if(v != par) GetAns(v, u);
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i < n; ++i) {
       cin >> u >> v;
       a[u].pb(v), a[v].pb(u);
    }
    fill_n(l, n + 1, -mod); fill_n(r, n + 1, mod);
    fill_n(val, n + 1, (ll)1e18);
    cin >> k; root = 1;
    for(int i = 0; i < k; ++i) {
        cin >> u >> v;
        val[root = u] = l[u] = r[u] = v;
    }
    Check(root, root, 0);
    DFS(root, root);
    GetAns(root, root);
    cout << "Yes\n";
    for(int i = 1; i <= n; ++i) cout << val[i] << '\n';
}


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

int main()
{
        int n;
        cin >> n;
        vector<map<int, int>> m(n);
        for (int i = 0; i < n; ++i) {
                string str;
                cin >> str;
                for (int j = 0; j < str.length(); ++j) {
                        m[i][str[j]-'a']++;
                }
        }
        vector<int> cnt(26, 0);
        for (int k = 0; k < 26; ++k) {
                int minv = -1;
                for (int i = 0; i < n; ++i) {
                        int tmp = m[i][k];
                        if (minv == -1) minv = tmp;
                        else if (minv > tmp) minv = tmp;
                }
                cnt[k] = minv;
        }
        for (int k = 0; k < 26; ++k) {
                int tmp = cnt[k];
                if (tmp > 0) {
                        for (int i = 0; i < tmp; ++i) {
                                char cc = k + 'a';
                                cout << cc;
                        }
                }
        }

}


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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


ll isq(ll a){
	ll lw=0, hi=a+2;
	while(hi - lw > 1){
		ll md= (hi + lw) /2;
		( md <= a/md? lw: hi ) = md;
	}
	return lw;
}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int q;
	cin >>q;
	rep(zz, q){
		ll a,b;
		cin >>a >>b;
		if(a>b) swap(a,b);
		
		if(a==b){
			cout << 2*(a-1) <<"\n"; continue;
		}
		if(a+1 == b){
			cout << 2*a -2 <<"\n"; continue;
		}
		ll c = isq(a*b);
		if(c*c == a*b) c--;
		if(c*(c+1) >= a*b){
			cout << 2*c -2 <<"\n"; continue;
		}
		cout << 2*c -1 <<"\n";
	
	}
	
	
	
	return 0;
	
}


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

using namespace std;

typedef long long LL;

const int MAXN = 105;
const int MAXL = 505;
const int base = 1E9 + 7;

int n, X;
int L[MAXN];
int dp[MAXN][MAXN][MAXL];

void Read_Input() {
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    scanf("%d%d", &n, &X);
    for (int i = 1; i <= n; i++)
        scanf("%d", &L[i]);
    sort(L + 1, L + 1 + n, greater <int> ());
}

void Update(int &x, int y) {
    if (y < 0) y += base;
    x += y;
    if (x < 0) x += base;
    if (x > base) x -= base;
}

void Solve() {
    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int k = 0; k <= min(i, X / L[i + 1]); k++) {
            for (int len = 0; len <= X; len++)
                if (dp[i][k][len]) {
                    /// Add a segment
                    if (len + L[i + 1] <= X)
                        Update(dp[i + 1][k + 1][len + L[i + 1]], (LL)dp[i][k][len] * (k + 1) % base);
                    /// Merge with one segment existed
                    for (int x = 1; x <= min(X - len, L[i + 1] - 1); x++) // that segment extend x
                        Update(dp[i + 1][k][len + x], dp[i][k][len] * 2LL * k % base);
                    Update(dp[i + 1][k][len], (LL)dp[i][k][len] * (len - k * (L[i + 1] - 1)) % base); //overlap Li
                    /// Merge two segments existed
                    if (k < 1) continue;
                    for (int x = 0; x <= min(X - len, L[i + 1] - 2); x++) // extend x
                        Update(dp[i + 1][k - 1][len + x], (LL)dp[i][k][len] * (L[i + 1] - x - 1) * (k - 1) % base);
                }
        }
    }
    int ans = 0;
    for (int k = 1; k <= n; k++)
        Update(ans, dp[n][k][X]);

    printf("%d", ans);
}

int main() {
    Read_Input();
    Solve();
    return 0;
}


Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
signed main(){
    long long a , b , n , x;
    cin >> a >> b >> n;
    
    x = min(n , a/b * b + b-1);
    if(x%b == 0){
        x--;
    }
    
    cout << (a*x)/b - a*(x/b) << endl; 
    return(0);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long int
#define pi 3.1415926536
using namespace std;

/*ll merge(vector<ll> &v,ll l,ll m,ll r)
{
	ll n1=m-l+1;
	ll n2=r-m;
	ll inv=0;
	vector<ll> a(n1),b(n2);
	for(ll i=0;i<n1;i++)
	a[i]=v[l+i];
	for(ll i=0;i<n2;i++)
	b[i]=v[m+1+i];
	ll i=0,j=0,k=l;
	while(i<n1&&j<n2)
	{
		if(a[i]<=b[j])
		{
			v[k]=a[i];
			i++;
		}
		else
		{   inv+=(m-i+1);
			v[k]=b[j];
			j++;
		}
		k++;
	}
	while(i<n1)
	{
		v[k]=a[i];
		i++;
		k++;
	}
	while(j<n2)
	{
		v[k]=b[j];
		j++;
		k++;
	}
	return inv;
}
ll mergesort(vector<ll> &v,ll l,ll r)
{  ll inv=0;
	if(l<r)
	{
		ll m=l+(r-l)/2;
		inv=mergesort(v,l,m);
		inv+=mergesort(v,m+1,r);
		inv+=merge(v,l,m,r);
	}
	return inv;
}*/

/*ll factorize(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            if((n/i)!=i)
            res.push_back(n/i);
        }
    }
    
    return (ll)res.size();
}*/
/*vector<ll> v[200005];
vector<ll> visited(200005,-1),cnt(200005,0);
void dfs(ll x,ll sum)
{
	for(ll i=0;i<v[x].size();i++)
	{
		if(visited[v[x][i]]==-1)
		{
			visited[v[x][i]]=sum+cnt[v[x][i]];
			dfs(v[x][i],sum+cnt[v[x][i]]);
		}
	}
	return;
}*/
void solve()
{ll n,k,ans,z=0,x,y,p=0,q=0,l=INT_MIN,mini=0,prev;
   string s,t;
   cin>>s>>t;
   unordered_map<char,ll> m;
   vector<ll> v[26];
   for(ll i=0;i<s.length();i++)
   {
   	m[s[i]]++;
   	v[s[i]-'a'].pb(i);
   }
   for(ll i=0;i<t.length();i++)
   {
   	 if(m[t[i]]==0)
   	 {
   	 	cout<<-1;
   	 	return;
	 }
   }
   n=s.length();
  // m=t.length();
   vector<ll> curr(26,0);
   p=-1; ans=1;
   for(ll i=0;i<t.length();i++)
   {
   		ll ind=t[i]-'a';
   		while(curr[ind]<v[ind].size()&&p>=v[ind][curr[ind]])
   		curr[ind]++;
   		if(curr[ind]==v[ind].size())
   		{
   			ans++;
   			for(ll j=0;j<26;j++)
   			curr[j]=0;
		}
		p=v[ind][curr[ind]];
		curr[ind]++;
   }
   cout<<(ans*n)-(n-p-1);
}

int main()
{
  fast
ll t=1;

while(t--)
{solve();
 //cout<<ma<<endl;
}
return 0;}

Measured memory_bytes: 1736
def a():
    a = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
    list_a = a.split(sep=",")
    k = int(input())
    print(list_a[k-1])
    

if __name__ == '__main__':
    a()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> vec;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        vec.push_back(x);
    }
    int pos=lower_bound(vec.begin(),vec.end(),k)-vec.begin();
    cout<<min(pos,m-pos);
}



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

long long int N, a[514][514], l[514], c[514], i, j, f, g, ans;
//vector<long long int> low[514], col[514];
vector<pair<long long int, long long int> > vp;
char C;

int main(){
    scanf("%lld", &N);
    for(i = 0; i < N; ++i){
        for(j = 0; j < N; ++j){
            scanf(" %c", &C);
            a[i][j] = (C == '.') ? 0 : 1;
            if(C != '.'){
                ++f;
                //low[i].push_back(j);
                //col[j].push_back(i);
                ++l[i];
                ++c[j];
            }
        }
    }
    if(f == 0)return 0 & puts("-1");
    f = count(l, l + N, N);
    g = count(c, c + N, N);
    //cout << f << " " << g << endl;
    if(f > 0)return 0 & printf("%lld\n", N - g);
    ans = N * 2 + 1;
    /*
    cout << " ";
    for(i = 0; i < N; ++i){
        cout << " " << c[i];
    }
    cout << endl;
    for(i = 0; i < N; ++i){
        cout << l[i] << " ";
        for(j = 0; j < N; ++j){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    */
    for(i = 0; i <= N; ++i){
        //if(c[i] == 0)continue;
        ans = min(ans, N * 2 - l[i] - g + ((c[i] == 0) ? 1 : 0));
    }
    cout << ans << endl;
    //f = max_element()
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll K, X;
    ll ans = 0;

    //input
    cin >> K >> X;

    if(K * 500 >= X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        a: isize,
        b: isize,
        c: isize,
        d: isize,
    }
    let ans_vec:Vec<isize> = vec![a*c, a*d, b*c, b*d];
    let ans = ans_vec.iter().max().unwrap();
    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2196
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
constexpr long long INF = 1e14;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    ll t, d;
    vector<vector<ll> > sushi(N);
    for(int i=0; i < N; ++i) {
        cin >> t >> d;
        --t;
        sushi[t].push_back(d);
    }
    
    // sort sushi
    for(int i=0; i < N; ++i) {
        if(sushi[i].empty()) {
            sushi[i].push_back(-INF);
            continue;
        }
        sort(sushi[i].rbegin(), sushi[i].rend()); 
    }
    sort(sushi.begin(), sushi.end(), [&](vector<ll> a, vector<ll> b) { return a[0] > b[0];});

    // calc
    ll sum = 0;
    priority_queue<ll> sushi_field; // sushi not eaten
    for(int i=0; i < K; ++i) {
        sum += sushi[i][0]; // sum top K of top sushi of each kind
        for(int j=1; j < (int)sushi[i].size(); ++j) sushi_field.push(sushi[i][j]);
    }
    for(int i=K; i < N; ++i) for(int j=0; j < (int)sushi[i].size(); ++j) sushi_field.push(sushi[i][j]);

    ll ans = sum + K * K;
    // eat i kind
    for(ll i=K-1; i >= 1; --i) {
        ll min_sushi = sushi[i][0];
        ll max_sushi_field = sushi_field.top();

        if(min_sushi < max_sushi_field) {
            // eat it
            sushi_field.pop();
            sum += max_sushi_field;
            // return it
            sushi_field.push(min_sushi);
            sum -= min_sushi;
        }
        ans = max(ans, sum + i * i);
    }
    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8696
//095 B - Bitter Alchemy
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n , x;
    cin >> n >> x;
    vector<int> m(n);
    rep(i ,n) cin >> m.at(i);
    int sum=0;int counter=0;
    rep(i ,n){
        sum+=m[i];
        ++counter;
    }
    int r=x-sum;
    sort(m.begin(),m.end());
    counter+=r/m[0];
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  double A, B; 
  cin >> A >> B;

  double H, M;
  cin >> H >> M;

  double T = H*60+M;


  double a = T/2/180*PI;
  double b = M*6/180*PI;

  double x, y, u, v;

  x = cos(a)*A;
  y = sin(a)*A;

  u = cos(b)*B;
  v = sin(b)*B;

  cout << hypot(x-u, y-v) << "\n";

  return 0;
}

Measured memory_bytes: 4080
#include <iostream>

using namespace std;

bool solve()
{
	int n; cin>>n;
	int cnt=0;
	while(n--){
		char p; int x; cin>>p>>x;
		if(p=='(')
			cnt+=x;
		else{
			cnt-=x;
			if(cnt<0)
				return false;
		}
	}
	return cnt==0;
}

int main()
{
	cout<<(solve()?"YES":"NO")<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	ll g = __gcd(n, m);
	rep (i, 0, g) {
		if (s[i * (n / g)] != t[i * (m / g)]) {
			cout << -1;
			return 0;
		}
	}
	cout << n * m / g;
	
}


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


int main(){
  int64_t K;
  pair<int64_t,int64_t> M;
  M.first=2;
  M.second=2;
  cin >> K;
  vector<int64_t> A(K);
  for(int64_t i=0;i<K;i++){
    cin >> A.at(i);
  }
  for(int64_t i=K-1;i>=0;i--){
    if(M.second/A.at(i)!=M.first/A.at(i)||M.first%A.at(i)==0){
      M.first=A.at(i)*((M.first-1)/A.at(i)+1);
      M.second=A.at(i)*(M.second/A.at(i)+1)-1;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << M.first << " " << M.second << endl;
}


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

typedef long long ll; 

const int N = 6000; 
const int MOD = 998244353;

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

inline ll add( ll a, ll b ) { ll ret = a + b; return ret >= MOD ? ret - MOD : ret; }

inline ll dec( ll a, ll b ) { ll ret = a - b; return ret < 0 ? ret + MOD : ret; }

inline ll ksm( ll a, ll b ) 
{
	ll ret = 1; 
	for( ; b; b >>= 1, a = a * a % MOD ) 
		if( b & 1 ) ret = ret * a % MOD; 
	return ret;
}

int n, k, sum[N<<1]; 

ll fac[N], inv_fac[N], f[N], g[N][N]; 

inline void calc_fac()
{
	fac[0] = 1; int lim = 5000; 
	for( int i = 1; i <= lim; i ++ )
		fac[i] = fac[i-1] * i % MOD; 

	for( int i = 0; i <= lim; i ++ )
		inv_fac[i] = ksm( fac[i], MOD - 2 );
		
//	printf( "%lld, %lld\n", fac[10], inv_fac[10] );  
}

inline ll C( int n, int m ) { return fac[n] * inv_fac[m] % MOD * inv_fac[n-m] % MOD; } 

inline ll solve( int i ) 
{
	ll ret = 0;  
	
	for( int j = 0; j <= sum[i] && ( ( j << 1 ) <= n ); j ++ )
	{
		if( j & 1 ) 
			ret = dec( ret, C( sum[i], j ) * g[n-2*j][k] % MOD ); 
		else ret = add( ret, C( sum[i], j ) * g[n-2*j][k] % MOD );  
	}
	
	return ret; 
}

int main()
{
	k = read(); n = read(); 
	
	calc_fac(); 
	
	for( int i = 1; i <= n; i ++ )
		g[i][1] = 1; 
	
	for( int i = 1; i <= k; i ++ )
		g[1][i] = i, g[0][i] = 1; 
	
	for( int i = 2; i <= n; i ++ )
		for( int j = 2; j <= k; j ++ )
			g[i][j] = add( g[i-1][j], g[i][j-1] ); 
	
	memset( sum, 0, sizeof( sum ) ); 
	for( int i = 1; i <= k; i ++ )
		for( int j = i; j <= k; j ++ )
			sum[i+j] ++; 
			
	for( int i = 2; i <= k<<1; i ++ )
		printf( "%lld\n", solve( i ) );
		
	return 0; 
}

Measured memory_bytes: 93440
def abc070_d():
    import sys
    sys.setrecursionlimit(10010010)
    read = sys.stdin.buffer.read
    inp = iter(map(int, read().split()))

    n = next(inp)
    adjlist = [[] for _ in range(n)]
    for _ in range(n-1):
        a = next(inp) - 1
        b = next(inp) - 1
        c = next(inp)
        adjlist[a].append((b, c))
        adjlist[b].append((a, c))

    q = next(inp)
    k = next(inp) - 1

    dist = [-1] * n

    def dfs(x:int, d:int):
        dist[x] = d
        for nx, nd in adjlist[x]:
            if dist[nx] != -1: continue
            dfs(nx, d + nd)

    dfs(k, 0)

    for _ in range(q):
        x = next(inp) - 1
        y = next(inp) - 1
        ans = dist[x] + dist[y]
        print(ans)

if __name__ == '__main__':
    abc070_d()

Measured memory_bytes: 188512
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3943024
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

bool cmp(pair<pair<LL, LL>, LL> a, pair<pair<LL, LL>, LL> b){
    if(a.first.first + a.first.second != b.first.first + b.first.second){
        return a.first.first + a.first.second < b.first.first + b.first.second;
    }
    return (a.second < b.second);
}

LL dp[1111][21111];
const int C = 20111;

int main(){
    
    // 1. 入力情報取得.
    vector<pair<pair<LL, LL>, LL>> vec;
    int N;
    scanf("%d", &N);
    vec.push_back({{-int(1e9), -1}, -1});
    for(int i = 0;i < N; i++){
        LL w, s, v;
        scanf("%lld %lld %lld", &w, &s, &v);
        vec.push_back({{w, s}, v});
    }
    
    // 2. dp更新.
    sort(vec.begin(), vec.end(), cmp);
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0;j <= C; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - vec[i].first.first >= 0 && vec[i].first.second >= j - vec[i].first.first){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - vec[i].first.first] + vec[i].second);
            }
        }
    }
    
    // 3. 出力.
    LL ans = 0;
    for(int j = 0; j <= C; j++) ans = max(ans, dp[N][j]);
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 166016
#include <iostream>
#include <string>

using namespace std;

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

  string s;
  cin >> s;

  int count[26] = {0};
  for (char c : s) {
    const int i = c - 'a';
    count[i]++;
    if (count[i] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;

    public static void main(String[] args) {
        int a = in.nextInt();
        int b = in.nextInt();
        out.println(IntStream.of(a + b, a - b, a * b).max().getAsInt());
    }
}


Measured memory_bytes: 27732
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  long long n;
  cin >> n;
  string s = "";

  while(n>0){
    n--;
    int o = n %26;
    s.push_back('a' + o);
    n/=26;
  }
  reverse(s.begin(), s.end());
  
  cout << s <<endl;
  
  return 0;
}

Measured memory_bytes: 3640