akhauriyash/Code-Regression huggingface dataset:
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
#define MA 2525
lint dp[58][MA+50];
bool sumi[58][MA+50];
lint inf=1e18;
priority_queue<tint> q;
void ae(int x,int y,lint z){
	if(dp[x][y]<=z) return;
	dp[x][y]=z;
	q.push(mp(-z,mp(x,y)));
}
vector<tint> gr[58];
lint c[58],d[58],out[58];
int main()
{
	int n,m,s,a,b,u,v;cin>>n>>m>>s;s=min(s,MA);
	rep(i,m){
		cin>>u>>v>>a>>b;u--;v--;
		gr[u].pb(mp(v,mp(b,a)));
		gr[v].pb(mp(u,mp(b,a)));
	}
	rep(i,n) cin>>c[i]>>d[i];
	rep(i,58){
		out[i]=inf;
		rep(j,MA+10) dp[i][j]=inf;
	}
	memset(sumi,false,sizeof(sumi));
	ae(0,s,0);
	while(!q.empty()){
		tint p=q.top();q.pop();
		int x=p.se.fi,y=p.se.se;lint z=-p.fi;
		if(sumi[x][y]) continue;
		sumi[x][y]=true;
		//cout<<x<<' '<<y<<' '<<z<<endl;
		out[x]=min(out[x],z);
		REP(i,1,MA){
			ae(x,min(c[x]*i+y,(lint)MA),z+d[x]*i);
			if(c[x]*i+y>MA) break;
		}
		rep(i,gr[x].size()){
			p=gr[x][i];
			if(p.se.se<=y) ae(p.fi,y-p.se.se,z+p.se.fi);
		}
	}
	REP(i,1,n) cout<<out[i]<<endl;
}


Measured memory_bytes: 70232
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() {
    char ch;
    for(int i=0; i<3; i++) {
        cin >> ch;
        if(ch == '7') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define pii pair<int,int>
#define abs(x)  ((x)>=0?x:-(x))
using namespace std;
int n,a[100010];
int read()
{
	int x=0,f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	int tot=0,k=n+1;
	for(int i=1;i<=n;i++)
		if(a[i]>=0) {k=i;break;}
	for(int i=1;i<=n;i++)
		tot+=abs(a[i]);
	if(k==1)
	{
		printf("%d\n",tot-a[1]-a[1]);
		int p=a[1];
		for(int i=2;i<=n-1;i++)
		{
			printf("%d %d\n",p,a[i]);
			p-=a[i];
		}
		printf("%d %d\n",a[n],p);	
	}
	else if(k>n)
	{
		printf("%d\n",tot+a[n]+a[n]);
		int p=a[n];
		for(int i=1;i<=n-1;i++)
		{
			printf("%d %d\n",p,a[i]);
			p-=a[i];
		}
	}
	else
	{
		printf("%d\n",tot);
		int p=a[1];
		for(int i=k;i<n;i++)
		{
			printf("%d %d\n",p,a[i]);
			p-=a[i];
		}
		int q=a[n];
		for(int i=2;i<k;i++)
		{
			printf("%d %d\n",q,a[i]);
			q=q-a[i];
		}
		printf("%d %d\n",q,p);		
	}

	return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;
vector<int> a, b;

signed main()
{
    cin >> n;

    a.resize(n + 1);
    rep(i, n + 1)
    {
        cin >> a[i];
    }
    b.resize(n + 1);
    rep(i, n)
    {
        cin >> b[i];
    }
    b[n] = 0;

    int ans = 0;
    int temp = 0;

    rep(i, n + 1)
    {
        if (a[i] >= b[i] + temp)
        {
            ans += b[i] + temp;
            temp = 0;
        }
        else
        {
            ans += a[i];
            if (temp >= a[i])
            {
                temp = b[i];
            }
            else
            {
                temp = b[i] - (a[i] - temp);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
n,m=map(int, input().split())
r = []

for i in range(n):
    r.append(str(0))

if n == 1 and m == 0:
    print('0')
    exit()
if n == 2 and m == 0:
    print('10')
    exit()
if n == 3 and m == 0:
    print('100')
    exit()

for i in range(m):
    s,c = map(int, input().split())
    if n == 1 and s == 1 and c == 0:
        print('0')
        exit()
    elif n > 1 and s == 1 and c == 0:
        print('-1')
        exit()

    if int(r[s-1]) == 0:
        r[s-1] = str(c)
    elif int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()

if n > 1 and r[0] == '0':
    r[0] = '1'
    print(''.join(r))
else:
    print(''.join(r))



Measured memory_bytes: 3064
parseInt(x) = parse(Int,x)
function gc(a::Array,m::Int,N::Int)
  if m == 1
    g = gcd(a[2:N])
  elseif m == N
    g = gcd(a[1:(N-1)])
  else
    g = gcd(gcd(a[1:(m-1)]),gcd(a[(m+1):N]))
  end
  return(g)
end

function main()
  N = parseInt(readline())
  a = map(parseInt,split(readline()))
  (b,k) = findmin(a)
  g = gc(a,k,N)
  d = zeros(Int,N)
  for i=1:N
    d[i] = gcd(b,a[i])
  end
  (c,l)=findmin(d)
  h = gc(a,l,N)
  GCD = maximum([g,h])
  println(GCD)
end

main()


Measured memory_bytes: 131412
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;

void solve(){
  ll h, w; cin >> h >> w;
  if(h%3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return ;
  }
  ll ans = 1e15;
  ans = min(ans, h);
  ans = min(ans, w);
  //横に１本それから縦に１本
  for(int i = 1; i < h; ++i){
    ll mainheight = i;
    ll anotherheight = h-i;
    ll smax;
    ll smin;
    if(w%2 == 0){
      smax = max(w * mainheight, w / 2 * anotherheight);
      smin = min(w * mainheight, w / 2 * anotherheight);
    } else {
      smax = max(w * mainheight, (w / 2 + 1) * anotherheight);
      smin = min(w * mainheight, w / 2 * anotherheight);
    }
    ans = min(ans, smax-smin);
  }
  //縦に１本それから横に１本
  for(int i = 1; i < w; ++i){
    ll mainwidth = i;
    ll anotherwidth = w-i;
    ll smaxw;
    ll sminw;
    if(h%2 == 0){
      sminw = min(h * mainwidth, h / 2 * anotherwidth);
      smaxw = max(h * mainwidth, h / 2 * anotherwidth);
    } else {
      smaxw = max(h * mainwidth, (h / 2 + 1) * anotherwidth);
      sminw = min(h * mainwidth, h / 2 * anotherwidth);
    }
    ans = min(ans, smaxw-sminw);
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int n, x,t;
	cin >> n >> x >>t;
	int time=ceil(double(n)/x);
	
	cout << int(time*t) << "\n";
	
	return 0;
}


Measured memory_bytes: 3660
N, X = [int(x) for x in input().split()]

list01 = []
for i in range(N):
  i = int(input())
  list01.append(i)

min_01 = 0
for i in range(len(list01)):
  if min_01 == 0:
    min_01 = list01[i]
  elif list01[i] < min_01:
    min_01 = list01[i]
  
for i in range(len(list01)):
  X -= list01[i]
    
print(X // min_01 + N)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;


#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull testcase;cin>>testcase;while(testcase--)
#define pb push_back
#define mp make_pair
#define nl cout<<"\n"
#define prime 1000000007
#define debug(x) cout<<(#x)<<" : "<<x,nl
#define debug2(x,y) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y,nl
#define debug3(x,y,z) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y<<" "<<(#z)<<" : "<<z,nl
#define f first
#define s second
#define oa(a,n) loop(i,0,n)cout<<a[i]<<" ";nl;
#define ov(a) loop(i,0,a.size()) cout<<a[i]<<" ";nl;
#define MOD(a) (((a%prime)+prime)%prime)

int main()
{


    ll a,b,i;

    cin >> a >> b;

    if(a>=13)
        cout << b;
    else if(a<13 && a>5)
        cout << b/2;
    else
        cout << 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

string S;

void solve() {

	ll ans = 0;
	ll tmp = 0;

	rep(i, S.size()) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
			tmp++;
		}
		else {
			ans = max(ans, tmp);
			tmp = 0;
		}
	}
	ans = max(ans, tmp);

	cout << ans;

	return;
}

int main() {

	cin >> S;

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] A = nextIntArray(sc, N);
		sc.close();

		int[] x = new int[N];

		x[0] = A[0];
		for (int i = 1; i < N; i += 2) {
			x[0] -= A[i];
			x[0] += A[i + 1];
		}

		for (int i = 1; i < N; i++) {
			x[i] = 2 * A[i - 1] - x[i - 1];
		}

		out.println(join(" ", x));
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 55364
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int maxn = 100 + 8;

int a,b,c;
int gcd(int a,int b)
{
    return b == 0 ? a : gcd(b,a%b);
}

int main()
{
    scanf("%d%d", &a, &b);
    int c;
    c = gcd(a,b);
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 3204
using System;

public class Program
{
	public static void Main()
	{
		var s = Console.ReadLine().Split(' ');
		var x = long.Parse(s[0]);
		var y = long.Parse(s[1]);
		
		Console.WriteLine(Program.GetGCD(x, y));
	}
	
	public static long GetGCD(long x, long y)
	{
		if(x < y) {
			long tmp = x;
			x = y;
			y = tmp;
		}
		
		while(x%y != 0) {
			long tmp = y;
			y = x%y;
			x = tmp;
		}
		
		return y;
	}
}

Measured memory_bytes: 9164
n = int(input())
al = list(map(int, input().split()))
l = 0
r = n-1

data = [[i, a] for i, a in enumerate(al)]
data.sort(key=lambda x: x[1], reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
    for j in range(0, i+1):
        p, a = data[i]
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + abs(n-1-j-p)*a)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a)
print(max(dp[-1]))


Measured memory_bytes: 100636
#include<bits/stdc++.h>
using namespace std;
struct ed{int to;int64_t cost;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<vector<ed>>g(n+1);
	for(int i=0;i<n-1;++i){
		int a,b,c; cin>>a>>b>>c;
		g.at(a).push_back({b,c});
		g.at(b).push_back({a,c});
	}
	int q,k; cin>>q>>k;
	vector<int64_t>mn(n+1,1e15); mn.at(k)=0;
	queue<ed>que; que.push({k,0});
	while(que.size()){
		ed t=que.front(); que.pop();
		for(auto&&i:g.at(t.to)){
			if(i.cost+t.cost>=mn.at(i.to))continue;
			mn.at(i.to)=i.cost+t.cost;
			que.push({i.to,mn.at(i.to)});
		}
	}
	for(int i=0;i<q;++i){
		int x,y; cin>>x>>y;
		cout<<mn.at(x)+mn.at(y)<<"\n"s;
	}
}


Measured memory_bytes: 12740
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX_N=25010;
const ll MAX_K=450;
const ll MOD=1000000007;
ll N,M,K,A[MAX_N],dp[MAX_N][MAX_K],dp_sum[MAX_N][MAX_K],ans,chk[MAX_K];
ll power(ll x,ll y){
    if(y==0ll) return 1ll;
    ll t=power(x,y/2ll);
    if(y%2ll) return t*t%MOD*x%MOD;
    return t*t%MOD;
}
ll fsum(ll l,ll k){
    if(K==M+k) return 0;
    if(N==l+M+k) return dp[N][M+k];
    return (dp_sum[N-l-M-k-1][M+k]*dp[l+M+k][M+k]%MOD+(K-M-k)*fsum(l,k+1)%MOD)%MOD;
}
int main(ll argc, char** argv)
{
    scanf("%lld%lld%lld",&N,&K,&M);
    for(ll i=0;i<M;i++) scanf("%lld",&A[i]);
    for(ll i=0;i<=M-K;i++){
        ll t=0;
        for(ll j=0;j<K;j++) chk[A[i+j]]=1;
        for(ll j=1;j<=K;j++) t+=chk[j],chk[j]=0;
        if(t==K){
            printf("%lld\n",(N-M+1ll)*power(K,N-M)%MOD);
            return 0;
        }
    }
    dp[0][0]=1;
    for(ll j=1;j<=K;j++) dp[0][j]=0;
    for(ll i=1;i<=N;i++){
        for(ll j=K-1;j>=0;j--){
            if(i<j) dp[i][j]=0;
            else if(i==j) dp[i][j]=1;
            else{
                dp[i][j]=(dp_sum[i-j-1][j]+(K-j)*dp[i][j+1]%MOD)%MOD;
            }
            if(j>0&&i>=j) dp_sum[i-j][j]=(dp_sum[i-j][j-1]+dp[i][j])%MOD;
        }
    }
    ll idx1,idx2;
    for(idx2=0;idx2<M;idx2++){
        if(chk[A[idx2]]!=1) chk[A[idx2]]=1;
        else break;
    }
    for(idx1=M-1;idx1>=0;idx1--){
        if(chk[A[idx1]]!=2) chk[A[idx1]]=2;
        else break;
    }
    for(ll i=0;i<=N-M;i++){
        ll pt;
        if(idx2!=M) ans+=dp[i+idx2][idx2]*dp[N-i-idx1-1][M-idx1-1]%MOD, ans%=MOD;
        else {
            ans+=fsum(i,0), ans%=MOD;
        }
    }
    printf("%lld\n",(((N-M+1)*power(K,N-M)-ans)%MOD+MOD)%MOD);
    return 0;
}


Measured memory_bytes: 176256
m=10**9+7
f=max
r=range
for _ in r(int(input())):
	x,y=sorted(map(int,input().split()))
	s=-1
	i=j=1
	while j<=x and i+j<=y:i,j,s=j,i+j,s+1
	if x==1 or y<3:print(1,x*y%m)
	else:
		a=f(0,(y-j)//i+1)+f(0,(x-j)//i+1)
		i=j=1
		for c in r(s):
			k,l=j,i+j*2
			for _ in r(s-c):k,l=l,k+l
			if x>=k:a+=f(0,(y-l)//k+1)
			if y>=k:a+=f(0,(x-l)//k+1)
			i,j=j,i+j
		print(s+1,a%m)

Measured memory_bytes: 81164
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define cot(x) cerr << #x << " " << x << " ";
#define cotd(x) cerr << #x << " " << x << endl;
#define her 	cerr << " here \n"; 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T > void check(T & a, const T & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }
LL mulmod(LL a, LL b, const LL & m) { LL q = (LL)(((LD)a*(LD)b) / (LD)m); LL r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, const T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }

const LL MOD = (int)1e9 + 7; 

int main(){
	SYNC; 
	int n, m; 
	cin >> n >> m; 
	vi x(n + 1), y(m + 1); 

	LL s1 = 0, s2 = 0; 

	REPN(i, n){
		cin >> x[i];
		s1 += ((i - 1) * 1LL * x[i] % MOD) - ((n - i) * 1LL * x[i] % MOD); 
		if(s1 < 0) s1 += MOD; 
		check(s1, MOD); 
	}
	REPN(i, m){
		cin >> y[i];
		s2 += ((i - 1) * 1LL * y[i] % MOD) - ((m - i) * 1LL * y[i] % MOD); 
		if(s2 < MOD) s2 += MOD;
		check(s2, MOD); 
	}
	cout << (s1 * s2 * 1LL) % MOD << endl; 
	return 0; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=1,d=1000000007;
  cin >> n;
  for(long long i=1;i<=n;i++){
    ans*=i;
    ans%=d;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=20;
#define ll long long
#define oo 1000000000000
ll n,a[N];
ll dp(int l,int r,int x,int y){
	if(r-l<=1)return 0;
	ll ans=oo;
	for(int m=l+1;m<=r-1;++m){
		ans=min(ans,dp(l,m,x,x+y)+dp(m,r,x+y,y)+(x+y)*a[m]);
	}
	return ans;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	cout<<a[1]+a[n]+dp(1,n,1,1);
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
ba = []
for i in range(N):
    a, b = map(int, input().split())
    ba.append([b, a])
ba.sort()

ans = "Yes"
c = 0
for i, v in enumerate(ba):
    b, a = v
    c += a
    if c > b:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 35608
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int a,b,c;cin >> a >> b >> c;
    string ans="NO";
    for(int i=1;i<b;i++){
        if(i*a%b==c){
            ans="YES";
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    if(A[N/2-1] == A[N/2]){
      System.out.println(0);
    } else {
      System.out.println(A[N/2] - A[N/2-1]);
    }
  }
}

Measured memory_bytes: 50032
import collections
N,M=map(int,input().split())
A=list(map(int,input().split()))
cuml=[0]*(N+1)
l=[]
su=0
for i in range(N):
    su=su+A[i]
    cuml[i+1]=su%M
#print(cuml)
c=collections.Counter(cuml)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
ans=0
#print(values)
for i in range(len(key)):
    ans=ans+(values[i]*(values[i]-1))//2
    #l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
print(ans)

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

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  while (n > 0) {
    int d = n % 10;
    if (d == 2) cnt++;
    n /= 10;
  }
  cout << cnt << endl;
  return 0;
}

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

const int N = 108;

namespace Flow {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = 40000, M = 200000;

	struct edge {
		int u, v, f;
		edge (int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2, flow;
	int first[N], next[M];
	int dep[N], cur[N], que[N];

	inline void addedge(int u, int v, int f) {
		e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h, t = 1, i, x, y;
		memset(dep, -1, sizeof dep);
		que[0] = si, dep[si] = 0;
		for (h = 0; h < t; h++) {
			if ((x = que[h]) == ti) return true;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] == -1 && e[i].f)
					que[t++] = y, dep[y] = dep[x] + 1;
		}
		return false;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c; e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	int Dinic() {
		for (flow = 0; bfs(); flow += dfs(si, INT_MAX))
			memcpy(cur, first, sizeof cur);
		return flow;
	}
}

int R, C, sr, sc, tr, tc;
int in[N][N], out[N][N];
char map[N][N];

int main() {
	int i, j, &n = Flow::V;
	scanf("%d%d", &R, &C);
	for (i = 0; i < R; ++i)
		for (scanf("%s", map[i]), j = 0; j < C; ++j)
			if (map[i][j] == 83) sr = i, sc = j;
			else if (map[i][j] == 84) tr = i, tc = j;
	if (sr == tr || sc == tc) return puts("-1"), 0;
	n = 2 + R + C;
	for (i = 0; i < R; ++i)
		for (j = 0; j < C; ++j)
			if (map[i][j] == 111)
				in[i][j] = ++n, out[i][j] = ++n,
				Flow::addedge(3 + i, in[i][j], INT_MAX),
				Flow::addedge(3 + R + j, in[i][j], INT_MAX),
				Flow::addedge(in[i][j], out[i][j], 1),
				Flow::addedge(out[i][j], 3 + i, INT_MAX),
				Flow::addedge(out[i][j], 3 + R + j, INT_MAX),
	Flow::addedge(1, 3 + sr, INT_MAX), Flow::addedge(1, 3 + R + sc, INT_MAX),
	Flow::addedge(3 + tr, 2, INT_MAX), Flow::addedge(3 + R + tc, 2, INT_MAX);
	printf("%d\n", Flow::Dinic());
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 
vector<vector<int>> v(1000, vector<int> (1000,0));

void conq(int l,int r,int c){
    if(r-l<2) return;
    int m = (r + l)/2;
    for (int i = l; i < m; i++) {
        for (int j = m; j < r; j++) {
            v[i][j] = c;
        }
    }
    conq(l,m,c+1);
    conq(m,r,c+1);
}


int main(){
    int n;cin >> n;
    conq(0,n,1);
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            cout << v[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


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

vector<int> e[101010];
bool used[101010];


void dfs(int x) {
  for (int t : e[x]) {
    if (!used[t]) {
      used[t] = true;
      dfs(t);
    }
  }
}
 
int main() {
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int x, y, z; cin >> x >> y >> z;
        --x;
        --y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (!used[i]) {
            used[i] = true;
            dfs(i);
            ++ans;
        }
    }

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

Measured memory_bytes: 8960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class64
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = new int[N];
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }
            int sum = A.Sum();
            Array.Sort(A);
            if(sum%10==0)
            for(int i = 0; i < N; i++)
            {
                    if (A[i] % 10 != 0)
                    {
                        sum -= A[i];
                        break;
                    }
            }
            Console.WriteLine(sum % 10 == 0 ? 0 : sum);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
int main()
{
    int a,b,c;
    int i=0;
    int tmp=0,tmc=0;
    scanf("%d%d%d",&a,&b,&c);
    int flag=0;
   while(a%2==0&&b%2==0&&c%2==0){

    tmp=a;
    tmc=b;
    a=b/2+c/2;
    b=tmp/2+c/2;
    c=tmp/2+tmc/2;
    i++;

    if(i>10000){
        flag=1;
        break;
    }
   }
   if(flag==1)
    printf("-1");
   else
    printf("%d",i);
    return 0;

}



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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N;
  cin >> N;
  vi h(N);
  REP(i, N) cin >> h[i];

  int ans = 0;

  REP(i, 101) {

    bool a = true;
    REP(j, N) {
      if (h[j] > 0 and a) {
        ans++;
        a = false;
      }
      if (h[j] <= 0)
        a = true;
    }

    REP(j, N) { h[j]--; }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    typedef long int l;
    l n,r; cin>>n>>r;
    if(n>10){
        cout<<r<<endl;
    }
    else{
        l a=(10-n);
        l b=100*a;
        cout<<r+b<<endl;
    }

}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int pre[40], in[40], post[40];
int pos = 0, n, p = 0;
void rec(int left,int right) {
  if (left < right) {
    int root = pre[pos++], i;
    for (i = 0; root != in[i]; ++i);
    rec(left, i);
    rec(i + 1, right);
    post[p++] = root;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> pre[i];
  for (int i = 0; i < n; ++i) cin >> in[i];
  rec(0,n);
  for (int i = 0; i < n; ++i) {
    if (i) cout << " ";
    cout << post[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3100
from collections import defaultdict
def Z(S):
    res = [0]*len(S)
    res[0] = len(S)
    i = 1
    j = 0
    while i < len(S):
        while i+j < len(S) and S[j] == S[i+j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < len(S) and k+res[k] < j:
            res[i+k] = res[k]
            k += 1
        i += k
        j -= k
    return res

class UnionFind:
    def __init__(self, num):
        self.table = [-1 for _ in range(num)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)

        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

s = input()
t = input()

S = s*(len(t)//len(s)+2)
z = Z(t+'*'+S)
z = z[len(t)+1:]

u = UnionFind(len(s))

loop = False
for i in range(len(s)):
    j = (i+len(t))%len(s)
    if z[i] == len(t) and z[j] == len(t):
        loop = (not u.union(i,j)) or loop


if loop:
    ans = -1
else:
    d = defaultdict(list)
    for i in range(len(s)):
        if z[i] == len(t):
            d[u.find(i)].append(i)
    ans = 0
    for k in d:
        ans = max(ans,len(d[k]))

print(ans)

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

using namespace std;
typedef long long ll;

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

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  ll l, r, d; cin >> l >> r >> d;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = r / d - (l - 1) / d;
  // bool ok = false;

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

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

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

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

#define MAX 101
int n,m;
string t[MAX];
int dp1[MAX][MAX];
int dp2[MAX][MAX];
int dp[MAX][MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  int ii,jj;
  R(i,n){
    cin >> t[i];
    R(j,m)if(t[i][j] == 'E'){
      ii = i;
      jj = j;
    }
  }
  if(ii > n - ii - 1){
    ii = n - ii - 1;
    R(i,n/2)swap(t[i],t[n-1 - i]);
  }
  if(jj > m - jj - 1){
    jj = m - jj - 1;
    R(i,n)reverse(ALL(t[i]));
  }
  R(i,n)R(j,m){
    dp1[i][j] = t[i][j] == 'o';
    if(i)dp1[i][j] += dp1[i-1][j];
    if(i > ii)dp1[i][j] -= t[i-ii-1][j] == 'o';
    
    dp2[i][j] = t[i][j] == 'o';
    if(j)dp2[i][j] += dp2[i][j-1];
    if(j > jj)dp2[i][j] -= t[i][j-jj-1] == 'o';
  }
  int out = 0;
  R(iii,ii+1)R(jjj,jj+1){
    int pi = ii + iii;
    int pj = jj + jjj;
    int res = 0;
    R(i,ii+1)R(j,jj+1){
      res += t[pi-i][pj-j] == 'o';
    }
    int ki = n - (ii - iii);
    int kj = m - (jj - jjj);
    for(int i = pi; i < ki; i++){
      for(int j = pj; j < kj; j++){
        dp[i][j] = 0;
        if(i != pi)
          maxi(dp[i][j], dp[i-1][j] + dp2[i][j]);
        if(j != pj)
          maxi(dp[i][j], dp[i][j-1] + dp1[i][j]);
      }
    }
    debug(pi,pj,res,dp[ki-1][kj-1]);
    maxi(out,res + dp[ki-1][kj-1]);
  }
  cout << out << "\n";
}


Measured memory_bytes: 640
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp                       __builtin_popcount

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int n,k,ans=1,x,y;
    cin>>n>>k;
    int a[n+2];
    a[0]=0;
    f(i,1,n+1)
        a[i]=a[i-1]+i;
    f(i,k,n)
    {
        x=a[i-1];
        y=a[n]-a[n-i];
        //cout<<x<<"   "<<y<<endl;
        ans=(ans + (y-x+1)%mod )%mod;
    }
    cout<<ans;
}

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

int main(void){
  int n, a, ma = -1, mi = 100000;
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a;
    if(mi > a) mi = a;
    if(ma < a) ma = a;
  }
  cout << ma - mi << endl;
}

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

using namespace std;

void chmax(int &a, int b)
{
  a = max(a, b);
}

int N, M, V[3000], H[3000], T[1000], S[1000];

void solve()
{
  cin >> N >> M;
  for(int i = 0; i < N; i++) {
    cin >> V[i] >> H[i];
    if(i) V[i] += V[i - 1];
  }

  for(int i = 0; i < M; i++) {
    cin >> T[i] >> S[i];
  }

  vector< int > cur(N + 1, -1);
  cur[0] = 0;

  for(int i = 0; i < M; i++) {
    vector< int > nxt(N + 1, -1), buf(N + 1, -1);
    for(int j = 0; j <= N; j++) {
      if(j < N && V[j] <= T[i] && ~cur[j]) chmax(buf[j + 1], cur[j] + H[j]);
      if(j < N && V[j] <= T[i] && ~buf[j]) chmax(buf[j + 1], buf[j] + H[j] + abs(H[j] - H[j - 1]));
      chmax(nxt[j], max(cur[j], buf[j]));
    }
    for(int j = 0; j <= N; j++) if(nxt[j] < S[i]) nxt[j] = -1;
    cur.swap(nxt);
  }

  int ret = -1;
  for(int j = 1; j <= N; j++) {
    if(cur[j] >= 0) ret = max(ret, T[M - 1] - V[j - 1]);
  }
  cout << ret << endl;
}

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

Measured memory_bytes: 3256
#include<iostream>
#include<string>
#include<set>
using namespace std;

int main() {
	int n; cin >> n;
	set<string>st;
	char prev;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		st.insert(s);
		if (i > 0) {
			if (s[0] != prev) {
				cout << "No" << endl;
				return 0;
			}
		}
		prev = s[s.size() - 1];
	}
	if (st.size() != n) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

ls = inputs[1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end


ans = ls.inject(:+) - ls.size

puts ans


Measured memory_bytes: 1916
N = int(input())
Alist = list(map(int, input().split()))
Sum = 0
for n in range(1, N):
  if Alist[n] < Alist[n-1]:
    Sum += Alist[n-1] - Alist[n]
    Alist[n] = Alist[n-1]
print(Sum)

Measured memory_bytes: 32068
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


const int MOD = 998244353;
int main() {
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    vector<vector<long long>> dp(N+1, vector<long long>(S+1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= S; ++j) {
            dp[i+1][j] += dp[i][j] * 2 % MOD;
            if (j-A[i] >= 0) dp[i+1][j] += dp[i][j-A[i]];
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[N][S] << endl;
}


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

int main(){
  while(true){
    string num;
    int sum = 0;
    cin >> num;
    if(num == "0"){
      break;
    }
    for(int i = 0; i < num.size(); i++){
      sum += num.at(i) - '0';
    }

    cout << sum << endl;
  }
}


Measured memory_bytes: 3208
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
        }

        int[] buy = new int[K];
        for (int i = 0; i < K; i++) {
            int minId = 0;
            for (int j = 0; j < N; j++){
                if (p[minId] > p[j]) {
                    minId = j;
                }
            }
            buy[i] = p[minId];
            p[minId] = 1001;
        }

        int sum = 0;
        for (int i : buy) {
            sum += i;
        }
        System.out.println(sum);

    }
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		int n = (int) nextLong();
		return n;
	}
}


Measured memory_bytes: 33380
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int res = 0;
		for (int a = 0; a <= 9; ++a)
			for (int b = 0; b <= 9; ++b)
				for (int c = 0; c <= 9; ++c)
					for (int d = 0; d <= 9; ++d)
						if (a+b+c+d == n)
							++res;
		printf("%d\n", res);
	}

	return 0;
}

Measured memory_bytes: 0
# データ読み込み

import sys
from collections import deque

def input_data(d=""):
  t = sys.stdin.read()
  if t:
    return t
  else:
    if d[0] == "\n":
      d = d[1:]
    if d[-1] == "\n":
      d = d[:-1]    
    return d

A, *B  = map(int,input_data().split())

def aaa(k):
  k = int(k)
  if A == k:
    if A % 2 == 1:
      return 0
    k = int(k // 2)
  if k == 0:
    return 0
  return int(k//5) + aaa(k//5)

def bbb(k):
  k = int(k)
  if A == k:
    if A % 2 == 1:
      return int(0)
    k = int(k / 2)
  if k == 0:
    return 0
  return int(k/2) + bbb(k/2)

print(min([aaa(A)]))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	COMinit();

	int N, K;
	cin >> N >> K;
	ll A[N];
	for(int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);

	ll ans = 0;
	for(int i = 0; i <= N - K; i++) {
		ans -= (A[i] * COM(N - 1 - i, K - 1)) % mod;
		if(ans < 0) ans += mod;
		ans %= mod;
	}

	sort(A, A + N, greater<int>());
	for(int i = 0; i <= N - K; i++) {
		ans += (A[i] * COM(N - 1 - i, K - 1)) % mod;
		if(ans < 0) ans += mod;
		ans %= mod;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 16364
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

long long gcd(long long a, long long b) {
	long long old_a, old_b;
	while (b != 0) {
		old_a = a;
		a = b;
		old_b = b;
		b = old_a % b;
	}
	return old_b;
}

int main() {
	int n; cin >> n;
	long long a[100010], k;
	cin >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 1) {
		if (a[0] == k) {
			cout << "POSSIBLE" << endl;
		}
		else {
			cout << "IMPOSSIBLE" << endl;
		}
      return 0;
	}
	sort(a, a + n);
	int g = gcd(a[0], a[1]);
	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}
	if (k <= a[n - 1] && k%g == 0) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
def resolve():
    S = list(input())
    rem = [0 for _ in range(2019)]
    v = 0
    rem[0] += 1
    p = 1
    for i in range(len(S)-1, -1, -1):
        v = p*int(S[i]) + v
        v %= 2019
        rem[v] += 1
        p = (p*10)%2019

    ans = 0
    for r in rem:
        ans += r*(r-1)//2
    print(ans)
        



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 82400
#include <iostream>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1 && B != 1){
    cout << "Alice";
  } else if (B == 1 && A != 1){
    cout << "Bob";
  } else if (A > B){
    cout << "Alice";
  } else if (A < B){
    cout << "Bob";
  } else {
    cout << "Draw";
  }
  cout << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
mod = 998244353

if d[0] != 0 or min(d[1:]) == 0:
    print(0)
else:
    c = Counter(d)
    ans = 1
    for i in range(1, max(d)+1):
        ans *= c[i-1] ** c[i]
        ans = ans % mod
    print(ans)

Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x;
	cin>>n>>x;
	vl l(n+1,0);
	rep(i,n)cin>>l[i+1];
	partial_sum(all(l),l.begin());
	int ans=0;
	rep(i,n+1)if(l[i]<=x)ans++;
	puta(ans);
	return 0;
}

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

int main(){
  int N;
  cin >> N;;
  //vector<int> S(N);
  int AC =0;
  int WA =0;
  int TLE =0;
  int RE=0;
  rep(i, N){
    string tmp;
    cin >> tmp;
    if(tmp=="AC") AC++;
    if (tmp =="WA") WA++;
    if (tmp == "TLE") TLE++;
    if (tmp == "RE") RE++;
  }

  cout << "AC x "<<AC<<endl;
  cout << "WA x "<<WA<<endl;
  cout << "TLE x "<<TLE<<endl;
  cout << "RE x "<<RE<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s;
    return 0;
}

Measured memory_bytes: 256