akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll n , q ;
	cin >> n >> q;
	vector<vector<ll>> KI(n);
	rep(i,n-1)
	{
		ll foo,fooo;
		cin >> foo >>fooo;
		foo--;fooo--;
		KI[foo].push_back(fooo);
		KI[fooo].push_back(foo);
	}
	vector<ll> cost(n,0);
	rep(i,q)
	{
		ll foo,fooo;
		cin >> foo >> fooo;
		foo--;
		cost[foo]+=fooo;
	}
	stack<ll> S;

	vector<ll> ans(n,-1);
	S.push(0);
	ans[0]=cost[0];
	ll ncost=0;
	while(!S.empty())
	{
		ll now = S.top();
		//if(ans[now]==-1)ncost+=cost[now];
		//cout<<now<<endl;
		ll next = -1;
		rep(i,KI[now].size())
		{
			if(ans[KI[now][i]]==-1)
			{
				S.push(KI[now][i]);
				next = KI[now][i];
				cost[next] += cost[now];
				ans[KI[now][i]]=1;
			}
		}
		//cout<<next<<endl;
		if(next==-1)
		{
			S.pop();
		}
		
	}

	rep(i,n)
	{
		cout<<cost[i]<<' ';
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 19440
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
const int MX = 210000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	
	int n, x, y; cin >> n >> x >> y;
	vector<vi> b(n);
	rep(i, n){
		int c, w; cin >> c >> w;
		b[c - 1].pb(w);
	}
	
	rep(i, n) sort(all(b[i]));
	sort(all(b));
	for(int i = n - 1; i >= 0; i--) if(!b[i].size()){
		b.erase(b.begin(), b.begin() + i + 1);
		break;
	}
	if(b.size() == 1){
		cout << 1 << endl;
		return 0;
	}
	
	//dbg(b);
	
	vi v;
	rep(i, b.size()){
		int p = i ? b[0][0] : b[1][0];
		if(p + b[i][0] > y) continue;
		int num = upper_bound(all(b[i]), max(x - b[i][0], y - p)) - b[i].begin();
		if(num) v.pb(num);
	}
	
	ll ans = 1;
	int sum = accumulate(all(v), 0);
	for(int i : v){
		ans = ans * C(sum, i) % mod;
		sum -= i;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 14844
N,P = list(map(int,input().split()))
mylist = []
roop  = int((10**12)**(1/N))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

flag = 0
tmp = 1
if N ==1:
    print(P)
else:
    Primelis = primes(roop)
    for i in Primelis:
        flag = 0
        tmp = 1
        while flag==0:
            if P%(i**N)==0:
                P = P/(i**N)
                tmp = tmp*i
            else:
                mylist.append(tmp)
                flag = 1
    ans = 1
    L = len(mylist)
    for i in range(L):
        ans = ans*mylist[i]
    print(ans)


Measured memory_bytes: 14036
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

bool is_prime[1001];
int power_num[1001];
int main(){
    int N;
    cin >> N;

    for(int i = 2; i <= N; i++){
        is_prime[i] = true;
    }

    for(int i = 2; i <= N; i++){
        if(!is_prime[i]){
            continue;
        }
        for(int j = 2 * i; j <= N; j += i){
            is_prime[j] = false;
        }
    }

    for(int i = 2; i <= N; i++){
        int tmp = i;
        for(int j = 2; j <= N; j++){
            if(is_prime[j]){
                while(tmp % j == 0){
                    tmp /= j;
                    power_num[j] ++;
                }
            }
            if(tmp == 1){
                break;
            }
        }
    }

    long long ans = 1;
    for(int i = 2; i <= N; i++){
        if(is_prime[i]){
            ans = ans * (power_num[i] + 1) % 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
K, X = map(int, input().split())

if (X + (K - 1)) <= 1000000:
    ans = [str(i) for i in range(X - (K - 1), X + (K - 1) + 1)]

elif (X - (K - 1)) >= -1000000:
     ans = [i for i in range(X - (K - 1), X + (K - 1) + 1)]

print(' '.join(ans))



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

int N;
ll ret = 0;

void dfs(ll cur, int mask) {

	if (cur > N) return;
	if (mask == 7) ret++;
	dfs(cur * 10 + 7, mask | 4);
	dfs(cur * 10 + 5, mask | 2);
	dfs(cur * 10 + 3, mask | 1);
}


void solve() {
	cin >> N;
	dfs(0, 0);
	cout << ret << endl;
}


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


Measured memory_bytes: 256
h, w = map(int, input().split())
Mod = 10**9 + 7
a = [["#"]*(w+1)]
for i in range(h):
    a.append(["#"])
    a[i+1]+=input()
a[1][1] = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] =="#":
            continue
        elif i==j==1:
            a[i][j] = 1
            continue
        elif a[i-1][j]=="#" and a[i][j-1]=="#":
            a[i][j] = 0
            continue
        elif a[i-1][j] =="#":
            a[i][j] = a[i][j-1]
            continue
        elif a[i][j-1] == "#":
            a[i][j] = a[i-1][j]
            continue
        else:
            a[i][j] = a[i-1][j] + a[i][j-1]
            continue
print(a[h][w]%Mod)

Measured memory_bytes: 157404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	
	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];

	bool ok = false;

	rep(i, n)rep(j, n) {

		swap(a[i], a[j]);

		bool increse = true;
		rep(k, n - 1)if (a[k] > a[k + 1])increse = false;
		if (increse)ok = true;

		swap(a[i], a[j]);

	}

	cout << (ok ? "YES" : "NO") << endl;

}

Measured memory_bytes: 256
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())

for i in range(10 ** 5):
	ans = x + i
	if is_prime(ans):
		print(ans)
		break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
ll s,n;
ll si[110],val[110];
ll dp[110][(int)1e5+1];
ll solve (int index , int sii){
    if(index == n)return 0;
    ll &re = dp[index][sii];
    if(re != -1 )return re;
    return re = max((sii+si[index]<= s )? val[index] + solve(index+1,sii+si[index]) : 0 , solve(index+1,sii));
}
int main(){
    fastIO;
    int t(1);
    //cin >> t;
    while (t--){
        memset(dp,-1,sizeof dp);
        cin>>n>>s;
        for(int i = 0 ; i < n  ; i++)cin>>si[i]>>val[i];
        cout<<solve(0,0)<<endl;
    }
}


Measured memory_bytes: 86272
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
h = "";
i = j + 1;
	}
	return vec;
}
template<typename T>
void print_vec(vector<T>a) {
	for (int i = 0; i < a.size(); i++) {
		cout << (i == 0 ? "" : " ") << a[i];
	}
	cout << endl;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
signed main() {
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < s.size(); ) {
		while (i < s.size() && !(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')) i++;
		int j = i;
		while (j<s.size()&&(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T')) {
			j++;
		}
		sum = max(sum, j - i);
		i = j;
	}
	cout << sum << endl;
}

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

using namespace std;

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

    int ans = 0;
    for (int i = a; i <= b; ++i) {
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());
        if (s == t) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		String S = scanner.next();
 		int day = 0;
 		if (S.equals("SAT")) {
 			day = 1;
 		} else if (S.equals("FRI")) {
 			day = 2;
 		} else if (S.equals("THU")) {
 			day = 3;
 		} else if (S.equals("WED")) {
 			day = 4;
 		} else if (S.equals("TUE")) {
 			day = 5;
 		} else if (S.equals("MON")) {
 			day = 6;
 		} else if (S.equals("SUN")) {
 			day = 7;
 		}
 		System.out.println(day);
	}
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    ll n,k,t,i,cnt,ans=20;
    cin>>n;
    k=sqrt(n);
    for(i=1; i<=k; i++)
    {
        if(n%i==0)
        {
            t=max(i,n/i);
            cnt=0;
            while(t)
            {
                cnt++;
                t/=10;
            }
            ans=min(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxp = 55555;
bool prime[maxp+1];

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    memset(prime,1,sizeof(prime));
    prime[0] = prime[1] = false;
    for (int i = 2; i*i <= maxp; i++) {
        if (prime[i]) {
            for (int j = i*i; j <= maxp; j += i)
                prime[j] = false;
        }
    }
    map<int,VI> ans;
    FOR(i,2,maxp+1) if (prime[i])
        ans[i%10].push_back(i);
    int N;
    while (cin >> N) {
        FOR_ALL(x,ans) {
            const VI& A = x->second;
            FOR(i,0,N)
                cout << A[i] << ' ';
            cout << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int c[4][4];

signed main()
{
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin>>c[i][j];
        }
    }
    
    if(c[1][1]+c[2][2]+c[3][3]==c[1][2]+c[2][3]+c[3][1] and
       c[1][1]+c[2][2]+c[3][3]==c[1][3]+c[2][1]+c[3][2])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
 
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

count = 0

for i in range(n):
    if a[i] >= b[i]:
        a[i] -= b[i]
        count += b[i]
        b[i] = 0
        continue
    
    else:
        b[i] -= a[i]
        count += a[i]
        a[i] = 0

        if a[i+1] >= b[i]:
            a[i+1] -= b[i]
            count += b[i]
            b[i] = 0
            continue
        
        else:
            b[i] -= a[i+1]
            count += a[i+1]
            a[i+1] = 0
            continue

print(count)

Measured memory_bytes: 18624
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int mini=INF_INT,A,N,ans;

int main(){
    cin>>N;
    rep(i,N){
        cin>>A;
        if(mini>=A){
            ans++;
            mini=A;
        }
    }
    out(ans);
    
}

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

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int main(){

    int N;
    cin>>N;
    long ans=0;
    int a;

    FOR(i,0,N){
        cin>>a;
        ans += (a-1);
    }
    put(ans);
}

Measured memory_bytes: 256
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
start = 0
end = 1
a_ls = [bin(i)[2:].zfill(20) for i in a_ls] + ["2" * 20]
dic = {i : 0 if j == "0" else 1 for i,j in enumerate(a_ls[0])}
cnt = 0
while start < n and end <= n:
    flg = True
    a = a_ls[end]
    for i, j in enumerate(a):
        if dic[i] + int(j) > 1:
            flg = False
    if flg:
        for i, j in enumerate(a):
            dic[i] += int(j)
        end += 1
    else:
        cnt += (end - start - 1)
        for i, j in enumerate(a_ls[start]):
            dic[i] -= int(j)
        start += 1
        if end == start:
            for i, j in enumerate(a):
                dic[i] += int(j)
            end += 1
print(cnt + n)

Measured memory_bytes: 106288
N = int(input())
S = input().rstrip()

def solve(N, S):
    n_close = 0
    max_n_close = 0
    for s in S:
        if s == ')':
            n_close += 1
            max_n_close = max(max_n_close, n_close)
        if s == '(':
            n_close -= 1
    SS = '(' * max_n_close + S
    n_open = SS.count('(')
    n_close = SS.count(')')
    SSS = SS + ')' * (n_open - n_close)
    return SSS

print(solve(N, S))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = GetInput_long();
            long _nowData = NK[0];
            long _K=NK[1];

            _nowData = _nowData % _K;

            long _before = 0;
            long _beforebefore = 0;
            while (true)
            {
                _nowData = Math.Abs(_K - _nowData);
                if (_beforebefore == _nowData)
                {
                    _nowData = (_before < _beforebefore) ? _before : _beforebefore;
                    break;
                }
                else
                {
                    _beforebefore = _before;
                    _before = _nowData;
                }
            }

            Console.WriteLine(_nowData);
        }

        #region input
        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        #endregion
    }
}

Measured memory_bytes: 11092
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,m = nm()
print(n*(n-1)//2 + m*(m-1)//2)


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

int N;
vector<int> c, s, f;

int main() {
    cin >> N;
    c.resize(N-1); s.resize(N-1); f.resize(N-1);
    for (int i = 0; i < N-1; i++) scanf("%d%d%d", &c[i], &s[i], &f[i]);

    for (int i = 0; i < N; i++) {
        int t = 0;
        for (int j = i; j < N-1; j++) {
            if (t<s[j]) t=s[j];
            else if (!(t%f[j]));
            else t += f[j]-t%f[j];
            t += c[j];
        }
        printf("%d\n", t);
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()


Measured memory_bytes: 6716
def solve():
    N = int(input())
    c = [0, 0, 0, 0]
    for _ in range(N):
        s = input()
        if s == 'AC':
            c[0] += 1
        elif s == 'WA':
            c[1] += 1
        elif s == 'TLE':
            c[2] += 1
        elif s == 'RE':
            c[3] += 1
    print('AC x', c[0])
    print('WA x', c[1])
    print('TLE x', c[2])
    print('RE x', c[3])



if __name__ == "__main__":
    solve()

Measured memory_bytes: 9212
import collections

def get_input_line():
    return list(map(int, input().split()))
n, k = get_input_line()
p_list = get_input_line()

def calc_dice_score(p):
    return 0.5*(p+1)

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0] * n

max_score = 0
tmp_score = 0

for i in range(k):
    dice_scores[i] = 0.5*(p_list[i]+1)
    tmp_score += dice_scores[i]

max_score = tmp_score
for i in range(1, n- k + 1):
    dice_scores[i+k-1] = 0.5*(p_list[i+k-1]+1)
    tmp_score -= dice_scores[i-1]
    tmp_score += dice_scores[i+k-1]
    max_score = max(max_score, tmp_score)
print(max_score)

Measured memory_bytes: 25564
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
char D[10]; int n, k;
int main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) { char F; cin >> F; D[F - '0'] = 1; }
	for (int i = n; i < 100000; i++) {
		string S = to_string(i);
		for (int j = 0; j < S.size(); j++) {
			if (D[(S[j] - '0')] == 1)goto E;
		}
		cout << i << endl; break; E:;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int j=0;
  for(int i=0;i<3;i++)
    if(s[i]=='A')
      j++;
  if(j==1||j==2)
    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 db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);
ll n,a,b,c,d;

signed main(){
    cin>>n>>a>>b>>c>>d;
    n--;
    if(b<a)swap(a,b);
    b-=a;

    if(c==d){
     for(int i=0;i <= n;i++)
     {
       if(c*n-i*(c+d) <= b && b <= d*n-i*(c+d)){
         cout<<"YES"<<endl;
         return 0;
       }
     }
     cout<<"NO"<<endl;
     return 0;
    }

    if((n)*(d-c)>=c+d){
      if(b<= d*n)cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
    }else{
     for(int i=0;i <= n;i++)
     {
       if(c*n-i*(c+d) <= b && b <= d*n-i*(c+d)){
         cout<<"YES"<<endl;
         return 0;
       }
     }
     cout<<"NO"<<endl; 
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int a,b,c;
  cin>>a>>b>>c;
  if(a!=b&&a!=c&&b!=c)
    cout<<3;
    if(a==b&&a!=c&&b!=c||a!=b&&a==c&&b!=c||a!=b&&a!=c&&b==c)
    cout<<2;
    if(a==b&&a==c&&b==c)
    cout<<1;
    return 0;
}


Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-16 20:26:49
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
#define pii std::pair<i64,i64>
const int N=300010;
i64 n,l,x[N],t[N],ans,s1,s2;
pii a[N];
#define v1 first
#define v2 second
int main()
{
	n=read(); l=read();
	fr(i,1,n) x[i]=read();
	fr(i,1,n) t[i]=read();
	fr(i,1,n)
	{
		ans+=t[i]/(2*l); t[i]=t[i]%(2*l);
		if(!t[i]) continue;
		ans++;
		a[i]=pii(2*(l-x[i])>=t[i],2*x[i]>=t[i]);
//		printf("%d %d\n",a[m].v1,a[m].v2);
	}
	ans+=(a[n].v1==0);
	fr(i,1,n-1)
		if(s1&&a[i].v1)
		{
			if(a[i].v2) s2++;
			s1--; ans--;
		}
		else if(a[i].v1&&!a[i].v2)
		{
			if(s2){ s2--; s1++; }
		}
		else if(a[i].v2) s1++;
//	fr(i,1,m) printf("%d %d\n",int(a[i].v1),int(a[i].v2));
	printf("%lld\n",ans*l*2);
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main(void){

    static int n,m,x,left,right ;
    scanf ("%d%d%d",&n,&m,&x) ;
    
    for (int i=0; i<m; i++ ){
        
        int a[i] ;
        scanf ("%d",&a[i]) ;
        
        if ( a[i]<x ){
            
            left++ ;
            
        } else {
            
            right++ ;
            
        }
    }
    
    if ( left<right ){
        
        printf ("%d\n",left) ;
        
    } else {
        
        printf ("%d\n",right) ;
        
    }

    return 0 ;
}

Measured memory_bytes: 128
///int ->(-2147483648<->2147483647)
///unsigned int(0<->4294967295)
///long long int (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
///unsigned long long int (0 to 18,446,744,073,709,551,615)
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<stack>
#include<cstring>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<iomanip> ///setprecision
#include<cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define OPEN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","r",stdin)
#define Precision cout<<fixed, cout<<setprecision(10);
#define INF 1000000000
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define pdd pair<double,double>
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vd vector<double>
#define sci(value) scanf("%d%*c",&value)
#define scl(value) scanf("%lld%*c",&value)
#define pi  (2*acos(0))
#define pb push_back
#define valid(value123,value234,limitrow,limitcol) value123>=0&&value123<limitrow&&value234>=0&&value234<limitcol
//int fx[]= {0,0,1,-1,-1,1,-1,1};//kings move
//int fy[]= {1,-1,0,0,-1,1,1,-1};//kings move
//int fx[]={-2,-2,-1,-1, 1,1, 2,2};  // Knights Move
//int fy[]={-1, 1,-2, 2,-2,2,-1,1}; // Knights Move
//ll powFunction(ll a,ll b){if(b==0)return 1;ll re=powFunction(a,b/2);re=(re*re);if(b&1)re=(re*a);return re;}
///ll digitSum(ll a){ll ans=0;while(a){ans+=(a%10);a/=10;}return ans;}

#define MX 100005
#define mod 1000000007
/// idea : if there are n stones in the pile and I can take several stones from this, after that with these remaining stones second player will loose the game then first player win otherwise he will loose.
bool dp[MX];
int main()
{
    int n,k;
    sci(n),sci(k);
    vector<int>arr(n);
    for(int &x:arr)
    {
        sci(x);
    }
    for(int stones = 0;stones <= k; stones++)
    {
        for(int x:arr)
        {
            if(stones >= x && !dp[stones-x])
            {
                dp[stones] = true;
            }
        }
    }
    printf("%s\n",dp[k]?"First":"Second");
}



Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int [][]eye=new int[4][2];
		while(sc.hasNext()){
			for(int i=0;i<2;i++){
				double p=sc.nextDouble();
				if(p<0.2)eye[3][i]++;
				else if(p<0.6)eye[2][i]++;
				else if(p<1.1)eye[1][i]++;
				else eye[0][i]++;
			}
		}
		for(int i=0;i<4;i++){
			System.out.println(eye[i][0]+" "+eye[i][1]);
		}
	}
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



int main() {
	ll r, c, n;
	scanf("%lld%lld%lld", &r, &c, &n);
	int i, j;
	vector< pair<pll, pll> > vp;
	for (i = 0; i < n; i++) {
		ll x1, x2, y1, y2;
		scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
		if ((x1 == 0 || x1 == r || y1 == 0 || y1 == c) &&
			(x2 == 0 || x2 == r || y2 == 0 || y2 == c)) {
			pii temp1 = pll(x1, y1);
			pii temp2 = pll(x2, y2);
			vp.push_back(make_pair(temp1, temp2));
		}
	}
	n = vp.size();
	vector<pll> l1, l2, l3, l4;
	for (i = 0; i < n; i++) {
		ll x1 = vp[i].first.first;
		ll x2 = vp[i].second.first;
		ll y1 = vp[i].first.second;
		ll y2 = vp[i].second.second;
		if (x1 == 0) {
			l4.push_back(pll(y1,i));
		}
		else if (x1 == r) {
			l2.push_back(pll(y1,i));
		}
		else if (y1 == 0) {
			l1.push_back(pll(x1, i));
		}
		else if (y1 == c){
			l3.push_back(pll(x1, i));
		}

		if (x2 == 0) {
			l4.push_back(pll(y2, i));
		}
		else if (x2 == r) {
			l2.push_back(pll(y2, i));
		}
		else if (y2 == 0) {
			l1.push_back(pll(x2, i));
		}
		else {
			l3.push_back(pll(x2, i));
		}
	}
	sort(l1.begin(), l1.end());
	sort(l2.begin(), l2.end());
	sort(l3.begin(), l3.end());
	reverse(l3.begin(), l3.end());
	sort(l4.begin(), l4.end());
	reverse(l4.begin(), l4.end());
	ll cnt = 0;
	vl used(n, false);
	vector<pll> l;
	l.insert(l.end(), l1.begin(), l1.end());
	l.insert(l.end(), l2.begin(), l2.end());
	l.insert(l.end(), l3.begin(), l3.end());
	l.insert(l.end(), l4.begin(), l4.end());
	stack<int> st;
	/*
	for (i = 0; i < 2 * n; i++) {
		cout << l[i].first << l[i].second << endl;
	}
	*/
	for (i = 0; i < 2 * n; i++) {
		if (!used[l[i].second]) {
			st.push(l[i].second);
			used[l[i].second] = true;
		}
		else {
			if (st.top() == l[i].second) {
				st.pop();
				used[l[i].second] = false;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 17644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod 1000000007
ll dp[5005][2005],ret;
int n,m,k;
int main(){
	cin>>n>>m>>k;
	dp[0][0] = 1;
	for(int i=0;i<5004/(k-1);i++){
		for(int j=0;j<=m;j++){
			if(dp[i][j] == 0) continue;
			for(int w=0;w<k;w++){
				if(j+w > m) break;
				dp[i+1][j+w] = (dp[i+1][j+w]+dp[i][j])%mod;
				if(w && (k-1)*(i+1)+1-(j+w) <= n && (j+w)%(k-1) == m%(k-1)){
					ret += dp[i][j];
				}
			}
		}
	}
	cout<<ret%mod<<endl;
}

Measured memory_bytes: 77184
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;
char s[101][101];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,K = 50;
	cin >> A >> B;
	A--;B--;
	for(int i=0;i<2*K;i++){
		for(int j=0;j<2*K;j++){
			if(i<K)s[i][j]='#';
			else s[i][j] ='.';
		}
	}
	//A個白い点を作る
	for(int i=0;i<2*K;i+=2){
		for(int j=0;j<2*K;j+=2){
			if(A){
				s[i][j] = '.';
				A--;
			}else break;
		}
		if(!A)break;
	}
	for(int i=1;i<2*K;i+=2){
		for(int j=0;j<2*K;j+=2){
			if(B){
				s[i+K][j] = '#';
				B--;
			}else break;
		}
		if(!B)break;
	}
	cout << 2*K << " " << 2*K << endl;
	rep(i,2*K){
		rep(j,2*K)cout << s[i][j];
		cout << endl;
	}
}

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

int maximum(int a,int b){
    return a>b?a:b;
}

int main() {
    //cout<<"givr n"<<endl;
	int n;
	cin>>n;
	int matrix[n][3];
	for(int i=0;i<n;i++){
	    //cout<<"give row"<<endl;
	    for(int j=0;j<3;j++){
	        cin>>matrix[i][j];
	    }
	}
	
	int dp[n][3];
	dp[0][0]=matrix[0][0];dp[0][1]=matrix[0][1];
	dp[0][2]=matrix[0][2];
	
	//int max=dp[0][0]>dp[0][1]?(dp[0][0]>dp[0][2]?dp[0][0]:dp[0][2]):(dp[0][1]>dp[0][2]:dp[0][1]:dp[0][2]);
	for(int i=1;i<n;i++){
	    for(int j=0;j<3;j++){
	        dp[i][j]=matrix[i][j]+maximum(dp[i-1][(j+1)%3],dp[i-1][(j-1>=0?j-1:3+j-1)%3]);
	        //max=dp[i][j]>max?dp[i][j]:max;
	    }
	}
	
	cout<<maximum(dp[n-1][0],maximum(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 5948
package main

import (
	"fmt"
)

func main() {

	var S string
	fmt.Scanf("%s", &S)

	var count int
	for i := 0; i < len(S)-1; i++ {
		if S[i] != S[i+1] {
			count++
		}
	}

	if count > 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1832
#include <cstdio>

int main(){
    float xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
    while(scanf("%f%f%f%f%f%f%f%f",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2)!=-1){
        if(xa1<=xb2 && xb1<=xa2 && ya1<=yb2 && yb1<=ya2) printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define ll long long int
using namespace std;
 
vector<ll> vec;
vector<pair<ll,ll> > vp;
ll mini;
 
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

map<ll,ll> has,mark;
set<ll> st;
 
ll ar[5000002],br[5123456];

const ll MOD = 1e9 + 7;
 
 
 
int main() 
{
	ll c,i,p,q,d,k,len,y,j,a,b,t,ans,flag,n,m,g=0,res=0,sum=0,e,f,r,minm=99999999999,maxm=-999999999999,x,hr,secmaxm=-999999999999,z;
	c=0;
//	freopen("output.out","w",stdout);
	string str,ptr,dtr;
	char ch,prev;
	
	set<ll>::iterator it;
	
	cin>>a>>b;
	
	d=b;
	
	while(d)
	{
		d/=10;
		c++;
	}
	
	for(i=1;i<=c;i++)
	a*=10;
	
	a+=b;
	
	d=sqrt(a);
	
	if((d*d)==a)
	cout<<"Yes";
	else
	cout<<"No";
	
	return 0;
}   

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
_, S = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = tuple(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
for a in A:
    dp[0]+=1
    for i in range(S,a-1,-1):
        dp[i]+=dp[i-a]
        dp[i]%=mod
    ans+=dp[-1]
    ans%=mod
    #print(dp)

print(ans)


Measured memory_bytes: 9340
#include <iostream>
#include <queue>

using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int INFTY = (1<<21);

int n;
int M[N][N] = {0};
int colur[N] = {WHITE};
int d[N];

void bfs(int s)
{
    queue <int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while(!q.empty())
    {
        u = q.front();q.pop();
        for(int v=0;v<n;v++)
        {
            if(M[u][v]==0) continue;
            if(d[v]!=INFTY) continue;
            d[v] = d[u]+1;
            q.push(v);
        }
    }

    for(int i=0;i<n;i++)
        cout << i+1 << " " << ( (d[i]==INFTY) ? -1:d[i] ) << endl;
}

int main()
{
    int u,v,i,j,k;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> u >> k;
        u--;
        for(j=0;j<k;j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}


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

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

    int A[N];
    rep(i, N) cin >> A[i];

    bool inc = false, dec = false;
    int ans = 1;

    rep(i, N-1) {
        if (A[i+1] > A[i]) inc = true;
        else if (A[i+1] < A[i]) dec = true;

        if (inc && dec) {
            ans++;
            inc = false;
            dec = false;
        }
    }

    cout << ans << endl;

   return 0;
}

Measured memory_bytes: 640
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
else:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Measured memory_bytes: 14116
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int stick = sc.nextInt();
        int bar = sc.nextInt();

        int[] amida = new int[stick];

        for(int i = 0; i < stick; i++){
            amida[i] = i;
        }

        for(int i = 0; i < bar; i++){
            String line = sc.next();

            int a = 0;
            int b = 0;

            int index = 0;
            for(; index < line.length(); index++){
                if(line.charAt(index) == ','){
                    index++;
                    break;
                }else{
                    a *= 10;
                    a += Integer.parseInt("" + line.charAt(index));
                }
            }

            for(; index < line.length(); index++){
                b *= 10;
                b += Integer.parseInt("" + line.charAt(index));
            }

            a--;
            b--;

            int c = amida[a];
            int d = amida[b];

            amida[a] = d;
            amida[b] = c;
        }

        for(int i = 0; i < stick; i++){
            System.out.println(amida[i]+1);
        }
 
    }
}

Measured memory_bytes: 17184
n = int(input())

count = 0
def dfs(x):
    global count
    if int(x) > n:
        return 0
    
    for i in ('753'):
        dfs(x+i)
    
    check =  True
    for j in ('753'):
        if x.find(j) == -1:
            check = False
    if check:
        count += 1
        
    return count
print(dfs('0'))

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;

int main() {
	cin >> N>>K;
	M = N%K;
	cout << min(M,abs(K-M))<<endl;
	return 0;
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)

int N,M,x[1501],y[1501];

int main(){
	while(cin>>N>>M&&N){
		int ans=0,l;
		x[0]=0;y[0]=0;
		rep(i,N){cin>>l;y[i+1]=y[i]+l;}
		rep(i,M){cin>>l;x[i+1]=x[i]+l;}
		map<int,int> m;
		rep(i,N+1)rep2(j,i+1,N+1)m[y[j]-y[i]]++;
		rep(i,M+1)rep2(j,i+1,M+1)ans+=m[x[j]-x[i]];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,k;cin >>a  >>b >> c >> k;
    if(k<=a+b)cout << min(a,k);
    else cout << a-(k-(a+b));
    }

Measured memory_bytes: 3640
from collections import deque
def solve():
    N = int(input())
    ans = 0
    d = deque([3,5,7])
    while len(d):
        n = d.popleft()
        for i in range(3,8,2):
            a = n*10+i
            if a<=N:
                if len(set(list(str(a))))==3:
                    ans += 1
                d.append(a)
    return ans
print(solve())

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    cout << ("ABC"+s) << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct Point{
    int x, y;
};

int main(){
    int w, h, n; cin >> w >> h >> n;
    
    Point a{0, 0};
    Point b{w, h};

    for(int i=0; i<n; i++){
        int s, t, p; cin >> s >> t >> p;
        if(p == 1) a.x = max(s, a.x);
        if(p == 2) b.x = min(s, b.x);
        if(p == 3) a.y = max(a.y, t);
        if(p == 4) b.y = min(b.y, t);
    }

    if(a.x > b.x || a.y > b.y) cout << 0 << endl;
    else cout << (b.x - a.x) * (b.y - a.y) << endl;
}

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

int main() {
    int A, B, C, K; cin >> A >> B >> C >> K;
    int cnt = 0;
    while (A >= B) { B *= 2; cnt++; }
    while (B >= C) { C *= 2; cnt++; }
    if (cnt <= K) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3580
public class Main {
	private static int h;
	private static int w;
	private static int k;
	private static boolean[][] c;
	private static int[][] redmemo;

	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		k = sc.nextInt();
		String[] cTmp = new String[h];
		c = new boolean[h][];
		redmemo = new int[h][];
		int sousu = 0;
		for (int i = 0; i < cTmp.length; i++) {
			cTmp[i] = sc.next();
		}

		for (int i = 0; i < h; i++) {
			c[i] = new boolean[w];
			redmemo[i] = new int[w];
			for (int j = 0; j < w; j++) {
				if ((cTmp[i].charAt(j) == '#')) {
					sousu++;
					c[i][j] = true;
				}
			}
		}
		int ret = 0;
		if (sousu == k) {
			ret++;
		}
		ret += count(0, sousu);
		System.out.println(ret);
	}

	public static int count(int index, int midSu) {

		if (midSu < k) {
			return 0;
		} else if (index >= w + h) {
			return 0;
		}
		int ret = 0;
		ret += count(index + 1, midSu);

		if (index < h) {
			for (int j = 0; j < w; j++) {
				if (redmemo[index][j] == 0 && c[index][j]) {
					midSu--;
				}
				redmemo[index][j]++;
			}
		} else {
			for (int i = 0; i < h; i++) {
				if (redmemo[i][index - h] == 0 && c[i][index - h]) {
					midSu--;
				}
				redmemo[i][index - h]++;
			}
		}
		if (midSu == k) {
			ret++;
		}
		ret += count(index + 1, midSu);
		if (index < h) {
			for (int j = 0; j < w; j++) {
				redmemo[index][j]--;
				if (redmemo[index][j] == 0 && c[index][j]) {
					midSu++;
				}
			}
		} else {
			for (int i = 0; i < h; i++) {
				redmemo[i][index - h]--;
				if (redmemo[i][index - h] == 0 && c[i][index - h]) {
					midSu++;
				}
			}
		}
		return ret;
	}

}

Measured memory_bytes: 39012
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e3;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
int N,M,a[MAX+2],b[MAX+2],c[MAX+2],dist[100][100];

void solve(){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) dist[i][j]=0;
            else dist[i][j]=INF;
        }
    }
    for(int i=0;i<M;i++){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }
    //ワーシャルフロイド
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++)
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
        }
    }
    int ans = M; //最短経路に含まれていない辺の数
    for(int i=0;i<M;i++){
        bool shortest = false;
        for(int j=0;j<N;j++){
            if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
        }
        if(shortest) ans--;
    }
    cout<<ans<<"\n";
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>M;
    
    for(int i=0;i<M;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--; b[i]--;
    }
    solve();
    
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

ans = 'Yes'
for i in range(n//2):
   if s[i] != s[n-1-i]:
      ans = 'No'

t = s[:n//2]
m = len(t)
for i in range(m//2):
   if t[i] != t[m-1-i]:
      ans = 'No'

t = s[(n+2)//2:]
m = len(t)
for i in range(m//2):
   if t[i] != t[m-1-i]:
      ans = 'No'

print(ans)


Measured memory_bytes: 3064