akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
	long long int a,m[100005]={0},i;
	m[0]=2;
	m[1]=1;
	scanf("%d",&a);
	for(i=2;i<=a;i++)
	{
		m[i]=m[i-1]+m[i-2];
	}
	printf("%lld",m[a]);
	return 0;
}

Measured memory_bytes: 896
n, k = map(int, input().split())
a = [int(i)-1 for i in input().split()]

p = 0

if n>=k:
    for i in range(k):
        p = a[p]
    print(p+1)

else:
    lst = [-1]*n
    lst[0] = 0
    
    for i in range(1,n+1):
        p = a[p]
        if lst[p] == -1:
            lst[p] = i
        else:
            loop = i - lst[p]
            k -= lst[p]
            extra = k % loop
            break

    for i in range(extra):
        p = a[p]
    print(p+1)

Measured memory_bytes: 32108
#include <stdio.h>
 
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        if(i%3 == 0)
            printf(" %d", i);
        else {
            int j = i;
            while(j > 0) {
                if(j%10 == 3) {
                    printf(" %d", i);
                    break;
                }
                j /= 10;
            }
        }
    puts("");
}



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

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll dp[n];
    for(ll i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<=i+k && j<n;j++)
        {
            dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#define lf (x<<1)
#define rg (lf^1)
#define ll long long
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=1e5+5;
int n,k,i,a[N],b[N];
ll ans,sum[N],dp[N];
int cn,id,tmp[N*2],seg[N*4],L[N],R[N];
ll mo(ll x) {
	return (x%k+k)%k;
}
void pushdown(int x) {
	if (!seg[x]) return ;
	seg[lf]=seg[x]; seg[rg]=seg[x]; seg[x]=0;
}
void updata(int x,int l,int r,int L,int R,int val)
{
	if (r<L || l>R) return;
	if (L<=l && r<=R) {
		seg[x]=val; return ;
	}
	int mid=(l+r)>>1;
	pushdown(x);
	updata(lf,l,mid,L,R,val);
	updata(rg,mid+1,r,L,R,val);
}
void query(int x,int l,int r,int pos)
{
	if (seg[x]) {
		id=seg[x]; return ;
	}
	if (l==r) return ;
	int mid=(l+r)>>1;
	if (pos<=mid) query(lf,l,mid,pos);
	else query(rg,mid+1,r,pos);
}
ll ask(int x)
{
	id=0; query(1,1,cn,x);
	if (!id) return 0;
	return dp[id]+((ll)tmp[L[id]]-tmp[x]+k)%k;
}
int main()
{
//	freopen("train.in","r",stdin);
//	freopen("train.out","w",stdout);
	scanf("%d%d",&n,&k);
	rep(i,1,n) scanf("%d%d",&a[i],&b[i]);
	rep(i,1,n) {
		sum[i]=sum[i-1]+a[i];
		if (b[i]==1) {
			if (a[i]*2>k) { printf("-1\n"); return 0; }
			R[i]=mo(-2*sum[i]);
			L[i]=mo(-2*sum[i-1]);
		}
		else L[i]=0,R[i]=k-1;
	}
	rep(i,1,n) tmp[++cn]=L[i],tmp[++cn]=R[i];
	sort(tmp+1,tmp+1+cn);
	cn=unique(tmp+1,tmp+1+cn)-tmp-1;
	down(i,n,1)
	{
		L[i]=lower_bound(tmp+1,tmp+1+cn,L[i])-tmp;
		R[i]=lower_bound(tmp+1,tmp+1+cn,R[i])-tmp;
	//	printf("%d %d\n",L[i],R[i]);
		dp[i]=ask(L[i]);
		if (L[i]<=R[i]) {
			if (L[i]>1) updata(1,1,cn,1,L[i]-1,i);
			if (R[i]<cn) updata(1,1,cn,R[i]+1,cn,i);
		}
		else if (L[i]-R[i]>1) updata(1,1,cn,R[i]+1,L[i]-1,i);
	}
	ans=dp[1];
//	rep(i,1,n) printf("%I64d ",dp[i]); printf("\n");
	rep(i,1,cn) ans=min(ans,ask(i));
	ans+=2*sum[n];
	printf("%lld\n",ans);
	return 0;
}

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


int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(n%2==0){
        if(s[0]==s[n-1]){
            cout<<"First"<<endl;
            return 0;
        }
        else{
            cout<<"Second"<<endl;
            return 0;
        }
    }
    else {
        if(s[n-1]==s[0]){
            cout<<"Second"<<endl;
            return 0;
        }
        else {
            cout<<"First"<<endl;
            return 0;
        }
    }

}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e5+10;
int n, a[N];
multiset<int> s;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), s.insert(a[i]);
    for (int i = 3; i <= n; ++i) if(a[i] != a[1]) swap(a[i], a[2]);
    int x = a[1], y = a[2], st = x;
    s.erase(s.find(x)); s.erase(s.find(y));
    for (int i = 3; i <= n; ++i) {
        int nx = x^y;
        if(s.find(nx) == s.end()) return 0*puts("No");
        else {
            s.erase(s.find(nx));
            x = y;
            y = nx;
        }
    }
    if((x^y) != st) return 0*puts("No");
    puts("Yes\n");
    return 0;
}


Measured memory_bytes: 5376
b = input()
max_len = 0
cnt = 0
for it in b:
    if it == 'A' or it=='T' or it=='C' or it=='G':
        cnt+=1
    else:
        if cnt != 0 and max_len < cnt:
            max_len = cnt
        cnt = 0
    
if cnt != 0 and max_len < cnt:
    max_len = cnt
    
print(max_len)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int k;
    cin>>k;
    long long sum=0;
    for(int i=1; i<=k; i++)
    {
        for(int x=1; x<=k; x++)
        {
            for(int j=1; j<=k; j++)
            {
                int cj=j, cx=x, ci=i;
                int gcd=1;
                while (j != 0)
                {
                    gcd = x % j;
                    x = j;
                    j = gcd;
                }
                int r=1;
                while (x != 0)
                {
                    r = i % x;
                    i = x;
                    x = r;
                }
                sum+=i;
                j=cj;
                x=cx;
                i=ci;
            }
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    int aMin = INF;
    int diffMax = -INF;
    int cnt = 0;
    for(int i=0; i<n; ++i){
        int diff = a[i] - aMin;
        if(diff == diffMax){
            ++ cnt;
        }
        else if(diffMax < diff){
            diffMax = diff;
            cnt = 1;
        }
        aMin = min(aMin, a[i]);
    }
    cout << cnt << endl;

    return 0;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int H,W,N;
	cin>>H>>W>>N;

    int ans = 0;
    int s = 0;
    while(s<N){
        if(H>W){
            s+=H;
        }else{
            s+=W;
        }
        ans=ans +1;
    }
    cout<<ans<<"\n";
	
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int res,ll,rr,uu,dd,ad,R,L,D,U,sx,sy,h,w,pr[105][105],pc[105][105],dp[105][105][105];
char s[105][105];
int main()
{
    scanf("%d%d",&h,&w);
    for (int i=1;i<=h;++i)
        scanf("%s",s[i]+1);
    for (int i=1;i<=h;++i)
        for (int j=1;j<=w;++j) {
            pr[i][j]=pr[i-1][j]+(s[i][j]=='o');
            pc[i][j]=pc[i][j-1]+(s[i][j]=='o');
            if (s[i][j]=='E')
                sx=i,sy=j;
        }
    memset(dp,-1,sizeof dp);
    dp[0][0][0]=0;
    L=sy-1,R=w-sy,U=sx-1,D=h-sx;
    for (int l=0;l<=L;++l)
        for (int r=0;r<=R;++r)
            for (int u=0;u<=U;++u)
                for (int d=0;d<=D;++d) {
                    if (dp[r][u][d]==-1)
                        continue;
                    rr=min(sy+r,w-l);
                    ll=max(sy-l,r+1);
                    uu=max(sx-u,d+1);
                    dd=min(sx+d,h-u);
                    res=max(res,dp[r][u][d]);
                    if (l+r<R) {
                        ad=pr[dd][sy+r+1]-pr[uu-1][sy+r+1];
                        dp[r+1][u][d]=max(dp[r+1][u][d],dp[r][u][d]+ad);
                    }
                    if (u+d<U) {
                        ad=pc[sx-u-1][rr]-pc[sx-u-1][ll-1];
                        dp[r][u+1][d]=max(dp[r][u+1][d],dp[r][u][d]+ad);
                    }
                    if (u+d<D) {
                        ad=pc[sx+d+1][rr]-pc[sx+d+1][ll-1];
                        dp[r][u][d+1]=max(dp[r][u][d+1],dp[r][u][d]+ad);
                    }
                    if (l+r<L) {
                        ad=pr[dd][sy-l-1]-pr[uu-1][sy-l-1];
                        dp[r][u][d]=max(dp[r][u][d],dp[r][u][d]+ad);
                    }
                }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 4736
n = int(input())
s = input()
l = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
for i in range(len(s)):
    for j in range(len(l)):
        if s[i] == l[j]:
            print(l[(j+n)%26], end="")
            break
print()

Measured memory_bytes: 44252
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn gcd(x: i32, y: i32) -> i32 {
    match y {
        0 => x,
        y => gcd(y, x % y)
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let c: i32 = sc.read();
    let g = gcd(a, b);
    match c % g == 0 {
        true => println!("YES"),
        false => println!("NO"),
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

}

Measured memory_bytes: 26516
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

ll N,W;
ll w[101], v[101];
ll dp[101][100001];

int main(){
    cin>>N>>W;
    repn(i,N) cin>>w[i]>>v[i];

    repn(i,N){
        repn(j,W){
            if(j<w[i]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
    }

    ll ans=0;
    repn(i,W) ans=max(ans,dp[N][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 81708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    rep(i,h)cin>>a[i];
    vector<bool> r(h,false), c(w,false);
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#'){
                r[i]=true;
                c[j]=true;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(r[i]&&c[j])cout<<a[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int div2(int a){
    int res = 0;
    while(a%2==0){
        res++;
        a/=2;
    }
    return res;
}

int main(){
    vector<int> a(3);
    REP(i,3){
        cin >> a[i];
    }
    SORT(a);
    vector<int> d(2);
    REP(i,2){
        d[i] = a[i+1]-a[i];
    }
    if(a[0]%2!=0||a[1]%2!=0||a[2]%2!=0){
        put(0);
    }else if(d[0]==0&&d[1]==0){
        put(-1);
    }else{
        int res = INT_MAX;
        REP(i,2){
            chmin(res,div2(d[i]));
        }
        put(res);
    }
    return 0;
}


Measured memory_bytes: 256
//ITP1_8_C

#include <stdio.h>

int main(){

	int i;
	int alp[26];
	int p,q;
	char r;

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

Measured memory_bytes: 540
# coding: utf-8
# Your code here!
H,W=map(int,input().split())


def bfs(h,w,n):
    yoyaku=[]
    if h>0:
        if lis[h-1][w]>n+1 and mp[h-1][w]!="#":
            yoyaku.append([h-1,w,n+1])
    if w>0:
        if lis[h][w-1]>n+1 and mp[h][w-1]!="#":
            yoyaku.append([h,w-1,n+1])
    if h<H-1:
        if lis[h+1][w]>n+1 and mp[h+1][w]!="#":
            yoyaku.append([h+1,w,n+1])
    if w<W-1:
        if lis[h][w+1]>n+1 and mp[h][w+1]!="#":
            yoyaku.append([h,w+1,n+1])
    
    lis[h][w]=min(n,lis[h][w])
    return yoyaku

    

mp=[]
for _ in range(H):
    mp.append(list(input()))

ans=[]

for h in range(H):
    for w in range(W):
        lis=[[1000]*W for i in range(H)]
        que=[[[h,w,0]]] if mp[h][w]!="#" else []
        while True:
            if len(que)==0:
                break
            else:
                temp=que.pop(-1)
                #print(temp)
                for tem in temp:
                    
                    que.append(bfs(tem[0],tem[1],tem[2]))
        
        pre=0
        for item in lis:
            for tem in item:
                if tem==1000:
                    continue
                pre=max(pre,tem)    
        ans.append(pre)

    
print(max(ans))



Measured memory_bytes: 121196
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)

using namespace std;

const int N = 200000;
int64_t ary[N + 1];
map<int64_t, int> cnt;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  ary[0] = 0;
  for (int i = 0; i < n; i++) {
    int64_t a;
    scanf("%lld", &a);
    ary[i + 1] = (ary[i] + a - 1) % k;
  }
  cnt[0] = 1;
  int64_t ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i - k >= 0)
      cnt[ary[i - k]]--;
    ans += cnt[ary[i]];
    cnt[ary[i]] += 1;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 14336
fun main(args: Array<String>) {
    readLine()!!
    var a = 0
    var b = 0
    readLine()!!.split(' ')
        .map(String::toInt)
        .sortedDescending()
        .forEachIndexed { i, e -> if (i and 1 == 0) a += e else b += e }
    println(a - b)
}


Measured memory_bytes: 38212
def main():
    H, W, M = map(int, input().split())
    cnth = [[0, i] for i in range(H)]
    cntw = [[0, i] for i in range(W)]
    L = set()
    for _ in range(M):
        h, w = map(lambda x: int(x) - 1, input().split())
        cnth[h][0] += 1
        cntw[w][0] += 1
        L.add((h, w))
    cnth.sort(reverse=True)
    cntw.sort(reverse=True)
    mh = set()
    ph = cnth[0]
    for h in cnth:
        if ph[0] == h[0]:
            mh.add(h[1])
        else:
            break
        ph = h
    mw = set()
    pw = cntw[0]
    for w in cntw:
        if pw[0] == w[0]:
            mw.add(w[1])
        else:
            break
        pw = w
    maxans = cnth[0][0] + cntw[0][0]
    for h in mh:
        for w in mw:
            if not ((h, w) in L):
                print(maxans)
                break
        else:
            continue
        break
    else:
        print(maxans - 1)
if __name__ == "__main__":
    main()

Measured memory_bytes: 228900
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt()*100;
		int b = in.nextInt()*100;
		int c = in.nextInt();
		int d = in.nextInt();
		int e = in.nextInt();
		int f = in.nextInt();
		Set<Integer> waters = new HashSet<>();
		int aMax = f/a;
		for(int i=0;i<=aMax;i++) {
			int bMax = (f-a*i)/b;
			for(int j=0;j<=bMax;j++) {
				if(i==0 && j==0) continue;
				waters.add(a*i+b*j);
			}
		}
		
		int ansWater = 0;
		int ansSugar = 0;
		
		double maxrate = -1;
		for(int water:waters) {
			int sugarCapacity = Math.min(f-water, water*e/100);
			int cMax = sugarCapacity/c;
			for(int i=0;i<=cMax;i++) {
				int dMax = (sugarCapacity-c*i)/d;
				double rate = ((double)(c*i+d*dMax))/(water+c*i+d*dMax);
				if(rate>maxrate) {
					maxrate = rate;
					ansWater = water;
					ansSugar = c*i+d*dMax;
				}
			}
		}
		
		System.out.println((ansWater+ansSugar)+" "+ansSugar);
		in.close();
	}

}


Measured memory_bytes: 23124
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
int N;
bool a[10000000];
int main(void) {
	cin >> N;
	int j = 0;
	while (N!=0) {
		a[j]=true;
		N -= (j + 1);
		if (N < 0) {
			a[-N-1] = false;
			N = 0;
			break;
		}
		j++;
	}
	for (int i = 0; i < 10000000; i++) {
		if (a[i]==true)cout << i + 1 << endl;
	}
	return 0;
}

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

int s[1000], d[1000], y[1000];
P p[100000];
int main() {
	int n, m, h, k;
	while (cin >> n >> m >> h >> k, n) {
		rep(i, n)cin >> s[i];
		rep(i, m) {
			int a, b; cin >> a >> b;
			p[i] = { b,a };
		}
		sort(p, p + m); iota(d, d + n, 0);
		rep(i, m) {
			swap(d[p[i].second - 1], d[p[i].second]);
			p[i] = { d[p[i].second - 1],d[p[i].second] };
			if (p[i].first > p[i].second)swap(p[i].first, p[i].second);
		}
		rep(i, n)y[d[i]] = s[i];
		int M = accumulate(y, y + k, 0); int S = M;
		rep(i, m) {
			if (p[i].first < k&&p[i].second >= k)
				M = min(M, S + y[p[i].second] - y[p[i].first]);
		}
		cout << M << endl;
	}
}

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

#define ll long long
#define pb push_back
#define F first
#define S second

ll inf =1e16+10;
const int N=3e3+5, L = 7;
int n, k;
int mem[N][N];
string s, t;

int dp(int i, int j)
{
    if (i == n || j == k)
        return 0;

    int &ret = mem[i][j];
    if (ret != -1)
        return ret;

    int p1 = 0, p2 = 0, p3 = 0;
    //cout<<i<<" "<<j<<"\n";
    if (s[i] == t[j])
        p1 = 1+dp(i+1, j+1);


    else
    {
        p2 = dp(i+1, j);
        p3 = dp(i, j+1);
    }
    return ret = max({p1, p2, p3});
}

int solve(int i, int j , int cnt)
{
    if (i == n || j == k)
        return 0;

    for (int r = i ; r<n; r++)
    {
        for (int d = j ; d<k; d++)
        {
            if (mem[r][d] == cnt && s[r] == t[d])
            {
                cout<<s[r] ;
                solve(r+1, d+1 , cnt-1);
                return 0;

            }
        }
    }
    return 0;
}

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s >>t;
    n = s.size();
    k = t.size();

    memset(mem, -1, sizeof mem);
    int y = dp(0, 0);
    for (int i = 0;i<=k;i++)
        mem[n][i] = 0;
    for (int i = 0;i<=n;i++)
        mem[i][k] = 0;
   //cout<<y<<"\n";
    solve(0,0 , y);
}


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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    int N,M;
    cin >> N >> M;

    vector<pair<int,int>> sc(M);

    repo(i,M) {
        cin >> sc[i].first >> sc[i].second;
    }
    
    repo(x,1000){
        int nx = x/10;
        vector<int> d(1,x%10);

        while(nx){
            d.push_back(nx%10);
            nx = nx/10;
        }
        if(d.size()!= N) continue;     
        reverse(d.begin(),d.end());
        bool ok = true;
        repo(i,M) {
            if(d[sc[i].first -1] != sc[i].second){
                ok = false;
            }
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()


int main() {
    int count = 0;
    int n; cin >> n;
    int a[n];
    REP(i, n) {
        int a; cin >> a;
        while(a % 2 == 0) {
            count++;
            a /= 2;
        }
    }
    cout << count << endl;
}


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



int main(void){
    int N, nums[200010];
    cin >> N;
    
    int v;
    for ( int i = 1; i <= N; i++ ) {
        cin >> v;
        v -= i;
        nums[i] = v;
    }
    
    int d = 1e9/2;
    int base = 0;
    long long u, m, l;
    for ( int c = 0; c < 30; c++) {
        
        u = 0, m = 0, l = 0;

        for ( int i = 1; i <= N; i++ ) u += abs( nums[i]-base-d );
        for ( int i = 1; i <= N; i++ ) m += abs( nums[i]-base );
        for ( int i = 1; i <= N; i++ ) l += abs( nums[i]-base+d );
        
        if ( u < m && u < l) base += d;
        else if ( l < m && l < u) base += -d;
        d /= 2;
        
    }
    cout << m << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
vector<string>vst;
int fx[]={1,-1,0,0}; //ডিরেকশন অ্যারে
int fy[]={0,0,1,-1};
int cell[100][100]; int ans; //cell[x][y] যদি -১ হয় তাহলে সেলটা ব্লক
int d[100][100],vis[100][100]; //d means destination from source.
void bfs(int sx,int sy,int dx,int dy,int row,int col) //Source node is in [sx][sy] cell.
{
	memset(vis,0,sizeof vis);  memset(d,0,sizeof d);
	vis[sx][sy]=1;
	queue<pii>q; //A queue containing STL pairs
	q.push(pii(sx,sy));
	while(!q.empty())
	{

		pii top=q.front(); q.pop();
		for(int k=0;k<4;k++)
		{
			int tx=top.first+fx[k];
			int ty=top.second+fy[k]; //Neighbor cell [tx][ty]
			if(tx>=0 and tx<row and ty>=0 and ty<col and vst[tx][ty]!='#' and vis[tx][ty]==0) //Check if the neighbor is valid and not visited before.
			{
				vis[tx][ty]=1;
				d[tx][ty]=d[top.first][top.second]+1;    //cout<<ans<<endl;
				q.push(pii(tx,ty)); //Pushing a new pair in the queue
			}

			if(tx==dx && ty==dy){ans=d[tx][ty]; break;}
		}
	}

	while(!q.empty())
    {
        q.pop();
    }
}

int main()
{


        int n,m,a,b,c,e,f,g,p,q,r,fr,sc,tr,sz,tz,sz1,zr=0,sz2,i,j,k,mx=-9,mn=999999; string str,ttr,ntr;
        int x=0,y=0,cnt=0,res=0,ttl=0,sum=0; int flg=0,flag=1,na=0,as=1;
        vector<int>u,v,w; vector< pair<int,int> >vct,tct;
        set<int>st,nt,tt; map<string,int>mp,nq,qr,mp1; map<int,int>mmm,mp2;

        cin>>n>>m;

        for(i=0;i<n;i++){cin>>str; vst.push_back(str);}

        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(vst[i][j]=='.')
                {
                    vct.push_back(make_pair(i,j));
                }
            }
        }

        sz=vct.size(); //cout<<sz<<endl;

        for(i=0;i<sz;i++)
        {
            a=vct[i].first; b=vct[i].second;

            for(j=0;j<sz;j++)
            {
                if(i==j)
                {

                    ans=0;
                }
                else
                {

                    fr=vct[j].first; sc=vct[j].second;
                    ans=0;
                    bfs(a,b,fr,sc,n,m);
                    //cout<<a<<"  "<<b<<"     "<<fr<<" "<<sc<<"    "<<ans<<endl; cout<<endl<<endl;
                    if(ans>mx)mx=ans;
                }
            }
        }

        cout<<mx<<endl;










    return 0;
}



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

using namespace std;

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

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

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

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



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

	ll n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	ll now = 1;
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == now)
		{
			now++;
		}
		else
		{
			ans++;
		}
	}
	if (ans == n)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

bool dp[80][80][6400];

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A, B;
    for (int i = 0; i < H; i++) {
        vector<int> l;
        for (int j = 0; j < W; j++) {
            int x;
            cin >> x;
            l.push_back(x);
        }
        A.push_back(l);
    }
    for (int i = 0; i < H; i++) {
        vector<int> l;
        for (int j = 0; j < W; j++) {
            int x;
            cin >> x;
            l.push_back(x);
        }
        B.push_back(l);
    }

    memset(dp, 0, sizeof dp);
    /*
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) for (int k = 0; k < 6400; k++)
        dp[i][j][k] = false;
    */


    dp[0][0][abs(A[0][0] - B[0][0])] = true;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i == 0 && j == 0)
                continue;
            int d = abs(A[i][j] - B[i][j]);
            if (i-1 >= 0) {
                for (int k = 0; k < 6400; k++) {
                    if (dp[i-1][j][k]) {
                        int k1 = abs(k+d);
                        int k2 = abs(k-d);
                        if (k1 < 6400)
                            dp[i][j][k1] = true;
                        if (k2 < 6400)
                            dp[i][j][k2] = true;
                    }
                }
            }
            if (j-1 >= 0) {
                for (int k = 0; k < 6400; k++) {
                    if (dp[i][j-1][k]) {
                        int k1 = abs(k+d);
                        int k2 = abs(k-d);
                        if (k1 < 6400)
                            dp[i][j][k1] = true;
                        if (k2 < 6400)
                            dp[i][j][k2] = true;
                    }
                }
            }
        }
    }

    for (int k = 0; k < 6400; k++) {
        if (dp[H-1][W-1][k] == true) {
            cout << k << endl;
            return 0;
        }
    }
    return 0;
}



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

using namespace std;

int main(void)
{
	int x, y;
	cin >> x >> y;
	int a, b, c;
	cin >> a >> b >> c;
	vector<long long> p(a), q(b), r(c);
	for (int i = 0; i < a; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> q[i];
	}
	for (int i = 0; i < c; i++) {
		cin >> r[i];
	}
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());
	p.push_back(0);
	q.push_back(0);
	r.push_back(0);

	int s = 0, t = 0, u = 0;
	bool sf = true;
	bool tf = true;
	long long ans = 0;
	for (int i = 0; i < x + y; i++) {
		if (s == x && sf) {
			for (int j = 0; j < p.size(); j++) {
				p[j] = 0;
			}
			sf = false;
		}
		if (t == y && tf) {
			for (int j = 0; j < q.size(); j++) {
				q[j] = 0;
			}
			tf = false;
		}

		if (p[s] > q[t]) {
			if (p[s] > r[u]) {
				ans += p[s];
				s++;
			}
			else {
				ans += r[u];
				u++;
			}
		}
		else {
			if (q[t] > r[u]) {
				ans += q[t];
				t++;
			}
			else {
				ans += r[u];
				u++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadInts();
            WriteLine(a.Max() - a.Min());

        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
int main(void)
{
  long k,num=1;
  scanf("%ld",&k);
  
  long a = (k%7 == 0) ? 9*k/7 : 9*k;
  if(a%2 == 0 || a%5 == 0){
    puts("-1");
    return 0;
  }
  long n = 10 % a;
  
  while(1){
    if(n == 1)
      break;
    n = n * 10 % a;
    num++;
  }
  printf("%ld\n",num);
  return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr.begin(), arr.end());

    int ans = 0;
    for (int i = 0; i < k; i++) ans += arr[i];
    cout << ans << endl;
}

Measured memory_bytes: 3632
x,y = map(int,input().split())
ans = 0
num = 100**x
for i in range(1,y+1):
    if(num*i != 100**(x+1)):
        ans = num*i
    else:
        ans = num*(i+1)
        i +=1
if(y == 0):
    ans = num
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <string>

//#define _USE_MATH_DEFINES
//#include<math.h>
const double PI = 3.14159265358979323846;


using namespace std;

using ll = long long;
constexpr ll N = 2e5;
ll a[N];

int main()
{
	int R;
	cin >> R;
	
	cout << 2 * PI * R << endl;
	return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   // #ifndef ONLINE_JUDGE
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   // #endif
   string s;
   cin >> s;
   int n = s.length();
   string res = "",prv="";
   prv += s[0];
   int ans = 1;
   f(i,1,n){
      res += s[i];
      if(res != prv){
         ans++;
         // cout << res << ' ' << prv<< '\n';
         prv = res;
         res = "";
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
const int MN = 2e5+5, MOD=1e9+7;
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int BIT[MN];
int n;
int ans = 0;
void update(int idx, int val) {
  for (;idx<MN;idx+=idx&-idx) {
    BIT[idx] += val;
  }
}
int query(int idx) {
  int res = 0;
  for (;idx > 0 ;idx-=idx&-idx) {
    res += BIT[idx];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0, z; i<n;i++) {
    cin >> z;
    if (query(z) == 0) {
      ans++;
    }
    update(z, 1);
  }
  cout << ans << "\n";
  return 0;
}
//lol

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		String n=as.next();
		long l=0;
		int s,t;
		s=0;
		t=0;
		for(int i=0;i<n.length();i++){
			if(String.valueOf(n.charAt(i)).equals("A")){
				s=i;
				break;
			}
		}
		for(int i=n.length()-1;i>=0;i--){
			if(String.valueOf(n.charAt(i)).equals("Z")){
				t=i;
				break;
			}
		}
		l=t-s+1;
		System.out.println(l);
	}
}

Measured memory_bytes: 22576
n,m=map(int,input().split())
ps=[list(map(int,input().replace('WA','0').replace('AC','1').split())) for i in range(m)]
ps.sort(key=lambda x:x[0])

tmp_p=0
ac_cnt=0
wa_cnt=0
wa=0
flg=0
for i in range(m):
  p=ps[i][0]
  s=ps[i][1]
  if tmp_p!=p:
    wa=0
    flg=0
  if s==1 and flg==0:
    flg=1
    ac_cnt+=1
    wa_cnt+=wa
  elif s==0 and flg==0:
    wa+=1
  tmp_p=p
print(ac_cnt, wa_cnt)

Measured memory_bytes: 25808
n,m=list(map(int,input().split(" ")))
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split(" "))))

ab.sort()

count=0
num=0
i=0
while count<m:
    if count+ab[i][1]<=m:
        num+=ab[i][0]*ab[i][1]
        count+=ab[i][1]
        i+=1
    else:
        num+=ab[i][0]*(m-count)
        break
print(num)

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

using namespace std;

int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(a<b)
    {
        if(c<d)
        {
          cout<<a+c<<endl;
        }
        else
        {
            cout<<a+d<<endl;
        }
    }
    else
    {
       if(c<d)
        {
          cout<<b+c<<endl;
        }
        else
        {
            cout<<b+d<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    ll s;
    cin>>s;
    vector<ll> dp(s+1,0);
    dp[0]=1;
    for(ll i=3;i<=s;i++){
        for(ll j=3;j<=s;j++){
            if(i-j>=0){
                (dp[i]+=dp[i-j])%=mod;
            }
        }
    }
    cout<<dp[s]<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
string lcs(string s, string t) {
        
        int m=s.size();
        int n=t.size();
        if(m==0||n==0) return 0;
        vector<vector<int>>dp(m+1,vector<int>(n+1,0));
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
             // cout<<dp[i][j]<<" ";
            }
            // cout<<endl;
        }
        string ans="";
        int i=m;
        int j=n;
         while(1){
        if(i<1||j<1) break;
        
             
        if(s[i-1]==t[j-1]&&(dp[i][j]==dp[i-1][j-1]+1)){ans=s[i-1]+ans;i--;j--; }
             else {
                 if(dp[i][j]==dp[i-1][j]) {
                     i--;
                 }
                 else j--;
                 
             }
        
        
    }
        return ans;
        
        
    }


int main() {
	string s,t;
	cin>>s>>t;
	string ans=lcs(s,t);

	cout<<ans<<endl;


	return 0;
}
		
		

Measured memory_bytes: 38880
main = do
  (n:k:_) <- getLine >>= return . map read . words :: IO [Int]

  print $
    if k>0 then
      sum [(b-k) * (div n b) + (if mod n b >= k then mod n b - (k-1) else 0) | b <- [k+1..n]]
    else
      n*n


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, int> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


int main() {

    int n;
    ll l;
    cin >> n >> l;

    vector<ll> lopes(n);
    rep(i, n) cin >> lopes[i];

    int start = -1;
    for (int i = 1; i < n; i++) {
        if (lopes[i - 1] + lopes[i] >= l) {
            start = i - 1;
        }
    }

    if (start == -1) {
        cout << "Impossible" << endl;
        ret();
    }

    vector<int> ans;
    ans.push_back(start);
    for (int i = start - 1; i >= 0; i--) {
        ans.push_back(i);
    }
    for (int i = start + 1; i < n - 1; i++) {
        ans.push_back(i);
    }

    reverse(ans.begin(), ans.end());

    cout << "Possible" << endl;
    for (int i : ans) cout << (i + 1) << endl;


}


Measured memory_bytes: 2168
#include <stdio.h>

int fib[44];

void fibonacci(int);

int main ()
{

  int n;

  scanf("%d",&n);

  fibonacci(n);

  printf("%d\n",fib[n]);
  
  return 0;

}

void fibonacci( int n )
{
  int i = 0;

  fib[i] = fib[i+1] = 1;

  for(i = 2;i <= n; i++) fib[i] = fib[i-1] + fib[i-2];
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>

int main(void)
{
    int num_A = 0, num_B = 0, num_C = 0;
    int temp_A = 0, temp_B = 0, temp_C = 0;

    // 整数を入力
    scanf("%d%d%d", &num_A, &num_B, &num_C);

    // 整数の並び替え
    temp_A = num_A;
    temp_B = num_B;
    temp_C = num_C;

    // 箱Aと箱Bを入れ替え
    num_A = temp_B;
    num_B = temp_A;

    temp_A = num_A;
    temp_B = num_B;
    temp_C = num_C;

    // 箱Aと箱Cを入れ替え
    num_A = temp_C;
    num_C = temp_A;

    // 結果を表示
    printf("%d %d %d", num_A, num_B, num_C);

    return 0;
}

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

int main(void){
    int n,m;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    vector<string>t(m);
    for(int i=0;i<m;i++){
        cin >> t[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        int tmp = count(s.begin(),s.end(),s[i]) - count(t.begin(),t.end(),s[i]);
        if(ans < tmp) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void) {
	long long n,ans = 0;
	long long div = 1;
	scanf("%lld", &n);
	if (n % 2) printf("%d", 0);
	else {
		long long a = n / 2;
		while (a / div) {
			div *= 5;
			ans += a / div;
		}
		printf("%lld", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
const int INF = 1e9;
int n, m; 
int bmemo[160][1010];//b[y][x]
vector<pair<int, int> > b[160];//
int dp[160][1010][80];//dp[y??§?¨?][x??§?¨?][1????£???°????????£??????????????°] = ????????????????°????
int main(void){
	while(1){
		//input
		cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		rep(i, 160)rep(j, 1010) bmemo[i][j] = INF;
		rep(i, 160) b[i].clear();//?????????
		rep(i, n){
			int k; cin >> k;
			rep(j, k){//k???????????§?¨?
				int x, s; cin >> x >> s; x--;
				b[i].push_back(make_pair(x, s));
				bmemo[i][x] = s;
			}
		}

		rep(i, 160)rep(j, 1010)rep(k, 80) dp[i][j][k] = INF;
		for(auto start1 : b[0]){//???????????????????????£??????
			dp[0][start1.fi][0] = 0;
		}

		for(auto start2 : b[1]){//????????????????£???°????????£??????
			dp[1][start2.fi][1] = 0;
		}

		//??????dp
		for (int i = 0; i <  n - 1; ++i){
			for (int j = 0; j < 1010; ++j){
				for (int k = 0; k <= m; ++k){
					if(dp[i][j][k] == INF) continue;
					//??????????????£?????????
					for(auto next : b[i + 1]){
						int score = (bmemo[i][j] + next.se) * abs(j - next.fi);//?????????????????±??????
						dp[i + 1][next.fi][k] = min(dp[i + 1][next.fi][k], dp[i][j][k] + score);
					}
					if(k == m || i == n - 2) continue;
					//???????£???°????????£??????
					for(auto next : b[i + 2]){
						int score = (bmemo[i][j] + next.se) * abs(j - next.fi);//?????????????????±??????
						dp[i + 2][next.fi][k + 1] = min(dp[i + 2][next.fi][k + 1], dp[i][j][k] + score);
					}
				}
			}
		}

		//????°????????????????
		int ans = INF;
		for (int j = 0; j < 1010; ++j){//???????????????????????£??????
			for (int k = 0; k <= m; ++k){
				ans = min(ans, dp[n - 1][j][k]);
			}
		}

		for (int j = 0; j < 1010; ++j){//?????????1????£???°???????????£??????
			for (int k = 0; k <= m - 1; ++k){
			 	ans = min(ans, dp[n - 2][j][k]);
			}
		}
		cout << ans << endl;
	}
}

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

int main() {
	ll n, maxx=-10000000,minx=10000000,sum=0;

	cin >> n;
	
	for (ll i = 0; i < n; i++) {
		ll val;
		cin >> val;
		maxx = max(maxx, val);
		minx = min(minx, val);
		sum += val;
	}

	cout << minx << " " << maxx << " " << sum << endl;
		
}



Measured memory_bytes: 3096
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[] a=sc.Ia;
		long ans=0;
		Array.Sort(a);
		var pq=new Pq<int>(s[1]-1);
		for(int i = 1;i<s[1];i++) {
			pq.Push(a[i]-a[i-1]);
		}
		for(int i = s[0];i<s[1];i++) {
			ans+=pq.Top();
			pq.Pop();
		}
		
		Console.WriteLine("{0}",ans);
	}
}
public class Mo<T>:IComparable{
	public int n;
	public T d;
	public Mo(int n,T d){this.n=n;this.d=d;}
	public int CompareTo(object obj){
		Mo<T> mymo=(Mo<T>)obj;
		if(mymo.n>this.n){return -1;}
		else if(mymo.n<this.n){return 1;}
		else{return 0;}
	}
}
public class Pq<T> where T:IComparable{
	private T[] he;
	public int cnt=0;
	public Pq(int max){he=new T[max];}
	public void Push(T x){
		int j=cnt;
		while(j!=0&&Compare(x,he[(j-1)/2])>0){he[j]=he[(j-1)/2];j=(j-1)/2;}
		he[j]=x;
		cnt++;
	}
	public void Pop(){
		cnt--;
		T r=he[cnt];
		int j=0;
		while(true){
			if(j*2+1<cnt){
				if(Compare(he[j*2+1],he[j*2+2])>0){j=j*2+1;}
				else{j=j*2+2;}
			}
			else if(j*2<cnt){j=j*2+1;}
			else{break;}
			if(Compare(he[j],r)<=0){j=(j-1)/2;break;}
			he[(j-1)/2]=he[j];
		}
		he[j]=r;
	}
	private int Compare(T x,T y){return y.CompareTo(x);}
	public int Count(){return cnt;}
	public T Top(){return he[0];}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 24360
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {

	ll N, K;

	cin >> N >> K;
	ll i = 0;
	ll  j;
	while(1){
		j = pow(K, i);
		if (N /j ==0) {

			break;
		}
		i++;
	}
	cout << i;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
 
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            if (s - x - y >= 0 && s - x - y <= k) ans++;
        }
    }
 
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int len = (h2 - h1) * 60 + (m2 - m1);
  cout << len - k << endl;
}


Measured memory_bytes: 3652