akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 2 * 1e5;

int main()
{
	lld n,a[MAXN] = {};

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

	lld sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += a[i];
	}

	lld sub = 0,sol = 1000000000000000000LL;

	for(int i = 0; i < n-1; i++)
	{
		sub += a[i];

		sol = min(sol,abs(sum - 2 * sub));
	}

	cout << sol << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>s;
    for0(s.size())if(s[i]=='R')c++;
    if(c==2&&s[1]=='S')cout<<1<<endl;
    else cout<<c<<endl;

}



Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] arrA = new long[n];
        long[] arrB = new long[n];
        for(int j = 0; j < n; j++){
            arrA[j] = sc.nextLong();
            arrB[j] = sc.nextLong();
        }
        Arrays.sort(arrA);
        Arrays.sort(arrB);
        if(n % 2 == 0){
            System.out.println(Math.max(0,arrB[n/2]+arrB[n/2-1]-arrA[n/2]-arrA[n/2-1]+1));
        }else{
            System.out.println(Math.max(0,arrB[n/2]-arrA[n/2]+1));
        }
        
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;

  for(int i = 0; i < n-2; i++) {
    if(s.at(i) == 'A') {
      i++;
      if(s.at(i) == 'B') {
        i++;
        if(s.at(i) == 'C') {
          ans++;
        } else {
          i--;
        }
      } else {
        i--;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;


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

		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] w = new int[n];
		int sum = 0;
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextInt();
			sum += w[i];
			max = Math.max(max, w[i]);
		}

		int first = max;
		int last = sum;
		int i = (first + last) / 2;
		while (last > first) {
			if (check(i, w) <= k) {
				last = i;
			} else {
				first = i + 1;
			}
			i = (first + last) / 2;
		}

		System.out.println(i);
		
		sc.close();
	}

	private static int check(int i, int[] w) {
		int count = 1;
		int sum = 0;
		for (int j = 0; j < w.length; j++) {
			if (w[j] > i) {
				return Integer.MAX_VALUE;
			} else {
				sum += w[j];
				if (sum > i) {
					sum = w[j];
					count++;
				}
			}
		}

		return count;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;

		private Scanner() {
		}

		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}

		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return st.sval;
		}

		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return (int)st.nval;
		}

		void close() {
		}
	}
}

Measured memory_bytes: 24664
//16
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>

using namespace std;

int cs(string s){
  return count(s.begin(),s.end(),' ');
}

string *fnd(string *a,string *b,string c){
  for(;a!=b;a++){
    if(a->substr(cs(*a))==c)break;
  }
  return a;
}

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    cin.ignore();
    string s[1000];
    for(int i=0;i<n;i++){
      getline(cin,s[i]);
    }
    for(int i=0;i<m;i++){
      char a[99],b[99],c[99];
      scanf("%s is %*s %s of %[^.].",a,b,c);
      int ax=fnd(s,s+n,string(a))-s;
      int cx=fnd(s,s+n,string(c))-s;
      bool r;
      if(b[0]!='s'){
	if(b[0]=='p'||b[0]=='a'){
	  swap(ax,cx);
	}
	int i;
	int ps=cs(s[cx]);
	for(i=cx+1;i<ax&&i<n;i++){
	  if(cs(s[i])<=ps)break;
	}
	r=cx<ax&&i==ax&&(((b[0]=='p'||b[0]=='c')&&cs(s[ax])==cs(s[cx])+1)||((b[0]=='a'||b[0]=='d')&&cs(s[ax])>cs(s[cx])));
      }else{
	int l=min(ax,cx),h=max(ax,cx);
	int i;
	for(i=l;i<h;i++){
	  if(cs(s[l])>cs(s[i]))break;
	}
	r=i==h&&cs(s[l])==cs(s[h]);
      }
      cout<<(r?"True":"False")<<endl;
    }
    cout<<endl;
  }
  return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    string S;
    std::cin >> S;

    int ans = 0;
    REP(i, S.size()) {
        auto s = S[i];
        while(i < S.size() && S[i] == s) {
            i++;
        }
        ans++;
        i--;
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	string str;
	int c1=0,c2=0,c3=0,c4=0;
	
	while(t--)
	{
	cin>>str;
	if(str=="AC")
	{
		c1++;
	}
	 if(str=="WA")
	{
		c2++;
	}
		 if(str=="TLE")
		{
			c3++;
		}
		 if(str=="RE")
			{
				c4++;
			}
		
			
			
	}
		cout<<"AC x "<<c1<<endl;
				cout<<"WA x "<<c2<<endl;
					cout<<"TLE x "<<c3<<endl;
					cout<<"RE x "<<c4<<endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void)
{
	int n,min,max,i,x;
	long int sum;
	sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		if(i<n-1)
		{
		scanf("%d ",&x);
		}
		if(i==n-1)
		{
			scanf("%d",&x);
		}
		if(i==0)
		{
			min=x;
			max=x;
		}
		if(max<=x)
		{
			max=x;
		}
		if(min>=x)
		{
			min=x;
		}
		sum=sum+x;
		x=0;
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

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

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

    double res;

    if (n % 2 == 0){
        res = 1 / 2.0;
        printf("%8f", res);
        return 0;
    }

    res = ((double)(n/2)+1) / ((double)n);
    printf("%8f", res);
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

const long long INF=1LL<<50LL;
const double PI=3.14159265358979323846264;
const long long mod=1000000000LL+7LL;

long long gcd(long long x,long long y){
	return y==0 ? x : gcd(y,x%y);
}

int main(){

	string s;
	cin>>s;

	int x=-1,y=-1;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){x=i;break;}
	}

	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='F'){y=i;break;}
	}

	if(x<y && x!=-1 && y!=-1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
const ll maxn=1e5+10;
ll n,x;
ll k;
ll a[maxn],b[maxn];
ll rhs;
ll ans,num;
int main()
{

    scanf("%lld%lld",&n,&x);
    for(ll i=0;i<n;i++){
        scanf("%lld",&k);
        a[i]=abs(k-x);
    }
    if(n==1){
        printf("%lld\n",abs(x-k));
    }

    else{
    sort(a,a+n);
    for(ll i=1;i<=a[0];i++){
            rhs=0;
        ++ans;
       // printf("ans->%d\n",ans);
        if(a[0]%ans)continue;
        //++ans;
        for(ll j=0;j<n;j++){
            if(a[j]%ans){
                rhs=1;
                break;
            }

            //printf("num->%d\n",num);
        }
        if(rhs!=1)num=ans;
       // printf("num->%d\n",num);

    }
    printf("%lld\n",num);
    }
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 896
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
ll fun(ll x,ll y,ll z){
  return x*x+ y*y+z*z +x*y+y*z+z*x;
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  vector<ll> f(n+1,0);
  for(ll x=1;x*x<=n;x++){
    for(ll y=1;x*x+y*y<=n;y++){
      for(ll z=1;x*x+y*y+z*z<=n;z++){
        ll v = fun(x,y,z);
        if(v<=n){
          f[v]++;
        }
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout << f[i]<<endl;
  }
}


Measured memory_bytes: 3720
from collections import Counter

S = list(input())
C = Counter(S)

o = []

for a in C.keys():
    j = 0
    m = 0
    for b in S:
        if a == b:
            j = 0
        else:
            j += 1
            m = max(m,j)
    o.append(m)

print(min(o))

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

int main()
{
  string S; cin >> S;  
  int cnt = 0;
  for (auto& i : S)
  {
    if (i == 'x')cnt++;
  }

  if (cnt < 8)cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  int s; cin >> s;
  set<int> st;
  int x = s;
  while (st.count(x) == 0) {
    st.insert(x);
    if (x%2 == 0) x /= 2;
    else x = x*3+1;
  }
  cout << st.size()+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int p[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  int max = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] > max) {
      max = p[i];
    }
    sum += p[i];
  }
  sum -= max/2;
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    long long N, M; cin >> N >> M;
    vector<long long> X(M);
    for (int i = 0; i < M; ++i) cin >> X[i];
    sort(X.begin(), X.end());
        
    vector<long long> diffs;
    for (long long i = 1; i < X.size(); ++i) diffs.push_back(X[i] - X[i-1]);
    sort(diffs.begin(), diffs.end(), greater<long long>());
        
    long long res = X.back() - X[0];
    for (long long i = 0; i < min((long long)diffs.size(), N-1); ++i) res -= diffs[i];
    cout << res << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

const int mod = 1'000'000'007;

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

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

  int ans = 0;
  int x = 0;

  // for (int i = 0; i < n; i++) {
  //   ans += a[i] * x;
  //   x += a[i];
  // }

  for (int i = 0; i < n; i++) {
    ans = (ans + (ll)a[i] * x) % mod;
    x = (x + a[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,x;
	n=1;
	while(1)	{
		scanf("%d",&x);
		if(x==0)	break;
		printf("Case %d: %d\n",n,x);
		n++;
	}
	return 0;
}


Measured memory_bytes: 2768
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;



void calc() {

	Int N; std::cin >> N;
	std::string str = std::to_string(N);
	bool flag = false;
	rep(i, str.size()) {
		if (str[i] == '7')flag = true;
	}
	std::cout << (flag ? "Yes" : "No");

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 3692
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

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

	n := scanInt()
	s := scanText()

	for _, e := range s {
		fmt.Fprint(wr, string((e+int32(n)-'A')%26+'A'))
	}
	fmt.Fprintln(wr)
	wr.Flush()
}


Measured memory_bytes: 896
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define MAXV 100000
#define INF 1e9

int V, E, r;
struct edge{int to, cost;};
typedef pair<int, int> P; // firstは最短距離、secondは頂点番号

vector<edge> G[MAXV];
int d[MAXV];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void) {
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edge e; e.to = t; e.cost = d;
        G[s].push_back(e);
    }
    dijkstra(r);
    for (int i = 0; i < V; i++) {
        if (d[i] < INF) cout << d[i] << endl;
        else cout << "INF" << endl;
    }
    return 0;
}

Measured memory_bytes: 11304
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	int m = scn.nextInt();
	int mod=1000000007;
	char[][]board = new char[n][m];
	for(int i=0;i<n;i++)
	{
		String s=scn.next();
		board[i]=s.toCharArray();
		
	}
	int[][]dp = new int[n+1][m+1];
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			if(i==n-1&&j==m-1)
			{
				dp[i][j]=1;
			}else {
				if(board[i][j]=='.')
					dp[i][j]=((dp[i+1][j])%mod+(dp[i][j+1])%mod)%mod;
			}
		}
	}
	System.out.println(dp[0][0]);
  }
	
}

Measured memory_bytes: 49484
using System;
using System.Text;

namespace ABC051BackAndForth
{
    class Program
    {
        static void Main(string[] args)
        {
            int sx, sy, tx, ty;
            string[] vals = Console.ReadLine().Split(' ');
            sx = int.Parse(vals[0]);
            sy = int.Parse(vals[1]);
            tx = int.Parse(vals[2]);
            ty = int.Parse(vals[3]);

            StringBuilder sb = new StringBuilder();
            int width = tx - sx;
            int height = ty - sy;

            for(int i=0; i< width; i++)
            {
                sb.Append("R");
            }
            for(int i=0; i < height; i++)
            {
                sb.Append("U");
            }
            for(int i=0; i< width; i++)
            {
                sb.Append("L");
            }
            for(int i=0; i< height + 1; i++)
            {
                sb.Append("D");
            }
            for (int i = 0; i < width+1; i++)
            {
                sb.Append("R");
            }
            for (int i = 0; i < height + 1; i++)
            {
                sb.Append("U");
            }
            sb.Append("LU");
            for (int i = 0; i < width + 1; i++)
            {
                sb.Append("L");
            }
            for (int i = 0; i < height + 1; i++)
            {
                sb.Append("D");
            }
            sb.Append("R");

            Console.WriteLine(sb);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<math.h>
#include<stdbool.h>
#include <string.h>


int main()
{
  int N, M;
  scanf("%d %d", &N, &M);
  int A[10010];
  int total_a=0;

  for(int i=0; i<M; i++){
    scanf("%d", &A[i]);
    total_a+=A[i];
  }

  if(total_a>N){
    printf("-1");
  }
  else{
    printf("%d", N-total_a );
  }



  return 0;
}


Measured memory_bytes: 1752
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];
    sort(All(L));
    int res = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            for(int k = j + 1; k < N; k++) {
                if(L[k] < L[i] + L[j] && L[i] < L[k] + L[j] &&
                   L[j] < L[i] + L[k] && L[k] != L[i] && L[k] != L[j] &&
                   L[j] != L[i]) {
                    res++;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3556
from math import ceil
from math import floor
a,b = map(int,input().split())
l1 = ceil((a)/0.08)
r1 = floor((a+0.999999999999)/0.08)
l2 = ceil((b)/0.1)
r2 = floor((b+0.99999999999)/0.1)
l3 = max(l1,l2)
r3 = min(r2,r1)
if(l3<=r3):
    print(l3)
else:
    print(-1)




Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> P;
typedef long long ll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int main(){
    int n;cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;++i) cin>>s[i];
    int ans=0;
    for(int a=0;a<n;++a){
        bool ok=true;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(s[(i+a)%n][j]!=s[(j+a)%n][i]) ok=false;
            }
        }
        if(ok) ans+=(n-a);
    }
    for(int b=1;b<n;++b){
        bool ok=true;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(s[i][(j+b)%n]!=s[j][(i+b)%n]) ok=false;
            }
        }
        if(ok) ans+=(n-b);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3792
package main

import "fmt"

func isHarshad(n int) (res bool) {
	f := 0
	cp := n
	for n > 0 {
		f += n % 10
		n /= 10
	}
	if cp%f == 0 {
		res = true
	} else {
		res = false
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	if isHarshad(n) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        
        for (int i = 0; i < n; i++) h[i] = Integer.parseInt(sc.next());
        
        Boolean[] f = new Boolean[n];
        
        Arrays.fill(f, true);
        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next()) - 1;
            int b = Integer.parseInt(sc.next()) - 1;
            if (h[a] <= h[b]) {
                f[a] = false;
            }
            if (h[b] <= h[a]) {
                f[b] = false;
            }
        }
        
        int c = 0;
        for (boolean i : f){
            if (i) c++;
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 62004
#include<bits/stdc++.h>
using namespace std;
int main(){
    char c;
    cin>>c;
    if(c == 'A') cout<<'T'<<endl;
    else if(c == 'T') cout<<'A'<<endl;
    else if(c == 'C') cout<<'G'<<endl;
    else cout<<'C'<<endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x,i,p;
    cin>>k>>x;
    for(i=(x-k+1) ;i<=(x+k-1) ;i++)
    {
        printf("%d ",i);
    }
    printf("\n");
    return 0;
}


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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int X[M];
  REP(i, M) cin >> X[i];
  sort(X, X + M);
  int diffs[M - 1];
  REP(i, M - 1) diffs[i] = X[i + 1] - X[i];
  sort(diffs, diffs + M - 1, greater<int>());

  ll result = 0;
  for (int i = N - 1; i < M - 1; i++) {
    result += diffs[i];
  }
  cout << result << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N=200003;
int n,m,cnt,f[N],kq[N];
pair< pair<int,int>,int> p[N*17];
void ud(int i)
{
    for (;i<=m*2;i+=(i&-i)) f[i]++;
}
int tv(int i)
{
    int res=0;
    for (;i>0;i-=(i&-i)) res+=f[i];
    return res;
}
int main()
{
   
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
        cnt++;
        cin>>p[cnt].S>>p[cnt].F.F;
        p[cnt].F.S=-1;
    }
    for (int i=2;i<=m;i++)
    for (int j=i;j<=m*2;j+=i)
    {
        cnt++;
        p[cnt].F.F=j-1;
        p[cnt].F.S=i;
        p[cnt].S=j-i+1;
    }
    sort(p+1,p+cnt+1);
    for (int i=1;i<=cnt;i++)
    {
        int cs=p[i].F.S;
        //cout<<p[i].F.F<<" "<<p[i].S<<" "<<p[i].F.S<<"\n";
        if (cs<0) ud(p[i].S);
        else
        {
            kq[cs]+=tv(p[i].F.F)-tv(p[i].S-1);
            //cout<<cs<<" "<<p[i].F.F<<" "<<p[i].S-1<<"\n";
        }
    }
    for (int i=1;i<=m;i++) cout<<n-kq[i]<<"\n";
    return 0;
}


Measured memory_bytes: 33792
c=[map(int, raw_input().split()) for i in range(3)]
def C(i,j):return c[i-1][j-1]
if C(1,1)-C(1,2) == C(3,1)-C(3,2) == C(2,1)-C(2,2) and C(1,2)-C(1,3)==C(2,2)-C(2,3)==C(3,2)-C(3,3):
    print("Yes")
else:
    print("No")




Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
// Runs range sum queries only.
// Sum : O(1)
template <class Abel>
class CumulativeSum
{
	std::vector<Abel> sums_;

public:
	CumulativeSum(const std::vector<Abel> &data) : sums_(data)
	{
		sums_.insert(sums_.begin(), Abel(0));
		for (int i = 1; i < (int)sums_.size(); ++i)
		{
			sums_[i] += sums_[i - 1];
		}
	}

	// Gets the sum of data[0, right)
	Abel Sum(int right) { return sums_[right]; }

	// Gets the sum of data[left, right)
	Abel Sum(int left, int right) { return Sum(right) - Sum(left); }
};
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> white(n), black(n);
	for (int i = 0; i < n; ++i)
	{
		if (s[n - i - 1] == '.')
		{
			white[i] = 1;
		}
		if (s[i] == '#')
		{
			black[i] = 1;
		}
	}
	CumulativeSum<int> white_sum(white), black_sum(black);
	int ans = 1e9;
	for (int i = 0; i <= n; ++i)
	{
		ans = min(ans, black_sum.Sum(i) + white_sum.Sum(n - i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4340
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    long long h,s=0;
    int n;
    cin >> h >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        s+=a.at(i);
    }
    sort(a.begin(),a.end());
    if(s>=h) cout << "Yes" << endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int x;
int memo[109000];
int dp(int sum);

int main(){
  cin>>x;
  memset(memo,-1,sizeof(memo));
  if(dp(0)){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return(0);
}

int dp(int sum){
  int rec=0;
  if(memo[sum]!=-1)return memo[sum];
  if(sum>=x){
    if(sum==x)return 1;
    else return 0;
  }
  for(int i=0;i<6;i++){
    rec+=dp(sum+100+i);
  }
  return memo[sum]=rec;
}


Measured memory_bytes: 768
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    S = list(input().split())
    yellow = False
    for c in S:
        if c == 'Y':
            yellow = True
            break
    if yellow: print("Four")
    else: print('Three')

if __name__ == "__main__":
    main()


Measured memory_bytes: 62020
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110

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

bool solve(){
  int w,h,c[4];
  int mm[SIZE][SIZE];
  int dp[SIZE][SIZE][4];

  scanf("%d%d",&w,&h);
  
  if(w == 0) return false;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d",mm[i]+j);

      for(int k=0;k<4;k++)
        dp[i][j][k] = -INF;
    }
  }

  for(int i=0;i<4;i++)
    scanf("%d",c+i);
  
  priority_queue<pair<pair<int,int>,pair<int,int> > > pq;

  pq.push({{0,0},{0,0}});

  while(pq.size()){
    int y = pq.top().second.first;
    int x = pq.top().second.second;
    int d = pq.top().first.second;
    int sum_c = pq.top().first.first;
    pq.pop();
    
    if(y == h-1 && x == w-1){
      printf("%d\n",-sum_c);
      return true;
    }

    if(dp[y][x][d] != -INF) continue;

    dp[y][x][d] = -sum_c;

    //floor
    if(mm[y][x] != 4){
      int next_d = (d+mm[y][x])%4;
      
      if(0 <= y+dy[next_d] && y+dy[next_d] < h &&
         0 <= x+dx[next_d] && x+dx[next_d] < w){
        pq.push({{sum_c,next_d},{y+dy[next_d], x+dx[next_d]}});
      }
    }

    
    for(int i=0;i<4;i++){
      int next_d = (d+i)%4;
      if(0 <= y+dy[next_d] && y+dy[next_d] < h &&
         0 <= x+dx[next_d] && x+dx[next_d] < w){
        pq.push({{sum_c-c[i],next_d},{y+dy[next_d], x+dx[next_d]}});
      }
    }
    
  }

  assert(false);
  return true;
}

int main(){

  while(solve());
  
  return 0;
}

Measured memory_bytes: 3484
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
[<EntryPoint>]
let main argv =
    let S=R string
    let T=R string
    [0..(S.Length)-1]|>Seq.sumBy(fun c -> if S.[c]<>T.[c] then 1 else 0)
    |>printfn "%d"
    0

Measured memory_bytes: 37632
#include <bits/stdc++.h>
//#define fastIO cin.tie(0);ios_base::sync_with_stdio(false)
#define N 10010
#define ll long long
#define INF 1000000000000000000
//min-cost flow problem
using namespace std;

struct edge {
  ll from, to, cap, flow, cost;
};

ll n, d[2 * N + 5], pre[2 * N + 5], Maxflow = 0, COST = 0;
bool inqueue[2 * N + 5];
vector<edge> Edge;     // store edges
vector<ll> G[2 * N + 10];

inline void addEdge( ll from, ll to, ll cap, ll cost )
{
    G[from].push_back( Edge.size() );
    Edge.push_back( edge{from, to, cap, 0, cost} );
    
    G[to].push_back( Edge.size() );
    Edge.push_back( edge{to, from, 0, 0, -cost} );
}

inline bool bfs( ll s, ll t )
{
    for ( int i = 0; i < 2 * N + 5; ++i )
        d[i] = INF;
    memset( inqueue, 0, sizeof( inqueue ) );

    queue<ll> q;
    q.push( s );

    d[s] = 0, inqueue[s] = true;

    ll now;
    while ( q.empty() == false ) {
        now = q.front();
        q.pop();
        inqueue[now] = false;
        for ( ll i = 0; i < G[now].size(); ++i ) {
            edge& tmp = Edge[G[now][i]];
            if ( tmp.cap > tmp.flow && d[now] + tmp.cost < d[tmp.to] ) {
                d[tmp.to] = d[now] + tmp.cost;
                pre[tmp.to] = G[now][i];

                if ( inqueue[tmp.to] == false && tmp.to != t ) {
                    inqueue[tmp.to] = true;
                    q.push( tmp.to );
                }
            }
        }
    }

    return d[t] != INF;
    /*
    if(d[t]==-INF)
        return false;
    else
        return true;
    */
}

inline void calc( ll s, ll t )
{
    ll minflow = INF;
    ll tmpu = t;
    while ( s != tmpu ) { //find minflow
        minflow = min( minflow, Edge[pre[tmpu]].cap - Edge[pre[tmpu]].flow );
        tmpu = Edge[pre[tmpu]].from;
    }

    Maxflow += minflow;
    COST += minflow * d[t];

    while ( s != t ) {
        Edge[pre[t]].flow += minflow;
        Edge[pre[t] ^ 1].flow -= minflow;
        t = Edge[pre[t]].from;
    }
}

inline void init()
{
    cin >> n;

    ll a, b, c;
    for ( int i = 1; i <= n; ++i ) {
        cin >> a >> b >> c;
        addEdge( 0, i, c, 0 );
        addEdge( i, 2 * n + 1, c, -a - b );
        addEdge( i, 2 * n + 2, c, a - b );
        addEdge( i, 2 * n + 3, c, -a + b );
        addEdge( i, 2 * n + 4, c, a + b );
    }
    for ( int i = 1; i <= n; ++i ) {
        cin >> a >> b >> c;
        addEdge( i + n, 2 * n + 5, c, 0 );
        addEdge( 2 * n + 1, i + n, c, a + b );
        addEdge( 2 * n + 2, i + n, c, -a + b );
        addEdge( 2 * n + 3, i + n, c, a - b );
        addEdge( 2 * n + 4, i + n, c, -a - b );
    }
}

inline void solve()
{
    ll s = 0, t = 2 * n + 5;

    while ( bfs( s, t ) == true ) {
        calc( s, t );  //update cost && Maxflow
    }
    cout << -COST << endl;
}

int main()
{
    init();
    solve();
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(long long N, std::string S, long long Q, std::vector<long long> K){

    for(auto k:K){
        
        //0:D 1:M 2:D,M
        lli dp[3]={0,0,0};
        lli ans = 0;

        REP(i,0,N){
            if(S[i]=='D')dp[0]++;
            else if(S[i]=='M')dp[1]++,dp[2]+=dp[0];
            else if(S[i]=='C')ans += dp[2];

            if(i<k-1)continue;
            if(S[i-k+1]=='D')dp[2]-=dp[1], dp[0]--;
            else if(S[i-k+1]=='M')dp[1]--;
        }

        cout<<ans<<endl;


    }

    

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> k(Q-1-0+1);
    for(int i = 0 ; i < Q-1-0+1 ; i++){
        scanf("%lld",&k[i]);
    }
    func(N, S, Q, std::move(k));
    return 0;
}


Measured memory_bytes: 2308
s = list(input())
k = int(input())
a = "azyxwvutsrqponmlkjihgfedcb"
for i in range(len(s)-1):
  t = a.index(s[i])
  if k < t:
    continue
  else:
    s[i] = "a"
    k -= t
s[len(s)-1] = a[(a.index(s[len(s)-1])-k)%26]
print(*s, sep="")

Measured memory_bytes: 6968
n = int(input())
t = [0] * (n+1)
x = [0] * (n+1)
y = [0] * (n+1)
for i in range(1,n+1):
    t[i],x[i],y[i] = map(int,input().split())

for i in range(n):
    tmp = abs(t[i+1]-t[i]) - (abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]))
    if tmp < 0 or tmp % 2 != 0:    
        print('No')
        quit()
print('Yes')



Measured memory_bytes: 11636
using AtCoderBeginnerContest152.Questions;
using AtCoderBeginnerContest152.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest152.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nm = inputStream.ReadIntArray();
            yield return nm[0] == nm[1] ? "Yes" : "No";
        }
    }
}


namespace AtCoderBeginnerContest152
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest152.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest152.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
#include <stdio.h>

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

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> veki[100003],ikev[100003];
int bio[100003];
vector <int> topo;
int dp[100003];

int dfs(int x){
	bio[x]=1;
	for(int i=0;i<veki[x].size();i++){
		if(bio[veki[x][i]]) continue;
		dfs(veki[x][i]);
	}
	topo.push_back(x);
}


int main () {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		veki[a].push_back(b);
		ikev[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		dfs(i);
	}
	reverse(topo.begin(),topo.end());
	int sol=0;
	for(int i=0;i<topo.size();i++){
		for(int j=0;j<ikev[topo[i]].size();j++){
			if(dp[ikev[topo[i]][j]]+1>dp[topo[i]]) dp[topo[i]]=dp[ikev[topo[i]][j]]+1;
		}
		if(dp[topo[i]]>sol) sol=dp[topo[i]];
	}
	cout<<sol;



return 0;
}



Measured memory_bytes: 14200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int64_t k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    vector<int> mark(n,-1);
    mark[0] = 0;

    int mod;
    int now = 0;
    int counter = 1;
    while(k>0){
        k--;
        now = a[now]-1;
        if(mark[now]>=0){
            mod = counter - mark[now] ;
            break;
        }
        else mark[now] = counter;

        counter++;
    }
    //cout << k <<" " <<mod<<endl;;
    if(k<=0){
        cout << now+1 <<endl;
    }else{

    for(int i=0;i<n;i++){
        if(k%mod == mark[i] - mark[now]){
            cout << i+1 <<endl;
            break;
        }
    }
    }
}

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

int main() {
    int N;
    cin >> N;
    while(N--) {
        vector<int> cnt;
        vector<vector<int>> g;
        vector<int> st;
        while(true) {
            int rec;
            cin >> rec;
            if(!rec) {
                break;
            }

            if(rec > 0) {
                if(st.empty()) {
                    st.push_back(0);
                    g.push_back(vector<int>{});
                    cnt.push_back(rec);
                } else {
                    int par = st.back();
                    g[par].push_back(g.size());
                    g.push_back(vector<int>(1, par));
                    st.push_back(g.size()-1);
                    cnt[par]--;
                    cnt.push_back(rec-1);
                }
            } else {
                int now = st.back();
                int v = st[st.size()+rec-1];
                g[v].push_back(now);
                g[now].push_back(v);
                cnt[v]--; cnt[now]--;
            }
            while(cnt[st.back()] == 0) {
                st.pop_back();
                if(st.empty()) {
                    break;
                }
            }
        }
        for(int i=0; i<g.size(); ++i) {
            cout << i+1 << ' ';
            sort(g[i].begin(), g[i].end());
            for(int j=0; j<g[i].size(); ++j) {
                cout << g[i][j]+1 << " \n"[j == g[i].size()-1] << flush;
            }
        }
    }
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

#define X real()
#define Y imag()

typedef double D;
D EPS = 1e-8;

typedef complex<D> P;
struct L{
    P a, b;
    P vec(){ return b - a; }
};
typedef vector<P> Pol;

int sig(D a) { return a < -EPS ? -1 : a > EPS ? 1 : 0; }
D dot(P a, P b){ return a.X * b.X + a.Y * b.Y; }
D cross(P a, P b){ return a.X * b.Y - a.Y * b.X; }

D area(Pol pol) {
    int n = pol.size();
    D res = 0;
    REP(i, n) {
        res += cross(pol[i], pol[ (i + 1) % n ]);
    }
    return abs(res) / 2.0;
}

// 2点a, bを通る半径rの円の中心
vector<P> tc2(P a, P b, D r){
    vector<P> res;

    D d = abs(b - a);
    if(sig(d - 2 * r) > 0) return res;

    P mid = 0.5 * (a + b);
    P dir = polar(sqrt(r * r - d * d / 4), arg(b - a) + M_PI / 2);
    res.push_back(mid + dir);
    res.push_back(mid - dir);
    return res;
}

int main(){
    int N;
    while(cin >> N && N > 0) {
        vector<P> ps(N);
        REP(i, N) {
            D x, y;
            cin >> x >> y;
            ps[i] = P(x, y);
        }

        int ans = 1;
        REP(i, N) REP(j, N) if(i != j) {
            vector<P> cv = tc2(ps[i], ps[j], 1.0);
            for(auto c : cv) {
                int sum = 0;
                REP(k, N) {
                    if(sig(abs(c - ps[k]) - 1.0) <= 0) {
                        sum++;
                    }
                }
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1344
# include <iostream>

using namespace std;

int K, S;
int ans = 0;

int main () {
    cin >> K >> S;
    for ( int X = 0; X <= K; X++) {
        for ( int Y = 0; Y <= K; Y++){
            if ( X + Y <= S && S - X - Y <= K ) { 
                ans ++;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string s,s1,s2;
  cin >> s >> s1 >> s2;
  cout << "A" << s1[0] << "C" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const double PI=3.1415926;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	double n;

	cin>>n;

	cout<<2*n*PI<<endl;

	return 0;

}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if(s=="SUN")ans = 7;
  if(s=="MON")ans = 6;
  if(s=="TUE")ans = 5;
  if(s=="WED")ans = 4;
  if(s=="THU")ans = 3;
  if(s=="FRI")ans = 2;
  if(s=="SAT")ans = 1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	int t = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (x != i) {
			t++;
		}
	}
	if (t <= 2) {
		cout << "YES";
	} else {
		cout << "NO";
	}
}

Measured memory_bytes: 256
import scala.io.Source.stdin

object Main extends App {
  val b = new StringBuilder

  for(d<-stdin.getLines.map(_.toInt)) {
    var i = 0
    var s = 0
    while(i*d < 600) {
      s += i*i
      i += 1
    }
    b.append(s*d*d*d+"\n")
  }
  print(b.result)
}

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

c_list = list(map(int, input().split()))

c_list.sort()


i = 0
for _ in range(len(c_list)):
    if x - c_list[i] < 0:
        print(i)
        exit()
    x -= c_list[i]
    i += 1

if x == 0:
    print(len(c_list))
else:
    print(len(c_list) - 1)



Measured memory_bytes: 3060
#DFS
from collections import deque

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  
stack = deque([(0, 0)])
visited = [0] * N
depth = 0
ans = 0
while stack:
  now, depth = stack.pop()
  if depth == N-1:
    ans += 1
    continue
  visited[depth] = now
  for nxt in G[now]:
    if nxt not in visited[:depth+1]:
      stack.append((nxt, depth+1))
    
print(ans)

Measured memory_bytes: 3316
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i).sort
dd = Hash.new { false }
t = a.tally

if a[0] == 1
  if t[1] > 1
    puts 0
  else
    puts 1
  end
  exit
end
max = a.last
a.each do |e|
  next if dd[e]

  i = 2
  loop do
    x = i * e
    break if x > max

    dd[x] = true
    i += 1
  end
end
c = []
a.each do |e|
  c.push e if !dd[e] && t[e] == 1
end

puts c.size


Measured memory_bytes: 73808
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define int long long
#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ; 

int n , m , tag , mark[MAXN] ;
vector <int> g[MAXN] ;

void dfs(int v) {
	mark[v] = 1 ;
	for ( auto u : g[v] )
		if ( !mark[u] )
			dfs(u) ;
}

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> m ;
	int x , y , z ;
	for ( int i = 1 ; i <= m ; i ++ )
		cin >> x >> y >> z , g[x].pb(y) , g[y].pb(x) ;
	for ( int i = 1 ; i <= n ; i ++ )
		if ( !mark[i] )
			tag ++ , dfs(i) ;
	cout << tag << "\n" ;
}


Measured memory_bytes: 31104