akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

INF = 1 << 50

def dfs(current, node_vals, seen, to):
    for next in to[current]:
        if not seen[next]:
            node_vals[next] += node_vals[current]
            seen[next] = 1
            dfs(next, node_vals, seen, to)


def run():
    N, Q = map(int, sysread().split())
    to = [[] for _ in range(N+1)]
    for i in range(N-1):
        a,b = map(int, sysread().split())
        to[a].append(b)
        to[b].append(a)

    node_vals = [0] * (N+1)

    for i in range(Q):
        p, x = map(int, sysread().split())
        node_vals[p] += x

    seen = [0] * (N+1)
    seen[1] = 1
    dfs(1, node_vals, seen, to)

    node_vals = [str(v) for v in node_vals]
    print(' '.join(node_vals[1:]))

if __name__ == "__main__":
    run()

Measured memory_bytes: 234676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define vi vector<long long>
#define pi pair<ll ,ll>
#define mkp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

ll ans=0, n, m;
pi a[100001];
set<int> se;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m;
    for(int i=1; i<=m; i++) se.insert(i);
    for(int i=0; i<n; i++)
        cin >> a[i].S >> a[i].F;
    sort(a, a+n);
    for(int i=n-1; i>=0; i--)
    {
        auto it = se.lower_bound(a[i].S);
        if(it==se.end()) continue;
        if(se.empty()) break;
        ans+=a[i].F;
        se.erase(it);
    }
    cout << ans;
}



Measured memory_bytes: 6528
from itertools import permutations
N,M = map(int,input().split())
ab = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
c = permutations(range(N)[1:])
ans = 0
for per in c:
    per = [0] + list(per)
    flag = True
    for i in range(N-1):
        p1 = min(per[i],per[i+1])
        p2 = max(per[i],per[i+1])
        if (p1,p2) in ab:
            continue
        else:
            flag=False
    if flag:
        ans+=1
print(ans)

Measured memory_bytes: 43504
def main():
    N, K = map( int,input().split())
    A = list( map( int, input().split()))
    ANS = []
    for i in range(K,N):
        if A[i-K] < A[i]:
            ANS.append("Yes")
        else:
            ANS.append("No")
    print("\n".join(ANS))
if __name__ == '__main__':
    main()


Measured memory_bytes: 31748
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
  string s,t;
  cin >> s >> t;
  int size=s.length();
  int cnt=0;
  for(int i=0;i<size;i++){
    if(s.at(i)!=t.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main () {
  
  vector<int> line(3) ;
  
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> line.at(i) ;
  }
  
  int contena = line.at(1) ;
  
  sort (line.begin() , line.end () ) ;
  
  if ( contena == line.at(2) ){
    cout << "Yes" << endl ;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  double w, h, x, y;cin>>w>>h>>x>>y;
  cout<<w*h*0.5<<" ";
  if((abs(w*0.5-x)<1e-5)&&(abs(h*0.5-y)<1e-5))cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int a,aa,aaa;
    cin >>a >>aa>>aaa;
    cout << aaa<<" "<<a<<" "<<aa<<endl;

}



Measured memory_bytes: 256
import math
import copy
import bisect







def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input().split())
m=nCast(inputArr1(n[0]))



def func():
    
    s=set(m[0][1:])
    for mm in m:
        tmp=set(mm[1:])
        s=s&tmp
    return len(s)
        


print(func()) 



Measured memory_bytes: 3540
#include <iostream>
using namespace std;
int n,m,x,y,mini,maxi,c;
int main()
{ cin>>n>>m>>maxi>>mini;
  for(int i=1;i<=n;i++)
  { cin>>c;
    if(c>maxi)
       maxi=c;
  }
  for(int i=1;i<=m;i++)
  { cin>>c;
    if(c<mini)
       mini=c;
  }
  if(maxi>=mini)
  { cout<<"War";
    return 0;
  }
  cout<<"No War";
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := newScanner()
	var n = sc.readInt()
	var l = make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = sc.readInt()
	}
	if n < 3 {
		fmt.Println("0")
		return
	}
	sort.SliceStable(l, func(i, j int) bool {
		return l[i] < l[j]
	})
	var cnt int
	for i := 0; i < n-2; i++ {
		for j := i + 1; j < n-1; j++ {
			for k := j + 1; k < n; k++ {
				if l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i]+l[j] > l[k] {
					cnt++
				}
			}
		}
	}

	fmt.Println(cnt)

}

//////////////////
//////////////////
//////////////////

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func reverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func reverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type scanner struct {
	bufScanner *bufio.Scanner
}

func newScanner() *scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &scanner{bufSc}
}

func (sc *scanner) readString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *scanner) readInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *scanner) readInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1776
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b){
	return b != 0 ? gcd(b, a%b) : a;
}

int lcm(int a, int b){
	return a*b / gcd(a, b);
}

#define N_MAX 310
#define MOD 1000000007

bool prime(int num)
{
	for (int i = 2; i <= sqrt(num); i++){
		if (0 == num%i){
			return false;
		}
	}

	return true;
}

void solv()
{
	int X; scanf("%d", &X);
	for (int i = X; i < 1000000; i++){
		if (prime(i)){
			printf("%d", i);
			return;
		}
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

double f(double n){
    return n*(n+1)/2/n;
}

void run(){
    int n,k;
    cin>>n>>k;
    vector<double> p(n+1);
    REP(i,1,n){
        cin>>p[i];
        p[i]=f(p[i]);
    }
    rep(i,n)p[i+1]+=p[i];
    double ans=0;
    rep(i,n-k+1){
        ans=max(ans,p[i+k]-p[i]);
    }
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 10005;

int digit[maxn], tot, d;
ll dp[maxn][105];

ll dfs(int len, int pre, int top) {
    if (!len) {
        if (pre == 0) return 1;
        return 0;
    }
    if (!top && dp[len][pre] != -1) return dp[len][pre];
    int up = (top ? digit[len] : 9);
    ll res = 0;
    for (int i = 0; i <= up; i++) {
        res += dfs(len - 1, (pre + i) % d, top && (i == up));
        res %= mod;
    }
    if (!top) dp[len][pre] = res;
    return res;
}

ll solve(int n) {
    memset(dp, -1, sizeof(dp));
    tot = n;
    return dfs(tot, 0, 1);
}
char str[maxn];
int main() {
   //freopen("in.in", "r", stdin);
//    freopen("o2.out", "w", stdout);
    scanf("%s%d", str + 1, &d);
    int n = strlen(str + 1);
    for (int i = n, j = 1; i >= 1; i--, j++) {
        digit[j] = str[i] - '0';
    }
    cout << (solve(n) - 1 + mod) % mod<< endl;
    return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	 int x,A,B,C,s=0;
    cin>>A>>B>>C>>x;
    for(int i=0;i<=A;i++)
    {
    	for(int j=0;j<=B;j++)
    	{
	    	for(int k=0;k<=C;k++)
	    	{
	    		if((i*500+j*100+k*50)==x)s++;
	    	}
	    }
    }
    cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int cnt=0;
  int ans=0;
  while(true){
    if(cnt==K)break;
    if(A>0){
      A--;
      ans++;
    }
    else if(A==0&&B>0){
      B--;
    }
    else if(A==0&&B==0&&C>0){
      ans--;
    }
  cnt++;

//  cout<<cnt<<" "<<ans<<endl;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int a,b;
  cin>>a>>b;
  if(b>=a){cout<<a<<endl;}
  else cout<<a-1<<endl;
  return 0;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  if(n == 1){
    cout << 0 << endl;
    return 0;
  }
  int ans = n + n*(n-1)/2;
  ans -= n;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=100005;
int st[N],vis[N],n;
inline void in(vi &a){
	int i,j;
	a.resize(n+1);
	rep(i,1,n)scanf("%d",&a[i]);
}
inline void out(const vi &a){
	int i;
	rep(i,1,n)printf("%d ",a[i]);
}
inline vi inv(const vi &a){
	vi b(n+1,0);
	int i;
	rep(i,1,n)b[a[i]]=i;
	return b;
}
inline vi mul(const vi &a,const vi &b){
	vi c(n+1,0);
	int i;
	rep(i,1,n)c[i]=b[a[i]];
	return c;
}
inline vi pow(vi a,int k){
	vi b(n+1,0);
	int i,j,t;
	rep(i,1,n)vis[i]=1;
	rep(i,1,n)if(vis[i]){
		st[t=0]=i;
		for(j=a[i];j!=i;j=a[j])vis[st[++t]=j]=0;
		++t;
		REP(j,0,t)b[st[j]]=st[(j+k)%t];
	}
	return b;
}
vi a,b,c,d;
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int k;
    scanf("%d%d",&n,&k);--k;
    in(a);
	in(b);
	d=pow(mul(mul(inv(b),a),mul(b,inv(a))),k/6);
	if(k%=6){
		if(k==1)c=b;
		else for(;k!=1;--k){c=mul(inv(a),b);a=b;b=c;}
	}else c=a;
	out(mul(mul(d,c),inv(d)));
    return 0;
}

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

int card[110][2];
int memo[110][110];

int cost(int a, int b, int c, int d){
	return card[a][0]*card[b][1]*card[c][0]*card[d][1];
}

int f(int a, int b){
	if(memo[a][b]!=-1){
		return memo[a][b];
	}
	if(a==b){
		memo[a][b]=0;
		return memo[a][b];
	}
	
	memo[a][b]=f(a,a)+f(a+1,b)+cost(a,a,a+1,b);
	for(int i=a;i+1<=b;i++){
		memo[a][b]=min(memo[a][b],f(a,i)+f(i+1,b)+cost(a,i,i+1,b));
	}
	return memo[a][b];
}

int main(){
	
	for(int i=0;i<110;i++){
		for(int j=0;j<110;j++){
			memo[i][j]=-1;
		}
	}
	
	int n;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>card[i][0]>>card[i][1];
	}
	
	cout<<f(1,n)<<endl;
	
	return 0;
}


Measured memory_bytes: 1212
n = int(input())
ca = 0
cb = 0
cab = 0
ans = 0
for i in range(n):
    a = input()
    if a[0] == "B":
        if a[-1] == "A":
            cab += 1
        else:
            cb += 1
    else:
        if a[-1] == "A":
            ca += 1
    for j in range(len(a)-1):
        if a[j] == "A" and a[j+1] == "B":
            ans += 1
if cab == 0:
    print(ans+min(ca,cb))
else:
    if max(ca,cb) > 0:
        print(ans + cab + min(ca,cb))
    else:
        print(ans + cab - 1)

Measured memory_bytes: 9152
#include <stdio.h>

int main() {
    int h1, m1, h2, m2, k;
    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
    h1 *= 60;
    h2 *= 60;
    h1 += m1;
    h2 += m2;
    int diff = h2 - h1;
    if (k == h2) {
        printf("0");
        return 0;
    }
    printf("%d", diff - k);
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


struct Node{
    ll cnt;
    ll cost;
    bool operator< (const Node &r) const{
        return cnt > r.cnt;
    }
};

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin >> n;

    priority_queue<Node> que;
    que.push({0, n});
    
    set<ll> visited;
    while(true){
        Node node = que.top(); que.pop();

        if(node.cost == 0){
            cout << node.cnt << endl;
            return 0;
        }

        if(0 < visited.count(node.cost)){
            continue;
        }
        visited.insert(node.cost);

        ll ncnt = node.cnt+1;
        que.push({ncnt, node.cost-1});
        rep(i, n){
            if(i == 0) continue;
            ll ncost = node.cost-pow(6, i);
            if(ncost < 0) break;
            que.push({ncnt, ncost});
        }
        rep(i, n){
            if(i == 0) continue;
            ll ncost = node.cost-pow(9, i);
            if(ncost < 0) break;
            que.push({ncnt, ncost});
        }
    }
    

    return 0;
}


Measured memory_bytes: 11368
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,K;
    cin >> N >> K;
    string S;
    cin  >> S;
    S[K-1] += 32;
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

ll gcd(ll a, ll b) {
    if (b>a) swap(a,b);
    while (b>0) {
        ll tmp=b;
        b=a%b;
        a=tmp;
    }
    return a;
}

int main() {
    ll a,b;
    cin >> a >> b;
    ll c=gcd(a,b);
    cout << (a/c)*b << endl;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll cnt = 0;
  for(int i = k; i < n; i++){
    cnt += a.at(i);
  }
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 3988
n = int(input())
alphabets = "abcdefghijklmnopqrstuvwxyz"
lstS = [input() for _ in range(n)]
lstN = []
ans = ""


for char in alphabets:
    numChar = float("inf")
    for s in lstS:
        numChar = min(numChar, s.count(char))
    lstN.append(numChar)


for char, num in zip(alphabets, lstN):
    ans += char * num
print(ans)

Measured memory_bytes: 3064
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <stdio.h>
#define abs(x) ((x) > 0 ? (x) : -(x))
#define neg(x) (((x) == 1) ? 1 : -1)
#define ptc(x) (*st ++ = (x), (__builtin_expect(st == ed, false) && (fwrite(outbuf, 100000, 1, stdout), st = outbuf)))

int main() {
	static char outbuf[100000];
	register char *st = outbuf, *ed = outbuf + 100000;
	long long k, x, y;
	scanf("%lld\n%lld %lld", &k, &x, &y);
	if (!(k & 1) && (x + y & 1))
		return puts("-1") & 0;
	static int sz = 0;
	static int ansx[239017];
	static int ansy[239017];
	long long px = 0, py = 0;
	while (abs(px - x) + abs(py - y) > k * 2) {
		if (abs(px - x) > k) px += (px > x) ? -k : k;
		else py += (py > y) ? -k : k;
		ansx[++ sz] = px, ansy[sz] = py;
	}
	if (abs(px - x) + abs(py - y) != k) {
		if ((k & 1) && (x - px + y - py & 1)) {
			if (abs(py - y) <= k) {
				px += (k - abs(py - y)) * neg(px < x);
				py = y;
			}
			else {
				py += (k - abs(px - x)) * neg(py < y);
				px = x;
			}
			ansx[++ sz] = px, ansy[sz] = py;
		}
		long long t = k * 2 - abs(px - x) - abs(py - y) >> 1;
		if (abs(px - x) < abs(py - y))
			if (px <= x) {
				ansx[++ sz] = x + t;
				ansy[sz] = py + (k - (x + t - px)) * neg(py < y);
			}
			else {
				ansx[++ sz] = x - t;
				ansy[sz] = py + (k - (px + t - x)) * neg(py < y); 
			}
		else
			if (py <= y) {
				ansy[++ sz] = y + t;
				ansx[sz] = px + (k - (y + t - py)) * neg(px < x);
			}
			else {
				ansy[++ sz] = y - t;
				ansx[sz] = px + (k - (py + t - y)) * neg(px < x);
			}
	}
	ansx[++ sz] = x, ansy[sz] = y;
	const static int ssz = sz;
	register char stk[20], top = 0;
	while (sz) stk[top++] = sz % 10, sz /= 10;
	while (top--) ptc(stk[top] + 48); ptc('\n');
	for (int i = 1; i <= ssz; ++i) {
		if (!ansx[i]) ptc('0');
		else {
			if (ansx[i] < 0) ptc('-'), ansx[i] = -ansx[i];
			top = 0;
			while (ansx[i]) stk[top++] = ansx[i] % 10, ansx[i] /= 10;
			while (top--) ptc(stk[top] + 48);
		}
		ptc(' ');
		if (!ansy[i]) ptc('0');
		else {
			if (ansy[i] < 0) ptc('-'), ansy[i] = -ansy[i];
			top = 0;
			while (ansy[i]) stk[top++] = ansy[i] % 10, ansy[i] /= 10;
			while (top--) ptc(stk[top] + 48);
		}
		ptc('\n');
	}
	if (st != outbuf)
		fwrite(outbuf, st - outbuf, 1, stdout);
}


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

int main() {
  // ここにプログラムを追記
  int a,b,c,d;
  cin >> a;
  b = a / 100;
  c = a % 100 / 10;
  d = a % 10;
  cout << b + c + d << endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(){
    int N;
    cin>>N;
    int a[110]={0};
    int b[110];
    REP(i, 0, N){
        cin>>a[i];
    }
    bool flag = false;
    for(int i=N-1; i >= 0; --i){
        flag = false;
        for(int j=i; j >= 0; --j){
            if(a[j]==j+1){
                b[i]=j+1;
                for(int k = j;k<i;++k){
                    a[k]=a[k+1];
                }
                flag=true;
                break;
            }
        }
        if(!flag){
            cout<<"-1"<<endl;
            return 0;
        }
    }

    REP(i, 0, N){
        cout<<b[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def d_binomial_coefficients():
    N = int(input())
    A = sorted([int(i) for i in input().split()])  # ソートしておく

    n = A[-1]  # n を大きく、r を n/2 に近づけると comb(n, r) は大きい
    r = min(A[:-1], key=lambda x: abs(n / 2 - x))
    return f'{n} {r}'

print(d_binomial_coefficients())

Measured memory_bytes: 19700
N, K = map(int, input().split())
A = [0] * N
for i in range(N):
  A[i] = list(map(int, input().split()))
  
A = sorted(A)
now = 0
for i in range(N):
  if now + A[i][1] >= K:
    print(A[i][0])
    quit()
  else:
    now += A[i][1]

Measured memory_bytes: 87748
// https://atcoder.jp/contests/abc116/tasks/abc116_a

#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::HashSet;
#[allow(unused)]
use std::collections::VecDeque;
use std::io;
use std::io::{BufRead, Read, Write};
use std::str::FromStr;

#[allow(unused, non_snake_case)]
pub fn solve<R: BufRead, W: Write>(mut io: Io<R, W>) {
    let ab: usize = io.next();
    let bc: usize = io.next();
    let ca: usize = io.next();

    let res = ab * bc / 2;
    io.println(res);
}

#[allow(dead_code)]
fn main() {
    let stdin = io::stdin();
    let stdin_lock = stdin.lock();
    let stdout = io::stdout();
    let stdout_lock = stdout.lock();

    let io = Io {
        reader: stdin_lock,
        writer: stdout_lock,
    };

    solve(io);
}

/* IO helpers */

pub struct Io<R, W>
where
    R: BufRead,
    W: Write,
{
    pub reader: R,
    pub writer: W,
}

#[allow(dead_code)]
impl<R, W> Io<R, W>
where
    R: BufRead,
    W: Write,
{
    fn println<T: std::fmt::Display>(&mut self, value: T) {
        writeln!(&mut self.writer, "{}", value).expect("Unable to write");
    }

    fn print<T: std::fmt::Display>(&mut self, value: T) {
        write!(&mut self.writer, "{}", value).expect("Unable to write");
    }

    fn next<T: FromStr>(&mut self) -> T {
        let token = self
            .reader
            .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().expect("Unable to parse")
    }
}

/* Structure helpers */

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


Measured memory_bytes: 4352
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main()
{
	int N, M;
  string str;
  map<string, int> m;
  
  cin >> N;
  REP(i, N)
  {
    cin >> str;
    auto it = m.find(str);
    if( it == m.end() )
    {
        m[str] = 1;
    } else
    {
      m[str]++;
    }
  }
  
  cin >> M;
  REP(i, M)
  {
    cin >> str;
    auto it = m.find(str);
    if( it == m.end() )
    {
        m[str] = -1;
    } else
    {
      m[str]--;
    }
  }
  
  int ret = 0;
  for(auto it = m.begin(); it != m.end(); ++it)
  {
    ret = max(ret, it->second);
  }
  
  cout << ret << endl;
  
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int n;
	cin >> n;
	ll T;
	cin >> T;
	vector<ll> t(n);
	rep(i, n) cin >> t.at(i);

	ll ans = 0;
	rep(i, n - 1) {
		int diff = t.at(i + 1) - t.at(i);

		if (diff <= T) {
			ans += diff;
			continue;
		}
		else{
			ans += T;
		}
	}
	ans += T;
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// マラソン用時間計測
clock_t start_clock;
constexpr double time_limit = 1.919114514; // 実行時間[s]より0.1ms程度余裕をあける
constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
inline bool intime() { return nowtime() < time_limit; }

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (int i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (int i=(is), i##_end=(ie); i<=i##_end; i++)
#define FOREACH(i, arr) for (auto &i : arr)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using ll = long long;
using namespace std;

// 汎用クラス
struct union_find {
    vector<int> par;
    vector<int> num;
    union_find(int n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// main前実行のためのダミークラス
struct preexec_dummy {
    preexec_dummy() {
        start_clock = clock();
    }
} preexec_dummy_instance;

// 0 xor 1 xor ... xor n
// -> a xor ... xor b = imos_xor(b) xor imos_xor(a-1)
ll imos_xor(ll n) {

    switch(n % 4) {
        case 0ll:
            return n;
        case 1ll:
            return 1ll;
        case 2ll:
            return n + 1ll;
        case 3ll:
            return 0;
        default:
            exit(EXIT_FAILURE);
    }

}

int main() {
    
    ll a, b;
    cin >> a >> b;

    ll ans = imos_xor(b);
    if (a > 1) {
        ans ^= imos_xor(a - 1ll);
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll p = abs(x) / d;
  ll ans;
  if (p > k)
    ans = d * (p - k) + abs(x) % d;
  else {
    p -= k;
    if (p % 2 == 0)
      ans = abs(x) % d;
    else
      ans = d - abs(x) % d;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    double ds=0;
    ll mul=1;
    rep(i,n){
        ll a;cin >> a;
        if(a==0){
            cout << 0 << endl;
            return 0;
        }
        mul*=a;
        ds+=logf(a);
    }
    ll p=1e18+1e17;
    ll q=1e18;
    if(ds>logf(p)){
        cout << -1 << endl;
    }
    else{
        if(mul>q){
            cout << -1 << endl;
        }
        else{
            cout << mul << endl;
        }
    }
}


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

int main(){
  int w,h,n;
  vector< vector<int> > b( 110, vector<int>(110) );
  
  cin >> w >> h >> n;
  
  int i,j,k;
  for(i = 0 ; i < n ; i++){
    int x,y,a;
    cin >> x >> y >> a;
    
    if( a == 1 ){
      for(j = 0 ; j < x  ; j++){
        for(k = 0 ; k < h ; k++)		b.at(j).at(k)++;
      }
    }
    
    if( a == 2 ){
      for(j = x ; j < w ; j++){
        for(k = 0 ; k < h ; k++)		b.at(j).at(k)++;
      }
    }
    
    if( a == 3 ){
      for(j = 0 ; j < w ; j++){
        for(k = 0 ; k < y ; k++) 		b.at(j).at(k)++;
      }
    }
    
    if( a == 4 ){
      for(j = 0 ; j < w ; j++){
        for(k = y ; k < h ; k++)		b.at(j).at(k)++;
      }
    }
  }
  
  int count = 0;
  for(i = 0 ; i < w ; i++){
    for(j = 0 ; j < h ; j++)	if( b.at(i).at(j) == 0 )	count++;
  }
  
  cout << count << endl;
  
} 

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

signed main(){

    int a, b, k; cin >> a >> b >> k;
    int num = 0;
    for(int i = max(a, b) ;; i--){
        if(a % i == 0 && b % i == 0){
            num++;
        }

        if(num == k){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
arr = [input() for _ in range(h)]

ans = 0
for bit_h in range(2**h):
    for bit_w in range(2**w):
        tmp = 0
        for i in range(h):
            if (bit_h >> i) & 1:
                continue
            for j in range(w):
                if (bit_w >> j) & 1:
                    continue
                if arr[i][j] == '#':
                    tmp += 1
        if tmp == k:
            ans += 1

print(ans)


Measured memory_bytes: 9088
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W,X;
long long A[200001] = {};
long long B[200002] = {};
long long tt[20000] = {};
bool f;
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vpl;
vector <long long>vl;


int main() {
	cin >> N;
	for (long i = 0; i < N; i++) {
		cin >> B[i];
		vpl.push_back(B[i]);
	}

	f = true;

	while (vpl.size()>0 && f)
	{
		for (int i = vpl.size() - 1; i >= 0; i--) {
			if (vpl[i] == i+1) {
				vl.push_back(vpl[i]);
				vpl.erase(vpl.begin()+i);
				break;
			}
			else if(i==0)
			{
				f = false;
				break;
			}

		}

	}

	if(f){
		for (int i = vl.size() - 1; i >= 0; i--) {
			cout << vl[i] << endl;
		}
	}
	else {
		cout << -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;
int main(){
    int n,m;
    cin >> n >> m;
    int x[n];
    int modm[m];
    fill_n(modm,m,0);
    rep(i,n){
        cin >> x[i];
        modm[x[i]%m]++;
    }
    sort(x,x+n);
    int pairnum[m];
    fill_n(pairnum,m,0);
    int streak = 1;
    rep(i,n-1){
        if(x[i]==x[i+1]) streak++;
        else{
            pairnum[x[i]%m]+=(streak/2);
            streak=1;
        }
    }
    pairnum[x[n-1]%m]+=(streak/2);
    int ans = 0;
    rep(i,(m/2)+1){
        if(i==0){
            ans+=(modm[0]/2);
            modm[0]%=2;
        }
        else if(i==m/2 && m%2==0){
            ans+=(modm[i]/2);
            modm[i]%=2;
        }
        else{
            int tmp = min(modm[i],modm[m-i]);
            ans+=tmp;
            modm[i]-=tmp;
            modm[m-i]-=tmp;
        }
    }
    rep(i,m) ans+=min(modm[i]/2,pairnum[i]);
    cout << ans << endl;
}

Measured memory_bytes: 1408
N=int(input())
s,t,u=0,0,0
for i in list(map(int,input().split())):
    if i%4==0:
        s+=1
    elif i%2==0:
        t+=1
    else:
        u+=1
if u-s<=1 and (t==0 or u-s<1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14480
#include<iostream>
#include<string>
#include<map>
#include<sstream>
using namespace std;

int stoi(string s){
  stringstream ss;
  ss << s;
  int res;
  ss >> res;
  return res;
}

int main(){
  int n,x,y,t,z[1000][5];
  string s,name[1000];

  while(cin >> n, n){
    cin >> s;
    t = 0;
    for(int i=1;i<(int)s.size();i++){

      if(s[i] != '/'){
	string tmp = "";
	while(i<(int)s.size() && s[i] != '>'){
	  tmp += s[i];
	  i++;
	}
	name[t] = tmp;
	for(int j=0;j<4;j++){
	  i++;
	  tmp = "";
	  while(s[i] != ',' && s[i] != '<'){
	    tmp += s[i];
	    i++;
	  }
	  z[t][j] = stoi(tmp);
	}
	t++;
      }else{
	while(i<(int)s.size() && s[i]!='<')i++;
      }
    }

    for(int i=0;i<n;i++){
      cin >> x >> y;

      int m = -1;
      for(int j=0;j<t;j++){
	if(z[j][0]<=x && x<=z[j][2] && z[j][1]<=y && y<=z[j][3]){
	  if(m<0 || (z[m][0]<z[j][0] && z[j][2]<z[m][2] && 
		     z[m][1]<z[j][1] && z[j][3]<z[m][3]) )m = j;
	} 
      }
      
      if(m<0)cout << "OUT OF MAIN PANEL 1" << endl;
      else{
	int num = 0;
	for(int j=0;j<t;j++){
	  if(z[m][0]<z[j][0] && z[j][2]<z[m][2] && 
	     z[m][1]<z[j][1] && z[j][3]<z[m][3]){
	    bool f = true;
	    for(int k=0;k<t;k++){
	      if(z[m][0]<z[k][0] && z[k][2]<z[m][2] && 
		 z[m][1]<z[k][1] && z[k][3]<z[m][3]){
		if(z[k][0]<z[j][0] && z[j][2]<z[k][2] && 
		   z[k][1]<z[j][1] && z[j][3]<z[k][3]){
		  f = false;
		  break;
		}
	      }
	    }
	    if(f)num++;
	  }
	}
	
	cout << name[m] << " " << num << endl;
      }
    }
  }
}

Measured memory_bytes: 0
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    int visited[200001];

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,i,j,k;
            cin>>n>>k;
            vector<int> v,v2;
            ll ar[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            i=1;
            while(true)
            {
                if(visited[i]==1)
                    break;
                visited[i]=1;
                v.pb(i);
                i=ar[i];
            }
            int ct=0;
            for(j=0;j<v.size();++j)
            {
                if(v[j]==i)
                    break;
            }
            ct=j;
            for(;j<v.size();++j)
            {
                v2.pb(v[j]);
            }
            if(k<v.size())
            {
                cout<<v[k]<<endl;
                return 0;
            }
            k=k-ct;
            k=k%v2.size();
            cout<<v2[k]<<endl;
        }
        return 0;
    }


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

void main_()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    vector<int> costs;
    for (int ab_num = 0; ab_num <= 2 * 100000; ab_num += 2) {
        int a_num = max((X - ab_num / 2), 0);
        int b_num = max((Y - ab_num / 2), 0);
        int cost = a_num * A + b_num * B + ab_num * C;
        costs.push_back(cost);
    }

    cout << *min_element(begin(costs), end(costs)) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 892
n,m = map(int,input().split())
x = [int(v) for v in input().split()]
x.sort()
ans_list = []

for i in range(len(x)-1):
  ans_list.append(abs(x[i]-x[i+1]))

ans_list.sort()

for i in range(n-1):
  if len(ans_list) == 0:
    break
  ans_list.pop()
print(sum(ans_list))

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

int main(){
 int num,i=0;
 string a;
  cin>> num >> a;
  if(a.size()<=num){
  cout << a;
}else{
  for(;i<num;){
  cout << a[i];
  i++;
  }
  cout << "...";
  
  }  }


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    int x[N];
    rep(i, N) {
        cin >> x[i];
    }
    int T[N-K+1];
    
    rep(i, N-K+1) {
        if(x[i+K-1] < 0) {
            T[i] = -x[i];
        }
        else if(0 < x[i]) {
            T[i] = x[i+K-1];
        }
        else {
            int y = min(abs(x[i]), abs(x[i+K-1]));
            T[i] = y + x[i+K-1] - x[i];
        }
    }

    sort(T, T+N-K+1);

    cout << T[0];

    cout << endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        if(s.equals("Sunny")){
        	System.out.println("Cloudy");
        	
        }else if(s.equals("Cloudy")){
        	System.out.println("Rainy");
        	
        }else{
        	System.out.println("Sunny");
        	
        }
	}        
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int X;
        cin >> X;
        vector<Int> dp(X + 1);
        dp[0] = 1;
        for (int i = 100; i <= 105; ++i) {
            for (int j = 0; j <= X; ++j) {
                if (dp[j] && j + i <= X) {
                    dp[j + i] = 1;
                }
            }
        }
        cout << dp[X] << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1024
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
N = I()
ans = int(0)
L = LI()
L.sort()
Lmax = max(L)
Long = [0]*(Lmax+1)
for i in range(Lmax+1):
    k = int(0)
    while k<N and i+1>L[k] :
        Long[i] += 1
        k +=1

#sumL = [[0]*(Lmax+1) for _ in range(Lmax+1)]
#for i in range(Lmax+1):
#    for j in range(i+1,Lmax+1):
#        sumL[i][j] = sum(Long[i:(j+1)])

s = int(0)
t = int(0)
for i in range(N):
    for j in range(i+1,N):
#        s = abs(L[i] - L[j]) +1
        t = L[i] + L[j] -1
        count =int(0)
        count += max(Long[min(t,Lmax)]-j-1,0)
        ans += count

#        count += sumL[s][min(Lmax,t)]
#        if s<=L[i]<=t:
#            ans -=1
#        if s <= L[j] <= t:
#            ans -= 1
#        ans += max(count,0)
#        for k in range(j+1,N):
#            if s<=L[k]<=t:
#                ans +=1
#        print(s,t)

print(ans)

Measured memory_bytes: 41308
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t A, B, C; cin >> A >> B >> C;

int64_t cnt = 0;
while(A%2 == 0 && B%2 == 0 && C%2 == 0){
    int64_t a = A, b = B, c = C;
    A = (b + c) / 2;
    B = (a + c) / 2;
    C = (a + b) / 2;
    ++cnt;
    if (A == B && B == C && C == A){
        cout << "-1\n";
        return 0;
    }
}
cout << cnt << endl;


}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256