akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
from operator import itemgetter


class DisjointSet():
    def __init__(self, size):
        self.size = size
        self.rank = [None] * size
        self.parents = [None] * size
        for i in range(size):
            self.makeSet(i)

    def makeSet(self, x):
        self.parents[x] = x
        self.rank[x] = 0

    def findSet(self, x):
        if x != self.parents[x]:
            self.parents[x] = self.findSet(self.parents[x])
        return self.parents[x]

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.parents[y] = x
        else:
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1


if __name__ == '__main__':

    n, m = [int(s) for s in input().split()]
    E = []
    for _ in range(m):
        E.append([int(s) for s in input().split(" ")])

    def kruskal(n, E):
        E = sorted(E, key=itemgetter(2))
        totalCost = 0
        S = DisjointSet(n)
        # K = []

        for s, t, w in E:
            if S.findSet(s) != S.findSet(t):
                S.unite(s, t)
                # K.append([s,t,w])
                totalCost += w

        return totalCost

    print(kruskal(n, E))



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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll gcd(ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[i] - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g;
    cin>>a>>b;
    cout<<a+(b-a)*2<<endl;

    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
const int INF = 1000000000;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x.at(i);
  
  sort(x.begin(), x.end());
  int l = x.at(0);
  int r = x.at(n-1);
  
  int hp = INF;
  for (int j = l; j <= r; j++) {
    int k = 0;
    rep(i,n) k += (x.at(i) - j) * (x.at(i) - j);
    hp = min (hp, k);
  }
  
  cout << hp << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,a,b,c;
  bool flag=true;
  cin>>n>>a>>b>>c;
  vector<string> s(n);
  rep(i,n){
    cin>>s[i];
  }
  vector<char> res(n);
  queue<int> que;
  for(int i=0;i<n;++i){
    //standby
    if(!que.empty()){
      if(s[que.front()]==s[i]){
        que.pop();
      }
      else if(s[i]=="AC"){
        if(a==0&&c==0){
          if(s[que.front()]=="BC"){
            res[que.front()]='C';
            b-=2;
            c+=2;
          }
          que.pop();
        }
        else{
          que.pop();
        }
      }
      else if(s[i]=="BC"){
        if(b==0&&c==0){
          if(s[que.front()]=="AC"){
            res[que.front()]='C';
            a-=2;
            c+=2;
          }
          else if(s[que.front()]=="AB"){
            res[que.front()]='B';
            a-=2;
            b+=2;
          }
          que.pop();
        }
        else{
          que.pop();
        }
      }
      else{
        que.pop();
      }
    }
    //main fase
    if(s[i]=="AB"){
      if(a>b){
        --a;++b;
        res[i]='B';
      }
      else if(a<b){
        ++a;--b;
        res[i]='A';
      }
      else{
        if(a==0){
          flag=false;
        }
        else{
          ++a;--b;
          res[i]='A';
          que.push(i);
        }
      }
    }
    else if(s[i]=="AC"){
      if(a>c){
        --a;++c;
        res[i]='C';
      }
      else if(a<c){
        ++a;--c;
        res[i]='A';
      }
      else{
        if(a==0){
          flag=false;
        }
        else{
          ++a;--c;
          res[i]='A';
          que.push(i);
        }
      }
    }
    else if(s[i]=="BC"){
      if(b>c){
        --b;++c;
        res[i]='C';
      }
      else if(b<c){
        ++b;--c;
        res[i]='B';
      }
      else{
        if(b==0){
          flag=false;
        }
        else{
          ++b;--c;
          res[i]='B';
          que.push(i);
        }
      }
    }
  }
	if(flag){
    cout<<"Yes"<<endl;
    rep(i,n){
      cout<<res[i]<<"\n";
    }
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 6380
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};


int main() {
    ll a,b; cin >> a >> b;
    if(a<=9 && b<=9) cout << a*b << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
//スタート点,頂点数、辺を渡して、最短経路の配列を返す
int gcd(int a,int b){
    if(b == 0)return a;
    return gcd(b, a % b);
}
int main(){
    CIN(N);
    CIN(X);
    vector<int> vec;
    vec.pb(X);
    for(int a = 0;a < N;a++){
        CIN(b);
        vec.pb(b);
    }
    sort(ALL(vec));
    LL ans = vec.at(1)-vec.front();
    for(int a = 1;a < vec.size();a++){
        ans = gcd(ans,vec.at(a)-vec.at(a-1));
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 892
bing = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
bn = [int(input()) for _ in range(n)]
for n in bn:
  for i in range(3):
    for j in range(3):
      if bing[i][j]==n:
        bing[i][j]=0
        continue

for i in range(3):
  if bing[i][0]==bing[i][1]==bing[i][2]:
    print('Yes')
    quit()
  if bing[0][i]==bing[1][i]==bing[2][i]:
    print('Yes')
    quit()

if bing[0][0]==bing[1][1]==bing[2][2]:
  print('Yes')
  quit()
if bing[2][0]==bing[1][1]==bing[0][2]:
  print('Yes')
  quit()

print('No')


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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M;/* your task */ }
int h2(int key){ return 1+(key%(M-1));/* your task */ }

int find(char str[]){
  long long key,i,n;
  key=getKey(str);
  for(i=0;;i++){
    n=(h1(key)+i*h2(key))%M;
    if(strcmp(H[n],str)==0) return 1;
    else if(strlen(H[n])==0) return 0;
  }
  return 0;

}

int insert(char str[]){
  long long key,i,n;
   
  key = getKey(str);
   for ( i = 0; ; i++ ){
     n = (h1(key) + i * h2(key)) % M;
     
    if( strcmp(H[n],str) == 0 ) {
      return 1;
    }
    else if ( strlen(H[n]) == 0 ){
      strcpy(H[n], str);
      return 0;  
    }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int cnt[13],vis[24];

int count(){
    int mi=101010;
    rep(i,24) rep(j,24){
        if(vis[i] && vis[j] && i!=j){
            int d1=abs(i-j);
            int d2=24-d1;
            int d=min(d1,d2);
            mi=min(mi,d);
        }
    }
    return mi;
}

int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n) cin>>d[i];

    rep(i,n) cnt[d[i]]++;
    if(cnt[0]){
        cout<<0<<endl;
        return 0;
    }
    vis[0]=1;

    vector<int> v;
    for(int i=1;i<12;i++){
        if(cnt[i]==1) v.push_back(i);
        else if(cnt[i]==2) vis[i]=vis[24-i]=1;
        else if(2<cnt[i]){
            cout<<0<<endl;
            return 0;
        }
    }

    if(cnt[12]==1) vis[12]=1;
    else if(cnt[12]>=2){
        cout<<0<<endl;
        return 0;
    }

    int m=v.size();
    if(m==0){
        cout<<count()<<endl;
        return 0;
    }
    
    int ans=0;
    rep(msk,1<<m){
        rep(i,m){
            if(msk & 1<<i) vis[v[i]]=1, vis[24-v[i]]=0;
            else vis[v[i]]=0, vis[24-v[i]]=1;
        }
        ans=max(ans,count());
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3644
n=int(input())
a=list(map(int, input().split()))
b=[0]*n

for i in range(n, 0, -1):
    if sum(b[i-1::i])%2 != a[i-1]:
        b[i-1]=1

print(sum(b))
if sum(b)!=0:
    for i in range(n):
        if b[i]==1:
            print(i+1, end=" ")


Measured memory_bytes: 69468
#include <iostream>
#include<string.h>

using namespace std;

int main() {
	string S;
	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
		cout << "Bad" << endl;
	}
	else cout << "Good" << endl;
		return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int N=scan.nextInt();
		int M=scan.nextInt();
		long K=scan.nextLong();

		long[] A = new long[N+1];
	    long[] B = new long[M+1];
	     A[0]=0;
	     B[0]=0;

	     for(int i=1;i<=N;i++){
	       A[i] = A[i-1]+scan.nextLong();
	     }
	     for(int i=1;i<=M;i++){
	       B[i] = B[i-1]+scan.nextLong();
	     }


	      int j = M;

	      int count = 0;
	      for(int i=0;i<=N;i++){
	        if(A[i]>K){
	          break;
	        }
	        while(A[i]+B[j]>K){
	          j--;
	        }
	         count = Math.max(count,i+j);
	      }
			System.out.println(count);
	}
}


Measured memory_bytes: 63288
#include <stdio.h>
#include <stdbool.h>

int min(int a,int b){return a > b ? b : a;}

int main()
{
    int n,k,x[100];
    scanf("%d %d",&n,&k);

    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d",&x[i]);
    }

    int ans = 0;
    for (i = 0; i < n; i++)
    {
        ans += 2 * min(x[i],k - x[i]);
    }
    printf("%d",ans);
}

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

typedef pair <int, int> ii;

const int Maxm = 100005;

int n;
int a[Maxm];
int freq[Maxm];
ii best[2][2];

void Get(int from)
{
    fill(freq, freq + Maxm, 0);
    for (int i = from; i < n; i += 2)
        freq[a[i]]++;
    for (int i = 1; i < Maxm; i++)
        if (ii(freq[i], i) > best[from][0])
            best[from][1] = best[from][0], best[from][0] = ii(freq[i], i);
        else if (ii(freq[i], i) > best[from][1])
            best[from][1] = ii(freq[i], i);
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    Get(0); Get(1);
    int res = 0;
    if (best[0][0].second == best[1][0].second)
        res = max(best[0][0].first + best[1][1].first,
                  best[0][1].first + best[1][0].first);
    else res = best[0][0].first + best[1][0].first;
    printf("%d\n", n - res);
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Two Anagrams
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            string sortedS = SortCharacters(s);
            string sortedT = SortCharacters(t, true);

            if (String.Compare(sortedT, sortedS) > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static string SortCharacters(string s, bool isDescending = false)
        {
            var chars = s.ToCharArray();
            var query = new List<char>();
            
            if (!isDescending)
            {
                query = chars.OrderBy(c => c).ToList();
            }
            else
            {
                query = chars.OrderByDescending(c => c).ToList();
            }

            return String.Join("", query);
        }
    }
}

Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int32_t main()
{
	IOS;
	int a;
	double d;
	cin >> a >> d;
	int b = round(d * 100);
	int ans = a * b;
	ans /= 100;
	cout << ans;
	return 0;
}


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

int main(void){
  int n,C=0;
  while(cin>>n,n){
    int a[10][10];
    int x=0,y=0,c=1;
    int dx=1,dy=-1;
    a[y][x]=c++;
    while(!(x==n-1&&y==n-1)){
      if(n<=x+dx){++y;a[y][x]=c++;dx=-1;dy=1;continue;}
      else if(n<=y+dy){++x;a[y][x]=c++;dx=1;dy=-1;continue;}
      else if(y+dy<0){++x;a[y][x]=c++;dx=-1;dy=1;continue;}
      else if(x+dx<0){++y;a[y][x]=c++;dx=1;dy=-1;continue;}
      x+=dx;
      y+=dy;
      a[y][x]=c++;
    }
    cout<<"Case "<<++C<<":"<<endl;
    for(int i=0;i<n;++i){
    	for(int j=0;j<n;++j){
    		printf("%3d",a[i][j]);
    	}
    	puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 1204
r, c = gets.split.map(&:to_i)
arr = Array.new(r+1).map{ Array.new(c+1, 0) }

for i in 0..r-1 
    arr[i] = gets.split.map(&:to_i)
    arr[i][c] = 0
end

for i in 0..r-1 
    for j in 0..c-1  
        arr[i][c] += arr[i][j]
end
end

for i in 0..c 
    for j in 0..r-1 
        arr[r][i] += arr[j][i] 
    end
end


for i in 0..r do
    puts arr[i].join(" ")
end


Measured memory_bytes: 7108
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
  int H, N;
  bool TF = false;
  char *ans;

  cin >> H >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int i = 0;
  while (i < N) {
    H = H - A[i];
    i++;
    if (H <= 0) { TF = true; break; }
  }

  if (TF == true) {
    ans = (char *)malloc(sizeof("Yes"));
    strcpy(ans, "Yes");
  }
  else {
    ans = (char *)malloc(sizeof("No"));
    strcpy(ans, "No");
  }

  cout << ans << endl;

  free(ans);

  return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N; string S;
  cin >> N; cin >> S;
  
  ll red=0, green=0, blue=0;
  for(int i=0; i<N; i++){
    if(S[i]=='R'){
      red ++; 
    }else if(S[i]=='G'){
      green ++; 
    }else{
      blue ++; 
    }
  }
  
  //main
  ll ans = red*green*blue;
  //cout << ans << endl;
  for(int i=0; i<N; i++){
    if(S[i]=='G'){
      for(int j=0; j<N; j++){
        if(S[j]=='B'){
          if(i>j){
            if((i-j-1)%2==1 && S[(i+j)/2]=='R'){
              ans -= 1; 
            }
            if(0<=2*j-i && 2*j-i<=N-1 && S[2*j-i]=='R'){
              ans -= 1; 
            }
            if(0<=2*i-j && 2*i-j<=N-1 && S[2*i-j]=='R'){
              ans -= 1;
            }
          }else if(i<j){
            if((j-i-1)%2==1 && S[(i+j)/2]=='R'){
              ans -= 1; 
            }
            if(0<=2*i-j && 2*i-j<=N-1 && S[2*i-j]=='R'){
              ans -= 1; 
            }
            if(0<=2*j-i && 2*j-i<=N-1 && S[2*j-i]=='R'){
              ans -= 1;
            }
          }
        }
      }
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3656
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
w = np.zeros((N, 3), dtype=int)
for i in range(N):
  w[i, :] = list(map(int, input().split()))
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1,N+1):
  dp[i][0] = max([dp[i][0], dp[i-1][1]+w[i-1][0], dp[i-1][2]+w[i-1][0]]) 
  dp[i][1] = max([dp[i][1], dp[i-1][2]+w[i-1][1], dp[i-1][0]+w[i-1][1]]) 
  dp[i][2] = max([dp[i][2], dp[i-1][0]+w[i-1][2], dp[i-1][1]+w[i-1][2]]) 
print(max(dp[N, :]))

Measured memory_bytes: 17116
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int main (){
	int NNN,KKK;
	cin >> NNN >> KKK;
	int a;
	int where_one=0;
	rep(i,NNN){
		cin >>a;
		if(a==1){
			where_one = i;
		}
	}
	if(KKK==2){
		cout << NNN -1 << endl;
		return 0;
	}
	if(KKK==NNN){
		cout << "1" << endl;
		return 0;
	}
	//左右の数字
	int wl = where_one;
	int wr = NNN-where_one-1;

	int left,right;

	//左から詰めていくトキ
	int ansl = 0;
	int twr = wr;
	if(wl == 0){
		left = 0;
	}else if(wl<KKK){
		left = 1;
		twr = twr - (KKK - wl - 1);
	}else if(wl%(KKK-1)==0){
		left = wl/(KKK-1);
	}else{
		left = (wl + (KKK-1) - (wl%(KKK-1)))/(KKK-1);
		twr = twr - ((KKK-1)-(wl%(KKK-1)));
	}
	if(twr <= 0){
		right = 0;
	}else if(twr<KKK){
		right = 1;
	}else if(twr%(KKK-1)==0){
		right = twr/(KKK-1);
	}else{
		right = (twr + (KKK-1) - (twr%(KKK-1)))/(KKK-1);
	}
	ansl = right + left;

	cout << ansl << endl;

	return 0;
}


Measured memory_bytes: 256
declare var require: (x: string) => any;
 
function Main(input: string[]) {
  const N = parseInt(input[0]);
  let flag: boolean = false;
  for (var a = 0; a <= N / 4; a++) {
    if ((N - a * 4) % 7 == 0) {
      flag = true;
    }
  }
  if(flag) {
    console.log('Yes') 
  } else {
    console.log('No')
  }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


Measured memory_bytes: 7372
s = str(input())
ans = [0]*2020
a = 0
po = 0
aaa = 0
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

for i in range(len(s)):
    a += int(s[len(s)-i-1]) * power_func(10,po,2019)
    a = a % 2019
    ans[a] += 1
    po += 1
    if a == 0:
        aaa += 1
for i in range(2020):
    aaa += ans[i] * (ans[i]-1)//2
print(aaa)

Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

#define N 200001
vector<int> G[N],rG[N],g;
bool u[N];
int n,cmp[N];
  
void add_edge(int x,int y){G[x].push_back(y);rG[y].push_back(x);}
void dfs(int x){u[x]=1;rep(i,G[x].size())if(!u[G[x][i]])dfs(G[x][i]);g.push_back(x);} 
void rdfs(int x,int k){u[x]=1;cmp[x]=k;rep(i,rG[x].size())if(!u[rG[x][i]])rdfs(rG[x][i],k);}
int scc() {
  mem(u);g.clear();rep(i,n)if(!u[i])dfs(i);mem(u);
  int k=0;rrep(i,g.size())if(!u[g[i]])rdfs(g[i],k++);return k;
}

void Main() {
  int m;
  cin >> n >> m;
  vector<int> v[n];
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    add_edge(x,y);
  }
  scc();
  rep(i,n) {
    bool f=0;
    rep(j,n) {
      if(cmp[i]==cmp[j]) {
        if(f) cout << " ";
        cout << j+1;
        f=1;
      }
    }
    ln;
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 13900
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		StringBuilder card = new StringBuilder();
		StringBuilder answer = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		//n????????¢?????????????????????????????????????????????StringBuilder?????\??????
		card.append(scan.nextLine());
		//?????£?????????????????°
		int shuffle = Integer.parseInt(scan.nextLine());
		//?????£????????????????????°
		String h = scan.nextLine();
		int i = 0;
		int w = 0;
		String hoge = "";
		
		while(true) {
			while(i < shuffle) {
				card.append( card.substring(0, Integer.parseInt(h)) );
				card.delete(0, Integer.parseInt(h));
				if(h.equals("-") || i == (shuffle - 1)){
					//?????£????????????????????£???????????????answer???????´?
					answer.append(card.toString() + "\n");
					break;
				}else{
					h = scan.nextLine();
				}
				i++;
			}
			//?¬???????????????????????????????while??????????????????
			hoge = scan.nextLine();
			if( i == (shuffle - 1) && hoge.equals("-")){
				break;
			}else{
				i = 0;
				card.delete(0, card.length());
				card.append(hoge);
				shuffle = Integer.parseInt(scan.nextLine());
				h = scan.nextLine();
			}
		}
		System.out.print(answer.toString());
	}
}

Measured memory_bytes: 17300
<?php
  

//$abc = explode(" ",trim(fgets(STDIN)));
fscanf(STDIN,"%d %d %d %d %d",$a,$b,$c,$d,$e);

$cheap = min(($a+$b),2*$c);
$sum=0;
$sum=0;

for($i=0;$i<min($d,$e);$i++){
  $sum+=$cheap;
}


for($i=0;$i<abs($d-$e);$i++){
  if($d<$e){
      $sum+=$b;
  }else{
    $sum+=$a;
  }
}

for($i=0;$i<max($d,$e);$i++){
  $sum2+=2*$c;
}

echo min($sum,$sum2)."\n";




Measured memory_bytes: 4604
mod = 10**9+7
N = int(input())
A = [int(x) for x in input().split()]
se = []
c = sum(A) - N * (N + 1) / 2
for i in range(len(A)):
    if A[i] == c:
        se.append(i)
l = se[0]
r = se[1]
import math

print(N)

factorial = [1]
inverse = [1]
for i in range(1, N + 2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append((pow(factorial[-1], mod - 2, mod)))


def nCr(n, r):
    if n < r or n == 0 or r == 0:
        return 0
    return factorial[n] * inverse[r] * inverse[n - r] % mod



for i in range(2,N+2):
    k = nCr(N+1, i)
    
    t = nCr(l+N-r,i-1)
    res  = k -t
    print(res % mod)


Measured memory_bytes: 17112
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  ll ans = INF;
  for (int i = 0; i + 2 < S.size(); i++) {
    string X = S.substr(i, 3);
    ans = min(ans, abs(stoll(X) - 753LL));
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int a, b , c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(k >= a){
        ans += a;
        k -= a;
    }
    else{
        ans += k;
        k = 0;
    }
    if(k >= b){
        ans += 0;
        k -= b;
    }
    else{
        ans += k;
        k = 0;
    }
    if(k >= c){
        ans -= c;
    }
    else{
        ans -= k;
    }
    cout << ans;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int gcd(int,int);

int main(){
    int k; cin >> k;
    int sum = 0;
    for(int a=1;a<=k;++a){
        for(int b=1;b<=k;++b){
            for(int c=1;c<=k;++c){
                int r = gcd(a,b);
                sum += gcd(c,r);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

int gcd(int a, int b)
{
    if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll n,p,c=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>p;
        if(p!=i) c++;
    }
    cout<<(c==0 ||c==2?"YES":"NO")<<endl;
    return 0;
}

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

int main(){
  long long int ans = 0;
  int N, temp[100010], ma = 0, i, j,temp3;
  cin>>N;

  
  ma = temp[0];
  for(i = 0; i < N; i++){
    cin>>temp[i];
    ma = max(ma, temp[i]);
  }
  for(i = 0; i < N; i++){
    temp3 = ma;
    for(j = 1; j * j <= ma; j++){
      if(ma%j == 0){
	if(j >= temp[i])temp3 = min(j - temp[i], temp3);
	if(ma/j >= temp[i])temp3 = min(ma/j - temp[i], temp3);
	} 
    }
    ans += temp3;
  }
  
  cout<<ans<<endl;
  return 0;
}
  



Measured memory_bytes: 3464
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   char s[201];scanf("%s",s);
   int ans=0;
   int flag = 1;
   for(int i = 0;i < strlen(s);i+=2){
      ans += 2;
      for(int j = 0;j < (strlen(s)-ans)/2;j++){
         //printf("j=%d,%c == %c\n",j,s[j],s[(strlen(s)-ans)/2+j]);
         if(s[j] != s[(strlen(s)-ans)/2+j]){
            flag = 0;
            break;
         }
      }
      if(flag == 1){
         printf("%d",strlen(s)-ans);
         return 0;
      }
      flag = 1;
   }
}

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

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

  int H = 0, maxH = 0, ans = 0;
  while (N--) {
    cin >> H;
    if (H >= maxH) ans++;
    maxH = max(H, maxH);
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    int xmin = 0;
    int xmax = W;
    int ymin = 0;
    int ymax = H;

    for (int i=0; i<N; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) xmin = max(xmin, x);
        else if (a == 2) xmax = min(xmax, x);
        else if (a == 3) ymin = max(ymin, y);
        else ymax = min(ymax, y);
    }
    if ((xmax < xmin) || (ymax < ymin)) cout << 0 << endl;
    else cout << (xmax - xmin) * (ymax - ymin) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て

int gcd(int a,int b);
int main() {
	int r,g,b,n,sum=0,ans=0;
	cin>>r>>g>>b>>n;

	for(int i=0;i<=n/r;i++){
		for(int k=0;k<=n/g;k++){
				sum=   i*r + g*k;
				//cout<<sum<<endl;
				if((n-sum)%b==0 &&sum<=n)
					ans++;
			//}
		}
	}
	cout<<ans;
}







int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
        char i1, i2, c;
        bool ball[3] = {false};
        ball[0] = true;
        while(cin >> i1){
                cin >> c;
                cin >> i2; 
                i1 -= 'A';
                i2 -= 'A';
                bool tmp = ball[i1];
                ball[i1] = ball[i2];
                ball[i2] = tmp;
        }   
        c = 0;
        while(!ball[c]){
                c++;
        }   
        cout << (char)(c+'A') << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char b;
  cin >> b;

  string s = "ATCG";
  for (int i = 0; i < 4; i++) {
    if (i % 2 == 0) {
      if (b == s[i]) {
        cout << s[i+1] << endl;
      } else {
        continue;
      }
    } else {
      if (b == s[i]) {
        cout << s[i-1] << endl;
      } else {
        continue;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
function main(arg) {
    arg = arg.split("\n")
    arg = parseInt(arg[0], 10)

    var flag = false
    for (var i = 0; i < 100; i++){
        var num = 4 * i
        if (num > arg) {
            break;
        }
        var sum = (arg - num)
        if ((sum % 7) === 0 ) {
            flag = true
            break
        }
    }
    if (flag) {
        console.log('Yes')
    } else {
        console.log('No')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

#define ll long long
#define mod 1000000007
#define inf 1001
vector<vector<char>> v;
vector<vector<ll>> dp;

ll ways(ll i, ll j){
	//base case
	if(i==0 && j==0){
		return 1;
	}
	//recursive case
	if(dp[i][j]!=-1){return dp[i][j];}

	ll op1=0, op2=0;

	if(j!=0 && v[i][j-1]=='.'){
		op1 = ways(i, j-1);
	}
	if(i!=0 && v[i-1][j]=='.'){
		op2 = ways(i-1, j);
	}
	dp[i][j]= (op1 + op2)%mod;
	return dp[i][j];
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll h, w;
	cin>>h>>w;
	v = vector<vector<char>> (h, vector<char>(w, ' '));
	dp = vector<vector<ll>> (h, vector<ll>(w, -1));
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>v[i][j];
		}
	}
	cout<<ways(h-1, w-1);
}

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

int main(){
    string S;
    cin >> S;
    if('R' == S.at(0) && 'R' == S.at(1) && 'R' == S.at(2)) cout << 3 << endl;
    else if('R' != S.at(0) && 'R' != S.at(1) && 'R' != S.at(2)) cout << 0 << endl;
    else if('S' == S.at(1) || ('S' == S.at(0) && 'R' == S.at(1) && 'S' == S.at(2))) cout << 1 << endl;
    else cout << 2 << endl;
}



Measured memory_bytes: 3636
//Coded by tzc_wk
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),m=read();
char s[105][105];
int dp[105][105][105][105][2];
inline int dfs(int x1,int y1,int x2,int y2,int t){
	if(x1==x2&&y1==y2){
		return (s[x1][y1]=='#')?1:0;
	}
	if(~dp[x1][y1][x2][y2][t])	return dp[x1][y1][x2][y2][t];
	dp[x1][y1][x2][y2][t]=0x3f3f3f3f;
	if(s[x2][y2]=='.'){
		if(x1!=x2)	dp[x1][y1][x2][y2][t]=min(dp[x1][y1][x2][y2][t],dfs(x1,y1,x2-1,y2,0));
		if(y1!=y2)	dp[x1][y1][x2][y2][t]=min(dp[x1][y1][x2][y2][t],dfs(x1,y1,x2,y2-1,1));
	}
	if(s[x2][y2]=='#'){
		if(x1!=x2)	dp[x1][y1][x2][y2][t]=min(dp[x1][y1][x2][y2][t],dfs(x1,y1,x2-1,y2,0)+(s[x2-1][y2]=='.'));
		if(y1!=y2)	dp[x1][y1][x2][y2][t]=min(dp[x1][y1][x2][y2][t],dfs(x1,y1,x2,y2-1,1)+(s[x2][y2-1]=='.'));
	}
//	cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<t<<" "<<dp[x1][y1][x2][y2][t]<<endl;
	return dp[x1][y1][x2][y2][t];
}
signed main(){
	fz(i,1,n)	cin>>s[i]+1;
	fill1(dp);
	int x=dfs(1,1,n,m,0),y=dfs(1,1,n,m,1);
	cout<<min(x,y)<<endl;
//	cout<<dfs(1,1,n,m,0)<<endl;
//	cout<<dfs(1,1,n,m,1)<<endl;
	return 0;
}

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

import sys
import os

n = int(input())

BASE = list(map(int, input().split()))
answers = []

for v in [0, 1]:
    A = BASE[:]

    # assume plus start
    sum_value = 0
    add_num = 0

    for i, a in enumerate(A):
        sum_value += a

        # 偶数項までの和は正
        if i % 2 == v:
            if sum_value <= 0:
                A[i] = A[i] - sum_value + 1
                add_num += (-sum_value + 1)
                sum_value = 1

        # 奇数までの和は負
        else:
            if sum_value >= 0:
                A[i] = A[i] - sum_value - 1
                add_num += (sum_value + 1)
                sum_value = -1
    #print(add_num)
    answers.append(add_num)

print(min(answers))

Measured memory_bytes: 14468
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n,m,proper=0,sum=0;
  cin>>n>>m;
  int a[n];
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  rep(i,n){
    if(4*m*a[i]>=sum){
      proper++;
    }
  }
  if(proper>=m){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

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

using namespace std;

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  if(k%2==0){
  for(int i=0;i!=k/2;i++){
    if(a%2==1){
      a--;
    }
    b=b+(a/2);
    a=a/2;
    if(b%2==1){
      b--;
    }
    a=a+(b/2);
    b=b/2;
  }
}
else{
  for(int i=0;i!=(k-1)/2;i++){
    if(a%2==1){
      a--;
    }
    b=b+(a/2);
    a=a/2;
    if(b%2==1){
      b--;
    }
    a=a+(b/2);
    b=b/2;
  }
  if(a%2==1){
    a--;
  }
  b=b+(a/2);
  a=a/2;
}
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

// int m[10000];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a;
    scanf("%d", &a);
    n -= a;
  }
  printf("%d", n < 0 ? -1 : n);
  return 0;
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,sum=0,big=0,tmp;cin>>N;
  while(N--){
    cin>>tmp;
    sum+=tmp;
    big=max(big,tmp);
  }
  if(big*2<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j;
  double s=0;
  cin>>n;
  vector<double> x(n),y(n);
  for(i=0;i<n;i++) cin>>x.at(i)>>y.at(i);
  for(i=0;i<n-1;i++) for(j=i+1;j<n;j++)
    s+=pow((x.at(j)-x.at(i))*(x.at(j)-x.at(i))+(y.at(j)-y.at(i))*(y.at(j)-y.at(i)),0.5);
  s*=2.0/n;
  cout<<fixed<<setprecision(10)<<s<<endl;
}

Measured memory_bytes: 384
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0)
    Dim ans=If(a Mod 2=0,a,a*2)
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
let readInt () = stdin.ReadLine() |> int

()
|> readInt
|> Array.zeroCreate
|> Array.map (fun _ ->
    stdin.ReadLine().Split(" ")
    |> (fun [| c; s |] -> (c, int s * -1)))
|> Array.indexed
|> Array.sortBy (fun (_, (c, s)) -> (c, s))
|> Array.map (fun (i, _) -> i + 1 |> string)
|> String.concat "\n"
|> printfn "%s"


Measured memory_bytes: 29968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll a[3 * n];
    rep(i, 3 * n) {
        cin >> a[i];
    }
    priority_queue<ll, vector<ll>, greater<ll> > lque;
    ll lsum[3 * n + 1] = {};
    rep(i, 3 * n) {
        lsum[i + 1] = lsum[i] + a[i];
        lque.emplace(a[i]);
        if ((int)lque.size() <= n) continue;
        lsum[i + 1] -= lque.top();
        lque.pop();
    }
    ll ans = -LINF;
    priority_queue<ll> rque;
    ll rsum = 0;
    for (int i = 3 * n - 1; i >= n; i--) {
        rsum += a[i];
        rque.emplace(a[i]);
        if ((int)rque.size() > n) {
            rsum -= rque.top();
            rque.pop();
        }
        if (i <= 2 * n){
            ans = max(ans, lsum[i] - rsum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10296
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n;){
    double p[40];
    for(int i=0;i<n;i++){
      cin>>p[i];
    }
    double area[40][40];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	area[i][j]=sin(fmod(p[j]+1-p[i],1)*4*acos(0))/2;
      }
    }
    double dp[41][40][40];
    fill(dp[0][0],dp[41][0],-1e9);
    for(int i=0;i<n;i++){
      dp[1][i][i]=0;
    }
    for(int i=2;i<=m;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<j;k++){
	  for(int l=0;l<n;l++){
	    dp[i][j][l]=max(dp[i][j][l],dp[i-1][k][l]+area[k][j]);
	  }
	}
      }
    }
    double ma=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	ma=max(ma,dp[m][i][j]+area[i][j]);
      }
    }
    cout.precision(6);
    cout<<fixed<<ma<<endl;
  }
}
    

Measured memory_bytes: 1872
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    long x;
    cin >> x;

    long price = 100;
    for (int i = 1; ; i++) {
        price = (long) (price * 1.01);
        if (price >= x) {
            cout << i;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int ans=0;
    while(n>0)
    {
        n/=m;
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, count=0, sum=1, target;
    cin >> n;
    //vector<int> a(n);
    
    for(int i=0; i<n; i++){
        cin >> target;
        if (sum == target) {
            sum++;
        } else {
            count++;
        }
    }
    
    if (count == n) {
        cout << "-1" << endl;
    } else {
        cout << count << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define MAX 100000000000000
#define INF 1000000 
#define M 1000000007
#define Pi 3.14159265 
using namespace std; 
int main(){ 
   FAST
   ll n;
   cin>>n;
   bool ok = false;
   ll prev = 0;
   while(n--){
      ll x,y;
      cin>>x>>y;
      if(x == y){
         prev++;
      }
      else{
         prev = 0;
      }
      if(prev >= 3)ok = true;
   }
   if(ok == true) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
} 

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

int main(){
	int n; cin >> n;
	string buf;
	map<string, int> t;
	for (int i = 0; i < n; i++) {
		cin >> buf;
		sort(buf.begin(), buf.end());
		if (t.count(buf) == 0) t.insert(make_pair(buf, 1));
		else t.at(buf)++;
	}
	long long a = 0;
	for (auto i : t) {
		a += (long long)i.second * (i.second - 1) / 2;
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 11136
def various_sushi(N: int, K: int, TD: list) -> int:
    _TD = sorted(TD, key=lambda x: x[1], reverse=True)

    tops, others = [], []
    tops_sum, others_sum = 0, 0
    kind = set()
    res = 0
    q = []
    for t, d in _TD[:K]:
        if t not in kind:
            kind.add(t)
        else:
            q.append(d)
        res += d

    max_d = res + len(kind) ** 2
    temp = max_d
    count = len(q)
    for t, d in _TD[K:]:
        if count == 0:
            break
        if t not in kind:
            temp += -q.pop() + d + len(kind) * 2 + 1
            kind.add(t)
            max_d = max(max_d, temp)
            count -= 1

    return max_d


if __name__ == "__main__":
    N, K = [int(s) for s in input().split()]
    TD = [tuple(int(s) for s in input().split()) for _ in range(N)]

    ans = various_sushi(N, K, TD)
    print(ans)


Measured memory_bytes: 20748
#![allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
    n: usize,
    al: [usize; n]
    }
    let mut l = vec![0; n];
    let mut ans:usize = 0;
    for i in 0..n{
        let a = al[i];
        if a + i < n {
            l[i + a] += 1;
        }
        if i >= a {
            ans += l[i - a];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6688
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N):
	if A[i]+A[i+1]<=B[i]:
		count+=A[i]+A[i+1]
		B[i]-=A[i]+A[i+1]
		A[i]=0
		A[i+1]=0
	elif A[i]<=B[i] and A[i]+A[i+1]>B[i]:
		count+=B[i]
		B[i]-=A[i]
		A[i+1]-=B[i]
		A[i]=0
		B[i]=0
	else:
		count+=B[i]
print(count)

Measured memory_bytes: 19004
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func isSame(s, t string, n, begin int) bool {
	for i := begin; i < n; i++ {
		if s[i] != t[i-begin] {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := next()
	t := next()

	for i := 0; i < n; i++ {
		if isSame(s, t, n, i) {
			fmt.Println(i + n)
			return
		}
	}
	fmt.Println(2 * n)
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
   int money,n,i;
   money=100000;
   scanf("%d",&n);
   for(i=0;i<n;i++){
      money=money*1.05;
      money=money+999;
      money=money*0.001,money=money*1000;
   }
   printf("%d\n",money);
   return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b && b!=c) || (b==c && c!=a) || (a==c && b!=c))
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Thu Mar 12 07:58:51 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

S = ns()
N = len(S)

c = Counter(S)
print("Yes" if len(c) == N else "No")

Measured memory_bytes: 3316