akhauriyash/Code-Regression huggingface dataset:
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

long long c[150][150];
int main(){
	FIO
	
	int n, m, o;cin >> n >> m >> o;
	long long a[n][m], b[m][o];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++)cin >> a[i][j];
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < o; j++)cin >> b[i][j];
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < o; k++){
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout << c[i][0];
		for(int j = 1; j < o; j++)cout << ' ' << c[i][j];
		cout << "\n";
	}
	return 0;
}



Measured memory_bytes: 3440
n=int(input())
p=list(map(int,input().split()))
a=0
for i in range(n-2):
    if (p[i+1]>p[i] and p[i+1]<p[i+2]) or (p[i+1]<p[i] and p[i+1]>p[i+2]):
        a+=1
print(a)

Measured memory_bytes: 3060
import java.util.*;
class Main{
    void solve(){
        int a, b;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        System.out.println((a>b) ? a-b : b-a);
    }
    public static void main(String[] args){ new Main().solve(); }
}


Measured memory_bytes: 26336
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 2e3 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

int r[N][N], l[N][N], u[N][N], d[N][N];

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int n, m;
    cin >> n >> m;
    string s[n];
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < m; ++j) {
            if (s[i][j] == '#') {
                cur = j + 1;
            } else {
                l[i][j] = j - cur;
            }
        }
        cur = m - 1;
        for (int j = m - 1; j >= 0; --j) {
            if (s[i][j] == '#') {
                cur = j - 1;
            } else {
                r[i][j] = cur - j;
            }
        }
    }
    for (int j = 0; j < m; ++j) {
        int cur = 0;
        for (int i = 0; i < n; ++i) {
            if (s[i][j] == '#') {
                cur = i + 1;
            } else {
                d[i][j] = i - cur;
            }
        }
        cur = n - 1;
        for (int i = n - 1; i >= 0; --i) {
            if (s[i][j] == '#') {
                cur = i - 1;
            } else {
                u[i][j] = cur - i;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i][j] != '#') {
                ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] + 1);
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 67328
import sys
input=sys.stdin.readline

n,k= map(int, input().split())
s = input().strip()

s.strip()
p = [0]
for i in range(n):
    if s[i] != s[p[-1]]:
        p.append(i)

X = []
for i in range(len(p)):
    if s[p[i]] == "1":
        li = i
        ri = i + 2 * k + 1
    else:
        li = i-1
        if li < 0:
            li = 0
        ri = i + 2 * k
    if ri > len(p)-1:
        x = n - p[li]
    else:
        x = p[ri] - p[li]
    X.append(x)
print(max(X))


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

int b()
{
    int k;
    std::string s;
    std::cin >> k >> s;
    
    std::string ans;
    if(s.length() <= k)
    {
        ans = s;
    }
    else
    {
        for(int i = 0; i < k; i++)
        {
            ans += s[i];
        }
        ans += "...";
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    b();
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;

const double eps = 1e-10 , pi = acos(-1.0);
inline int dcmp(double x) {
    return (x > eps) - (x < -eps);
}

struct Point {
    double x , y;
    Point (double x = 0 , double y = 0) : x(x) , y(y) {} 
    void input() {
        scanf("%lf%lf",&x,&y);
    }
    bool operator < (const Point& R) const{
        if (dcmp(x - R.x) == 0)
            return dcmp(y - R.y) < 0;
        return dcmp(x - R.x) < 0;
    }
    bool operator == (const Point& R) const{
        return dcmp(x - R.x) == 0 && dcmp(y - R.y) == 0;
    }
    Point operator + (const Point& R) const{
        return Point(x + R.x , y + R.y);
    }
    Point operator - (const Point& R) const{
        return Point(x - R.x , y - R.y);
    }
    Point operator * (const double& R) const{
        return Point(x * R , y * R);
    }
    Point operator / (const double& R) const{
        return Point(x / R , y / R);
    }
    double operator ^ (const Point& R) const{
        return x * R.y - y * R.x;
    }
    double operator % (const Point& R) const{
        return x * R.x + y * R.y;
    }
    double len() {
        return sqrt(*this % *this);
    }
};

int n;
int R[N];
double pos[N];


bool check(int k , double r) {    
    for (int i = 0 ; i < k ; ++ i) {
        Point A(pos[i] , R[i]);
        Point B(r , R[k]);
        if (dcmp((A - B).len() - R[i] - R[k]) < 0)
            return 0;
    }
    return 1;
}

int main() {
    double res = 0;
    scanf("%d" , &n);
    for (int i = 0 ; i < n ; ++ i) {
        scanf("%d" , &R[i]);
        double l = max((i ? pos[i - 1] : 0.0) , (double)R[i]) , r = 2e7 , m;
        for (int T = 0 ; T < 100 ; ++ T) {
            m = 0.5 * (l + r);
            if (check(i , m))
                r = m;
            else
                l = m;
        }
        pos[i] = r;
        res = max(res , pos[i] + R[i]);
    }
    printf("%.10f\n" , res);
    return 0;
}

Measured memory_bytes: 1232
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>


using namespace std;
using ll=long long;


int solve(int n, ll a, ll b, ll c, ll d)
{
	if(a>b) swap(a, b);
	if(c>d) swap(c, d);
	b-=a;
	ll e=d-c;

	if(b>d*(n-1)) return 0;
	if(d==0)
	{
		return b==0;
	}
	if(e==0)
	{
		if(b%c) return 0;
		return (b%(2*c)==((n+1)%2)*c);
	}

	ll x=2*b/(c+d);
	if(((n-1)&1)!=(x&1)) if(x>0) x--; else x++;

//printf("x=%lld\n", x);
	if(e*(n-1)>=abs((c+d)*x-2*b)) return 1;
	x+=2;
	if(x>n-1) return 0;
	if(e*(n-1)>=abs((c+d)*x-2*b)) return 1;

	return 0;
}


int main(void)
{
	int n, a, b, c, d;

	while(scanf("%d%d%d%d%d", &n, &a, &b, &c, &d)==5)
	{
		printf("%s\n", solve(n, a, b, c, d)?"YES":"NO");
	}

	return 0;
}


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

int main(){
  ll a,c; double b;
  cin >>a >>b;
  c = b*100+0.5;
  ll ans = a*c/100;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto& e : v) cin >> e;

    map<int, int> odd {{-1, -1}}, even {{-1, -1}};
    for (int i = 0; i < n; i++) (i % 2 ? odd : even)[v[i]]++;

    vector<pair<int, int>> ov(begin(odd), end(odd)), ev(begin(even), end(even));
    sort(begin(ov), end(ov), [](auto a, auto b) { return a.second > b.second; });
    sort(begin(ev), end(ev), [](auto a, auto b) { return a.second > b.second; });

    int ans = 1e6;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            if (ov[i].first == ev[j].first) ans = min(ans, min(n - ov[i].second, n - ev[j].second));
            else ans = min(ans, (n + 1) / 2 - ov[i].second + n / 2 - ev[j].second);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
char ch;
int main()
{
	cin>>ch;
	if(ch-96==1||ch-96==5||ch-96==9||ch-96==15||ch-96==21) cout<<"vowel";
	else cout<<"consonant";
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define ifl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i++)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	    int n;
	    cin>>n;
	    int k;
	    cin>>k;
	    vector< int >v[n+1];
	    int vis[n+1];
	    f(i,n+1)vis[i]=1;
	    int a[n+1]={0};
	    for(int i=1;i<n+1;i++)
	    {
	        cin>>a[i];
	    }
	    
	    f(i,k)
	    {
	        int u,j;
	        cin>>u>>j;
	        v[u].pb(j);
	        v[j].pb(u);
	    }
	    fl(i,1,n+1)
	    {
	        for(auto x:v[i])
	        {
	            if(a[x]>=a[i])
	           { vis[i]=0;break;}
	        }
	    }
	    int s=0;
	   f(i,n+1)
	   s=s+vis[i];
	   
	   cout<<s-1<<bn;
	    
	}
	
	return 0;
}


Measured memory_bytes: 9552
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n;
int g[1010][1010];
int main() {
	cin >> n;
	int sum = 0;
	bool flg = false;
	if (n == 1) {
		cout << "Yes" << endl;
		cout << "2\n1 1\n1 1" << endl;
		return 0;
	}
	int num = -1;
	for (int i = 1; sum + i <= n; i++) {
		sum += i;
		if (sum == n) {
			flg = true;
			num = i + 1;
		}
	}
	if (flg) {
		cout << "Yes" << endl;
		cout << num << endl;
		int k = 1;
		for (int i = 1; i <= num; i++) {
			for (int j = 1; j <= num; j++) {
				if (i == j)continue;
				if (g[i][j] == 0)g[i][j] = g[j][i] = k++;
			}
		}
		for (int i = 1; i <= num; i++) {
			cout << num - 1;
			for (int j = 1; j <= num; j++) {
				if (i == j)continue;
				cout << " " << g[i][j];
			}
			cout << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	//system("pause");
}

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

void print_vec(vector<int> vec) {
    cout << "{";
    for(auto s: vec) cout << s << " ";
    cout << "}" << endl;
}

int main() {
    int N; cin >> N;
    vector<int> T(N+1);
    vector<P> A(N+1);
    T.at(0) = 0;
    A.at(0).first = 0;
    A.at(0).second = 0;
    for(int i = 1; i < N+1; i++) {
        cin >> T.at(i) >> A.at(i).first >> A.at(i).second;
    }

    //print_vec(T);

    //rep(i,N+1) cout << "(" << A.at(i).first << "," << A.at(i).second << ")" << endl;
    rep(i,N) {
        int dt = T.at(i+1) - T.at(i);
        int dx = abs(A.at(i+1).first-A.at(i).first);
        int dy = abs(A.at(i+1).second-A.at(i).second);
        if(dt < dx + dy) {
            cout << "No" << endl;
            return 0;
        }
        else {
            if(dt % 2 != (dx+dy)%2) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
a,b,x=map(float,input().split())
import math
if x<=a*a*b/2:
  print(math.degrees(math.atan(a*b*b/2/x)))
elif (-x/a+a*b)==0:
  print(0)
else:
  print(math.degrees(math.atan(2/a/a*(a*b-x/a))))

Measured memory_bytes: 9260
#include <stdio.h>
#define SMAX 100000
#define TMAX 50000

int n, q;
int S[SMAX], T[TMAX];

int binarySearch( int first, int last, int number )
{
        int mid;
        while ( first < last )
        {
                mid = ( first + last ) / 2;
                if ( T[number] > S[mid] )
                {
                        first = mid + 1;
                }
                else if ( T[number] < S[mid] )
                {
                        last = mid;
                }
                else if ( T[number] == S[mid] )
                {
                        return 1;
                }
        }

        return 0;
}

int Search( int s_size, int q_size )
{
        int first = 0;
        int last = s_size;
        int i = 0;
        int number = 0;
        for ( i = 0 ; i < q_size ; i = i + 1 )
        {
                first = 0;
                last = s_size;
                number = number + binarySearch( first, last, i );
        }

        return number;
}

int main()
{
        int i = 0;

        scanf( "%d", &n );
        for ( i = 0 ; i < n ; i = i + 1 )
        {
                scanf( "%d", &S[i] );
        }

        scanf( "%d", &q );
        for ( i = 0 ; i < q ; i = i + 1 )
        {
                scanf( "%d", &T[i] );
        }

        fprintf( stdout, "%d\n", Search( n, q ) );

        return 0;
}

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

#define rep(i,start,n) for(int i=start;i<(int)(n);i++)
#define rrep(i,n,end) for(int i=n-1;i>=end;i--)
#define each(it,v) for(auto it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

main()
{
        int a,b,c; cin>>a>>b>>c;
        if((b*10+c)%4==0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h,w,i,j;
    scanf("%d %d",&h,&w);
    int a[h+2][w+2];
    /*for(i=1;i<h+1;i++){
        for(j=1;j<w+1;j++){
            scanf("%c",&a[i][j]);
            if(j==w)
                getchar();

        }

    }*/
    for(i=0;i<h+2;i++){
        for(j=0;j<w+2;j++){
                if(i==0 || i==h+1 || j==0 || j==w+1)
                    a[i][j]='#';
                else
                    scanf(" %c",&a[i][j]);
        }
        //getchar();
    }

    for(i=0;i<h+2;i++){
        for(j=0;j<w+2;j++){
            printf("%c",a[i][j]);
        }
        printf("\n");
        //getchar();
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
const ll INF = 1e18L + 5;

vector<ll> pre; // preprocessing
// pre[mask] - score of group 'mask'
vector<ll> dp;

void rec(int i, const vector<int>& not_taken, ll score_so_far, int mask, int group) {
    if(i == (int) not_taken.size()) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }
    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}

// O(2^n * n^2 + 3^n)

int main() {
    int n;
    scanf("%d", &n);
    vector<vector<ll>> in(n, vector<ll>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%lld", &in[i][j]);
        }
    }
    pre.resize(1 << n);
    // O(2^n * n^2)
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) {
            if(mask & (1 << i)) {
                for(int j = i + 1; j < n; ++j) {
                    if(mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
        }
    }
    // dp[mask] - best total score if we grouped rabbits from 'mask' already
    dp.resize(1 << n, -INF);
    dp[0] = 0;
    // O(2^n * n + 3^n)
    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> not_taken;
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    printf("%lld\n", dp[(1<<n)-1]);
}


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



int main(){
    int n;
    cin >> n;
    int l[n];
    for(int i=0;i<n;i++) cin >> l[i];
    int ans = 0;

    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            for(int j=0;j<n;j++){
                if(l[i]!=l[k]&&l[i]!=l[j]&&l[j]!=l[k]){
                    if(abs(l[k]-l[j])<l[i]&&l[k]+l[j]>l[i]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans/6 << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
  int a,b,c,res;
  while(scanf("%d %d",&a,&b) != EOF){
    c = a+b;
    res = 0;
    for(;c > 0;c /= 10) res++;
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 600
import sys

def main():
    input = sys.stdin.readline
    S = int(input())

    a = S // 100
    b = S % 100

    if (a > 12 or a == 0) and 0 < b <= 12:
        return 'YYMM'
    elif 0 < a <= 12 and (b > 12 or b == 0):
        return 'MMYY'
    elif 0 < a <= 12 and 0 < b <= 12:
        return 'AMBIGUOUS'
    else:
        return 'NA'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
import sys
import math
from copy import deepcopy
from collections import deque
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)


def main():
    mod = 10**9 + 7

    N, K = map(int, input().split())

    blue = K
    red = N - K

    for i in range(1, K+1):
        b_p = cmb(blue, i)
        r_p = cmb(red, i - 1) + cmb(red, i) + cmb(red, i) + cmb(red, i + 1)

        if i == 1 and red == 0:
            print(1 % mod)
        else:
            print((b_p * r_p) % mod)


def cmb(n, r):
    if n < r or r == 0:
        return 0

    n -= 1
    r -= 1
    r = min(n - r, r)

    if r <= 0:
        return 1

    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


if __name__ == '__main__':
    main()



Measured memory_bytes: 4084
import sys
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Edge = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, input().split())
        Edge[u-1].append(v-1)
    S, T = map(int, input().split())
    S -= 1
    T -= 1
    DP = [[1000000000 for j in range(N)] for i in range(3)]
    q = []
    heapify(q)
    heappush(q, (0, S, 0)) #回数, 頂点, mod
    while q:
        nc, nn, nlevel = heappop(q)
        if DP[nlevel][nn] == 1000000000:
            DP[nlevel][nn] = nc
            for nextnode in Edge[nn]:
                if nlevel == 2: heappush(q, (nc + 1, nextnode, 0))
                else: heappush(q, (nc, nextnode, nlevel + 1))
    if DP[0][T] < 1000000000: print(DP[0][T])
    else: print(-1)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 82012
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define MAX 100001
#define INF 1000001
typedef struct{
    int p,n,c;
} Edge;


Edge G[500000];
int d[MAX];
void daikstra(int,int);
int main(){
    int i,j,n,u,num,cnt;
    cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&num);
        for(j=0;j<num;j++){
            G[cnt].p=u;
            scanf("%d%d",&G[cnt].n,&G[cnt].c);
            cnt++;
        }
    }
    daikstra(n,cnt);
    for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
    return 0;
}

void daikstra(int n,int count){
    int i,min=1;
    d[0]=0;
    for(i=1;i<n;i++){
        d[i]=INF;
        
    }
    while(min!=0){
        min=0;
        for(i=0;i<count;i++){
        if(d[G[i].p]+G[i].c<d[G[i].n]){
            d[G[i].n]=d[G[i].p]+G[i].c;
            min=1;
        }
        }
    }
}


Measured memory_bytes: 7572
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const arr = ["ABC"];
  arr.push(input);
  return arr.join("");
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29508
#include <cstdio>
#define MAX 1000000000
#define MN 5000001
long long M[MN];
long long c;

void merge(long long A[], long long left, long long mid, long long right) {
    long long n1 = mid - left + 2;
    long long n2 = right - mid + 1;
    long long L[n1], R[n2];
    for (long long i=0; i<n1-1; i++) L[i] = A[left + i];
    for (long long i=0; i<n2-1; i++) R[i] = A[mid + 1 + i];

    L[n1-1] = MAX;
    R[n2-1] = MAX;

    long long l=0, r = 0;
    for (long long i=left; i<=right; i++) {
        if (L[l] <= R[r]) {
            A[i] = L[l];
            l++;
        } else {
            A[i] = R[r];
            r++;
        }
        c++;
    }
}

void merge_sort(long long A[], long long left, long long right) {
    if (left < right) {
        long long mid = (left + right) / 2;
        merge_sort(A, left, mid);
        merge_sort(A, mid + 1, right);
        merge(A, left, mid, right);
    }
}


int
main() {
    c = 0;
    long long n;
    scanf("%lld", &n);
    for (long long i=0; i<n; i++) scanf("%lld", &M[i]);

    merge_sort(M, 0, n-1);
    for (long long i=0; i<n; i++) {
        printf("%lld", M[i]);
        if (i == n-1) printf("\n");
        else printf(" ");
    }
    printf("%lld\n", c);

    return 0;
}

Measured memory_bytes: 9024
<?php
function check($n, $x) {
  // ???????????????????¨????n???????°?????????????n?????????
  if ($n > ($x - 3)) $n = $x - 3;

  $ret = 0;
  for ($i = $n; $i > 2; $i--) {
    // ????????\????????????????????????????±???????(a + a-2 + a-1)
    if (($i * 3 - 3) < $x) break;

    for ($j = $i-1; $j > 1; $j--) {
      // ????????\????????????????????????????±???????(a + b + b-1)
      if (($i + $j * 2 - 1) < $x) break;

      for ($k = $j-1; $k > 0; $k--) {
        $sum = $i + $j + $k;
        if ($sum == $x) {
          $ret++;
        } elseif ($sum < $x) {
          // ????????\????????????????????????????±???????
          break;
        }
      }
    }
  }
  return $ret;
}

$input = trim(fgets(STDIN));
List($n, $x) = explode(" ", $input);

while ($n != 0 or $x != 0) {
  $ans = check($n, $x);
  echo $ans . PHP_EOL;

  $input = trim(fgets(STDIN));
  List($n, $x) = explode(" ", $input);
}

Measured memory_bytes: 15440
d, g = gets.to_s.split.map{|i|i.to_i}
s, c = Array.new(d){ gets.to_s.split.map{|i|i.to_i} }.transpose

ans = 1000
(2**d).times do |b|
  
  tot = 0
  n   = 0
  d.times do |i|
    if 1 == b[i]
      tot += c[i] + s[i] * 100 * (i+1)
      n += s[i]
    end
  end
  
  (0...d).reverse_each do |i|
    break if tot >= g
    next if 1 == b[i]
    score = 100 * (i+1)
    r = ( g - tot + score - 1 ) / score
    r = s[i] - 1 if r > s[i] - 1
    tot += score * r
    n   += r
  end
  
  ans = n if ans > n && tot >= g
end

puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll a,b;
    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
    }else if(6<=a and a<=12){
        cout<<b/2<<endl;
    }else{
        cout<<0<<endl;
    }
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll T[32] = {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};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    K--;
    cout << T[K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<pair<ll,ll>> ab(n,pair<ll,ll>(0,0));
    ll lim = 1e+9 + 100;
    ll sum = 0, mn=lim;
    rep(i,n) {
        cin>>ab[i].first>>ab[i].second;
        sum += ab[i].first;
        if (ab[i].second < ab[i].first) {
            chmin(mn, ab[i].second);
        }
        // if (ab[i].first<ab[i].second) {
        //     sum += abs(ab[i].second-ab[i].first);
        // }
    }
    if (mn == lim) {
        cout << 0 << endl;
    }
    else {
        cout << sum - mn << endl; 

    }

    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n,m,cnt[50];

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

	cin>>n>>m;
	REP(i,m) {
		int a,b; cin>>a>>b;
		a--,b--;
		cnt[a]++,cnt[b]++;
	}
	REP(i,n) cout<<cnt[i]<<endl;

	return 0;
}


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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<int>v1, v2;
		rep(i, n + 1) {
			int a; scanf("%d", &a);
			v1.push_back(a);
		}
		rep(i, n + 1) {
			v2 = v1; v2.erase(v2.begin() + i);
			int s = v2[1] - v2[0];
			if (s <= 0)continue;
			bool flag = true;
			for (int i = 1; i < n; i++) {
				if (s != v2[i] - v2[i - 1])flag = false;
			}
			if (flag) {
				cout << v1[i] << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3268
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long P = 1_000_000_000 + 7;

long[long] primes(long n) {
    long[long] ret;
    foreach(i; iota(2, n+1)) {
        while(n % i == 0) {
            ++ret[i];
            n /= i;
        }
    }
    return ret;
}

long[long] merge(long[long] a, long[long] b) {
    if(a.length < b.length) {
        swap(a, b);
    }
    foreach(k, v; b) {
        a[k] += v;
    }
    return a;
}

void main() {
    auto n = readLong();
    long[long] p;
    foreach(i; iota(n+1)) {
        p = merge(p, primes(i));
    }
    long ans = 1;
    foreach(v; p) {
        ans *= v+1;
        ans %= P;
    }
    writeln(ans);
}



Measured memory_bytes: 380
n, k = map(int,input().split())
a_l = list(map(int,input().split()))

town = 1
count = 0
town_visited = set()
while count < k:
    town_visited.add(town)
    town = a_l[town-1]
    count += 1
    if town in town_visited:
        break

k -= count
if k == 0:
    print(town)
    exit()
count = 0
town_visited = set()
while count < k:
    town_visited.add(town)
    town = a_l[town-1]
    count += 1
    if town in town_visited:
        break

remain = k%count
count = 0
while count < remain:
    town = a_l[town-1]
    count += 1
   
print(town)

Measured memory_bytes: 32404
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> h(100010);
  rep(i,N){
    cin >> h[i];
  }
  vector<ll> dp(100010,INFL);
  dp[0] = 0;
  for(int i = 0;i <N;i++){
    for(int j = 1;j <= K;j++){
      dp[i+j] = min(dp[i]+abs(h[i]-h[i+j]),dp[i+j]);
    }
    //dp[i+1] = min(dp[i]+abs(h[i]-h[i+1]),dp[i+1]);
    //if(i >= 2)dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define mod 163577857
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
li modInverse(li n)
{
    return mpow(n, mod-2);
}

li nCrModPFermat(li n, li r,li x,li y,li z)
{
   // Base case
   if (r==0)
      return 1;
    // li fac[n+1];
    // fac[0] = 1;
    // for (int i=1 ; i<=n; i++)
    //     fac[i] = fac[i-1]*i%mod;
    return (x* modInverse(y) % mod *modInverse(z) % mod) % mod;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void buildtree(int*tree,int*arr,int start,int end,int treeNode)
{
  if(start<end)
  {
    int mid=start+(end-start)/2;
    buildtree(tree,arr,start,mid,2*treeNode);
    buildtree(tree,arr,mid+1,end,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}
void update(int*tree,int*arr,int start,int end,int pos,int val,int treeNode)
{
  if(start==end)
  tree[treeNode]=val;
  else
  {
    int mid=start+(end-start)/2;
    if(pos<=mid)
    update(tree,arr,start,mid,pos,val,2*treeNode);
    else
    update(tree,arr,mid+1,end,pos,val,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}

void dfs(vector<li>v[],li visit[],li s,li c[],li ans[],map<li,li>*m,li pred[])
{
    visit[s]=1;
     (*m)[c[s]]++;
    for(auto i=v[s].begin();i!=v[s].end();i++)
      {
        if(!visit[*i])
        {pred[*i]=s;
           dfs(v,visit,*i,c,ans,m,pred);
        }
      }
      if((*m)[c[pred[s]]]==1)
    ans[s]=(*m).size()-1;
    else
    ans[s]=(*m).size();
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    {n/=2;
    v.push_back(2);
    }
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      {n/=i;
      v.push_back(i);
      }
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
// li t,i,j;
// cin>>t;
// while(t--)
// {
//
//   cout<<endl;
// }
li k,a,b;
cin>>k>>a>>b;
li x=(a/k)*k;
if(x<a)
x+=k;
li y=(b/k)*k;
if(x>y)
cout<<"NG";
else
cout<<"OK";
return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    fastio;
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r" , stdin);
//    freopen("output.txt", "w" , stdout);
//    #endif
    
    int n;
    cin >> n;
    
    ll arr[n];
    unordered_map<ll, ll> umap;
    
    rep(i, n) cin >> arr[i];
    
    rep(i, n)
    	umap[arr[i] + i + 1]++;
    	
    ll ans = 0;
    
    rep(i, n) {
    	
    	ll x = i + 1 - arr[i];
    	
    	if (umap.find(x) != umap.end())
    		ans += umap[x];
	}
	
	cout << ans << "\n";
	//code
	return 0;
}


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

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

	string ans = "No";
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == n) {
				ans = "Yes";
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

void Game(int round, std::istream& in, std::ostream& out)
{
    int scoreA = 0;
    int scoreB = 0;
    for(int i = 0; i < round; ++i){
        int a, b;
        in >> a >> b;
        if(a > b){
            scoreA += a + b;
        }else
        if(a < b){
            scoreB += a + b;
        }else{
            scoreA += a;
            scoreB += b;
        }
    }
    out << scoreA << " " << scoreB << std::endl;
}

int main()
{
    int n;
    std::cin >> n;
    while(n){
        Game(n, std::cin, std::cout);
        std::cin >> n;
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    string s;
    bool g1,g2;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>s;
    for (int i=0; i<s.size(); i++)
        if (s[i] == 'A')
            g1 = 1;
        else
            g2 = 1;
    if (g1 && g2)
        cout <<"Yes";
    else
        cout <<"No";


    return 0;
}


Measured memory_bytes: 256
let a,b,c = Scanf.scanf " %d %d %d" @@ fun p q r -> p,q,r;;
print_int @@
  if a>=1 && b=1 && c=3 then 4
  else if c=3 && b>1 && a>=1 then b+3
  else if b>=1 && a>=1 && a+b+1<c then a+2*b+1
  else b+c

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll ans = 1;
    ll inf = (ll)1e18;
    
    if (count(A.begin(), A.end(), 0)) {
        cout << 0 << endl;
        return 0;
    }
    
    for (int i = 0; i < N; i++) {
        if (A[i] <= inf/ans) ans *= A[i];
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    if (ans <= inf) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4000
#[int(i) for i in input().split()]
def diff(x,y):
	ret = 0
	for i in range(len(x)):
		if x[i]!=y[i]:
			ret+=1
	return ret
s=input()
t=input()

l = len(t)
ans = float('inf')
for i in range(len(s)):
	if i+l<len(s)+1:
		tmp = diff(s[i:i+l], t)
		ans = min(ans, tmp)
		
print(ans)


Measured memory_bytes: 8988
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;cin >> a >> b >> c;
    if((a==b&&b!=c)||(b==c&&a!=b)||(a==c&&a!=b)){
        cout << "Yes" << '\n';
    }else{
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  vector<P> A(n);rep(i,n) {cin>>a;A[i]=P(a,i);}
  sort(RALL(A));
  vector<lvector> dp(n+10,lvector(n+10,0));
  rep(i,n) {
    ll activeness=A[i].first, pos=A[i].second;
    rep(j,i+1) {
      if(dp[i][j]>=0) {
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+activeness*abs(pos-j));
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]+activeness*abs(n-1-(i-j)-pos));
      }
    }
  }
  ll ans=*max_element(ALL(dp[n]));
  print(ans);
  return 0;
}

Measured memory_bytes: 34880
N , K = (map(int , input().split()))
a = -(-N//K)

aaans = abs(N-K)

if N == K:
    ans = 0
elif a == 1:
    ans = N
else:
    ans = (a*K)-N
    
aa = (N//K)
if N == K:
    aans = 0
elif aa == 1:
    aans = N
else:
    aans = N - (aa*K)

aaaans = min(ans,aans)
print(min(aaans,aaaans))

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(100000)


def rootedTree(node,parent,root,add):
    A.append([node,parent,root,add])
    for root_num,num in root:
            rootedTree(root_num,node,tree[root_num],num)


n=int(input())
AB=[list(map(int,input().split()))+[i+1] for i in range(n-1)]
A=[]
tree=[[] for i in range(n+1)]
for a,b,c in AB:
    tree[a] +=[[b,c]]

rootedTree(1,0,tree[1],0)
ans=[0]*n
for node,parent,root,num in A:
    flag=0
    for i,j in enumerate(root):
        if ans[num]==i+1:flag=1
        if flag:
            ans[j[1]]=i+2
            continue
        ans[j[1]]=i+1

print(max(ans))
for i in range(1,n):print(ans[i])


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};
int main() {
    ll n,m;
    cin >> n>>m;
	UnionFind uf(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	ll u = 0;
	rep(i, n) {
		chmax(u, uf.size(i));
	}
	cout << u << endl;
    return 0;
}


Measured memory_bytes: 6424
n=int(input())
a=tuple(map(lambda x:int(x)-1,input().split()))
b=tuple(map(lambda x:int(x)-1,input().split()))

import itertools as it
pe=list(it.permutations(range(n),n))

x,y=0,0
for ind,i in enumerate(pe):
    if i==a:
        x=ind
    if i==b:
        y=ind
print(abs(x-y))

Measured memory_bytes: 8052
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef unsigned long long ll;

ll gcd(ll a,ll b){
	if(a<b){int alt=a;a=b;b=alt;}
	if(a%b==0)return b;
	else return gcd(b,a%b);
}

int main(){
	int n;
	cin>>n;
	ll t[n];
	ll ans,alt;
	cin>>t[0];
	if(n>1){
		loop(i,1,n){
			cin>>t[i];
			if(i==1){
				ans=t[0]/gcd(t[0],t[1])*t[1];
			}else{
				alt=ans;
				ans=alt/gcd(alt,t[i])*t[i];
			}
		}
	}else ans=t[0];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256