akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderMake.EX_HITACHI2020
{
    class H20A
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            if (s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
package main

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

type AP struct {
	acknowledged int
	penalty      int
}

var buf = bufio.NewScanner(os.Stdin)

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

func scanInts(n int) []int {
	a := make([]int, n)
	for k, _ := range a {
		a[k] = scanInt()
	}
	return a
}

func scanString() string {
	buf.Scan()
	return buf.Text()
}

func main() {
	buf.Split(bufio.ScanWords)

	n := scanInt()
	m := scanInt()
	ap := make([]AP, n)
	for i := 0; i < m; i++ {
		p := scanInt()
		s := scanString()
		if ap[p-1].acknowledged == 0 {
			switch s {
			case "AC":
				ap[p-1].acknowledged = 1
			case "WA":
				ap[p-1].penalty++
			}
		}
	}

	correctAnswers, penalties := 0, 0
	for _, v := range ap {
		correctAnswers += v.acknowledged
		if v.acknowledged == 1 {
			penalties += v.penalty
		}
	}
	fmt.Printf("%d %d", correctAnswers, penalties)
}


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

#define M 1000000
#define L 14

char H[M][L];

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

long long getKey(char s[]){
  long long i,sum=0,p=1;

  for(i=0;i<strlen(s);i++){
    sum+=p*(getChar(s[i]));
    p*=5;
  }
  return sum;
}

int h1(int key){ 
  return key % M; 
}

int h2(int key){ 
  return 1 + (key%(M-1)); 
}

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

int insert(char s[]){
  long long key,i,h;
  key=getKey(s);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],s)==0)return 1;
    else if(strlen(H[h])==0){ 
      strcpy(H[h],s);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char s[L],com[10];

  for(i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",com,s);

    if(com[0]=='i'){
        insert(s);
    } else {
        if (find(s)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
 
    return 0;
  }

Measured memory_bytes: 14280
def main():
    b = []
    line = input().split(" ")
    H = int(line[0])
    W = int(line[1])
    for l in range(H):
        b.append(input())

    result = []
    for i, line in enumerate(b):
        result_row = ""
        for j, c in enumerate(line):
            if c == ".":
                n = count(i, j, b, H, W)
                result_row += str(n)
            else:
                result_row += b[i][j]
        result.append(result_row)

    for l in result:
        print(l)


def count(row, column, board, H, W):
    n = 0
    rs, re = judge_row(row, H)
    cs, ce = judge_col(column, W)
    for r in range(rs, re):
        for c in range(cs, ce):
            if board[r][c] == "#":
                n += 1
    return n


def judge_row(row, H):
    if H == 1:
        return 0, 1
    elif row == 0:
        return row, row+1+1 
    elif row == H-1:
        return row-1, row+1
    else:
        return row-1, row+1+1


def judge_col(col, W):
    if W == 1:
        return 0, 1
    elif col == 0:
        return col, col+1+1 
    elif col == W-1:
        return col-1, col+1
    else:
        return col-1, col+1+1


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,d;
  cin>>N;
  int A[101]={0};
  int ans=0;
  for(int i=0;i<N;i++){
    cin>>d;
    A[d]=1;
  }
  for(int i=1;i<101;i++) ans+=A[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=1e5+10;
int V,E; 
int memo[1000][1000];
int R,C;
vi adj[MX];
char g[1000][1000];


int solve(int x, int y){
	if(x==R-1 && y==C-1) return 1;
	if(x<0 || y<0 || x>=R || y>=C || g[x][y]=='#') return 0;
	if(memo[x][y]!=-1) return memo[x][y];
	return memo[x][y]=(solve(x,y+1)+solve(x+1,y))%MOD;
}

int32_t main(){
   boost;
   IO();

   memset(memo,-1,sizeof(memo));
   /*cin>>N>>W;
   for(int i=0; i<N;i++) cin>>w[i]>>v[i];

   for(int i=100000; i>=0; i--) if(solve(0,i)<=W){cout << i << endl; return 0;}*/

   cin>>R>>C;
   for(int i=0; i<R; i++) for(int j=0; j<C; j++) cin>>g[i][j];
   cout << solve(0,0) << endl;


   return 0;
}



Measured memory_bytes: 14876
#include <bits/stdc++.h>
using namespace std;
int n;
 
int main() {
  cin >> n;
  if (n % 10 == 7 || (n / 10) % 10 == 7 || (n / 100) % 10 == 7 ) {
    cout << "Yes";
  } else {
     cout << "No";
  }
}

Measured memory_bytes: 3620
def f(n):
    digsum = 0
    while n > 0:
        digsum += n % 10
        n //= 10
    return digsum


def main():
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(1, N+1):
        x = f(i)
        if A <= x <= B:
            ans += i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41072
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
typedef double db;
ll n,a,b;


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

Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, k = LMIIS()
    aa = LMIIS()
    ff = LMIIS()
    aa.sort(reverse=True)
    ff.sort()
    a = tuple(aa)
    f = tuple(ff)


    max_ = 10**12
    min_ = 0

    while max_ != min_ + 1:
        x = (max_ + min_) // 2
        shugyo = 0
        for i in range(n):
            shugyo += max(0, a[i] - x // f[i])

        if shugyo <= k:
            max_ = x
        else:
            min_ = x


    if x == min_:
        x += 1
    if sum(a) <= k:
        x = 0
    print(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 113152
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;

  string base = "Z";
  REP(i,(lint)(s.length())){
    lint si = (lint)(unsigned char)s[i] + n;
    if(si > (lint)(unsigned char)base[0]) s[i] = (char)(si-26);
    else s[i] = (char)si;
  }
  cout << s << "\n";
  return 0;
}


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

int main(void){
    string word[4]={"dream","dreamer","erase","eraser"};
    
    string S;
    cin>>S;
    
    for(int i=0;i<4;i++) reverse(word[i].begin(),word[i].end());
    
    reverse(S.begin(),S.end());
    
    int N=S.size();
    for(int i=0;i<N;i++){
        for(int j=0;j<4;j++){
            if(S.substr(i,word[j].size())==word[j]){
                i+=word[j].size()-1;
                break;
            }
            if(j==3){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    
    cout<<"YES"<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

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

    int64_t N;
    std::cin >> N;

    std::vector<std::pair<int64_t, int64_t>> x;
    int64_t n=N;
    for(int64_t a=2; a*a <= n; ++a){
        if( n%a!=0 ){
            continue;
        }
        int64_t ex = 0;
        while (n % a == 0) {
            ++ex;
            n /= a;
        }
        x.push_back({a, ex});
    }
    if(n!=1){
        x.push_back({n, 1});
    }

    std::vector<int64_t> z;
    for(int i=0; i<x.size(); i++){
        for(int j=1; j<=x.at(i).second; j++){
            z.push_back(std::pow(x.at(i).first, j));
        }
    }

    int64_t ans=0;
    for(int i=0; i<z.size(); i++){
        if(N%z.at(i)==0){
            N /= z.at(i);
            ans++;
        }
    }

    std::cout << ans;

    return 0;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn= 1e5+10;
struct Node
{
    ll a,b;
} s[maxn];
int vis[maxn];
priority_queue<ll,vector<ll>,greater<ll> >que;
bool cmp(Node a,Node b)
{
    return a.b>b.b;
}
int main()
{
    int  n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%lld%lld",&s[i].a,&s[i].b);
 ll t=0;
    sort(s,s+n,cmp);
    ll sum=0,ans=0;
    for(int i=0; i<k; i++)
    {
        sum+=s[i].b;
        if(vis[s[i].a]==0)
        {
            vis[s[i].a]=1;
            t++;

        }
        else
            que.push(s[i].b);

    }
     ans=sum+t*t;
    for(int i=k; i<n; i++)
    {
        if(vis[s[i].a])
            continue;
       if(que.empty()||t==k)
           break;
        ll qq=que.top();
          t++;
          sum-=qq;
          sum+=s[i].b;
        que.pop();
        vis[s[i].a]=1;
    ans=max(ans,sum+t*t);
    }
        
        cout<<ans<<endl;
        return 0;
    }


Measured memory_bytes: 2812
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
priority_queue<P, vector<P>, greater<P> > que[100010];

const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    P a[100010];
    rep(i, N) {
        cin >> a[i].first;
        a[i].second = i;
    }
    init(N);
    rep(i, M) {
        int s, t;
        cin >> s >> t;
        unite(s, t);
    }
    set<int> st;
    rep(i, N) {
        que[find(i)].push({a[i].first, i});
        st.insert(find(i));
    }
    bool used[100010] = {};
    int ans = 0;
    int V = (size - 1) * 2;
    //dump(V);
    rep(i, N) {
        if (V == 0) break;
        if (que[i].size() >= 1) {
            //cout << que[i].top().first << " " << que[i].top().second << endl;
            used[que[i].top().second] = true;
            ans += que[i].top().first;
            V--;
        }
    }
    //dump(ans);
    sort(a, a + N);
    rep(i, N) {
        if (V == 0) break;
        if (!used[a[i].second]) {
            ans += a[i].first;
            V--;
        }
    }
    if (V > 0) {
        cout << "Impossible" << endl;
    } else {
        cout << ans << endl;
    }
   


    return 0;
}


Measured memory_bytes: 14464
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

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

    cout << min(a * n, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll a,b,k;
    cin>>a>>b>>k;

    if(a-k>=0)cout<<a-k<<" "<<b<<endl;
    else if(a-k<0&&(a+b)-k>=0)cout<<'0'<<" "<<b-(k-a)<<endl;
    else if((a+b)-k<0) cout<<'0'<<" "<<'0'<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(final String[] args) {
    final Scanner scan = new Scanner(System.in);

    final int N = scan.nextInt();

    final int num = N % 10;
scan.close();
if((num==2) ||(num==4)||(num==5)||(num==7)||(num==9)){
    System.out.println("hon");
}else if((num==0)||(num==1)||(num==6)||(num==8)){
    System.out.println("pon");
}else 
System.out.println("bon");
}
}

Measured memory_bytes: 27088
s = int(input())
lst = [s]
for i in range(2,1000000):
    if s%2 == 0:
        s = s/2
        lst.append(s)
    else:
        s = 3*s + 1
        lst.append(s)
    if lst.count(s) == 2:            
        print(i)
        break

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    int n, k;
    long long ans = 0;
    cin >> n >> k;
    
    for(int b = k + 1; b <= n; b++){
        long long v = (n - b + 1) / b;
        ans += (v+1) * (b-k);
        if(b*(v+1)+k <= n){
            ans += n - b*(v+1)-k + 1;
        }
    }
    if(k == 0) ans -= n;
    cout << ans << endl;
}


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

int N;
int f1[2], f2[2], f3[2], a, b, c;

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int main() {
	N = Rd();
	for(register int i = 1; i <= N; ++i) {
		a = Rd(), b = Rd(), c = Rd();
		f1[1] = max(f2[0], f3[0]) + a;
		f2[1] = max(f1[0], f3[0]) + b;
		f3[1] = max(f1[0], f2[0]) + c;
		f1[0] = f1[1], f2[0] = f2[1], f3[0] = f3[1];
	}
	cout << max(f1[1], max(f2[1], f3[1])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int bk[n];
    int i;
    for(i=0;i<n;i++)bk[i]=0;
    for(i=1;i<n;i++){
        int a;
        cin >> a;
        bk[a-1]++;
    }
    for(i=0;i<n;i++){
        cout << bk[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4416
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = input()
    l = len(n)

    dp = [[0] * 2 for _ in range(l + 1)]

    dp[0][1] = 1

    for i, d in enumerate(n, 1):
        di = int(d)
        dp[i][0] = min(dp[i - 1][1] + (10 - di), dp[i - 1][0] + di)
        dp[i][1] = min(dp[i - 1][1] + (10 - di - 1), dp[i - 1][0] + (di + 1))

    ans = min(dp[l][0], dp[l][1] + 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 138568
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

int n,m,q;
int a,b,c,d;
int ma=0;
vector<int> A(60),B(60),C(60),D(60);

void dfs(vector<int> &T){
  if(T.size()==n+1){
    int sum=0;
    rep(i,q){
      if(T[B[i]]-T[A[i]]==C[i]) sum+=D[i]; 
    }
    chmax(ma,sum);
    return;
  }
  
  for(int i=T.back();i<m+1;i++){
    T.push_back(i);
    dfs(T);
    T.pop_back();
  }
}

int main() {
  cin>>n>>m>>q;
  rep(i,q) cin>>A[i]>>B[i]>>C[i]>>D[i];
  
  vector<int> T={1};
  dfs(T);
  
  cout<<ma<<endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

struct edge { int to, cost; };
int N,M,id=0;
vector<edge> G[500009];
map<pii,int> comid;

int getid(int node,int com){
    pii p={node,com};
    if(comid.find(p)!=comid.end()) return comid[p];
    return comid[p]=id++;
}

void addedge1(int u,int v,int c){
    u=getid(u,c), v=getid(v,c);
    G[u].push_back({v,0});
    G[v].push_back({u,0});
}

void addedge2(int u,int v,int c){
    u=getid(u,c), v=getid(v,-1);
    G[u].push_back({v,0});
    G[v].push_back({u,1});
}

int dijkstra(int s, int t, int range) {
    
    vector<int> d(range,INF);
    priority_queue< pii, vector<pii>, greater<pii> > que;   // first:cost second:頂点 cost基準の昇順
    que.push({0,s});
    d[s] = 0;
    
    while(!que.empty()){
        pii p = que.top(); que.pop();
        int v = p.second;
        if(v==t) break;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push({d[e.to],e.to});
            }
        }
    }
    return d[t];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    rep(i,M){
        int u,v,c; cin>>u>>v>>c;
        addedge1(u,v,c);
        addedge2(u,u,c);
        addedge2(v,v,c);
    }
    
    int s=getid(1,-1);
    int t=getid(N,-1);
    int ans=dijkstra(s,t,id);
    
    if(ans==INF) ans=-1;
    
    cout1(ans)
}


Measured memory_bytes: 64756
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define inf 1e9+5
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<int> dp(3);
    for(int d=0;d<n;d++){
      vector<int> newdp(3,0);
      vector<int> c(3);
      for(int m=0;m<3;m++) cin>>c[m];
      for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
              if(i!=j){
                  newdp[j]=max(newdp[j],dp[i]+c[j]);
              }
          }
      }
      dp=newdp;
    }
    cout<< max(dp[0],max(dp[1],dp[2]));
}



Measured memory_bytes: 256
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

now = 1
check = [-1]*(n+1)

for i in range(k):
  if check[now] == -1:
    check[now] = i
    now = a[now]
  else:
    loop = i - check[now]
    afterloop = (k-(i-loop))%loop
    print(check.index((i-loop) + afterloop))
    exit()
print(now)

Measured memory_bytes: 32400
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

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

int main(){ FastIO;

int k,s=0;cin>>k;
for(int i=1;i<=k;i++)
{
	for(int j=1;j<k+1;j++)
	{
		for(int p=1;p<k+1;p++)
		{
			s+=gcd(i,gcd(j,p));	
		}
	}
}
cout<<s;




return 0;
}

Measured memory_bytes: 3648
R,C = map(int,input().split(' '))
c_list = [0] * (C + 1)
for r in range(R):
    r_list = list(map(int,input().split(' ')))
    r_list.append(sum(r_list))
    print(*r_list)
    c_list = [r + c for r,c in zip(r_list,c_list)]
print(*c_list)


Measured memory_bytes: 5636
#include<iostream>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a > b)ans = a + (a - 1);
	else if (a < b) ans = b + (b - 1);
	else ans = 2 * a;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	int n;
	int matrix[11][11];
	/*****処理部*****/
	while(1){
		cin >> n;
		if(n==0)	break;
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++)
				matrix[i][j] = 0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin >> matrix[i][j];
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				matrix[i][n] += matrix[i][j];
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				matrix[n][j] += matrix[i][j];
		for(int i=0;i<n;i++)
			matrix[n][n] += matrix[i][n];
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cout.width(5);
				cout << matrix[i][j];
			}
			cout << endl;
		}
	}

	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int ans[101]={};
ans[10]=1;
ans[11]=1;
ans[12]=1;
ans[13]=1;
ans[14]=2;
ans[15]=2;
ans[16]=3;
ans[17]=3;
ans[18]=3;
ans[19]=3;
ans[20]=8;
ans[21]=8;
ans[22]=11;
ans[23]=11;
ans[24]=11;
ans[25]=11;
ans[26]=14;
ans[27]=14;
ans[28]=32;
ans[29]=32;
ans[30]=35;
ans[31]=35;
ans[32]=35;
ans[33]=35;
ans[34]=42;
ans[35]=42;
ans[36]=42;
ans[37]=42;
ans[38]=49;
ans[39]=49;
ans[40]=49;
ans[41]=49;
ans[42]=49;
ans[43]=49;
ans[44]=75;
ans[45]=75;
ans[46]=86;
ans[47]=86;
ans[48]=86;
ans[49]=86;
ans[50]=86;
ans[51]=86;
ans[52]=123;
ans[53]=123;
ans[54]=131;
ans[55]=131;
ans[56]=131;
ans[57]=131;
ans[58]=148;
ans[59]=148;
ans[60]=153;
ans[61]=153;
ans[62]=170;
ans[63]=170;
ans[64]=170;
ans[65]=170;
ans[66]=170;
ans[67]=170;
ans[68]=227;
ans[69]=227;
ans[70]=227;
ans[71]=227;
ans[72]=227;
ans[73]=227;
ans[74]=250;
ans[75]=250;
ans[76]=323;
ans[77]=323;
ans[78]=324;
ans[79]=324;
ans[80]=324;
ans[81]=324;
ans[82]=354;
ans[83]=354;
ans[84]=354;
ans[85]=354;
ans[86]=384;
ans[87]=384;
ans[88]=384;
ans[89]=384;
ans[90]=384;
ans[91]=391;
ans[92]=491;
ans[93]=491;
ans[94]=529;
ans[95]=529;
ans[96]=529;
ans[97]=529;
ans[98]=529;
ans[99]=529;
ans[100]=543;
int n;
cin >> n;
cout << ans[n] << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

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

	vector < vector<int>> A(2, vector<int>(N));
	rep(j, 2) {
		rep(i, N) {
			cin >> A[j][i];
		}
	}

	int ans = 0;
	rep(j, N) {
		int x = 0;
		rep(i, N) {
			if (j <= i) {
				if (j == i)
					x += A[0][i];
				x += A[1][i];
			}
			else {
				x += A[0][i];
			}
		}
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int o = 0;
	string s;
	cin >> s;
	for(int i = 0; i <= s.length(); i++){
		if(s[i] == 'o'){
			o++;
		}
	}
	if(15 - s.length() >= 8 - o){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  rep (i, n) cin >> h[i];
  double z = (t - a) / 0.006;
  int ans  = 0;
  double diff = DBL_MAX;
  rep (i, n) {
    if (abs(z - h[i]) < diff) {
      ans  = i + 1;
      diff = abs(z - h[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383

int main(){
   
    fast;
    
    ll n;
    ll mod = 1000000007;
	cin >> n;
	ll arr[n];
    ll sum = 0;
	for(int i=0;i<n;i++){
	    cin >> arr[i];
        sum = (sum + arr[i]);
	}
	ll ans = 0;
	
	for(int i=0;i<n;i++){
		
	}
	for(int i=0;i<n;i++){
		sum = sum - arr[i];
		ans = (ans + ((sum%mod)*(arr[i]%mod))%mod)%mod;
	}
	cout << ans << endl;










}

Measured memory_bytes: 5216
#include <cstdio>

int main(){
	int N;
	long long A,B,C,D;
	scanf("%d %lld %lld %lld %lld",&N,&A,&B,&C,&D);

	bool can = false;
	for(int m=0;m<N;m++){
		if( (N-1-m)*C-m*D <= B-A && B-A <= (N-1-m)*D-m*C ) can = true;
	}

	if(can){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;



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

    in(x);
    int n;
    cin >> n;
    int a[n];
    umapii m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    int i = 0;
    int ans;
    while (1) {
        if (!m.count(x - i) > 0) {
            ans = x - i;
            break;
        }
        if (!m.count(x + i) > 0) {
            ans = x + i;
            break;
        }
        i++;
    }
    cout << ans << endl;
}


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

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

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

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i - 1 >= 0 && i + 1 < n)
        {
            vector<int> tmp{p[i - 1], p[i], p[i + 1]};
            sort(tmp.begin(), tmp.end());
            if (tmp[1] == p[i])
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args){
        char[] s = sc.next().toCharArray();
        int n = s.length;
        int[] black = new int[n], white = new int[n]; // black[i]: paint the i-th to be black
        // The i-th tile from the left is painted black if the i-th character of S
        // is 0, and painted white if that character is 1.
        black[0] = s[0]=='1'?1:0; white[0] = s[0]=='0'?1:0;
        for(int i=1;i<n;i++){
            if(s[i]=='0'){
                black[i] = white[i-1];
                white[i] = black[i-1]+1;
            } else{
                white[i] = black[i-1];
                black[i] = white[i-1]+1;
            }
        }
        System.out.println(Math.min(white[n-1],black[n-1]));
    }
}

Measured memory_bytes: 26708
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    for (int i=0; i<=K; i++){
        for (int j=0; j<=K-i; j++){
            for (int k=0; k<=K-i-j; k++){
                if (B * pow(2, j) > A * pow(2, i) and C * pow(2, k) > B * pow(2, j)){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4000
//最大フロー問題を解くエドモンズ・カープのアルゴリズム
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9 + 7)

typedef struct {
	int *array;
	int last;
	int first;
}queue;

queue *make_queue(int maxN){
	queue *q = (queue *)malloc(sizeof(queue));
	q->array = (int *)malloc(sizeof(int) * maxN);
	q->last = 0;
	q->first = 0;
	return q;
}

int element_num_queue(queue *q){
	return q->first - q->last;
}

void add_data_queue(int val, queue *q){
	q->array[q->first] = val;
	q->first++;
}

int take_data_queue(queue *q){
	if(element_num_queue(q) <= 0){
		printf("no data in the queue\n");
	}
	q->last++;
	return q->array[q->last - 1];
}

void flush_queue(queue *q){
	q->last = 0;
	q->first = 0;
}

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

//n:頂点数, s:始点の番号, t:終点の番号, e:(u, v)->f uからvへの容量
int Edmonds_Karp(int N, int s, int t, int **e){
	int v, i, flow_sum = 0;
	int *flow = (int *)malloc(sizeof(int) * N);//各頂点に流せるフロー
	int *p = (int *)malloc(sizeof(int) * N);//増加道の履歴 前の頂点を入れる
	queue *q = make_queue(N * N);

	for(;;){
		//初期化
		for(i = 0; i < N; i++){
			flow[i] = 0;
			p[i] = -1;
		}
		flow[s] = inf;
		p[s] = -2;

		add_data_queue(s, q);
		while(element_num_queue(q) > 0){
			v = take_data_queue(q);
			if(v == t){
				break;
			}
			for(i = 0; i < N; i++){
				if(e[v][i] > 0 && p[i] == -1){
					p[i] = v;
					flow[i] = min(flow[v], e[v][i]);
					add_data_queue(i, q);
				}
			}
		}
		//増加道がなかった場合
		if(flow[t] == 0){
			break;
		}
		//残余ネットワークの構築
		for(v = t; v != s; v = p[v]){
			e[p[v]][v] -= flow[t];
			e[v][p[v]] += flow[t];
		}
		flow_sum += flow[t];
		flush_queue(q);
	}
	return flow_sum;
}

int main(){
	int N, M, s, t, i, j, k;
	scanf("%d%d%d%d", &N, &M, &s, &t);
	s--;
	t--;
	int **dis = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		dis[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			dis[i][j] = i == j ? 0 : inf;
		}
	}
	int *u = (int *)malloc(sizeof(int) * M);
	int *v = (int *)malloc(sizeof(int) * M);
	int *d = (int *)malloc(sizeof(int) * M);
	int *c = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		scanf("%d%d%d%d", &u[i], &v[i], &d[i], &c[i]);
		u[i]--;
		v[i]--;
		dis[u[i]][v[i]] = d[i];
	}
	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			for(j = 0; j < N; j++){
				if(dis[i][j] > dis[i][k] + dis[k][j]){
					dis[i][j] = dis[i][k] + dis[k][j];
				}
			}
		}
	}
	int **e = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		e[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			e[i][j] = 0;
		}
	}
	for(i = 0; i < M; i++){
		if(dis[s][u[i]] + d[i] + dis[v[i]][t] == dis[s][t]){
			e[u[i]][v[i]] = c[i];
		}
	}
/*	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			printf("%d  ", e[i][j]);
		}
		printf("\n");
	}
*/	int ans = Edmonds_Karp(N, s, t, e);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2140
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		int c=0;
	        int ans = 0;
 
		for( int a=0; a<=k; a++ ){
			for(int b=0; b<=k; b++){
				c = s-a-b;
				if( c >= 0 && c <= k){
					ans++;
				}
			}
		}

		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 9680
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d){
		cout<<"Left"<<endl;
	}else if(a+b==c+d){
		cout<<"Balanced"<<endl;
	}else if(a+b<c+d){
		cout<<"Right"<<endl;
	}
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,N) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.rbegin(),b.rend());
  rep(i,N){
    if(a[i]==b[0]){
      cout << b[1] << endl;
    }else{
      cout << b[0] << endl;
    }
  }
}

Measured memory_bytes: 3200
x,y= map(int,input().split())
ans=0
if x==1:
    ans+=300000
elif x==2:
    ans+=200000
elif x==3:
    ans+=100000

if y==1:
    ans+=300000
elif y==2:
    ans+=200000
elif y==3:
    ans+=100000

if x==1 and y==1:
    ans+=400000
print(ans)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<ll,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	const ll INF =1LL<<60;
	cin >>n;
	vector<VL> a(n, VL(n, INF));
	rep(i, n) rep( j, n) cin >>a[i][j];
	
	auto org = a;
	rep(k,n) rep(i,n) rep(j,n) a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
	if( org != a){
		puts("-1"); return 0;
	}
	ll ans =0;
	vector<VI> sk(n, VI(n, 0));
	rep(k, n) rep(i, n) rep(j, n) {
		if( a[i][j] == a[i][k] + a[k][j]) sk[i][j]++;
	}
	rep(i, n) rep2(j,i+1,n) if(sk[i][j] ==2) ans += a[i][j];
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>

int a,b,c[1000][1000],d[1000][2],e,i,j;

int main(){
	
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0){
			return 0;
		}
		for(i=0;i<a;i++){
			for(j=0;j<b;j++){
				scanf("%d",&c[i][j]);
			}
		}
		for(j=0;j<b;j++){
			d[j][0]=0;
			d[j][1]=j;
			for(i=0;i<a;i++){
			d[j][0]+=c[i][j];
			}
		}
		for(j=0;j<b;j++){
			for(i=0;i<b-1;i++){
				if(d[i][0]>d[i+1][0]){
					e=d[i][0];
					d[i][0]=d[i+1][0];
					d[i+1][0]=e;
					e=d[i][1];
					d[i][1]=d[i+1][1];
					d[i+1][1]=e;
				}
				if(d[i][0]==d[i+1][0]){
					if(d[i][1]<d[i+1][1]){
						e=d[i][1];
						d[i][1]=d[i+1][1];
						d[i+1][1]=e;
					}
				}
			}
		}
		for(i=b-1;i>0;i--){
			printf("%d ",d[i][1]+1);
		}
		
		printf("%d\n",d[0][1]+1);
	}
}

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

long long int euclidean_gcd(long long int a,long long int b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
    int n;
    long long int ans = 0;
    cin >> n;
    for(long long int i=1;i<=n;i++)for(long long int j=1;j<=n;j++)for(long long int k=1;k<=n;k++){
        //cout << i << j << k << endl;
       ans += euclidean_gcd(i,euclidean_gcd(j,k));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
// This program prints "Yes" if a<b<c, otherwise "No".
#include <iostream>
using namespace std;

int main(){

  // input three integers a,b,c
  int a,b,c;
  cin >> a >> b >> c;

  
  string ans =  (a < b and b < c) ? "Yes" : "No";
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std;

int H, W, d;
char HW[501][501];
#define OFFSET (502)

struct ToHW {
	int x;
	int y;
};
ToHW linkHW[1010][1010];


// HW
// 1 2 3 
// 4 5 6
// 7 8 9

// hw
//     1
//   4   2
// 7   5   3
//   8   6
//     9

int main(void)
{
	cin >> H >> W >> d;
	memset(HW, 0, sizeof(HW));

	for (int x = 0; x < 1010; x++) {
		for (int y = 0; y < 1010; y++) {
			linkHW[x][y].x = -1;
			linkHW[x][y].y = -1;
		}
	}

	int cnt = 0;
	for (int x = 0; x < W; x++) {
		for (int y = 0; y < H; y++) {
			int nx = OFFSET + x - y;
			int ny = x + y;
			linkHW[nx][ny].x = x;
			linkHW[nx][ny].y = y;
		}
	}

	int paint1 = 0;
	int paint2 = 0;
	for (int sx = 0; sx < 1010; sx+= d) {
		paint1 ^= 1;
		for (int sy = 0; sy < 1010; sy+= d) {
			paint2 ^= 1;
			for (int x = sx; x < sx+d; x++) {
				for (int y = sy; y < sy+d; y++) {
					if (x>=1010) continue;
					if (y>=1010) continue;
					int ox = linkHW[x][y].x;
					int oy = linkHW[x][y].y;
					if ((ox >= 0) && (oy >= 0)) {
						int paint = (paint1 << 1) + paint2;
						char color;
						switch(paint) {
							case 0: color = 'R'; break;
							case 1: color = 'B'; break;
							case 2: color = 'G'; break;
							case 3: color = 'Y'; break;
						}
						HW[ox][oy] = color;
					}
				}
			}
		}
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			cout << HW[x][y];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 8704
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define mod 1000000007

int main() {
	int n;
	int i, j;
	cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	ll ans=0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	b[0] = a[n - 1];
	for (i = 1 ; i < n - 1; i++) {
		b[i] = (b[i - 1] + a[n - i - 1])%mod;
	}
	for (i = 0; i < n - 1; i++) {
		ans += (a[i] * b[n - i - 2]) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6428
H, W = map(int, input().split())
a = [input() for _ in range(H)]

clm = [True] * H
for hi in range(H):
  ai = a[hi]
  for c in ai:
    if c == '#':
      clm[hi] = False
      break
      
row = [True] * W
for wi in range(W):
  for ci in range(H):
    if a[ci][wi] == '#':
      row[wi] = False
      break
      
for hi in range(H):
  if clm[hi] == True:
    continue
  ans = ''
  ai = a[hi]
  for wi in range(W):
    if row[wi] == True:
      continue
    ans += ai[wi]
  print(ans)


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

void solve(int ar[],int n)
{
    int s=0;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            if(ar[j]>ar[j+1]){
                swap(ar[j],ar[j+1]);
                s++;
            }
        }
    }
    
    for(int i=0;i<n;i++){
        cout<<ar[i]<<((i == n-1) ? "\n" : " ");
    }
    cout<<s<<"\n";
}

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

   int ar[n];

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

    solve(ar,n);

    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

int n,d;

template <typename T> bool is_square(T n){T rt = sqrt(n); return rt*rt == n;}


bool check(const vector<int> &a, const vector<int> &b){
  int k = 0;
  REP(i,d){
    k += (a[i]-b[i])*(a[i]-b[i]);
  }

  return is_square(k);
}


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

  while(cin >> n >> d){
    vector<vector<int>> x(n, vector<int>(d)); cin >> x;

    int ans = 0;
    REP(i,n){
      REP(j,n){
        if(i<j and check(x[i],x[j])) ++ans;
      }
    }
    cout << ans << endl;
    


    
  }

  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int n,a,b;
    cin >> n >> a >> b;
    vector<long long int> v;
    if((b - a) % 2 == 0)
    {
        v.push_back((b - a) / 2);
    }
    else if((a - 1) < (n - b))
    {
        v.push_back((b - a) / 2 + a);
    }
    else
    {
        v.push_back((b - a) / 2 + (n - b) + 1);
    }
    v.push_back(b - 1);
    v.push_back(n - a);
    sort(v.begin(),v.end());
    cout << v[0] << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>v[3020];
int dep[3020];
int n,ans,d,k;
int p[3000][2],miner;
void dfs(int fath,int x){
	dep[x]=dep[fath]+1;
	if(dep[x]>d)ans++;
	for(int i=0;i<v[x].size();i++){
		int dot=v[x][i];	
		if(dot!=fath)dfs(x,dot);
	}
}
void ad(int x,int y){
	v[x].push_back(y);	
	v[y].push_back(x);
}
int main(){
	//freopen("p.in","r",stdin);
	//freopen("p.out","w",stdout);
	miner=3000;
	cin>>n>>k;
	for(int i=1;i<n;i++){
	cin>>p[i][0]>>p[i][1];	
	ad(p[i][0],p[i][1]);
	}
	if(k%2==0){
	d=k/2;
	for(int i=1;i<=n;i++){
	ans=0;
	memset(dep,0,sizeof(dep));
	dep[0]=-1;
	dfs(0,i);
	miner=min(miner,ans);
	}}
	if(k%2){
	d=k/2;	
	for(int i=1;i<n;i++){
	ans=0;
	memset(dep,0,sizeof(dep));
	dep[p[i][0]]=-1;
	dfs(p[i][0],p[i][1]);
	memset(dep,0,sizeof(dep));
	dep[p[i][1]]=-1;
	dfs(p[i][1],p[i][0]);
	miner=min(miner,ans);
	}
	}
	cout<<miner;
	return 0;
}

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

int main(){
    int n; cin>>n;
    for(int i=1;i<=9;i++){
        if((n/i)<10 &&(n%i)==0){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n + 1], p = 0,ans=1e+9;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        p += a[i];
    }
    int p1 = p / n;
    for (int j = -1; j <= 1; j++)
    {
        p = p1 + j;
        int fans=0;
        for (int i = 1; i <= n; i++)
        {
            fans += (p - a[i]) * (p - a[i]);
        }
        ans=min(ans,fans);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000000000LL
#define MOD 1000000007

long long fun(long long n, long long b) {
	long long sum = 0;

	while (n) {
		sum += n % b;
		n /= b;
	}

	return sum;
}

int main() {
	long long n, s, b = 2, ans = INF;;

	cin >> n >> s;

	if (n == 1) {
		if (s == 1) {
			cout << 2;
		}
		else {
			cout << -1;
		}
		return 0;
	}

	if (fun(n, n + 1) ==  s) {
		cout << n + 1 << endl;
		return 0;
	}

	while (b * b <= n) {
		if (fun(n,b) == s) {
			ans = min(ans, b);
		}
		b++;
	}

	b = 1;

	while (b * b <= n - s) {
		if ((n - s) % b == 0) {
			if (fun(n, (n - s) / b + 1) == s) {
				ans = min(ans, (n - s) / b + 1);
			}
		}
		b++;
	}

	if (ans != INF) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256