akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
ll N,M,ans,X;
string S,T;
ll C[13];
ll A[13][13];
ll D[13];
ll money;
ll INF = 100000009;
bool found = true;
int main(){
    ans = INF;
    cin >> N >> M >>X;
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0;j<M;j++){
            cin >> A[i][j];
        }
    }
    for (int bit = 0; bit < (1<<N); ++bit) {
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) {
                for(int j = 0;j<M;j++){
                    D[j] += A[i][j];
                }
                money += C[i];
            }
        }
        found = true;
        for(int i = 0;i<M;i++){
            if(X>D[i]){
                found = false;
                break;
            }
        }
        if(found){
            if(ans>money){
                ans = money;
            }
        }
        for(int i=0;i<M;i++){
            D[i] = 0;
        }
        money = 0;
        
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}




Measured memory_bytes: 3636
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 998244353;

const int BIT_SIZE = 550000; // 必要な数よりも大きい2^nよりも大きい数を入れるとよい
long long int BIT[BIT_SIZE + 1];

void init(){
	for(int i = 0; i <= BIT_SIZE; i++){
		BIT[i] = 0;
	}
}

void add(int a, long long int w){
	
	// a番目の要素にwを足す O(log N)
	
	for(int x = a; x <= BIT_SIZE; x += x & -x){
		BIT[x] += w;
	}
}

long long int sum(int a){
	
	// 1からaまでの要素の合計を返す O(log N)
	
	long long int ret = 0;
	for(int x = a; x > 0; x -= x & -x){
		ret += BIT[x];
	}
	return ret;
}

long long int P1[210000], P2[210000], P3[210000], P4[210000];
long long int p2[210000];

int main(){
    p2[0] = 1;
    for(int i = 1; i < 210000; i++){
        p2[i] = p2[i - 1] * 2 % MOD;
    }
    int N;
    cin >> N;
    set<P> mx, my;
    vector<P> v;
    for(int i = 0; i < N; i++){
        long long int x, y;
        cin >> x >> y;
        mx.insert(P(x, i));
        my.insert(P(y, i));
        v.push_back(P(x, y));
    }
    int cnt = 1;
    for(P p : mx){
        v[p.second].first = cnt;
        cnt += 1;
    }
    cnt = 1;
    for(P p : my){
        v[p.second].second = cnt;
        cnt += 1;
    }
    sort(v.begin(), v.end());

    init();
    for(int i = 0; i < N; i++){
        int num = sum(v[i].second);
        P4[i] = num;
        P1[i] = i - num;
        add(v[i].second, 1);
    }
    init();
    for(int i = N - 1; i >= 0; i--){
        int num = sum(v[i].second);
        P2[i] = num;
        P3[i] = (N - 1 - i) - num;
        add(v[i].second, 1);
    }
    long long int ans = p2[N - 1] * N % MOD;
    for(int i = 0; i < N; i++){
        long long int S1 = (p2[P1[i]] - 1) * (p2[P2[i]] - 1) % MOD * p2[P3[i] + P4[i]] % MOD;
        long long int S2 = (p2[P3[i]] - 1) * (p2[P4[i]] - 1) % MOD * p2[P1[i] + P2[i]] % MOD;
        long long int S3 = (p2[P1[i]] - 1) * (p2[P2[i]] - 1) % MOD * (p2[P3[i]] - 1) % MOD * (p2[P4[i]] - 1) % MOD;
        ans += S1 + S2 - S3 + MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 41580
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [u64; n],
    }
    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        input! {
            a: usize,
            b: usize,
        }
        graph[a - 1].push(b - 1);
        graph[b - 1].push(a - 1);
    }

    let mut ret = 0;
    for i in 0..n {
        let hi = h[i];
        if graph[i].is_empty() {
            ret += 1;
        } else {
            let ma = graph[i].iter().map(|v| h[*v]).max().unwrap();
            if hi > ma {
                ret += 1;
            }
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 10600
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
# 後ろからボールの有無を決定
for i in range(n - 1, -1, -1):
    cnt = 0
    for j in range(2 * (i + 1), n + 1, i + 1):
        cnt += b[j - 1]
    # 条件と異なるならボールを投入
    if cnt % 2 != a[i]:
        b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
    if b[i]:
        print(i + 1, end=' ')


Measured memory_bytes: 7148
package main

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

func nextLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func main() {
	totalTime := 0
	remainderList := []int{}
	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < 5; i++ {
		num, _ := strconv.Atoi(nextLine(sc))
		if num%10 != 0 {
			remainderList = append(remainderList, (10 - num%10))
		}
		totalTime += num
	}
	sort.Sort(sort.IntSlice(remainderList))

	adjustment := 0
	for j := 0; j < len(remainderList)-1; j++ {
		adjustment += remainderList[j]
	}
	fmt.Println(totalTime + adjustment)
}


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

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

  int n, d; cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n) rep(j, d) cin >> x[i][j];

  int ans = 0;
  rep(i, n) rep(j, i) { // j<i(<n) 全列挙
    int dist = 0;
    rep(k, d) {
      int tmp = x[i][k]-x[j][k];
      dist += tmp*tmp;
    }
    if(sqrt(dist) == ceil(sqrt(dist))) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b, c, d, e, f;
cin >> a >> b;
c = a + b;
d = c % 3;
e = a % 3;
f = b % 3;
 if(d == 0)cout << "Possible" << endl;
else if(e == 0)cout << "Possible" << endl;
else if(f == 0)cout << "Possible" << endl;
else cout << "Impossible" << endl;
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, d; cin >> n >> d;
  vector<vector<int> > x(n, vector<int>(d)); REP(i, n) REP(j, d) cin >> x[i][j];
  int ans = 0;
  REP(i, n) FOR(j, i + 1, n) {
    long long dist = 0;
    REP(k, d) dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
    int sq = (int)sqrt(dist);
    if (sq * sq == dist) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int ans=0;
	rep(i,s.size()){
		if(s[i]=='+') ans++;
		else ans--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    if (N % 2 == 0) {
        for (int64_t i = N; i >= 2; i-= 2) {
            std::cout << A[i-1] << " ";
        }
        for (int64_t i = 1; i <= N; i+= 2) {
            std::cout << A[i-1] << " ";
        }
    }
    else {
        for (int64_t i = N; i >= 1; i-= 2) {
            std::cout << A[i-1] << " ";
        }
        for (int64_t i = 2; i <= N-1; i+= 2) {
            std::cout << A[i-1] << " ";
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3952
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  var w = ""

  def shuffle(cnt:Int, w:String):String =
    if(cnt == 0)  w else { val m = readInt;shuffle(cnt-1, (w drop m)+(w take m)) }

  def exec(w:String):Unit =
    if(w=="-") return else { val n = readInt;println(shuffle(n,w));exec(readLine) }

  exec(readLine.trim)
}

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

namespace Atc_0035
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var result = s.Split(' ')[1] + s.Split(' ')[0];

            Console.WriteLine(result);

        }
    }
}


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

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
int a[N], d[N];
vector<int> e[N];

LL dfs(int v, int fa) {
    LL sum = 0, mx = 0;
    int cnt = 0;
    for (auto u : e[v]) {
        if (u == fa) continue;
        LL tmp = dfs(u, v);
        mx = max(mx, tmp);
        sum += tmp;
        cnt++;
    }
    if (!cnt) return a[v];
    if (sum < a[v]) {
        puts("NO");
        exit(0);
    }
    LL t = sum - a[v];
    LL t2;
    if (cnt == 1) t2 = 0;
    else t2 = mx >= sum - mx ? sum - mx : sum / 2;
    if (t > t2 || sum - 2 * t < 0) {
        puts("NO");
        exit(0);
    }
    return sum - 2 * t;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        e[y].push_back(x);
        d[x]++;
        d[y]++;
    }
    if (n == 2) {
        puts(a[1] == a[2] ? "YES" : "NO");
        return 0;
    }
    for (int i = 1; i <= n; i++) if (d[i] != 1) {
        puts(dfs(i, 0) ? "NO" : "YES");
        break;
    }
    return 0;
}


Measured memory_bytes: 13184
N,D = map(int,input().split())
X = [ list(map(int,input().split())) for i in range(N)]

ans = 0
l = [ i for i in range(N)]
import itertools
for a in itertools.combinations(l,2):
    dis = 0
    for k in range(D):
        dis += (X[a[0]][k] - X[a[1]][k])**2
    dis = dis**(1/2)
    if float.is_integer(dis):
        ans += 1
print(ans)


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

#define ll long long
#define M 1000000007
#define deb(x) cout<<#x<<" "<<x<<endl;
#define foi(a,b) for(int i=a;i<b;i++)
#define foj(a,b) for(int j=a;j<b;j++)
#define fod(a,b) for(int i=a;i>b;i--)
#define MAX  1e9
#define MIN -1e9
#define nl cout<<"\n";
#define show(arr,a,b) for(int i=a;i<b;i++) cout<<arr[i]<<" "; cout<<endl;
#define  mp(a,b) pair<ll,ll> p(a,b)
#define pb push_back
typedef pair<ll,ll> p1;
typedef vector<ll> vecd;
typedef vector<string> vecsd;
typedef map<ll,ll> mpd;
typedef set<ll> setd;
typedef multiset<ll> msetd;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k; cin>>k>>n;
    ll arr[n];
    foi(0,n) cin>>arr[i];
    ll maxz=0;
   foi(1,n){
       maxz=max(maxz,arr[i]-arr[i-1]);
   }
   maxz=max(maxz,k-arr[n-1]+arr[0]);
   cout<<(k-maxz)<<"\n";
    return 0;
}


Measured memory_bytes: 1792
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3592
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();
   
    public void Solve() {
        var A = sc.nextInt();
        var P = sc.nextInt();
        WriteLine(((A * 3) + P) / 2);
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

int main(){
    int k, s;
    cin >> k >> s;

    // int x, y, z;
    long long ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            int tpz = s - i - j;
            if(tpz >= 0 && tpz <= k){
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from functools import lru_cache

N = int(input())
K = int(input())
memo = {}

@lru_cache(maxsize = 128)
def F(N, K):
    """
    F(N, K) = (1以上N以下で0でない桁がちょうどK個なものの個数)
    Nを一の桁から見ていくことで再帰で求める
    （例）F(314,3) = F(31,2)*4 + F(30,2)*5 + F(31,3)
                      = {F(3,1) + F(2,1)*8 + F(3,2)} * 4
                            + {F(2,1)*9 + F(3,2)} * 5
                            + {F(3,2) + F(2,2)*8 + F(3,3)}
                      = ...
    """
    r = int(str(N)[-1])
    M = (N - r) // 10
    if K == 0 and N >= 0:
        return 1
    elif K == 0 and N <= -1:
        return 0
    elif N <= 0:
        return 0
    else:
        return F(M, K-1) * r + F(M-1, K-1) * (9-r) + F(M, K)

print(F(N, K))


Measured memory_bytes: 58072
n,m=map(int,input().split())
lst=[]
for i in range(n):
    a=list(map(int,input().split()))
    lst.append(a)
    
lst=sorted(lst,key=lambda x:x[0])
ans=0
for i in range(n):
    honsuu=lst[i][1]
    if honsuu>=m:
        ans+=(m*lst[i][0])
        break
    else:
        m-=honsuu
        ans+=(honsuu*lst[i][0])

print(ans)

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

int main(void){
  int width,height;
  char alf;

  cin>>width>>height>>alf;
  int h_center =height/2;
  int w_center =width/2;

  for(int i=0;i<height;i++){
    if((i==0)||(i==height-1)){
      for(int j=0;j<width;j++){
        if(j==0||j==width-1) cout<<"+";
        else cout<<"-";
      }
      cout<<endl;
      continue;
    }

    if(i==h_center){
      for(int j=0;j<width;j++){
        if(j==0||j==width-1) cout<<"|";
        else if (j==w_center) cout<<alf;
        else  cout<<".";
      }
      cout<<endl;
      continue;
    }

    for(int j=0;j<width;j++){
      if(j==0||j==width-1)  cout<<"|";
      else cout<<".";
    }
    cout<<endl;
  }

  return 0;
}



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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,ans = -1;
    cin >> a >> b;
    int al = ceil(a/0.08),au = ceil((a+1)/0.08) - 1,bl = ceil(b/0.1),bu = ceil((b+1)/0.1) - 1;
    for(int i = al; i <= au; i++){
        if(bl <= i && i <= bu){
            ans = i;
            break;
        }
    }
    cout << ans;
    return 0;
}



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

int main() {
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  int a=x2+y1-y2,b=y2+x2-x1,c=x1+y1-y2,d=y1+x2-x1;
  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}

Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> N;
	cin >> s;
	if (s.size() <= N) {
		cout << s << endl;
	}
	else {
		s.resize(N);
		cout << s << "..." << endl;
	}
}

Measured memory_bytes: 3652
def main():
    N = int(input())
    S = []
    S.append(input())
    S.append(input())
    MOD = 10**9 + 7
    ans = 1
    pre_mino_flag = -1 # vertical:0, horizontal:1
    pass_flag = False
    if S[0][0] == S[1][0]:
        ans *= 3
        pre_mino_flag = 0
    else:
        ans *= 6
        pre_mino_flag = 1
        pass_flag = True
    
    for i in range(1, N):
        if pass_flag:
            pass_flag = False
            continue
        
        if S[0][i] == S[1][i]:
            if pre_mino_flag == 0:
                ans *= 2
                ans %= MOD
            else:
                pass
            pre_mino_flag = 0
        else:
            pass_flag = True
            if pre_mino_flag == 0:
                ans *= 2
                ans %= MOD
            else:
                ans *= 3
                ans %= MOD
            pre_mino_flag = 1
            
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 9184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int rect = 0;
		int dia = 0;
		while(true){
			String tmp = br.readLine();
			
			if(tmp == null){
				break;
			}
			
			String[] tmpArray = tmp.split(",");
			
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			int c = Integer.parseInt(tmpArray[2]);
			///System.out.println(a + " "+ b + " "+ c);
			if(a*a + b*b == c*c){
				rect++;
			}
			if(a == b){
				dia++;
			}
			
		}
		
		System.out.println(rect);
		System.out.println(dia);
	}

}

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

using namespace std;

const int MAX = 1e4;
 
int n;
vector<int> v,array;
int tri[MAX+1];
 
void init(){
    int t = 1;
    tri[0] = 0;
    for(int i = 1 ; i <= MAX ; i++){
	tri[i] = tri[i-1] + t;
	t++;
    }
}
 
bool check(){
    int len = array.size();
    for(int i = 0 ; i < len ; i++){
	if(array[i] != i+1) return false;
    }
    return true;
}
 
void judge(){
    int LIMIT = MAX,cnt = 0;
    bool possible = false;
 
    while(LIMIT--){
	if(check()){
	    break;
	}
     
	int s = 0, len = array.size();
	for(int i = 0 ; i < len ; i++){
	    if(array[i]){
		array[i]--;
		s++; 
	    }
	}
	array.push_back(s);
	for(int i = 0 ; i < len ; i++){
	    if(!array[i]){
		array.erase(array.begin() + i);
 
	    }
	}
 
	++cnt;
    }
    if(check()) possible = true;
    if(possible) cout << cnt << endl;
    else cout << "-1" << endl;
}
 
int main(){ 
    init(); 
    while(cin >> n ,n){
	int in,sum = 0;
	array.clear();
	for(int i = 0 ; i < n ; i++){
	    cin >> in;
	    sum += in;
	    array.push_back(in);
	}
 
	bool flg = false;
	for(int i = 1 ; i <= MAX ; i++){
	    if(tri[i] == sum){
		flg = true;
		break;
	    } 
	}
 
	if(!flg){
	    cout << "-1" << endl;
	}
	else{
	    judge();
	}
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 1e5 + 5;

vi node[N];
int memo[N], par[N];

int dfs(int idx, int par)
{
	if (memo[idx] != -1)
		return memo[idx];
	memo[idx] = 0;
	for(auto i : node[idx])
	{
		if (i == par)
			continue;
		memo[idx] = max(memo[idx], 1 + dfs(i, idx));
	}
	return memo[idx];
}

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

	reset(memo, -1);
	reset(par, -1);
	int n, m;
	cin >> n >> m;

	while(m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
		par[v] = u;
	}

	int res = 0;
	erep(i, 1, n)
		if (par[i] == -1)
			res = max(res, dfs(i, 0));

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 11264
h, w, k = map(int, input().split())
s = [None] * h
st = [0] * h
ans = [[0] * w for _ in range(h)]
cnt = 0
for i in range(h):
    s[i]  = list(input())
    st[i] = s[i].count('#')
col_first = False
col_first_num = 0
for i in range(h):
    if st[i] == 0:
        if col_first:
            for j in range(w):
                ans[i][j] = ans[i-1][j]
    else:
        cnt += 1
        if not col_first:
            col_first_num = i
        col_first = True
        row_first = False
        for j in range(w):
            if row_first:
                if s[i][j] == '#':
                    cnt += 1
                ans[i][j] = cnt
            else:
                if s[i][j] == '#':
                    row_first = True
                ans[i][j] = cnt
for i in range(h):
    if ans[i][0] == 0:
        for j in range(w):
            ans[i][j] = ans[col_first_num][j]
    else:
        break
for i in ans:
    for j in i:
        print(j, end=' ')
    print()

Measured memory_bytes: 13332
#include<stdio.h>
#include<math.h>
int a[109];
int b[109];
int main()
{
    int n;
    scanf("%d",&n);
    int i;    int sum=0;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int sum1=0;
    int ans=1000;
    for(i=1;i<=n-1;i++)
    {
        sum1+=a[i];
        sum-=a[i];
        if(fabs(sum1-sum)<ans)
        {
            ans=fabs(sum1-sum);
        }
    }
    printf("%d\n",ans);
//    for(i=n; i>=1; i--)
//    {
//        b[n-i+1]+=a[i];
//        sum-=a[i];
//        5  2 6 4
//        //t=sum-b[i];
//        //if(t<0)
//          //  printf("%d\n",-t);
//        //if(t>0)
//          //  printf("%d\n",t)
//        if((sum-b[i])>0&&(sum-b[i+1]<0))//||(b[i]-sum<0)&&(b[i+1]-sum)>0)
//            break;
//        else if(sum==b[i])
//            printf("0\n");
//
//    }
//    if(sum>b[i])
//        printf("%d\n",sum-b[i]);
//    else
//        printf("%d\n",b[i]-sum);
}


Measured memory_bytes: 128
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int a,b;
    cin>>a>>a>>b;
    cout<<(((a*10+b)%4)?"NO":"YES")<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let n = get!(usize);
    let mut b = read::<usize>();
    for i in 0..n {
        if b[i] > (i+1) {
            println!("-1");
            return;
        }
    }
    let mut s = Vec::new();
    for _i in 0..n {
        for j in (0..(b.len())).rev() {
            if b[j] == j+1 {
                s.push(b.remove(j));
                break;
            }
        }
    }
    for e in s.into_iter().rev() {
        println!("{}", e);
    }
}


Measured memory_bytes: 8572
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

MOD = 10**9 + 7

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

inv_t = [0]+[1]
for i in range(2,5):
  inv_t += [inv_t[MOD % i] * (MOD - int(MOD / i)) % MOD]

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            cnt += 1

cnt = cnt % MOD

if K >= 2:
    cnt = (cnt * K) % MOD

cnt2 = 0

if K >= 2:
    for i in range(N):
        for j in range(N):
            if A[i] > A[j]:
                cnt2 += 1

    cnt2 = cnt2 % MOD

    tmp = ( (((K) * (K-1)) % MOD)) * inv_t[2]

    cnt2 = (cnt2 * tmp) % MOD

cnt = (cnt + cnt2) % MOD

print(int(cnt))

Measured memory_bytes: 66920
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		
		System.out.println((n % 500 <= a) ? "Yes" : "No");
	}
	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

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

	ll n = x / 11; // (6,5) のペア数でわる
	ll m = x % 11; // 残りの数
	ll result = n*2; // (6,5) 始まりの回数

	bool flag = true;
	while (m > 0) {
		m -= flag ? 6 : 5;
		result++;
		flag = !flag;
	}

	cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 100 * 1000 + 7;
ll a[MAXN], dpPref[MAXN], dpSuff[MAXN], ps[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		ps[i] = ps[i - 1] + a[i];
		dpPref[i] = dpPref[i - 1];
		if (a[i] > 0)
		{
			dpPref[i] += a[i];
		}
	}
	for (int i = n; i >= 1; i--)
	{
		dpSuff[i] = dpSuff[i + 1];
		if (a[i] > 0) dpSuff[i] += a[i];
	}
	ll res = 0;
	for (int i = 1; i <= n - k + 1; i++)
	{
		res = max(res, dpPref[i - 1] + dpSuff[i + k] + max(0LL, ps[i + k - 1] - ps[i - 1]));
	}
	printf("%lld\n", res);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    rep (i, n) {
        int x, l;
        cin >> x >> l;
        int s = x - l;
        int t = x + l;
        v[i] = make_pair(t, s);
    }
    sort(all(v));
    int ans = 0;
    int nowt = -2e9;
    rep (i, n) {
        if (nowt <= v[i].second) {
            ans++;
            nowt = v[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l)
{
    T tmp = r;
    r = l;
    l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
    return is;
}

int main()
{
    ll a,b;
    cin >>a>>b;  //10^5

    ll ans= a;
    for (ll i = 0; i < b; i++){
        if (ans%b==0)break;
        ans+=a;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int an[SIZE];
bool good(int n,VPII& p){
    int it=1;
    REP(i,SZ(p)){
        an[p[i].F]=p[i].S;
    }
    REP(i,SZ(p)){
        REPP(j,1,p[i].S){
            while(an[it])it++;
            if(it>=p[i].F)return 0;
            an[it]=p[i].S;
        }
    }
    it=n*n;
    for(int i=SZ(p)-1;i>=0;i--){
        REPP(j,p[i].S,n){
            while(an[it])it--;
            if(it<=p[i].F)return 0;
            an[it]=p[i].S;
        }
    }
    return 1;
}
int main(){
    DRI(n);
    VPII p;
    REP(i,n){
        DRI(x);
        p.PB(MP(x,i+1));
    }
    sort(ALL(p));
    if(good(n,p)){
        puts("Yes");
        REPP(i,1,n*n+1)printf("%d%c",an[i]," \n"[i==n*n]);
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll n,m;
    cin >> n >> m;
    ll cand = 0;
    vector <ll> v;
    ll sum = 0;
    for(ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
//        if(tmp * 4 * m >= n){
//            cand++;
//        }
        sum += tmp;
    }
    for(ll i=0;i<n;i++){
        if(v[i] * 4 * m >= sum){
            cand++;
        }
    }

    if(cand >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    inlis = list(map(int, input().split()))
    flag = 0
    trans = 0
    now = 1
    indic = dict()
    indic[1] = 0

    while flag < 1:
        if trans < k:
            trans += 1
            tsugi = inlis[now-1]
            now = tsugi
            if tsugi not in indic:
                indic[tsugi] = trans
                #print(tsugi, indic)
            else:
                flag = 1
                loop = trans - indic[tsugi]
                yokei = indic[tsugi]
                #print(loop, yokei)

        if trans == k:
            print(tsugi)
            exit()
    
    loopamari = (k-yokei) % loop

    for _ in range(loopamari):
        tsugi = inlis[now-1]
        now = tsugi
    
    print(now)
    




if __name__ == "__main__":
    main()

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

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

	ll n, m;cin >> n >> m;m *= 2;
	vector<ll> v(n);
	ll lcm_sum = 0;
	REP(i, n){
		cin >> v[i];
		if(i)lcm_sum = lcm_sum * v[i] / gcd(lcm_sum, v[i]);
		else lcm_sum = v[i];
	}

	//cout << lcm_sum << endl;

	REP(i, n){
		if((lcm_sum / v[i]) % 2 == 0){
			cout << 0 << endl;
			return 0;
		}
	}

	cout << ((m / lcm_sum) / 2) + ((m / lcm_sum) % 2) << endl;

	return 0;
}


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


int main() {
	string s;
	cin >> s;
	long long n=s.size();
	long long mod=2019;
	vector<long long> t(n+1,0);
	t[n]=0;
	long long b=1;
	vector<long long> c(2019,0);
	t[n]=0;
	c[0]++;
	for(long long i=1;i<=n;i++){
		t[n-i]=(t[n-i+1]+b*(s[n-i]-'0'))%mod;
		c[t[n-i]]++;
		b=(b*10)%mod;
	}
	long long ans=0;
	for(long long i=0;i<2019;i++){
		ans+=c[i]*(c[i]-1)/2;
	}
	cout << ans << endl;
}


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

					using namespace std;
					typedef long long ll;
					set<int> s;
					int n, a[222222];
					int main()
					{	
						cin >> n;
						for(int i = 1; i <= n; i++)
							cin >> a[i], s.insert(a[i]);
						if(s.size() == n)
							cout << "YES";
						else cout << "NO";	
					}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	mint ans = 0;
	for (int n = K; n <= N + 1; ++n) {
		ans += ((mint)n * (N + 1-n) + 1);
	}
	cout << ans <<endl;
	return 0;
}

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

using namespace std;

const int N = 1e5 + 10;

vector<int> edge[N];
int dp[N];

int solve(int u) {
  if (edge[u].empty()) return 0;
  int &ret = dp[u];
  if (ret != -1) return ret;
  for (auto v : edge[u]) {
    ret = max(ret, 1 + solve(v));
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    edge[x].push_back(y);
  }
  memset(dp, -1, sizeof dp);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res = max(res, solve(i));
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
bool used[105];

int main()
{
	int N;
	cin >> N;
	int ans = 0;
	rep(i,N)
	{
		int d;
		cin >> d;
		if (!used[d])
		{
			ans++;
			used[d] = true;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {

	static final int CRANE = 2;
	static final int TURTLE = 4;

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

		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();

		if (CRANE * x == y || TURTLE * x == y) {
			System.out.println("Yes");
			return;
		}

		int crane_num = 4 * x - y;
		if (crane_num < 0 || crane_num % 2 != 0) {
			System.out.println("No");
			return;
		}
		crane_num /= 2;
		if (x - crane_num < 0) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");

	}
}


Measured memory_bytes: 27000
// https://onlinejudge.u-aizu.ac.jp/challenges/search/titles/1160
// dfs

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;

int field[55][55];
int W, H;

void dfs(int y, int x)
{
    field[y][x] = 0;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            if (i == 0 && j == 0) continue;
            int nx = x + i;
            int ny = y + j;
            if (nx >= 0 && ny >= 0 && nx < W && ny < H && field[ny][nx] == 1) {
                dfs(ny, nx);
            }
        }
    }
}

void Main()
{
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        memset(field, 0, sizeof(field));
        rep(i, H)
        {
            rep(j, W)
            {
                cin >> field[i][j];
            }
        }
        int cnt = 0;
        rep(i, H)
        {
            rep(j, W)
            {
                if (field[i][j] == 1) {
                    dfs(i, j);
                    ++cnt;
                }
            }
        }
        cout << cnt << endl;
    }
}

int main()
{
    // cin.tie(nullptr);
	// ios_base::sync_with_stdio(false);
	Main();
}



Measured memory_bytes: 3200