akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

    ll n, sum = 0, cnt = 1;
    cin >> n;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a, a + n);
	sum += a[n - 1];
	for(int i=n-2;i>=0;i--)
	{
		if(cnt == n - 1) break;
		sum += a[i];
		cnt += 1;
		if(cnt == n - 1) break;
		sum += a[i];
		cnt += 1;
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5216
N, M = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(N)]
point = [tuple(map(int, input().split())) for _ in range(M)]

for n in range(N):
    mindis = 10 ** 9
    for m in range(M):
        dis = abs(student[n][0] - point[m][0]) + abs(student[n][1] - point[m][1])
        if mindis > dis:
            mindis = dis
            ans = m + 1
    print(ans)


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

/*==========type============*/
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::pair<std::string,ll> psl;

/*==========constant============*/
#define INF INT_MAX
#define INF_L LONG_MAX
#define INF_LL LLONG_MAX
#define MOD 1000000007

/*==========function============*/
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

using namespace std;

struct P{
    ll y,x;
    P(){};
    P(ll y,ll x):y(y),x(x){};
    bool operator ==(P p){
        return (y == p.y) && (x == p.x);
    }
    friend ostream& operator<<(ostream& os, P p){
        os << "y:" << p.y << " x:" << p.x;
    }
};

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

    ll n,m;
    cin >> n >> m;
    vector<ll> g[n];
    REP(i,0,m){
        ll a,b;
        cin >> a >> b;
        a--,b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }


    queue<pair<ll,ll>> que;	
    que.push(make_pair(0,0));
    vector<ll> ans(n,-1);
    while (que.size()){

        ll index = que.front().first;
        ll cost = que.front().second;	
        que.pop();
        if(ans[index] != -1)continue;
        ans[index] = cost+1;
        // cout << index << " " << cost << endl;
        REP(i,0,g[index].size()){
            que.push(make_pair(g[index][i],index));
        }
    }

    REP(i,1,n){
        if(ans[i] == -1){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    REP(i,1,n)cout << ans[i] << endl;

    return 0;
}    

Measured memory_bytes: 17124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	private static void solve(FastScanner fr) {
		int n = fr.nextInt();
		int[][] h = new int[n][3];
		for(int i = 0; i < n; i++) {
			h[i] = fr.readArray(3);
		}
		int[][] dp = new int[n][3];
		dp[0] = h[0];
		int max = Math.max(h[0][0], Math.max(h[0][1], h[0][2]));
		for(int i = 1; i < n; i++) {			
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(j == k) continue;
					dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + h[i][j]);
				}
				max = Math.max(max, dp[i][j]);
			}
		}

		sout(max);
	}
    public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = 1;
		// int n = fs.nextInt();
		while (n-- > 0)	{
			solve(fs);
        }
    }

    private static void sout()          { System.out.println();  }
    private static void sout(String s)  { System.out.println(s); }
    private static void sout(int s)     { System.out.println(s); }
    private static void sout(long s)    { System.out.println(s); }
    private static void sout(double s)  { System.out.println(s); }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }
			return st.nextToken();
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


Measured memory_bytes: 52932
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
int di[4]={-1,0,1,0};
int dj[4]={0,-1,0,1};
int main()
{
int h,w;
cin>>h>>w;
int si,sj;
cin>>si>>sj;
int ti,tj;
cin>>ti>>tj;
si--;sj--;ti--;tj--;
vector<string>s(h);
rep(i,h)cin>>s[i];
int INF =1e9;
vector<vector<int>>dist(h,vector<int>(w,INF));

deque<P>q;
dist[si][sj]=0;
q.emplace_back(si,sj);
while(!q.empty())
{
int i=q.front().first;
int j=q.front().second;
int d=dist[i][j];
q.pop_front();
rep(v,4)
{
int ni=i+di[v];
int nj=j+dj[v];
if(ni<0||ni>=h||nj<0||nj>=w)continue;
if(s[ni][nj]=='#')continue;
if(dist[ni][nj]<=d)continue;
dist[ni][nj]=d;
q.emplace_front(ni,nj);
}

for(int ei=-2;ei<=2;ei++)
{
    for(int ej=-2;ej<=2;ej++)
    {
    int ni=i+ei,nj=j+ej;
    if(ni<0||ni>=h||nj<0||nj>=w)continue;
    if(s[ni][nj]=='#')continue;
    if(dist[ni][nj]<=d+1)continue;
    dist[ni][nj]=d+1;
    q.emplace_back(ni,nj);

    }

}


}

int ans=dist[ti][tj];
if(ans==INF)cout <<-1;
else cout <<ans;
}

Measured memory_bytes: 9540
n = int(input())
h_list = [int(_) for _ in input().split()]
ans = 0
while sum(h_list) != 0:
    # 0で区切られた、1以上の数のかたまりを数える
    # 要素が全て1以上ならansに+1して次のループ
    if h_list.count(0) == 0:
        ans += 1
    else:
        for i in range(1, n):
            # 1以上から0に下がった時にかたまりをカウント
            if h_list[i] == 0 and h_list[i - 1] != 0:
                ans += 1
            elif i == n - 1 and h_list[i] != 0:
                ans += 1
    # 1以上の箇所を1段ずつ落とす
    for i in range(n):
        if h_list[i] != 0:
            h_list[i] -= 1

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int is_Prime(int m);

int main() {
	int a[10000], n, i;
	int count = 0;

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

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

	return 0;
}

int is_Prime(int m) {
	int i;
	for (i = 2; i <= sqrt(m)+1; i++) {
		if (m >= 3 && m % i == 0) {
			return 0;
		}
	}
	return 1;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int partition(int *a,int p,int r){
	int x=a[r];
	int i=p-1;
	for(int j=p;j<r;j++){
		if(a[j]<=x){
			i++;
			swap(a[i],a[j]);
		}
	}
	swap(a[i+1],a[r]);
	return i+1;
}
signed main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int k=partition(a,0,n-1);
	for(int i=0;i<n;i++){
		if(i) cout<<" ";
		if(i==k) cout<<"[";
		cout<<a[i];
		if(i==k) cout<<"]";
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3852
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int l = Integer.parseInt(sc.next());
		int r = Integer.parseInt(sc.next());
		sc.close();
		r -= l;
		l %= 2019;
		r += l;
		int yono = 2019;
		if(r - l > 2019){
			yono = 0;
		}else{
			for(int i = l ; i <= r ; i++){
				for(int j = l ; j < i ; j++){
					yono = Math.min(yono , (i * j) % 2019);
				}
			}
		}
		ou.print(yono + "\n");
		ou.flush();
    }
}

Measured memory_bytes: 38536
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<array>
#include<cmath>

using namespace std;

int main(){

    long long int n, k;
    cin>>n>>k;
    n = n % k;
    if(abs(n - k) >= n){
        cout<<n<<endl;
    }
    else{
        cout<<abs(n - k)<<endl;
    }
}

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

p = []

if X == 1:
  p.append(300000)
elif X == 2:
  p.append(200000)
elif X == 3:
  p.append(100000)

if Y == 1:
  p.append(300000)
elif Y == 2:
  p.append(200000)
elif Y == 3:
  p.append(100000)


if X == 1 and Y == 1:
  p.append(400000)

ans = sum(p)
print(ans)

Measured memory_bytes: 3064
def isPrime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


x = int(input())

for i in range(x, 10 ** 6):
    if isPrime(i):
        print(i)
        exit()

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <bitset>
#include <set>

using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define repe_r(i,s,n)for(int i = n;i>=s;i--)

ll a[100001] = {};
ll gcd(ll a, ll b) {
	if (a == 0)return b;
	return gcd(b % a, a);
}
int main() {
	ll n; cin >> n;
	rep(i, 0, n) cin >> a[i];

	rep(i, 1, n) {
		ll v = gcd(a[i], a[i - 1]);
		a[i] = v;
	}

	cout << a[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long a[205];
char s[205];
long long dp[65];
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        memset(dp, -1, sizeof(dp));
        int n;
        scanf("%d", &n);
        for(int i=1;i<=n;i++) scanf("%lld", &a[i]);
        scanf("%s", s+1);
        bool ans = 0;
        for(int i=n;i>=1;i--){
            if(s[i] == '0'){
                for(int j=60;j>=0;j--){
                    if((a[i]>>j)&1){
                        if(dp[j] == -1){
                            dp[j] = a[i];
                            break;
                        }
                        else a[i] ^= dp[j];
                    }
                }
            }
            else{
                long long sum = 0;
                for(int j=60;j>=0;j--){
                    if(((a[i]>>j)&1) != ((sum>>j)&1)){
                        if(dp[j] == -1) break;
                        sum ^= dp[j];
                    }
                }
                if(sum != a[i]){
                    ans = 1;
                    break;
                }
            }

        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    ll a,b;
    cin >> a >> b;
    if(a==1&&b==1){
        cout << 1 << endl;
    }else if(a<3&&b<3){
        cout << 0 << endl;
    }else if(a==1||b==1){
        cout << a*b-2 << endl;
    }else{
        cout << (a-2)*(b-2) << endl;
    }
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim//
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d,c=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0) c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>

using namespace std;

int m;
int f(int n) { return n*(n+1)*(n+2)/6; }
vector<int> l1, l2;

void r(int n, int step, vector<int> &l, int p) {
  if(step+1 >= m) return;
 
  for(int i=p; i>=0; i--) {
    int n2 = n-l[i];
    if(n2<0) continue;
    if(n2==0) {
      m = step+1;
      return;
    }
    if(n2>0) {
      r(n2, step+1, l, i);
    }
  }
  
}

int main() {
  while(1) {
    vector<int> l1, l2;
    int n;

     cin >> n;
     if(n==0) break;
    
    // not over
    for(int i=1; true; i++) {
      int mm = f(i);
      if(mm>n) break;
      l1.push_back(mm);
      if(mm&1) l2.push_back(mm);
    }

    m = n;
    r(n, 0, l1, l1.size()-1);
    cout << m;

    cout << ' ';
    
    m = n;
    r(n, 0, l2, l2.size()-1);
    cout << m;

    cout << "\n";

    
  }
  return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
typedef long long int intl;
typedef unsigned long long intu;

#define int           long long // change here
#define sfi(x)        scanf("%lld", &x) // change here

#define sfi2(x, y)    sfi(x) , sfi(y)
#define sfi3(x, y, z) sfi(x) , sfi(y) , sfi(z)
#define sfc(x)        scanf(" %c", &x)
#define sfs(x)        scanf(" %s", x)
#define sfsn(x)       scanf(" %[^\n]s", x)

#define pfi(x)        printf("%lld", (intl)x)
#define pfis(x)       printf("%lld", (intl)x), printf(" ")
#define pfin(x)       printf("%lld", (intl)x), printf("\n")
#define pfs(x)        printf("%s", x)
#define pfnl          printf("\n")
#define pfsp          printf(" ")
#define endl          '\n'
#define sp            ' '

#define watch(x)      cout<<"::debug::   "<< #x <<" : "<<x<<endl
#define watchi(i, x)  cout<<"::debug::   "<< #x <<"-> ["<<i<<"]"<<" : "<<x<<endl

#define FOR(i, begin, end)  for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define repit(it, x)        for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define perit(it, x)        for(__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); ++it)
#define rep(i, begin, end)  for(int i = (begin), ed = (end); i < (ed); ++i)
#define per(i, end, begin)  for(int i = (end)-1, bg = (begin); i >= (bg); --i)

#define setvalue(a, v)  for(int i = 0, sz = (sizeof(a)/sizeof(*a)); i<sz; i++){ a[i] = v; }
#define ZERO(a)       memset(a, 0, sizeof(a))
#define MINUS(a)      memset(a, 0xff, sizeof(a))

#define all(a)        a.begin(), a.end()
#define min3(x, y, z) min(x,min(y,z))
#define max3(x, y, z) max(x,max(y,z))
#define PI            2*acos(0)
#define INF           1000000007
#define debug         if( 1 )

const int mxn = 100010;



void solve(int tc)
{
    int n;
    cin >> n;

    int arr[2*n];
    for(int i=0; i<2*n; i++) cin >> arr[i];

    sort(arr, arr+2*n);

    int tot = 0;
    for(int i=0; i<2*n; i+=2) tot += arr[i];

    cout << tot << endl;
}

int32_t main()
{
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    solve(1);
    //int tc; cin>>tc; for(int t=1; t<=tc; t++) solve(t);

    return 0;
}



Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s;
int n;
long long int ans;

long long int string_to_num(string t)
{
    long long int n = 0;


    for (int j = 0; j < t.length(); j++)
    {
        n = (10 * n) + (t[j] - '0');
    }

    return n;
}


void solve(vector <int> v, int i)
{
    if (i == n)
    {
        v.push_back(n);

        for (int j = 1; j < v.size(); j++)
        {
            string u = "";
            for (int k = v[j-1]; k < v[j]; k++)
            {
                u += s[k];
            }
            ans += string_to_num(u);
        }

        return;
    }

    solve(v, i+1);
    v.push_back(i);
    solve(v, i+1);
}

int main()
{
    cin >> s;

    n = s.length();

    vector <int> v;
    v.push_back(0);
    solve(v, 1);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int min(int x, int y) {
    if (x>=y) return y;
    else return x;
}

int abs0(int x) {
    if (x>=0) return x;
    else return -x;
}

int main(void){
    int N, K, a[100005], i, x, m;
    scanf("%d%d", &N, &K);
    for (i=1; i<=N; i++) scanf("%d", &a[i]);
    for (i=1; i<=N-K+1; i++) {
        if (a[i]>=0) x=a[i+K-1];
        else if (a[i+K-1]<=0) x=-a[i];
        else x=abs0(a[i])+abs0(a[i+K-1])+min(abs0(a[i]), abs0(a[i+K-1]));
        if (x<m || i==1) m=x;
    }
    printf("%d", m);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main(){
	int n;cin>>n;
	dl a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	dl re=0;
	for(int i=1;i<=n;i++){
		re+=1.0/a[i];
	}
	cout<<setprecision(10);
	cout<<1.0/re<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main() {
 long long A, B;
 cin >> A >> B;
 if(A % 2 != B % 2) {
 cout << "IMPOSSIBLE" << endl;
 } else {
 cout << (A + B) / 2 << endl;
 }
 return 0;
 }


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n;
    cin>>n;
    map<string,int> mp[6];
    rep(i,0,n){
        string s;
        int n;
        cin>>s>>n;
        mp[s.size()-1][s]+=n;
    }
    
    rep(i,0,6){
        for(auto x:mp[i]){
            cout<<x.fi<<" "<<x.se<<endl;
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define xx first
#define yy second
#define mx 100001
string s[51];
int h,w;
bool ins(int i,int j)
{
	if(i<0 || i>=h)
		return 0;
	if(j<0 || j>=w)
		return 0;
	return 1;
}
int check(int r,int c)
{
	int ans=0;
	int x[3]={0,-1,1};
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			if(ins(x[i]+r,x[j]+c) && s[x[i]+r][x[j]+c]=='#')
				ans++;
	return ans;
}
int main()
{
	sd2(h,w);
	for(int i=0;i<h;i++)
		cin>>s[i];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='.')
				pd(check(i,j));
			else
				printf("#");
		}
		nl;
	}
}

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

int main() {
	string s1, s2;
st:;
	cin >> s1;
	while (s1 != ".") {
		cin >> s2;

		bool f = false; // trueなら""中
		int i1, i2;
		i1 = i2 = 0; // 次に見る文字
		int n1 = s1.length();
		int n2 = s2.length();
		int count_diff = 0;
		
		while (true) {
			if (!f) {
				if (s1[i1] != s2[i2]) {
					cout << "DIFFERENT" << endl; // ""外で対応する文字が違えばDIFFERENT
					goto st;
				}
				if (s1[i1] == '"')
					f = true;
				i1++; i2++;
			}
			else {
				string str1 = "";
				string str2 = "";
				while (s1[i1] != '"') {
					str1 += s1[i1];
					i1++;
				}
				i1++;
				while (s2[i2] != '"') {
					str2 += s2[i2];
					i2++;
				}
				i2++;
				if (str1 != str2) {
					count_diff++;
				}
				f = false;
			}
			if (i1 == n1 && i2 == n2)
				break;
			if (i1 == n1 && i2 != n2) {
				cout << "DIFFERENT" << endl;
				goto st;
			}
			if (i1 != n1 && i2 == n2) {
				cout << "DIFFERENT" << endl;
				goto st;
			}
		}

		if (count_diff == 0)
			cout << "IDENTICAL" << endl;
		if (count_diff == 1)
			cout << "CLOSE" << endl;
		if (count_diff > 1)
			cout << "DIFFERENT" << endl;

		cin >> s1;
	}
	return 0;
}


Measured memory_bytes: 3160
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            cnt += d[i] * d[j];
        }
    }
    OUT(cnt);
}

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

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll a;
  cin >> a;
  int b1, b23;
  scanf("%d.%d", &b1, &b23);
  ll b = b1*100+b23;
  ll ans = a*b/100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3680
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

int32_t main()
{
    IOS
    
    
    int n;
    cin>>n;
    int x=0;
    for(int i=0;i<n;++i)
        {
            int p;
            cin>>p;
            x=x^p;
        }
        if(x)
        {
            cout<<"No";
        }
        else
        {
            cout<<"Yes";
        }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll ans = 0;

    for(ll i=0; i<=3000; i++){
        // 既にnを超えていたらループを抜ける
        ll rb = r*i;
        if(rb > n) break;
        for(ll j=0; j<=3000; j++){
            // 既にnを超えていたらループを抜ける
            ll gb = g*j;
            if(rb+gb > n) break;

            // 青色の箱を整数個買って条件を達成できるか確認
            if((n-(rb+gb))%b == 0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3548
# include "iostream"
# include "cstdio"
# include "cstring"

using namespace std;

const int maxm=1e5+10;

int Len;
char S[maxm],N[maxm];

int main(){
	register int i,Top=0,Ans=0;
	scanf("%s",S+1);
	Len=strlen(S+1);
	for(i=1;i<=Len;i++){
		if(S[i]!=N[Top] && Top!=0){
			Top--;
			Ans+=2;
			continue;
		}
		N[++Top]=S[i];
	}
	printf("%d",Ans);
	return 0;
}

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

int main(){
	int n;cin>>n;
	int a[3];
	rep(i,n)cin>>a[i];
	int min=*min_element(a,a+n);
	for(int i=1;i<=min;i++){
		bool flag=true;
		rep(j,n){
			if(a[j]%i)flag=false;
		}
		if(flag)cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define per(i,a,b) for(int i = (a);i >= (b);i--)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n;
void solve(){
	for(int i = 1;i <= 10;i++){
		if(i * 1000 >= n){
			cout << i * 1000 - n << endl;
			return;
		}
	}
	return;
}
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	solve();
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define LL long int

const LL N = 1000000009;

LL average(LL n,LL m){
    return int((((double)n / m) * 10.0 + 0.5) / 10);
}

int main(){
    LL n;
    cin >> n;
    vector<LL> x(n);
    for(int i = 0; i < n; ++i){
        cin >> x[i];
    }

    LL ans = N;

    for(int i = 1; i <= 100; ++i){
        LL count = 0;
        for(int j = 0; j < n; ++j){
            count += pow(x[j] - i,2);
        }
        ans = min(ans,count);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int num[100001];
long long mod = 1e9+7;
int main(void){
	int N;
	long long ans = 1;
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++)cin >> A[i];
	for(int i=0;i<N;i++){
		num[A[i]]++;
	}
	//Nが偶数だったら1 3 5 ... N-1までの個数が2個だったらok
	//Nが奇数だったら0が1個 2 4 6 ... N-1の個数が2個だったらok
	if(N%2==0){
		for(int i=1;i<=N-1;i+=2){
			if(num[i]!=2){
				cout << "0";
				return 0;
			}
		}
		for(int i=0;i<(N/2);i++){
			ans *= 2;
			ans %= mod;
		}
	}else{
		if( num[0]!=1){
			cout << "0";
			return 0;
		}
		for(int i=2;i<=N-1;i+=2){
			if(num[i]!=2){
				cout << "0";
				return 0;
			}
		}
		for(int i=0;i<(N/2);i++){
			ans *= 2;
			ans %= mod;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  int h,n;cin>>h>>n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i] >>b[i];
  ll ans[10005];
  rep(i,10005)ans[i] = INFTY;
  ans[0] = 0;
  rep(i,h){
    rep(j,n){
      if(i+a[j]>=h)ans[h] = min(ans[h],ans[i]+b[j]);
      else ans[i+a[j]] = min(ans[i+a[j]],ans[i]+b[j]);
    }
  }

cout<<ans[h]<<endl;

  return 0;
}

Measured memory_bytes: 384
from itertools import accumulate

mod = 10 ** 9 + 7

N = int(input())
S = input()

dp = [1] * N
for s in S:
    if s == "<":
        dp = [a % mod for a in accumulate(dp[:-1])]
    else:
        dp = [a % mod for a in accumulate(reversed(dp[1:]))]
        dp.reverse()

print(dp[0])

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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int m = int.Parse(str[1])
                ;

            if (n > m) Console.WriteLine("safe");
            else Console.WriteLine("unsafe");


            //ここまで
        }



        static long Max(long a, long b)
        {
            if (a > b) return a;
            else return b;
        }
    }

}


Measured memory_bytes: 27552
// #define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(x) { cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
# define _debug(...) {((void) 0);}
#endif
#define REP(i, n) for (int i = (0); i < (n); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define EACH(x, arr) for (auto& x : arr) 
#define ITR(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 5005;

int n, m;
void MAIN() {
    cin >> n >> m;
    VI c(m);
    int k, x;
    REP(i, n) { cin >> k; REP(j, k) { cin >> x; x--; c[x]++; }}
    int ret = 0;
    REP(i, m) if (c[i] == n) ret++;
    cout << ret << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int TC = 1;
    // cin >> TC;
    REP(tc, TC) {
        // cout << "Case " << tc + 1 << ": ";
        MAIN();
    }
    return 0;
}


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

int main(){
  long long a, b, tmp, ans;
  cin >> a >> b;
  
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  if(b == 1) ans = a;
  if(!(a % b)){
      cout << a << endl;
      return 0;
  }
  
  for(int i = 2; i <= b; i++){
    if(!((a*i)%b)){
      ans = a*i;
      break;
    }   
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,k;cin>>n>>k;
	ll count=(n/k)*(n/k)*(n/k);
	if(k%2==0){
		ll c = 0;
		For(i,1,n+1) if(i%k==k/2) c++;
		count+=(c*c*c);
	}
	cout<<(count)<<endl;










	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
int main() {
    string t;
    cin>>s>>t;
    ll start=-1;
    ll size=s.size();
    ll tsize=t.size();
    REP(i,size){
        bool ok=true;
        REP(j,tsize){
            if(i+j>=size||(s[i+j]!='?'&&s[i+j]!=t[j])){
                ok=false;
                break;
            }
        }
        if(ok)start=i;
    }
    if(start<0)cout<<"UNRESTORABLE"<<endl;
    else{
        /*REP(i,size){
            if(s[i]!='?')cout<<s[i];
            else if(i<start||i>start+tsize)cout<<'a';
            else cout<<t[i-start];
        }
        cout<<endl;*/
        REP(i,tsize)s[i+start]=t[i];
        REP(i,size){
            if(s[i]=='?')s[i]='a';
        }
        cout<<s<<endl;
    }
    return 0;
}

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

int main(){
    uint64_t x;
    cin >> x;

    uint64_t tmp = x / 500;
    uint64_t ans = tmp * 1000 + (x - tmp * 500) / 5 * 5;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
mint comb(int n, int r) {
  if (n - r < r) r = n - r;
  if (r == 0) return 1;
  if (r == 1) return n;
 
  vector<mint> numerator(r, 0), denominator(r, 0);
  for (int k = 0; k < r; k++) {
    numerator[k] = n - r + k + 1;
    denominator[k] = k + 1;
  }
 
  for (int p = 2; p < r + 1; p++) {
    mint pivot = denominator[p - 1];
    if (pivot.x > 1) {
      int offset = (n - r) % p;
      for (int k = p - 1; k < r; k += p) {
        numerator[k - offset] /= pivot;
        denominator[k] /= pivot;
      }
    }
  }
 
  mint res = 1;
  for (int k = 0; k < r; k++) {
    if (numerator[k].x > 1) {
      res *= numerator[k];
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  mint ans = 0;
  for(int i = 1;i<=n;i++){
    int x = n-3*i;
    if(x<0)break;
    ans+=comb(x+i-1,x);
  }
  cout<<ans.x<<endl;
  return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			while(true){
				int H = sc.nextInt();
				int W = sc.nextInt();

				if(H ==0 && W == 0)break;

				for(int i = 0;i < H;i++) {
					for(int j = 0;j < W;j++) {
						if(i == 0 || i == H-1) {
						System.out.print("#");
						}else {
							if(j == 0 || j == W -1) {
								System.out.print("#");
							}else {
								System.out.print(".");
							}
						}
					}
					System.out.println("");
				}
				System.out.println("");
			}
		}
	}
}



Measured memory_bytes: 32644
N,T=map(int,input().split())
a,b,s,name1=input().split()
def func(s):
    a=s[:2]
    b=s[3:]
    return int(a)*60+int(b)
s=func(s)
l=[]
for i in range(N-1):
    t,name1,s2,name2=input().split()
    t=func(t)
    s2=func(s2)
    if t-s>=T:
        l.append([name1,t-s])
    s=s2
print(len(l))
for i,j in l:
    print(i,j)



Measured memory_bytes: 5600
#include <stdio.h>

int main(void){
    int H,W,i,j,k,l;
    while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0) break;
    for(i=0;i<W;i++){
        printf("#");
    }
    printf("\n");
    for(j=0;j < H-2;j++){
        printf("#");
        for(k=0;k < W-2;k++){
            printf(".");
        }
        printf("#");
        printf("\n");
    }
    for(l=0;l<W;l++){
        printf("#");
    }
    printf("\n\n");
    }
    
     return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - たてなが / Thin
            var line = ReadLine();
            int h = line[0];
            int w = line[1];
            
            for(int i = 0; i < h; i++)
            {
                var s = Console.ReadLine();

                Console.WriteLine(s + Environment.NewLine + s);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  
  if (a+b>=10) {
    console.log("error");
  }else{
    console.log(a+b);
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
package main

import (
	"fmt"
)

func main() {

	var A, B int
	fmt.Scanf("%d %d", &A, &B)

	if A >= 13 {
		fmt.Println(B)
	} else if 6 <= A && A <= 12 {
		fmt.Println(B / 2)
	} else {
		fmt.Println("0")
	}
}


Measured memory_bytes: 1836
def insertionSort(A,n,g):#cを引数に入れる方針では更新が怒らないらしい
    global c #ここにglobal cを置くことでmainからcの値を変更可能になる.c=0と書くと(ローカル宣言したのでこの瞬間からcがlocalになり、mainのcと別物になる)
    #print(tp[2])の結果はmainのc=0のグローバル宣言の影響を受け0のままになる
    for i in range(g,n):
        v=A[i]
        j = i - g
        while j >= 0 and A[j] >v:
            A[j+g] = A[j]
            j = j- g
            c+=1
            #print(c)
        A[j+g] = v
def shellSort(A,n): #ローカルスコープ
    i = 0
    G=[1]
    while 3*G[i]+1 < n :
        G.append(3*G[i]+1)
        #print("\n")
        i+=1
    G.reverse()
    m=len(G)
    for i in range(m):#シェルソーとは3G[i]+1の感覚がだんだん狭まっていくように
       insertionSort(A,n,G[i])
    return m,G,c,A#ここにc書いてもエラー出されないのはglobalのおかげなんだろうか←main関数内のc=0の定義のおかげ
#この関数内でcに代入がされた時点でcはローカル変数になっていたが、ここでは何も代入してないのでmainのglobal宣言が生きる
"""
def test():
    return 'abc', 100
"""
#Pythonにおいて、構文上必要な場合を除き、カンマで区切られた値は
# 丸括弧を省略したタプルとみなされる。このため、上の例の関数はそれぞれの値を要素とするタプルを返すことになる。

if __name__=="__main__":#グローバルスコープ
    c = 0#ここで各関数実行前にcをかけばglobal変数になる
    n = int(input())
    l = [int(input().rstrip()) for _ in range(n)]
    tp = shellSort(l,n)
    print(tp[0])
    #print(tp[1])
    a = [str(tp[1][i]) for i in range(len(tp[1]))]
    #print(a)
    print(' '.join(a))
    print(tp[2])
    for i in range(len(tp[3])):
        print(tp[3][i])


Measured memory_bytes: 45528
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int a, b, c, s; lint k;
  scanf("%d %d %d %ld", &a, &b, &c, &k);
  if(k % 2 & 1) s = b-a;
  else s = a - b;
  printf("%d\n", s);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
bool cmp(pair<int,int> a, pair<int,int> b){
    return a.second > b.second;
}
int main(){
    long long int n,m;
    cin >> n >> m;
    priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
    for(int i = 0 ; i < n ; i++){
        int tmp;
        cin >> tmp;
        pq.push(tmp);
    }
    pair <int,int> op[m];
    for(int i = 0 ; i < m ; i++){
        long long int b,c;
        cin >> b >> c;
        op[i].first = b;
        op[i].second = c;
        
    }
    sort(op,op+m,cmp);
    for(int i = 0 ; i < m ; i++){
        while(pq.top() < op[i].second && op[i].first--){
            pq.pop();
            pq.push(op[i].second);
        }
    }
    long long int ans = 0;
    for(int i = 0 ; i < n ; i++){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long
const int mod = 1e9 + 7;
const int nax = 1e5 + 5;
int n, m, k, q;

int main()
{
	fast();
	cin >> n >> m;
	if(m >= n)
		cout << "unsafe";
	else
		cout << "safe";

}



Measured memory_bytes: 3648
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  string S,T;
  
  cin >> S >> T;
  
  int ans=0;
  
  REP(i,3){
    if(S[i]==T[i]){ans++;}
  }
 
  cout << ans << endl;
  
  return;
   
}


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

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}





Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char s[101] , p[101] ;
    int i , j , sn = 0 , pn = 0 , t ;
    
    scanf("%s %s" , s , p) ;
    
    while(s[sn] != '\0'){
        sn++ ;
    }
    while(p[pn] != '\0'){
        pn++ ;
    }
    for(i = 0 ; i < sn ; i++){
        t = 1 ;
        for(j = 0 ; j < pn ; j++){
            if(s[(i + j) % sn] != p[j]){
                t = 0 ;
            }
        }
        if(t){break ;}
    }
    if(t){
        printf("Yes\n") ;
    }
    else{
        printf("No\n") ;
    }
    return 0;
}


Measured memory_bytes: 2056