akhauriyash/Code-Regression huggingface dataset:
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def len_count(S):
    H, W = len(S), len(S[0])
    L = [[0] * W for _ in range(H)]
    for row_S, row_L in zip(S, L):
        vec = [1]
        for i in range(1, W):
            if row_S[i - 1] == row_S[i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = row_S[0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    row_L[i] = n
            idx += n
            valid = not valid

    return L


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    L1 = len_count(S)
    L2 = len_count(list(zip(*S)))

    ans = 0
    for i in range(H):
        for j in range(W):
            if ans < L1[i][j] + L2[j][i] - 1:
                ans = L1[i][j] + L2[j][i] - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define fur(i,n,m,k) for (int i = (n) ; i < (m) ; i += k)
#define fr(i,n,m,k) for (int i = (n - 1) ; i >= (m) ; i -= k)
#define pub push_back
#define pob pop_back
#define Sz size()
#define F first
#define S second

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const int maxn=1e6+20;
ll n,t,b,a,sum,d;
bool bo;
int main(){
	cin>>t;
	n=t;
	while(t--){
		if(n%3!=0&&n%5!=0){
			sum+=n;
		}
		n--;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  int j;
  for(int i = a; i <= b; i++){
    if(i / 10000 == i % 10 && i / 1000 % 10 == i / 10 % 10){
      j++;
    }
  }
  cout << j << endl;
}

Measured memory_bytes: 384
while True:
    try:
        a = list(map(int,input().split()))
        b = list(map(int,input().split()))
    except:
        break
    hit = 0
    blow = 0
    for i in range(4):
        if a[i] == b[i]:
            hit += 1
    for i in range(4):
        if a[i] != b[i]:
            if b[i] in a:
                blow += 1
    print(hit,blow)


Measured memory_bytes: 5596
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]
 
A = [0]
B = [0]
C = [0]
for i in range(N):
    a = abc[i][0] + max(B[-1], C[-1])
    b = abc[i][1] + max(A[-1], C[-1])
    c = abc[i][2] + max(A[-1], B[-1])
    A += [a]
    B += [b]
    C += [c]
print(max(A[-1], B[-1], C[-1]))

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

static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int MAX=10000;
static const int INFTY=(1<<20);

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
  
  priority_queue<pair<int, int> > PQ;
  int i,j,u,color[MAX],d[MAX],v;
  
  for(i=0;i<n;i++){
   
    color[i]=WHITE;
    d[i]=INFTY;
  }
   color[0]=GRAY;
  d[0]=0;
  PQ.push(make_pair(0,0));
 

  while(!PQ.empty()){
    pair<int, int> f=PQ.top();  PQ.pop();
  
    u=f.second;
    color[u]=BLACK;
    
    if(d[u]<f.first*(-1))continue;

    for(j=0;j<adj[u].size();j++){
      v=adj[u][j].first;
      if(color[v]==BLACK)continue;
      if(d[v]>d[u] + adj[u][j].second){
	d[v]=d[u]+adj[u][j].second;

	PQ.push(make_pair(d[v]*(-1),v));
	color[v]=GRAY;

      }
    }
  }
  for(i=0;i<n;i++){
    cout<<i<<" "<<(d[i] == INFTY ? -1:d[i])<<endl;

  }
  
}

int main(){
  int i,k,u,v,c,j;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));

    }
    
  }

  dijkstra();

  return 0;
}

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

int main() {
	int N;
  	cin>> N;
  	vector<int> a(N);
    string ans="YES";
  
  	for(int i=0;i<N;i++){
     	 cin>>a.at(i);
    }
  
  	sort(a.begin(),a.end());
  
  	for(int i=0;i<a.size()-1;i++){
     	 if(a.at(i)==a.at(i+1)){
          	ans="NO";
         }
    }
  	
  	cout<<ans<<endl;
}

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

int main(){
	long n, x;
	while (cin >> n >> x){
		//cin >> n >> x;
		//n = 100;
		//x = 297;
		if (n == 0 && x == 0) break;
		long cnt = 0;
		for (long i = 1; i <= n; i++){
			if (i > x) break;
			for (long j = i + 1; j <= n; j++){
				if (i + j > x) break;
				for (long k = j + 1; k <= n; k++){
					if (i + j + k == x) cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;

#define ull long long

int main(){

    int n;
    cin >> n;

    vector<double> a;

    rep(i,n){
        double tmp;
        cin >> tmp;

        a.pback(tmp);
    }

    double sum = 0.0;

    rep(i,n){
        sum = sum + 1.0 / a[i];
    }

    cout << setprecision(10) << 1.0 / sum << endl;


    return 0;
}

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

//#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    int cost[n];
    int a[n][m];
    for (int i = 0; i < n; i++) {
        cin >> cost[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int res = 1e9;
    for (int i = 0; i < (1<<n); i++) {
        int cnt[m];
        int sum = 0;
        for (int j = 0; j < m; j++) cnt[j] = 0;
        for (int j = 0; j < n; j++) {
            if (i&(1<<j)) {
                sum += cost[j];
                for (int k = 0; k < m; k++) {
                    cnt[k] += a[j][k];
                }
            }
        }
        bool flag = false;
        for (int j = 0; j < m; j++) if (cnt[j] < x) flag = true;
        if (!flag) res = min(res, sum);
    }
    if (res == 1e9) cout << "-1\n";
    else cout << res << '\n';
}
/*

 */

Measured memory_bytes: 3588
import sys

fin = sys.stdin.readline

N, M = map(int, fin().split())

ks = [tuple(map(int, fin().split())) for i in range(M)]
p = tuple(map(int, fin().split()))

count = 0

for i in range(2 ** N):
    switch = format(i, "b").zfill(N)
    ok = 1
    for ks_, p_ in zip(ks, p):
        p__ = p_
        for s in ks_[1:]:
            p__ += int(switch[s - 1])
        if p__ % 2 == 1:
            ok = 0
            break
    if ok:
        count += 1

print(count)


Measured memory_bytes: 40944
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        int s;
        for(int i = 0; i < 3; i++){
            a[i] = sc.nextInt();
        }

        for(int i = 0; i < 2; i++){
            for(int j = 2; j > i; j--){
                if(a[j] < a[j-1]){
                    s = a[j];
                    a[j] = a[j-1];
                    a[j-1] = s;
                }
            }
        }
        System.out.printf("%d %d %d\n", a[0], a[1], a[2]);
    }
}


Measured memory_bytes: 26324
#include "bits/stdc++.h"
using namespace std;
const int N = 1e6 + 5;
long long n;
long long a[N];
bool vis[N];
int main()
{
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            cin >> n;
            for(int i = 1 ; i <= n ; i++){
                    cin >> a[i];
            }
            int refs = 1;
            int st = 0;
            while(vis[refs] == false){
                    vis[refs] = true;
                    refs = a[refs];
                    st++;
                    if(refs == 2){
                            cout << st << endl;
                            return 0;
                    }
            }
            cout << -1 << endl;
            return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll h,w,n;
	cin>>h>>w>>n;
	ll u,v;
	cin>>u>>v;
	string s,t;
	cin>>s>>t;

	map<char,ll> mps,mpt;
	REP(i,n){
		mps[s[i]]++;
		
		if(w-v<mps['R']-mpt['L']){
			cout<<"NO"<<endl;
			return 0;
		}
		if(v-1<mps['L']-mpt['R']){
			cout<<"NO"<<endl;
			return 0;
		}
		if(h-u<mps['D']-mpt['U']){
			cout<<"NO"<<endl;
			return 0;
		}
		if(u-1<mps['U']-mpt['D']){
			cout<<"NO"<<endl;
			return 0;
		}

		mpt[t[i]]++;
		if(w-v<mpt['R']-mps['L']){
			mpt[t[i]]--;
		}
		if(v-1<mpt['L']-mps['R']){
			mpt[t[i]]--;
		}
		if(h-u<mpt['D']-mps['U']){
			mpt[t[i]]--;
		}
		if(u-1<mpt['U']-mps['D']){
			mpt[t[i]]--;
		}
	}


	cout<<"YES"<<endl;

	return 0;
}




Measured memory_bytes: 920
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn,now,ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


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

using namespace std;

int main()
{
  int  n,k;
  cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   } int sum=0;
    sort(a,a+n);
   for(int i=0;i<k;i++)
   {
       sum=sum+a[i];
   }
    cout<<sum<<"\n";
        return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#define endl '\n'

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m;
	int arr[101];
	int sum = 0;

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
	}

	sort(arr, arr + n, greater<int>());

	for (int i = 0; i < m; i++)
	{
		if ((double)arr[i] < (double)sum / (double)(4 * m))
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define time clock_t tStart = clock();
#define show printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define ll                    long long int
#define loop(a,b)             for(int i=a;i<=b;++i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define tcase()               ll t,n; cin>>t;n=t; while(t--)
#define iscn(num)             scanf("%d",&num);
#define eb                    emplace_back
#define ull                   unsigned long long
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    KAMEHAMEHA
//    #ifdef _soumik
//        freopen("input.txt", "r", stdin);
//    #endif
    int n,d;
    cin>>n>>d;
    cout<<ceil((double)n/(2*d+1))<<endl;
    return 0;
}




Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let mut count = [0u32; 26];
    loop {
        let s = read::<String>();
        if s.len() == 0 { break; }
        for c in s.chars() {
            let n = c as usize;

            if 65 <= n && n <= 90 {
                count[n - 65] += 1;
            } else if 97 <= n && n <= 122 {
                count[n - 97] += 1;
            }
        }
    }

    for i in 0..26usize {
        println!("{} : {}", ((i + 97) as u8) as char, count[i]);
    }
}



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

void output(int N, int A[]) {
    for (int i = 0; i < N; i++) {
        if (i == N-1) {
            cout << A[N-1] << endl;
            break;
        }
        cout << A[i] << " ";
    }
}

int main() {
    int N, j, key;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    output(N, A);

    for (int i = 1; i < N; i++) {
        key = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > key) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        output(N, A);
    }
    return 0;
}


Measured memory_bytes: 3104
h,w,d,i,f;main(c){for(;scanf(f="%d %d\n",&h,&w)*h;c=printf(f,h,w))for(d=i=h*h+w*w;c;d++)for(h*=d==i;c&&++h<(w=sqrt(d-h*h));c=h*h+w*w-d);}

Measured memory_bytes: 604
import scala.io.StdIn._
object Main extends App {
  readLine
  val hs = readLine.split(" ").map(_.toInt)
  val possible = (hs.scanLeft(0){(pre, h) =>
    if (h < pre) -1
    else if (h == pre) h
    else h - 1
  }).forall(_ >= 0)

  println(if (possible) "Yes" else "No")
}

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

string s;

int main() {
    cin >> s;
    
    int n = (int) s.length();
    int now = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') now ++;
        else
            now = 0;

        ans = max(ans, now);
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl




signed main(){

	string S;
	cin >> S;
	int N = S.length();
	int ans = N;
	for (int i = 0; i < N - 1; i++){
		if (S[i] != S[i + 1]){
			ans = min(ans, max({ i + 1, N - i - 1 }));
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 512
N = int(input())
A = []
D = {}
cnt = 0

for i in range(N):
    S=''.join(sorted(input()))#文字列で受け取る
    A.append(S)

for s in A:
    if s in D:
        cnt += D[s]
        D[s] += 1 #D[s]=これまでのs登場回数
    else:
        D[s]=1
print(cnt)

Measured memory_bytes: 66904
#include<iostream>
#define N 5
#define M 40

using namespace std;

int main(){
  int x, ans=0;
  for(int i=0; i<N; ++i){
    cin >> x;
    ans += (x>M ? x : M);
  }
  cout << ans/N << endl;
  return 0;
}

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

int main()
{
  int cnt = 0;
  string S, T;
  cin >> S >> T;
  for(int i=0; i<S.size(); i++)
  {
    if(S[i] == T[i])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3636
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a = int(input())
    print((24-a)+24)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#!/usr/bin/env python3
import sys, fractions, math

def eratosthenes_sieve(n: int):
    """
    エラトステネスの篩を用いてn以下の素数を求める
    """
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    
    return prime_list

def prime_factorization(n: int, prime_list: "List[int]"):
    """
    n: 素因数分解したい数
    prime_list: sqrt(n)までの素数が格納されたリスト
    -------------------
    prime_count: 素因数の個数が入ったCounterオブジェクト
    """
    import collections
    prime_count = collections.Counter()
    
    for i in prime_list:
        if i * i > n:
            break
        while n % i == 0:
            n /= i
            prime_count[int(i)] += 1
    if n > 1:
        prime_count[int(n)] += 1
    
    return prime_count

def solve(A: int, B: int):
    g = fractions.gcd(A, B)
    prime_list = eratosthenes_sieve(math.ceil(math.sqrt(g)))
    prime_count = prime_factorization(g, prime_list)
    print(len(prime_count) + 1)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16168
import sys
n,k=map(int,input().split())
alist=list(map(int,input().split()))

vislist=[1]
visset={1}
loopflag=True
endflag=False
donek=0
ima=1

while loopflag:
    ima=alist[ima-1]
    if ima in visset:
        loopflag=False
        if ima == alist[ima-1]:
            endflag=True
    else:
        vislist.append(ima)
        visset.add(ima)

        donek+=1

        if donek == k:
            loopflag=False
            endflag=True

if endflag:
    print(ima)
    sys.exit()

loopstartindex=vislist.index(ima)
looplength=len(visset)-loopstartindex
if (k+1-loopstartindex)%looplength == 0:
    print(vislist[-1])
else:
    print(vislist[loopstartindex+(k+1-loopstartindex)%looplength-1])



Measured memory_bytes: 32556
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()

//グローバル変数宣言
 ll p=0,q=0,r=0;

int main(){
  ll x1,y1,x2,y2,x3=0,y3=0,x4=0,y4=0;
  cin>>x1>>y1>>x2>>y2;
  p=x1-x2;
  q=y1-y2;

  x3=x2+q;
  y3=y2-p;
  x4=x3+p;
  y4=y3+q;
  cout<<x3<<' '<<y3<<' '<<' '<<x4<<' '<<y4<<endl;
}

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

vector<int> tsort_Kahn(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<int> indeg(V,0);
    stack<int>  S;

    // ??¨???????????????????????????????????\?¬???°????¨????
    for(auto& u_out_edges : g)
	for(auto& v : u_out_edges)
	    indeg[v]++;

    // ??\?¬???° == 0 ?????????????¨????
    for(int i=0; i<V; ++i) 
	if( indeg[i] == 0 )
	    S.push(i);

    vector<int> ans;
    while( S.size() > 0 ) {
	int u = S.top(); S.pop();
	ans.emplace_back(u);
	for(auto& v : g[u]) {
	    indeg[v]--;
	    if( indeg[v] == 0 ) S.push(v);
	}
    }
    return ans;
}

void visit(const vector<vector<int>>& g, int u, vector<bool>&used, vector<int>& ans) {

    if( used[u] == false ) {
	used[u] = true;
	for(auto& v : g[u]) {
	    visit(g, v, used, ans);
	}
	ans.emplace_back(u);
    }
}

vector<int> tsort_Tarjan(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<bool> used(V,false);
    vector<int> ans;
    for (int u=0; u<V; ++u) {
	visit(g, u, used, ans);
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

// tsort_Kahn??¨???????????????
vector<int> tsort_BFS(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<int> indeg(V,0);
    queue<int>  Q;

    // ??¨???????????????????????????????????\?¬???°????¨????
    for(auto& u_out_edges : g)
	for(auto& v : u_out_edges)
	    indeg[v]++;

    // ??\?¬???° == 0 ?????????????¨????
    for(int i=0; i<V; ++i) 
	if( indeg[i] == 0 )
	    Q.push(i);
    
    vector<int> ans;
    while( Q.size() ) {
	int u = Q.front(); Q.pop();
	ans.emplace_back(u);
	for(auto& v : g[u]) {
	    indeg[v]--;
	    if( indeg[v] == 0 ) Q.push(v);
	}
    }
    return ans;
}



int main () {

    int V,E;
    cin >> V >> E;

    vector<vector<int>> g(V);
    for (int i=0; i<E; ++i) {
	int s,t;
	cin >> s >> t;
	g[s].emplace_back(t);
    }

    vector<int> ans = tsort_Kahn(g);
    for(auto& e : ans) {
	cout << e << endl;
    }

    
    
    return 0;
}

Measured memory_bytes: 3688
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var hps = lines[0].split(" ").map(x => Number(x))
  var attack = lines[1].split(" ").map(x => Number(x))
  var hp = hps[0]
  var atk_cnt = attack.reduce((a,x) => a += x, 0)
  if (atk_cnt >= hp) {
    console.log("Yes")
  } else {
    console.log("No")
  }
});

Measured memory_bytes: 17356
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n;
int many[1010];
int ans = 1;
int mod = 1000000007;
signed main()
{
  cin >> n;
  for(int i = 1; i <= n; i++){
    int num = i;
    for(int j = 2; j * j <= n; j++){
      while(num % j == 0){
	many[j]++;
	num /= j;
      }
    }
    many[num]++;
  }

  for(int i = 2; i <= n; i++){
    ans *= many[i] + 1;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        k: usize,
        s: chars
    }

    let mut s = s;
    s[k - 1] = (s[k - 1] as u8 + 32) as char;

    println!("{}", s.into_iter().collect::<String>());
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#include <array>
#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(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

int ans = 0;

int dfs(ll a,ll n, int bit) {
	if (a > n) { return 0; }
	if (bit==0b111)
		ans++;

	dfs(a * 10 + 3, n, 0b001 | bit);
	dfs(a * 10 + 5, n, 0b010 | bit);
	dfs(a * 10 + 7, n, 0b100 | bit);
}

int main() {
	ll n; CI n;
	dfs(0, n, 0b000);
	CO ans EN;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f;
int main(){
    int n,m;
    cin>>n>>m;
    int s,c,fg=1;
    int a[4];
    for(int i=1;i<=3;i++) a[i]=-1;
    for(int i=1;i<=m;i++){
        scanf("%d %d",&s,&c);
        if(a[s]!=-1&&a[s]!=c) fg=0;
        a[s]=c;
    }
    if(a[1]==0&&n!=1) fg=0;
    if(fg==0) printf("-1");
    else {
        if(n==1) {
            if(a[1]==-1) printf("0");
            else printf("%d",a[1]);
        }
        else{
            for(int i=1;i<=n;i++){
                if(i==1&&a[i]==-1) printf("1");
                else if(i!=1&&a[i]==-1) printf("0");
                else printf("%d",a[i]);
            }
        }

    }

    return 0;
}



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

int main() {
    int n, m, x[100000], d[100000], ans;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> x[i];
    }
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(x, x+m);
    for(int i=0;i<m-1;i++){
        d[i] = x[i+1] - x[i];
    }
    sort(d, d+m-1, greater<int>());
    ans = x[m-1] - x[0];
    for(int i=0;i<n-1;i++){
        ans -= d[i];
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int vs[100];

int main(void) {
  int n;
  cin >> n;
  int res = 0;
  REP(i, n) {
    cin >> vs[i];
    REP(j, i) {
      res += vs[i] * vs[j];
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 888
# coding: utf-8
N = int(input())
S = input()

if N%2 != 0:
    print("No")
    exit(0)

else :
    n = N//2
    s1 = S[0:n]
    s2 = S[n:N]
    
    if (s1 == s2):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std ;
#define ll  long long 
#define dl long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second


int main ()
{
	ll n,a=0,w=0,t=0,r=0 ;
	cin >>n ;
	for (int i = 0 ;i<n;i++)
	{
		string s ;
		cin >>s;
		if (s[0]=='A')
			a++;
		else if (s[0]=='W')
			w++;
		else if (s[0]=='T')
			t++;
		else 
			r++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;
   

	return 0;

}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main(){
  int N,d[105],sum=0;
  
  cin>>N;
  
  for(int i=0;i<N;i++){
   cin>>d[i]; 
  }
  
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      sum+=d[i]*d[j];
    }
  }
    
  cout<<sum;
    
   
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

tuple<int,bool> dfs(const vector<vecint>& g,
    int i, int p = -1) {
  int res = 0;
  bool ok = true;
  int cch = 0;
  int ccz = 0;
  for (auto&& to : g[i]) {
    if (to == p) continue;
    ++cch;
    int cr, cz;
    tie(cr, cz) = dfs(g, to, i);
    if (!cz) ok = false;
    else {
      ++ccz;
      if (ccz > 1) ++cr;
    }
    res += cr;
  }
  if (cch > 1) ok = false;
  return make_tuple(res, ok);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<vecint> g(n);
  REP(i,n-1) {
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vecint dis(n, n);
  dis[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (auto&& to :g[i]) {
      if (dis[to] > dis[i] + 1) {
        dis[to] = dis[i] + 1;
        q.push(to);
      }
    }
  }
  int root = max_element(ALL(dis)) - begin(dis);
  int ans;
  tie(ans, ignore) = dfs(g, root);
  cout<<1+ans<<endl;
  return 0;
}


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

int main()
{
    string S;
    int check;
    do{
        check = 0;
        cin >> S;
        for(int i=0;i<3;i++){
            if(S[i] != 'A' && S[i] != 'B')check = 1;
        }
        
    }while(S.length()!=3 || check == 1);

    if(S=="AAA" || S=="BBB"){
        cout << "No";
    }else{
        cout << "Yes";
    }
    

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

vl f(vl a,vl b){
	vl c(n+1);
	ll m=0;
	for(int i=1;i<=n;i++) b[i]+=b[i-1];
	for(int i=1;i<=n;i++){
		m=min(m,a[i]-b[i]);
		c[i]=m+b[i];
	}
	return c;
}

vl a,b,c;

int main(){
	cin>>n;
	a=b=c=vl(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(!a[i]) c[i]=2;
		else c[i]=a[i]%2;
		b[i]=a[i]+b[i-1];
	}
	b=f(b,c);
	for(int i=1;i<=n;i++) c[i]=(a[i]+1)%2;
	b=f(b,c);
	for(int i=1;i<=n;i++){
		if(!a[i]) c[i]=2;
		else c[i]=a[i]%2;
	}
	b=f(b,c);
	b=f(b,a);
	cout<<b[n]<<endl;
}

Measured memory_bytes: 9644
n,m = map(int,input().split())

l = ['a']*(n+1)
for i in range(m):
    s,c = map(int,input().split())
    if l[s-1] == 'a':
        l[s-1] = c
    else:
        if l[s-1] != c:
            l[n] = 'N'

    
if n == 1 and l[n] =='a':
    if l[0] == 'a':
        print(0)
    else:
        print(l[0])
else:
    if l[0] == 'a':
        l[0] = 1
    if l[0] ==0:
        l[n] = 'N'
    if l[n] == 'N':
        print('-1')
        
    else:
        for i in range(n):
            if l[i] == 'a':
                l[i] = 0
        del l[-1]
        ans = map(str,l)
        ans = ''.join(ans)
        print(ans)

Measured memory_bytes: 3064
a,b,c,d=map(int,input().split())
A=0
if a%d==0:
  A=a//d
else:
  A=a//d+1
if c%b==0:
  T=c//b
else:
  T=c//b+1
if T<=A:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
  	ll n;cin>>n;
    ll w[n];rep(i,0,n)cin>>w[i];

    ll ans = 10000;
    rep(i,0,n){
        ll tmp1 = 0, tmp2 = 0;
        rep(j,0,i) tmp1+=w[j];
        rep(j,i,n) tmp2+=w[j];
        if(ans > abs(tmp1-tmp2)) ans = abs(tmp1-tmp2);
    }
    cout << ans << ednl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MOD 1000000007
int n;
long long d;
long long dp[51][51][61];
long long cur[51], temp[51];
long long o = 0;
int main () {
	cin >> n >> d;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			cin >> dp[i][j][0];
		}
	}
	for (int k=1; k<=60; k++) {
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				for (int m=0; m<n; m++) {
					dp[i][j][k] += (dp[i][m][k-1]*dp[m][j][k-1])%MOD;
					dp[i][j][k] %= MOD;
				}
			}
		}
	}
	for (int i=0; i<n; i++) {
		cur[i] = 1;
	}
	for (int k=0; k<=60; k++) {
		if ((d&(1ll<<k)) == 0) continue;
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				temp[j] += (cur[i]*dp[i][j][k])%MOD;
				temp[j] %= MOD;
			}
		}
		for (int i=0; i<n; i++) {
			cur[i] = temp[i];
			temp[i] = 0;
		}
	}
	for (int i=0; i<n; i++) {
		o += cur[i];
		o %= MOD;
	}
	cout << o << endl;
}

Measured memory_bytes: 4816
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int AC=0,WA=0,TLE=0,RE=0;
        String str = null;
        for(int i=0;i<N;i++){
             str = scanner.next();
             if(str.equals("AC")){
                 AC++;
             }else if(str.equals("WA")){
                 WA++;
             }else if(str.equals("TLE")){
                 TLE++;
             }else{
                 RE++;
             }
        }
        System.out.println("AC x "+AC);
        System.out.println("WA x "+WA);
        System.out.println("TLE x "+TLE);
        System.out.println("RE x "+RE);
    }
}


Measured memory_bytes: 58488
n = int(input())
A = list(map(int,input().split()))
dp = [[[0,0,0] for i in range(2)] for i in range(n+1)]
for i in range(1,n+1):
    if i%2 == 1:
        if i > 1:
            dp[i][0][1] = dp[i-1][1][0]+A[i-1]
            dp[i][0][2] = dp[i-1][1][1]+A[i-1]
            dp[i][1][0] = max(dp[i-1][0][0],dp[i-1][1][0])
            dp[i][1][1] = max(dp[i-1][0][1],dp[i-1][1][1])
        else:
            dp[i][0][2] = A[0]
    else:
        dp[i][0][0] = dp[i-1][1][0]+A[i-1]
        dp[i][0][1] = dp[i-1][1][1]+A[i-1]
        dp[i][1][0] = max(dp[i-1][0][1],dp[i-1][1][1])
        dp[i][1][1] = dp[i-1][0][2]
if n%2 == 0:
    print(max(dp[n][0][1],dp[n][1][1]))
else:
    print(max(dp[n][0][1],dp[n][1][1]))

Measured memory_bytes: 96516
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n int
		s []string
		max int = -100
	)
	fmt.Scan(&n)

	s = make([]string, n)
	count := make(map[string]int)

	for i := 0; i < n ; i++ {
		fmt.Scan(&s[i])
	}

	for _, ss := range s {
		count[ss] += 1
		if count[ss] > max {
			max = count[ss]
		}
	}

	slice := make([]string, n)
	index := 0
	for key := range count {
		slice[index] = key
		index++
	}
	sort.Strings(slice)

	for _, k := range slice{
		if count[k] == max {
			fmt.Println("\n" + k)
		}
	}
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

struct Edge{
    ll from, to, cost;
};

using Edges = vector<Edge>;

bool bellman_ford(Edges &Es, int V, int s, vector<ll>& dis){
    dis.resize(V,LINF);
    dis[s] = 0;
    int cnt = 0;
    ll t_num;
    while(cnt < 2*V){
        bool end = true;
        for(auto e: Es){
            if(dis[e.from] != LINF && dis[e.from]+e.cost < dis[e.to]){
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if(end) return false;
        if(cnt==V-1) t_num = dis[V-1];
        cnt++;
    }
    return (t_num!=dis[V-1]);
}

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

    Edges Es(M);
    REP(i,M){
        int a,b,c; cin >> a >> b >> c;
        a--;b--;
        Es[i] = {a,b,-c};
    }

    vector<ll> dis;
    if(!bellman_ford(Es, N, 0, dis)){
        cout << -dis[N-1] << endl;
    }else{
        cout << "inf" << endl;
    }



    return 0;
}

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

using namespace std;
#define ll long long



int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	string s;
	cin >> s;
	if (s.size() <= n) {
		cout << s << "\n";
	}
	else {
		string ans = s.substr(0, n);
		ans += "...";
		cout << ans << "\n";
	}




	return 0;

}

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

n = int(input())
a = [input() for i in range(n)]
count = 0

for i in range(n - 1):
    if a[i][-1] != a[i+1][0]:
        count += 1

import collections
b = collections.Counter(a)

if b.most_common(1)[0][1] >= 2:
    count += 1

if count == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
import sys
input = sys.stdin.readline



def main():
    n, k = map(int, input().split())
    p = [int(x)-1 for x in input().split()]
    c = list(map(int, input().split()))
    
    doubling = [[0]*n for i in range(31)]
    doubling_max = [[0]*n for i in range(31)]
    place = [[0]*n for i in range(31)]
    
    ans = -1000000000
    for i in range(n):
        sub = c[p[i]]
        if sub >= 0:
            break
        if ans < sub:
            ans = sub
        if i == n-1:
            print(ans)
            sys.exit()
            
    
    for i in range(31):
        if i == 0:
            for j in range(n):
                doubling[i][j] = c[p[j]]
                place[i][j] = p[j]
            continue
        for j in range(n):
            place[i][j] = place[i-1][place[i-1][j]]
            doubling[i][j] = doubling[i-1][j]+doubling[i-1][place[i-1][j]]
    
    for i in range(31):
        if i == 0:
            for j in range(n):
                doubling_max[i][j] = doubling[i][j]
            continue
        for j in range(n):
            doubling_max[i][j] = max(doubling_max[i-1][j], doubling[i-1][j]+doubling_max[i-1][place[i-1][j]])
    
    ans = 0
    judge = []
    key = 0
    while k:
        if k%2:
            judge.append(key)
        k //= 2
        key += 1
    judge.reverse()
    
    for i in range(n):
        pl = i
        key = 0
        for j in range(len(judge)):
            if ans < key+doubling_max[judge[j]][pl]:
                ans = key+doubling_max[judge[j]][pl]
            key += doubling[judge[j]][pl]
            pl = place[judge[j]][pl]
        

    print(ans)
        
    


    
    
if __name__ == "__main__":
    main()


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

int main(void){
    int n;
    cin >> n;
    
    int a[100000] = {0};
    int i;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a, a + n);
    
    int num = 0;
    int cnt = 0, ans = 0;
    for(i = 0; i < n; i++){
        if(num != a[i]){
            if(cnt >= num){
                ans += cnt - num;
            }else{
                ans += cnt;
            }
            num = a[i];
            cnt = 0;
        }
        
        cnt++;
    }
    
    if(cnt >= num){
        ans += cnt - num;
    }else{
        ans += cnt;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < 9; i++){
    if(n % (9 - i) == 0){
      n /= (9 - i);
      if(n <= 9){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
      break;
    }
  }
}


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

int main() {
  int N;
  int r;
  int flag =0;
  r=0;
  string s;
  cin >> N >> s;

  int i =0;
  while(i<N){
    if(s[i] == 'R')r++;
      i++;
      if(r> (N/2)) {
	flag =1;
      }
  }
  if(flag ==1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
H,W=map(int, input().split())
S=["."+input()+"." for _ in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]
ans="Yes"
for i in range(H):
    for j in range(W):
        if S[i][j]=="#" and S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
            ans="No"
print(ans)

Measured memory_bytes: 3064
N,D = map(int,input().split())
 
X = [list(map(int,input().split())) for _ in range(N)]
 
ans = 0
for i in range(N):
  for j in range(i):
    tmp = 0
    for k in range(D):
      tmp += (X[i][k] - X[j][k]) ** 2
    tmp = tmp ** 0.5
    if tmp % 1 == 0:
      ans += 1
      
print(ans)

Measured memory_bytes: 3064
using System;

namespace A___Expired
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var x = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            var b = int.Parse(input[2]);
            if (-a + b > x)
            {
                Console.WriteLine("dangerous");
            }
            else if (-a + b <= 0)
            {
                Console.WriteLine("delicious");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;

  cout << (k==1 ? 0 : n-k) << endl;
  return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())

seq = [int(i) for i in input().split()]

ans = 0

for i in range(N-1):
    if seq[i]+seq[i+1] > x:
        dec = seq[i]+seq[i+1] - x
        if seq[i+1] > dec:
            seq[i+1] = seq[i+1] - dec
        else:
            seq[i+1] = 0
            seq[i] = seq[i] - dec + seq[i+1]
        ans += dec

print(ans)

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

int main(){
  int N;
  cin>>N;
  double X[N];
  double count=0;
  rep(i, N){
      cin>>X[i];
      count+=X[i];
  }
  double a=count/N;
  int b=a+0.5;
  int ans=0;
  rep(i, N){
      ans+=(X[i]-b)*(X[i]-b);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from fractions import gcd
a, b, k = map(int, input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    print(divisors[len(divisors) - k])
make_divisors(gcd(a, b))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define cs const 
#define int long long
#define mid ((l+r)>>1)
#define low(i) (i&(-i))
#define ls (now<<1)
#define rs (now<<1|1)
#define rep(i, x, y) for(int i=x; i<=y; ++i)
cs int ff = 1e6+1;
cs int mod = 1e9+7;
int a, b;
void init()
{
	cin >> a >> b;
	rep(i, 1, 1e6)
		if( (int) i * 8 / 100 == a && (int) i / 10 == b )
			cout << i << endl, exit(0);
	puts("-1");
}
signed main()
{
	init();
} 

Measured memory_bytes: 256