akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int K = sc.nextInt();
      
        long h[] = new long[N];
      
      long th = 0;

      long ans = 0;
      for(int i=0; i<N; i++){
          h[i] =sc.nextLong();
          th +=h[i];
      }
    Arrays.sort(h);
        if(K>0){
      for(int j=0; j<N-K; j++){

        ans +=h[j];
     }  System.out.println(ans);
          
        }else{ System.out.println(th);}
    }
}

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

int main(){
  int N, K, ans=0;
  int h[100001];
  cin>>N>>K;
  for(int i=1; i<=N; i++) cin>>h[i];
  for(int i=1; i<=N; i++) {
    if(h[i]>=K) ans++;
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 640
s = input()
n = len(s)

now = '$'
ans = 0
flg = True

while s != '':
    if s[0] != now:
        ans += 1
        now = s[0]
        s = s[1:]
    else:
        if now == s[:2]:
            now = s[:2]
            s = s[2:]
        else:
            ans += 1
            now = s[:2]
            s = s[2:]
            
print(ans)
    

Measured memory_bytes: 3500
d,g = map(int,input().split())
PC = [list(map(int,input().split())) for _ in range(d)]
cost = 10000000

for j in range(2**d):
    temp = 0
    score = 0
    bit = format(j,"0"+str(d)+"b")
    for i in range(d):
        if bit[i] == "1":
            score += PC[i][0]*(i+1)*100 + PC[i][1]
            temp += PC[i][0]
    if score >= g:
        if temp < cost:
            cost = temp
    else:
        for i in range(d-1,-1,-1):
            if bit[i] == "0":
                p,c = PC[i]
                point = 100*(i+1)
                for v in range(p):
                    score += point
                    temp += 1
                    if score >= g:
                        break
                break
        if score >= g and temp < cost:
            cost = temp
print(cost)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct order{
  string dealer, type, commodity;
  int price;
  order(string d, string t, string c, int p) :
    dealer(d), type(t), commodity(c), price(p) {}
};

order parse(){
  string d, t, c;
  int p;
  cin>>d>>t>>c>>p;
  return order(d, t, c, p);
}

int main(){
  int N;
  while(cin>>N && N){
    vector<order> orders;
    map<string, int> d_buy;
    map<string, int> d_sell;
    map<string, vector<int> > c_trade;
    REP(i, N){
      order od = parse();
      vector<order>::iterator tr_i = orders.end();
      d_buy[od.dealer] += 0;
      d_sell[od.dealer] += 0;
      if(od.type == "BUY"){
        FORIT(it, orders){
          if((it->type == "SELL" && it->commodity == od.commodity && it->price <= od.price && it->dealer != od.dealer)
              && (tr_i == orders.end() || tr_i->price > it->price)){
            tr_i = it;
          }
        }
        if(tr_i != orders.end()){
          int price = (od.price + tr_i->price) / 2;
          //printf("%s buy %s from %s by %d yen\n", od.dealer.c_str(), od.commodity.c_str(), tr_i->dealer.c_str(), price);
          d_buy[od.dealer] += price;
          d_sell[tr_i->dealer] += price;
          c_trade[od.commodity].push_back(price);
          orders.erase(tr_i);
        }else{
          orders.push_back(od);
        }
      }else{
        FORIT(it, orders){
          if((it->type == "BUY" && it->commodity == od.commodity && it->price >= od.price && it->dealer != od.dealer)
              && (tr_i == orders.end() || tr_i->price < it->price)){
            tr_i = it;
          }
        }
        if(tr_i != orders.end()){
          int price = (od.price + tr_i->price) / 2;
          //printf("%s sell %s to %s by %d yen\n", od.dealer.c_str(), od.commodity.c_str(), tr_i->dealer.c_str(), price);
          d_sell[od.dealer] += price;
          d_buy[tr_i->dealer] += price;
          c_trade[od.commodity].push_back(price);
          orders.erase(tr_i);
        }else{
          orders.push_back(od);
        }
      }
    }
    //cout<<"-"<<endl;
    FORIT(it, c_trade){
      string name = it->first;
      vector<int> v = it->second;
      sort(v.begin(), v.end());
      int a = v.front();
      int c = v.back();
      int b = 0;
      REP(i, v.size()) b += v[i];
      b /= v.size();
      printf("%s %d %d %d\n", name.c_str(), a, b, c);
    }
    cout<<"--"<<endl;
    FORIT(it, d_sell){
      string name = it->first;
      printf("%s %d %d\n", name.c_str(), d_buy[it->first], it->second);
    }
    cout<<"----------"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class MainProgram
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            int n = input.Length - input.Replace("1", "").Length;

            // 出力
            Console.WriteLine(n);
        }
    }
}

Measured memory_bytes: 11092
def slove():
    import sys
    input = sys.stdin.readline
    a, b, k = list(map(int, input().rstrip('\n').split()))
    ans = []
    for i in range(a, min(a + k, b+1)):
        if i not in ans:
            ans.append(i)
    for i in range(b, max(b - k, a-1), -1):
        if i not in ans:
            ans.append(i)
    ans.sort()
    print(*ans, sep="\n")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string S,T;cin>>S>>T;
    int s=0;
    if(S.size()==T.size())s=1;
    for(int i=0;i<S.size();i++){
        if (S[i]!=T[i]) s=1;
    }

    if(s==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

}


Measured memory_bytes: 3628
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

ll int mod_inverse(int a,int M){
	int x=M-2;
	ll int temp=a;
	ll int ret=1;
	//a^(MOD-1)==1(mod MOD)を利用
	//a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める

	while(x!=0){
		if(x%2==1){
			ret=(ret*temp)%M;
		}
		temp=(temp*temp)%M;
		x=x/2;
	}
	return ret;
}

int main(void)
{
	//変数の宣言
	int n,a,b,c;
	static ll conbi[100010]; 
	static ll ruijouA[100010];
	static ll ruijouB[100010];
	ll modAB;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	ll int temp=0;
	ll int temp1=0;
	ll int temp2=0;
	int temp3=0;
	int max=0;
	int min=INFINT;
	int len=0;
	ll int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[11];
	ll antisum;

	//データの読み込み


	scanf("%d %d %d %d",&n,&a,&b,&c);
//	scanf_s("%d %d %d %d",&n,&a,&b,&c);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


/*	for(i=0;i<n;i++){
//		scanf("%d",&s[i]);
		scanf_s("%d",&s[i]);
	}*/


/*	for(i=0;i<m;i++){
//		scanf("%d",&p[i]);
		scanf_s("%d",&p[i]);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	modAB=mod_inverse(a+b,MOD);
	temp=a*modAB%MOD;
	for(i=0;i<=n;i++){
		if(i==0){
			ruijouA[i]=1;
		}else{
			ruijouA[i]=ruijouA[i-1]*temp%MOD;
		}
	}

	temp=b*modAB%MOD;
	for(i=0;i<=n;i++){
		if(i==0){
			ruijouB[i]=1;
		}else{
			ruijouB[i]=ruijouB[i-1]*temp%MOD;
		}
	}

	conbi[0]=1;

	for(i=1;i<n;i++){
		conbi[i]=conbi[i-1]*(n-1+i)%MOD;
		conbi[i]=conbi[i]*mod_inverse(i,MOD)%MOD;
//		printf("conbi[%d]=%lld\n",i,conbi[i]);
	}

	for(i=0;i<n;i++){
		temp=conbi[i]%MOD;
		temp=temp*(n+i)%MOD;
		temp=temp*100%MOD;
		temp=temp*modAB%MOD;
		
		temp1=temp*ruijouA[n]%MOD;
		temp1=temp1*ruijouB[i]%MOD;

		temp2=temp*ruijouA[i]%MOD;
		temp2=temp2*ruijouB[n]%MOD;

		ans=(ans+temp1+temp2)%MOD;

//		printf("(n,%d)=%lld\n",i,temp1);
//		printf("(%d,n)=%lld\n",i,temp2);
	}

	//	printf("計算部分終了\n");

	//出力
	printf("%lld",ans);

//	printf("\n mod_inverse(93/16)=%lld",5*mod_inverse(8,MOD)%MOD);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 2560
#include <iostream>

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

    int four = 0;
    int remnant;
    bool flg = false;
    if(7 == n){
        flg = true;
    }else{
        while(four <= n){
            four += 4;
            remnant = n - four;
            if(0 == remnant % 7){
                flg = true;
                break;
            }
        }
    }

    if(flg){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k,h[200010],sum = 0;
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> h[i];
	sort(h,h + n);
	for(int i = 0;i < n - min(n,k);i++) sum += h[i];
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool ok(char c){
    if(c=='A' || c =='C' || c=='G' || c=='T'){
        return true;
    }
    return false;
}
int main(){
    string s; cin>>s;
    int n = s.size();
    vector<int> dp(n);
    for(int i =0; i<n; i++){
        if(!ok(s[i])){
            dp[i] = 0;
        }
        else dp[i] = dp[i-1] + 1;
    }
    int ans = - 1;
    for(int i =0; i<n; i++){
        ans = max(ans, dp[i]);
    }
    cout<<ans;
    return 0;
}

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

int main()
{
	pair<double, double> x, y;
	cin >> x.first >> x.second >> y.first >> y.second;

	cout << fixed <<  sqrt(pow((y.first - x.first), 2) + pow((y.second - x.second), 2)) << endl;
	return 0;
}

Measured memory_bytes: 3276
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
#define rreps(i, s, n) for (int i = n - 1; (int)(s) <= i; --i)
// reps(s,n)[::-1]
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
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;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* _sep, const char* _term) : sep(_sep), term(_term) {}
        template <class... Args> void operator()(const Args&... args) const { print(args...); }
        template <typename T> void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T> void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail> void print(const T& head, const Tail&... tail) const {
            std::cout << head, print_rest(tail...);
        }
        template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const {
            std::cout << sep << head, print_rest(tail...);
        }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints print;

void solve() {
    int n, k;
    cin >> n >> k;
    V<int> A(n);
    V<int> B(n);
    rep(i, n) cin >> A[i];
    ll ans = 1e12;
    ll cost;
    int max_h;
    int cnt;  // 見える
    rep(bit, 1 << n) {
        cost = 0;
        max_h = 0;
        cnt = 0;
        rep(i, n) {
            B[i] = A[i];
            if (bit & (1 << i)) {
                if (max_h >= A[i]) {
                    cost += max_h + 1 - A[i];
                    B[i] = max_h + 1;
                }
            }
            if (max_h < B[i]) {
                max_h = B[i];
                cnt++;
            }
        }
        if (k <= cnt) chmin(ans, cost);
    }
    print()(ans);
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3584
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    string s, c;
    cin >> s >> c;
    if(s[0] == c[2] && s[1] == c[1] && s[2] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int a, b, f = 0;
	
	while(1){
		cin >> a >> b;
		if(a == 0 && b == 0){
			break;
		}
		if(f == 1)cout << endl;
		
		for(f = 0; a <= b; a++){
			if(a%400 == 0 || (a%4 == 0 && a%100 != 0)){
				cout << a << endl;
				f = 1;
				a += 4;
				break;
			}
		}

		for(; a <= b; a += 4){
			if(a%400 == 0 || a % 100 != 0){
				cout << a << endl;
			}
		}
		
		if(f == 0){
			cout << "NA" << endl;
		}
		f = 1;
	}
	
	return 0;
}

Measured memory_bytes: 0
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  p=10005
  h,n=LI()
  a=[]
  b=[]

  for _ in range(n):
    x,y=LI()
    a.append(x)
    b.append(y)

  dp=[[inf]*(p+1) for _ in range(n+1)]
  dp[0][0]=0

  for i in range(n):
    for j in range(p):
      dp[i+1][j]=min(dp[i+1][j],dp[i][j])
      if j+a[i]<p:
        dp[i+1][j+a[i]]=min(dp[i+1][j+a[i]],dp[i+1][j]+b[i])
      else:
        dp[i+1][p]=min(dp[i+1][p],dp[i+1][j]+b[i])

  # print(dp)
  ans=inf
  for i in range(h,p+1):
    ans=min(ans,dp[n][i])
  return ans

# main()
print(main())


Measured memory_bytes: 303116
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!
 
/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 1000000000005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
 
signed main()
{
    fast;
    
    ll n,m,i,j,pe=0,ac=0;
    cin>>n>>m;
    map<ll,ll> ma;
    multiset<ll> mu;
    for(i=0;i<m;i++)
    {
        ll x;
        string sa;
        cin>>x>>sa;
        if(ma[x]==0 and sa=="WA")
        {
            mu.in(x);
        }
        else if(sa=="AC" and ma[x]==0)
        {
            ac++;
            ma[x] = 1;
        }
    }
    for(auto u:mu)
    {
        if(ma[u]) pe++;
    }
    cout<<ac<<" "<<pe;
}

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

int main()
{
    int X[5];
    int K;
    rep (i, 5) {
        cin >> X[i];
    }
    cin >> K;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            int d = abs(X[i] - X[j]);
            if (d > K) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int main()
{
	int a , b , c , d;
	cin >> a >> b >> c >> d;
	if(c >= b || d <= a){
		cout << 0 << endl;
		return 0;
	}
	cout << min(b,d) - max(a , c) << endl;
	return 0;
} 




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

#define pb push_back

void solution(int n, vector<vector<int> >& days);
void solution1(int n, vector<vector<int> >& days);

int main(void){
	int n;
	cin >> n;
	vector<vector<int> > days(n, vector<int>(3));
	for(int i = 0;i < n;i++){
		cin >> days[i][0];
		cin >> days[i][1];
		cin >> days[i][2];
	}
	// solution(n, days);
	solution1(n, days);
}

// iterative
void solution(int n, vector<vector<int> >& days){
	vector<vector<int> > dp(n, vector<int>(3, -1));
	dp[0][0] = days[0][0];
	dp[0][1] = days[0][1];
	dp[0][2] = days[0][2];
	for(int i =1;i < n;i++){
		for(int j = 0;j < 3;j++){
			dp[i][j] = max(dp[i][j], dp[i-1][(j+1)%3] + days[i][j]);
			dp[i][j] = max(dp[i][j], dp[i-1][(j+2)%3] + days[i][j]);
		}
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return;
}

int helper(int n, vector<vector<int> >& days, vector<vector<int> >& dp, int x, int k){
	if(dp[x][k] == -1){
		dp[x][k] = max(helper(n, days, dp, x-1,(k+1)%3), helper(n, days, dp, x-1,(k+2)%3)) + days[x][k];
	}
	return dp[x][k];
}

// recursive
void solution1(int n, vector<vector<int> >& days){
	vector<vector<int> > dp(n,vector<int>(3, -1));
	dp[0][0] = days[0][0];
	dp[0][1] = days[0][1];
	dp[0][2] = days[0][2];
	int ans = helper(n, days, dp, n-1, 0);
	ans = max(ans, helper(n, days, dp, n-1, 1));
	ans = max(ans, helper(n, days, dp, n-1, 2));
	cout << ans << endl;
	return;
}

Measured memory_bytes: 18944
#include<cstdio>
#include<iostream>
#include<string>
#define R(i, n) for(int i = 0; i < n; i++)
#define RR(i, n) for(int i = n; i >= 0; i--)
#define F(i, m, n) for(int i = m; i < n; i++)
#define FR(i, m, n) for(int i = m; i >= n; i--)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d\n", a)
#define INF 1000000000
using namespace std;
typedef long long ll;

string S;

int main(){
	cin >> S;
	int ans = 0;
	int hanbunn = S.size() / 2;
	R(i, hanbunn){
		if(S[i] != S[S.size()-1-i]) ans++;
	}
	P(ans);
};

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b || (n == 1 && a != b)){
        cout << 0 << endl;
        return 0;
    }
    if(n == 1 && a == b){
        cout << 1 << endl;
        return 0;
    } 
    ll ans = b * (n-1) + a - a * (n-1) - b + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
leng = 0
t = ('A','C','G','T')

for i in range(len(s)):
	if s[i] in t:
		leng += 1
	else:
		ans = max(ans,leng)
		leng = 0
ans = max(ans,leng)
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
constexpr ll mod = 1000000007;

ll n;
ll a, b;

ll powMod( ll x, ll y )
{
  ll ret = 1ll;

  while( y > 0 )
  {
    if( y & 1 )
      ret = (ret * x) % mod;

    x = (x*x) % mod;

    y >>= 1;
  }

  return ret;
}

ll fact[200010], inv[200010];

ll comb( ll n, ll r )
{
  if( n < r || n <= 0 || r < 0 )
    return 0;

  ll ret = 1;
  rep( i, r )
  {
    ret = (ret*n)%mod;
    --n;
  }

  return ret*inv[r]%mod;
}

int main()
{
  scanf( "%lld%lld%lld", &n, &a, &b );

  ll ma = std::max(a,b);

  fact[0] = 1;
  rep( i, ma+1 )
    fact[i+1] = (i+1)*fact[i]%mod;

  rep( i, ma+1 )
    inv[i] = powMod( fact[i], mod-2 );

  ll ans = (powMod(2,n)-comb(n,a)+mod)%mod-comb(n,b);
  ans = (ans+mod)%mod;

  printf( "%lld\n", (ans-1+mod)%mod );

  return 0;
}

Measured memory_bytes: 3328
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
    x = q.popleft()
    y = int(x[-1])
    if y != 0:
        q.append(x + str(y - 1))
    q.append(x + x[-1])
    if y != 9:
        q.append(x + str(y + 1))
print(q[0])


Measured memory_bytes: 22712
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, mm, dd;
	long double ans = 0.0;
	cin >> nn >> mm >> dd;
	if(dd == 0)
	{
		ans += (long double)(mm - 1) / (long double)nn;
	}
	else
	{
		ans += (long double)(mm - 1) * 2.0 * (long double)(nn - dd) / (long double)(nn * nn);
	}
    cout << fixed << setprecision(20);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
using ll = long long;

template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> void show(vector<T>v){rep(i,v.size()-1){cout<<v.at(i)<<" ";}cout<<v.at(v.size()-1)<<endl;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
vector<string> split(const string&s,char d){vector<string>r;stringstream ss(s);string k;while(getline(ss,k,d))if(!k.empty())r.pb(k);return r;}

// Template ends here

int main() {
    string s;
    cin >> s;
    Yes(!(s.at(0) == s.at(1) && s.at(1) == s.at(2)));
    return 0;
}

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

using namespace std;

int solve(vector< vector<int> > G, vector<int> H){
  int n = G.size();
  int cnt=0;
  for(int i=0;i<n;i++){
    // cout<<"RN: "<<i+1<<"\n";
    if(G[i].size()==0){
      cnt++;
      // cout<<"0 "<<i+1<<"\n";
    }else{
      int max = H[i];
      int f=0;
      for(int k=0;k<G[i].size();k++){
        // cout<<"-"<<G[i][k]<<" "<<H[G[i][k]]<<"\n";
        if(H[G[i][k]]>=max) {
          f=1;
          break;
        }
      }
      if(f==0) {
        cnt++;
        // cout<<"1 "<<i+1<<"\n";
      }
    }
  }
  return cnt;
}
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> H;
  for(int i=0;i<n;i++){
    int h;
    cin>>h;
    H.push_back(h);
  }
  vector< vector<int> > G(n);
  for(int k=0;k<m;k++){
    int i,j;
    cin>>i>>j;
    G[i-1].push_back(j-1);
    G[j-1].push_back(i-1);
  }
  // for(int i=0;i<n;i++){
  //   cout<<i<<"  ";
  //   for(int j=0;j<G[i].size();j++){
  //     cout<<G[i][j]<<" ";
  //   }
  //   cout<<"\n";
  // }

  int res = solve(G,H);
  cout<<res<<"\n";
}

Measured memory_bytes: 14300
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define inf 0x3f3f3f3f
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define mst(x) memset(x,0,sizeof(x))
#define mstinf(x) memset(x,0x3f,sizeof(x))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
string a[]={"SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main(){
    string in;
    cin>>in;
    if(in == "SUN") cout<<"7"<<endl;
    if(in == "MON") cout<<"6"<<endl;
    if(in == "TUE") cout<<"5"<<endl;
    if(in == "WED") cout<<"4"<<endl;
    if(in == "THU") cout<<"3"<<endl;
    if(in == "FRI") cout<<"2"<<endl;
    if(in == "SAT") cout<<"1"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int r[10],a=0,b=0,c=0,i;
    for(i=0;i<10;i++){
        scanf("%d",&r[i]);
        if(a<r[i]){
            c=b;
            b=a;
            a=r[i];
        }
        else if(b<r[i]){
            c=b;
            b=r[i];
        }
        else if(c<r[i]){
            c=r[i];
        }
    }
    printf("%d\n%d\n%d\n",a,b,c);
    return 0;
}

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

using namespace std;

#define ll long long
int main(){
    int h,n;
    cin>>h>>n;
    int arr[n];
    ll sum=0;
    int f=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
                
        if(f==0)
        sum+=arr[i];
        
        if(sum>=h){
            f=1;
        }

        
    }
    
    if(f==1){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
        
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int x,y;cin>>x>>y;
  int a,b;
  if (x==4||x==6||x==9||x==11) a=0;
  else if (x==2) a=1;
  else a=2;
  if (y==4||y==6||y==9||y==11) b=0;
  else if (y==2) b=1;
  else b=2;
  if (a==b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    Cout(3*n*n);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
}


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

int main() {
  string s; cin >> s;
  int c[27] = {};
  for (int i = 0; i < s.size(); i++) {
    if (c[s[i] - 'a'] > 0) {
      cout << "no" << endl;
      return 0;
    }
    c[s[i] - 'a']++;
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		
		if(S<1200)
		System.out.println("ABC");
		else if(S<2800)
			System.out.println("ARC");
		else
			System.out.println("AGC");
		sc.close();
	}
}

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

int main(){
	int n; cin >> n;
	int p[n];
	int ans = 0;
	for(int i = 0; i < n; ++i) cin >> p[i];
	for(int i = 0; i < n; ++i) --p[i];
	for(int i = 0; i < n; ++i){
		if(i == n - 1 && p[i] == i) ++ans;
		else if(i == n - 1) break;
		else if(p[i] == i){
			ans += 1;
			++i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
void check()
{
    if(false)
    cout<<"C"<<endl;
}
#define ll long long
int main() {
    long long n,i,z,t;
    long long aa,bb,cc;
cin >> n;
	ll vious[n + 1], a[n + 1];
	memset(vious, 0, sizeof(vious));
	memset(a, 0, sizeof(a));
check();
	for(i=1; i<n + 1; i+=1) {
		cin >> a[i];
		vious[i] = ( vious[i - 1] + a[i]) % 1000000007;
	}
check();
	z = 0;
check();
	for(i= 2;i<n + 1; i+=1) {
		t = (vious[i - 1] * a[i]) % 1000000007;
		z =z+ t;
		z = z % 1000000007;
	}

	cout<<z<<"\n";
}

Measured memory_bytes: 6752
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
//https://kujira16.hateblo.jp/entry/2016/12/15/000000
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}
const int sqrtN = 512;
class SqrtDecomposition{
private:
	int N, K;
	vector<int> data;
	vector<int> bucketSum;
public:
	SqrtDecomposition(int n){
		N = n;
		K = (N + sqrtN - 1) / sqrtN;
		data.resize(K * sqrtN, 0);
		bucketSum.resize(K, 0);
	}
	void add(int x, int y) {
		int k = x / sqrtN;
		data[x] += y;
		int sum = 0;
		/*
		for (int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
			sum += data[i];
		}
		*/
		bucketSum[k] +=y;
	}
	// [x, y)
	int getSum(int x, int y) {
		int sum = 0;
		for (int k = 0; k < K; ++k) {
			int l = k * sqrtN, r = (k + 1) * sqrtN;
			if (r <= x || y <= l)
				continue;
			if (x <= l && r <= y) {
				sum += bucketSum[k];
			}
			else {
				for (int i = max(x, l); i < min(y, r); ++i) {
					sum += data[i];
				}
			}
		}
		return sum;
	}
};
signed main() {
	my_io();
	int N, Q; cin >> N >> Q;
	SqrtDecomposition decomp(N);
	while (Q--) {
		int c, x, y; cin >> c >> x >> y;
		if (c == 0) {
			decomp.add(x, y);
		}
		else {
			cout << decomp.getSum(x, y + 1) << endl;
		}
	}
	return 0;
}




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

long long maxn=1e17;

int main()
{
    int a[210000];
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]),a[i]-=i;
        sort(a+1,a+1+n);
        long long  ans=0;
        for(int i=1;i<=n;i++)ans+=abs(a[i]-a[n/2+1]);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e18
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b)  for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,ans=0,x,mx=0;cin>>n;
         for(ll i=0;i<n;i++){
            cin>>x;
            if(mx>x)ans+=mx-x;
            mx=max(mx,x);
         }
         cout<<ans<<"\n";
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
#define abs(x) ((x)>0?(x):(-(x)))
#define eps (double)(0.0000001)
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
long a[105];
int main()
{
    long n,m;
    long a,b,c;
    cin>>a>>b>>c>>n>>m;
    c*=2;
    if(c>a+b){
        cout<<n*a+m*b;
    }
    else{
        if(n>m){
            cout<<min((n-m)*a+m*c,n*c);
        }
        else{
            cout<<min(n*c+(m-n)*b,m*c);
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc052/tasks/arc067_a
// math
import std.algorithm;
import std.array;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;

uint[] sieve(in uint limit) nothrow @safe {
    if (limit < 2)
        return [];
    auto composite = new bool[limit];

    foreach (immutable uint n; 2 .. cast(uint)(limit ^^ 0.5) + 1)
        if (!composite[n])
            for (uint k = n * n; k < limit; k += n)
                composite[k] = true;

    return iota(2, limit).filter!(i => !composite[i]).array;
}

void main() {
    uint[] primes = sieve(1000);

    long n = readln.chomp.to!long;

    long[long] exponents;
    foreach(prime; primes)
        exponents[prime] = 0;

    for(long i = 2; i <= n; ++i) {
        long m = i;
        foreach(prime; primes) {
            long div = 0;
            while(m%prime == 0) {
                div += 1;
                m /= prime;
            }
            exponents[prime] += div;
        }
    }

    long ans = 1;
    foreach(exp; exponents.values) {
        ans *= (exp+1);
        ans %= 10^^9+7;
    }

    ans.writeln;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
tocni = [0 for i in range(n + 1)]
correct = wrong = 0
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if s == "AC" and tocni[p] != 1:
        correct += 1
        wrong -= tocni[p]
        tocni[p] = 1
    if s == "WA" and tocni[p] != 1:
        tocni[p] -= 1
print(correct, wrong)


Measured memory_bytes: 3888
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> v(n+1);
	vector<bool> visited(n+1,false);
	for(ll i=1;i<=n;i++)
		cin>>v[i];
	vector<int> ans;
	ll pos = 1;
	while(1)
	{
		if(!visited[pos])
		{
			ans.push_back(v[pos]);
			visited[pos] = true;
			pos = v[pos];
		}
		else
			break;
	}
	int start;
	for(int i=0;i<sz(ans);i++)
	{
		if(ans[i] == v[pos])
		{
			start = i;
			break;
		}
	}
	ll out;
	ll loopSize = sz(ans) - start;
	if(k <= sz(ans))
		out = ans[k-1];
	else
	{
		k -= sz(ans);
		--k;
		k %= loopSize;
		out = ans[start+k];
	}
	cout<<out;
	return 0;
}

Measured memory_bytes: 5908
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
int ans=1;
int a[5];
int main()
{
	for(int i=1;i<=4;i++)
	{
		scanf("%1d",&a[i]);
	}
	if((a[1]==a[2]&&a[2]==a[3])||(a[2]==a[3]&&a[3]==a[4]))
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
export class Main {
  static main(input): string {
    const [r, d, x]: number[] = input.split("\n")[0].split(" ").map(Number);
    let t: number = x;
    const result: number[] = [];
    for (let i = 2001; i <= 2010; ++i) {
      t = r * t - d;
      result.push(t);
    }
    return result.join("\n");
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7628
use std::collections::VecDeque;

fn main(){
  let wh: Vec<usize> = read_vec();
  let w = wh[0];
  let h = wh[1];

  let mut mp: Vec<Vec<usize>> = vec![vec![0; h+2]; w+2];

  for y in 1 .. h + 1 {
    let tv: Vec<usize> = read_vec();
    
    for x in 1 .. w + 1 {
      mp[x][y] = tv[x-1];
    }
  }

  let np: Vec<Vec<(i32, i32)>> = vec![
    vec![(1, 0), (-1, 0), (-1, -1), (0, -1), (-1, 1), (0, 1)],
    vec![(1, 0), (-1, 0), (0, -1), (1, -1), (0, 1), (1, 1)]
  ];
  
  let mut que: VecDeque<(usize, usize)> = VecDeque::new();

  que.push_back((0, 0));
  
  mp[0][0] = 2;
  
  loop {
    match que.pop_front() {
      Some((x, y)) => {
        for &(dx, dy) in &np[y % 2] {
          let nx = x as i32 + dx;
          let ny = y as i32 + dy;

          if nx >= 0 &&
             nx <= w as i32 + 1 &&
             ny >= 0 &&
             ny <= h as i32 + 1 &&
             mp[nx as usize][ny as usize] == 0 {
            mp[nx as usize][ny as usize] = 2;
            que.push_back((nx as usize, ny as usize));
          }
        }
      },
      None => { break; },
    }
  }

  let mut ans: usize = 0;

  for y in 1 .. h + 1 {
    for x in 1 .. w + 1 {
      if mp[x][y] == 1 {
        for &(dx, dy) in &np[y % 2] {
          let nx = (x as i32 + dx) as usize;
          let ny = (y as i32 + dy) as usize;
          
          if mp[nx][ny] == 2 {
            ans += 1;
          }
        }
      }
    }
  }
  
  println!("{}", ans);
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 5052
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val x = readLong()
    println(360 / gcd(x, 360))
}

/** O(log(n)): n = min(a, b) */
tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 34560
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(n) push_back(n)
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
void solve(){
	ll n,k,d,i,j,tot,x;
	cin>>n>>k;
	static ll a[117];
	for(i=0;i<k;i++){
		cin>>d;
		for(j=0;j<d;j++){
			cin>>x;
			a[x-1]=1;
		}
	}
	tot=0;
	for(i=0;i<n;i++)
		if(a[i]==0)
			tot++;
	cout<<tot;
	return;
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>


int main() {

    int i, t;
    int n;
    int A[100001];

    scanf("%d",&n);

    for(i=1;i<=n;i++)scanf("%d",&A[i]);

    for(i=1;i<=n;i++){
      if(i==1){
	printf("node 1: key = %d, left key = %d, right key = %d, \n",A[i],A[i*2],A[i*2+1]);
	continue;
      }
      printf("node %d: key = %d, parent key = %d, ",i,A[i],A[i/2]);
      if(i*2<=n) printf("left key = %d, ",A[i*2]);
      if(i*2+1<=n) printf("right key = %d, ",A[i*2+1]);
      printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;

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

    if ( b % a == 0) {
        cout << a + b << endl;
    }else {
        cout << b - a << endl;
    }

    return 0;
}


Measured memory_bytes: 256
count_moji = gets.chomp.to_i
moji = gets.chomp.split("")
len = []

max = 0

count_moji.times do |j|
    
    # もじれつの破壊(破壊しない方法が知りたい)
    len[0] = moji.shift(j)
    len[1] = moji.pop(count_moji-j)
    # 破壊した文字列の結合
    moji = len[0] + len[1]


    #print len[0]," ",len[1],"\n"
    count_len = 0

    ("a".."z").each do |i|
        if len[0].count(i) >= 1 && len[1].count(i) >= 1
            count_len += 1
        end
    end

    if max <= count_len
        max = count_len
    end

end

puts max

Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,k,ans = 1;
	cin >> n >> k;
	
	REP(i,n)
	{
		if(ans < k)
		{
			ans *= 2;
			
		}
		else
		{
			ans += k;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char s[20];
int n, cnt, sum;
bool flag;
int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if(s[1] != 'A') return puts("WA") & 0;
	for(int i = 3; i <= n - 1; ++i){
		flag |= s[i] == 'C'; 
	}
	if(!flag) return puts("WA") & 0;
	for(int i = 2; i <= n; ++i){
		cnt += s[i] == 'C';
		if(s[i] >= 'A' && s[i] <= 'Z') sum++;
	}
	sum--;
	if(cnt >= 2 || sum) return puts("WA") & 0;
	puts("AC");
	return 0;
}

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

int main() {
  int L, R;
  cin >> L >> R;
  
  if (R - L >= 2019) cout << 0 << endl;
  
  else {
    int64_t min_mod = 2019;
    for (int64_t i = L; i <= R; i++) {
      for (int64_t j = L; j < i; j++) {
        min_mod = min(min_mod, i * j % 2019);
      }
    }
    cout << min_mod << endl;
  }
}

Measured memory_bytes: 256