akhauriyash/Code-Regression huggingface dataset:
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;

int main() {
    string s;
    cin>>s;
    int l=s.size()-1;
    int x=l/2;
    for(int i=0; i<=x/2; i++){
        if(s[i]!=s[x-1-i]||s[i]!=s[x+1+i]||s[i]!=s[l-i]){cout<<"No"; return 0;}
    }
    cout<<"Yes";

}



Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var x = parseInt(tmp[0], 10);
	var a = parseInt(tmp[1], 10);
	var b = parseInt(tmp[2], 10);
	//出力
	if (b <= a) {
		console.log('delicious');
	} else if (a < b && b <= a + x) {
		console.log('safe');
	} else if (a + x < b) {
		console.log('dangerous');
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int k, s, c = 0, ch = 0;
  cin >> k >> s;
  rep(i, 0, k+1) {
    rep(j, 0, k+1) {
      if(s-(i+j) >= 0 && s-(i+j) <= k) c++;
    }
  }
  cout << c << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            break;
        }
        n=n/10;
    }
    if(n%10==7)
    cout<<"Yes"<<endl;
    else 
    cout<<"No"<<endl;

}

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

typedef long long int ll;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0){
        ll ans = (b - a) / 2;
        cout << ans;
    }
    else{
        ll ans = min(b - 1, n - a);
        //cout << ans << endl;
        if(b - (b - a + 1) / 2 > 1)ans = min(ans, b - (b - a + 1) / 2);
        //cout << ans << endl;
        if((n + (a + (n - b + 1))) / 2 - a > 1)ans = min(ans, (n + (a + (n - b + 1))) / 2 - a);
        cout << ans;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>

#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

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

const int INF = 0x3fffffff;

int vx[] = {1,0,-1,0}, vy[] = {0,1,0,-1};

int main(){
	int N;
	int sq[300];
	rep(i, 300){
		sq[i] = (ll)i*(i+1)*(i+2)/6;
	}
	sq[0] = INF;
	int memo[1000006]={};
	int modd[1000006]={};
	memo[1] = 1;
	modd[1] = 1;
	for(int n=1; n<1000002; n++){
		int mn = INF, mn_o = INF;
		rep(i,300){
			if( sq[i] > n ) continue;
			mn = min(mn, memo[ n-sq[i] ] + 1);
			if( sq[i]%2 == 1 ){
				mn_o = min(mn_o, modd[ n-sq[i] ] + 1);
			}
		}
		memo[n] = mn;
		modd[n] = mn_o;
	}
	//rep(i,20) cout << modd[i] << endl;
	while(cin >> N, N){
		cout << memo[N] << " " << modd[N] << endl;
	}
	return 0;
}

Measured memory_bytes: 10836
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,a=0,r=0,t=0,w=0;
 cin>>n;
 string s;
 while(n--)
 {
     cin>>s;
     if(s=="AC")a++;
     if(s=="TLE")t++;
     if(s=="RE")r++;
     if(s=="WA")w++;
 }
 cout<<"AC x "<<a<<"\nWA x "<<w<<"\nTLE x "<<t<<"\nRE x "<<r;

    return 0;
}




Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a[N], G[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int g = 0;
  FOR(i, 0, n){
    G[i] = g;
    cin >> a[i];
    g = gcd(g, a[i]);
  }
  g = 0;
  ll ans = 0;
  FORR(i, n-1, 0){
    maxs(ans, gcd(g, G[i]));
    g = gcd(g, a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int q; cin >> q;
    rep(i, q) {
        string s, t; cin >> s >> t;
        vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));

        rep(j, s.size()) {
            rep(k, t.size()) {
                if (s[j] == t[k]) {
                    dp[j+1][k+1] = max(dp[j][k] + 1, dp[j+1][k]);
                    dp[j+1][k+1] = max(dp[j+1][k+1], dp[j][k+1]);
                } else {
                    dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
                }
            }
        }
        cout << dp[s.size()][t.size()] << endl;
    }
    return 0;
}


Measured memory_bytes: 6792
#include <iostream>
#include <queue>

using namespace std;

int h, w;
// maze[y][x][i] = 1 -> (x, y) は (dx[i], dy[i]) 方向に移動可能
int maze[100][100][4];
int dist[100][100];
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, 1, -1, 0};

struct sets { int x, y, d; };

void init() {
  for (int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      for (int k = 0; k < 4; k++) {
        maze[i][j][k] = 0;
      }
    }
  }
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      dist[i][j] = -1; 
    }
  }
}

int bfs() {
  queue<sets> q;
  q.push( sets{0, 0, 0} );
  dist[0][0] = 0;

  while (!q.empty()) {
    sets cur = q.front(); q.pop();
    int x = cur.x;
    int y = cur.y;
    int d = cur.d;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if ( maze[y][x][i] == 0 ) { continue; }
      if ( dist[ny][nx] != -1 ) { continue; }

      q.push( sets{nx, ny, d+1} );
      dist[ny][nx] = d+1;
    }
  }
  return dist[h-1][w-1] + 1;
}

int main() {
  while (cin >> w >> h) {
    if (h == 0 && w == 0) { break; }
    init();
    for (int i = 0; i < 2*h-1; i++) {
      if (i & 1) {
        for (int j = 0; j < w; j++) {
          int t; cin >> t;
          if (t == 0) {
            maze[i/2][j][1] = 1;
            maze[i/2+1][j][2] = 1;
          }
        }
      } else {
        for (int j = 0; j < w-1; j++) {
          int t; cin >> t;
          if (t == 0) {
            maze[i/2][j][3] = 1;
            maze[i/2][j+1][0] = 1;
          }
        }
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
#2019/10/24
s = open(0).read()
# print(s)
index_A = []
index_Z = []
for index, char in enumerate(list(s)):
    if char == "A":
        index_A.append(index)
    if char == "Z":
        index_Z.append(index)
print(max(index_Z) - min(index_A)+1)

Measured memory_bytes: 12788
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int a[4],max=0,ans=0;
	for (int i=1;i<=3;i++)
	{
		cin>>a[i];
		ans+=a[i];
	}
	for (int i=1;i<=3;i++)
		if (a[i]>max)
		max=a[i];
	cout<<ans-max;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<int> w,s;
	A *= 100;
	B *= 100;
	rep(i,31) {
		rep(j,31) {
			if(A*i + B*j <= F && (i||j)) {
				w.push_back(A*i + B*j);
			}
		}
	}
	sort(all(w));
	w.erase(unique(all(w)), w.end());

	rep(i,3001) {
		rep(j,3001) {
			if(C*i + D*j <= F) {
				s.push_back(C*i + D*j);
			}
		}
	}
	sort(all(s));
	s.erase(unique(all(s)), s.end());

	pii res(A,0);
	rep(i,w.size()) {
		rep(j,s.size()) {
			if(w[i]+s[j] <= F && s[j] <= E*w[i]/100 && (double)res.se / res.fi < (double)s[j] / (w[i]+s[j])) {
				res.fi = w[i]+s[j];
				res.se = s[j];
			}
		}
	}
	cout << res.fi << " " << res.se << endl;

	return 0;
}


Measured memory_bytes: 1400
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	static int N;
	static int M;
	static Node[] nodeArray;
	static Node root;

	public static void main(String[] args) {
		readInput();

		solve();
	}

	static void solve() {
		boolean[] isSearched = new boolean[N+1];
		Deque<Integer> sortedNode = new ArrayDeque<>(N+1);
		
		for(int i = 1; i<=N; i++) {
			recursiveSearch(i, isSearched, sortedNode);
		}
		
		Integer[] sortedNodeArray = new Integer[sortedNode.size()];
		sortedNode.toArray(sortedNodeArray);
		
		int[] parentList = new int[N+1];
		
//		for(int i = sortedNodeArray.length - 1; i>=0; i--) {
//			int nodeId = sortedNodeArray[i];
//			
//			for(int j = i-1; j>=0; j--) {
//				if(nodeArray[nodeId].parents.contains(sortedNodeArray[j])) {
//					parentList[nodeId] = sortedNodeArray[j];
//					break;
//				}
//			}
//		}
		
		for(int i = 0; i<sortedNodeArray.length; i++) {
			for(int child : nodeArray[sortedNodeArray[i]].children) {
				parentList[child] = sortedNodeArray[i];
			}
		}
		
		for(int i = 1; i<=N; i++) {
			System.out.println(parentList[i]);
		}
	}
	
	static void recursiveSearch(int nodeId, boolean[] isSearched, Deque<Integer> queue) {
		if(isSearched[nodeId]) {
			return;
		}
		
		isSearched[nodeId] = true;
		
		for(int childId : nodeArray[nodeId].children) {
			recursiveSearch(childId, isSearched, queue);
		}
		
		queue.addFirst(nodeId);
	}

	static void readInput() {
		try (Scanner sc = new Scanner(System.in)) {
			N = sc.nextInt();
			M = sc.nextInt();

			nodeArray = new Node[N+1];

			for(int i = 0; i<nodeArray.length; i++) {
				nodeArray[i] = new Node(i);
			}

			// 辺の情報を読み込む
			for(int i = 0; i<(N - 1 + M); i++) {
				int s = sc.nextInt();
				int d = sc.nextInt();

				nodeArray[d].parents.add(s);
				nodeArray[s].children.add(d);
			}
		}
	}

	static class Node{
		public int id;
		public ArrayList<Integer> parents;
		public ArrayList<Integer> children;

		public Node(int id) {
			this.id = id;
			parents = new ArrayList<>();
			children = new ArrayList<>();
		}
	}
}


Measured memory_bytes: 125608
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
ll MOD = 1000000000 + 7;
int N;
const int MAX_N = 100;
int dp[MAX_N][4][4][4];

int main() {
    cin >> N;
    dp[0][3][3][3] = 1;

    for (int i = 0; i < N; i++){
        for (int c1 = 0; c1 < 4; c1++){
            for (int c2 = 0; c2 < 4; c2++){
                for (int c3 = 0; c3 < 4; c3++){
                    if (dp[i][c1][c2][c3] == 0) continue;
                    for (int a = 0; a < 4; a++) {
                        if (a == 2 && c1 == 1 && c2 == 0) continue; // ?ACG
                        if (a == 2 && c1 == 0 && c2 == 1) continue; // ?CAG
                        if (a == 1 && c1 == 2 && c2 == 0) continue; // ?AGC
                        if (a == 2 && c1 == 1 && c3 == 0) continue; // A?CG
                        if (a == 2 && c2 == 1 && c3 == 0) continue; // AC?G

                        dp[i+1][a][c1][c2] += dp[i][c1][c2][c3];
                        dp[i+1][a][c1][c2] %= MOD;
                    }
                }
            }

        }
    }
    int ans = 0;
    for (int c1 = 0; c1 < 4; c1++) {
        for (int c2 = 0; c2 < 4; c2++) {
            for (int c3 = 0; c3 < 4; c3++) {
                ans += dp[N][c1][c2][c3];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int cnt[128];

int main(void) {
    string s;
    cin >> s;
    int i, n = s.size();

    for (auto c: s) cnt[c]++;
    ll ans = (ll) n * (n + 1) / 2;
    REP (i,128) ans -= (ll) cnt[i] * (cnt[i] + 1) / 2;
    cout << ans + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n,m;
      cin>>n>>m;
      lint a[n];
      lint sum=0;
      map<lint,lint>mp;
      mp[0]++;
      rep(i,n){
          cin>>a[i];
          sum+=a[i];
          mp[sum%m]++;
      }
      lint ans=0;
      for(auto x:mp){
        ans+=x.second*(x.second-1)/2;
      }
      cout<<ans<<endl;
  }
  
     


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
main(){
	int n,ans=0;
	cin>>n;

	int a[n];

	r(i,n)cin>>a[i];

	int r=0,x=0;

	r(l,n){
		while( r<n && x+a[r]==(x^a[r]) ) x+=a[r++] ;
		ans+=(r-l);
		x-=a[l];
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

int h, w;
char c[21][21];
int d[21][21];
int dist[21][21][21][21];
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

void bfs(int sy, int sx){
    rep(i, 0, h) rep(j, 0, w) d[i][j] = INF;
    d[sy][sx] = 0;
    queue<P> q;
    q.push(P(sy, sx));
    while(!q.empty()){
        P p = q.front(); q.pop();
        rep(i, 0, 4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(!contain(ny, nx) || d[ny][nx] != INF || c[ny][nx] == 'x') continue;
            d[ny][nx] = d[p.first][p.second] + 1;
            q.push(P(ny, nx));
        }
    }
}

signed main(){
    while(1){
        cin >> w >> h;
        if(w + h == 0) break;
        vector<P> pl;
        int sy, sx;
        rep(i, 0, h){
            rep(j, 0, w){
                cin >> c[i][j];
                if(c[i][j] == 'o'){
                    sy = i; sx = j;
                }
                if(c[i][j] == '*'){
                    pl.push_back(P(i, j));
                }
            }
        }
        pl.push_back(P(sy, sx));
        rep(i, 0, pl.size()){
            bfs(pl[i].first, pl[i].second);
            rep(j, 0, h){
                rep(k, 0, w){
                    dist[pl[i].first][pl[i].second][j][k] = d[j][k];
                }
            }
        }
        vector<int> perm;
        perm.push_back(pl.size() - 1);
        rep(i, 0, pl.size() - 1){
            perm.push_back(i);
        }
        int ans = INF;
        do{
            int tmp = 0;
            rep(i, 0, perm.size() - 1){
                tmp += dist[pl[perm[i]].first][pl[perm[i]].second][pl[perm[i + 1]].first][pl[perm[i + 1]].second];
            }
            ans = min(ans, tmp);
        }while(next_permutation(perm.begin(), perm.end()));
        if(ans == INF) ans = -1;
        cout << ans << endl;
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
    ll R, C, Q;
    while (cin >> R >> C >> Q, R) {
        vector<ll> a(Q), b(Q), order(Q);
        for (int i = 0; i < Q; i++) {
            cin >> a[i] >> b[i] >> order[i];
        }
        vector<bool> used_a(R, 0), used_b(C, 0);
        ll r = 0, c = 0, res = 0;
        for (int i = Q-1; i >= 0; i--) {
            if (a[i] == 0) { // ???
                if (!used_a[b[i]]) {
                    used_a[b[i]] = 1;
                    r++;
                    if (order[i] == 1) {
                        res += C - c;
                    }
                }
            } else {         // ???
                if (!used_b[b[i]]) {
                    used_b[b[i]] = 1;
                    c++;
                    if (order[i] == 1) {
                        res += R - r;
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d" , &n);

    while(n){
            if(n%10 == 7){
                    printf("Yes\n");
                    return;
            }
            n /= 10;
    }
    printf("No\n");

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>

int main()
{
    int x = 0;
    std::cin >> x;
    int s = x%60;
    int m = ((x-s)/60)%60;
    int h = (x-(m*60)-s)/60/60;
    std::cout << h << ":" << m << ":" << s << std::endl;
    return 0;
}


Measured memory_bytes: 3056
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    if(n>0) {
        ans += n * (n-1) / 2;
    }
    if(m>0) {
        ans += m * (m-1) / 2;
    }
    print(ans);
    return 0;
}


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

using namespace std;

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

  s[5] = ' ';
  s[13] = ' ';

  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_H = 90;
const ll MAX_W = 90;
const ll MAX_VALUE = 2*MAX_H*MAX_W;

bool dp[MAX_H][MAX_W][MAX_VALUE];  // dp[i][j][k] : (i,j)の偏りをkにできればtrue

int main() {
    ll h, w;
    cin >> h >> w;

    vvl a(MAX_H, vl(MAX_W));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }

    vvl b(MAX_H, vl(MAX_W));
    rep(i, h) {
        rep(j, w) {
            cin >> b[i][j];
        }
    }

    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    rep(i, h) {
        rep(j, w) {
            ll x = abs(a[i+1][j] - b[i+1][j]);
            ll y = abs(a[i][j+1] - b[i][j+1]);
            rep(k, MAX_VALUE) {
                if(i < h-1 && dp[i][j][k]) {
                    dp[i+1][j][k + x] = true;
                    dp[i+1][j][abs(k - x)] = true;
                }
                if(j < w-1 && dp[i][j][k]) {
                    dp[i][j+1][k + y] = true;
                    dp[i][j+1][abs(k - y)] = true;
                }
            }
        }
    }

    rep(k, MAX_VALUE) {
        if(dp[h-1][w-1][k]) {
            out(k);
            re0;
        }
    }

    re0;
}

Measured memory_bytes: 113792
N, M = gets.split.map{|i|i.to_i}
n = N
m = M
r = 0
if n >= m / 2
    r = m / 2
    m = 0
    n = 0
end
if n < m / 2
    r += n
    m -= 2 * n
    n = 0
end
r += m / 4
puts r


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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    while(A > 0 && C > 0){
        C -= B;
        if (C <= 0){
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0){
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3596
using System;

namespace ALDS1_1_C_PrimeNumbers
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());

			int count = 0;

			for (int lp = 0; lp < dataCount; lp++)
			{
				int inputNum = int.Parse (Console.ReadLine ());
				if (IsPrimeNumber (inputNum))
					count++;
			}

			Console.WriteLine (count);
		}

		static bool IsPrimeNumber ( int num )
		{
			if (num < 2)
				return false;

			if (num == 2)
				return true;

			if (num % 2 == 0)
				return false;

			int lp = 3;
			double limit = Math.Sqrt (num);
			while (lp <= limit)
			{
				if (num % lp == 0)
					return false;

				lp += 2;
			}

			return true;
		}
	}
}

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


int main(){
  int N ; 
  string S  ;

  
  cin >> N ;
  cin >> S ; 
  vector<char> A(N);   
  
  for(int i = 0 ; i < N ; i++){
    A.at(i) = '0' ; 
  }
  
  for(int i = 0 ; i < N-1 ; i++){
    if(S.at(i) != S.at(i+1)){
      A.at(i) = S.at(i) ;
    }
  }     
  int cnt = 0 ; 
  for(int i = 0 ; i < N-1 ; i++){
  	if(A.at(i) == '0') cnt++ ; 
  }
  
  if(S.at(N-1) == '0' ) cnt++ ; 
  
  cout << N-cnt << endl ; 
}


Measured memory_bytes: 3844
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2005;
int n,m,Q;
char s[N][N];
int sum[N][N];
int a[N][N],b[N][N];
int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+s[i][j]-'0';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j-1>=1&&s[i][j]=='1'&&s[i][j-1]=='1') a[i][j]++;
			if(i-1>=1&&s[i][j]=='1'&&s[i-1][j]=='1') b[i][j]++;
			a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
		}
	while(Q--)
	{
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int ans=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
		ans-=a[x2][y2]-a[x2][y1]-a[x1-1][y2]+a[x1-1][y1];
		ans-=b[x2][y2]-b[x2][y1-1]-b[x1][y2]+b[x1][y1-1];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 52864
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    char S[101];

    if (scanf("%s", S) < 1) return 0;

    int mincnt = strlen(S);

    for (char i = 'a'; i <= 'z'; i++)
    {
        int cnt = 0;

        char X[101];

        strcpy(X, S);

        bool flg = true;
        int len = strlen(X) - 1;
        for (int k = 0; k < len; k++)
        {
            if (X[k] != X[k + 1])
            {
                flg = false;
                break;
            }
        }

        while (!flg)
        {
            for (int j = 0; j < len; j++)
            {
                if (X[j] != i && X[j + 1] == i) X[j] = i;
                else if (X[j] != i && X[j] != X[j + 1]) X[j] = X[j + 1];
            }

            X[len] = '\0';

            flg = true;
            len = strlen(X) - 1;
            for (int k = 0; k < len; k++)
            {
                if (X[k] != X[k + 1])
                {
                    flg = false;
                    break;
                }
            }

            cnt++;
        }

        mincnt = min(mincnt, cnt);
    }

    printf("%d\n", mincnt);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int s, w;
    cin, s, w;
    cout << (w >= s ? "unsafe" : "safe") << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  deque<int> que;

  rep(i,n) {
    int a;
    cin >> a;
    if (i%2) que.push_front(a);
    else que.push_back(a); 
  }

  if (n%2) {
    while(!que.empty()) {
      cout << que.back() << " ";
      que.pop_back();
    }
    cout << endl;
  } else {
    while(!que.empty()) {
      cout << que.front() << " ";
      que.pop_front();
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

const long long int INF = 99999999999999999;

struct edge {
	long long int from, to, cost;
};
edge ed[200101];
long long int d[201000];
long long int V, E;

struct COUNT {
	long long int id, cou;
};
COUNT  Cou[200100];
void Bellman_Ford(int s) {
	for (int i = 0; i <=V; i++) { d[i] = INF; }
	d[s] = 0;
	while (true) {
		bool update = false;
		for (int i = 0; i < E; i++) {
			edge e = ed[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) {
			for (int i = 1; i <= V; i++) {
				Cou[i].cou = d[i];
				Cou[i].id = i;
			}
			
			break; }
	}
}

bool cmp(COUNT a, COUNT b) {
	return a.cou > b.cou;
}


int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	string  str, s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, a[200001], b[200001], c[200001],res[200001], k,now=1, memo=0, ma, mi;
	
	cin >> n;

	V = n;
	E = 2*n - 2;

	for (int i = 0; i < n-1; i++) {
		cin >> ed[i].from >> ed[i].to;

		
		ed[i + n-1].from = ed[i].to;
		ed[i+n-1].to=ed[i].from;
		ed[i].cost = 1;
		ed[i + n-1].cost = 1;
	}
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	sort(c + 1, c + n + 1);
	Bellman_Ford(1);
	sort(Cou + 1, Cou + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		res[Cou[i].id] = c[i];
		memo += c[i];
	}
	cout << memo - c[n] << endl;
	for (int i = 1; i <= n; i++) {
		cout << res[i] << " ";
	}
}


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

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

Measured memory_bytes: 256
import heapq


def main():
    N = int(input())
    q = []
    for i in range(N):
        a, b = map(int, input().split())
        q.append((b, a))

    heapq.heapify(q)

    t = 0
    while q:
        b, a = heapq.heappop(q)
        t += a
        # print(a, b)
        if t > b:
            print("No")
            return
    print("Yes")



if __name__ == '__main__':
    main()

Measured memory_bytes: 28804
#include <stdio.h>


int main()
{
    int k,o=0,e=0;
    scanf("%d",&k);
    for(int i=1;i<=k;i++){
        if(i%2==1){
            o++;
        }else{e++;}
    }
    printf("%d",o*e);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='A')
		{
			s[i]='X';
		}
		else if(s[i]=='B')
		{
			s[i]='Y';
		}
		else if(s[i]=='C')
		{
			s[i]='Z';
		}
		else
		{
			s[i]-=3;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<string, P> PS;

struct edge{
	int to;
	string lab;
};

int main()
{
	while(1){
		int n, a, s, g;
		cin>>n>>a>>s>>g;
		if(n==0 && a==0 && s==0 && g==0) return 0;
		vector<edge> v[40];
		for(int i=0; i<a; i++){
			int x, y;
			string l;
			cin>>x>>y;
			cin>>l;
			edge e;
			e.to=y, e.lab=l;
			v[x].push_back(e);
		}
		string d[40][501];
		for(int i=0; i<n; i++){
			for(int j=0; j<501; j++){
				if(i==s && j==0) continue;
				d[i][j]+='0';
			}
		}
		priority_queue<PS, vector<PS>, greater<PS> > que;
		que.push(PS(d[s][0], P(s, 0)));
		while(!que.empty()){
			PS p=que.top();
			que.pop();
			int x=p.second.first, lx=p.second.second;
			if(d[x][lx]<p.first) continue;
			for(auto e:v[x]){
				int y=e.to;
				string str=e.lab;
				int m=str.size();
				if(lx+m<=500 && (d[y][lx+m]=="0" || d[y][lx+m]>(d[x][lx]+str))){
					d[y][lx+m]=(d[x][lx]+str);
					que.push(PS(d[y][lx+m], P(y, lx+m)));
				}
			}
		}
		string ans;
		ans+='0';
		for(int i=0; i<=500; i++){
			if(d[g][i]=="0") continue;
			if(ans=="0" || ans>d[g][i]) ans=d[g][i];
		}
		if(ans=="0" || ans.size()>250){
			cout<<"NO"<<endl;
		}else{
			cout<<ans<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24884
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long K,A,B;
cin>>K>>A>>B;
bool judge=false;
for(int i=A;i<=B;++i){
    if(i%K==0){
        judge=true;
        break;
    }
}
if(judge){
    cout<<"OK"<<"\n";
}
else{
    cout<<"NG"<<"\n";
}
return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

    int fcount=0, count=0;
    rep(i, n){
        if(s[i]=='A'){
            fcount=1;
        }
        else if(fcount==1&&s[i]=='B') fcount++;
        else if(fcount==2&&s[i]=='C'){
            count++;
            fcount=0;
        }
        else fcount=0;
    }
    out(count);
}

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

int main()
{
  int n;
  cin >> n;
  vector<vector<int> > G(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      int v;
      cin >> v;
      G.at(u - 1).at(v - 1) = 1;
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      cout << G.at(i).at(j);
      if (j == n - 1)
      {
        cout << endl;
      }
      else
      {
        cout << " ";
      }
    }
  }
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i],a[i]*=2;
  ll x=0;
  rep(i,n)x=a[i]-x;
  x/=2;
  rep(i,n){
      cout<<x<<' ';
      x=a[i]-x;
  }
  cout<<endl;
  return 0;
  }


Measured memory_bytes: 2176
#include<stdio.h>

const int mod = 1e9 + 7;
long long fact[302020], rfact[302020];

long long modPow(int x, int n)
{
  if(n == 0) return (1);
  long long ret = modPow(x, n / 2);
  ret *= ret;
  ret %= mod;
  if(n % 2 == 1) {
    ret *= x;
    ret %= mod;
  }
  return (ret);
}

long long modInv(int p)
{
  return (modPow(p, mod - 2));
}

long long modCombination(int p, int q)
{
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

void init()
{
  fact[0] = rfact[0] = 1;
  for(int i = 1; i < 302020; i++) {
    fact[i] = fact[i - 1] * i % mod;
    rfact[i] = modInv(fact[i]);
  }
}

int main()
{
  int N, A[100000];
  int appear[100000] = {};
  int i, left, right;
  long long curr = 0;

  init();

  scanf("%d", &N);
  ++N;
  for(i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    --A[i];
    ++appear[A[i]];
  }


  for(i = 0; i < N; i++) {
    if(appear[A[i]] == 2) {
      left = i;
      break;
    }
  }
  for(i = N - 1; i >= 0; i--) {
    if(appear[A[i]] == 2) {
      right = N - i - 1;
      break;
    }
  }

  for(i = 1; i <= N; i++) {
    printf("%lld\n", (modCombination(N, i) + mod - modCombination(right + left, i - 1)) % mod);
  }

}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    string s;
    cin >> s;
    // s       = "0" + s;
    ll n = s.size();
    vector<ll> v(n);

    ll cur = 0;
    ll keta = 1;
    for (ll i = n-1; i >= 0; --i) {
        ll c = s[i] - '0';
        cur = c * keta + cur;
        cur %= 2019;
        v[i] = cur;
        keta = (keta * 10) % 2019;
    }

    //for (ll i = 0; i < n; ++i) {
    //    cerr << v[i] << endl;
    //}

    vector<ll> p(2019, 0);

    for (ll i = 0; i < n; ++i) {
        p[v[i]]++;
    }

    ll sum = 0;
    for (ll i = 0; i <= 2018; ++i) {
        if (i == 0) {
            if (p[i] == 0) continue;
            sum += (p[i] * (p[i] + 1)) / 2;
        } else {
            if (p[i] < 2) continue;
            sum += (p[i] * (p[i]- 1)) / 2;
        }
    }
    //if (p[0] > 0) sum++;

    cout << sum << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int a,b,k;

int g[500][500];
int cap[500][500];

const int INF = 1000000000;

// ????°??????¨???

const int C = 200;

int h[500];
int dist[500];
int prevv[500];
pii preve[500];
int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+500,0);
  while(f>0){
    priority_queue<pii> Q;
    fill(dist,dist+500,INF);
    dist[s] = 0;
    Q.push(pii(INF-0,INF-s));
    while(!Q.empty()){
      pii P = Q.top(); Q.pop();
      int d = INF-P.first;
      int v = INF-P.second;
      if(dist[v]<d)continue;
      REP(to,500){
        int cost = g[v][to];
        int capa = cap[v][to];
        if(capa>0 && dist[to]>dist[v]+cost+h[v]-h[to]){
          dist[to] = dist[v]+cost+h[v]-h[to];
          prevv[to] = v;
          preve[to] = pii(v,to);
          Q.push(pii(INF-dist[to],INF-to));
        }
      }
    }
    if(dist[t]==INF){
      return -1;
    }
    REP(i,500) h[i]+=dist[i];
    int d = f;
    for(int v=t;v!=s;v=prevv[v]){
      d = min(d, cap[preve[v].first][preve[v].second]);
    }
    f -= d;
    res += d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      cap[preve[v].first][preve[v].second] -= d;
      cap[preve[v].second][preve[v].first] += d;
    }
  }
  return res;
}

int main(){
  // 0~a-1 : A part
  // 200~200+b-1 : B part
  // 400 : source
  // 401 : sink
  // ??¢??????????????£??\????????§O(FV^2)
  // ?????£????????¨??¨1
  scanf("%d%d%d",&a,&b,&k);
  REP(i,500)REP(j,500)g[i][j]=INF;
  REP(i,a)REP(j,b){
    g[i][C+j]=1;
    cap[i][C+j]=1;
    g[C+j][i]=-1;
    cap[C+j][i]=0;
  }
  char s[252];
  // dislike : cost += 300
  REP(i,a){
    scanf("%s",s);
    REP(j,b){
      g[i][C+j] += (s[j]-'0'==0?0:300);
      g[C+j][i] -= (s[j]-'0'==0?0:300);
    }
  }
  REP(i,b){
    scanf("%s",s);
    REP(j,a) g[j][C+i] += (s[j]-'0'==0?0:300);
    REP(j,a) g[C+i][j] -= (s[j]-'0'==0?0:300);
  }
  // ???????????¨2??¨??°??????
  // source to A part
  REP(i,a){
    g[400][i]=0;
    cap[400][i]=1;
    g[i][400]=0;
    cap[i][400]=0;
  }
  // B part to sink
  REP(i,b){
    g[C+i][401]=0;
    cap[C+i][401]=1;
    g[401][C+i]=0;
    cap[401][C+i]=0;
  }

  // ????????????1????????????
  // ????°????????????§
  int limitcost = (k+1)*300;  // ??????????¶????????????????
  int nowflow = 0;
  int nowcost = 0;

  while(true){
    int f = min_cost_flow(400,401,1);
    if(f==-1)break;
    nowcost += f;
    if(nowcost>limitcost)break;
    ++nowflow;
  }
  cout<<nowflow<<endl;

  return 0;
}

Measured memory_bytes: 3004
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	int N;
	cin >> N;
	cout << N/3 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct FSD{
int f,s,d;
};
bool p[5000][5000]={false};
struct FSD q[5000],t;
int main(){
int i,j,n,m,a,b,cnt,c=0;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){
scanf("%d%d",&a,&b);
p[b-1][a-1]=true;
}
for(i=0;i<n;i++){
q[i].f=i;
q[i].d=i;
for(j=0;j<n;j++){
if(p[i][j])
q[i].s++;
}
}
for(i=0;i<n;i++){
t.f=q[i].f;
t.s=q[i].s;
t.d=q[i].d;
for(j=i+1;j<n;j++){
if(t.s>=q[j].s&&!p[q[j].f][t.f]){
t.f=q[j].f;
t.s=q[j].s;
t.d=q[j].d;
}
}
cnt=0;
for(j=i;j<n;j++){
if(q[j].s==t.s)
cnt++;
if(p[q[j].f][t.f])
q[j].s--;
}
if(cnt>=2)
c=1;
q[t.d].f=q[i].f;
q[t.d].s=q[i].s;
q[i].f=t.f;
q[i].s=t.s;
}
for(i=0;i<n;i++)
printf("%d\n",q[i].f+1);
printf("%d\n",c);
return 0;
}



Measured memory_bytes: 27492
#include <iostream>
#include <string>
#include <iomanip>

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

    std::cin >> r;

    std::cout << std::setprecision(16) << static_cast<double>(r) * 2.0 * 3.14159265358979 << std::endl;

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int A[m];
  for (int i = 0; i < m; i++ ) {
        A[i] = 0;
  }
  for(int i=0;i<n;i++)
  {
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int ak;
      cin >> ak;
      A[ak-1]+=1;
    }
  }
  int c=0;
  for(int i=0;i<m;i++)
  {
  	if(A[i] >= n)c++; 
  }
  cout<<c<<endl;
  return 0;
}

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

int main(void) {
    int A,B;
    int maxa ;  
    cin >> A >> B;
    
    maxa = max(A,B);
    if(A == B)    cout << maxa + maxa  << endl;
    else cout << maxa + maxa -1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;

long long int N, M;

int main(){
    long long int ans = 0;
    cin >> N >> M;

    ans = min(N, M/2);
    N -= ans;
    M -= (ans*2);
    while(N > 0 && M/2 > 0){
        ans++;
        M -= 2;
        N--;
    }
    if(M/2 == 0){
        cout << ans;
        return 0;
    }
    if(M/4 > 0) ans += (M/4);
    cout << ans;

    return 0;
}

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	vl v(n);
	rep(i,0,n) cin>>v[i];
	sort(all(v));
	cout<<abs(v[0]-v[n-1]);
	
	return 0;
}

Measured memory_bytes: 3616
N, M = map(int, input().split())

mise = []
for i in range(N):
    a, b = map(int, input().split())
    mise.append((a, b))

mise.sort()

honnsuu = 0
kinngaku = 0
for a, b in mise:
    if honnsuu >= M:
        break

    kauhonnsuu = M - honnsuu
    kaeruhonnsuu = min(kauhonnsuu, b)
    kinngaku += kaeruhonnsuu * a
    honnsuu += kaeruhonnsuu

print(kinngaku)


Measured memory_bytes: 16908