akhauriyash/Code-Regression huggingface dataset:
import collections
N, M = map(int, input().split())
ablist = []
hublist1 = []
hublistN = []
work = []
for i in range(M):
    ab = tuple(map(int, input().split()))
    ablist.append(ab)
    if N in ab:
        if ab[0] == N:
            hublistN.append(ab[1])
        else:
            hublistN.append(ab[0])

    if 1 in ab:
        if ab[0] == 1:
            hublist1.append(ab[1])
        else:
            hublist1.append(ab[0])
            
work = hublist1 + hublistN
c = collections.Counter(work)
if 2 in c.values():
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
# print(ablist)
# print(hublist1)
# print(hublistN)
# print(work)

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << a*b/2 << endl;
	return 0;
}

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

int main(){
    string S;
    int N, len, i;
    cin >> N >> S;
    len = S.size();
    for(i = 0; i < len; i++){
        S[i] += N;
        if(S[i] > 'Z')S[i] -= 26;
    }
    cout << S << endl;
}

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

using namespace std;

int main()
{
	long long n,k;
	cin >> n >> k;
	vector<pair<long long,long long> > ab(n);
	for(int i=0;i<n;i++)
		cin >> ab[i].first >> ab[i].second;
	sort(ab.begin(),ab.end());
	long long cou=0;
	int i=0;
	while(true)
	{
		cou+=ab[i].second;
		if(cou>=k)
		{
			cout << ab[i].first << endl;
			return 0;
		}
		i++;
	}
}


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

struct Card { char suit, value; };
 
void bubble(struct Card A[], int N) {
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j > i; j--) {
			if (A[j - 1].value > A[j].value) {
				swap(A[j], A[j - 1]);
				flag = 1;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	int minj;
	for (int i = 0; i < N - 1; i++) {
		minj = i;
		for (int j = i; j < N; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		if (i != minj) {
			swap(A[i], A[minj]);
		}
	}
}

void print(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		cout << A[i].suit << A[i].value;
		if (i == N - 1)
			cout << endl;
		else
			cout << " ";
	}
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0; i < N; i++) {
		if (C1[i].suit != C2[i].suit)
			return false;
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int N;
	cin >> N;
	char ch;
	
	for (int i = 0; i < N; i++) 
		cin >> C1[i].suit >> C1[i].value;
	
	for (int i = 0; i < N; i++)
		C2[i] = C1[i];
	
	bubble(C1, N);
	selection(C2, N);

	print(C1, N);
	cout << "Stable" << endl;

	print(C2, N);
	if (isStable(C1, C2, N))
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ll long long
#define N 3005
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
template<typename T>
inline void in(T &x)
{
	x=0;
	char c=getchar();
	bool fu=0;
	while(c<'0'||c>'9'){if(c=='-')fu=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x=fu?-x:x;
}
int n,m,K;
ll dp[N][N][4],a[N][N];
void update(ll &x,ll y)
{
	if(y==-1)return;
	if(x==-1)x=y;
	else if(x<y)x=y;
}
int main()
{
	in(n);in(m);in(K);
	for(int i=0;i<K;++i)
	{
		int x,y,val;
		in(x);in(y);in(val);
		a[x][y]=val;
	}
	memset(dp,-1,sizeof(dp));
	if(a[1][1])dp[1][1][1]=a[1][1];
	dp[1][1][0]=0;
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)
	for(int k=0;k<4;++k)
	if(dp[i][j][k]!=-1)
	{
		if(i+1<=n)
		{
			update(dp[i+1][j][0],dp[i][j][k]);
			if(a[i+1][j])update(dp[i+1][j][1],dp[i][j][k]+a[i+1][j]);
		}
		if(j+1<=m)
		{
			update(dp[i][j+1][k],dp[i][j][k]);
			if(k<3&&a[i][j+1])update(dp[i][j+1][k+1],dp[i][j][k]+a[i][j+1]);
		}
	}
	ll ans=-1;
	for(int i=0;i<4;++i)
	update(ans,dp[n][m][i]);
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    set<int> st;
    st.insert(1);

    REP(i, 2, sqrt(1000) + 1) {
        int k = i;
        k *= i;
        while (k <= 1000) {
            st.insert(k);
            k *= i;
        }
    }

    int x;
    cin >> x;

    while (1) {
        if (st.count(x)) {
            cout << x << endl;
            return 0;
        }
        x--;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,r) for(int i=0;i<r;i++)
int main(){
    long h,w; cin>>h>>w;
    long c[10][10];
    REP(i,10){
        REP(j,10)
            cin>>c[i][j];
    }
    REP(i,10){
        REP(j,10){
            REP(k,10)
                c[j][k]=min(c[j][k],c[j][i]+c[i][k]);
        }
    }
    long count=0;
    REP(i,h){
        REP(j,w){
            long t; cin>>t;
            if(abs(t)!=1)
                count+=c[t][1];
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
int N; cin >> N; 
  bool flag = false; int sum = 0; int min_notmultiple = 1145141919;
  for(int i = 0; i < N; i++){
    int s; cin >> s; 
    if( s % 10 != 0){
      flag = true; min_notmultiple = min(min_notmultiple , s);}
    sum += s;}
  
  if( flag == false){ cout << 0 << endl;}
  else{
    if( sum % 10 != 0){ cout << sum << endl;}
   else{ cout << sum - min_notmultiple << endl;}}
  
  return 0;}
      

Measured memory_bytes: 256
// AOJ ALDS1_13_C 15 Puzzle
// 2018.5.8 bal4u

#include <stdio.h>

typedef unsigned long long ull;

#define QMAX 100000
typedef struct { ull s; char x, v; char t; } QUE;  // t:ステップ数
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r;
	int min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

void deq()
{
  que[0] = que[--qsize];
  min_heapify(0);
}

void enq(ull s, int x, int v, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].x = x, que[i].v = v, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

#define HASHSIZ 200003
typedef struct { ull s; char v; } HASH;
HASH hash [HASHSIZ+3], *hashend  = hash +HASHSIZ;

int lookup(ull s)
{
	HASH *hp = hash + (int)(s % HASHSIZ);
	while (hp->s) {
		if (hp->s == s) return hp->v;
		if (++hp == hashend) hp = hash;
	}
	return -1;
}


void insert(ull s, char v)
{
	HASH *hp = hash + (int)(s % HASHSIZ);
	while (hp->s) {
		if (hp->s == s) { hp->v = v; break; }
		if (++hp == hashend) hp = hash;
	}
	hp->s = s, hp->v = v;
}

#define GOAL 0x123456789ABCDEF0LL
#define ABS(a) ((a)>=0?(a):-(a))

int hi[16] = {2,3,3,2,3,4,4,3,3,4,4,3,2,3,3,2};
int to[16][4] = {
{1,4},{0,2,5},{1,3,6},{2,7},
{0,5,8},{1,4,6,9},{2,5,7,10},{3,6,11},
{4,9,12},{5,8,10,13},{6,9,11,14},{7,10,15},
{8,13},{9,12,14},{10,13,15},{11,14}};
double magic = 1;

void toArray(char *p16, ull s)
{
	int i;
	
	for (i = 15; i >= 0; i--) {
		p16[i] = s & 0xf, s >>= 4;
	}
}

ull swap(char *p16, int zero, int nx)
{
	int i;
	ull res;
	
	res = 0;
	for (i = 0; i < 16; i++) {
		res <<= 4;
		if      (i == zero) res |= p16[nx];
		else if (i == nx)   res |= p16[zero];
		else                res |= p16[i];
	}
	return res;
}

int eval(ull s)
{
	int i, r1, c1, r2, c2;
	int e, t;

	e = 0;
	for (i = 15; i >= 0; i--) {
		t = s & 0xf, s >>= 4;
		if (t) {
			t--;
			r1 = i >> 2, c1 = i & 3;
			r2 = t >> 2, c2 = t & 3;
			e += ABS(r1-r2) + ABS(c1-c2);
		}
	}
	return (int)(e*magic);

}

int main()
{
	int i, x, nx, v, nv, t;
	ull s, ns;
	char p16[16];

	s = 0; for (i = 0; i < 16; i++) {
		scanf("%d", &t);
		p16[i] = t, s <<= 4, s |= t;
		if (t == 0) x = i;
	}
	qsize = 0;
	t = eval(s);
	if      (t <= 22) magic = 1.12;
	else if (t <= 25) magic = 1.14;
	else              magic = 1.28;

	enq(s, x, 0, (int)(t*magic));

	insert(s, 0);
	while (qsize) {
		s = que[0].s, x = que[0].x, v = que[0].v, deq();
		if (s == GOAL) break;
		if (lookup(s) < v) continue;

		toArray(p16, s);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			ns = swap(p16, x, nx), nv = v+1;
			t = lookup(ns);
			if (t < 1 || nv < t) {
				enq(ns, nx, nv, eval(ns)+v);
				insert(ns,  nv);
			}
		}
	}
	printf("%d\n", v);
	return 0;
}



Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long T1, T2, A1, A2, B1, B2, C1, C2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    C1 = A1 - B1;
    C2 = A2 - B2;

    if(C1 < 0){
        C1 = -C1;
        C2 = -C2;
    }
    if(T1*C1+T2*C2 > 0){
        cout << 0 << endl;
        return 0;
    }
    if(T1*abs(C1)==T2*abs(C2)){
        cout << "infinity" << endl;
        return 0;
    }
    long long threshold = -T1*C1/(T1*C1+T2*C2);
    long long ans = 2 * threshold;
    if(threshold*(T1*C1+T2*C2)!=-T1*C1) ans++;
    cout << ans << endl;
    return 0;
}

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

#define SYNC ios::sync_with_stdio(0);
#define F first
#define S second
#define endl '\n'


using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const int MAXN = 58;
const ll mod = 1000000007;



int main() {
    SYNC
    int n;
    cin >> n;
    int ans = 1, inn;
    cin >> inn;
    int maxi = inn;
    int a;
    for (int i = 1; i < n; ++i) {
        cin >> a;
        if (a >= inn && a >= maxi) {
            ans++;
        }
        maxi = max(a, maxi);
    }
    cout << ans << endl;
    return 0;
}

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

int par[200000],siz[200000];

int find(int a) {
    if (par[a]==a)
        return a;
    return par[a]=find(par[a]);
}

void unite(int a,int b) {
    a=find(a);
    b=find(b);
    if (a==b)
        return;
    par[b]=a;
    siz[a]+=siz[b];
}

int main() {
    int n,m;cin>>n>>m;
    for (int i=0;i<n;i++) {
        par[i]=i;
        siz[i]=1;
    }
    int ans=1;
    for (int i=0;i<m;i++) {
        int a,b;cin>>a>>b;
        unite(a-1,b-1);
        ans=max(ans,siz[par[a-1]]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1000000007;
int Size = 100010;
int main()
{
    int n;
    cin >> n;
    ll A[n+5] = {};
    int dp[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> A[i];
    }
    for(int i = 2; i <= n; i++)
    {
        if(A[i-1] >= A[i])
        {
            dp[i] = dp[i-1]+1;
        }
    }
    int Max = 0;
    for(int i = 1; i <= n; i++)
    {
        Max = max(Max, dp[i]);
    }
    cout << Max << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
  int i, j, flag, A[100], n, temp, cnt = 0;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);
  
  flag = 1;
  i = 0;
  while(flag){
    flag = 0;
    for(j = n-1; j >= i+1; j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
	cnt++;
      }
    }
    i++;
  }
  for(i = 0; i < n; i++){
    if(0 < i)   printf(" %d", A[i]);
    else        printf("%d", A[i]);
  }
  printf("\n%d\n", cnt);

  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int digit(long long int a)
{
    int i,j,b,s=0;
    for( ;a>0;)
    {
        b=a%10;
        s=s+b;
        a=a/10;
    }
    return s;
}
int main()
{
    long long int a,b,c,d,i,j,s=0;
    scanf("%lld%lld%lld",&a,&b,&c);
    for(i=1;i<=a;i++)
    {
        d=digit(i);
        if(d>=b && d<=c)s=s+i;
    }
    printf("%lld\n",s);
    return 0;
}


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

int main() {
  int n, a, answer;
  answer = 0;
  cin >> n;
  vector<int> jewel(n);
  
  for(int i = 0; i < n; i++) {
    cin >> jewel.at(i);
  }
  
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(jewel.at(i) - a > 0) {
      answer += jewel.at(i) - a;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char s[4];
	scanf("%s", &s);
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < 4; i++) {
		switch (s[i]) {
		case 'a':
			a++;
			break;
		case 'b':
			b++;
			break;
		case 'c':
			c++;
			break;
		}
	}
	if ((a == 1) && (b == 1) && (c == 1)) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Map as Map
import Data.List

import Control.Monad
import Control.Monad.State

getInts :: IO [Int]
getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  n <- readLn :: IO Int
  
  let ans = (flip evalState) Map.empty $ do
        forM_ [1..n] $ \x -> do
          let s = show x
          let p = (head s, last s)
          
          res <- (Map.lookup p) <$> get
          
          modify $ case res of
            Just c -> Map.insert p (c+1)
            _ -> Map.insert p 1

        sum . catMaybes <$> do
          forM [1..n] $ \x -> do
            let s = show x
            let p = (last s, head s)

            ret <- (Map.lookup p) <$> get

            return ret
      

  print $ ans


Measured memory_bytes: 75132
#include<stdio.h>
#include<string.h>
int main()
{
    int i,A[26]= {0},p;
    char a;
    while((scanf("%c",&a))!=EOF)
    {

        if(a!=' ')
        {
            if(a>='A' && a<='Z')
            {
                p=a-'A';
            }
            else
            {
                p=a-'a';
            }
            A[p]++;
        }
    }
    for(i=0; i<26; i++)
    {
        printf("%c : %d\n",'a'+i,A[i]);
    }
    return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

char func(char a,char b){
	string s = "abc";
	FOR(i,0,3){
		if(s[i] != a && s[i] != b)return s[i];
	}
}

bool func(ll a,ll b,ll c){
	string s = "ab";
	if(!a || !b)return 0;
	a--;
	b--;
	map<char,int> m;
	m['a'] = a;
	m['b'] = b;
	m['c'] = c;
	FOR(i,0,a+b+c){
		if(!m[func(s[s.size()-1],s[s.size()-2])])return 0;
		m[func(s[s.size()-1],s[s.size()-2])]--;
		s += func(s[s.size()-1],s[s.size()-2]);
	}
	return 1;
}

signed main(){
	string S;
	cin >> S;
	map<char,int> m;
	FOR(i,0,S.size())m[S[i]-'a']++;
	if(!(m[0]&&m[1]&&m[2])){
		if(m[0]+m[1]+m[2]-max({m[0],m[1],m[2]})){
			YES(S.size() == 2);
			return 0;
		}
		else{
			YES(S.size() == 1);
			return 0;
		}
	}
	bool ans = 0;
	ans |= func(m[0],m[1],m[2]);
	ans |= func(m[0],m[2],m[1]);
	ans |= func(m[1],m[0],m[2]);
	ans |= func(m[1],m[2],m[0]);
	ans |= func(m[2],m[0],m[1]);
	ans |= func(m[2],m[1],m[0]);
	YES(ans);
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

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

	int m = 0;
	for (int i = n; i > 0; i--) {
		int need = xs[i];
		int have = 0;
		for (int j = i; j <= n; j += i) {
			have += xs[j];
		}
		if (need != have%2) {
			xs[i] = 1 - xs[i];
		}
		m += xs[i] == 1;
	}

	cout << m << '\n';
	for (int i = 1; i <= n; i++) {
		if (xs[i]) {
			cout << i << ' ';
		}
	}
	cout << '\n';

	return 0;
}



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

using namespace std;

typedef long long LL;
typedef pair<LL, LL> PII;
typedef vector<LL> VI;
#define rep(i , j) for (LL i = 0 , i##_end_ = j; i < i##_end_ ; ++ i)
#define For(i , j , k) for (LL i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i)
#define Fordown(i , j , k) for (LL i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define SZ(a) ((LL)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprLLf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif

inline void File() {
#ifdef hany01 
	freopen("b.in" , "r" , stdin);
    freopen("b.out" , "w" , stdout);
#endif
}

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

char c_; LL _ , __;
inline LL read() {
    for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 10000005;

LL n, a[100005], Max, Min, l, r, tmp;

int main()
{
	File();
    n = read();
    For(i, 1, n) a[i] = read();
    Max = 2; Min = 2;
    Fordown(j, n, 1) {
        tmp = Max / a[j] * a[j] - 1;
        if (tmp < Max) tmp += a[j];
        Max = tmp;
        tmp = Min / a[j] * a[j];
        if (tmp < Min) tmp += a[j];
        Min = tmp;
        if (Min > Max) { puts("-1"); return 0; }
    }
    cout << Min << ' ' << Max << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<iostream>

using namespace std;

string change1(char x){
	if(x==' ')return "101";
	if(x==',')return "000011";
	if(x=='-')return "10010001";
	if(x=='.')return "010001";
	if(x=='?')return "000001";
	if(x=='A')return "100101";
	if(x=='B')return "10011010";
	if(x=='C')return "0101";
	if(x=='D')return "0001";
	if(x=='E')return "110";
	if(x=='F')return "01001";
	if(x=='G')return "10011011";
	if(x=='H')return "010000";
	if(x=='I')return "0111";
	if(x=='J')return "10011000";
	if(x=='K')return "0110";
	if(x=='L')return "00100";
	if(x=='M')return "10011001";
	if(x=='N')return "10011110";
	if(x=='O')return "00101";
	if(x=='P')return "111";
	if(x=='Q')return "10011111";
	if(x=='R')return "1000";
	if(x=='S')return "00110";
	if(x=='T')return "00111";
	if(x=='U')return "10011100";
	if(x=='V')return "10011101";
	if(x=='W')return "000010";
	if(x=='X')return "10010010";
	if(x=='Y')return "10010011";
	if(x=='Z')return "10010000";
	return "000000";
}

string change2(string x){
	int c=0;
	for(int i=0;i<5;i++){
		c*=2;
		c+=x[i]-'0';
	}
	if(c<=25){
		string ans;
		ans+='A'+c;
		return ans;
	}
	if(c==26)return " ";
	if(c==27)return ".";
	if(c==28)return ",";
	if(c==29)return "-";
	if(c==30)return "'";
	if(c==31)return "?";
}

int main(void){
	string s;
	while(cin && getline(cin,s)){
		string str;
		for(int i=0;i<s.size();i++){
			str+=change1(s[i]);
		}
		int plus=str.size()%5;
		if(plus>0)for(int i=0;i<5-plus;i++)str+="0";
		string res;
		for(int i=0;i<str.size()/5;i++){
			string ss;
			for(int j=0;j<5;j++)ss+=str[i*5+j];
			res+=change2(ss);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=200005;
long long n,N;
long long a[MAXN];
bool check(long long mid)
{
	for(long long i=0;i<n-1;i++)
	{
		long long s0=0,s1=0;
		if(a[n-i]>=mid&&a[n-i-1]>=mid)
			s1++;
		if(a[n-i]<mid&&a[n-i-1]<mid)
			s0++;
		if(a[n+i]>=mid&&a[n+i+1]>=mid)
			s1++;
		if(a[n+i]<mid&&a[n+i+1]<mid)
			s0++;
		if(s1)
			return 1;
		if(s0)
			return 0;
	}
	return a[1]>=mid;
}
int main()
{
	//freopen("mid.in","r",stdin);
	//freopen("mid.out","w",stdout);
	scanf("%lld",&n);
	N=2*n-1;
	for(long long i=1;i<=N;i++)
	{
		scanf("%lld",&a[i]);
	}
	long long l=2,r=N,ans=1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid;
			l=mid+1;
		}
		else
			r=mid-1;
	}
	printf("%lld\n",ans);
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 1664
#include <iostream>
#include <map>
using namespace std;

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

    map<int, int> mp;
    int a;
    for(int i=0; i<n; i++){
        cin >> a;
        if(mp.count(a) == 0){
            mp[a] = 1;
        }else{
            mp[a]++;
        }
    }
    int num = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        if(itr->first > itr->second){
            num += itr->second;
        }else{
            num += itr->second - itr->first;
        }
    }
    cout << num << endl;
  
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

const ll N=100005ll;
ll l[N],r[N],p[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll d;
    for(int i=1;i<=n;i++){
        cin>>d;
        p[d]=i;
        l[i]=i-1;
        r[i]=i+1;
    }
    ll ans=0;
    for(int i=1;i<n;i++){
        ll a=l[p[i]];
        ll b=l[a];
        ll c=r[p[i]];
        ll d=r[c];
        if(a!=0)ans+=(a-b)*(c-p[i])*i;
        if(c!=n+1)ans+=(d-c)*(p[i]-a)*i;
        l[c]=a;
        r[a]=c;
    }
    cout<<ans<<"\n";
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(string s){
	string t,ans;
	cin>>t;
	int cnt=0,pos=0;
	vs sa,sb,ta,tb;
	rep(i,s.size()){
		if(s[i]=='"'){
			sa.push_back(s.substr(pos,i-pos));
			range(j,i+1,s.size()){
				if(s[j]=='"'){
					sb.push_back(s.substr(i+1,j-i-1));
					pos=j+1;
					i=j;
					j=s.size();
				}
			}
		}
	}
	sa.push_back(s.substr(pos,s.size()-pos));
	pos=0;
	rep(i,t.size()){
		if(t[i]=='"'){
			ta.push_back(t.substr(pos,i-pos));
			range(j,i+1,t.size()){
				if(t[j]=='"'){
					tb.push_back(t.substr(i+1,j-i-1));
					pos=j+1;
					i=j;
					j=t.size();
				}
			}
		}
	}
	ta.push_back(t.substr(pos,t.size()-pos));
	ans="IDENTICAL";
	if(sb.size()!=tb.size())ans="DIFFERENT";
	else{
		rep(i,sb.size())if(sb[i]!=tb[i])cnt++;
		if(cnt>1)ans="DIFFERENT";
		if(cnt==1)ans="CLOSE";
	}
	if(sa.size()!=ta.size())ans="DIFFERENT";
	else{
		rep(i,sa.size())if(sa[i]!=ta[i])ans="DIFFERENT";
	}
	cout<<ans<<endl;
	
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s,s!=".")solve(s);
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
typedef pair<int,int>P;
int n;
vector<P>e[19];

int dfs(int k,int bits){
  if(k==n){
    bool f=true;
    int cnt=0;
    rep(i,n){
      if(!((bits>>i)&1))continue;
      rep(j,e[i].size()){
        int x=e[i][j].fi;
        int y=e[i][j].se;
        if(y!=((bits>>x)&1)){
          f=false;
        }
      }
      cnt++;
    }
    if(!f)cnt=0;
    return cnt;
  }
  int rec=dfs(k+1,bits);
  rec=max(rec,dfs(k+1,bits|(1<<k)));
  return rec;
}

int main(){
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    rep(j,a){
      int x,y;
      cin>>x>>y;
      x--;
      e[i].push_back(P(x,y));
    }
  }

  cout<<dfs(0,0)<<endl;

  return(0);
}


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

int main(){    
  string S;
  cin >> S;
  int Ans = 0;
  int N = S.size();
  if(N%2 == 0){
    for(int i = 0; i < N/2; i++){
      if(S.at(2*i) == 'R' || S.at(2*i) == 'U' || S.at(2*i) == 'D') Ans++;
      if(S.at(2*i+1) == 'L' || S.at(2*i+1) == 'U' || S.at(2*i+1) == 'D') Ans++;
    }
  }
  else{
    for(int i = 0; i < N/2; i++){
      if(S.at(2*i) == 'R' || S.at(2*i) == 'U' || S.at(2*i) == 'D') Ans++;
      if(S.at(2*i+1) == 'L' || S.at(2*i+1) == 'U' || S.at(2*i+1) == 'D') Ans++;
    }
    if(S.at(N-1) == 'R' || S.at(N-1) == 'U' || S.at(N-1) == 'D') Ans++;
  }
  if(Ans == N) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int h, m, s, t;
	while(scanf("%d%d%d", &h, &m, &s), h>=0 && m>=0 && s>=0){
		t = 7200 - (h*3600+m*60+s);
		printf("%02d:%02d:%02d\n", t/3600, t/60%60, t%60);
		t *= 3;
		printf("%02d:%02d:%02d\n", t/3600, t/60%60, t%60);
	}
	return 0;
}

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


int main(){
  
  int N;
  cin >>N;
  vector<pair<pair<string,int>,int>> v(N);
  
  for (int i=0;i<N;i++){
    cin>>v.at(i).first.first>>v.at(i).first.second;
    v.at(i).first.second=100-v.at(i).first.second;
    v.at(i).second=i;
  }
  sort(v.begin(),v.end());
  
  for (int i=0;i<N;i++){
    cout<<v.at(i).second+1<<endl;
  }
  
}
  

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int sum=-n;
    for(int i=0;i<n;i++){
      sum+=sc.nextInt();
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 25936
#include<bits/stdc++.h>
using namespace std;
vector<string>grid;
bool removed[105];
int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0; i<h; i++){
		string s;
		cin>>s;
		bool all_white = true;
		for(int j=0; s[j]; j++){
			if(s[j]=='#') all_white = false;
		}
		if(!all_white) grid.push_back(s);
	}
	for(int i=0; i<w; i++){
		bool all_white = true;
		for(int j=0; j<grid.size(); j++){
			if(grid[j][i]=='#') all_white = false;
		}
		if(all_white) removed[i] = true;
	}
	for(int i=0; i<grid.size(); i++){
		for(int j=0; j<w; j++){
			if(removed[j]==false) cout<<grid[i][j];
		}
		cout<<'\n';
	}
}

Measured memory_bytes: 3596
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
long long int N,M,Q,K,res=0,a[200],b[200],c[200],d[200];
string S;
long long int A,B;


int main()
{
    cout << fixed << setprecision(18);
    cin>>A>>B>>N;
    if(N>=B-1){
        cout<<(A*(B-1))/B<<endl;
    }else{
        cout<<(A*N)/B<<endl;
    }
    
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int L,R;
    cin >> L >> R;
    int t=L+4038;
    int a=2019;
    R=min(t,R);
    for(ll i=L; i<=R; i++){
        for(ll j=i+1; j<=R; j++){
            int ans=i*j%2019;
            if(ans<a){
                a=ans;
            }
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
# seishin.py
from collections import deque
N = int(input())
*P, = map(int, input().split())
MOD = 10**9 + 7

G = [[] for i in range(N+1)]
U = [0]*(N+1)
C = [0]*(N+1)
for i, p in enumerate(P):
    G[p].append(i+1)
    U[i+1] = u = U[p]+1
    C[u] += 1
Q = [None]*(N+1)
PP = {}
def pp(k):
    if k not in PP:
        PP[k] = p = pow(2, k, MOD)
        return p
    return PP[k]
L = [0]*(N+1)

ept = []
sz = L.__getitem__
for i in range(N, -1, -1):
    g = G[i]
    if not g:
        continue

    # 子ノードのdequeを集める
    g.sort(key=sz, reverse=1)
    k = len(g)
    e = [pp(k) - k, k, 0]

    g0 = g[0]
    L[i] = L[g0] + 1
    if L[g0] == 0:
        Q[i] = deque([e])
        continue
    Q[i] = R = Q[g0]
    if k > 1:
        # a0 <- a2
        for s, r in zip(Q[g[1]] or ept, R):
            r[0] += r[2]; r[2] = 0

        for j in g[1:]:
            S = Q[j]
            if not S:
                break

            # dequeの小さい方から大きい方へマージする処理
            for (a0, a1, a2), r in zip(S, R):
                b0, b1, b2 = r; a0 += a2
                r[0] = a0*b0 % MOD
                r[1] = (a0*b1 + a1*b0) % MOD
                r[2] = ((a0+a1)*b2 + a1*b1) % MOD
    R.appendleft(e)
print((pp(N) + sum(pp(N+1-c) * a1 % MOD for (a0, a1, a2), c in zip(Q[0], C[1:]))) % MOD)


Measured memory_bytes: 139972
#include<cstdio>
int main(){
	int l,n;
	scanf("%d%d",&n,&l);
	int ans=(2*l+n-1)*n/2;
	if(l>0)ans=ans-l;
	if(l+n-1<0)ans=ans-(l+n-1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,b,f,r,v;
    cin >> n;
    int count[5][4][11];
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                count[i][j][k]=0;
            }
        }
    }
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        count[b][f][r]+=v;
    }
    
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                cout << " "<< count[i][j][k];
            }
            cout << endl;
        }
      if(i==4){
        break;
      }
        cout << "####################" << endl;
    }
}


Measured memory_bytes: 3088
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// It's something that is not good
// & i'm trying right just nothing
// dont't know what god is upto
// but i shall tryna make it come.
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define el "\n"

ll tests=1;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //cin>>tests;
    while(tests--){
        ll k; cin>>k;
        ll p_md=7%k;
        if(p_md==0){
        	cout<<1<<el;
        	return 0;
        }
        ll ans=1;
        ll n=7;
        ll flg=0;
        while(n<k){
        	if(p_md==0){
        		flg=1; goto l;
        	}
        	n=n*10+7;
        	p_md=n%k;
        	ans++;
        }
        for(int i=0;i<=k;i++){
        	if(p_md==0){
        		flg=1; break;
        	}
        	p_md=p_md*10+7;
        	p_md%=k;
        	ans++;
        }
        l:
        if(flg==1)
        	cout<<ans<<el;
        else cout<<-1<<el;
    }
}

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


using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
 
int N, M;
map<pair<int, int>, int> stnid;
int idlast;
vector<pair<int, int> > graph[606060];
bool vis[606060];
 
void ae(int p, int q, int c, int d)
{
	graph[p].push_back({ q, c });
	graph[q].push_back({ p, d });
}
 
int getid(int stn, int cmp)
{
	if (stnid.count({ stn, cmp })) return stnid[{stn, cmp}];
	int ret = idlast++;
	ae(stn, ret, 1, 0);
	return stnid[{stn, cmp}] = ret;
}
 
int main()
{
	scanf("%d%d", &N, &M);
	idlast = N;
	for (int i = 0; i < M; ++i) {
		int p, q, c;
		scanf("%d%d%d", &p, &q, &c);
		--p; --q;
 
		int a = getid(p, c);
		int b = getid(q, c);
		ae(a, b, 0, 0);
	}
 
	priority_queue<pair<int, int> > Q;
	for (int i = 0; i < idlast; ++i) vis[i] = false;
	Q.push({ 0, 0 });
	while (!Q.empty()) {
		pair<int, int> tmp = Q.top(); Q.pop();
		int cost = -tmp.first;
		int pt = tmp.second;
		if (vis[pt]) continue;
		vis[pt] = true;
		if (pt == N - 1) {
			printf("%d\n", cost);
			return 0;
		}
		for (auto e : graph[pt]) {
			Q.push({ -(cost + e.second), e.first });
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 60152
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
const int maxn = 1e6 + 10;
const int INF = 1e9;
char a[maxn], s[maxn];
int h, w, k, sx, sy, tx, ty;
int fa[4][maxn];
int dis[maxn];
const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};
int getfa(int d, int x)
{
	if(x == -1) return -1;
	return x == fa[d][x] ? x : fa[d][x] = getfa(d, fa[d][x]);
}
void e(int i, int j)
{
	int x = i * w + j;
	for(int d = 0; d < 4; ++d)
	{
		if(0 <= i + dx[d] && i + dx[d] < h && 0 <= j + dy[d] && j + dy[d] < w) 
			fa[d][x] = getfa(d, (i + dx[d])* w + j + dy[d]);
		else 
			fa[d][x] = -1;
	}
}
void bfs()
{
	queue<int> Q;
	dis[sx * w + sy] = 0;
	Q.push(sx * w + sy);
	e(sx, sy);
	while(!Q.empty())
	{
		int x = Q.front(); Q.pop();
		int i = x / w, j = x % w;
		for(int d = 0; d < 4; ++d)
		{
			int curi = i, curj = j, nxt;
			while(0 <= curi + dx[d] && curi + dx[d] < h && 0 <= curj + dy[d] && curj + dy[d] < w && 
				(nxt = getfa(d, (curi + dx[d]) * w + curj + dy[d])) != -1)
 			{
 				curi = nxt / w;
 				curj = nxt % w;	
 				if(abs(curi - i) + abs(curj - j) > k) break;
				e(curi, curj);
				dis[curi * w + curj] = dis[x] + 1;
				Q.push(curi * w + curj);
			}
		}
	}
	int ans = dis[tx * w + ty];
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}
int main()
{
	scanf("%d%d%d", &h, &w, &k);
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	--sx; --sy; --tx; --ty;
	for(int i = 0; i < h; ++i)
	{
		scanf("%s", s);
		for(int j = 0; j < w; ++j)
			a[i * w + j] = s[j];
	}
	for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j)
		{
			dis[i * w + j] = INF;
			for(int d = 0; d < 4; ++d)
				fa[d][i * w + j] = a[i * w + j] == '.' ? i * w + j : -1;
		}
	bfs();
	return 0;
}

Measured memory_bytes: 25172
#include<stdio.h>
int main(){
  int A[100];
  int i,j,flag,a,b;
  int N,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  flag=1;
  i=0;
  while(flag==1){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(A[j]<A[j-1]){
	a=A[j];
	A[j]=A[j-1];
	A[j-1]=a;
	flag=1;
	count++;
      }
      i++;
    }
  }
  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}


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



int split(int x){
	if(x%2==1){
		return 0;
	}else{
		return x /2;
	}
}



int main(){
	//int a;
	int count =0;
	int endflg =0;
	int n;
	cin >> n;
	vector<int> a(n);
	


	// atを使って1つずつ入力
	for(int i=0;i<n;i++){
		cin >> a[i];
	}


	for(int j =0;j<100;j++){

		for(int i=0;i<n;i++){
			if(split(a[i]) != 0){
			a[i] = split(a[i]);
			}else{
				endflg = 1;
				break;
			}
		}
	
		if(endflg == 0){
			count = count + 1;
		}else{
			break;
		}
		

	}
	
	cout << count;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s,a="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
	cin>>n>>s;
	for (int i=0;i<s.size();i++) s[i]=a[s[i]-'A'+n];
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
dp = [-1]*N


def dfs(n):
    global dp
    if dp[n] > 0:
        return dp[n]

    ma = 0
    for b in G[n]:
        ma = max(ma, dfs(b) + 1)
    dp[n] = ma
    return ma


def main():
    global dp
    for i in range(N):
        dp[i] = dfs(i)
    print(max(dp))


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int x, y;
    cin >> x >> y;
    // x = a+b;
    // y = 2*a + 4*b
    // y - 2*x = 2b;

    int b2 = y - 2*x;
    if (b2%2 || b2 < 0 || b2/2 > x)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int h,w;
int s[200][200];

class WarshallFloyd{
    public:
        vector<vector<int>> d;
        WarshallFloyd(vector<vector<int>> g) : d(g){
            int V=g.size();
            for(int i=0;i<V;i++) d[i][i]=0;

            for(int k=0;k<V;k++)
                for(int i=0;i<V;i++)
                    for(int j=0;j<V;j++)
                        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }

        int get(int i,int j){
            return d[i][j];
        }
};

int main(){
    cin >> h >> w;
    vector<vector<int>> g(10,vector<int>(10));
    rep(i,10) rep(j,10) cin >> g[i][j];

    WarshallFloyd c(g);
    ll ans = 0;
    rep(i,h) rep(j,w){
        int a;cin>>a;
        if(a==-1) continue;
        ans += c.get(a,1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; 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();
    string s; cin >> s;
    ll ans = 0;
    rep(i, s.size()){
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
 
void Str0(char s[])
{
    int len;
    int i;
    char *p;
     
    s[9999] = '\0';
    len = strlen(s);
    p = s;
    for (p += 9999; p >= s; p--){
        if (len >= 0){
            *p = s[len];
            len--;
        }
        else {
            *p = '0';
        }
    }
}
 
void Kuriagari(int j, char a[], char b[], char sum[])
{
    char *p;
     
    p = sum + j - 1;/*1をたす桁を指定*/
     
    *(p) += 1;
    if (*(p) == ':'){
        *(p) = '0';
        Kuriagari(j - 1, a, b, sum);
    }
}
 
int main(void)
{
    char a[10000], b[10000], sum[10000];
    int len;
    int n;
    int i, j;
    char *p;
    int flag;
     
    scanf("%d", &n);
     
    for (i = 0; i < n; i++){
        flag = 0;
         
        /*0詰めで文字列を入力*/
        scanf("%s", a);
        if (strlen(a) > 80){
            flag = 1;
        }
        Str0(a);
         
        scanf("%s", b);
        if (strlen(b) > 80){
            flag = 1;
        }
        Str0(b);
         
         
        if (flag == 1){
            printf("overflow\n");
        }
        else {
            /*繰り上がり処理*/
            for (j = 0; j < 9999; j++){
                sum[j] = ((a[j] - '0') + (b[j] - '0')) % 10;/*筆算する*/
                if (((a[j] - '0') + (b[j] - '0')) / 10 >= 1){/*もし繰り上がりが発生したら*/
                    /*printf("test:%c\n", sum[j - 1]);*/
                    Kuriagari(j, a, b, sum);/*繰り上がり処理*/
                    /*printf("test:%c\n", sum[j - 1]);*/
                }
                sum[j] += '0';
            }
            sum[9999] = '\0';
             
             
            p = sum;
            while (*p == '0'){
                p++;
            }
            /*printf("%d\n", *p);*/
            if (strlen(p) == 0){
                printf("0\n");
            }
            else if (strlen(p) <= 80){
                printf("%s\n", p);
            }
            else {
                printf("overflow\n");
            }
        }
    }
     
    return (0);
}

Measured memory_bytes: 616