akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    long long int n, W;   cin >> n >> W;
    vector< vector<long long int> > dp(n+1, vector<long long int>(100001));
    for(int i=1;n>=i;i++){
        long long int w, v;   cin >> w >> v;
        for(int j=100000;j>v;j--){
            dp[i][j]=dp[i-1][j];
            if(dp[i-1][j-v]){
                if(dp[i][j]){
                    dp[i][j]=min(dp[i-1][j-v]+w, dp[i][j]);   continue;
                }
                dp[i][j]=dp[i-1][j-v]+w;
            }
        }
        if(dp[i-1][v]){
            dp[i][v]=min(dp[i-1][v], w);
        }
        else{
            dp[i][v]=w;
        }
        for(int j=1;v>j;j++){
            dp[i][j]=dp[i-1][j];
        }
    }
    for(int i=100000;i;i--){
        if(dp[n][i] and dp[n][i]<=W){
            cout << i;  return 0;
        }
    }
    cout << 0;
}

Measured memory_bytes: 80256
program main
	implicit none
	integer:: n,i=2
	read(*,*)n
	do
		i=i*2
		if(i>n)exit
	enddo
	i=i/2
	if(n==1)i=1
	if(i>=10)then
		write(*,"(i2)")i
	else 
		write(*,"(i1)")i
	endif
	end program main


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  int k;
  cin >> k;
  vint A(k);
  rep(i,0,k) cin >> A[i];
  int up = 2;
  int down = 2;
  rrep(i,k-1,0){
    down = A[i]*((down + (A[i]-1))/A[i]);
    up = A[i]*(up/A[i]) + (A[i] - 1);
    if(down > up){
      cout << -1 << endl;
      return 0;
    }
    // cout << down << " " << up << endl;
  }
  cout << down << " " << up << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,z[1000005];
bool fi[1000005],ls[1000005];
set<char> used;
string st;
void getz(string st)
{
	int i,l=0,r=0,le=st.length();
	for (i=1;i<=le;i++)
	{
		if (i<=r)
		{
			z[i]=min(z[i-l],r-i);
		}
		while (i+z[i]<le&&st[z[i]]==st[i+z[i]]) z[i]++;
		if (i+z[i]>r)
		{
			l=i;
			r=i+z[i];
		}
	}
	for (i=le+1;i;i--) z[i]=z[i-1];
}
void getz2(string st)
{
	reverse(st.begin(),st.end());
	int i,l=0,r=0,le=st.length();
	for (i=1;i<=le;i++)
	{
		z[i]=0;
		if (i<=r)
		{
			z[i]=min(z[i-l],r-i);
		}
		while (i+z[i]<le&&st[z[i]]==st[i+z[i]]) z[i]++;
		if (i+z[i]>r)
		{
			l=i;
			r=i+z[i];
		}
	}
	for (i=le+1;i;i--) z[i]=z[i-1];
	
}
int main()
{
	cin>>st;
	st=" "+st;
	n=st.length()-1; 
	for (i=1;i<st.length();i++)
	{
		used.insert(st[i]);
	}
	if (used.size()==1)
	{
		cout<<st.length()-1<<endl<<1;
		return 0;
	}
	st.erase(0,1);
	getz(st);
	for (i=2;i<n;i++)
	{
		if (n%i!=0) continue;
		bool ok=1;
		for (j=i+1;j<=n;j+=i)
		{
			if (z[j]<i)
			{
				ok=0;
				break;
			}
		}
		if (ok)
		{
			cout<<2<<endl;
			int ans=0;
			for (i=1;i<n;i++)
			{
				for (j=i+1;j<=n;j+=i)
				{
					if (z[j]<i)
					{
						break;
					}
					fi[j+i-1]=1;
				}
			}
			getz2(st);
			for (i=1;i<n;i++)
			{
				for (j=i+1;j<=n;j+=i)
				{
					if (z[j]<i)
					{
						break;
					}
					ls[j+i-1]=1;
				}
			}
			reverse(ls+1,ls+n+1);
			for (i=2;i<=n;i++)
			{
				if (fi[i-1]||ls[i]);
					else ans++;
			}
			cout<<ans;
			return 0;	
		}
	}
	cout<<1<<endl<<1;
	return 0;
}

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

int GetDayWeek(int64 Y, int64 M, int64 D) {
  if(M <= 2) {
    Y--, M += 12;
  }
  return(D + ((8 + 13 * M) / 5) + (Y + Y / 4 - Y / 100 + Y / 400)) % 7;
}

int main() {
  int64 Y[2], M[2], D[2];

  const int64 Fry = 688;

  for(int i = 0; i < 2; i++) {
    cin >> Y[i] >> M[i] >> D[i];
  }
  if(D[0] <= 13) M[0]--;
  if(D[1] < 13) M[1]--;


  int64 Begin = Y[0] / 400LL * Fry;
  int64 End   = Y[1] / 400LL * Fry;
  int64 ret1 = 0, ret2 = 0;

  // ?????????????????¨???
  for(int64 i = Y[0] / 400LL * 400LL + 1; i <= Y[0]; i++) {
    for(int j = 1; j <= (Y[0] == i ? M[0] : 12); j++) {
      ret1 += (GetDayWeek(i, j, 13) == 5);
    }
  }

  for(int64 i = Y[1] / 400LL * 400LL + 1; i <= Y[1]; i++) {
    for(int j = 1; j <= (Y[1] == i ? M[1] : 12); j++) {
      ret2 += (GetDayWeek(i, j, 13) == 5);
    }
  }
  cout << (End - Begin) + (ret2 - ret1) << endl;  
}


Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     1000000007
#define PI                      2*acos(0.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     10005
#define LIM                     10000007

using namespace std;

struct Matrix{
    ll a[51][51];
};

Matrix dp[MAX];
bool vis[MAX];

Matrix I;

Matrix mat_mult(Matrix A,Matrix B,ll n)
{
    Matrix C;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            C.a[i][j]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                C.a[i][k]=(C.a[i][k]+A.a[i][j]*B.a[j][k]);
//                if(C.a[i][k]>=MOD)
                    C.a[i][k]%=MOD;
            }
        }
    }
    return C;
}

//Matrix fast_exp(Matrix A,ll p,int n)
//{
//    Matrix Ans;
//
//    if(p<MAX && vis[p])
//    {
//        return dp[p];
//    }
//    if(p==1)return mat_mult(A,I,n);
//    else if(p%2==0)
//    {
//        Matrix A1 = fast_exp(A,p/2,n);
//        Ans=mat_mult(A1,A1,n);
//    }
//    else Ans=mat_mult(fast_exp(A,p-1,n),A,n);
//    if(p<MAX)
//    {
//        vis[p]=1;
//        dp[p]=Ans;
//    }
//    return Ans;
//}

Matrix fast_exp(Matrix A,ll p,int n)
{
    Matrix Ans=I;
    while(p>0)
    {
        if(p%2!=0)
        {
            Ans = mat_mult(Ans,A,n);
        }
        A = mat_mult(A,A,n);
        p/=2;
    }
    return Ans;
}

int main()
{
//    READ;
//    WRITE;
    for(int i=0;i<51;i++)
    {
        for(int j=0;j<51;j++)
        {
            I.a[i][j]=0;
            if(i==j)I.a[i][j]=1;
        }
    }
    Matrix A,B;
    ll n,k,ans=0;
    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            scanf("%lld",&A.a[i][j]);
        }
    }
    B=fast_exp(A,k,n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            ans+=B.a[i][j];
            if(ans>=MOD)
            ans%=MOD;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;
typedef long long int ll;
const ll MAX = 2e5+3;
const ll INF = 1e9;
ll dp[MAX];


int main()
{
    ll n,k;
    cin>>n>>k;
    ll ht[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>ht[i];
      	dp[i]=INF;
    }

    dp[0]=dp[1]=0;
    for(int i=2;i<=k+1 && i<=n;i++)
    {
        dp[i]=abs(ht[i]-ht[1]);
    }
    for(int i=2;i<=k+1;i++)
    {
        for(int j=i-1;j>=1;j--)
        {
            dp[i]=min(dp[i],abs(ht[i]-ht[j])+dp[j]);
        }
    }
    for(int i=k+2;i<=n;i++)
    {
        for(int j=i-k;j<=i-1;j++)
        {    
               dp[i]=min(dp[i],dp[j]+abs(ht[i]-ht[j]));
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

const int MaxN = 100;
int n, m;
int dp[105][105][305];
struct Node {
	int w, v;
}a[105];

int main() 
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d%d", &a[i].w, &a[i].v);
	int t = a[1].w; int sum = 0;
	for(int i = 1; i <= n; i++) a[i].w -= t, sum += a[i].w;
	int ans = 0;
	for(int k = 1; k <= n; k++) {
		m -= t;
		if(m < 0) break;
		memset(dp, 0, sizeof(dp));
		for(int i = 1; i <= n; i++)
			for(int p = 1; p <= k; p++)
				for(int j = 0; j <= min(m, sum); j++) {
					dp[i][p][j] = dp[i - 1][p][j];
					if(j >= a[i].w) 
						dp[i][p][j] = max(dp[i][p][j], dp[i - 1][p - 1][j - a[i].w] + a[i].v);
				}
		for(int i = 1; i <= n; i++)
			for(int j = 0; j <= min(m, sum); j++) ans = max(ans, dp[i][k][j]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 13440
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

template<class T> void gc(T &x)
{
    int k = 0;
    int m = 0;

    while (true)
    {
        k = getchar_unlocked();

        // none negative
        //if (k == '-')
        //{
        //    m = 1;
        //    break;
        //}

        if ('0' <= k && k <= '9')
        {
            x = k - '0';
            break;
        }
    }
    while (true)
    {
        k = getchar_unlocked();

        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }

    // none negative
    //if (m) x = -x;
}

int main()
{
    int N, X, a;

    // 前の箱の飴の数
    int bka;

    // X との差異
    int div;

    long long int ans = 0LL;

    gc(N);
    gc(X);
    gc(a);

    if (X < a)
    {
        div = a - X;
        a -= div;
        ans += div;
    }

    bka = a;

    for (int i = 1; i < N; i++)
    {
        gc(a);

        div = bka + a - X;

        if (div > 0)
        {
            a -= div;
            ans += div;
        }

        bka = a;
    }

    printf("%lld\n", ans);    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

			int result = Integer.MAX_VALUE;

			for (int i = 0; i <= s.length() - t.length(); i++) {

				int temp = 0;

				for (int j = 0; j < t.length(); j++) {
					if (s.charAt(i + j) != t.charAt(j)) {
						temp++;
					}
				}

				result = Math.min(result, temp);

			}

			System.out.println(result);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 35908
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

typedef long long ll;
ll gcd(ll x, ll y){ return y ? gcd(y,x%y) : x; }
ll lcd(ll x, ll y){
    return x/gcd(x,y) * y;
}

int main(){
    ll a1,a2,a3,m1,m2,m3;
    ll i,j,k;

    while( cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 ){
        if( !(a1|a2|a3|m1|m2|m3) ) break;

        ll a = a1;
        for(i=1; a!=1 ;i++) a = a * a1 % m1;

        ll b = a2;
        for(j=1; b!=1; j++) b = b * a2 % m2;

        ll c = a3;
        for(k=1; c!=1; k++) c = c * a3 % m3;

        cout << lcd(lcd(i,j),k) << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n, k; cin >> n >> k;
    vector<pair<ll, ll>> ab(n);
    rep(i, n){
        ll a, b; cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(), ab.end());
    ll cnt = 0;
    for(auto i : ab){
        cnt += i.second;
        if(k <= cnt){
            cout << i.first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdlib.h>
#include <stdio.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(void){
  int a=0;
  scanf("%d",&a);
  int b[a+1];
  int check = 0;
  for(int i=0; i<a; i++){
    scanf("%d",&b[i]);
  }
  qsort(b,a,sizeof(int),compare_int);
  for(int i=0; i<a; i++){
    if(b[i]==b[i+1]){
      check=1;
    }
  }
  if(check==1){
    printf("NO");
  }else{
    printf("YES");
  }
  }

Measured memory_bytes: 1788
from itertools import groupby
from operator import itemgetter

N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)


class UnionFindTree:
    def __init__(self, n):
        self.p = [i for i in range(n + 1)]
        self.r = [0 for _ in range(n + 1)]

    def find(self, x):
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
        return self.p[x]

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.r[px] < self.r[py]:
                self.p[px] = py
            else:
                self.p[py] = px
                if self.r[px] == self.r[py]:
                    self.r[px] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


# x座標またはy座標を共有する点についてグループ化する
# グループごとに可能な操作回数を求めるのは簡単
uft = UnionFindTree(N)
for d in range(2):
    for _, g in groupby(
                sorted(
                    zip(
                        x,
                        y,
                        range(1, N + 1)
                    ),
                    key=itemgetter(d)
                ),
                key=itemgetter(d)
            ):
        p = list(g)
        for (_, _, i), (_, _, j) in zip(p[1:], p):
            uft.union(i, j)
ans = sum(
    len({x for x, _, _ in C}) * len({y for _, y, _ in C}) - len(list(C))
    for C in (
        list(g)
        for _, g in groupby(
            sorted(
                (
                    (x, y, uft.find(i))
                    for x, y, i in zip(
                        x,
                        y,
                        range(1, N + 1)
                    )
                ),
                key=itemgetter(2)
            ),
            key=itemgetter(2)
        )
    )
)

print(ans)


Measured memory_bytes: 126808
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = 0x3f3f3f3f;

int n, k;
ll ans;
vector<int> adj[100010];
ll f[100010];
ll inv[100010];
ll finv[100010];
vector<int> v(100010);

void dfs(int nn, int c)
{
    v[nn]=1; int p=0;
    for(int i=0; i<(int)adj[nn].size(); i++)
    {
        if(!v[adj[nn][i]])
        {
            dfs(adj[nn][i], max(c-1, k-2));
            p++;
        }
    }
    if(c-p<0)
    {
        ans=0;
        return;
    }
    ans = ans*f[c]%mod*finv[c-p]%mod;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n >> k;
    for(int i=0; i<n-1; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    f[0]=f[1]=inv[1]=finv[0]=inv[0]=finv[1]=1;
    for(int i=2; i<=k; i++){
        f[i]=f[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    ans=k;
    dfs(1, k-1);
    cout << ans;
}


Measured memory_bytes: 11136
A, B = map(int, input().split())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import fractions
x = fractions.gcd(A, B)
ans = prime_factorize(x)
print(len(set(ans))+1)

Measured memory_bytes: 64108
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()
int pow(int v,long long k){
    int res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

signed main() {
	int x;
	std::cin >> x;
	print(pow(2,x+2)-2);
	return 0;
}


Measured memory_bytes: 256
/*input
1 2 3 4

*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
#define trav(a,x) for(auto &a:x)
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
//void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1000005;


	

int32_t main() {
    IOS;
	int a,b,c,k;cin>>a>>b>>c>>k;
	int ans = min(k,a);
	k -= ans;
	if(k==0){
		cout<<ans<<endl;
		return 0;
	}
	k-=min(b,k);
	if(k==0){
		cout<<ans<<endl;
	}
	else{
		cout<<ans-min(c,k)<<endl;
	}
	return 0;
}






Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

ll ds(ll n)
{
        ll sm = 0;
        while (n > 0) {
                sm += n % 10;
                n /= 10;
        }
        return sm;
}

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

        ll ans = inf;

        rep(i, 1, N) {
                ll j = N - i;
                chmin(ans, ds(i) + ds(j));
        }

        cout << ans << endl;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
 
using namespace std;
long long int modInverse(long long int a, long long int m) 
{ 
    long long int m0 = m; 
    long long int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        long long int q = a / m; 
        long long int t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
 
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n;
long long int const p=1000000007;
cin>>n;
long long int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
long long int sum=0;
long long int sum1=0;
for(int i=0;i<n;i++)
{
	sum= (sum + a[i])%(p);
	sum1 = (sum1 + a[i]*a[i])%p;
}

cout<<  ((((sum*sum)%p - sum1 + p)%p)*((modInverse(2,p))%p))%p<<endl;
}

 
 

 


Measured memory_bytes: 5192
#define _CRT_SECURE_NO_WARNINGS
#define MAX_DATA 200000
#define MIN_DATA 2

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){

	int NUM;
	scanf( "%d", &NUM );


	int max = -1000000000;
	int min = 0;
	int temp;

	scanf("%d", &min);

	for (int i = 1 ; i < NUM ; i++){
		scanf("%d", &temp);

		int sub = temp - min;

		if (sub > max) {
			max = sub;
		}

		if (temp < min){
			min = temp;
		}
	}



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

	return 0;
}

Measured memory_bytes: 1028
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String u, nl = System.getProperty("line.separator");
		StringBuilder 
			p = new StringBuilder(1000),
		  	d = (new StringBuilder(100)).append("."),
		  	s = (new StringBuilder(100)).append("#"),
		  	k = new StringBuilder(100);
		Scanner r = new Scanner(System.in);
		int h, w, ww = 0x10;
		while (0 != (ww >>= 1)) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(u = s.substring(0, w)).append(nl);
			k.setLength(0);
			k.append(d.substring(0, w)).append(nl)
			.replace(0, 1, "#").replace(w - 1, w, "#");
			while (2 != h--) {
				p.append(k);
			}
			p.append(u).append(nl).append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18396
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}

int main() {
	ll N,M;
	cin >> N>>M;
	ll a[N + 10];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	ll sum = 0;
	map<ll, ll>cnt;
	cnt[0] = 1;
	for (ll i = 0; i < N; i++) {
		sum += a[i]; 
		ans += cnt[sum%M];
		cnt[sum%M]++;
	}
	cout << ans << endl;

		
}


Measured memory_bytes: 4992
import math
a = int(input())
 
b = math.floor(a/1.08)
 
if a <= b*1.08 and b*1.08 < a + 1:
    print(b)
elif a <= (b + 1)*1.08 and (b + 1)*1.08 < a + 1:
    print(b+1)
else:
    print(":(")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long N, long long A, long long B){
  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(N, A, B);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
    constexpr Int mod = 1e9 + 7;
    Int N; cin >> N;
    vector<vector<Int>>edge(N);
    for(Int i = 0; i < N - 1; ++i){
        Int u,v; cin >> u >> v;
        --u;--v;
        edge[v].push_back(u);
        edge[u].push_back(v);
    }
    Int root = -1;
    for(int i = 0; i < N; ++i)
        if(edge[i].size() != 1)
            root = i;
    vector<vector<Int>>dp(2,vector<Int>(N,-1));
    
    function<Int(Int,Int,Int)>solve = [&](Int color,Int v,Int prev){
        if(edge[v].size() == 1){
            return dp[color][v] = 1;
        }
        if(dp[color][v] != -1) return dp[color][v];
        Int res = 1;
        for(auto nv : edge[v]){
            if(nv == prev) continue;
            res *= (solve(1,nv,v) + (color ? solve(0,nv,v) : 0));
            res %= mod;
            
        }
        return dp[color][v] = res;
    };
    cout << (solve(0LL,root,-1) + solve(1LL,root,-1)) % mod << endl;
    
}


Measured memory_bytes: 16752
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long count = 0;
		ArrayList<Long> list = new ArrayList<Long>();

		for(int i = 0;i < n;i++) {
			list.add(scan.nextLong());
		}

		Collections.sort(list, Comparator.reverseOrder());

		if(n == 2) {
			count += list.get(0);
		}else {
			for(int i = 1;i < n;i++) {
				if(i <= n/2) {
					count += list.get(i - 1);
				}else {
					count += list.get(i - n/2);
				}

			}
		}


		System.out.println(count);
	}
}


Measured memory_bytes: 66264
require 'set'
s = Set.new
h = {}
loop do
    k, point = gets.split(",").map(&:to_i)
    break if k == 0
    h[k] = point
    s << point
end
rank = {}
s.sort.reverse.each.with_index {|x, i| rank[x] = i+1}

while l = gets
    n = l.to_i
    puts rank[h[n]]
end



Measured memory_bytes: 6960
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        int XMax = X;
        int YMin = Y;

        for(int i=0; i<N; i++){
            XMax = Math.max(XMax, scanner.nextInt());
        }

        for(int j=0; j<M; j++){
            YMin = Math.min(YMin, scanner.nextInt());
        }

        if(YMin <= XMax){
            System.out.println("War");
        }else{
            System.out.println("No War");
        }
    }
}


Measured memory_bytes: 21972
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(){
	int n,a;cin>>n;
	vector<int> v;
	REP(i,n){
		cin>>a;
		v.push_back(a);
	}

	sort(v.begin(),v.end(),greater<int>());
	long long b[2] = {};
	int j=0;
	for(int i=0;i<v.size()-1;i++){
		if(v[i]==v[i+1]){
			b[j]=v[i];
			j++;
			i++;
		}
		if(j==2){
			cout<<b[0]*b[1]<<endl;
			return 0;
		}
	}
	cout<<"0"<<endl;
	return 0;
}



Measured memory_bytes: 1652
N, K = map(int, raw_input().split())

prob = 0.0
potencias = [1]
i = 1
while i < 100001:
    i *= 2
    potencias.append(i)


# print potencias
for i in xrange(1, N+1):
    if i < K:
        j = 0
        while potencias[j]*i < K:
            j += 1
        p = 1.0/(N*1.0)
        p *= (0.5**j)
        prob += p
    else:
        prob += 1.0/(N*1.0)
    
print prob

Measured memory_bytes: 2568
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int ans[305], n;
    int x[1005], y[1005], z[1005], check;
    int ac, bc, cc;
    while(cin >> ac >> bc >> cc, ac||bc||cc){
        rep(i, ac + bc + cc + 1){
            ans[i] = 2;
        }
        cin >> n;
        rep(i,n){
            cin >> x[i] >> y[i] >> z[i] >> check;
            if(check){
                ans[x[i]] = check;
                ans[y[i]] = check;
                ans[z[i]] = check;
            }
        }
        rep(i,n){
            if(ans[x[i]] == 1 && ans[y[i]] == 1 && ans[z[i]] != 1)
                ans[z[i]] = 0;
            else if(ans[x[i]] == 1 && ans[y[i]] != 1 && ans[z[i]] == 1)
                ans[y[i]] = 0;
            else if(ans[x[i]] != 1 && ans[y[i]] == 1 && ans[z[i]] == 1)
                ans[x[i]] = 0;
        }
        range(i, 1, ac + bc + cc + 1){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 1172
#include<iostream>
int main() {
	int n;
	std::cin >> n;
	int a[100];
	for (int i = 0; i < n; i++)
		std::cin >> a[i];
	int max = a[0], min = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) max = a[i];
		if (a[i] < min) min = a[i];
	}
	std::cout << max - min << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);

		int s = scan.nextInt();
		int w = scan.nextInt();

		if(w >= s){
			System.out.println("unsafe");
		}
	else {
		System.out.println("safe");
	}
}
}


Measured memory_bytes: 27040
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int A[MAXN], B[MAXN];
bool visit[MAXN];
int edge[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    vector<pii> V1, V2;
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        V1.push_back(make_pair(A[i], i));
    }
    for (int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
        V2.push_back(make_pair(B[i], i));
    }
    sort(V1.begin(), V1.end());
    sort(V2.begin(), V2.end());
    bool OK1 = true, OK2 = false;
    for (int i = 0; i < N; i++) {
        int cur_B = V2[i].first, org_A = A[V2[i].second];
        if (V1[i].first > cur_B) OK1 = false;
        if (i && V2[i - 1].first >= V1[i].first) OK2 = true;
        edge[V1[i].second] = V2[i].second;
    }
    if (!OK1) return !printf("No\n");
    if (OK2) return !printf("Yes\n");
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (visit[i]) continue;
        cnt++;
        int cur = i;
        while (!visit[cur]) {
              visit[cur] = 1;
              cur = edge[cur];
        }
    }
    if (cnt > 1) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3188
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int v[] = new int[N];
    
    for(int i=0; i<N; i++) {
      v[i] = sc.nextInt();
    }
    Arrays.sort(v);
    
    String newV[] = new String[N-1];
    double sum01 = ((double)v[0]/2 + (double)v[1]/2);
    newV[0] = String.valueOf(sum01);
    if(N>1) {
      for(int j=1; j<N-1; j++) {
        String val1 = newV[j-1];
        String val2 = String.valueOf(v[j+1]);
        BigDecimal bd1 = new BigDecimal(val1);
        BigDecimal bd2 = new BigDecimal(val2);
        BigDecimal sum =bd1.add(bd2);
        BigDecimal two = new BigDecimal(2.0);
        BigDecimal result = sum.divide(two);
        newV[j] = result.toString();
    	}
    }
    
    System.out.println(newV[N-2]);
  }
}

Measured memory_bytes: 24148
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
    }

    let mut odd: i32 = 0;

    for i in 1..n + 1 {
        if i % 2 == 1 {
            odd += 1;
        } else {
            continue;
        }
    }

    println!("{}", odd as f32 / n as f32);
}


Measured memory_bytes: 4352
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

typedef long long int ll;
const ll mod = 1e9+7;
const ll INF= 1e18;
const long double PI=3.1415926;

ll power(ll a,ll b){
    if(b==0)
        return 1;
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}

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

vector<ll>v;
vector<ll>::iterator it;
map<ll,ll>mp;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
        freopen("out.tex", "w", stdout);
    #endif

    ll t;
    //cin>>t;
    t=1;
    //ll c=1;
    while(t--){
        ll n;
        cin>>n;
        ll arr[n][n];
        for(ll x=0; x<n; x++){
            for(ll y=0; y<n; y++){
                cin>>arr[x][y];
            }
        }
        ll dp[1<<n];
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        for(ll x=1; x<(1<<n); x++){
            ll count=__builtin_popcount(x);
            //cout<<count<<"\n";
            for(ll y=0; y<n; y++){
                if(arr[count-1][y]==1&&(x&(1<<y))!=0){
                    dp[x]+=dp[x-(1<<y)];
                    dp[x]%=mod;
                }
            }
        }
        cout<<dp[(1<<n) -1]<<"\n";
        mp.clear();  
        v.clear();
        //cout<<"Case #"<<c<<": "<<ans<<"\n";
        //c++;
    }
    return 0;
}

Measured memory_bytes: 20024
N = gets.to_i
H = gets.split.map(&:to_i)

result = 0
count = 0

(1...H.size).each do |n|
  if H[n-1] >= H[n]
    count += 1
  else
    result = count if count > result
    count = 0
  end
end

result = count if count > result

puts result

Measured memory_bytes: 8580
#include <iostream>
#include <string>
using namespace std;
 
int main() { 
    string s, s_f;
    int ans1 = 0, ans2 = 0;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(i%2) {
            if(s[i] == '0') {
                ans1++;
            }
        } else {
            if(s[i] == '1') {
                ans1++;
            }
        } 
    }
    for(int i = 0; i < s.size(); ++i) {
        if(i%2) {
            if(s[i] == '1') {
                ans2++;
            }
        } else {
            if(s[i] == '0') {
                ans2++;
            }
        } 
    }
    cout << min(ans1, ans2) << '\n';
}

Measured memory_bytes: 512
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 200001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,p[N],q[N],T[N],f[N];
bool cyclic(int a,int b,int c)
{
	return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b);
}
int main()
{
	re(n);
	for(int i=1;i<=n;++i)re(p[i]);
	for(int i=1;i<=n;++i)
		q[p[i]]=i;
	for(int i=n-1;i;--i)
	{
		if(!T[i+1])
		{
			if(q[i]<q[i+1])T[i]=0;
			else T[i]=1,f[i]=i+1;
		}
		else
		{
			if(cyclic(q[f[i+1]],q[i],q[i+1]))T[i]=T[i+1],f[i]=f[i+1];
			else T[i]=T[i+1]+1,f[i]=i+1;
		}
	}
	printf("%d\n",T[1]);
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main() {
	int a,sum=0;
	for(int i = 0; i < 5; i++) {
		cin >> a;
		if (a < 40)a = 40;
		sum += a;
	}
	cout << (int)(sum / 5) << endl;
}

Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using ll = long long;
using namespace std;
int main(){
    ll n,k,m=1000000000000,h,H;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)    cin >> a[i];
    sort(a.begin(),a.end());
    for(ll i=0;i<(n-k+1);i++){
        ll sa = a[i+k-1]-a[i];
        if(sa<m)    m = sa;
    }
    cout << m;
    return 0;
}

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

using namespace std;
const static int INT_INF = 2147483647;
const static int MOD_NUM = 1000000007;
static string S[2005] = { "" };

int main()
{
	int n, x;
	int bounds[102];
	cin >> n >> x;

	for (int i = 1; i <= n; i++)
	{
		cin >> bounds[i];
	}

	int sum = 0;

	int result = n + 1;
	for (int i = 1; i <= n; i++)
	{
		sum += bounds[i];
		if (sum > x) {
			result = i;
			break;
		}
	}

	cout << result << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const int mod = 1000000007;
int dp[3000000][22];
bool field[22][22];
vector<int> in[3000000];
int n;
int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int in;
            cin >> in;
            if(in == 1) field[i][j] = true;
            else field[i][j] = false;
        }
    }
    for(ll bits = 0; bits < ((ll)1<<n); ++bits){
        for(int woman = 1; woman <= n; woman++){
            if(!(bits & ((ll)1 << (woman - 1)))) in[bits].push_back(woman);
            //cout << bits << " " << woman << endl;
        }
    }
    dp[0][0]++;
    for(int man = 1; man <= n; man++){
        for(ll bits = 0; bits < ((ll)1<<n); ++bits){
            if(__builtin_popcount(bits) != (man - 1)) continue;
            dp[bits][man] = (dp[bits][man] + dp[bits][man - 1]) % mod;
            //dp[bits][man] %= mod;
            //cout << man << " " << bits << " " << dp[bits][man - 1] << endl;
            for(int i = 0; i < in[bits].size(); i++){
                //cout << i << endl;
            //for(ll woman = 1; woman <= n; woman++){
                int woman = in[bits][i];
                //cout << man << " " << woman << " " << bits << endl;
                //if(bits & ((ll)1<<(woman - 1))) continue;
                if(!field[man][woman]) continue;
                //cout << man << " " << woman << " " << bits << endl;
                //dp[bits | ((ll)1<<(woman - 1))][man] += dp[bits][man - 1];
                dp[bits | ((ll)1<<(woman - 1))][man] = (dp[bits][man - 1] + dp[bits | ((ll)1<<(woman - 1))][man]) % mod;
            }
        }
    }
    cout << dp[((ll)1 << n) - 1][n] << endl;
    return 0;
}


Measured memory_bytes: 403712
#include <stdio.h>

int main()
{
   int r,g,b,a;
   scanf("%d", &r);
   scanf("%d", &g);
   scanf("%d", &b);
   a = r*100 + g*10 + b;
   
   if(a%4 == 0){
   printf("YES");
   }else{
   printf("NO");
   }
   
   return 0;
}

Measured memory_bytes: 128
s = input()

if s == 'SUN':
    print("7")
elif s == 'MON':
    print("6")
elif s == 'TUE':
    print("5")
elif s == 'WED':
    print("4")
elif s == 'THU':
    print("3")
elif s == 'FRI':
    print("2")
elif s == 'SAT':
    print("1")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
char s[100005],cmp1[100005],cmp2[100005];
int ans1,ans2;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>s;
	int len=strlen(s);
	for(int i=0;i<len;i++){
		if(i%2) cmp1[i]='1',cmp2[i]='0';
		else cmp1[i]='0',cmp2[i]='1';
	}
	for(int i=0;i<len;i++){
		if(s[i]!=cmp1[i]) ans1++;
		if(s[i]!=cmp2[i]) ans2++;
	}
	cout<<min(ans1,ans2);
	re 0;
}


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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    string s;
    cin >> n >> s;
    modint res = 1;
    map<char, ll> cnt;
    rep(i,n) {
        cnt[s[i]]++;
    }
    for (auto itr : cnt) {
        res *= (itr.second+1);
    }
    cout << res-modint(1) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

#define keta setprecision(15) //15桁表示

//最大公約数
long long gcd(long long a, long long b)
{
	long long tmp, r;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

//最小公倍数
long long lcm(long long a, long long b)
{
	long long tmp, x;
	x = a * b;
	return x / gcd(a, b);
}

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

	ll a, b;
	cin >> a >> b;

	cout << lcm(a, b) << endl;

	return 0;
}

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

int A[MAX],n;

int partition(int p,int r)
{
	int x,i,j,t;
	x = A[r];
	i = p - 1;
	for(j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

int main()
{
	int i,q;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++) scanf("%d",A + i);
	
	q = partition(0,n - 1);
	
	for(i = 0; i < n; i++)
	{
		if(i) printf(" ");
		if(i == q) printf("[");
		printf("%d",A[i]);
		if(i == q) printf("]");
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2140
mod = 10**9+7
n, X = map(int, input().split())
s = [int(x) for x in input().split()]
s = sorted(s)

dp = [[0 for _ in range(X+1)] for _ in range(n+1)]

for i in range(n+1):
    if i == 0:
        for x in range(X+1):
            dp[i][x] = x
    else:
        for x in range(X+1):
            dp[i][x] = dp[i-1][x % s[i-1]] + dp[i-1][x]*(i-1)
            dp[i][x] %= mod

ans = dp[n][X]

print(ans)


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

int n;
int li[105];

inline int sq(int x){
	return x*x;
}

int main(){
	scanf("%d",&n);
	int tot = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
		tot+=li[i];
	}
	int tb = tot/n;
	int ta = (tot+n-1)/n;
	int tmpa = 0;
	int tmpb = 0;
	for(int i=1;i<=n;i++){
		tmpa += sq(li[i]-ta);
		tmpb += sq(li[i]-tb);
	}
	printf("%d\n",min(tmpa,tmpb));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    char ch;
    do{
        cin.get(ch);
        if(islower(ch)) cout<<(char)toupper(ch);
        else if(isupper(ch)) cout<<(char)tolower(ch);
        else cout<<ch;
    }while(ch!='\n');
    return 0;
}

Measured memory_bytes: 1148