akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    N = list(map(int,sys.stdin.readline().split()))
    if 0 in N:
        print('0')
        return 0
    ans = 1
    for i in N:
        ans *= i
        if ans > 10**18:
            print('-1')
            return 0
    print(ans)
    return 0

if __name__ == "__main__":
    main()

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

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

int main() {
    int x, y;
    cin >> x >> y;

    cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3096
#include<stdio.h>
int main() {
	int H, W, i, j;
	while (1) {
		scanf("%d %d", &H, &W);
		if ((H == 0) && (W == 0)) {
			break;
		}
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				if ((i == 0) || (i == H - 1)) {
					printf("#");
				}
				else if ((j == 0) || (j == W - 1)) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2564
#include <iostream>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	int res = 1;
	
	while(n--){
	    int a;
	    cin >> a;
	    
	    res *= (a%2 == 0);
	}
	
	if(res) cout << "second" << endl;
	else cout << "first" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
set<ll> st;
map<char, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

typedef pair<Weight, Edge> P;

int main()
{
	int n;
	cin >> n;
	cout << (n * 800 - (n / 15) * 200) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int xx;
    cin>>xx;
    float x=xx*1.0;
    float l=float((x*1.0)/3);
    x-=l;
    float b=float((x*1.0)/2);
    x-=b;
    float h=x;
    cout<<fixed<<setprecision(12)<<1.0*l*b*h<<endl;

}

Measured memory_bytes: 256
n = int(input())
odd = 0
even = 0
four = 0
for i in list(map(int,input().split())):
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        even += 1
    else:odd += 1
if four == 0:
    if even == n:
        print("Yes")
    else:print("No")
elif even+odd <= four+1:
    print("Yes")
elif four >= odd:
    print("Yes")
else:print("No")

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if(A[i] >= 2){
            ans += (A[i]-1)/2;
            A[i] = (A[i]+1)%2 + 1;
        }
    }

    for (ll i = 0; i < N-1; i++) {
        if(A[i] == 2){
            A[i] = 0;
            ans++;
        }
        else if(A[i]==1 && A[i+1]>=1){
            A[i]--; A[i+1]--;
            ans++;
        }
    }
    if(A[N-1]==2){
        ans++;
    }
    printf("%lld\n", ans);


}


Measured memory_bytes: 4040
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
using namespace std;
using ll =long long;
int main() {
	int K, N;
	vector<int>A;
	cin >> K >> N;

	int c;
	int big=0;
	for (int i = 0; i < N; i++) {
		cin >> c;
		A.push_back(c);

	}
	big =K+A[0]- A[N - 1];
	for (int i=0; i < N-1; i++) {
			if (A[i + 1] -A[i]>big ) {
				big = A[i + 1] - A[i];

			}

	}
	cout << K - big;

}

Measured memory_bytes: 1400
s=input()
count=0
b=s.count("B")
w=s.count("W")
for x in range(len(s)):
    if s[x:x+1] == "B":
        count += w
        b-=1
    elif s[x:x+1] == "W":
        w-=1
    if w == 0:
        break

print(count)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    string s;
    cin>>s;

    int len=s.size();
    for(int i=0; i<len; i++){
        if(s[i]=='?') s[i]='D';
    }
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main(){

    map <int, int> m;
    for (int i = 0; i < 4; i++){
        int x;
        cin >> x;
        m[x] ++;
    }
    
    if (m[1] == 1 && m[9] == 1 && m[7] == 1 && m[4] == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll B[N]{};
    ll C[N]{};
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (i + A[i] < N) {
            B[i + A[i]]++;
        }
        if (i - A[i] > 0) {
            C[i - A[i]]++;
        }
    }
    for (int i = 1; i < N - 1; i++) {
        ans += B[i] * C[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7540
S = input()
S = list(S)
cnt = 0
maxcount = 0

for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
        cnt += 1
        if cnt > maxcount:
            maxcount = cnt
    else:
        cnt = 0
print(maxcount)

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

# define Size 1000000

inline int readInt ( )  {
	register int x, c ;
	static char buf [Size], *ss, *tt ;
	# define pick( ) ( (ss == tt) ? ( tt = buf + fread ( ss = buf, 1, Size, stdin ), ( ss == tt ) ? -1 : *ss ++ ) : *ss ++ )
	while ( ! isdigit ( c = pick ( ) ) ) ;
	for ( x = -48 + c ; isdigit ( c = pick ( ) ) ; x = x * 10 + c - 48 ) ;
	return x ;
	# undef pick
}

inline void smin ( long long& d, long long x )  {  ( d > x ) ? d = x : 0 ;  }

const long long inf = ( ~0ull >> 1 ) ;
const int N = 200010 ;

int q [N] ;
bool inq [N] ;
long long a [N] ;

struct edge  {
	int to, w ; edge* nxt ;
} g [N], *head [N], *NewEdge ;

int main ( )  {
	int h, w, n ;
	h = readInt ( ), w =  readInt ( ), n = readInt ( ) ;
	NewEdge = g ;
	for ( int i = 0 ; i < n ; ++ i )  {
		int x = readInt ( ), y = readInt ( ), z = readInt ( ) ;
		-- x, -- y ;
		*( ++ NewEdge ) = ( edge ) {  h + y, z, head [x]  } ; head [x] = NewEdge ;
		*( ++ NewEdge ) = ( edge ) {  x, z, head [h + y]  } ; head [h + y] = NewEdge ;
	}
	for ( int i = 0, l = h + w ; i < l ; ++ i )  {
		if ( ! inq [i] )  {
			register edge* it ;
			register int fr ( 0 ), tl ( 0 ) ;
			a [i] = 0 ;
			q [++ tl] = i ;
			inq [i] = true ;
			while ( fr ^ tl )  {
				int u = q [++ fr] ;
				for ( it = head [u] ; it ; it = it -> nxt )  {
					int r = it -> to, v = it -> w ;
					if ( inq [r] )  {
						if ( a [u] + a [r] != v )  {
							return puts ( "No" ), 0 ;
						}
						continue ;
					}
					q [++ tl] = r ;
					inq [r] = true ;
					a [r] = v - a [u] ;
				}
			}
			long long m1 = inf, m2 = inf ;
			while ( tl )  {
				( q [tl] < h ) ? smin ( m1, a [q [tl --]] ) : smin ( m2, a [q [tl --]] ) ;
			}
			if ( m1 + m2 < 0 )  {
				return puts ( "No" ), 0 ;
			}
		}
	}
	return puts ( "Yes" ), 0 ;
}

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

int deg[1234];

int edges[1234][1234];

void dfs(int v, int n) {
  int cur = 0;
  while (true) {
    while (cur <= n && edges[v][cur] == 0) ++cur;
    if (cur > n) break;
    --edges[v][cur];
    dfs(cur, n);
  }
}

int main() {
  int n, h;
  scanf("%d%d", &n, &h);
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int from = c == 0 ? a : (c + 2 * h);
    int to = d == 0 ? (b + 2 * h) : d;
    deg[from]--;
    deg[to]++;
    edges[from][to]++;
  }
  for (int i = 0; i < 4 * h; i++) {
    if (deg[i] != 0) {
      if ((deg[i] < 0 && i >= 2 * h) || (deg[i] > 0 && i < 2 * h)) {
        puts("NO");
        return 0;
      }
      if (deg[i] < 0) {
        edges[4 * h][i] = -deg[i];
      } else {
        edges[i][4 * h] = deg[i];
      }
    }
  }
  dfs(4 * h, 4 * h);
  for (int i = 0; i <= 4 * h; i++) {
    for (int j = 0; j <= 4 * h; j++) {
      if (edges[i][j] != 0) {
        puts("NO");
        return 0;
      }
    }
  }
  puts("YES");
}


Measured memory_bytes: 9600
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,w=map(int,input().split())
WV=[tuple(map(int,input().split())) for i in range(n)]
dp=[inf]*(10**5+1); dp[0]=0
for i in range(n):
  wi,vi = WV[i]
  for di in range(10**5,-1,-1):
    if not (0<=di-vi<10**5+1): continue
    # if dp[di-vi]==-1: continue
    dp[di]=min(dp[di],dp[di-vi]+wi)
for i,di in enumerate(dp):
  if di <= w:
    ans = max(ans,i)
# print(dp[:110])
print(ans)
    

Measured memory_bytes: 95180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
//
int main(){
   vector<int> v(5);
   
   rep(i,5){
      cin>>v[i];
   }
   int x;
   rep(i,5){
      if(v[i]==0){
         cout<<i+1<<endl;
         break;
      }
   }
   
   

}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
    int A = 0, B = 0, C = 0, D = 0, L = 0, a = 0, b = 0, c, d;
    scanf("%d", &L);
    scanf("%d %d", &A, &B);
    scanf("%d %d", &C, &D);
    c= A / C;
    a = A%C;
    if (a > 0) {
        c++;
    }
    d= B / D;
    b = B%D;
    if (b > 0) {
        d=d+1;
    }
    if (c>d) {
        L= L-c;
    }
    else {
        L= L- d;
    }
    if (L <= 0) {
        L = 1;
    }
    printf("%d\n", L);
    return 0;
}

Measured memory_bytes: 2584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {

  rep(i,5){
    int x;
    cin>>x;
    if(x==0) {
      cout << i+1 << endl;
      return 0;
    }
  }
  
  


  
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

typedef pair<double, double> PDD;

const double EPS = 1e-8;
const double PI = acos(-1.0);

int D, N, B;
vector<PDD> os;

double get_v0(double th, int bound)
{
	double d = D/(bound+1.0);
	return sqrt(d/sin(2*th));
}

double get_h(double x, double v0, double th)
{
	double vx = v0*cos(th), vy = v0*sin(th);
	return -(x*x/(2.0*vx*vx))+ (vy/vx)*x;
}

bool check(double th, double bound)
{
	double end = D/(bound+1.0);
	double v0 = get_v0(th, bound);
	
	rep(i, N) {
		double obx = os[i].first;
		while (obx - EPS > end) obx -= end;
		if (get_h(obx, v0, th) + EPS < os[i].second)
			return false;
	}
	
	return true;
}

int main()
{
	cin>>D>>N>>B;
	os.resize(N);
	rep(i, N) {
		cin>>os[i].first>>os[i].second;
	}
	
	double ans = INF;
	for (int b=0; b<=B; b++) {
		double lb = PI/4, ub = PI/2;
		for (int i=0; i<100; i++) {
			double mid = (lb+ub)/2;
			
			if (check(mid, b)) {
				ub = mid;
			} else {
				lb = mid;
			}
		}
		
		ans = min(ans, get_v0(lb, b));
	}
	
	cout << fixed << setprecision(8);
	cout << ans << endl;
}

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

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

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

    vector<pair<int, int>> AI(N);
    for(int i=0;i<N;i++) {
        cin >> AI.at(i).first;
        AI.at(i).second = i;
    }

    sort(AI.begin(), AI.end(), pairCompare);

    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            if(AI.at(j).second==i) continue;
            cout << AI.at(j).first << endl;
            break;
        }
    }
  
    // for(int i=0;i<N;i++) {
    //     cout << AI.at(i).first << " " << endl;
    // }

    return (0);
}


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

#define int long long

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

  int N;
  cin >> N;

  string s, t;
  cin >> s >> t;

  string u = "";
  for ( int i = 0; i < N; i++ ) {
    u.push_back(s[i]);
    u.push_back(t[i]);    
  }

  cout << u << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

p = list(range(N))
p.sort(key=lambda i: A[i], reverse=True)

dp = [[0]*(N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(i + 1):
        pi = p[i]
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[pi]*(N - i + j - 1 - pi))
        dp[i+1][j+1] = dp[i][j] + A[pi]*(pi - j)
print(max(dp[N]))


Measured memory_bytes: 98240
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0; i<N; i++)
    cin >> v[i];

  sort(v.begin(), v.end(), greater<double>());

  double ans = 0.0;

  for(int i=0; i<N-1; i++)
    ans += v[i] / pow(2, i+1);
  ans += v[N-1] / pow(2, N-1);

  cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ss              second
#define ar              array
#define int             long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("ip1.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);
#endif
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int prime(int n) {
  int flag = 1;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {flag = 0; break;}
  }
  return flag;
}
int power(int x, int y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
  else
    return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}

int32_t main()
{
  k_007();
  int h, n;
  cin >> h >> n;
  int a[n];
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }

  if (sum >= h)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vvi cnt(60, vi(2));
  rep(i, 60) cnt[i][0] = n;
  rep(i, n) {
    ll a; std::cin >> a;
    int d = 0;
    while(a) {
      if (a%2) cnt[d][1]++, cnt[d][0]--;
      d++, a/=2;
    }
  }
  mint ans, f2 = 1;
  rep(i, 60) {
    ans += f2 * cnt[i][0] * cnt[i][1];
    f2 *= 2;
  }
  std::cout << ans.x << "\n";
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          long[] n = ReadLine().Split(' ').Select(long.Parse).ToArray();
          long ans = n[0] % n[1];
          if(((ans - n[1]) * -1) >= 0 && ((ans - n[1]) * -1 < ans)) ans = (ans - n[1]) * -1;

          WriteLine(ans);
      }
   }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
using namespace std;
int main(){
	string w[500], s;
	int wn[500] = {0}, n = -1;
	while(cin >> s){
		bool f = true;
		for(int i = 0; i < n; i++)
			if(s == w[i]){
				wn[i]++;
				f = false;
			}
		if(f){
			w[++n] = s;
			wn[n] = 1;
		}
	}
	int m = 0, mi, ml = 0, mli;
	for(int i = 0; i <= n; i++){
		if(wn[i] > m){
			m = wn[i];
			mi = i;
		}
		if((int)w[i].length() > ml){
			ml = (int)w[i].length();
			mli = i;
		}
	}
	cout << w[mi] << " " << w[mli] << endl;
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  cout << b - a + b << endl;
}

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

typedef long long ll;

int main() {
    string s, t = "";
    cin >> s;
    int n = s.size();
    rep(i, n) {
        if (i < n - 1 && s[i] == 'B' && s[i + 1] == 'C') {
            t.push_back('D');
            i++;
        } else {
            t.push_back(s[i]);
        }
    }
    //cout << t << "\n";
    ll ans = 0, A = 0;
    n = t.size();
    rep(i, n) {
        if (t[i] == 'A') A++;
        else if (t[i] == 'D') ans += A;
        else A = 0;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 776
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: i32 = read();
    let M: i32 = read();
    let mut cards: Vec<i32> = vec![];
    let mut replaces: Vec<(i32, i32)> = vec![];

    for _ in 0..N {
        cards.push(read());
    }
    cards.sort();
    cards.reverse();

    for _ in 0..M {
        let b: i32 = read();
        let c: i32 = read();
        replaces.push((b, c));
    }
    replaces.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
    replaces.reverse();

    let mut sum: i64 = 0;
    for (count, num) in replaces {
        for _ in 0..count {
            let card = cards.pop().unwrap();
            if card < num {
                sum += num as i64;
            } else {
                sum += card as i64;
            }
            if cards.len() == 0 {
                println!("{}", sum);
                return;
            }
        }
    }
    for card in cards {
        sum += card as i64;
    }
    println!("{}", sum);
}


Measured memory_bytes: 6396
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,m=MI()
    start=set()
    goal=set()
    for _ in range(m):
        a,b=MI()
        if a>b:a,b=b,a
        if a==1:start.add(b)
        if b==n:goal.add(a)
    if start&goal:print("POSSIBLE")
    else:print("IMPOSSIBLE")
main()

Measured memory_bytes: 18956
#include <iostream>
#include <string>
#include <utility>
#include <queue>

constexpr int INF = 1000000000;
using Pair = std::pair<int, int>;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int h, w, n;
std::string map[1010];
int cost[1010][1010];
Pair pts[10];

int bfs(Pair st, Pair en) {
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cost[i][j] = INF;
        }
    }
    cost[st.first][st.second] = 0;

    std::queue<Pair> que;
    que.push(st);

    while(!que.empty()) {
        auto p = que.front(); que.pop();

        for(int i = 0; i < 4; ++i) {
            int py = p.first + dy[i], px = p.second + dx[i];

            if(py < 0 || px < 0 || py >= h || px >= w)
                continue;

            if(map[py][px] == '.' && cost[py][px] == INF) {
                que.push({py, px});
                cost[py][px] = cost[p.first][p.second] + 1;
            }
        }
    }

    return cost[en.first][en.second];
}

int main() {
    std::cin >> h >> w >> n;

    for(int i = 0; i < h; ++i) {
        std::cin >> map[i];

        for(int j = 0; j < w; ++j) {
            if(map[i][j] != '.' && map[i][j] != 'X') {
                int idx = (map[i][j] == 'S' ? 0 : map[i][j] - '0');

                pts[idx] = {i, j};
                map[i][j] = '.';
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        ans += bfs(pts[i - 1], pts[i]);
    }

    std::cout << ans << std::endl;
}

Measured memory_bytes: 7944
#include<bits/stdc++.h>
using namespace std;
int m[5][105];
bool cmp (int x,int y)
{
	return x > y; 
}
int main()
{
	long long n,t;
	cin>>n>>t;
	long long a[105],b[105];
	cin>>a[1]>>b[1];
	int q[5]={};
	m[a[1]-a[1]+1][++q[a[1]-a[1]+1]]=b[1];
	
	for(int i=2;i<=n;++i)
	{
		cin>>a[i]>>b[i];
		m[a[i]-a[1]+1][++q[a[i]-a[1]+1]]=b[i];
	}
	//cout<<q[1]<<" "<<q[2]<<" "<<q[3]<<" "<<q[4]<<endl;
	sort(m[1]+1,m[1]+1+q[1],cmp);
	sort(m[2]+1,m[2]+1+q[2],cmp);
	sort(m[3]+1,m[3]+1+q[3],cmp);
	sort(m[4]+1,m[4]+1+q[4],cmp);
	long long ans=0;
    long long i1,i2,i3,i4;
    i1=i2=i3=i4=0;
	for(int i=0;i<=q[1];++i)
	{
		
		for(int j=0;j<=q[2];++j)
		{
			for(int k=0;k<=q[3];++k)
			{
			     for(int p=0;p<=q[4];++p)
			    {
			    	if(i*a[1]+j*(a[1]+1)+k*(a[1]+2)+p*(a[1]+3)>t) break;
			    	ans=max(ans,i1+i2+i3+i4);
			    	i4+=m[4][p+1];
				}
				i4=0;
				i3+=m[3][k+1];
			}
			i3=0;
			i2+=m[2][j+1];
		}
		i2=0;
		i1+=m[1][i+1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) {
    t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin>>N;
    long double a;
    vector<ll> A(N), d2(N), d5(N);
    auto plane = make_v<ll>(19, 19), acc = plane;
    for (size_t i = 0; i < N; i++)
    {
        cin>>a;
        ll tmp = A[i]=llround(a*1e9);
        while (tmp%2==0)
        {
            d2[i]++;
            tmp /=2;
        }
        tmp=A[i];
        while (tmp%5==0)
        {
            d5[i]++;
            tmp/=5;
        }
        plane[min(18LL, d2[i])][min(18LL, d5[i])]++;
    }
    ll ans=0;
    for (size_t i = 0; i < 19; i++)
    {
        for (size_t j = 0; j < 19; j++)
        {
            for (size_t i2 = 0; i2 < 19; i2++)
            {
                for (size_t j2 = 0; j2 < 19; j2++)
                {
                    if(i+i2 >= 18 and j + j2 >= 18)
                    {
                        ans+= plane[i][j]*plane[i2][j2];
                        if(i==i2 and j == j2)
                    ans -= plane[i][j];
                    }
                    
                }
                
            }
            
        }
        
    }
    
    cout<<ans/2<<endl;
    return 0;
}

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

using namespace std;

int main(){

    int n;
    cin>>n;

int x;
    int xnt=0;
    int cnt=0;
for(int i=0;i<n;i++){
cin>>x;
if(x%2==0){
cnt++;
  if(x%3==0||x%5==0){
     xnt++;
  }
}

}
    if(xnt==cnt){

cout<<"APPROVED";
}
    else cout<<"DENIED";

}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())

    e = []
    for i in range(M):
        P, Y = map(int, input().split())
        e.append([i,P,Y])

    e.sort(key=lambda x : (x[1],x[2]))
    cnt = 1
    for i in range(M):
        if i == 0:
            e[i][1] = str(e[i][1]).zfill(6)
            e[i][2] = str(cnt).zfill(6)
            cnt += 1
        if int(e[i-1][1]) == e[i][1]:
            cnt += 1
            e[i][1] = str(e[i][1]).zfill(6)
            e[i][2] = str(cnt).zfill(6)
        else:
            cnt = 1
            e[i][1] = str(e[i][1]).zfill(6)
            e[i][2] = str(cnt).zfill(6)

    ans = sorted(e)
    for i,j,k in ans:
        print(j+k)

main()

Measured memory_bytes: 95576
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
static const int MAX_W = 33;
static const int MAX_H = 33;
 
int w, h;
bool field1[MAX_H][MAX_W], field2[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];
int dy[] = {0, -1, 0, 1};
int dx[] = {1, 0, -1, 0};
 
int bfs(int y, int x){
    fill(visited[0], visited[h], false);
    queue<PP> qa;
    qa.push(PP(P(y, x), 1));
    visited[y][x] = true;
    while(!qa.empty()){
        PP cur = qa.front(); qa.pop();
        int cy = cur.first.first, cx = cur.first.second;
        int dist = cur.second;
        if(cy == h - 1 && cx == w - 1) return dist;
        for(int i = 0; i < 4; i++){
            int ny = cy + dy[i], nx = cx + dx[i];
            if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if(visited[ny][nx]) continue;
            if(i == 0){
                if(field1[cy][cx]) continue;
            }else if(i == 1){
                if(field2[ny][nx]) continue;
            }else if(i == 2){
                if(field1[ny][nx]) continue;
            }else{
                if(field2[cy][cx]) continue;
            }
            qa.push(PP(P(ny, nx), dist + 1));
            visited[ny][nx] = true;
        }
    }
    return 0;
}
 
int main(){
    for(;;){
        scanf("%d %d", &w, &h);
        if(w == 0 && h == 0) break;
        for(int i = 0; i < 2 * h - 1; i++){
            if(i % 2 == 0){
                for(int j = 0; j < w - 1; j++) scanf("%d", &field1[i / 2][j]);
            }else{
                for(int j = 0; j < w; j++) scanf("%d", &field2[i / 2][j]);
            }
        }
        printf("%d\n", bfs(0, 0));
    }
    return 0;
}


Measured memory_bytes: 2608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, W;
ll dp[110][100010]={0};
vector<ll> w, v;

template<class T>
void chmax(T &a, T b)
{
	if (a < b) a = b;
}

int main(int argc, char **argv)
{
	cin >> N >> W;
	w.resize(N), v.resize(N);
	for (ll i = 0; i < N; ++i) cin >> w[i] >> v[i];

	for (ll ni = 0; ni < N; ++ni)
	{
		for (ll wi = 0; wi <= W; ++wi)
		{
			if (wi - w[ni] >= 0)
				chmax(dp[ni+1][wi], dp[ni][wi-w[ni]]+v[ni]);
			chmax(dp[ni+1][wi], dp[ni][wi]);
		}
	}

	std::cout << dp[N][W] << std::endl;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,bool>> vp(n);
    rep(i,n){
        vp[i].first = 1;
        if(!i)vp[i].second = true;
        else vp[i].second = false;
    }
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        --vp[a-1].first;
        ++vp[b-1].first;
        if(vp[a-1].second)vp[b-1].second = true;
        if(vp[a-1].first <= 0)vp[a-1].second = false;
    }
    ll res = 0;
    for(auto a : vp)if(a.second)res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
n=int(input())
a=map(int,input().split())  
b,c=[],[]
for i,q in enumerate(a):
  b.append(i+q)
  c.append(i-q)
from collections import*
b=Counter(b).items()
c=Counter(c)
z=0
for d,e in b:z+=e*c[d]
print(z)


Measured memory_bytes: 159644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String W = sc.nextLine();
		W = W.toLowerCase();
		int num = 0;
		for(;;){
			String T = sc.next();
			if(T.equals("END_OF_TEXT"))break;
			T = T.toLowerCase();
			if(W.equals(T))num++;
		}
		System.out.println(num);
	}	
}

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,M,m=0,ans=0;
  cin >> N >> M;
  vector<ll> A(N);
  map<ll,ll> B;
  B[0]=1;
  rep(i,N){
    cin >> A.at(i);
    m+=A.at(i);
    m%=M;
    if(B.count(m)){
      B.at(m)++;
    }else{
      B[m]=1;
    }
  }
  for(auto p:B) {
    auto key = p.first;
    auto value = p.second;
    ans+=value*(value-1);
  }
  ans/=2;
  cout << ans << endl;
}
      

Measured memory_bytes: 7816
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
	res = list(sys.stdin.readline())
	if res[-1] == "\n":
		return res[:-1]
	return res


def IR(n):
	return [I() for i in range(n)]


def LIR(n):
	return [LI() for i in range(n)]


def SR(n):
	return [S() for i in range(n)]


def LSR(n):
	return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
	a, b = LI()
	ansa = str(a) * b
	ansb = str(b) * a
	print(min(ansa,ansb))
	return


# Solve
if __name__ == "__main__":
	solve()


Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,i,j,k,w[100005],u,head[100005],adj[200005],nxt[200005],d[100005],size[100005],sz[100005];
void dfs(int x,int dad)
{
	sz[x]=1;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dfs(adj[y],x);
			sz[x]+=sz[adj[y]];
		}
	if(sz[x]>2)
		u=1;
	else if(sz[x]==2)
		sz[x]=0;
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		++d[j],++d[k];
	}
	dfs(1,-1);
	if(sz[1])
		u=1;
	if(u)
		printf("First");
	else
		printf("Second");
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define PI 3.14159265
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  double x,y,z;
  cin>>x>>y>>z;
  double hey = (pow(x,2)*y/z);
  double no = (x*y)/2;
  double haut = y/hey;
  double kal = x*haut;
  if(kal>no)
  {
  double fal = kal*2/y;
  double newi = fal-x;
  double kobr = newi*(y/fal);
  double area = kobr*newi/2;
  double fark = kal-(x*y);
  double fark1 = (x*y)-(kal);
  double last = (fark1*2)/x;
  double ans = atan(last/x)* 180 / PI;
  cout<<fixed<<setprecision(6)<<ans;
  }
  else
  {double fal = kal*2/y;
  double nal = y/fal;
  double ans = atan(nal)* 180 / PI;
  cout<<fixed<<setprecision(6)<<ans;}
  return 0;
}
//code the AC sol !
// BS/queue/map


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

using namespace std;

int main()
{
    string S;
    cin >> S;

    /*
    // 1/10 = 202 (mod 2019)
    for(int i=0;i<=2018;i++){
        if((10*i)%2019==1)
            cout << i <<endl;
    }
    */

    reverse(S.begin(), S.end());
    // 格桁のmod
    vector<int> vmod(S.size(), 0);
    int deci = 1;
    for (int i = 0; i < S.size(); i++)
    {
        vmod[i] = ((S[i] - '0') * deci) % 2019;
        deci *= 10;
        deci %= 2019;
    }
    vector<int> vsum(S.size(), 0);
    vsum[0] = vmod[0];
    for (int i = 1; i < S.size(); i++)
    {
        vsum[i] = vsum[i - 1] + vmod[i];
        vsum[i] %= 2019;
    }

    // vsumが同じものの個数を数える。
    // 202と2019が互いに素であることを利用。
    int ans = 0;
    vector<int> vans(2019, 0);
    for (int x : vsum)
    {
        vans[x]++;
        //cout << x << endl;
    }
    for (int x : vans)
    {
        ans += x * (x - 1) / 2;
    }

    ans += vans[0];

    cout << ans << endl;
}

Measured memory_bytes: 5160
from networkx.utils import UnionFind

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

uf = UnionFind()
same = lambda v1,v2: uf.__getitem__(v1)==uf.__getitem__(v2)

for i in range(Q):
  t,u,v = map(int,input().split())
  if t:
    if same(u,v):print(1)
    else:print(0)
  else:
    uf.union(u,v)

Measured memory_bytes: 68732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int flag=0;
    for(int i=0; i<a.length(); i++)
    {
        if(a[i]==b[a.length()-1-i])
            continue;
        else
            flag=1;
    }
    if(flag==0)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
//Optimize
#pragma GCC optimize("Ofast")

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

#define il inline

//Variable
#define ll long long
#define ull unsigned long long
#define db double
#define lb long double
#define ui unsigned int

//Debug
#define B cerr<<"Break Point"<<endl;
#define P(x) cerr<<#x<<' '<<"="<<' '<<(x)<<endl;
#define p(x) cerr<<#x<<' '<<"="<<' '<<(x)<<' ';
#define ml(x) cerr<<"Size of array is "<<x*4/1024/1024<<" MB"<<endl;

//Vector
#define vc vector
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define vbe(x) x.begin(),x.end()

//Memset
#define ms(x) memset(x,0,sizeof(x))
#define MS(x) memset(x,0x3f3f3f3f,sizeof(x))

//Pair
#define fi first
#define se second

//File

#define fin(x) freopen(x,"r",stdin)
#define fou(x) freopen(x,"w",stdout)
void fio()
{
    #ifndef ONLINE_JUDGE
    freopen("sample.in","r",stdin);
    freopen("sample.out","w",stdout);
    #endif
}
void pti()
{
    double timeuse = clock()*1000.0/CLOCKS_PER_SEC;
    cerr<<"Timeuse "<<timeuse<<"ms"<<endl;
}
void end()
{
    pti();
    exit(0);
}

//Inf
#define INF 0x3f3f3f3f
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))

//IO
#define pc(s) putchar(s)
#define say(s) cout<<s<<endl
namespace io
{
    const int SIZ=55;int que[SIZ],op,qr;char ch;
    template<class I>
    il void gi(I &w)
    {
        ch=getchar(),op=1,w=0;
	while(!isdigit(ch)){if(ch=='-') op=-1;ch=getchar();}
        while(isdigit(ch)){w=w*10+ch-'0';ch=getchar();}w*=op;
    }
    template<typename T,typename... Args>
    il void gi(T& t,Args&... args){gi(t);gi(args...);}
    template<class I>
    il void print(I w)
    {
        qr=0;if(!w) putchar('0');if(w<0) putchar('-'),w=-w;
	while(w) que[++qr]=w%10+'0',w/=10;
        while(qr) putchar(que[qr--]);
    }
}
using io::gi;
using io::print;

int n,k;

int main()
{
    gi(n,k);
    int res=0;
    while(n) n/=k,++res;
    print(res);
    end();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

ll table[3][3];

void open(ll val) {
  for (ll i = 0; i < 3; i++) {
    for (ll j = 0; j < 3; j++) {
      if (table[i][j] == val) {
        table[i][j] = -1;
      }
    }
  }
}

bool calc() {
  if (table[0][0] == -1 && table[0][1] == -1 && table[0][2] == -1) {
    return true;
  }
  if (table[1][0] == -1 && table[1][1] == -1 && table[1][2] == -1) {
    return true;
  }
  if (table[2][0] == -1 && table[2][1] == -1 && table[2][2] == -1) {
    return true;
  }
  if (table[0][0] == -1 && table[1][0] == -1 && table[2][0] == -1) {
    return true;
  }
  if (table[0][1] == -1 && table[1][1] == -1 && table[2][1] == -1) {
    return true;
  }
  if (table[0][2] == -1 && table[1][2] == -1 && table[2][2] == -1) {
    return true;
  }

  if (table[0][0] == -1 && table[1][1] == -1 && table[2][2] == -1) {
    return true;
  }
  if (table[2][0] == -1 && table[1][1] == -1 && table[0][2] == -1) {
    return true;
  }

  return false;
}

int main() {
  for (ll i = 0; i < 3; i++) {
    ll a1, a2, a3;
    scanf("%lld %lld %lld", &a1, &a2, &a3);
    table[i][0] = a1;
    table[i][1] = a2;
    table[i][2] = a3;
  }

  ll n;
  scanf("%lld", &n);

  for (ll i = 0; i < n; i++) {
    ll v;
    scanf("%lld", &v);
    open(v);
  }

  cout << (calc() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  static long ans = 0;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] path = new int[n+1][n+1];
    int[] visited = new int[n+1];
    for(int i=0;i<m;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      path[a][b]=path[b][a]=1;
    }
    dfs(1,n-1,path,visited,n);
    System.out.println(ans);
  }
  static void dfs(int s,int res,int[][] path,int[] visited,int n){
    if(res==0){
      ans++;
      return;
    }
    for(int i=2;i<=n;i++){
      if(path[s][i]==1&&visited[i]==0){
        visited[i]=1;
        dfs(i,res-1,path,visited,n);
        visited[i]=0;
      }
    }
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
ll dp[2001][2001];
int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    pii arr[n];
    rep(i,1,n+1)
    {
        cin>>arr[i].F;
        arr[i].S=i;
    }
    sort(arr+1,arr+n+1);

    int len;
    for(len=n;len>=1;len--)
    {
        rep(i,1,n+1)
        {
            j=len+i-1;
            if(j>n)break;
            if(i==j)
            {
                dp[0][0]=max(dp[0][0],dp[i][j]+arr[len].F*(ll)(abs(i-arr[len].S)));
            }
            else
            {
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]+arr[len].F*(ll)(abs(i-arr[len].S)));
                dp[i][j-1]=max(dp[i][j-1],dp[i][j]+arr[len].F*(ll)(abs(j-arr[len].S)));
            }
        }
    }
    cout<<dp[0][0];
    return 0;
}



Measured memory_bytes: 26276
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String[] A = new String[N];
		String[] B = new String[M];

		for(int i = 0; i < N; i++) {
			A[i] = sc.next();
		}
		for(int i = 0; i < M; i++) {
			B[i] = sc.next();
		}

		int count = 0;
		Serch: {
			for(int i = 0; i <= N-M; i++) {
				for(int j = 0; j <= N-M; j++) {
					for(int k = 0; k < M; k++) {
						if(A[i+k].substring(j,j+M).equals(B[k].substring(0))) {
							count++;
						}else {
							count = 0;
							break;
						}
						if(count == M) {
							break Serch;
						}
					}
				}
			}
		}

		if(count == 0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 27380
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101

int count = 0;

void selection_sort(int n,int *A){
  int i,j,tmp,index;
  for(i=0;i<n-1;i++){
    index = i;
    for(j=i+1;j<n;j++)
      if(A[j]<A[index])
        index = j;
    tmp = A[i];
    A[i] = A[index];
    A[index] = tmp;
    if(index!=i)count++;
  }
}

int main(){
  int n,i;
  int a[MAX];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  selection_sort(n,a);
  for(i=0;i<n-1;i++)
    printf("%d ",a[i]);
  printf("%d\n",a[i]);
  printf("%d\n",count);
  return 0;
}



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

int calq(long long N, vector<long long> P)
{
    int s = 0;
    for (int i = 0; i < N - 1; i++)
    {
        int tmp = 1;
        for (int j = 1; j <= N - 1 - i; j++)
        {
            tmp *= j;
        }

        int tmp2 = 0;
        for (int j = 1; j < P[i]; j++)
        {
            bool flag = true;
            for (int q = 0; q < i; q++)
            {
                if (j == P[q])
                    flag = !flag;
            }
            if (flag)
                tmp2++;
        }
        s += tmp * tmp2;
    }
    return s;
}

void solve(long long N, std::vector<long long> P, std::vector<long long> Q)
{
    int s = calq(N, P);
    int t = calq(N, Q);

    cout << abs(s - t) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> P(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &P[i]);
    }
    std::vector<long long> Q(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,i,a[3][3],c[3][3]={0};
    for(i=0;i<3;i++){
      for(int j=0;j<3;j++){
        scanf("%d",&a[i][j]);
      }
    }
    scanf("%d", &n);
    int b[n],t=0; 
    for(i=0;i<n;i++){
      scanf("%d",&b[i]);
    }
   for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        for(int k=0;k<n;k++){
          if(a[i][j]==b[k]) c[i][j]=1;
        }
      }
    }
    for(i=0;i<3;i++){
      if(c[i][0]==1&&c[i][1]==1&&c[i][2]==1) t=1;
    }
    for(i=0;i<3;i++){
      if(c[0][i]==1&&c[1][i]==1&&c[2][i]==1) t=1;
    }
    if(c[0][0]==1&&c[1][1]==1&&c[2][2]==1) t=1;
    if(c[2][0]==1&&c[1][1]==1&&c[0][2]==1) t=1;
    if(t==0) puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 128