akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long MOD = 1000000007;
    long num = 1;
    for(int i = 2; i <= N; i++) {
      if(isPrime(i)) {
        long power = 0;
        for(int k = 1; k < 10; k++) {
          if(N >= Math.pow(i, k)) {
            power += (N / (long)Math.pow(i, k));
          } else {
            break;
          }
        }
        num = (num * (power + 1)) % MOD;
      }
    }
    System.out.println(num);
  }

  public static boolean isPrime(int n) {
    boolean flg = true;
    for(int i = 2; i * i <= n; i++) {
      if(n % i == 0) {
        flg = false;
        break;
      } 
    }
    return flg;
  }
}

Measured memory_bytes: 9808
#include <stdio.h>
#define MAX 100
#define INFTY (1 << 21)
#define W 0
#define G 1
#define B 2

int i, j, v, n, M[MAX][MAX];

int main()
{

    int k, c, u, v;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            M[i][j] = INFTY;
        }
    }
    for (i = 0; i < n; i++)
    {
        scanf("%d%d", &u, &k);
        for (j = 0; j < k; j++)
        {
            scanf("%d%d", &v, &c);
            M[u][v] = c;
        }
    }

    int minv;
    int d[MAX], color[MAX];

    for (i = 0; i < n; i++)
    {
        d[i] = INFTY;
        color[i] = W;
    }

    d[0] = 0;
    color[0] = G;
    while (1)
    {
        minv = INFTY;
        int u = -1;
        for (i = 0; i < n; i++)
        {
            if (minv > d[i] && color[i] != B)
            {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1)
            break;
        color[u] = B;
        for (v = 0; v < n; v++)
        {
            if (color[v] != B && M[u][v] != INFTY)
            {
                if (d[v] > d[u] + M[u][v])
                {
                    d[v] = d[u] + M[u][v];
                    color[v] = G;
                }
            }
        }
    }

    for (i = 0; i < n; i++)
    {
        printf("%d ", i);
        if (d[i] == INFTY)
            printf("-1");
        else
            printf("%d", d[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2052
import sys

n = int(input())

xyh = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for xyhTemp in xyh:
            if xyhTemp[2] != 0:
                temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in xyh:
                if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)
        


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

int main(void){
    ll n,t; cin >> n >> t;
    vector<ll>a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<ll>left(n,0);
    left[0] = a[0];
    for(int i=1;i<n;i++){
        left[i] = min(left[i-1],a[i]);
    }
    vector<ll>value(n);
    for(int i=0;i<n;i++) value[i] = a[i] - left[i];
    ll cnt = count(value.begin(),value.end(),*max_element(value.begin(),value.end()));
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int n,u,v,m,x;
map<int,int> Ai,Aj,Bi,Bj,Af,Bf;
int sumA,sumB;
int Ay[1000],Ax[1000],Ac,Ad;
int By[1000],Bx[1000],Bc,Bd;

void init(){
  sumA=0;
  Ac=0;
  Ad=0;
  sumB=0;
  Bc=0;
  Bd=0;
  Ai.clear();
  Aj.clear();
  Af.clear();
  Bi.clear();
  Bj.clear();
  Bf.clear();
  for(int i=0;i<1000;i++){
    Ay[i]=0;
    Ax[i]=0;
    By[i]=0;
    Bx[i]=0;
  }
}

int M[100000];
void solve(){
  
  for(int i=0;i<m;i++)cin>>M[i];
  for(int i=0;i<m;i++){
    x=M[i];
    int ai=Ai[x];
    int aj=Aj[x];
    int bi=Bi[x];
    int bj=Bj[x];
    if(Af[x]){
      Ay[ai]++;
      Ax[aj]++;
      if(Ay[ai]==n)sumA++;
      if(Ax[aj]==n)sumA++;
      if(ai==aj){
	Ac++;
	if(Ac==n)sumA++;
      }
      if(ai+aj==n-1){
	Ad++;
	if(Ad==n)sumA++;
      }
    }
    if(Bf[x]){
      By[bi]++;
      Bx[bj]++;
      if(By[bi]==n)sumB++;
      if(Bx[bj]==n)sumB++;
      if(bi==bj){
	Bc++;
	if(Bc==n)sumB++;
      }
      if(bi+bj==n-1){
	Bd++;
	if(Bd==n)sumB++;
      }
    }
    //cout<<x<<' '<<sumA<< ' ' <<sumB<<endl;
    if(sumA>=u&&sumB>=v){
      cout<<"DRAW"<<endl;
      return;
    }else if(sumA>=u){
      cout<<"USAGI"<<endl;
      return;
    }else if(sumB>=v){
      cout<<"NEKO"<<endl;
      return;
    }
  }

  cout<<"DRAW"<<endl;
}

int main(){
  cin>>n>>u>>v>>m;

  init();
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>x;
      Ai[x]=i;
      Aj[x]=j;
      Af[x]=1;
    }
  }
  if(n==1){
    u+=3;
    v+=3;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>x;
      Bi[x]=i;
      Bj[x]=j;
      Bf[x]=1;
    }
  }

  solve();

  return 0;
}

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

int main(){
  int n;
  cin>>n;
  int cnt=0;
  rep(ai,n+1)rep(bi,n+1){
    if(ai*bi<n)cnt++;
    else break;
    /*cout<<"ai:"<<ai<<endl;
    cout<<"bi:"<<bi<<endl;*/
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int N = sc.nextInt();
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i=0; i<N; i++) {
    		b.add(sc.nextInt());
    	}
    	ArrayList<Integer> ans = new ArrayList<>();
    	for(int i=0; i<N; i++) {
    		for(int j=b.size()-1; j>=0; j--) {
    			if(b.get(j) == j+1) {
    				int tmp = b.remove(j);
    				ans.add(tmp);
    				break;
    			} else if(b.get(j) > j+1) {
    				System.out.println(-1);
    				return;
    			}
    		}
    	}
    	while(!ans.isEmpty()) {
    		System.out.println(ans.remove(ans.size()-1));
    	}
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	char c;
	cin>>c;
	if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o')
		cout<<"vowel"<<endl;
	else
		cout<<"consonant"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		String str = sc1.next();

		if (str.contains("a") && str.contains("b") && str.contains("c")) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

		sc1.close();
	}

}

Measured memory_bytes: 23124
n,k = map(int,input().split())

sunukes = list()
for i in range(1,n+1):
    sunukes.append(i)

sunukes = set(sunukes)

for i in range(1,k+1):
    input()
    sunukes = sunukes - set(map(int,input().split()))

print(len(sunukes))


Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

ll dp[51][2501][51]={};
ll x[51]={};

ll calc(int b,int c,int d){
	if(dp[b][c][d]>=0)return dp[b][c][d];
	dp[b][c][d]=calc(b-1,c,d);
	if(c>=x[b])dp[b][c][d]+=calc(b-1,c-x[b],d-1);
	return dp[b][c][d];
}

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

	for(int i=1;i<n+1;++i)cin>>x[i];
	for(int i=1;i<51;++i){
		for(int j=1;j<2501;++j){
			for(int k=1;k<51;++k){
				dp[i][j][k]=-1;
			}
		}
	}
	dp[0][0][0]=1;
	for(int i=1;i<n+1;++i){
		dp[i][0][0]=1;
	}
	ll t=0;
	for(int i=1;i<n+1;++i){
		t+=calc(n,a*i,i);
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 50048
from bisect import bisect_left


def p_d():
    n, k = map(int, input().split())
    *v, = map(int, input().split())
    ans = 0
    for _l in range(k + 1):
        for _r in range(k - _l + 1):
            if _l + _r > n:
                break
            d = k - (_l + _r)
            s = v[:_l] + v[n - _r:]
            s.sort()
            d = min(len(s), d)
            ans = max(ans, sum(s[bisect_left(s, 0, 0, d):]))

    print(ans)
    
p_d()

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
  long int a,sum,d,i;
  cin>>a;
  d=a;
  sum=0;
  for(i=0;i<8;i++){
    sum=sum+a%10;
    a=a/10;}
  if(d%sum==0)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

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


int main() {
    
    ll n,x;
    cin>>n>>x;
    ll a[n];
    for(int i = 0; i < n; i++)  cin>>a[i];
    ll ans = 0;
    for(int i = 0; i < n-1; i++)
    {
        if(a[i]+a[i+1] > x)
        {
            ll diff = a[i]+a[i+1]-x;
            ans+=diff;
            if(a[i+1] >= diff)
                a[i+1]-=diff;
            else
            {
                a[i+1] = 0;
                diff-=a[i+1];
                a[i]-=diff;
            }
        }
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    int64_t N = 0, ans = 0;
    for (int i = 0; i < S.size(); i++){
        if (S.at(S.size() - 1 - i) == 'B'){
            ans += i - N;
            N++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
const ll mod = 1000000007;

int main() {

  ll A,B; cin >> A >> B;

  ll c = A + B;

  while(c >= 24) {
    c -= 24;
  }

  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

// 1~N の整数で、0でない数字がちょうどk個あるものの個数
// dp[i][j][k]
// i　:　確定している桁数（最大100桁）0~100
// j　:　0でない数字が何個あるか（条件) 0~3
// k　:　N未満(0)か否(1)か(smaller) 0~1

int dp[101][4][2];

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

    int n = s.size(); // 桁数
    vector<int> data(n); rep(i,n) data[i] = s[i] - '0'; // 各桁の数字
    dp[0][0][0] = 1; // 初期化　（0桁目に0があると考える)

    rep(i,n){
        rep(j,4){
            dp[i+1][j][1] += dp[i][j][1]; // smaller 0 →smaller
            if(j+1 < 4) dp[i+1][j+1][1] += dp[i][j][1] * 9; // smaller 1~9 →smaller
            if(data[i] > 0){
                dp[i+1][j][1] += dp[i][j][0]; // bigger 0 →smaller
                if(j+1 < 4){
                    dp[i+1][j+1][1] += dp[i][j][0] * (data[i] -1); // bigger 1~data[i]-1 →smaller
                    dp[i+1][j+1][0] += dp[i][j][0]; // bigger data[i] →bigger
                }
            }
            else{
                dp[i+1][j][0] += dp[i][j][0]; // bigger 0 →bigger
            }
        }
    } // DP遷移

    int ans = dp[n][k][0] + dp[n][k][1];
    cout << ans << endl;
}

Measured memory_bytes: 3608
from collections import defaultdict
N = int( input())
A = list( map( int, input().split()))
D = defaultdict(lambda: 0)
ansL = 0
ansS = 0
for a in A:
    D[a] += 1
    if D[a] == 2:
        if a >= ansL:
            ansL, ansS = a, ansL
        else:
            ansS = max( ansS, a)
    if D[a] == 4:
        if a >= ansL:
            ansL, ansS = a, a
        else:
            ansS = max( ansS, a)
print(ansL*ansS)

Measured memory_bytes: 18600
def main():
    A = [int(i) for i in input().split()]
    A.sort()
    B = [A[2] - A[0], A[2] - A[1]]
    ans = 0
    if B[0] % 2 == B[1] % 2:
        ans = (B[0]+B[1])//2
    else:
        ans = 0--(B[0]+B[1])//2 + 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>

int main(){
	bool f=false,a=false;
	char c[101]={0};
	std::cin>>c;
	for(int i=0;i<100;i++){
		if(c[i]=='C')f=true;
		if(c[i]=='F'&&f==true)a=true;
	}
	if(a==true)printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int ord(long long int n) {
  int ord = 0;
  while (n % 2 == 0) { n /= 2; ord++; }
  return ord;
}

int main() {
  int N;
  cin >> N;
  int ans;
  for (int i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    ans += ord(a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 1000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[MAX][MAX];
void dijkstra();

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

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      A[i][j] = INFTY;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0; j<k; j++){
      scanf("%d",&v);
      scanf("%d",&A[u][v]);
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int i,u,v,mincost,d[MAX],pi[MAX],color[MAX];

  for(i=0; i<n; i++){
    d[i] = INFTY;
    pi[i] = NIL;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = INFTY;
    for(i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INFTY)
      break;
    color[u] = BLACK;
    for(v=0; v<n; v++){
      if(color[v] != BLACK && d[u] + A[u][v] < d[v]){
	pi[v] = u;
	d[v] = A[u][v] + d[u];
      }
    }
  }

  for(i=0; i<n; i++)
    printf("%d %d\n",i,d[i]);
}

Measured memory_bytes: 632
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
#define ll long long
#define REP(i,e,s) for(register ll i=e; i<=s; i++)
#define DREP(i,e,s) for(register ll i=e; i>=s; i--)
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define int ll

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=400+10,MOD=1e9+7;

int a[MAXN],b[MAXN],_pow[MAXN][MAXN],sum[MAXN][MAXN],f[MAXN][MAXN];

signed main() {
	int n=read(),c=read();
	REP(i,1,n) a[i]=read();
	REP(i,1,n) b[i]=read();
	
	REP(i,1,400) {
		_pow[i][0]=1;
		REP(j,1,400) _pow[i][j]=(_pow[i][j-1]*i)%MOD;
	}

	REP(i,1,400) REP(j,0,400) sum[i][j]=(sum[i][j]+sum[i-1][j]+_pow[i][j])%MOD;
	f[0][0]=1;	
	REP(i,1,n) REP(j,0,c) REP(k,0,j) f[i][j]=(f[i][j]+f[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+MOD)%MOD)%MOD;
	
	printf("%lld",f[n][c]);
	return 0;
}


Measured memory_bytes: 4096
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	if s == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}
}


Measured memory_bytes: 1756
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	vector<int> inputs;
	for (int i = 2; i <= 100000; ++i) {
		int ok = 1;
		for (int q = 2; q * q <= i; ++q) {
			if (i % q == 0) {
				ok = 0;
			}
		}
		if (ok == 1) inputs.push_back(i);
	}
	while (true) {
		int m, a, b;
		cin >> m >> a >> b;
		if (m == 0) return;
		pair<int, int> ans = mp(2, 2);
		REP(i, inputs.size() - 1) {
			for (int q = i; inputs[i] * inputs[q] <= m; ++q) {
				if (ans.first * ans.second >= inputs[i] * inputs[q]) continue;
				if (a * inputs[q] <= inputs[i] * b) {
					ans = mp(inputs[i], inputs[q]);
				}
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3316
#include<cstdio>
 
int main()
{
	int X;
	scanf("%d", &X);
	for (int A = 0; A < 1000; ++A) {
      	for (int B = -1000; B < A; ++B) {
			if (A * A * A * A * A - B * B * B * B * B == X)
			{
				printf("%d %d", A, B);
				return 0;
            }
		}
    }
}


Measured memory_bytes: 1716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
int s[100010], t[100010], w[100010];
ll dist[100010];
vector<pair<int, ll>> G[100010];

int cnt = 0;
int dfs1(int u, int par) {
	// printf("u %d v %d\n", u, par);
	// if(u == 511) cnt++;
	// if(cnt > 10) exit(1);
	ll ma = 0;
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) continue;
		// printf("v %d\n", v);
		// chmax(ma, dfs1(v, u) + cost);
		// ma = (ma < dfs1(v, u)) ? (dfs1(v, u)) : (ma)
		ma = max(ma, dfs1(v, u) + cost);
	}
	return dist[u] = ma;
}

ll dfs2(int u, int w, int par) {
	vector<pair<int, ll>> child; // (??????, ?????????????????????)
	child.pb(mp(0, -1));
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) child.pb(mp(w + cost, v));
		else child.pb(mp(dist[v] + cost, v));
	}
	sort(all(child)); reverse(all(child));
	ll ret = child[0].fi + child[1].fi;
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) continue;
		if(v == child[0].se) chmax(ret, dfs2(v, child[1].fi, u));
		else chmax(ret, dfs2(v, child[0].fi, u));
	}
	return ret;
}


int main(void) {
	cin >> n;
	rep(i, n - 1) cin >> s[i] >> t[i] >> w[i];
	rep(i, n - 1) G[s[i]].pb(mp(t[i], w[i]));
	rep(i, n - 1) G[t[i]].pb(mp(s[i], w[i]));
	// printf("k\n");
	dfs1(0, -1);
	auto ret = dfs2(0, 0, -1);
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 32476
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define vpii vector<pair<int,int>> 
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>> 
#define pii pair<int,int> 
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>

ld pie=3.141592653589793238462643383279;
int mod=1e9+7;

struct point{
  ld x,y;
};

vvi mat_mul(vvi mat1,vvi mat2){
  vvi ret;
  f(i,0,2){
    vi xx;
    f(j,0,2){
      int r=0;
      f(k,0,2) r=(r+(mat1[i][k]*mat2[k][j])%mod)%mod;
      xx.pb(r%mod);
    }
    ret.pb(xx);
  }
  return ret;
}

vvi mat_exp(vvi mat,int p){
  vvi iden={{1,0},{0,1}};
  while(p!=0){
    if(p&1) iden=mat_mul(iden,mat);
    p/=2; 
    mat=mat_mul(mat,mat);
  }
  return iden;
}


int myexp(int p){
  p++;
  int r=1;
  int val=2;
  while(p!=0){
    if(p&1){
      r*=val;
    }
    val*=val;
    p/=2;
  }
  r-=2;
  return r;
}


int fact[2000005];
int infact[2000005];
 
int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}
 
int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}
 
void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}
 
int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}
  
void mymul(int arr[],int num){
  int carry=0;
  f(i,0,100){
    arr[i]=arr[i]*num+carry;
    carry=arr[i]/10;
    arr[i]%=10;
  }
}

map<int,int> mp;

int myfun(int val){
  auto it = mp.lower_bound(val);
  if(it==mp.begin()) return 0;
  --it; 
  return it->second;
}

void myerase(int val,int key){
 
}

int32_t main(){ 
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  string s,t; cin>>s>>t;
  sort(all(s));
  sort(all(t));
  reverse(all(t));
  if(s<t) cout<<"Yes\n";
  else cout<<"No\n";
  return 0; 
}
// check for overflows dummy !!!

Measured memory_bytes: 3656
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      long cnt2 =0;
      int flg=0;
      long N = sc.nextLong();
      long X = sc.nextLong();
      
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
      }

      for(int i=0;i<N;i++) {
    	  if (cnt<=X) {
    		  cnt2++;
    	  } else {
    		  break;
    	  }
    	  cnt=cnt+a[i];
      }
      if(cnt<=X) {
    	  cnt2++;
      }
	  System.out.println(cnt2);
  }
  
 
}

Measured memory_bytes: 23764
require 'set'
Move = [ [2],
         [2, 5], [0, 1, 3, 6], [2, 7],
         [5], [1, 4, 6, 9], [2, 5, 7, 10], [3, 6, 8, 11], [7],
         [5, 10], [6, 9, 11, 12], [7, 10],
         [10] ]
R = [0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4]
C = [2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2]

while n = gets.to_i
  break if n == -1
  brd = [n, 4.times.map{ gets.split.map(&:to_i) } ].flatten
  q = [[brd, 0]]
  ans = -1
  set = Set.new([])
  set.add(brd)
  until q.empty?
    b, d = q.shift
    if (1..11).all?{ |v| b[v] == v }
      ans = d
      break
    end
    x = d
    13.times do |i|
      if b[i] > 0
        [R, C].each do |a|
          x += (a[i] - a[b[i]]).abs
        end
      end
    end
    unless x > 20
      13.times do |i|
        if b[i] == 0
          Move[i].each do |m|
            b[i], b[m] = b[m], b[i]
            unless set.include?(b)
              set.add(nb = b.dup)
              q << [nb, d + 1]
            end
            b[i], b[m] = b[m], b[i]
          end
        end
      end
    end
  end
  puts ans == -1 ? 'NA' : ans
end

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

int main(){
  
  int a;
  int b;
  
  cin >> a >> b;
  
  if ( a*b%2 == 0 )
     
    cout << "Even" << endl;
  
  if ( a*b%2 == 1 )
    
    cout << "Odd" << endl;
  
}

Measured memory_bytes: 3552
n = int(input())
monster= list(map(int,input().split()))

while True:
    index_list = [i for i, v in enumerate(monster) if v >0]
    mini = monster[index_list[0]]
    for i in range(1, len(index_list)):
        if mini > monster[index_list[i]]:
            mini =  monster[index_list[i]]

    miniindex_list = [i for i, v in enumerate(monster) if v ==mini]
    min_index = miniindex_list[0]

    for i in range(len(monster)):
        if not i == min_index:
            monster[i] = monster[i] % monster[min_index]
            
    non_zeroindex_list = [i for i, v in enumerate(monster) if v >0] 
    non_zeroindex = non_zeroindex_list[0]
    if len(non_zeroindex_list) == 1:
        break
print(monster[non_zeroindex])

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

using namespace std;

#define INF 210000000
#define int long long

signed main() {
	string s;
	cin >> s;
	int flag = 0;
	for (auto a:s){
		if (a=='7') flag = 1;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

int main(void) {
  int N;
  cin >> N;
  string w[110];

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

  bool ans = true;

  for (int i = 0; i < N-1; i++) {
    if(w[i][w[i].length() - 1] != w[i+1][0]) {
      ans = false;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (w[i] == w[j]) {
        ans = false;
      }
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX 100
#define INFTY INT_MAX
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

void dijkstra();

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

  scanf("%d",&n);
  if(n < 1 || n > 100)
    exit(1);
  //printf("test\n");

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = INFTY;
    }
  }
  //printf("test1\n");

  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d %d",&v,&c);
      if(c < 0 || c > 100000)
        exit(1);
      M[u][v] = c;
    }
  }

  dijkstra();
  return 0;
}

void dijkstra(){
  int minv;
  int d[MAX], color[MAX];
  int i, j, u;

  for(i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1)
      break;
    color[u] = BLACK;
    for(j = 0; j < n; j++){
      if(color[j] != BLACK && M[u][j] != INFTY){
        if(d[j] > d[u] + M[u][j]){
          d[j] = d[u] + M[u][j];
          color[j] = GRAY;
        }
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("%d ",i);
    if(d[i] == INFTY)
      printf("-1\n");
    else
      printf("%d\n",d[i]);
  }

}


Measured memory_bytes: 2108
#include<bits/stdtr1c++.h>
#include<list>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    std::vector<int> a{A+C,A+D,B+C,B+D};
    sort(a.begin(),a.end());
    cout << a.front() << endl;
}

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

using namespace std;

int main(){
    long long a=0,b=0,c=0;
    int f,g,h,n;
    cin>>n;
    while(n--){
        cin>>f>>g>>h;
        int q,w,e;
        q=max(b,c)+f;
        w=max(a,c)+g;
        e=max(a,b)+h;
        a=q;
        b=w;
        c=e;
        //cout<<f<<" "<<g<<" "<<h<<"\n";
    }
    cout<<max(a,max(b,c));
    return 0;
}

Measured memory_bytes: 256
s1, s2, s3 = map(str, input().split())
alpha = "abcdefghijklmnopqrstuvwxyz"
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
t1 = ALPHA[alpha.index(s1[0])]
t2 = ALPHA[alpha.index(s2[0])]
t3 = ALPHA[alpha.index(s3[0])]
print(t1 + t2 + t3)

Measured memory_bytes: 3060
#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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q; cin >> Q;
    while(Q--) {
        int A, B;
        cin >> A >> B;
        if (A > B) swap(A, B);
        int C = sqrt(A * B - 1) + 1.5;
        while(C * C >= A * B) C--;
        int ans = C * 2;
        if (C >= A) ans--;
        if (C * (C + 1) >= A * B) ans--;
        cout <<ans << endl;
    }
    return 0;
}
// 3 3
// ---
// 1 8
// 2 4
// 4 2
// 8 1


// 5 10
// 1 49
// 2 24
// 3 16
// 4 12
// 6 8
// 7 7 

// 3 4
// ---
// 1 11
// 2 5
// 4 2
// 11 1

//2 4
//---
//1 7
//3 2
//7 1

// 8 9
// ---
// 1 71
// 2 36
// 3
// 4
// 5
// 6
// 7 10
// 9 7

Measured memory_bytes: 256
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

#input = sys.stdin.readline

########################################

s = input()
if s[-1] == "s":
	print(s+"es")
else:
	print(s+"s")








'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''


Measured memory_bytes: 67336
import sys

n, k = map(int, input().split())
A = list(map(int, input().split()))

visit = [-1] * n   #到達しているかどうかを管理

D = [1]  # 循環するもののindexを格納

tmp = A[0]  #初期位置
ct = 1

while visit[tmp - 1] == -1:
    D.append(tmp)
    visit[tmp - 1] = ct  #到達済に変更
    if k == ct:
        print(tmp)
        sys.exit()
    ct += 1
    tmp = A[tmp - 1]

#循環している場合の残りの処理
k -= visit[tmp - 1]
k %= (ct - visit[tmp - 1])
print(D[visit[tmp - 1] + k])

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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n,k; 
	cin >> n >> k ;
	vector<ll> h(n);
	rep(i,n) cin >> h[i];

	ll dp[100100];
	rep(i,n){
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i,n){
		For(j,1,k+1){
			chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
		}
	}
	cout << dp[n-1] <<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
typedef queue<pii> qpii;
 
void test_case() {
	int n, m, k, a, b, c, d; cin >> n >> m >> k >> a >> b >> c >> d;
	vector<string> grid(n+1);
	vector<vector<int> > odl(n+1, vector<int>(m+1, 1e9));
	vector<vector<bool> > odw(n+1, vector<bool>(m+1));
//	int odl[n+1][m+1];
	for (int i = 1; i <= n; i ++) {
		cin >> grid[i];
	}
	if (grid[a][b-1] == '@') {
		cout << -1 << '\n';
		return;
	}
	if (a == c && b == d) {
		cout << 0 << '\n';
		return;
	}
	qpii Q;
	Q.push({a, b});
	odl[a][b] = 0;
	odw[a][b] = true;
	while (!Q.empty()) {
		pii cur = Q.front(); Q.pop();
		int X = cur.f, Y = cur.s, licz = k;
		while (X < n && licz) {
			X ++;
			licz --;
			if (grid[X][Y-1] == '@' || odl[X][Y] < odl[cur.f][cur.s] + 1) break;
			if (!odw[X][Y]) {
				odw[X][Y] = true;
				odl[X][Y] = odl[cur.f][cur.s] + 1;
				if (X == c && Y == d) {
					cout << odl[X][Y] << '\n';
					return;
				}
				Q.push({X, Y});
			}
		}
		X = cur.f, Y = cur.s, licz = k;
		while (X > 1 && licz) {
			X --;
			licz --;
			if (grid[X][Y-1] == '@' || odl[X][Y] < odl[cur.f][cur.s] + 1) break;
			if (!odw[X][Y]) {
				odw[X][Y] = true;
				odl[X][Y] = odl[cur.f][cur.s] + 1;
				if (X == c && Y == d) {
					cout << odl[X][Y] << '\n';
					return;
				}
				Q.push({X, Y});
			}
		}
		X = cur.f, Y = cur.s, licz = k;
		while (Y < m && licz) {
			Y ++;
			licz --;
			if (grid[X][Y-1] == '@' || odl[X][Y] < odl[cur.f][cur.s] + 1) break;
			if (!odw[X][Y]) {
				odw[X][Y] = true;
				odl[X][Y] = odl[cur.f][cur.s] + 1;
				if (X == c && Y == d) {
					cout << odl[X][Y] << '\n';
					return;
				}
				Q.push({X, Y});
			}
		}
		X = cur.f, Y = cur.s, licz = k;
		while (Y > 1 && licz) {
			Y --;
			licz --;
			if (grid[X][Y-1] == '@' || odl[X][Y] < odl[cur.f][cur.s] + 1) break;
			if (!odw[X][Y]) {
				odw[X][Y] = true;
				odl[X][Y] = odl[cur.f][cur.s] + 1;
				if (X == c && Y == d) {
					cout << odl[X][Y] << '\n';
					return;
				}
				Q.push({X, Y});
			}
		}
	}
	//for (int i = 1; i <= n; i ++) {
		//for (int j = 1; j <= m; j ++) {
			//cout << odl[i][j] << ' ';
		//}
		//cout << '\n';
	//}
	cout << -1 << '\n';
}
 
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 15076
#include<bits/stdc++.h>
#define REP(i,n) for(double i=1;i<=n;i++)
using namespace std;
int main(){
    double N,K;
    double ans=0;
    double coun;
    double kkkk=0;
    cin>>N>>K;
    REP(i,N){
        double k=i;
        coun=0;
        if(i<K){
            for(;;){
                if(k<K){
                    coun++;
                    k=k*2;
                } else {
                    break;
                }
            }
            int q=1;
            ans+=(q/N)*(q/pow(2,coun));
        } else {
            kkkk++;
        }
    }
    if(kkkk!=0)ans+=(kkkk/N);
    printf("%0.9lf\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true){
		int H = scan.nextInt();
		int W = scan.nextInt();
		if(H==0&&W==0) break;
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				System.out.print("#");
			}
			System.out.println();
		}
		System.out.println();
		
		}
	}

}

Measured memory_bytes: 26972
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n;cin>>n;
  bool ok=true;
  rep(i,0,n){
    int x;cin>>x;
    if(x%2==0){
      if(x%3 && x%5)ok=false;
    }
  }
  if(ok)cout<<"APPROVED"<<ENDL;
  else cout<<"DENIED"<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
use std::io::*;
use std::str::*;

// const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s: String = read().unwrap();
    let mut n = 0;

    for i in s.chars() {
        if i == 'o' {
            n += 1;
        }
    }
    print!("{}\n", 700 + n * 100);

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      vector<pair<int, int>> p(N);
      for (int i = 0; i < N; i++) {
        int a;
        cin >> a ;
        p.at(i) = make_pair(a, i);  // b, a の順でペアにする
      }
     
      sort(p.begin(), p.end());
     
      for (int i = 0; i < N; i++) {
        int x, y;
        tie(x, y) = p.at(i);  // b, a の順であることに注意
        cout << y+1 << " " << endl;
      }
    }



Measured memory_bytes: 1664
#include<stdio.h>
int main(void){
  int n,k,d[101],a[101][101],i,j,b[101],c;
  scanf("%d %d",&n,&k);
  c=0;
  for(i=0;i<k;i++){
    scanf("%d",&d[i]);
    for(j=0;j<d[i];j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=1;i<=n;i++){
    b[i]=0;
  }
  for(i=0;i<k;i++){
    for(j=0;j<d[i];j++){
      b[a[i][j]]=1;
    }
  }
  for(i=1;i<=n;i++){
    if(b[i]==0){
      c+=1;
    }
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,k,c;
const int Maxn=2e5+5;
char s[Maxn];
int pre[Maxn],suf[Maxn];
int main(){
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	int pos=1,cnt=1;
	while(pos<=n&&cnt<=k){
		if(s[pos]=='o'){
			pre[cnt++]=pos;pos+=c+1;
		}else pos++;
	}
	reverse(s+1,s+n+1);
	pos=1;cnt=1;
	while(pos<=n&&cnt<=k){
		if(s[pos]=='o'){
			suf[cnt++]=n-pos+1;pos+=c+1;
		}else pos++;
	}
	reverse(suf+1,suf+cnt);
//	for(int i=1;i<=k;i++)cout<<pre[i]<<' ';cout<<endl;
//	for(int i=1;i<cnt;i++)cout<<suf[i]<<' ';cout<<endl;
	for(int i=1;i<=k;i++){
		if(pre[i]&&pre[i]==suf[i]){
			cout<<pre[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    cin >> s;
    if(s[s.length()-1] == '1' || s[0] == '0'){
        cout << -1 << "\n";
        return 0;
    }
    vector<int> v;
    for (int i = 0; i < s.length()-1; ++i) {
        if(s[i] != s[s.length()-i-2]) {
            cout << -1 << "\n";
            return 0;
        }else if(s[i] == '1'){
            v.emplace_back(i+1);
        }
    }
    int k = 1;
    for (int j = 0; j < v.size(); ++j) {
        cout << k << " " << k+1 << "\n";
        k++;
    }
    k++;
    for (int i = 1; i < v.size(); ++i) {
        for (int j = 0; j < v[i]-v[i-1]-1; ++j) {
            cout << i+1 << " " << k << "\n";
            k++;
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
 
 
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
ll mod = 1e9 + 7;
ld eps = 1e-6;
 
 
ll dp[107][100007], accumDP[107][100007];
 
int main() {
	fastIO;
	ll n, k;
	cin >> n >> k;
	ll arr[107];
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
 
	for (int i = 0; i <= n; i++) {
		accumDP[i][0] = 1;
	}
	for (int i = 0; i <= k; i++) {
		accumDP[0][i] = 1;
	}
 
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j <= k; j++) {
			if (j == 0) {
				dp[i][j] = 1;
				continue;
			}
			if (i == 0) {
				dp[i][j] = 0;
				continue;
			}
			ll sum = accumDP[i-1][j] % mod;
			if (j - arr[i] - 1 >= 0) {
				sum -= accumDP[i-1][j-arr[i]-1];
                sum += mod;
                sum %= mod;
			}
			dp[i][j] = sum % mod;
			accumDP[i][j] = ((dp[i][j] % mod) + (accumDP[i][j-1] % mod)) % mod;
		}
	}
	cout << dp[n][k] % mod;
 
}
 

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

int main(){

int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
int count=0;
sort(a,a+n);
int x=a[n/2-1],y=a[n/2];
count+=y-x;
cout<<count;


	
return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int m, k;
int main() {
	cin >> m >> k;
	
	if(m == 1) {
		if(k == 0) { cout << "0 0 1 1" << endl; }
		else { cout << -1 << endl; }
		return 0;
	}
	
	if(! inID(k, 0, 1 << m)) { cout << -1 << endl; return 0; }
	
	vector<int> ans;
	ans.PB(k);
	inc(i, 1 << m) { if(i != k) { ans.PB(i); } }
	ans.PB(k);
	dec(i, 1 << m) { if(i != k) { ans.PB(i); } }
	
	inc(i, SI(ans)) { cout << (i == 0 ? "" : " ") << ans[i]; }
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 2932
use std::collections::BTreeMap;
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let a: Vec<u32> = parse_line().unwrap();
    let mut map: BTreeMap<u32, usize> = BTreeMap::new();

    for &ai in &a {
        map.entry(ai).and_modify(|x| *x += 1).or_insert(1);
    }

    let ans = map
        .values()
        .filter(|&&x| x >= 2)
        .fold(0, |x, &y| x + y * (y - 1) / 2);

    for &ai in &a {
        let diff;
        match map.get(&ai).unwrap() {
            0 | 1 => diff = 0,
            &e @ _ => diff = (e * (e - 1) / 2) - ((e - 1) * (e - 2) / 2),
        }
        println!("{}", ans - diff);
    }
}


Measured memory_bytes: 5728
import math


def getMinprime(N):
	# 最小の素数を返す
	if n % 2 == 0:
		return 2
	nsqrt = int(math.sqrt(n))
	for i in range(2, nsqrt + 1):
		if n % i == 0:
			return i

	return N


# 入力値の取得（整数）
n = int(input())
primes = []

# 素因数分解
m = n  # 入力値の退避
while n > 1:
	minprime = getMinprime(n)
	primes.append(minprime)
	n = int(n / minprime)

# print(primes)

# 結果出力
print('{0}:'.format(m), end='')
for i in primes:
	print(' {0}'.format(i), end='')
print()



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

int main() {
  double a[2][2];
  double a_inv[2][2];
  double det;
  double b[2];
  double x[2];
  int tmp;
  while (1) {
    cin >> a[0][0] >> a[0][1] >> b[0];
    cin >> a[1][0] >> a[1][1] >> b[1];
    if (cin.eof()) break;

    det = a[0][0]*a[1][1] - a[0][1]*a[1][0];
    a_inv[0][0] = a[1][1]/det;
    a_inv[0][1] = -a[0][1]/det;
    a_inv[1][0] = -a[1][0]/det;
    a_inv[1][1] = a[0][0]/det;
    for (int i=0; i<2; i++) {
      x[i] = 0.0;
      for (int j=0; j<2; j++) {
        x[i] += a_inv[i][j]*b[j];
      }
      tmp = round(x[i]*1000);
      if (!tmp) x[i] = 0.0;
    }
    cout.setf(ios::fixed);
    cout.precision(3);
    cout << x[0] << " " << x[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long


signed main(void){
  string s;
  cin >> s;
  s.replace(5,1," ");
  s.replace(13,1," ");
  cout << s << "\r\n";
}


Measured memory_bytes: 256
R,G,B,N=gets.split.map(&:to_i)
 
X,Y,Z=[R,G,B].sort
 
count=0
 
 
xs=0
while xs<=N
  ys=0
  while ys+xs<=N
    count+=1 if (N-(ys+xs))%Z==0
    ys+=Y
  end
  xs+=X
end
 
 
puts count

Measured memory_bytes: 1788
def distance(x, y, p):
	dist = 0
	for cx, cy in zip(x, y):
		dist += abs(cx - cy) ** p
	return dist ** (1 / p)

N = int(input())
X = list(map(float, input().split()))
Y = list(map(float, input().split()))

print(distance(X, Y, 1))
print(distance(X, Y, 2))
print(distance(X, Y, 3))

max_dist = 0
for cx, cy in zip(X, Y):
	max_dist = max(max_dist, abs(cx - cy))
print(max_dist)



Measured memory_bytes: 5660