akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int ctoi(const char c){
    switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
    }
}

int main(){
    string str;
    cin >> str;
    
    int numEq = 1 << (str.size()-1); // num of equation
    
    int ans=0;
    for(int i=0; i<numEq; ++i){
        string tmp;
        tmp += str[0];
        
        int i_buf = i;
        int sum = ctoi(str[0]);
        for(int n=1; n<str.size(); ++n){
            if(i_buf&1){ sum += ctoi(str[n]);
            }else      { sum -= ctoi(str[n]);
            }
            i_buf = i_buf >> 1;
        }
        
        if(sum==7){
            ans = i;
            break;
        }
    }
    
    for(int i=0; i<str.size()-1; ++i){
        printf("%c", str[i]);
        if(ans&1){ printf("+");
        }else    { printf("-");
        }
        ans = ans >> 1;
    }
    printf("%c=7\n", str[str.size()-1]);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
bool vis[5] ;
int main()
{
	int a , b ;
	scanf("%d%d" , &a , &b) ;
	memset(vis , 0 , sizeof(vis)) ;
	vis[a] = vis[b] = 1 ; 
	for(int i = 1 ; i <= 3 ; i ++)
	  if(!vis[i])  printf("%d\n" , i) ;
	return 0 ;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    map<ll,ll>a;
    rep(i,n){
        ll x;
        cin>>x;

        a[x]++;
    }

    ll ans=0;

    for (auto i : a) {
        if(i.second%2!=0)ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=3000005;

int n,a,b,ans[N];

int main()
{
    scanf("%d%d%d",&n,&a,&b);
    if (a==1)
    {
        if (b!=n) {puts("-1");return 0;}
        for (int i=n;i>=1;i--) printf("%d ",i);
        return 0;
    }
    if (a>n||b>n) {puts("-1");return 0;}
    int tot=0,now=b;
    for (int i=b;i>=1;i--) ans[++tot]=i;
    if (n-b<a-1) {puts("-1");return 0;}
    int x=(n-b)/(a-1),y=(n-b)%(a-1);
    if (x+(y>0)>b) {puts("-1");return 0;}
    for (int i=1;i<=y;i++)
    {
        for (int j=now+x+1;j>now;j--) ans[++tot]=j;
        now+=x+1;
    }
    for (int i=1;i<=a-1-y;i++)
    {
        for (int j=now+x;j>now;j--) ans[++tot]=j;
        now+=x;
    }
    for (int i=1;i<=n;i++) printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

a=int(input()) #500
b=int(input()) #100
c=int(input()) #50
x=int(input()) #sum

cnt=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            tmp=500*i+100*j+50*k
            if tmp==x:
                cnt+=1
            elif tmp>x:
                break
print(cnt)


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

int main() {
    ll x, y;
    scanf("%lld%lld", &x, &y);
    int ans = 0;
    for (ans; x <= y; ans++) {
        x *= 2;
    }
    printf("%d\n", ans);
    return 0;
}

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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

ll mi;

bool helper(unordered_set <ll> &mp,ll k,vi &dp)
{
    if(k<mi)
        return dp[k]=false;
    if(mp.count(k))
        return dp[k]=true;
    if(dp[k]!=-1)
        return dp[k];
    bool ans=false;
    for(auto ch:mp)
    {
        if(ch<=k)
        ans=ans||!helper(mp,k-ch,dp);
    }
    return dp[k]=ans;
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    unordered_set <ll> mp;
    mi=inf;
    rep(i,0,n)
    {
        ll x;
        cin>>x;
        mi=min(mi,x);
        mp.insert(x);
    }
    vi dp(k+1,-1);
    if(helper(mp,k,dp))
        cout<<"First";
    else
        cout<<"Second";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 5760
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b); 
   if(a==b)printf("%d",a*2);
   if(a>b)printf("%d",a*2-1);
   if(a<b)printf("%d",b*2-1);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    sc.close();
    int manner=k*(int)(Math.pow(k-1,n-1));
    System.out.println(manner);
  }
}

Measured memory_bytes: 20948
#include<stdio.h>

#define T 1
#define MAX 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

P Q[MAX+1];
int head,tail;


int main(){
  int i,n,q,elaps = 0,a,b,c;
  P u;
  initialize();
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
  }
  head = 0;
  tail = n;
  while(head != tail){
    u=dequeue();
    if(u.t<=q){
      b=u.t;
      elaps += b;
      printf("%s %d\n",u.name,elaps);
    }
    else{
      b=q;
      u.t = u.t - q;
      enqueue(u);
      elaps += b;
    }

  }
  return 0;
}

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  if(head == tail){
    return T;
  }
  return 0;
}

int isFull(void){
  if(head == (tail+1)%MAX){
    return T;
  }
  return 0;
}

void enqueue(P x){
  if(isFull()==T){
    fprintf(stderr,"overflow\n");
  }
  Q[tail] = x;
  if(tail+1 ==MAX){
    tail = 0;
  }
  else{
    tail++;
  }
}

P dequeue(void){
 P x;
  if(isEmpty()==T){
    fprintf(stderr,"underflow\n");
  }
  x = Q[head];
  if(head + 1 ==MAX){
    head = 0;
  }
  else{
    head++;
  }
  return x;
}



Measured memory_bytes: 12008
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline long long read()
{
	long long kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
int main()
{
	double a,b,c,d;
	a=read();b=read();c=read();d=read();
	double fi,se;
	fi=ceil(c/b);se=ceil(a/d);
	if(fi<=se)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	vector<int> x1(N), y1(N), x2(N), y2(N), xs, ys;
	for (int i = 0; i < N; i++) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		xs.push_back(x1[i]);
		xs.push_back(x2[i]);
		ys.push_back(y1[i]);
		ys.push_back(y2[i]);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());

	int H = xs.size(), W = ys.size();
	vector<vector<int>> val(H, vector<int>(W));
	for (int i = 0; i < N; i++) {
		int X1 = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
		int X2 = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
		int Y1 = lower_bound(ys.begin(), ys.end(), y1[i]) - ys.begin();
		int Y2 = lower_bound(ys.begin(), ys.end(), y2[i]) - ys.begin();
		val[X1][Y1]++;
		val[X2][Y2]++;
		val[X1][Y2]--;
		val[X2][Y1]--;
	}
	for (int i = 0; i < H; i++) {
		for (int j = 1; j < W; j++) {
			val[i][j] += val[i][j - 1];
		}
	}
	for (int i = 1; i < H; i++) {
		for (int j = 0; j < W; j++) {
			val[i][j] += val[i - 1][j];
		}
	}
	ll res = 0;
	for (int i = 0; i < H - 1; i++) {
		for (int j = 0; j < W - 1; j++) {
			if (val[i][j]) {
				res += (ll)(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 65624
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, from, dest;
        Edge(int cost, int dest): cost(cost), from(-1), dest(dest){ }
        Edge(int cost, int from, int dest): cost(cost), from(from), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << from << ' ' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    ll dijkstra2(int start, vector<ll> &lens){
        struct DElem{
            ll cost, dest;
            bool operator < (const DElem& e) const { return cost > e.cost; }
        };
        priority_queue<DElem> pq;
        pq.push({0, start});
        while(pq.size()){
            auto e = pq.top(); pq.pop();
            if(lens[e.dest] <= e.cost){ continue; }
            lens[e.dest] = e.cost;
            for(auto& edge : nodes[e.dest].edges){
                pq.push({e.cost + edge.cost, edge.dest});
            }
        }
        return -1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<ll> lens(n, MLL);
    g.dijkstra2(k, lens);
    prints(lens);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << lens[x] + lens[y] << '\n';
    }
}


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

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	int s=0,p=n;
	
	while(p!=0)
	{
		s+=p%10;
		p/=10;
	}
	
	if(n%s==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int inf = 99999999;
int n, ma, mb;
int a[50], b[50], c[50];
int dp[50][500][500];

int main() {
    cin >> n >> ma >> mb;
    imfor(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int ca = 0; ca <= 400; ca++) {
            for (int cb = 0; cb <= 400; cb++) {
                dp[i][ca][cb] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int ca = 0; ca <= 400; ca++) {
            for (int cb = 0; cb <= 400; cb++) {
                if (dp[i][ca][cb] == inf) {
                    continue;
                }
                dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b [i]], dp[i][ca][cb] + c[i]);
            }
        }
    }
    int ans = inf;
    for (int ca = 1; ca <= 400; ca++) {
        for (int cb = 1; cb <= 400; cb++) {
            if (ca * mb == cb * ma) {
                ans = min(ans, dp[n][ca][cb]);
            }
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 40832
#include <iostream>

using namespace std;

int main()
{
    //freopen("vacation.inp","r",stdin);
    int n,sum=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int A[n+1],B[n+1],C[n+1];
    A[1]=a[1];
    B[1]=b[1];
    C[1]=c[1];
    for(int i=2;i<=n;i++)
    {
        A[i]=max(B[i-1],C[i-1])+a[i];
        B[i]=max(A[i-1],C[i-1])+b[i];
        C[i]=max(A[i-1],B[i-1])+c[i];
    }
    cout<<max(A[n],max(B[n],C[n]));
}


Measured memory_bytes: 2560
#include <stdio.h>
 int main(void){    
 int N,M,i,j;  
   scanf("%d %d",&N,&M);  
   int A[1000];  
   int Ai;   
  int Bj;   
  int count[1000];
     for(i=0;i<N;i++){  
       scanf("%d",&Ai);    
     A[i]=Ai;      
   count[i]=0;   
  }    
 for(j=0;j<M;j++){   
      scanf("%d",&Bj);   
      for(i=0;i<N;i++){     
        if(A[i]<=Bj){count[i]++;break;}   
      }     
}     int max_count=0;   
  int max_game=-1;  
   for(i=0;i<N;i++){        
 if(max_count<count[i]){    
         max_count=count[i];     
        max_game=i;      
   }    
 }      
 printf("%d\n",max_game+1);
return 0;
 } 

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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 300005;

int n, k;

int32_t main(){

  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> n >> k;
  n %= k;
  cout << min(n, abs(n - k));


	return 0;
}




Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[100001];
        for(int i=0;i<n;i++){
            nums[sc.nextInt()]++;
        }
        int output=0;
        for(int i=1;i<99999;i++){
            output=Math.max(output,nums[i-1]+nums[i]+nums[i+1]);
        }
        System.out.println(output);
    }
 
    
}


Measured memory_bytes: 51236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define FBO find_by_order
#define OOK order_of_key
#define mset(m,v) memset((m),(v),sizeof(m))
#define inrep int TC;cin>>TC;while(TC--)
#define cppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PI 3.1415926535897932384626433832795028841971693993751
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<"\n"
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// SOLUTION

int main() {
	cppio;
	ll a, b;
	cin >> a >> b;
	a *= b;
	if(a&1) cout <<"Odd";
	else cout << "Even";
	return 0;
}


Measured memory_bytes: 764
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s;
	cin>>s;
	int n=s.length();
	string ans=s.substr(0,n-8);
	cout<<ans<<'\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
    
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	
    	String sss = sc.next();
    	sc.close();
    	String temp = null;
    	StringBuilder ss = new StringBuilder();
    	for(int i = 0; i < sss.length(); i+=2) {
    		 
    		ss.append(sss.charAt(i));
    		
    	}
    	
    	temp = ss.toString();
    	System.out.println(temp);
      
    }
}

Measured memory_bytes: 26028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
 
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
 
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
 
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll x,ans;
int main(){
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	cin>>x;
	ans = x/11;
	ans*=2;
	x%=11;
	if(x > 0){
		if(x<7) ans++;
		else ans+=2;
	}
	cout<<ans<<newl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=[int(a)-1 for a in input().split()]

if K<=N:
  p=0
  for i in range(K):
    p=A[p]
  print(p+1)
  exit()
p=0
t=[-1]*N
t[0]=0
for i in range(1,N):
  p=A[p]
  if t[p] !=-1:
    break
  t[p]=i

d=i-t[p]
K-=i
K%=d
for i in range(K):
  p=A[p]
print(p+1)

Measured memory_bytes: 32308
// https://atcoder.jp/contests/agc029/tasks/agc029_d
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        h: usize, w: usize, n: usize,
        objects: [(usize1, usize1); n]
    };

    let mut objects = objects;
    objects.sort();

    let mut ans = h;
    let mut wset = HashSet::new();

    let mut ty = 0;
    let mut lastx = 0;
    for (x, y) in objects {
        let diff = x - lastx;
        if diff > 0 {
            if !wset.contains(&(x - 1, y)) {
                ty += diff - 1;
                if ty >= y {
                    ans = x;
                    break;
                }
                if ty + 1 < y {
                    ty += 1;
                }
            } else {
                ty += 1;
                if ty == y {
                    ty -= 1;
                }
            }
        }
        lastx = x;
        wset.insert((x, y));
    }

    println!("{}", ans);
}


Measured memory_bytes: 24084
#include <bits/stdc++.h>
using namespace std;
int a1[20], a2[20], b[20], z[20], o[20];
int main(){
	int n,m;
	cin>>n>>m;
	int zero=0, one=0;
	for(int i=1;i<=n;i++){
		cin>>a1[i];
		a2[i]=a1[i];
		if(!a1[i]) zero++;
		else one++;
	}

	bool f=0;
	int one1=0, zero1=0;
	int one2=0, zero2=0;
	for(int i=1, k=1;i<=m;i++){
		cin>>b[i];
		if(f) one2+=b[i], zero1+=b[i];
		else one1+=b[i], zero2+=b[i];
		for(int j=1;j<=b[i];j++){
			z[k]=f;
			o[k]=!f;
			k++;
		}
		f=!f;
	}

	int cnt1=0, cnt2=0;
	for(int i=1;i<=n;i++){
		if(a1[i]!=z[i]){
			for(int j=i+1;j<=n;j++){
				if(z[i]==a1[j]){
					swap(a1[i], a1[j]);
					cnt1+=(j-i);
					break;
				}
			}
		}
	}

	for(int i=1;i<=n;i++){
		if(a2[i]!=o[i]){
			for(int j=i+1;j<=n;j++){
				if(o[i]==a2[j]){
					swap(a2[i], a2[j]);
					cnt2+=(j-i);
					break;
				}
			}
		}
	}

	/*cout<<one1<<" "<<one2<<" "<<zero1<<" "<<zero2<<endl;
	cout<<one<<" "<<zero<<endl;*/
	if(one1==one2 && zero1==zero2) cout<<min(cnt1, cnt2)<<endl;
	else if(one1==one && zero1==zero) cout<<cnt2<<endl;
	else cout<<cnt1<<endl;
	return 0;
}


Measured memory_bytes: 3096
import std.algorithm, std.conv, std.range, std.stdio, std.string;

alias point = Point!int;

void main()
{
  auto rd1 = readln.split.to!(int[]), h = rd1[0], w = rd1[1], n = rd1[2];
  auto p = new point[](n);
  foreach (i; 0..n) {
    auto rd2 = readln.splitter;
    auto a = rd2.front.to!int; rd2.popFront();
    auto b = rd2.front.to!int;
    p[i] = point(b, a);
  }

  p.multiSort!("a.y < b.y", "a.x < b.x");

  SortedRange!(point[], "a.x < b.x")[int] b;

  if (!p.empty) {
    auto prevI = 0, prevY = p[0].y;
    foreach (i; 0..n) {
      if (prevY != p[i].y) {
        b[prevY] = p[prevI..i].assumeSorted!"a.x < b.x";
        prevY = p[i].y;
        prevI = i;
      }
    }
    b[prevY] = p[prevI..$].assumeSorted!"a.x < b.x";
  }

  auto c = new long[](10);
  c[0] = (h-2).to!long * (w-2);

  foreach (pi; p) {
    auto dy = new long[][](3, 3);
    foreach (i; 0..3) {
      if (pi.y-2+i in b) {
        auto q = i < 2 ? b[pi.y-2+i] : b[pi.y].lowerBound(point(pi.x));
        foreach (j; 0..3)
          dy[i][j] = q.upperBound(point(pi.x-3+j, 0)).lowerBound(point(pi.x+j+1, 0)).length;
      }
    }
    foreach_reverse (i; 0..2) dy[i][] += dy[i+1][];

    foreach (i; 0..3)
      foreach (j; 0..3) {
        if (pi.y-2+i >= 1 && pi.y+i <= h && pi.x-2+j >= 1 && pi.x+j <= w) {
          --c[dy[i][j]];
          ++c[dy[i][j]+1];
        }
      }
  }

  foreach (ci; c) writeln(ci);
}

struct Point(T)
{
  T x, y;
  pure auto opBinary(string op: "+")(Point!T rhs) const { return Point!T(x + rhs.x, y + rhs.y); }
  pure auto opBinary(string op: "-")(Point!T rhs) const { return Point!T(x - rhs.x, y - rhs.y); }
  pure auto opBinary(string op: "*")(Point!T rhs) const { return x * rhs.x + y * rhs.y; }
  pure auto opBinary(string op: "*")(T a) const { return Point!T(x * a, y * a); }
  pure auto opBinary(string op: "/")(T a) const { return Point!T(x / a, y / a); }
  pure auto hypot2() const { return x ^^ 2 + y ^^ 2; }
}


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

int N, X;
int m[100];

int main(){
	cin >> N >> X;
	for(int i=0; i<N; i++){
		cin >> m[i];
		X -= m[i];
	}
	sort(m,m+N);
	cout << N+X/m[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>      
#define pb push_back 
#define fr first 
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii; 

int main() {

    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    //int t; cin>>t; while(t--) { 
    int n; cin>>n;
    vi h(n);
    f(i,0,n) cin>>h[i];
    vi dp(n,MOD);
    dp[0]=0;
    f(i,0,n) {
        for(int j: {i+1,i+2}) {
            if(j<n) dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1];
    

    return 0 ;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

signed main() {
    ll s, c; 
    cin >> s >> c;
    
    ll r = 0;
    r += min(s, c/2);
    s -= r;
    c -= r*2;
    
    r += c/4;
    
    mes(r);
    
    
    
}

Measured memory_bytes: 3552
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int nac = 0;
        int nwa = 0;
        int ntle = 0;
        int nre = 0;
        for (int i = 0; i < N; i++) {
            String s = ns();
            if(s.equals("AC")) nac++;
            if(s.equals("WA")) nwa++;
            if(s.equals("TLE")) ntle++;
            if(s.equals("RE")) nre++;
        }
        
        out.println("AC x " + String.valueOf(nac));
        out.println("WA x " + String.valueOf(nwa));
        out.println("TLE x " + String.valueOf(ntle));
        out.println("RE x " + String.valueOf(nre));
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 48424
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100100],n,ans,temp,edges,gcd,maxi,a,b,c,k,m,p,l,temp1,temp2;
vector<pair<ll,ll> > v[100100];
ll subtreeSiz[100100],par[100100],distanc[100100];
void dfs(ll st,ll parent)
{
    subtreeSiz[st]=1;
    for(int i=0;i<v[st].size();i++)
    {
        if(v[st][i].first!=parent)
        {
            par[v[st][i].first]=st;
            dfs(v[st][i].first,st);
            subtreeSiz[st]+=subtreeSiz[v[st][i].first];
        }
    }
}
pair<ll,ll> func(ll st)
{
    pair<ll,ll> p;
    for(int i=0;i<v[st].size();i++)
    {
        if(v[st][i].first!=par[st])
        {
            if(2*subtreeSiz[v[st][i].first]>n)
                return func(v[st][i].first);
            if(2*subtreeSiz[v[st][i].first]==n)
            {
                p.first=st;
                p.second=i;
                return p;
            }
        }
    }
    p.first=st;
    p.second=-1;
    return p;
}
void dfs2(ll st,ll parent)
{
    subtreeSiz[st]=1;
    for(int i=0;i<v[st].size();i++)
    {
        if(v[st][i].first!=par[st])
        {
            par[v[st][i].first]=st;
            dfs2(v[st][i].first,st);
            subtreeSiz[st]+=subtreeSiz[v[st][i].first];
            distanc[st]+=(distanc[v[st][i].first]+(subtreeSiz[v[st][i].first]*v[st][i].second));
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    edges=n-1;
    while(edges--)
    {
        cin>>a>>b>>c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    dfs(1,0);
    //cout<<"subtree size after dfs  is:"<<endl;
    //for(int i=1;i<=n;i++)
    //    cout<<subtreeSiz[i]<<" ";
    //cout<<endl;
    pair<ll,ll> p1=func(1);
    temp1=p1.first;
    par[temp1]=temp1;
    dfs2(temp1,0);
    //cout<<"subtree size after dfs2  is:"<<endl;
    //for(int i=1;i<=n;i++)
    //    cout<<subtreeSiz[i]<<" ";
    //cout<<endl;
    //cout<<"distance after ddfs2 is:"<<endl;
    //for(int i=1;i<=n;i++)
    //    cout<<distanc[i]<<" ";
    //cout<<endl;
    ans=distanc[temp1];
    ans=ans*2;
    if(p1.second==-1)
    {
        temp=1000000000000000;
        for(int i=0;i<v[temp1].size();i++)
            temp=min(temp,v[temp1][i].second);
        ans-=temp;
    }
    else
    {
        ans-=v[temp1][p1.second].second;
    }
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 == 0) {
    cout << "Yes" << endl;
  }
  else if (n % 500 <= a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;    
  }
}
 


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    unsigned long long int flag[1000000] = {};
    int N;
    int a,b;
    unsigned long long int K, sum = 0;
    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        flag[a] += b;
    }
    int i;
    for (i = 1; i <= 100001; i++) {
        sum += flag[i];
        if (sum >= K) {
            cout << i << '\n';
            break;
        }
    }
    if (i == 100002) {
        cout << 0 << '\n';
    }
    return 0;
}

Measured memory_bytes: 8064
H, W, N = map(int, input().split())
sh, sw = map(int, input().split())
S = input()
T = input()

command = []
for s, t in zip(S, T):
    command.append(s)
    command.append(t)

L, U, R, D = sw, sh, sw, sh
taka = 1
for c in command:
    if c == "R":
        if taka:
            R += 1
        else:
            L += 1
            L = min(L, W)
    elif c == "L":
        if taka:
            L -= 1
        else:
            R -= 1
            R = max(R, 1)
    elif c == "U":
        if taka:
            U -= 1
        else:
            D -= 1
            D = max(1, D)
    elif c == "D":
        if taka:
            D += 1
        else:
            U += 1
            U = min(U, H)
    taka = 1 - taka
    if R == W + 1 or L == 0 or U == 0 or D == H + 1:
        print("NO")
        exit()

print("YES")

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

int main(){
	
	int a,b,c,d,p ;
	cin >> a >> b >> c >> d >> p ;
	cout << min( a*p , b+((p-c>0)?(p-c)*d:0) ) << endl;
	
	return 0;
}

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

int main(void){
	int n;
	while(cin >> n,n){
		bool taro[210],hanako[210];
		rep(i,2*n+1) taro[i]=hanako[i]=false;
		rep(i,n){
			int in;
			cin >> in;
			taro[in]=true;
		}
		rep(i,2*n+1) hanako[i]=1-taro[i];
		taro[0]=hanako[0]=false;
		int cur=0,turn=0;
		while(1){
			int ti=0,hi=0;
			rep(i,2*n+1) ti+=taro[i],hi+=hanako[i];
			if(ti==0||hi==0) break;
			int i;
			if(turn){
				for(i=cur+1;i<=2*n;++i){
					if(hanako[i]){
						cur=i;
						hanako[i]=false;
						break;
					}
				}
				if(i>2*n) cur=0;
			}else{
				for(i=cur+1;i<=2*n;++i){
					if(taro[i]){
						cur=i;
						taro[i]=false;
						break;
					}
				}
				if(i>2*n) cur=0;
			}
			turn^=1;
		}
		int ta=0,ha=0;
		rep(i,2*n+1){
			if(hanako[i]) ta++;
			if(taro[i]) ha++;
		}
		cout << ta << endl << ha << endl;
	}
}

Measured memory_bytes: 1160
import sys
from collections import deque


input = sys.stdin.readline
n, m = map(int, input().split())
info = tuple(map(int, input().split()) for i in range(m))
s, t = map(int, input().split())

graph = [[] for i in range(n)]
for i, j in info:
    graph[i-1].append(j-1)

q = deque()
q.append((s - 1, 0))
INF = 10 ** 10
visited = [10 ** 10] * n
visited_1 = [10 ** 10] * n
visited_2 = [10 ** 10] * n
visited[s - 1] = 0
while q:
    pos, times = q.popleft()
    for i in graph[pos]:
        if (times + 1) % 3 == 1 and times + 1 < visited_1[i]:
            visited_1[i] = times + 1
            q.append((i, times + 1))

        elif (times + 1) % 3 == 2 and times + 1 < visited_2[i]:
            visited_2[i] = times + 1
            q.append((i, times + 1))
            
        elif (times + 1) % 3 == 0 and times + 1 < visited[i]:
            visited[i] = times + 1
            q.append((i, times + 1))

if visited[t - 1] == 10 ** 10:
    print(-1)
else:
    print(visited[t-1]//3)
    

Measured memory_bytes: 90972
#include <bits/stdc++.h>
using namespace std;
#define ll int
const ll N = 1e5 + 5;
vector<ll> a[N];
ll n, m, u, v, ans[N];
ll dfs(ll x)
{
    if (ans[x])
        return ans[x];
    for (ll e : a[x])
        ans[x] = max(ans[x], dfs(e) + 1);
    return ans[x];
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m;
    while (m--)
        cin >> u >> v, a[u].push_back(v);
    for (ll i = 1; i <= n; i++)
        dfs(i);
    cout << *max_element(ans + 1, ans + n + 1);
}

Measured memory_bytes: 7552
import java.util.Scanner

fun main() {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val k = scn.nextLong()
	val arr = IntArray(n){scn.nextInt()-1}
	val f = BooleanArray(n){false}
	val list = mutableListOf<Int>()
	var i = 0
	while(!f[i]){
		f[i] = true
		list.add(i)
		i = arr[i]
	}
	val l = list.indexOf(i)
	val r = list.lastIndex
	println(if (k<l) list[k.toInt()]+1 else list[((k-l)%(r-l+1)+l).toInt()]+1)
}

Measured memory_bytes: 61908
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n, h;
  cin >> n >> h;
  int a = 0;
  vector<int> b(n);
  rep(i,n) {
    int x;
    cin >> x >> b[i];
    a = max(a,x);
  }
  sort(rng(b));
  reverse(rng(b));
  int i = 0;
  int cnt = 0;
  while(h>0) {
    if(a>=b[i]||i==n) {
      cnt += (h+a-1)/a;
      break;
    }
    else {
      h -= b[i];
      cnt++;
      i++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 9e18;

signed main() {
    int N, P;
    cin >> N >> P;
    vector<int> S(N);
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        S[i] = c - '0';
    }
    if (P == 2 || P == 5) {
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (S[i] % P == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    reverse(S.begin(), S.end());
    vector<int> cumulative(N + 1, 0);
    map<int, int> check;
    int base = 1;
    for (int i = 0; i < N; i++) {
        cumulative[i + 1] = (S[i] * base) % P;
        cumulative[i + 1] = (cumulative[i] + cumulative[i + 1] ) % P;
        base *= 10;
        base %= P;
        check[cumulative[i + 1]]++;
    }
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        if (i != 0) check[cumulative[i]]--;
        ans += check[cumulative[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3968
import java.lang.Integer.min
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val x = sc.nextInt()
    val c = mutableListOf<Int>()
    val a = Array(n) {mutableListOf<Int>()}
    repeat(n) {i->
        c.add(sc.nextInt())
        repeat(m) {
            a[i].add(sc.nextInt())
        }
    }

    var ans = Int.MAX_VALUE
    for (i in 1 until (1 shl n)) {
        val sum = Array(m) {0}
        var cost = 0
        for (j in 0 until n) {
            if (i and (1 shl j) == 0) continue
            cost += c[j]
            for (k in 0 until m) {
                sum[k] += a[j][k]
            }
        }
        val count = sum.count { it >= x }
        if (count == m) {
            ans = min(cost, ans)
        }
    }
    println(if (ans == Int.MAX_VALUE) -1 else ans)
}

Measured memory_bytes: 44136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100005];
int mincost(ll s,ll n,ll *a,ll k)
{
  if(s==(n-1))
    return 0;
  if(dp[s]!=-1)
    return dp[s];
  else
  {
    ll ans=INT_MAX;
    ll i;
    for(i=1;i<=k;i++)
        {
          if(i+s<n)
          ans=min(ans,abs(a[i+s]-a[s])+mincost(s+i,n,a,k));
           else
             break;
        }
        dp[s]=ans;
        return dp[s];
  }   
}
 int main()
{
  ll n,k;
    cin>>n>>k;
    ll i=0;
    ll a[n];
  memset(dp,-1,sizeof(dp));
  for(i=0;i<n;i++)
    cin>>a[i];
   cout<<mincost(0,n,a,k)<<"\n";
    
}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;
using Pos = std::pair<int, int>;
//cout<<fixed<<std:cout<<fixed<<setprecision(2)<<Max<<endl;
constexpr int mod = 1e9 + 7;

int main() {
    int N;
    cin>>N;
    vector<Pos> a(N);
    for(int i = 0; i < N; ++i) {
        int ai;
        cin>>ai;
        a[i]=Pos(ai,i);
    }

    sort(begin(a),end(a),[](auto x,auto y){return x.first!=y.first?x.first>y.first:x.second>y.second;});

    vector<long long> ans(N,0);
    int prev=a[0].first;
    int Min=a[0].second;
    for(int i=1;i<N;++i) {
        if(a[i].first!=prev){
            ans[Min]+=(long long)i*(long long)(prev-a[i].first);
            prev=a[i].first;
        }
        Min=min(Min,a[i].second);
    }
    ans[Min]+=(long long)N*(long long)a[N-1].first;

    for(const auto& val:ans)
        cout<<val<<'\n';

    return 0;
}

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

int main() {
    int n,m,ans;
    cin>>n>>m;
    vector<int> x(m),d;
    rep(i,m) cin>>x[i];
    sort(x.begin(),x.end());
    for (int i=1; i<m; i++) {
        d.push_back(x[i]-x[i-1]);
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    ans=x.back()-x[0];
    for (int i=0; i<min((int)d.size(),n-1); i++) {
        ans-=d[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1276
#include <stdio.h>
int main (void){
  int n = 0;
  int a = 0;
  int b = 0;
  
  scanf("%d %d %d", &n, &a, &b);
    if(b <= a*n){
        printf("%d\n", b);
    }else{
        printf("%d\n", a*n);
    }
 
  return 0;
}


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

int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> v0, v1;
    v0.push_back(0); v1.push_back(0);
    int count0 = 0, count1 = 0;

    for(int i = 0; i < N - 1; i++){
        if(S[i] == '0'){
            count0++;
            if(S[i + 1] == '1'){
                v0.push_back(count0);
            }
        }
    }
    if(S[N - 1] == '0') v0.push_back(count0 + 1);

    for(int i = 0; i < N - 1; i++){
        if(S[i] == '1'){
            count1++;
            if(S[i + 1] == '0'){
                v1.push_back(count1);
            }
        }
    }
    if(S[N - 1] == '1') v1.push_back(count1 + 1);

    if(K >= v0.size()){
        cout << N << endl;
        exit(0);
    }

/*
    for(auto e : v0){
        cout << e << " ";
    }
    cout << endl;
    for(auto e : v1){
        cout << e << " ";
    }
    cout << endl;
*/

    int ans = 0;
    if(S[0] == '1' && S[N - 1] == '1'){
        int i = 0;
        while(i + K + 1 <= v0.size()){
            int tmp = (v0[i + K] - v0[i]) + (v1[i + K + 1] - v1[i]);
            ans = max(ans, tmp);
            i++;
        }

    }else if(S[0] == '1' && S[N - 1] == '0'){
        int i = 0;
        while(i + K + 1 < v0.size()){
            int tmp = (v0[i + K] - v0[i]) + (v1[i + K + 1] - v1[i]);
            ans = max(ans, tmp);
            i++;
        }
        int b = (v0[i + K] - v0[i]) + (v1[i + K] - v1[i]);
        ans = max(ans, b);

    }else if(S[0] == '0' && S[N - 1] == '0'){
        int a = (v0[K] - v0[0]) + (v1[K] - v1[0]);
        ans = max(ans, a);
        int i = 0;
        while(i + K + 1 < v1.size()){
            int tmp = (v0[i + K + 1] - v0[i + 1]) + (v1[i + K + 1] - v1[i]);
            ans = max(ans, tmp);
            i++;
        }
        int b = (v0[i + K + 1] - v0[i + 1]) + (v1[i + K] - v1[i]);
        ans = max(ans, b);

    }else if(S[0] == '0' && S[N - 1] == '1'){
        int a = (v0[K] - v0[0]) + (v1[K] - v1[0]);
        ans = max(ans, a);
        int i = 0;
        while(i + K + 1 < v0.size()){
            int tmp = (v0[i + K + 1] - v0[i + 1]) + (v1[i + K + 1] - v1[i]);
            ans = max(ans, tmp);
            i++;
        }
    }

    //cout << endl;
    cout << ans << endl;

}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007

#define MAX 100000000
bool isprime[MAX];

void eratos(){
  for ( int i = 0; i < MAX; i++){isprime[i] = true;}
  isprime[0] = isprime[1] = false;
  for ( int i = 2; i <= sqrt(MAX); i++){
    if ( isprime[i] ){
      int j = i + i;
      while( j <= MAX){
        isprime[j] = false;
        j += i;
      }
    }
  }
}

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  for ( int i = 2; i <= n; i++ ){
    int crr = i;
    while(1){
      bool isDivided = false;
      for ( int i = 2; i <= crr; i++){
        if ( crr % i == 0 ){
          mp[i]++;
          crr = crr/i;
          isDivided = true;
          break;
        }
      }
      if ( !isDivided ){
        break;
      }
    }
  }

  long long ans = 1;
  for ( map<int,int>::iterator it = mp.begin(); it!=mp.end(); ++it){
    long long x = (it->second + 1) % mod;
    ans = ans * x % mod;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [int(input()) for _ in range(N)]
A = sorted(S)

for i in range(N):
  if S[i] == A[-1]:
    if len(A) > 1:
      print(A[-2])
    else:
      print(A[-1])
  else:
    print(A[-1])



Measured memory_bytes: 18988